Class SqlMerge

All Implemented Interfaces:
Cloneable

public class SqlMerge extends SqlCall
A SqlMerge is a node of a parse tree which represents a MERGE statement.
  • Field Details

  • Constructor Details

  • Method Details

    • getOperator

      public SqlOperator getOperator()
      Specified by:
      getOperator in class SqlCall
    • getKind

      public SqlKind getKind()
      Description copied from class: SqlNode
      Returns the type of node this is, or SqlKind.OTHER if it's nothing special.
      Overrides:
      getKind in class SqlCall
      Returns:
      a SqlKind value, never null
      See Also:
    • getOperandList

      public List<@Nullable SqlNode> getOperandList()
      Description copied from class: SqlCall
      Returns the list of operands. The set and order of operands is call-specific.

      Note: the proper type would be List<@Nullable SqlNode>, however, it would trigger too many changes to the current codebase.

      Specified by:
      getOperandList in class SqlCall
      Returns:
      the list of call operands, never null, the operands can be null
    • setOperand

      public void setOperand(int i, @Nullable SqlNode operand)
      Description copied from class: SqlCall
      Changes the value of an operand. Allows some rewrite by SqlValidator; use sparingly.
      Overrides:
      setOperand in class SqlCall
      Parameters:
      i - Operand index
      operand - Operand value
    • getTargetTable

      public SqlNode getTargetTable()
      Return the identifier for the target table of this MERGE.
    • getAlias

      @Pure public @Nullable SqlIdentifier getAlias()
      Returns the alias for the target table of this MERGE.
    • getSourceTableRef

      public SqlNode getSourceTableRef()
      Returns the source query of this MERGE.
    • setSourceTableRef

      public void setSourceTableRef(SqlNode tableRef)
    • getUpdateCall

      public @Nullable SqlUpdate getUpdateCall()
      Returns the UPDATE statement for this MERGE.
    • getInsertCall

      public @Nullable SqlInsert getInsertCall()
      Returns the INSERT statement for this MERGE.
    • getCondition

      public SqlNode getCondition()
      Returns the condition expression to determine whether to UPDATE or INSERT.
    • getSourceSelect

      public @Nullable SqlSelect getSourceSelect()
      Gets the source SELECT expression for the data to be updated/inserted.

      The source SELECT column order:

      • `WHEN NOT MATCHED THEN INSERT` only: [new values...]
      • `WHEN MATCHED THEN UPDATE` only: [old table columns..., updated new values...]
      • Both `NOT MATCHED THEN INSERT` and `WHEN MATCHED THEN UPDATE`: [insert new values..., old table columns..., updated new values...]
      Returns null before the statement has been expanded by SqlValidatorImpl.performUnconditionalRewrites(SqlNode, boolean) and SqlValidatorImpl.rewriteMerge(SqlMerge).
      Returns:
      the source SELECT for the data to be updated/inserted
    • setSourceSelect

      public void setSourceSelect(SqlSelect sourceSelect)
    • unparse

      public void unparse(SqlWriter writer, int leftPrec, int rightPrec)
      Description copied from class: SqlNode
      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).

      Overrides:
      unparse in class SqlCall
      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
    • validate

      public void validate(SqlValidator validator, SqlValidatorScope scope)
      Description copied from class: SqlCall
      Validates this call.

      The default implementation delegates the validation to the operator's SqlOperator.validateCall(org.apache.calcite.sql.SqlCall, org.apache.calcite.sql.validate.SqlValidator, org.apache.calcite.sql.validate.SqlValidatorScope, org.apache.calcite.sql.validate.SqlValidatorScope). Derived classes may override (as do, for example SqlSelect and SqlUpdate).

      Overrides:
      validate in class SqlCall
      Parameters:
      scope - Validator