Search in sources :

Example 31 with ConstantExpression

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()));
}
Also used : PinotException(com.facebook.presto.pinot.PinotException) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression)

Example 32 with ConstantExpression

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) + ")");
}
Also used : PinotException(com.facebook.presto.pinot.PinotException) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) PinotPushdownUtils.getLiteralAsString(com.facebook.presto.pinot.PinotPushdownUtils.getLiteralAsString) CallExpression(com.facebook.presto.spi.relation.CallExpression)

Example 33 with ConstantExpression

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 + ")");
}
Also used : PinotException(com.facebook.presto.pinot.PinotException) ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) PinotPushdownUtils.getLiteralAsString(com.facebook.presto.pinot.PinotPushdownUtils.getLiteralAsString) CallExpression(com.facebook.presto.spi.relation.CallExpression)

Aggregations

ConstantExpression (com.facebook.presto.spi.relation.ConstantExpression)33 RowExpression (com.facebook.presto.spi.relation.RowExpression)25 CallExpression (com.facebook.presto.spi.relation.CallExpression)14 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)14 SpecialFormExpression (com.facebook.presto.spi.relation.SpecialFormExpression)10 Map (java.util.Map)8 ImmutableList (com.google.common.collect.ImmutableList)7 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)6 Type (com.facebook.presto.common.type.Type)6 InputReferenceExpression (com.facebook.presto.spi.relation.InputReferenceExpression)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 Slice (io.airlift.slice.Slice)6 List (java.util.List)6 Scope (com.facebook.presto.bytecode.Scope)5 Variable (com.facebook.presto.bytecode.Variable)5 FunctionHandle (com.facebook.presto.spi.function.FunctionHandle)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 Optional (java.util.Optional)5 IfStatement (com.facebook.presto.bytecode.control.IfStatement)4