mihaibudiu commented on code in PR #3435:
URL: https://github.com/apache/calcite/pull/3435#discussion_r1518410698
##########
core/src/main/java/org/apache/calcite/sql/fun/SqlExtractFunction.java:
##########
@@ -83,8 +88,102 @@ public SqlExtractFunction(String name) {
// startUnit = EPOCH and timeFrameName = 'MINUTE15'.
//
// If the latter, check that timeFrameName is valid.
- validator.validateTimeFrame(
- (SqlIntervalQualifier) call.getOperandList().get(0));
+ SqlIntervalQualifier qualifier = call.operand(0);
+ validator.validateTimeFrame(qualifier);
+ TimeUnitRange range = qualifier.timeUnitRange;
+
+ RelDataType type = validator.getValidatedNodeTypeIfKnown(call.operand(1));
+ if (type == null) {
+ return;
+ }
+
+ SqlTypeName typeName = type.getSqlTypeName();
+ boolean legal;
+ switch (range) {
+ case YEAR:
+ case MONTH:
+ case ISOYEAR:
+ case QUARTER:
+ case DECADE:
+ case CENTURY:
+ case MILLENNIUM:
+ legal = new ImmutableList.Builder<SqlTypeName>()
+ .add(SqlTypeName.DATE)
+ .add(SqlTypeName.TIMESTAMP)
+ .add(SqlTypeName.TIMESTAMP_WITH_LOCAL_TIME_ZONE)
+ .addAll(SqlTypeName.YEAR_INTERVAL_TYPES)
+ .build()
+ .contains(typeName);
+ break;
+ case WEEK:
+ case DOW:
+ case ISODOW:
+ case DOY:
+ legal = new ImmutableList.Builder<SqlTypeName>()
Review Comment:
I am now using static fields for these constant lists.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]