use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.
the class CursorProcessorCompiler method fieldReferenceCompiler.
private static RowExpressionVisitor<BytecodeNode, Scope> fieldReferenceCompiler(Variable cursorVariable) {
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");
Class<?> javaType = type.getJavaType();
if (!javaType.isPrimitive() && javaType != Slice.class) {
javaType = Object.class;
}
IfStatement ifStatement = new IfStatement();
ifStatement.condition().setDescription(String.format(Locale.ROOT, "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 visitSpecialForm(SpecialForm specialForm, Scope context) {
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) {
throw new UnsupportedOperationException();
}
};
}
use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.
the class IndexServiceUtils method matchCallExpEqual.
public static boolean matchCallExpEqual(Object expression, Function<Object, Boolean> matchingFunction) {
if (expression instanceof CallExpression) {
CallExpression callExp = (CallExpression) expression;
BuiltInFunctionHandle builtInFunctionHandle;
if (callExp.getFunctionHandle() instanceof BuiltInFunctionHandle) {
builtInFunctionHandle = (BuiltInFunctionHandle) callExp.getFunctionHandle();
} else {
throw new UnsupportedOperationException("Unsupported function: " + callExp.getDisplayName());
}
Optional<OperatorType> operatorOptional = Signature.getOperatorType(builtInFunctionHandle.getSignature().getNameSuffix());
Object value = extractValueFromRowExpression(callExp.getArguments().get(1));
if (operatorOptional.isPresent() && operatorOptional.get() == EQUAL) {
return matchingFunction.apply(value);
}
return true;
}
return true;
}
use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.
the class MinMaxIndex method matches.
@Override
public boolean matches(Object expression) {
if (expression instanceof CallExpression) {
CallExpression callExp = (CallExpression) expression;
BuiltInFunctionHandle builtInFunctionHandle;
if (callExp.getFunctionHandle() instanceof BuiltInFunctionHandle) {
builtInFunctionHandle = (BuiltInFunctionHandle) callExp.getFunctionHandle();
} else {
throw new UnsupportedOperationException("Unsupported function: " + callExp.getDisplayName());
}
Optional<OperatorType> operatorOptional = Signature.getOperatorType(builtInFunctionHandle.getSignature().getNameSuffix());
if (operatorOptional.isPresent()) {
OperatorType operator = operatorOptional.get();
Comparable value = (Comparable) extractValueFromRowExpression(callExp.getArguments().get(1));
switch(operator) {
case EQUAL:
return (value.compareTo(min) >= 0) && (value.compareTo(max) <= 0);
case LESS_THAN:
return value.compareTo(min) > 0;
case LESS_THAN_OR_EQUAL:
return value.compareTo(min) >= 0;
case GREATER_THAN:
return value.compareTo(max) < 0;
case GREATER_THAN_OR_EQUAL:
return value.compareTo(max) <= 0;
default:
throw new UnsupportedOperationException("Unsupported operator " + operator);
}
}
}
// Not supported expression. Don't filter out
return true;
}
use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.
the class ExtractSpatialJoins method tryCreateSpatialJoin.
private static Result tryCreateSpatialJoin(Context context, JoinNode joinNode, RowExpression filter, PlanNodeId nodeId, List<Symbol> outputSymbols, CallExpression spatialComparison, Metadata metadata, SplitManager splitManager, PageSourceManager pageSourceManager, TypeAnalyzer typeAnalyzer) {
FunctionMetadata spatialComparisonMetadata = metadata.getFunctionAndTypeManager().getFunctionMetadata(spatialComparison.getFunctionHandle());
checkArgument(spatialComparison.getArguments().size() == 2 && spatialComparisonMetadata.getOperatorType().isPresent());
PlanNode leftNode = joinNode.getLeft();
PlanNode rightNode = joinNode.getRight();
List<Symbol> leftSymbols = leftNode.getOutputSymbols();
List<Symbol> rightSymbols = rightNode.getOutputSymbols();
RowExpression radius;
Optional<Symbol> newRadiusSymbol;
CallExpression newComparison;
OperatorType operatorType = spatialComparisonMetadata.getOperatorType().get();
if (operatorType.equals(OperatorType.LESS_THAN) || operatorType.equals(OperatorType.LESS_THAN_OR_EQUAL)) {
// ST_Distance(a, b) <= r
radius = spatialComparison.getArguments().get(1);
Set<Symbol> radiusSymbols = extractUnique(radius);
if (radiusSymbols.isEmpty() || (rightSymbols.containsAll(radiusSymbols) && containsNone(leftSymbols, radiusSymbols))) {
newRadiusSymbol = newRadiusSymbol(context, radius);
newComparison = new CallExpression(spatialComparison.getDisplayName(), spatialComparison.getFunctionHandle(), spatialComparison.getType(), ImmutableList.of(spatialComparison.getArguments().get(0), mapToExpression(newRadiusSymbol, radius, context)), Optional.empty());
} else {
return Result.empty();
}
} else {
// r >= ST_Distance(a, b)
radius = spatialComparison.getArguments().get(0);
Set<Symbol> radiusSymbols = extractUnique(radius);
if (radiusSymbols.isEmpty() || (rightSymbols.containsAll(radiusSymbols) && containsNone(leftSymbols, radiusSymbols))) {
OperatorType newOperatorType = SpatialJoinUtils.flip(operatorType);
FunctionHandle flippedHandle = getFlippedFunctionHandle(spatialComparison, metadata.getFunctionAndTypeManager());
newRadiusSymbol = newRadiusSymbol(context, radius);
newComparison = new CallExpression(newOperatorType.name(), flippedHandle, spatialComparison.getType(), ImmutableList.of(spatialComparison.getArguments().get(1), mapToExpression(newRadiusSymbol, radius, context)), Optional.empty());
} else {
return Result.empty();
}
}
RowExpression newFilter = replaceExpression(filter, ImmutableMap.of(spatialComparison, newComparison));
PlanNode newRightNode = newRadiusSymbol.map(symbol -> addProjection(context, rightNode, symbol, radius)).orElse(rightNode);
JoinNode newJoinNode = new JoinNode(joinNode.getId(), joinNode.getType(), leftNode, newRightNode, joinNode.getCriteria(), joinNode.getOutputSymbols(), Optional.of(newFilter), joinNode.getLeftHashSymbol(), joinNode.getRightHashSymbol(), joinNode.getDistributionType(), joinNode.isSpillable(), joinNode.getDynamicFilters());
return tryCreateSpatialJoin(context, newJoinNode, newFilter, nodeId, outputSymbols, (CallExpression) newComparison.getArguments().get(0), Optional.of(newComparison.getArguments().get(1)), metadata, splitManager, pageSourceManager, typeAnalyzer);
}
use of io.prestosql.spi.relation.CallExpression in project hetu-core by openlookeng.
the class TestPageProcessorCompiler method testNonDeterministicProject.
@Test
public void testNonDeterministicProject() {
Signature lessThan = internalOperator(LESS_THAN, BOOLEAN, ImmutableList.of(BIGINT, BIGINT));
CallExpression random = new CallExpression(QualifiedObjectName.valueOfDefaultFunction("random").getObjectName(), new BuiltInFunctionHandle(new Signature(QualifiedObjectName.valueOfDefaultFunction("random"), SCALAR, parseTypeSignature(StandardTypes.BIGINT), parseTypeSignature(StandardTypes.BIGINT))), BIGINT, singletonList(constant(10L, BIGINT)), Optional.empty());
InputReferenceExpression col0 = field(0, BIGINT);
CallExpression lessThanRandomExpression = new CallExpression(lessThan.getName().getObjectName(), new BuiltInFunctionHandle(lessThan), BOOLEAN, ImmutableList.of(col0, random), Optional.empty());
PageProcessor processor = compiler.compilePageProcessor(Optional.empty(), ImmutableList.of(lessThanRandomExpression), MAX_BATCH_SIZE).get();
assertFalse(new RowExpressionDeterminismEvaluator(metadata).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);
}
Aggregations