Search in sources :

Example 1 with CallExpression

use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.

the class TestExternalFunctionPushDownChecker method setup.

@BeforeClass
public void setup() {
    planSymbolAllocator = new PlanSymbolAllocator();
    columnA = planSymbolAllocator.newSymbol("a", DOUBLE);
    columnB = planSymbolAllocator.newSymbol("b", DOUBLE);
    sumCall = call("sum", SUM, DOUBLE, ImmutableList.of(VariableReferenceSymbolConverter.toVariableReference(columnA, DOUBLE)));
    externalFooCall1 = new CallExpression("jdbc.v1.foo", EXTERNAL_FOO, DOUBLE, ImmutableList.of());
    externalFooCall2 = new CallExpression("jdbc.v1.foo2", EXTERNAL_FOO, DOUBLE, ImmutableList.of());
    metadata = getQueryRunner().getMetadata();
    builder = new PlanBuilder(new PlanNodeIdAllocator(), metadata);
}
Also used : PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) PlanSymbolAllocator(io.prestosql.sql.planner.PlanSymbolAllocator) CallExpression(io.prestosql.spi.relation.CallExpression) PlanBuilder(io.prestosql.sql.planner.iterative.rule.test.PlanBuilder) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with CallExpression

use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.

the class RowExpressionVerifier method visitArithmeticBinary.

@Override
protected Boolean visitArithmeticBinary(ArithmeticBinaryExpression expected, RowExpression actual) {
    if (actual instanceof CallExpression) {
        FunctionMetadata functionMetadata = metadata.getFunctionAndTypeManager().getFunctionMetadata(((CallExpression) actual).getFunctionHandle());
        if (!functionMetadata.getOperatorType().isPresent() || !functionMetadata.getOperatorType().get().isArithmeticOperator()) {
            return false;
        }
        OperatorType actualOperatorType = functionMetadata.getOperatorType().get();
        OperatorType expectedOperatorType = getOperatorType(expected.getOperator());
        if (expectedOperatorType.equals(actualOperatorType)) {
            return process(expected.getLeft(), ((CallExpression) actual).getArguments().get(0)) && process(expected.getRight(), ((CallExpression) actual).getArguments().get(1));
        }
    }
    return false;
}
Also used : FunctionMetadata(io.prestosql.spi.function.FunctionMetadata) CallExpression(io.prestosql.spi.relation.CallExpression) OperatorType(io.prestosql.spi.function.OperatorType)

Example 3 with CallExpression

use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.

the class RowExpressionVerifier method visitCast.

@Override
protected Boolean visitCast(Cast expected, RowExpression actual) {
    // TODO: clean up cast path
    if (actual instanceof ConstantExpression && expected.getExpression() instanceof Literal && expected.getType().equals(actual.getType().toString())) {
        Literal literal = (Literal) expected.getExpression();
        if (literal instanceof StringLiteral) {
            Object value = LiteralInterpreter.evaluate((ConstantExpression) actual);
            String actualString = value instanceof Slice ? ((Slice) value).toStringUtf8() : String.valueOf(value);
            return ((StringLiteral) literal).getValue().equals(actualString);
        }
        return getValueFromLiteral(literal).equals(String.valueOf(LiteralInterpreter.evaluate((ConstantExpression) actual)));
    }
    if (actual instanceof VariableReferenceExpression && expected.getExpression() instanceof SymbolReference && expected.getType().equals(actual.getType().toString())) {
        return visitSymbolReference((SymbolReference) expected.getExpression(), actual);
    }
    if (!(actual instanceof CallExpression) || !functionResolution.isCastFunction(((CallExpression) actual).getFunctionHandle())) {
        return false;
    }
    if (!expected.getType().equalsIgnoreCase(actual.getType().toString()) && !(expected.getType().toLowerCase(ENGLISH).equals(VARCHAR) && actual.getType().getTypeSignature().getBase().equals(VARCHAR))) {
        return false;
    }
    return process(expected.getExpression(), ((CallExpression) actual).getArguments().get(0));
}
Also used : StringLiteral(io.prestosql.sql.tree.StringLiteral) Slice(io.airlift.slice.Slice) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) SymbolReference(io.prestosql.sql.tree.SymbolReference) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) NullLiteral(io.prestosql.sql.tree.NullLiteral) DoubleLiteral(io.prestosql.sql.tree.DoubleLiteral) GenericLiteral(io.prestosql.sql.tree.GenericLiteral) LongLiteral(io.prestosql.sql.tree.LongLiteral) StringLiteral(io.prestosql.sql.tree.StringLiteral) Literal(io.prestosql.sql.tree.Literal) DecimalLiteral(io.prestosql.sql.tree.DecimalLiteral) BooleanLiteral(io.prestosql.sql.tree.BooleanLiteral) CallExpression(io.prestosql.spi.relation.CallExpression)

Example 4 with CallExpression

use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.

the class TestExpressionOptimizer method testIfConstantOptimization.

@Test
public void testIfConstantOptimization() {
    assertEquals(optimizer.optimize(ifExpression(constant(true, BOOLEAN), 1L, 2L)), constant(1L, BIGINT));
    assertEquals(optimizer.optimize(ifExpression(constant(false, BOOLEAN), 1L, 2L)), constant(2L, BIGINT));
    assertEquals(optimizer.optimize(ifExpression(constant(null, BOOLEAN), 1L, 2L)), constant(2L, BIGINT));
    FunctionHandle bigintEquals = functionAndTypeManager.resolveOperatorFunctionHandle(EQUAL, fromTypes(BIGINT, BIGINT));
    RowExpression condition = new CallExpression(EQUAL.name(), bigintEquals, BOOLEAN, ImmutableList.of(constant(3L, BIGINT), constant(3L, BIGINT)), Optional.empty());
    assertEquals(optimizer.optimize(ifExpression(condition, 1L, 2L)), constant(1L, BIGINT));
}
Also used : RowExpression(io.prestosql.spi.relation.RowExpression) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) FunctionHandle(io.prestosql.spi.function.FunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Example 5 with CallExpression

use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.

the class TestExpressionOptimizer method testCastWithJsonParseOptimization.

@Test
public void testCastWithJsonParseOptimization() {
    FunctionHandle jsonParseFunctionHandle = functionAndTypeManager.lookupFunction("json_parse", fromTypes(VARCHAR));
    // constant
    FunctionHandle jsonCastFunctionHandle = functionAndTypeManager.lookupCast(CAST, JSON.getTypeSignature(), parseTypeSignature("array(integer)"));
    RowExpression jsonCastExpression = new CallExpression(CAST.name(), jsonCastFunctionHandle, new ArrayType(INTEGER), ImmutableList.of(call("json_parse", jsonParseFunctionHandle, JSON, constant(utf8Slice("[1, 2]"), VARCHAR))), Optional.empty());
    RowExpression resultExpression = optimizer.optimize(jsonCastExpression);
    assertInstanceOf(resultExpression, ConstantExpression.class);
    Object resultValue = ((ConstantExpression) resultExpression).getValue();
    assertInstanceOf(resultValue, IntArrayBlock.class);
    assertEquals(toValues(INTEGER, (IntArrayBlock) resultValue), ImmutableList.of(1, 2));
    // varchar to array
    jsonCastFunctionHandle = functionAndTypeManager.lookupCast(CAST, JSON.getTypeSignature(), parseTypeSignature("array(varchar)"));
    jsonCastExpression = call(CAST.name(), jsonCastFunctionHandle, new ArrayType(VARCHAR), ImmutableList.of(call("json_parse", jsonParseFunctionHandle, JSON, field(1, VARCHAR))));
    resultExpression = optimizer.optimize(jsonCastExpression);
    assertEquals(resultExpression, call(JSON_TO_ARRAY_CAST.name(), functionAndTypeManager.lookupCast(JSON_TO_ARRAY_CAST, VARCHAR.getTypeSignature(), parseTypeSignature("array(varchar)")), new ArrayType(VARCHAR), field(1, VARCHAR)));
    // varchar to row
    jsonCastFunctionHandle = functionAndTypeManager.lookupCast(CAST, JSON.getTypeSignature(), parseTypeSignature("row(varchar,bigint)"));
    jsonCastExpression = call(CAST.name(), jsonCastFunctionHandle, RowType.anonymous(ImmutableList.of(VARCHAR, BIGINT)), ImmutableList.of(call("json_parse", jsonParseFunctionHandle, JSON, field(1, VARCHAR))));
    resultExpression = optimizer.optimize(jsonCastExpression);
    assertEquals(resultExpression, call(JSON_TO_ROW_CAST.name(), functionAndTypeManager.lookupCast(JSON_TO_ROW_CAST, VARCHAR.getTypeSignature(), parseTypeSignature("row(varchar,bigint)")), RowType.anonymous(ImmutableList.of(VARCHAR, BIGINT)), field(1, VARCHAR)));
    // varchar to map
    jsonCastFunctionHandle = functionAndTypeManager.lookupCast(CAST, JSON.getTypeSignature(), parseTypeSignature("map(integer,varchar)"));
    jsonCastExpression = call(CAST.name(), jsonCastFunctionHandle, mapType(INTEGER, VARCHAR), ImmutableList.of(call("json_parse", jsonParseFunctionHandle, JSON, field(1, VARCHAR))));
    resultExpression = optimizer.optimize(jsonCastExpression);
    assertEquals(resultExpression, call(JSON_TO_MAP_CAST.name(), functionAndTypeManager.lookupCast(JSON_TO_MAP_CAST, VARCHAR.getTypeSignature(), parseTypeSignature("map(integer, varchar)")), mapType(INTEGER, VARCHAR), field(1, VARCHAR)));
}
Also used : ArrayType(io.prestosql.spi.type.ArrayType) IntArrayBlock(io.prestosql.spi.block.IntArrayBlock) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) RowExpression(io.prestosql.spi.relation.RowExpression) BuiltInFunctionHandle(io.prestosql.spi.function.BuiltInFunctionHandle) FunctionHandle(io.prestosql.spi.function.FunctionHandle) CallExpression(io.prestosql.spi.relation.CallExpression) Test(org.testng.annotations.Test)

Aggregations

CallExpression (io.prestosql.spi.relation.CallExpression)69 RowExpression (io.prestosql.spi.relation.RowExpression)30 BuiltInFunctionHandle (io.prestosql.spi.function.BuiltInFunctionHandle)27 Symbol (io.prestosql.spi.plan.Symbol)24 Test (org.testng.annotations.Test)23 VariableReferenceExpression (io.prestosql.spi.relation.VariableReferenceExpression)22 FunctionHandle (io.prestosql.spi.function.FunctionHandle)19 Signature (io.prestosql.spi.function.Signature)19 AggregationNode (io.prestosql.spi.plan.AggregationNode)17 ConstantExpression (io.prestosql.spi.relation.ConstantExpression)17 Map (java.util.Map)17 OperatorType (io.prestosql.spi.function.OperatorType)16 ImmutableMap (com.google.common.collect.ImmutableMap)15 Type (io.prestosql.spi.type.Type)13 Optional (java.util.Optional)13 SpecialForm (io.prestosql.spi.relation.SpecialForm)12 List (java.util.List)12 PlanNode (io.prestosql.spi.plan.PlanNode)11 ImmutableList (com.google.common.collect.ImmutableList)10 ProjectNode (io.prestosql.spi.plan.ProjectNode)10