use of io.prestosql.spi.function.OperatorType 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.function.OperatorType 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.function.OperatorType in project hetu-core by openlookeng.
the class AbstractGreatestLeast method specialize.
@Override
public BuiltInScalarFunctionImplementation specialize(BoundVariables boundVariables, int arity, FunctionAndTypeManager functionAndTypeManager) {
Type type = boundVariables.getTypeVariable("E");
checkArgument(type.isOrderable(), "Type must be orderable");
MethodHandle compareMethod = functionAndTypeManager.getBuiltInScalarFunctionImplementation(functionAndTypeManager.resolveOperatorFunctionHandle(operatorType, TypeSignatureProvider.fromTypes(type, type))).getMethodHandle();
List<Class<?>> javaTypes = IntStream.range(0, arity).mapToObj(i -> type.getJavaType()).collect(toImmutableList());
Class<?> clazz = generate(javaTypes, type, compareMethod);
MethodHandle methodHandle = methodHandle(clazz, getSignature().getNameSuffix(), javaTypes.toArray(new Class<?>[javaTypes.size()]));
return new BuiltInScalarFunctionImplementation(false, nCopies(javaTypes.size(), valueTypeArgumentProperty(RETURN_NULL_ON_NULL)), methodHandle);
}
use of io.prestosql.spi.function.OperatorType 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.function.OperatorType in project hetu-core by openlookeng.
the class BuiltInFunctionNamespaceManager method getFunctionMetadata.
@Override
public FunctionMetadata getFunctionMetadata(FunctionHandle functionHandle) {
checkArgument(functionHandle instanceof BuiltInFunctionHandle, "Expect BuiltInFunctionHandle");
Signature signature = ((BuiltInFunctionHandle) functionHandle).getSignature();
SpecializedFunctionKey functionKey;
try {
functionKey = specializedFunctionKeyCache.getUnchecked(signature);
} catch (UncheckedExecutionException e) {
throwIfInstanceOf(e.getCause(), PrestoException.class);
throw e;
}
SqlFunction function = functionKey.getFunction();
Optional<OperatorType> operatorType = OperatorType.tryGetOperatorType(signature.getName());
if (operatorType.isPresent()) {
return new FunctionMetadata(operatorType.get(), signature.getArgumentTypes(), signature.getReturnType(), signature.getKind(), BUILTIN, function.isDeterministic(), function.isCalledOnNullInput());
} else {
return new FunctionMetadata(signature.getName(), signature.getArgumentTypes(), signature.getReturnType(), signature.getKind(), BUILTIN, function.isDeterministic(), function.isCalledOnNullInput());
}
}
Aggregations