Class SqlIntervalQualifier
- All Implemented Interfaces:
Cloneable
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 Summary
Modifier and TypeFieldDescriptionfinal @Nullable String
final org.apache.calcite.avatica.util.TimeUnitRange
Fields inherited from class org.apache.calcite.sql.SqlNode
EMPTY_ARRAY, pos
-
Constructor Summary
ConstructorDescriptionSqlIntervalQualifier
(String timeFrameName, SqlParserPos pos) Creates a qualifier based on a time frame name.SqlIntervalQualifier
(org.apache.calcite.avatica.util.TimeUnit startUnit, int startPrecision, @Nullable org.apache.calcite.avatica.util.TimeUnit endUnit, int fractionalSecondPrecision, SqlParserPos pos) SqlIntervalQualifier
(org.apache.calcite.avatica.util.TimeUnit startUnit, @Nullable org.apache.calcite.avatica.util.TimeUnit endUnit, SqlParserPos pos) -
Method Summary
Modifier and TypeMethodDescription<R> R
accept
(SqlVisitor<R> visitor) Accepts a generic visitor.static SqlNode
asIdentifier
(SqlNode node) Converts aSqlIntervalQualifier
to aSqlIdentifier
if it is a time frame reference.clone
(SqlParserPos pos) Clones a SqlNode with a different position.static int
combineFractionalSecondPrecisionPreservingDefault
(RelDataTypeSystem typeSystem, SqlIntervalQualifier qual1, SqlIntervalQualifier qual2) static int
combineStartPrecisionPreservingDefault
(RelDataTypeSystem typeSystem, SqlIntervalQualifier qual1, SqlIntervalQualifier qual2) boolean
equalsDeep
(@Nullable SqlNode node, Litmus litmus) Returns whether this node is structurally equivalent to another node.int[]
evaluateIntervalLiteral
(String value, SqlParserPos pos, RelDataTypeSystem typeSystem) Validates an INTERVAL literal according to the rules specified by the interval qualifier.org.apache.calcite.avatica.util.TimeUnit
int
getFractionalSecondPrecision
(RelDataTypeSystem typeSystem) int
int
getIntervalSign
(String value) Returns 1 or -1.getKind()
Returns the type of node this is, orSqlKind.OTHER
if it's nothing special.int
getStartPrecision
(RelDataTypeSystem typeSystem) int
org.apache.calcite.avatica.util.TimeUnit
org.apache.calcite.avatica.util.TimeUnit
getUnit()
ReturnsSECOND
for bothHOUR TO SECOND
andSECOND
.boolean
isDate()
Whether this is a DATE interval (including all week intervals).boolean
Returns whether this interval has a single datetime field.boolean
isTime()
Whether this is a TIME interval.boolean
Whether this is a TIMESTAMP interval (including all week intervals).boolean
isWeek()
Whether this qualifier representsWEEK
,ISOWEEK
, orWEEK(
weekday)
(for weekday inSUNDAY
..final boolean
static org.apache.calcite.avatica.util.TimeUnit
stringToDatePartTimeUnit
(String stringValue) typeName()
void
Writes a SQL representation of this node to a writer.boolean
Returnstrue
if fractional second precision is not specified.boolean
Returnstrue
if start precision is not specified.void
validate
(SqlValidator validator, SqlValidatorScope scope) Validates this node.Methods inherited from class org.apache.calcite.sql.SqlNode
clone, clone, cloneArray, equalDeep, equalDeep, equalsDeep, findValidOptions, getMonotonicity, getParserPosition, isA, toList, toList, toSqlString, toSqlString, toSqlString, toString, unparseWithParentheses, validateExpr
-
Field Details
-
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
Creates a qualifier based on a time frame name.
-
-
Method Details
-
getKind
Description copied from class:SqlNode
Returns the type of node this is, orSqlKind.OTHER
if it's nothing special. -
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 representsWEEK
,ISOWEEK
, orWEEK(
weekday)
(for weekday inSUNDAY
..SATURDAY
). -
validate
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. -
accept
Description copied from class:SqlNode
Accepts a generic visitor.Implementations of this method in subtypes simply call the appropriate
visit
method on thevisitor object
.The type parameter
R
must be consistent with the type parameter of the visitor. -
equalsDeep
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 classSqlNode
-
getStartPrecision
-
getStartPrecisionPreservingDefault
public int getStartPrecisionPreservingDefault() -
useDefaultStartPrecision
public boolean useDefaultStartPrecision()Returnstrue
if start precision is not specified. -
combineStartPrecisionPreservingDefault
public static int combineStartPrecisionPreservingDefault(RelDataTypeSystem typeSystem, SqlIntervalQualifier qual1, SqlIntervalQualifier qual2) -
getFractionalSecondPrecision
-
getFractionalSecondPrecisionPreservingDefault
public int getFractionalSecondPrecisionPreservingDefault() -
useDefaultFractionalSecondPrecision
public boolean useDefaultFractionalSecondPrecision()Returnstrue
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()ReturnsSECOND
for bothHOUR TO SECOND
andSECOND
. -
clone
Description copied from class:SqlNode
Clones a SqlNode with a different position. -
unparse
Description copied from class:SqlNode
Writes a SQL representation of this node to a writer.The
leftPrec
andrightPrec
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)
. -
isSingleDatetimeField
public boolean isSingleDatetimeField()Returns whether this interval has a single datetime field.Returns
true
if it is of the formunit
,false
if it is of the formunit TO unit
. -
isYearMonth
public final boolean isYearMonth() -
getIntervalSign
Returns 1 or -1. -
stringToDatePartTimeUnit
-
evaluateIntervalLiteral
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
Converts aSqlIntervalQualifier
to aSqlIdentifier
if it is a time frame reference.Helps with unparsing of EXTRACT, FLOOR, CEIL functions.
-