Class RexLiteral

    • Method Detail

      • computeDigest

        public final String computeDigest​(RexDigestIncludeType includeType)
        Returns a string which concisely describes the definition of this rex literal. Two literals are equivalent if and only if their digests are the same.

        The digest does not contain the expression's identity, but does include the identity of children.

        Technically speaking 1:INT differs from 1:FLOAT, so we need data type in the literal's digest, however we want to avoid extra verbosity of the RelNode.getDigest() for readability purposes, so we omit type info in certain cases. For instance, 1:INT becomes 1 (INT is implied by default), however 1:BIGINT always holds the type

        Here's a non-exhaustive list of the "well known cases":

        • Hide "NOT NULL" for not null literals
        • Hide INTEGER, BOOLEAN, SYMBOL, TIME(0), TIMESTAMP(0), DATE(0) types
        • Hide collation when it matches IMPLICIT/COERCIBLE
        • Hide charset when it matches default
        • Hide CHAR(xx) when literal length is equal to the precision of the type. In other words, use 'Bob' instead of 'Bob':CHAR(3)
        • Hide BOOL for AND/OR arguments. In other words, AND(true, null) means null is BOOL.
        • Hide types for literals in simple binary operations (e.g. +, -, *, /, comparison) when type of the other argument is clear. See RexCall.computeDigest(boolean) For instance: =(true. null) means null is BOOL. =($0, null) means the type of null matches the type of $0.
        includeType - whether the digest should include type or not
      • valueMatchesType

        public static boolean valueMatchesType​(Comparable value,
                                               SqlTypeName typeName,
                                               boolean strict)
        Returns whether a value is appropriate for its type. (We have rules about these things!)
      • printAsJava

        public void printAsJava​(PrintWriter pw)
        Prints the value this literal as a Java string constant.
      • fromJdbcString

        public static RexLiteral fromJdbcString​(RelDataType type,
                                                SqlTypeName typeName,
                                                String literal)
        Converts a Jdbc string into a RexLiteral. This method accepts a string, as returned by the Jdbc method ResultSet.getString(), and restores the string into an equivalent RexLiteral. It allows one to use Jdbc strings as a common format for data.

        If a null literal is provided, then a null pointer will be returned.

        type - data type of literal to be read
        typeName - type family of literal
        literal - the (non-SQL encoded) string representation, as returned by the Jdbc call to return a column as a string
        a typed RexLiteral, or null
      • getKind

        public SqlKind getKind()
        Description copied from class: RexNode
        Returns the kind of node this is.
        getKind in class RexNode
        Node kind, never null
      • isNull

        public boolean isNull()
        Returns whether this literal's value is null.
      • getValue

        public Comparable getValue()
        Returns the value of this literal.

        For backwards compatibility, returns DATE. TIME and TIMESTAMP as a Calendar value in UTC time zone.

      • getValue2

        public Object getValue2()
        Returns the value of this literal, in the form that the calculator program builder wants it.
      • getValue3

        public Object getValue3()
        Returns the value of this literal, in the form that the rex-to-lix translator wants it.
      • getValue4

        public Comparable getValue4()
        Returns the value of this literal, in the form that RexInterpreter wants it.
      • getValueAs

        public <T> T getValueAs​(Class<T> clazz)
        Returns the value of this literal as an instance of the specified class.

        The following SQL types allow more than one form:

        Called with clazz = Comparable, returns the value in its native form.

        Type Parameters:
        T - Return type
        clazz - Desired return type
        Value of this literal in the desired type
      • booleanValue

        public static boolean booleanValue​(RexNode node)
      • isAlwaysTrue

        public boolean isAlwaysTrue()
        Description copied from class: RexNode
        Returns whether this expression always returns true. (Such as if this expression is equal to the literal TRUE.)
        isAlwaysTrue in class RexNode
      • isAlwaysFalse

        public boolean isAlwaysFalse()
        Description copied from class: RexNode
        Returns whether this expression always returns false. (Such as if this expression is equal to the literal FALSE.)
        isAlwaysFalse in class RexNode
      • intValue

        public static int intValue​(RexNode node)
      • stringValue

        public static String stringValue​(RexNode node)
      • isNullLiteral

        public static boolean isNullLiteral​(RexNode node)