use of com.facebook.presto.spi.relation.ConstantExpression in project presto by prestodb.
the class PinotFilterExpressionConverter method handleContains.
private PinotExpression handleContains(CallExpression contains, Function<VariableReferenceExpression, Selection> context) {
if (contains.getArguments().size() != 2) {
throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), format("Contains operator not supported: %s", contains));
}
RowExpression left = contains.getArguments().get(0);
RowExpression right = contains.getArguments().get(1);
if (!(right instanceof ConstantExpression)) {
throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), format("Contains operator can not push down non-literal value: %s", right));
}
return derived(format("(%s = %s)", left.accept(this, context).getDefinition(), right.accept(this, context).getDefinition()));
}
use of com.facebook.presto.spi.relation.ConstantExpression in project presto by prestodb.
the class PinotAggregationProjectConverter method handleDateTruncationViaDateTruncation.
private PinotExpression handleDateTruncationViaDateTruncation(CallExpression function, Map<VariableReferenceExpression, PinotQueryGeneratorContext.Selection> context) {
RowExpression timeInputParameter = function.getArguments().get(1);
String inputColumn;
String inputTimeZone;
String inputFormat;
CallExpression timeConversion = getExpressionAsFunction(timeInputParameter, timeInputParameter);
switch(timeConversion.getDisplayName().toLowerCase(ENGLISH)) {
case FROM_UNIXTIME:
inputColumn = timeConversion.getArguments().get(0).accept(this, context).getDefinition();
inputTimeZone = timeConversion.getArguments().size() > 1 ? getStringFromConstant(timeConversion.getArguments().get(1)) : DateTimeZone.UTC.getID();
inputFormat = "seconds";
break;
default:
throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "not supported: " + timeConversion.getDisplayName());
}
RowExpression intervalParameter = function.getArguments().get(0);
if (!(intervalParameter instanceof ConstantExpression)) {
throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "interval unit in date_trunc is not supported: " + intervalParameter);
}
return derived("dateTrunc(" + inputColumn + "," + inputFormat + ", " + inputTimeZone + ", " + getStringFromConstant(intervalParameter) + ")");
}
use of com.facebook.presto.spi.relation.ConstantExpression in project presto by prestodb.
the class PinotAggregationProjectConverter method handleDateTruncationViaDateTimeConvert.
private PinotExpression handleDateTruncationViaDateTimeConvert(CallExpression function, Map<VariableReferenceExpression, PinotQueryGeneratorContext.Selection> context) {
// Convert SQL standard function `DATE_TRUNC(INTERVAL, DATE/TIMESTAMP COLUMN)` to
// Pinot's equivalent function `dateTimeConvert(columnName, inputFormat, outputFormat, outputGranularity)`
// Pinot doesn't have a DATE/TIMESTAMP type. That means the input column (second argument) has been converted from numeric type to DATE/TIMESTAMP using one of the
// conversion functions in SQL. First step is find the function and find its input column units (seconds, secondsSinceEpoch etc.)
RowExpression timeInputParameter = function.getArguments().get(1);
String inputColumn;
String inputFormat;
CallExpression timeConversion = getExpressionAsFunction(timeInputParameter, timeInputParameter);
switch(timeConversion.getDisplayName().toLowerCase(ENGLISH)) {
case FROM_UNIXTIME:
inputColumn = timeConversion.getArguments().get(0).accept(this, context).getDefinition();
inputFormat = "'1:SECONDS:EPOCH'";
break;
default:
throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "not supported: " + timeConversion.getDisplayName());
}
String outputFormat = "'1:MILLISECONDS:EPOCH'";
String outputGranularity;
RowExpression intervalParameter = function.getArguments().get(0);
if (!(intervalParameter instanceof ConstantExpression)) {
throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "interval unit in date_trunc is not supported: " + intervalParameter);
}
String value = getStringFromConstant(intervalParameter);
switch(value) {
case "second":
outputGranularity = "'1:SECONDS'";
break;
case "minute":
outputGranularity = "'1:MINUTES'";
break;
case "hour":
outputGranularity = "'1:HOURS'";
break;
case "day":
outputGranularity = "'1:DAYS'";
break;
case "week":
outputGranularity = "'1:WEEKS'";
break;
case "month":
outputGranularity = "'1:MONTHS'";
break;
case "quarter":
outputGranularity = "'1:QUARTERS'";
break;
case "year":
outputGranularity = "'1:YEARS'";
break;
default:
throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "interval in date_trunc is not supported: " + value);
}
return derived("dateTimeConvert(" + inputColumn + ", " + inputFormat + ", " + outputFormat + ", " + outputGranularity + ")");
}
Aggregations