Search in sources :

Example 41 with FunctionHandle

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);
}
Also used : SqlFunctionHandle(com.facebook.presto.spi.function.SqlFunctionHandle) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) Test(org.testng.annotations.Test)

Example 42 with FunctionHandle

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);
}
Also used : TableStatisticType(com.facebook.presto.spi.statistics.TableStatisticType) Type(com.facebook.presto.common.type.Type) ColumnStatisticType(com.facebook.presto.spi.statistics.ColumnStatisticType) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) CallExpression(com.facebook.presto.spi.relation.CallExpression)

Example 43 with FunctionHandle

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")))));
}
Also used : BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) PlanMatchPattern.project(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.project) SortOrder(com.facebook.presto.common.block.SortOrder) WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) ImmutableMap(com.google.common.collect.ImmutableMap) Ordering(com.facebook.presto.spi.plan.Ordering) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) PlanMatchPattern.output(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.output) Assignments(com.facebook.presto.spi.plan.Assignments) Test(org.testng.annotations.Test) Expressions.call(com.facebook.presto.sql.relational.Expressions.call) OptimizerAssert(com.facebook.presto.sql.planner.assertions.OptimizerAssert) RANGE(com.facebook.presto.sql.planner.plan.WindowNode.Frame.WindowType.RANGE) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest) ImmutableList(com.google.common.collect.ImmutableList) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) Optional(java.util.Optional) PlanMatchPattern.values(com.facebook.presto.sql.planner.assertions.PlanMatchPattern.values) CallExpression(com.facebook.presto.spi.relation.CallExpression) UNBOUNDED_PRECEDING(com.facebook.presto.sql.planner.plan.WindowNode.Frame.BoundType.UNBOUNDED_PRECEDING) OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) UNBOUNDED_FOLLOWING(com.facebook.presto.sql.planner.plan.WindowNode.Frame.BoundType.UNBOUNDED_FOLLOWING) RuleTester(com.facebook.presto.sql.planner.iterative.rule.test.RuleTester) WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) Ordering(com.facebook.presto.spi.plan.Ordering) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) CallExpression(com.facebook.presto.spi.relation.CallExpression) Test(org.testng.annotations.Test) BaseRuleTest(com.facebook.presto.sql.planner.iterative.rule.test.BaseRuleTest)

Example 44 with FunctionHandle

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));
}
Also used : FunctionMetadata(com.facebook.presto.spi.function.FunctionMetadata) PinotException(com.facebook.presto.pinot.PinotException) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) OperatorType(com.facebook.presto.common.function.OperatorType)

Aggregations

FunctionHandle (com.facebook.presto.spi.function.FunctionHandle)44 Test (org.testng.annotations.Test)20 CallExpression (com.facebook.presto.spi.relation.CallExpression)16 Type (com.facebook.presto.common.type.Type)14 RowExpression (com.facebook.presto.spi.relation.RowExpression)13 FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)9 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)9 ImmutableList (com.google.common.collect.ImmutableList)8 Variable (com.facebook.presto.bytecode.Variable)7 JavaScalarFunctionImplementation (com.facebook.presto.spi.function.JavaScalarFunctionImplementation)7 BytecodeBlock (com.facebook.presto.bytecode.BytecodeBlock)6 IfStatement (com.facebook.presto.bytecode.control.IfStatement)6 Page (com.facebook.presto.common.Page)6 ArrayType (com.facebook.presto.common.type.ArrayType)6 Map (java.util.Map)6 BytecodeNode (com.facebook.presto.bytecode.BytecodeNode)5 Scope (com.facebook.presto.bytecode.Scope)5 FunctionMetadata (com.facebook.presto.spi.function.FunctionMetadata)5 LabelNode (com.facebook.presto.bytecode.instruction.LabelNode)4 MapType (com.facebook.presto.common.type.MapType)4