Class SqlNode

    • Constructor Detail

      • SqlNode

        SqlNode​(SqlParserPos pos)
        Creates a node.
        Parameters:
        pos - Parser position, must not be null.
    • Method Detail

      • clone

        @Deprecated
        public java.lang.Object clone()
        Deprecated.
        Please use clone(SqlNode); this method brings along too much baggage from early versions of Java
        Overrides:
        clone in class java.lang.Object
      • clone

        public static <E extends SqlNode> E clone​(E e)
        Creates a copy of a SqlNode.
      • clone

        public abstract SqlNode clone​(SqlParserPos pos)
        Clones a SqlNode with a different position.
      • isA

        public final boolean isA​(java.util.Set<SqlKind> category)
        Returns whether this node is a member of an aggregate category.

        For example, node.isA(SqlKind.QUERY) returns true if the node is a SELECT, INSERT, UPDATE etc.

        This method is shorthand: node.isA(category) is always equivalent to node.getKind().belongsTo(category).

        Parameters:
        category - Category
        Returns:
        Whether this node belongs to the given category.
      • cloneArray

        @Deprecated
        public static SqlNode[] cloneArray​(SqlNode[] nodes)
        Deprecated.
      • toString

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

        public SqlString toSqlString​(SqlDialect dialect,
                                     boolean forceParens)
        Returns the SQL text of the tree of which this SqlNode is the root.

        Typical return values are:

        • 'It''s a bird!'
        • NULL
        • 12.3
        • DATE '1969-04-29'
        Parameters:
        dialect - Dialect (null for ANSI SQL)
        forceParens - Whether to wrap all expressions in parentheses; useful for parse test, but false by default
      • unparse

        public abstract void unparse​(SqlWriter writer,
                                     int leftPrec,
                                     int rightPrec)
        Writes a SQL representation of this node to a writer.

        The leftPrec and rightPrec parameters give us enough context to decide whether we need to enclose the expression in parentheses. For example, we need parentheses around "2 + 3" if preceded by "5 *". This is because the precedence of the "*" operator is greater than the precedence of the "+" operator.

        The algorithm handles left- and right-associative operators by giving them slightly different left- and right-precedence.

        If SqlWriter.isAlwaysUseParentheses() is true, we use parentheses even when they are not required by the precedence rules.

        For the details of this algorithm, see SqlCall.unparse(org.apache.calcite.sql.SqlWriter, int, int).

        Parameters:
        writer - Target writer
        leftPrec - The precedence of the SqlNode immediately preceding this node in a depth-first scan of the parse tree
        rightPrec - The precedence of the SqlNode immediately
      • getParserPosition

        public SqlParserPos getParserPosition()
      • findValidOptions

        public void findValidOptions​(SqlValidator validator,
                                     SqlValidatorScope scope,
                                     SqlParserPos pos,
                                     java.util.Collection<SqlMoniker> hintList)
        Lists all the valid alternatives for this node if the parse position of the node matches that of pos. Only implemented now for SqlCall and SqlOperator.
        Parameters:
        validator - Validator
        scope - Validation scope
        pos - SqlParserPos indicating the cursor position at which completion hints are requested for
        hintList - list of valid options
      • accept

        public abstract <R> R accept​(SqlVisitor<R> visitor)
        Accepts a generic visitor.

        Implementations of this method in subtypes simply call the appropriate visit method on the visitor object.

        The type parameter R must be consistent with the type parameter of the visitor.

      • equalsDeep

        public abstract boolean equalsDeep​(SqlNode node,
                                           Litmus litmus)
        Returns whether this node is structurally equivalent to another node. Some examples:
        • 1 + 2 is structurally equivalent to 1 + 2
        • 1 + 2 + 3 is structurally equivalent to (1 + 2) + 3, but not to 1 + (2 + 3), because the '+' operator is left-associative
      • equalsDeep

        @Deprecated
        public final boolean equalsDeep​(SqlNode node,
                                        boolean fail)
        Deprecated.
      • equalDeep

        public static boolean equalDeep​(SqlNode node1,
                                        SqlNode node2,
                                        Litmus litmus)
        Returns whether two nodes are equal (using equalsDeep(SqlNode, Litmus)) or are both null.
        Parameters:
        node1 - First expression
        node2 - Second expression
        litmus - What to do if an error is detected (expressions are not equal)
      • getMonotonicity

        public SqlMonotonicity getMonotonicity​(SqlValidatorScope scope)
        Returns whether expression is always ascending, descending or constant. This property is useful because it allows to safely aggregate infinite streams of values.

        The default implementation returns SqlMonotonicity.NOT_MONOTONIC.

        Parameters:
        scope - Scope
      • equalDeep

        public static boolean equalDeep​(java.util.List<SqlNode> operands0,
                                        java.util.List<SqlNode> operands1,
                                        Litmus litmus)
        Returns whether two lists of operands are equal.