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);
}
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;
}
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));
}
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));
}
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)));
}
Aggregations