use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class TestVerifyNoOriginalExpression method setup.
@BeforeClass
public void setup() {
metadata = getQueryRunner().getMetadata();
builder = new PlanBuilder(TEST_SESSION, new PlanNodeIdAllocator(), metadata);
valuesNode = builder.values();
comparisonCallExpression = new CallExpression("LESS_THAN", metadata.getFunctionAndTypeManager().resolveOperator(LESS_THAN, fromTypes(BIGINT, BIGINT)), BooleanType.BOOLEAN, ImmutableList.of(VARIABLE_REFERENCE_EXPRESSION, VARIABLE_REFERENCE_EXPRESSION));
}
use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class TestRowExpressionOptimizer method testPossibleExponentialOptimizationTime.
@Test(timeOut = 10_000)
public void testPossibleExponentialOptimizationTime() {
RowExpression expression = constant(1L, BIGINT);
for (int i = 0; i < 100; i++) {
FunctionHandle functionHandle = functionAndTypeManager.resolveOperator(ADD, fromTypes(BIGINT, BIGINT));
expression = new CallExpression(ADD.name(), functionHandle, BIGINT, ImmutableList.of(expression, constant(1L, BIGINT)));
}
optimize(expression);
}
use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class TestRowExpressionOptimizer 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))));
RowExpression resultExpression = 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 = 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 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 = 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)));
// 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 = 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)));
}
use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class TestRowExpressionOptimizer method testIfConstantOptimization.
@Test
public void testIfConstantOptimization() {
assertEquals(optimize(ifExpression(constant(true, BOOLEAN), 1L, 2L)), constant(1L, BIGINT));
assertEquals(optimize(ifExpression(constant(false, BOOLEAN), 1L, 2L)), constant(2L, BIGINT));
assertEquals(optimize(ifExpression(constant(null, BOOLEAN), 1L, 2L)), constant(2L, BIGINT));
FunctionHandle bigintEquals = functionAndTypeManager.resolveOperator(EQUAL, fromTypes(BIGINT, BIGINT));
RowExpression condition = new CallExpression(EQUAL.name(), bigintEquals, BOOLEAN, ImmutableList.of(constant(3L, BIGINT), constant(3L, BIGINT)));
assertEquals(optimize(ifExpression(condition, 1L, 2L)), constant(1L, BIGINT));
}
use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class TestDeterminismEvaluator method testDeterminismEvaluator.
@Test
public void testDeterminismEvaluator() {
FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
RowExpressionDeterminismEvaluator determinismEvaluator = new RowExpressionDeterminismEvaluator(functionAndTypeManager);
CallExpression random = new CallExpression("random", functionAndTypeManager.lookupFunction("random", fromTypes(BIGINT)), BIGINT, singletonList(constant(10L, BIGINT)));
assertFalse(determinismEvaluator.isDeterministic(random));
InputReferenceExpression col0 = field(0, BIGINT);
FunctionHandle lessThan = functionAndTypeManager.resolveOperator(LESS_THAN, fromTypes(BIGINT, BIGINT));
CallExpression lessThanExpression = new CallExpression(LESS_THAN.name(), lessThan, BOOLEAN, ImmutableList.of(col0, constant(10L, BIGINT)));
assertTrue(determinismEvaluator.isDeterministic(lessThanExpression));
CallExpression lessThanRandomExpression = new CallExpression(LESS_THAN.name(), lessThan, BOOLEAN, ImmutableList.of(col0, random));
assertFalse(determinismEvaluator.isDeterministic(lessThanRandomExpression));
}
Aggregations