public class SqlIntervalQualifier extends SqlNode
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 SECONDINTERVAL '1 2:3:4' DAY TO SECONDINTERVAL '1 2:3:4' DAY(4) TO SECOND(4)An instance of this class is immutable.
| Modifier and Type | Field and Description |
|---|---|
private int |
fractionalSecondPrecision |
private static BigDecimal |
INT_MAX_VALUE_PLUS_ONE |
private static BigDecimal[] |
POWERS10 |
private int |
startPrecision |
private static BigDecimal |
THOUSAND |
org.apache.calcite.avatica.util.TimeUnitRange |
timeUnitRange |
private static BigDecimal |
ZERO |
EMPTY_ARRAY, pos| Constructor and Description |
|---|
SqlIntervalQualifier(org.apache.calcite.avatica.util.TimeUnit startUnit,
int startPrecision,
org.apache.calcite.avatica.util.TimeUnit endUnit,
int fractionalSecondPrecision,
SqlParserPos pos) |
SqlIntervalQualifier(org.apache.calcite.avatica.util.TimeUnit startUnit,
org.apache.calcite.avatica.util.TimeUnit endUnit,
SqlParserPos pos) |
| Modifier and Type | Method and Description |
|---|---|
<R> R |
accept(SqlVisitor<R> visitor)
Accepts a generic visitor.
|
private void |
checkLeadFieldInRange(RelDataTypeSystem typeSystem,
int sign,
BigDecimal value,
org.apache.calcite.avatica.util.TimeUnit unit,
SqlParserPos pos) |
SqlNode |
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(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.
|
private int[] |
evaluateIntervalLiteralAsDay(RelDataTypeSystem typeSystem,
int sign,
String value,
String originalValue,
SqlParserPos pos)
Validates an INTERVAL literal against a DAY interval qualifier.
|
private int[] |
evaluateIntervalLiteralAsDayToHour(RelDataTypeSystem typeSystem,
int sign,
String value,
String originalValue,
SqlParserPos pos)
Validates an INTERVAL literal against a DAY TO HOUR interval qualifier.
|
private int[] |
evaluateIntervalLiteralAsDayToMinute(RelDataTypeSystem typeSystem,
int sign,
String value,
String originalValue,
SqlParserPos pos)
Validates an INTERVAL literal against a DAY TO MINUTE interval qualifier.
|
private int[] |
evaluateIntervalLiteralAsDayToSecond(RelDataTypeSystem typeSystem,
int sign,
String value,
String originalValue,
SqlParserPos pos)
Validates an INTERVAL literal against a DAY TO SECOND interval qualifier.
|
private int[] |
evaluateIntervalLiteralAsHour(RelDataTypeSystem typeSystem,
int sign,
String value,
String originalValue,
SqlParserPos pos)
Validates an INTERVAL literal against an HOUR interval qualifier.
|
private int[] |
evaluateIntervalLiteralAsHourToMinute(RelDataTypeSystem typeSystem,
int sign,
String value,
String originalValue,
SqlParserPos pos)
Validates an INTERVAL literal against an HOUR TO MINUTE interval
qualifier.
|
private int[] |
evaluateIntervalLiteralAsHourToSecond(RelDataTypeSystem typeSystem,
int sign,
String value,
String originalValue,
SqlParserPos pos)
Validates an INTERVAL literal against an HOUR TO SECOND interval
qualifier.
|
private int[] |
evaluateIntervalLiteralAsMinute(RelDataTypeSystem typeSystem,
int sign,
String value,
String originalValue,
SqlParserPos pos)
Validates an INTERVAL literal against an MINUTE interval qualifier.
|
private int[] |
evaluateIntervalLiteralAsMinuteToSecond(RelDataTypeSystem typeSystem,
int sign,
String value,
String originalValue,
SqlParserPos pos)
Validates an INTERVAL literal against an MINUTE TO SECOND interval
qualifier.
|
private int[] |
evaluateIntervalLiteralAsMonth(RelDataTypeSystem typeSystem,
int sign,
String value,
String originalValue,
SqlParserPos pos)
Validates an INTERVAL literal against a MONTH interval qualifier.
|
private int[] |
evaluateIntervalLiteralAsSecond(RelDataTypeSystem typeSystem,
int sign,
String value,
String originalValue,
SqlParserPos pos)
Validates an INTERVAL literal against an SECOND interval qualifier.
|
private int[] |
evaluateIntervalLiteralAsYear(RelDataTypeSystem typeSystem,
int sign,
String value,
String originalValue,
SqlParserPos pos)
Validates an INTERVAL literal against a YEAR interval qualifier.
|
private int[] |
evaluateIntervalLiteralAsYearToMonth(RelDataTypeSystem typeSystem,
int sign,
String value,
String originalValue,
SqlParserPos pos)
Validates an INTERVAL literal against a YEAR TO MONTH interval qualifier.
|
private CalciteContextException |
fieldExceedsPrecisionException(SqlParserPos pos,
int sign,
BigDecimal value,
org.apache.calcite.avatica.util.TimeUnit type,
int precision) |
private int[] |
fillIntervalValueArray(int sign,
BigDecimal year,
BigDecimal month) |
private int[] |
fillIntervalValueArray(int sign,
BigDecimal day,
BigDecimal hour,
BigDecimal minute,
BigDecimal second,
BigDecimal secondFrac) |
org.apache.calcite.avatica.util.TimeUnit |
getEndUnit() |
int |
getFractionalSecondPrecision(RelDataTypeSystem typeSystem) |
int |
getFractionalSecondPrecisionPreservingDefault() |
int |
getIntervalSign(String value) |
int |
getStartPrecision(RelDataTypeSystem typeSystem) |
int |
getStartPrecisionPreservingDefault() |
org.apache.calcite.avatica.util.TimeUnit |
getStartUnit() |
org.apache.calcite.avatica.util.TimeUnit |
getUnit()
Returns
SECOND for both HOUR TO SECOND and
SECOND. |
private CalciteContextException |
invalidValueException(SqlParserPos pos,
String value) |
private boolean |
isFractionalSecondFieldInRange(BigDecimal field) |
private boolean |
isLeadFieldInRange(RelDataTypeSystem typeSystem,
BigDecimal value,
org.apache.calcite.avatica.util.TimeUnit unit) |
private boolean |
isSecondaryFieldInRange(BigDecimal field,
org.apache.calcite.avatica.util.TimeUnit unit) |
boolean |
isSingleDatetimeField()
Returns whether this interval has a single datetime field.
|
boolean |
isYearMonth() |
private BigDecimal |
normalizeSecondFraction(String secondFracStr) |
private BigDecimal |
parseField(Matcher m,
int i) |
private String |
stripLeadingSign(String value) |
SqlTypeName |
typeName() |
void |
unparse(RelDataTypeSystem typeSystem,
SqlWriter writer) |
void |
unparse(SqlWriter writer,
int leftPrec,
int rightPrec)
Writes a SQL representation of this node to a writer.
|
private boolean |
useDefaultFractionalSecondPrecision() |
private boolean |
useDefaultStartPrecision() |
void |
validate(SqlValidator validator,
SqlValidatorScope scope)
Validates this node.
|
clone, clone, cloneArray, equalDeep, equalDeep, equalsDeep, findValidOptions, getKind, getMonotonicity, getParserPosition, isA, toSqlString, toSqlString, toString, validateExprprivate static final BigDecimal ZERO
private static final BigDecimal THOUSAND
private static final BigDecimal INT_MAX_VALUE_PLUS_ONE
private final int startPrecision
public final org.apache.calcite.avatica.util.TimeUnitRange timeUnitRange
private final int fractionalSecondPrecision
private static final BigDecimal[] POWERS10
public SqlIntervalQualifier(org.apache.calcite.avatica.util.TimeUnit startUnit,
int startPrecision,
org.apache.calcite.avatica.util.TimeUnit endUnit,
int fractionalSecondPrecision,
SqlParserPos pos)
public SqlIntervalQualifier(org.apache.calcite.avatica.util.TimeUnit startUnit,
org.apache.calcite.avatica.util.TimeUnit endUnit,
SqlParserPos pos)
public SqlTypeName typeName()
public void validate(SqlValidator validator, SqlValidatorScope scope)
SqlNodeThe 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.
public <R> R accept(SqlVisitor<R> visitor)
SqlNodeImplementations 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.
public boolean equalsDeep(SqlNode node, Litmus litmus)
SqlNodeequalsDeep in class SqlNodepublic int getStartPrecision(RelDataTypeSystem typeSystem)
public int getStartPrecisionPreservingDefault()
private boolean useDefaultStartPrecision()
public static int combineStartPrecisionPreservingDefault(RelDataTypeSystem typeSystem, SqlIntervalQualifier qual1, SqlIntervalQualifier qual2)
public int getFractionalSecondPrecision(RelDataTypeSystem typeSystem)
public int getFractionalSecondPrecisionPreservingDefault()
private boolean useDefaultFractionalSecondPrecision()
public static int combineFractionalSecondPrecisionPreservingDefault(RelDataTypeSystem typeSystem, SqlIntervalQualifier qual1, SqlIntervalQualifier qual2)
public org.apache.calcite.avatica.util.TimeUnit getStartUnit()
public org.apache.calcite.avatica.util.TimeUnit getEndUnit()
public org.apache.calcite.avatica.util.TimeUnit getUnit()
SECOND for both HOUR TO SECOND and
SECOND.public SqlNode clone(SqlParserPos pos)
SqlNodepublic void unparse(SqlWriter writer, int leftPrec, int rightPrec)
SqlNodeThe 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).
public void unparse(RelDataTypeSystem typeSystem, SqlWriter writer)
public boolean isSingleDatetimeField()
Returns true if it is of the form unit,
false if it is of the form unit TO unit.
public final boolean isYearMonth()
public int getIntervalSign(String value)
private boolean isLeadFieldInRange(RelDataTypeSystem typeSystem, BigDecimal value, org.apache.calcite.avatica.util.TimeUnit unit)
private void checkLeadFieldInRange(RelDataTypeSystem typeSystem, int sign, BigDecimal value, org.apache.calcite.avatica.util.TimeUnit unit, SqlParserPos pos)
private boolean isFractionalSecondFieldInRange(BigDecimal field)
private boolean isSecondaryFieldInRange(BigDecimal field, org.apache.calcite.avatica.util.TimeUnit unit)
private BigDecimal normalizeSecondFraction(String secondFracStr)
private int[] fillIntervalValueArray(int sign,
BigDecimal year,
BigDecimal month)
private int[] fillIntervalValueArray(int sign,
BigDecimal day,
BigDecimal hour,
BigDecimal minute,
BigDecimal second,
BigDecimal secondFrac)
private int[] evaluateIntervalLiteralAsYear(RelDataTypeSystem typeSystem, int sign, String value, String originalValue, SqlParserPos pos)
CalciteContextException - if the interval
value is illegalprivate int[] evaluateIntervalLiteralAsYearToMonth(RelDataTypeSystem typeSystem, int sign, String value, String originalValue, SqlParserPos pos)
CalciteContextException - if the interval
value is illegalprivate int[] evaluateIntervalLiteralAsMonth(RelDataTypeSystem typeSystem, int sign, String value, String originalValue, SqlParserPos pos)
CalciteContextException - if the interval
value is illegalprivate int[] evaluateIntervalLiteralAsDay(RelDataTypeSystem typeSystem, int sign, String value, String originalValue, SqlParserPos pos)
CalciteContextException - if the interval
value is illegalprivate int[] evaluateIntervalLiteralAsDayToHour(RelDataTypeSystem typeSystem, int sign, String value, String originalValue, SqlParserPos pos)
CalciteContextException - if the interval
value is illegalprivate int[] evaluateIntervalLiteralAsDayToMinute(RelDataTypeSystem typeSystem, int sign, String value, String originalValue, SqlParserPos pos)
CalciteContextException - if the interval
value is illegalprivate int[] evaluateIntervalLiteralAsDayToSecond(RelDataTypeSystem typeSystem, int sign, String value, String originalValue, SqlParserPos pos)
CalciteContextException - if the interval
value is illegalprivate int[] evaluateIntervalLiteralAsHour(RelDataTypeSystem typeSystem, int sign, String value, String originalValue, SqlParserPos pos)
CalciteContextException - if the interval
value is illegalprivate int[] evaluateIntervalLiteralAsHourToMinute(RelDataTypeSystem typeSystem, int sign, String value, String originalValue, SqlParserPos pos)
CalciteContextException - if the interval
value is illegalprivate int[] evaluateIntervalLiteralAsHourToSecond(RelDataTypeSystem typeSystem, int sign, String value, String originalValue, SqlParserPos pos)
CalciteContextException - if the interval
value is illegalprivate int[] evaluateIntervalLiteralAsMinute(RelDataTypeSystem typeSystem, int sign, String value, String originalValue, SqlParserPos pos)
CalciteContextException - if the interval
value is illegalprivate int[] evaluateIntervalLiteralAsMinuteToSecond(RelDataTypeSystem typeSystem, int sign, String value, String originalValue, SqlParserPos pos)
CalciteContextException - if the interval
value is illegalprivate int[] evaluateIntervalLiteralAsSecond(RelDataTypeSystem typeSystem, int sign, String value, String originalValue, SqlParserPos pos)
CalciteContextException - if the interval
value is illegalpublic int[] evaluateIntervalLiteral(String value, SqlParserPos pos, RelDataTypeSystem typeSystem)
CalciteContextException - if the interval
value is illegalprivate BigDecimal parseField(Matcher m, int i)
private CalciteContextException invalidValueException(SqlParserPos pos, String value)
private CalciteContextException fieldExceedsPrecisionException(SqlParserPos pos, int sign, BigDecimal value, org.apache.calcite.avatica.util.TimeUnit type, int precision)
Copyright © 2012–2018 The Apache Software Foundation. All rights reserved.