use of org.joda.time.base.AbstractInterval in project druid by apache.
the class DruidSqlParserUtils method validateQueryAndConvertToIntervals.
/**
* This method validates and converts a {@link SqlNode} representing a query into an optmizied list of intervals to
* be used in creating an ingestion spec. If the sqlNode is an SqlLiteral of {@link #ALL}, returns a singleton list of
* "ALL". Otherwise, it converts and optimizes the query using {@link MoveTimeFiltersToIntervals} into a list of
* intervals which contain all valid values of time as per the query.
*
* The following validations are performed
* 1. Only __time column and timestamp literals are present in the query
* 2. The interval after optimization is not empty
* 3. The operands in the expression are supported
* 4. The intervals after adjusting for timezone are aligned with the granularity parameter
*
* @param replaceTimeQuery Sql node representing the query
* @param granularity granularity of the query for validation
* @param dateTimeZone timezone
* @return List of string representation of intervals
* @throws ValidationException if the SqlNode cannot be converted to a list of intervals
*/
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);
Filtration filtration = Filtration.create(dimFilter);
filtration = MoveTimeFiltersToIntervals.instance().apply(filtration);
List<Interval> intervals = filtration.getIntervals();
if (filtration.getDimFilter() != null) {
throw new ValidationException("Only " + ColumnHolder.TIME_COLUMN_NAME + " column is supported in OVERWRITE WHERE clause");
}
if (intervals.isEmpty()) {
throw new ValidationException("Intervals for replace are empty");
}
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 " + intervals + " which is not aligned with PARTITIONED BY granularity " + granularity);
}
}
return intervals.stream().map(AbstractInterval::toString).collect(Collectors.toList());
}
use of org.joda.time.base.AbstractInterval in project druid by druid-io.
the class DruidSqlParserUtils method validateQueryAndConvertToIntervals.
/**
* This method validates and converts a {@link SqlNode} representing a query into an optmizied list of intervals to
* be used in creating an ingestion spec. If the sqlNode is an SqlLiteral of {@link #ALL}, returns a singleton list of
* "ALL". Otherwise, it converts and optimizes the query using {@link MoveTimeFiltersToIntervals} into a list of
* intervals which contain all valid values of time as per the query.
*
* The following validations are performed
* 1. Only __time column and timestamp literals are present in the query
* 2. The interval after optimization is not empty
* 3. The operands in the expression are supported
* 4. The intervals after adjusting for timezone are aligned with the granularity parameter
*
* @param replaceTimeQuery Sql node representing the query
* @param granularity granularity of the query for validation
* @param dateTimeZone timezone
* @return List of string representation of intervals
* @throws ValidationException if the SqlNode cannot be converted to a list of intervals
*/
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);
Filtration filtration = Filtration.create(dimFilter);
filtration = MoveTimeFiltersToIntervals.instance().apply(filtration);
List<Interval> intervals = filtration.getIntervals();
if (filtration.getDimFilter() != null) {
throw new ValidationException("Only " + ColumnHolder.TIME_COLUMN_NAME + " column is supported in OVERWRITE WHERE clause");
}
if (intervals.isEmpty()) {
throw new ValidationException("Intervals for replace are empty");
}
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 " + intervals + " which is not aligned with PARTITIONED BY granularity " + granularity);
}
}
return intervals.stream().map(AbstractInterval::toString).collect(Collectors.toList());
}
Aggregations