adarshsanjeev commented on code in PR #12386:
URL: https://github.com/apache/druid/pull/12386#discussion_r862680688
##########
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java:
##########
@@ -167,4 +189,89 @@ public static Granularity
convertSqlNodeToGranularity(SqlNode sqlNode) throws Pa
TimeFloorOperatorConversion.SQL_FUNCTION_NAME
));
}
+
+ public static List<String> validateQueryAndConvertToIntervals(
+ SqlNode replaceTimeQuery,
+ Granularity granularity,
+ DateTimeZone dateTimeZone
+ ) throws ValidationException
+ {
+ if (replaceTimeQuery instanceof SqlLiteral &&
"all".equalsIgnoreCase(((SqlLiteral) replaceTimeQuery).toValue())) {
+ return ImmutableList.of("all");
+ }
+
+ DimFilter dimFilter = convertQueryToDimFilter(replaceTimeQuery,
dateTimeZone);
+ if
(!ImmutableSet.of(ColumnHolder.TIME_COLUMN_NAME).equals(dimFilter.getRequiredColumns()))
{
+ throw new ValidationException("Only " + ColumnHolder.TIME_COLUMN_NAME +
" column is supported in OVERWRITE WHERE clause");
+ }
+
+ Filtration filtration = Filtration.create(dimFilter);
+ filtration = MoveTimeFiltersToIntervals.instance().apply(filtration);
+ List<Interval> intervals = filtration.getIntervals();
+
+ for (Interval interval : intervals) {
+ DateTime intervalStart = interval.getStart();
+ DateTime intervalEnd = interval.getEnd();
+ if (!granularity.bucketStart(intervalStart).equals(intervalStart) ||
!granularity.bucketStart(intervalEnd).equals(intervalEnd)) {
+ throw new ValidationException("OVERWRITE WHERE clause contains an
interval which is not aligned with PARTITIONED BY granularity");
+ }
+ }
+ return intervals
+ .stream()
+ .map(AbstractInterval::toString)
+ .collect(Collectors.toList());
+ }
+
+ public static DimFilter convertQueryToDimFilter(SqlNode replaceTimeQuery,
DateTimeZone dateTimeZone)
+ throws ValidationException
+ {
+ if (replaceTimeQuery instanceof SqlBasicCall) {
Review Comment:
Changed
##########
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java:
##########
@@ -167,4 +189,89 @@ public static Granularity
convertSqlNodeToGranularity(SqlNode sqlNode) throws Pa
TimeFloorOperatorConversion.SQL_FUNCTION_NAME
));
}
+
+ public static List<String> validateQueryAndConvertToIntervals(
+ SqlNode replaceTimeQuery,
+ Granularity granularity,
+ DateTimeZone dateTimeZone
+ ) throws ValidationException
+ {
+ if (replaceTimeQuery instanceof SqlLiteral &&
"all".equalsIgnoreCase(((SqlLiteral) replaceTimeQuery).toValue())) {
+ return ImmutableList.of("all");
+ }
+
+ DimFilter dimFilter = convertQueryToDimFilter(replaceTimeQuery,
dateTimeZone);
+ if
(!ImmutableSet.of(ColumnHolder.TIME_COLUMN_NAME).equals(dimFilter.getRequiredColumns()))
{
+ throw new ValidationException("Only " + ColumnHolder.TIME_COLUMN_NAME +
" column is supported in OVERWRITE WHERE clause");
+ }
+
+ Filtration filtration = Filtration.create(dimFilter);
+ filtration = MoveTimeFiltersToIntervals.instance().apply(filtration);
+ List<Interval> intervals = filtration.getIntervals();
+
+ for (Interval interval : intervals) {
+ DateTime intervalStart = interval.getStart();
+ DateTime intervalEnd = interval.getEnd();
+ if (!granularity.bucketStart(intervalStart).equals(intervalStart) ||
!granularity.bucketStart(intervalEnd).equals(intervalEnd)) {
+ throw new ValidationException("OVERWRITE WHERE clause contains an
interval which is not aligned with PARTITIONED BY granularity");
Review Comment:
Added
##########
sql/src/main/java/org/apache/druid/sql/calcite/parser/DruidSqlParserUtils.java:
##########
@@ -167,4 +189,89 @@ public static Granularity
convertSqlNodeToGranularity(SqlNode sqlNode) throws Pa
TimeFloorOperatorConversion.SQL_FUNCTION_NAME
));
}
+
+ public static List<String> validateQueryAndConvertToIntervals(
+ SqlNode replaceTimeQuery,
+ Granularity granularity,
+ DateTimeZone dateTimeZone
+ ) throws ValidationException
+ {
+ if (replaceTimeQuery instanceof SqlLiteral &&
"all".equalsIgnoreCase(((SqlLiteral) replaceTimeQuery).toValue())) {
Review Comment:
Done
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]