Class CustomTargetType

java.lang.Object
adql.query.operand.function.cast.CustomTargetType
All Implemented Interfaces:
TargetType

public class CustomTargetType extends Object implements TargetType
Representation of a non-standard target type of the CAST function.

Parameters

On the contrary to a standard target type, a custom type does not have any restriction on parameters: it may have as many parameters as desired. There is no constraint as well on their type: no strict signature to follow.

Return type

Because the target type is custom, there is no way to automatically determine the (approximate or precise) type of the value returned by the CAST function. The constructor of CustomTargetType tries anyway to resolve the given custom type name, in case it is a datatype known by the ADQL library (see DBType.DBDatatype). If successfully resolved, a DBType is automatically created (with no length parameter) and will be returned by getReturnType(). If still unknown (or erroneous), one has to explicitly use setReturnType(DBType).

The functions isNumeric(), isString() and isGeometry() are used to give hint to the ADQL query parser about where the CAST function can be used. By default, they return what the same functions of the getReturnType() returns. If this latter returns NULL, all these functions return true so that the CAST function can be used anywhere in an ADQL query. However, this may lead to errors when running the query against a database.

Since:
2.0
See Also:
  • Field Details

    • typeName

      protected String typeName
      Datatype's name. Never NULL or empty.
    • parameters

      protected ADQLOperand[] parameters
      Ordered list of all type parameters. >NULL (preferably ; by default) or empty if no parameter.
    • returnType

      protected DBType returnType
      Type of the value returned by the CAST function. NULL if unknown (default).
  • Constructor Details

    • CustomTargetType

      public CustomTargetType(String typeName) throws NullPointerException
      Create a custom CAST's target type with no parameter.

      Implementation note: This constructor is equivalent to CustomTargetType(String, ADQLOperand[]) with (typeName, null).

      Parameters:
      typeName - Name of the custom type.
      Throws:
      NullPointerException - If the given name is NULL or empty.
    • CustomTargetType

      public CustomTargetType(String typeName, ADQLOperand[] parameters)
      Create a custom CAST's target type.
      Parameters:
      typeName - Name of the custom type.
      parameters - Type parameters (e.g. a length). NULL or empty if no parameter.
      Throws:
      NullPointerException - If the given name is NULL or empty, or if one parameter is NULL.
  • Method Details

    • getName

      public final String getName()
      Description copied from interface: TargetType
      Get the type name (as written in ADQL).

      IMPORTANT: This function MUST never return NULL or an empty string.

      Specified by:
      getName in interface TargetType
      Returns:
      The type name.
    • getPosition

      public final TextPosition getPosition()
      Description copied from interface: TargetType
      Position of the type name (start) and all its parameters (end).
      Specified by:
      getPosition in interface TargetType
      Returns:
      Position of this target type in the input ADQL query, or NULL if this piece of information is not available.
    • setPosition

      public final void setPosition(TextPosition newPosition)
      Description copied from interface: TargetType
      Sets the position at which this TargetType has been found in the original ADQL query string.
      Specified by:
      setPosition in interface TargetType
    • isNumeric

      public boolean isNumeric()
      Description copied from interface: TargetType
      Indicate whether the output of the CAST function is numeric or not.

      Implementation note: If the return type is unknown, it is a good practice to make TargetType.isNumeric(), TargetType.isGeometry() and TargetType.isString() to return true. This information is used only by the parser when checking whether the CAST function can be used in some context. So, when the type of an ADQL operand is unknown, it is assumed it could be placed anywhere until its type can be precisely determined or until the query reaches the database.

      Specified by:
      isNumeric in interface TargetType
      Returns:
      true if the CAST function returns a numeric, false otherwise.
    • isString

      public boolean isString()
      Description copied from interface: TargetType
      Indicate whether the output of the CAST function is a character string or not.

      Implementation note: If the return type is unknown, it is a good practice to make TargetType.isNumeric(), TargetType.isGeometry() and TargetType.isString() to return true. This information is used only by the parser when checking whether the CAST function can be used in some context. So, when the type of an ADQL operand is unknown, it is assumed it could be placed anywhere until its type can be precisely determined or until the query reaches the database.

      Specified by:
      isString in interface TargetType
      Returns:
      true if the CAST function returns a string, false otherwise.
    • isGeometry

      public boolean isGeometry()
      Description copied from interface: TargetType
      Indicate whether the output of the CAST function is a geometry or not.

      Implementation note: If the return type is unknown, it is a good practice to make TargetType.isNumeric(), TargetType.isGeometry() and TargetType.isString() to return true. This information is used only by the parser when checking whether the CAST function can be used in some context. So, when the type of an ADQL operand is unknown, it is assumed it could be placed anywhere until its type can be precisely determined or until the query reaches the database.

      Specified by:
      isGeometry in interface TargetType
      Returns:
      true if the CAST function returns a geometry, false otherwise.
    • getReturnType

      public final DBType getReturnType()
      Description copied from interface: TargetType
      Indicate the precise type of the value expected to be returned by the CAST function.

      This information is used only when the CAST function is used as output column (so, in the SELECT clause). It is a hint when formatting the query result to make the most appropriate conversion.

      Specified by:
      getReturnType in interface TargetType
      Returns:
      The expected type returned by the CAST function, or NULL if unknown.
    • setReturnType

      public void setReturnType(DBType newType)
      Set the expected type returned by the CAST function.
      Parameters:
      newType - The presumed returned type, or NULL if unknown.
    • getNbParameters

      public int getNbParameters()
      Description copied from interface: TargetType
      Get the actual number of parameters.
      Specified by:
      getNbParameters in interface TargetType
      Returns:
      Number of parameters.
    • getParameters

      public ADQLOperand[] getParameters()
      Description copied from interface: TargetType
      Get the ordered list of all parameters.
      Specified by:
      getParameters in interface TargetType
      Returns:
      All type parameters, or an empty array if no parameter.
    • getParameter

      public ADQLOperand getParameter(int indParam)
      Description copied from interface: TargetType
      Get the indParam-th parameter.
      Specified by:
      getParameter in interface TargetType
      Parameters:
      indParam - Index (≥ 0) of the parameter to get.
      Returns:
      The corresponding parameter.
    • setParameter

      public ADQLOperand setParameter(int indParam, ADQLOperand newParam)
      Description copied from interface: TargetType
      Replace the indParam-th parameter.
      Specified by:
      setParameter in interface TargetType
      Parameters:
      indParam - Index (≥ 0) of the parameter to replace.
      newParam - The operand to set instead of the current indParam-th parameter.
      Returns:
      The former indParam-th parameter.
    • toADQL

      public String toADQL()
      Description copied from interface: TargetType
      Serialize this type into ADQL.
      Specified by:
      toADQL in interface TargetType
      Returns:
      Its ADQL serialization.
    • getCopy

      public TargetType getCopy() throws Exception
      Description copied from interface: TargetType
      Create a deep copy of this target type.
      Specified by:
      getCopy in interface TargetType
      Returns:
      Type copy.
      Throws:
      Exception - If the copy fails.
    • toString

      public String toString()
      Overrides:
      toString in class Object