use of com.facebook.presto.spi.function.FunctionHandle in project presto by prestodb.
the class TestMySqlFunctionNamespaceManager method testGetFunctionMetadata.
@Test
public void testGetFunctionMetadata() {
createFunction(FUNCTION_POWER_TOWER_DOUBLE, true);
FunctionHandle handle1 = getLatestFunctionHandle(FUNCTION_POWER_TOWER_DOUBLE.getFunctionId());
assertGetFunctionMetadata(handle1, FUNCTION_POWER_TOWER_DOUBLE);
createFunction(FUNCTION_POWER_TOWER_DOUBLE_UPDATED, true);
FunctionHandle handle2 = getLatestFunctionHandle(FUNCTION_POWER_TOWER_DOUBLE_UPDATED.getFunctionId());
assertGetFunctionMetadata(handle1, FUNCTION_POWER_TOWER_DOUBLE);
assertGetFunctionMetadata(handle2, FUNCTION_POWER_TOWER_DOUBLE_UPDATED);
}
use of com.facebook.presto.spi.function.FunctionHandle in project presto by prestodb.
the class StatisticsAggregationPlanner method createAggregation.
private ColumnStatisticsAggregation createAggregation(String functionName, RowExpression input, Type inputType, Type outputType) {
FunctionAndTypeManager functionAndTypeManager = metadata.getFunctionAndTypeManager();
FunctionHandle functionHandle = functionAndTypeManager.lookupFunction(functionName, TypeSignatureProvider.fromTypes(ImmutableList.of(inputType)));
Type resolvedType = metadata.getType(getOnlyElement(functionAndTypeManager.getFunctionMetadata(functionHandle).getArgumentTypes()));
verify(resolvedType.equals(inputType), "resolved function input type does not match the input type: %s != %s", resolvedType, inputType);
return new ColumnStatisticsAggregation(new AggregationNode.Aggregation(new CallExpression(input.getSourceLocation(), functionName, functionHandle, outputType, ImmutableList.of(input)), Optional.empty(), Optional.empty(), false, Optional.empty()), outputType);
}
use of com.facebook.presto.spi.function.FunctionHandle in project presto by prestodb.
the class TestPruneUnreferencedOutputs method windowNodePruning.
/**
* Test that the unreferenced output pruning works correctly when WindowNode is pruned as no downstream operators are consuming the window function output
*/
@Test
public void windowNodePruning() {
FunctionHandle functionHandle = createTestMetadataManager().getFunctionAndTypeManager().lookupFunction("rank", ImmutableList.of());
CallExpression call = call("rank", functionHandle, BIGINT);
WindowNode.Frame frame = new WindowNode.Frame(RANGE, UNBOUNDED_PRECEDING, Optional.empty(), UNBOUNDED_FOLLOWING, Optional.empty(), Optional.empty(), Optional.empty());
assertRuleApplication().on(p -> p.output(ImmutableList.of("user_uuid"), ImmutableList.of(p.variable("user_uuid", VARCHAR)), p.project(Assignments.of(p.variable("user_uuid", VARCHAR), p.variable("user_uuid", VARCHAR)), p.window(new WindowNode.Specification(ImmutableList.of(p.variable("user_uuid", VARCHAR)), Optional.of(new OrderingScheme(ImmutableList.of(new Ordering(p.variable("expr"), SortOrder.ASC_NULLS_LAST), new Ordering(p.variable("random"), SortOrder.ASC_NULLS_LAST))))), ImmutableMap.of(p.variable("rank"), new WindowNode.Function(call, frame, false)), p.project(Assignments.builder().put(p.variable("user_uuid", VARCHAR), p.variable("user_uuid", VARCHAR)).put(p.variable("expr", BIGINT), p.variable("expr", BIGINT)).put(p.variable("random", BIGINT), p.rowExpression("random()")).build(), p.values(p.variable("user_uuid", VARCHAR), p.variable("expr", BIGINT))))))).matches(output(project(project(values("user_uuid")))));
}
use of com.facebook.presto.spi.function.FunctionHandle 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