Class SqlIntervalQualifier

java.lang.Object
org.apache.calcite.sql.SqlNode
org.apache.calcite.sql.SqlIntervalQualifier
All Implemented Interfaces:
Cloneable

public class SqlIntervalQualifier extends SqlNode
Represents an INTERVAL qualifier.

INTERVAL qualifier is defined as follows:

<interval qualifier> ::=
   <start field> TO <end field>
  | <single datetime field>
<start field> ::=
   <non-second primary datetime field>
   [ <left paren> <interval leading field precision> <right paren> ]
<end field> ::=
   <non-second primary datetime field>
  | SECOND [ <left paren> <interval fractional seconds precision> <right paren> ]
<single datetime field> ::=
  <non-second primary datetime field>
  [ <left paren> <interval leading field precision> <right paren> ]
  | SECOND [ <left paren> <interval leading field precision>
  [ <comma> <interval fractional seconds precision> ] <right paren> ]
<primary datetime field> ::=
  <non-second primary datetime field>
  | SECOND
<non-second primary datetime field> ::= YEAR | MONTH | DAY | HOUR | MINUTE
<interval fractional seconds precision> ::= <unsigned integer>
<interval leading field precision> ::= <unsigned integer>

Examples include:

  • INTERVAL '1:23:45.678' HOUR TO SECOND
  • INTERVAL '1 2:3:4' DAY TO SECOND
  • INTERVAL '1 2:3:4' DAY(4) TO SECOND(4)

An instance of this class is immutable.

  • Field Details

    • timeFrameName

      public final @Nullable String timeFrameName
    • timeUnitRange

      public final org.apache.calcite.avatica.util.TimeUnitRange timeUnitRange
  • Constructor Details

    • SqlIntervalQualifier

      public SqlIntervalQualifier(org.apache.calcite.avatica.util.TimeUnit startUnit, int startPrecision, @Nullable org.apache.calcite.avatica.util.TimeUnit endUnit, int fractionalSecondPrecision, SqlParserPos pos)
    • SqlIntervalQualifier

      public SqlIntervalQualifier(org.apache.calcite.avatica.util.TimeUnit startUnit, @Nullable org.apache.calcite.avatica.util.TimeUnit endUnit, SqlParserPos pos)
    • SqlIntervalQualifier

      public SqlIntervalQualifier(String timeFrameName, SqlParserPos pos)
      Creates a qualifier based on a time frame name.
  • Method Details

    • 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 SqlNode
      Returns:
      a SqlKind value, never null
      See Also:
    • typeName

      public SqlTypeName typeName()
    • isDate

      public boolean isDate()
      Whether this is a DATE interval (including all week intervals).
    • isTime

      public boolean isTime()
      Whether this is a TIME interval.
    • isTimestamp

      public boolean isTimestamp()
      Whether this is a TIMESTAMP interval (including all week intervals).
    • isWeek

      public boolean isWeek()
      Whether this qualifier represents WEEK, ISOWEEK, or WEEK(weekday) (for weekday in SUNDAY .. SATURDAY).
    • validate

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

      The typical implementation of this method will make a callback to the validator appropriate to the node type and context. The validator has methods such as SqlValidator.validateLiteral(org.apache.calcite.sql.SqlLiteral) for these purposes.

      Specified by:
      validate in class SqlNode
      Parameters:
      scope - Validator
    • accept

      public <R> R accept(SqlVisitor<R> visitor)
      Description copied from class: SqlNode
      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.

      Specified by:
      accept in class SqlNode
    • equalsDeep

      public boolean equalsDeep(@Nullable SqlNode node, Litmus litmus)
      Description copied from class: SqlNode
      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
      Specified by:
      equalsDeep in class SqlNode
    • getStartPrecision

      public int getStartPrecision(RelDataTypeSystem typeSystem)
    • getStartPrecisionPreservingDefault

      public int getStartPrecisionPreservingDefault()
    • useDefaultStartPrecision

      public boolean useDefaultStartPrecision()
      Returns true if start precision is not specified.
    • combineStartPrecisionPreservingDefault

      public static int combineStartPrecisionPreservingDefault(RelDataTypeSystem typeSystem, SqlIntervalQualifier qual1, SqlIntervalQualifier qual2)
    • getFractionalSecondPrecision

      public int getFractionalSecondPrecision(RelDataTypeSystem typeSystem)
    • getFractionalSecondPrecisionPreservingDefault

      public int getFractionalSecondPrecisionPreservingDefault()
    • useDefaultFractionalSecondPrecision

      public boolean useDefaultFractionalSecondPrecision()
      Returns true if fractional second precision is not specified.
    • combineFractionalSecondPrecisionPreservingDefault

      public static int combineFractionalSecondPrecisionPreservingDefault(RelDataTypeSystem typeSystem, SqlIntervalQualifier qual1, SqlIntervalQualifier qual2)
    • getStartUnit

      public org.apache.calcite.avatica.util.TimeUnit getStartUnit()
    • getEndUnit

      public org.apache.calcite.avatica.util.TimeUnit getEndUnit()
    • getUnit

      public org.apache.calcite.avatica.util.TimeUnit getUnit()
      Returns SECOND for both HOUR TO SECOND and SECOND.
    • clone

      public SqlNode clone(SqlParserPos pos)
      Description copied from class: SqlNode
      Clones a SqlNode with a different position.
      Specified by:
      clone in class SqlNode
    • 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).

      Specified by:
      unparse in class SqlNode
      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
    • isSingleDatetimeField

      public boolean isSingleDatetimeField()
      Returns whether this interval has a single datetime field.

      Returns true if it is of the form unit, false if it is of the form unit TO unit.

    • isYearMonth

      public final boolean isYearMonth()
    • getIntervalSign

      public int getIntervalSign(String value)
      Returns 1 or -1.
    • stringToDatePartTimeUnit

      public static org.apache.calcite.avatica.util.TimeUnit stringToDatePartTimeUnit(String stringValue)
    • evaluateIntervalLiteral

      public int[] evaluateIntervalLiteral(String value, SqlParserPos pos, RelDataTypeSystem typeSystem)
      Validates an INTERVAL literal according to the rules specified by the interval qualifier. The assumption is made that the interval qualifier has been validated prior to calling this method. Evaluating against an invalid qualifier could lead to strange results.
      Returns:
      field values, never null
      Throws:
      CalciteContextException - if the interval value is illegal
    • asIdentifier

      public static SqlNode asIdentifier(SqlNode node)
      Converts a SqlIntervalQualifier to a SqlIdentifier if it is a time frame reference.

      Helps with unparsing of EXTRACT, FLOOR, CEIL functions.