use of com.facebook.presto.common.function.OperatorType in project presto by prestodb.
the class RowExpressionVerifier method visitComparisonExpression.
@Override
protected Boolean visitComparisonExpression(ComparisonExpression expected, RowExpression actual) {
if (actual instanceof CallExpression) {
FunctionMetadata functionMetadata = metadata.getFunctionAndTypeManager().getFunctionMetadata(((CallExpression) actual).getFunctionHandle());
if (!functionMetadata.getOperatorType().isPresent() || !functionMetadata.getOperatorType().get().isComparisonOperator()) {
return false;
}
OperatorType actualOperatorType = functionMetadata.getOperatorType().get();
OperatorType expectedOperatorType = getOperatorType(expected.getOperator());
if (expectedOperatorType.equals(actualOperatorType)) {
if (actualOperatorType == EQUAL) {
return (process(expected.getLeft(), ((CallExpression) actual).getArguments().get(0)) && process(expected.getRight(), ((CallExpression) actual).getArguments().get(1))) || (process(expected.getLeft(), ((CallExpression) actual).getArguments().get(1)) && process(expected.getRight(), ((CallExpression) actual).getArguments().get(0)));
}
// TODO support other comparison operators
return process(expected.getLeft(), ((CallExpression) actual).getArguments().get(0)) && process(expected.getRight(), ((CallExpression) actual).getArguments().get(1));
}
}
return false;
}
use of com.facebook.presto.common.function.OperatorType in project presto by prestodb.
the class FunctionsParserHelper method createTypeVariableConstraints.
public static List<TypeVariableConstraint> createTypeVariableConstraints(Iterable<TypeParameter> typeParameters, List<ImplementationDependency> dependencies) {
Set<String> orderableRequired = new HashSet<>();
Set<String> comparableRequired = new HashSet<>();
for (ImplementationDependency dependency : dependencies) {
if (dependency instanceof OperatorImplementationDependency) {
OperatorType operator = ((OperatorImplementationDependency) dependency).getOperator();
if (operator == CAST) {
continue;
}
Set<String> argumentTypes = ((OperatorImplementationDependency) dependency).getArgumentTypes().stream().map(TypeSignature::getBase).collect(toImmutableSet());
checkArgument(argumentTypes.size() == 1, "Operator dependency must only have arguments of a single type");
String argumentType = Iterables.getOnlyElement(argumentTypes);
if (COMPARABLE_TYPE_OPERATORS.contains(operator)) {
comparableRequired.add(argumentType);
}
if (ORDERABLE_TYPE_OPERATORS.contains(operator)) {
orderableRequired.add(argumentType);
}
}
}
ImmutableList.Builder<TypeVariableConstraint> typeVariableConstraints = ImmutableList.builder();
for (TypeParameter typeParameter : typeParameters) {
String name = typeParameter.value();
String variadicBound = typeParameter.boundedBy().isEmpty() ? null : typeParameter.boundedBy();
checkArgument(variadicBound == null || PARAMETRIC_TYPES.contains(variadicBound), "boundedBy must be a parametric type, got %s", variadicBound);
if (orderableRequired.contains(name)) {
typeVariableConstraints.add(new TypeVariableConstraint(name, false, true, variadicBound, false));
} else if (comparableRequired.contains(name)) {
typeVariableConstraints.add(new TypeVariableConstraint(name, true, false, variadicBound, false));
} else {
typeVariableConstraints.add(new TypeVariableConstraint(name, false, false, variadicBound, false));
}
}
return typeVariableConstraints.build();
}
use of com.facebook.presto.common.function.OperatorType in project presto by prestodb.
the class PinotFilterExpressionConverter method visitCall.
@Override
public PinotExpression visitCall(CallExpression call, Function<VariableReferenceExpression, Selection> context) {
FunctionHandle functionHandle = call.getFunctionHandle();
if (standardFunctionResolution.isNotFunction(functionHandle)) {
return handleNot(call, context);
}
if (standardFunctionResolution.isCastFunction(functionHandle)) {
return handleCast(call, context);
}
if (standardFunctionResolution.isBetweenFunction(functionHandle)) {
return handleBetween(call, context);
}
FunctionMetadata functionMetadata = functionMetadataManager.getFunctionMetadata(call.getFunctionHandle());
Optional<OperatorType> operatorTypeOptional = functionMetadata.getOperatorType();
if (operatorTypeOptional.isPresent()) {
OperatorType operatorType = operatorTypeOptional.get();
if (operatorType.isArithmeticOperator()) {
throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), "Arithmetic expressions are not supported in filter: " + call);
}
if (operatorType.isComparisonOperator()) {
return handleLogicalBinary(operatorType.getOperator(), call, context);
}
}
if ("contains".equals(functionMetadata.getName().getObjectName())) {
return handleContains(call, context);
}
// Otherwise TypeManager.canCoerce(...) will return false and directly fail this query.
if (functionMetadata.getName().getObjectName().equalsIgnoreCase("$literal$timestamp") || functionMetadata.getName().getObjectName().equalsIgnoreCase("$literal$date")) {
return handleDateAndTimestampMagicLiteralFunction(call, context);
}
throw new PinotException(PINOT_UNSUPPORTED_EXPRESSION, Optional.empty(), format("function %s not supported in filter", call));
}
Aggregations