use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class CursorProcessorCompiler method fieldReferenceCompiler.
static RowExpressionVisitor<BytecodeNode, Scope> fieldReferenceCompiler(Map<VariableReferenceExpression, CommonSubExpressionFields> variableMap) {
return new RowExpressionVisitor<BytecodeNode, Scope>() {
@Override
public BytecodeNode visitInputReference(InputReferenceExpression node, Scope scope) {
int field = node.getField();
Type type = node.getType();
Variable wasNullVariable = scope.getVariable("wasNull");
Variable cursorVariable = scope.getVariable("cursor");
Class<?> javaType = type.getJavaType();
if (!javaType.isPrimitive() && javaType != Slice.class) {
javaType = Object.class;
}
IfStatement ifStatement = new IfStatement();
ifStatement.condition().setDescription(format("cursor.get%s(%d)", type, field)).getVariable(cursorVariable).push(field).invokeInterface(RecordCursor.class, "isNull", boolean.class, int.class);
ifStatement.ifTrue().putVariable(wasNullVariable, true).pushJavaDefault(javaType);
ifStatement.ifFalse().getVariable(cursorVariable).push(field).invokeInterface(RecordCursor.class, "get" + Primitives.wrap(javaType).getSimpleName(), javaType, int.class);
return ifStatement;
}
@Override
public BytecodeNode visitCall(CallExpression call, Scope scope) {
throw new UnsupportedOperationException("not yet implemented");
}
@Override
public BytecodeNode visitConstant(ConstantExpression literal, Scope scope) {
throw new UnsupportedOperationException("not yet implemented");
}
@Override
public BytecodeNode visitLambda(LambdaDefinitionExpression lambda, Scope context) {
throw new UnsupportedOperationException();
}
@Override
public BytecodeNode visitVariableReference(VariableReferenceExpression reference, Scope context) {
CommonSubExpressionFields fields = variableMap.get(reference);
return new BytecodeBlock().append(context.getThis().invoke(fields.getMethodName(), fields.getResultType(), context.getVariable("properties"), context.getVariable("cursor"))).append(unboxPrimitiveIfNecessary(context, Primitives.wrap(reference.getType().getJavaType())));
}
@Override
public BytecodeNode visitSpecialForm(SpecialFormExpression specialForm, Scope context) {
throw new UnsupportedOperationException();
}
};
}
use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class TestPageProcessorCompiler method testSanityFilterOnRLE.
@Test
public void testSanityFilterOnRLE() {
FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
FunctionHandle lessThan = functionAndTypeManager.resolveOperator(LESS_THAN, fromTypes(BIGINT, BIGINT));
CallExpression filter = new CallExpression(LESS_THAN.name(), lessThan, BOOLEAN, ImmutableList.of(field(0, BIGINT), constant(10L, BIGINT)));
PageProcessor processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.of(filter), ImmutableList.of(field(0, BIGINT)), false, MAX_BATCH_SIZE).get();
Page page = new Page(createRLEBlock(5L, 100));
Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
assertEquals(outputPage.getPositionCount(), 100);
assertTrue(outputPage.getBlock(0) instanceof RunLengthEncodedBlock);
RunLengthEncodedBlock rle = (RunLengthEncodedBlock) outputPage.getBlock(0);
assertEquals(BIGINT.getLong(rle.getValue(), 0), 5L);
}
use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class TestPageProcessorCompiler method testNoCaching.
@Test
public void testNoCaching() {
FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
ImmutableList.Builder<RowExpression> projectionsBuilder = ImmutableList.builder();
ArrayType arrayType = new ArrayType(VARCHAR);
FunctionHandle functionHandle = functionAndTypeManager.lookupFunction("concat", fromTypes(arrayType, arrayType));
projectionsBuilder.add(new CallExpression("concat", functionHandle, arrayType, ImmutableList.of(field(0, arrayType), field(1, arrayType))));
ImmutableList<RowExpression> projections = projectionsBuilder.build();
PageProcessor pageProcessor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.empty(), projections).get();
PageProcessor pageProcessor2 = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.empty(), projections).get();
assertTrue(pageProcessor != pageProcessor2);
}
use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class TestPageProcessorCompiler method testNonDeterministicProject.
@Test
public void testNonDeterministicProject() {
FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
FunctionHandle lessThan = functionAndTypeManager.resolveOperator(LESS_THAN, fromTypes(BIGINT, BIGINT));
CallExpression random = new CallExpression("random", functionAndTypeManager.lookupFunction("random", fromTypes(BIGINT)), BIGINT, singletonList(constant(10L, BIGINT)));
InputReferenceExpression col0 = field(0, BIGINT);
CallExpression lessThanRandomExpression = new CallExpression(LESS_THAN.name(), lessThan, BOOLEAN, ImmutableList.of(col0, random));
PageProcessor processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.empty(), ImmutableList.of(lessThanRandomExpression), false, MAX_BATCH_SIZE).get();
assertFalse(new RowExpressionDeterminismEvaluator(metadataManager.getFunctionAndTypeManager()).isDeterministic(lessThanRandomExpression));
Page page = new Page(createLongDictionaryBlock(1, 100));
Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
assertFalse(outputPage.getBlock(0) instanceof DictionaryBlock);
}
use of com.facebook.presto.spi.relation.CallExpression in project presto by prestodb.
the class TestWindowNode method testSerializationRoundtrip.
@Test
public void testSerializationRoundtrip() {
VariableReferenceExpression windowVariable = variableAllocator.newVariable("sum", BIGINT);
FunctionHandle functionHandle = createTestMetadataManager().getFunctionAndTypeManager().lookupFunction("sum", fromTypes(BIGINT));
WindowNode.Frame frame = new WindowNode.Frame(RANGE, UNBOUNDED_PRECEDING, Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty());
PlanNodeId id = newId();
WindowNode.Specification specification = new WindowNode.Specification(ImmutableList.of(columnA), Optional.of(new OrderingScheme(ImmutableList.of(new Ordering(columnB, SortOrder.ASC_NULLS_FIRST)))));
CallExpression call = call("sum", functionHandle, BIGINT, new VariableReferenceExpression(Optional.empty(), columnC.getName(), BIGINT));
Map<VariableReferenceExpression, WindowNode.Function> functions = ImmutableMap.of(windowVariable, new WindowNode.Function(call, frame, false));
Optional<VariableReferenceExpression> hashVariable = Optional.of(columnB);
Set<VariableReferenceExpression> prePartitionedInputs = ImmutableSet.of(columnA);
WindowNode windowNode = new WindowNode(Optional.empty(), id, sourceNode, specification, functions, hashVariable, prePartitionedInputs, 0);
String json = codec.toJson(windowNode);
WindowNode actualNode = codec.fromJson(json);
assertEquals(actualNode.getId(), windowNode.getId());
assertEquals(actualNode.getSpecification(), windowNode.getSpecification());
assertEquals(actualNode.getWindowFunctions(), windowNode.getWindowFunctions());
assertEquals(actualNode.getFrames(), windowNode.getFrames());
assertEquals(actualNode.getHashVariable(), windowNode.getHashVariable());
assertEquals(actualNode.getPrePartitionedInputs(), windowNode.getPrePartitionedInputs());
assertEquals(actualNode.getPreSortedOrderPrefix(), windowNode.getPreSortedOrderPrefix());
}
Aggregations