Search in sources :

Example 1 with RowExpression

use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.

the class TestPinotExpressionConverters method testAggregationProjectUnsupported.

private void testAggregationProjectUnsupported(String sqlExpression, SessionHolder sessionHolder) {
    try {
        RowExpression pushDownExpression = getRowExpression(sqlExpression, sessionHolder);
        String actualPinotExpression = pushDownExpression.accept(new PinotAggregationProjectConverter(functionAndTypeManager, functionAndTypeManager, standardFunctionResolution, sessionHolder.getConnectorSession()), testInput).getDefinition();
        fail("expected to not reach here: Generated " + actualPinotExpression);
    } catch (PinotException e) {
        assertEquals(e.getErrorCode(), PINOT_UNSUPPORTED_EXPRESSION.toErrorCode());
    }
}
Also used : PinotException(com.facebook.presto.pinot.PinotException) RowExpression(com.facebook.presto.spi.relation.RowExpression)

Example 2 with RowExpression

use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.

the class TestPinotExpressionConverters method testFilter.

private void testFilter(String sqlExpression, String expectedPinotExpression, SessionHolder sessionHolder) {
    RowExpression pushDownExpression = getRowExpression(sqlExpression, sessionHolder);
    String actualPinotExpression = pushDownExpression.accept(new PinotFilterExpressionConverter(functionAndTypeManager, functionAndTypeManager, standardFunctionResolution), testInputFunction).getDefinition();
    assertEquals(actualPinotExpression, expectedPinotExpression);
}
Also used : RowExpression(com.facebook.presto.spi.relation.RowExpression)

Example 3 with RowExpression

use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.

the class TestPinotExpressionConverters method testAggregationProject.

private void testAggregationProject(String sqlExpression, String expectedPinotExpression, SessionHolder sessionHolder) {
    RowExpression pushDownExpression = getRowExpression(sqlExpression, sessionHolder);
    String actualPinotExpression = pushDownExpression.accept(new PinotAggregationProjectConverter(functionAndTypeManager, functionAndTypeManager, standardFunctionResolution, sessionHolder.getConnectorSession()), testInput).getDefinition();
    assertEquals(actualPinotExpression, expectedPinotExpression);
}
Also used : RowExpression(com.facebook.presto.spi.relation.RowExpression)

Example 4 with RowExpression

use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.

the class DruidProjectExpressionConverter method handleCast.

private DruidExpression handleCast(CallExpression cast, Map<VariableReferenceExpression, Selection> context) {
    if (cast.getArguments().size() == 1) {
        RowExpression input = cast.getArguments().get(0);
        Type expectedType = cast.getType();
        if (isImplicitCast(input.getType(), expectedType)) {
            return input.accept(this, context);
        }
        throw new PrestoException(DRUID_PUSHDOWN_UNSUPPORTED_EXPRESSION, "Non implicit casts not supported: " + cast);
    }
    throw new PrestoException(DRUID_PUSHDOWN_UNSUPPORTED_EXPRESSION, "This type of CAST operator not supported: " + cast);
}
Also used : Type(com.facebook.presto.common.type.Type) RowExpression(com.facebook.presto.spi.relation.RowExpression) PrestoException(com.facebook.presto.spi.PrestoException)

Example 5 with RowExpression

use of com.facebook.presto.spi.relation.RowExpression in project presto by prestodb.

the class SubfieldExtractor method toRowExpression.

private RowExpression toRowExpression(Subfield subfield, List<Type> types) {
    List<Subfield.PathElement> path = subfield.getPath();
    if (path.isEmpty()) {
        return new VariableReferenceExpression(Optional.empty(), subfield.getRootName(), types.get(0));
    }
    RowExpression base = toRowExpression(new Subfield(subfield.getRootName(), path.subList(0, path.size() - 1)), types.subList(0, types.size() - 1));
    Type baseType = types.get(types.size() - 2);
    Subfield.PathElement pathElement = path.get(path.size() - 1);
    if (pathElement instanceof Subfield.LongSubscript) {
        Type indexType = baseType instanceof MapType ? ((MapType) baseType).getKeyType() : BIGINT;
        FunctionHandle functionHandle = functionResolution.subscriptFunction(baseType, indexType);
        ConstantExpression index = new ConstantExpression(base.getSourceLocation(), ((Subfield.LongSubscript) pathElement).getIndex(), indexType);
        return new CallExpression(base.getSourceLocation(), SUBSCRIPT.name(), functionHandle, types.get(types.size() - 1), ImmutableList.of(base, index));
    }
    if (pathElement instanceof Subfield.StringSubscript) {
        Type indexType = ((MapType) baseType).getKeyType();
        FunctionHandle functionHandle = functionResolution.subscriptFunction(baseType, indexType);
        ConstantExpression index = new ConstantExpression(base.getSourceLocation(), Slices.utf8Slice(((Subfield.StringSubscript) pathElement).getIndex()), indexType);
        return new CallExpression(base.getSourceLocation(), SUBSCRIPT.name(), functionHandle, types.get(types.size() - 1), ImmutableList.of(base, index));
    }
    if (pathElement instanceof Subfield.NestedField) {
        Subfield.NestedField nestedField = (Subfield.NestedField) pathElement;
        return new SpecialFormExpression(base.getSourceLocation(), DEREFERENCE, types.get(types.size() - 1), base, new ConstantExpression(base.getSourceLocation(), getFieldIndex((RowType) baseType, nestedField.getName()), INTEGER));
    }
    verify(false, "Unexpected path element: " + pathElement);
    return null;
}
Also used : ConstantExpression(com.facebook.presto.spi.relation.ConstantExpression) RowExpression(com.facebook.presto.spi.relation.RowExpression) MapType(com.facebook.presto.common.type.MapType) MapType(com.facebook.presto.common.type.MapType) Varchars.isVarcharType(com.facebook.presto.common.type.Varchars.isVarcharType) ArrayType(com.facebook.presto.common.type.ArrayType) Type(com.facebook.presto.common.type.Type) RowType(com.facebook.presto.common.type.RowType) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) CallExpression(com.facebook.presto.spi.relation.CallExpression) SpecialFormExpression(com.facebook.presto.spi.relation.SpecialFormExpression) Subfield(com.facebook.presto.common.Subfield)

Aggregations

RowExpression (com.facebook.presto.spi.relation.RowExpression)237 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)97 Test (org.testng.annotations.Test)87 ImmutableList (com.google.common.collect.ImmutableList)58 CallExpression (com.facebook.presto.spi.relation.CallExpression)52 Map (java.util.Map)49 List (java.util.List)42 Type (com.facebook.presto.common.type.Type)41 PlanNode (com.facebook.presto.spi.plan.PlanNode)41 ConstantExpression (com.facebook.presto.spi.relation.ConstantExpression)40 ImmutableMap (com.google.common.collect.ImmutableMap)38 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)37 SpecialFormExpression (com.facebook.presto.spi.relation.SpecialFormExpression)35 Optional (java.util.Optional)35 Expression (com.facebook.presto.sql.tree.Expression)31 ColumnHandle (com.facebook.presto.spi.ColumnHandle)27 Objects.requireNonNull (java.util.Objects.requireNonNull)27 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)24 Set (java.util.Set)24 ArrayList (java.util.ArrayList)23