Class StandardTargetType

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

public class StandardTargetType extends Object implements TargetType
Representation of an ADQL standard target type of the CAST function.

Parameters

All target types represented by this class can not be parameterized, except variable datatypes (such as DBType.DBDatatype.CHAR and DBType.DBDatatype.VARCHAR) which may have only one - the length.

Standard datatypes

Datatypes considered as standard by this class can be retrieved thanks to getStandardDatatypes(). It is also possible to get them by category with getNumericDatatypes(), getStringDatatypes() and getGeometricDatatypes(). A given DBType.DBDatatype can be tested to know whether it is considered as standard or not with isStandardDatatype(DBDatatype).

Note: DBType.DBDatatype.DOUBLE is represented in ADQL with the string DOUBLE PRECISION. This specificity is already taken into account by toADQL() and when creating a StandardTargetType with a string (see below).

Datatype normalization

The constructors StandardTargetType(String) and StandardTargetType(String, int) accepts the string version of a standard datatype. To resolve it, they rely on the static function resolveDatatype(String). This latter always normalize the input string so that consecutive whitespace characters are replaced by only one and all other characters are upper-case. The normalization is performed by the static function normalizeDatatype(String).

Since:
2.0
See Also:
  • Field Details

    • STANDARD_DATATYPES

      protected static final DBType.DBDatatype[] STANDARD_DATATYPES
      All datatypes allowed by ADQL as CAST's target type.
    • type

      protected DBType type
      The represented target type.
  • Constructor Details

  • Method Details

    • normalizeDatatype

      public static final String normalizeDatatype(String str) throws NullPointerException
      Normalize the given datatype serialization.

      The normalization performed here...

      • ...remove leading and trailing space characters,
      • ...replace all consecutive space characters by a single space,
      • ...and put all characters in upper-case.
      Parameters:
      str - The string to normalize.
      Returns:
      Its normalized version.
      Throws:
      NullPointerException - If the given string is NULL or empty.
    • resolveDatatype

      public static final DBType.DBDatatype resolveDatatype(String str) throws NullPointerException, IllegalArgumentException
      Resolve the given type serialization into a DBType.DBDatatype.

      The given string is normalized and then resolved into a DBType.DBDatatype value. If no DBDatatype matches, an IllegalArgumentException is thrown.

      Note: The returned datatype is not guaranteed to be a standard CAST's target datatype: this is not checked in this function. To check the datatype use isStandardDatatype(DBDatatype) with the DBType.DBDatatype returned by this function.

      Parameters:
      str - The type's string serialization.
      Returns:
      The resolved datatype.
      Throws:
      NullPointerException - If the given string is NULL or empty.
      IllegalArgumentException - If the serialized datatype is unknown.
    • isStandardDatatype

      public static boolean isStandardDatatype(DBType.DBDatatype datatype)
      Tell whether the given datatype is allowed as target for CAST function.
      Parameters:
      datatype - The datatype to test.
      Returns:
      true if allowed by ADQL as CAST' target type, false otherwise.
    • getStandardDatatypes

      public static final DBType.DBDatatype[] getStandardDatatypes()
      Get all datatypes considered as standard CAST's target types.
      Returns:
      All standard CAST's target types.
    • getNumericDatatypes

      public static final DBType.DBDatatype[] getNumericDatatypes()
      Get all numeric datatypes among all the standard CAST's target types.
      Returns:
      All standard numeric CAST's target types.
    • getStringDatatypes

      public static final DBType.DBDatatype[] getStringDatatypes()
      Get all string datatypes among all the standard CAST's target types.
      Returns:
      All standard string CAST's target types.
    • getGeometricDatatypes

      public static final DBType.DBDatatype[] getGeometricDatatypes()
      Get all geometric datatypes among all the standard CAST's target types.
      Returns:
      All standard geometric CAST's target types.
    • 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.
    • getName

      public 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.
    • getTypeLength

      public int getTypeLength()
      Get the length associated with this target type.

      Note: The returned length can be positive and not null ONLY IF the target type is a variable length type (e.g. CHAR, VARCHAR).

      Returns:
      Type length.
    • getReturnType

      public 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.
    • 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.
    • getPosition

      public 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 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
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • 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.