Class SelectValue

  • All Implemented Interfaces:
    java.lang.Cloneable

    public class SelectValue
    extends java.lang.Object
    implements java.lang.Cloneable
    This class represents a single expression in a SELECT clause. The expression can be one of the following:
    • An Expression that evaluates to a single value
    • A wildcard expression like "*" or "loan.*" that evaluates to a set of column values
    • A scalar subquery (often correlated) that evaluates to a single column and row

    The isWildcard() method can be used to determine if an object of this type represents a wildcard value.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Expression expression
      If this select-value is a simple expression then this field will be set to the expression.
      private java.lang.String resultAlias
      If this select-value is an expression or a scalar subquery, this field will optionally specify an alias for the expression's value.
      private SelectClause scalarSubquery
      If this select-value is a scalar subquery then this field references the subquery expression.
      static java.lang.String UNNAMED_COLUMN_PREFIX  
      private ColumnName wildcardColumnName
      If the SELECT clause includes a wildcard column specifier (e.g.
    • Constructor Summary

      Constructors 
      Constructor Description
      SelectValue​(Expression e)
      Construct a select-value object from an expression, with no alias.
      SelectValue​(Expression e, java.lang.String alias)
      Construct a select-value object from an expression and an optional alias or nickname value.
    • Field Detail

      • UNNAMED_COLUMN_PREFIX

        public static final java.lang.String UNNAMED_COLUMN_PREFIX
        See Also:
        Constant Field Values
      • expression

        private Expression expression
        If this select-value is a simple expression then this field will be set to the expression. Otherwise, this value will be null.
      • scalarSubquery

        private SelectClause scalarSubquery
        If this select-value is a scalar subquery then this field references the subquery expression. Otherwise, this value will be null.
      • resultAlias

        private java.lang.String resultAlias
        If this select-value is an expression or a scalar subquery, this field will optionally specify an alias for the expression's value. This is for expressions such as "SELECT balance * interest AS new_balance FROM loans". For this example, the result-alias would be "new_balance".
      • wildcardColumnName

        private ColumnName wildcardColumnName
        If the SELECT clause includes a wildcard column specifier (e.g. "*" or "product.*") then this field will contain the details of that specifier. If the expression doesn't include a wildcard then this field will be null, and the expression field will specify the expression.
    • Constructor Detail

      • SelectValue

        public SelectValue​(Expression e,
                           java.lang.String alias)
        Construct a select-value object from an expression and an optional alias or nickname value.
        Parameters:
        e - The expression that generates the select-value.
        alias - If not null, this is the column name to assign to the result value.
        Throws:
        java.lang.NullPointerException - if e is null
        java.lang.IllegalArgumentException - if e is a wildcard expression, and alias is also specified
      • SelectValue

        public SelectValue​(Expression e)
        Construct a select-value object from an expression, with no alias.
        Parameters:
        e - The expression that generates the select-value.
        Throws:
        java.lang.NullPointerException - if e is null
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • isWildcard

        public boolean isWildcard()
        Returns true if this SelectValue is a wildcard expression, either of the form "*" or "loan.*".
        Returns:
        true if this select expression is a wildcard expression.
      • isExpression

        public boolean isExpression()
      • isSimpleColumnValue

        public boolean isSimpleColumnValue()
      • getExpression

        public Expression getExpression()
        Returns this SelectValue's expression or null if this is a wildcard.
        Returns:
        the expression that generates the select value
      • setExpression

        public void setExpression​(Expression e)
      • isScalarSubquery

        public boolean isScalarSubquery()
      • getAlias

        public java.lang.String getAlias()
        Returns this SelectValue's alias result name or null if it is unspecified.
        Returns:
        the string alias, or null if unspecified
      • setAlias

        public void setAlias​(java.lang.String alias)
        Sets this SelectValue's alias result name to the specifie string.
        Parameters:
        alias - the alias to use for the column, or null if no alias should be used
      • getWildcard

        public ColumnName getWildcard()
        Returns the wildcard ColumnName object or null if there is none.
        Returns:
        the wildcard specification, or null if unspecified
      • getScalarSubquery

        public SelectClause getScalarSubquery()
      • getColumnInfos

        public java.util.List<ColumnInfo> getColumnInfos​(Schema inputSchema,
                                                         Schema resultSchema)
        This function returns the column-details of all results that will be produced by this select-value. For example, if the select value is a wildcard such as * or tbl.* then the referenced column details will be retrieved from the input-schema.

        If the select value is an expression then the result column-info is determined from the expression itself. For example, the expression might simply be a column a, or tbl.a; in these cases the column-info is retrieved from the input schema. Expressions can also be renamed; this renaming is applied here. However, if a complex expression doesn't have a name then it will be assigned a unique name.

        Parameters:
        inputSchema - the schema against which the select-value will be evaluated
        resultSchema - the current result schema "so far". This is provided so that if the select-value is unnamed then a unique name can be generated.
        Returns:
        a collection of one or more column-information objects containing the schema for this select-value.
      • equals

        public boolean equals​(java.lang.Object obj)
        Checks if the argument is a SelectValue with the same fields.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object to which we are comparing
      • hashCode

        public int hashCode()
        Computes the hashcode of a SelectValue. This method is used to see if two SelectValues CAN be equal.
        Overrides:
        hashCode in class java.lang.Object
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Creates a copy of a select value.
        Overrides:
        clone in class java.lang.Object
        Throws:
        java.lang.CloneNotSupportedException