Search in sources :

Example 16 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class TestInlineSqlFunctions method setup.

@BeforeTest
public void setup() {
    RuleTester tester = new RuleTester();
    FunctionAndTypeManager functionAndTypeManager = tester.getMetadata().getFunctionAndTypeManager();
    functionAndTypeManager.addFunctionNamespace("unittest", new InMemoryFunctionNamespaceManager("unittest", new SqlFunctionExecutors(ImmutableMap.of(SQL, FunctionImplementationType.SQL, JAVA, THRIFT), new NoopSqlFunctionExecutor()), new SqlInvokedFunctionNamespaceManagerConfig().setSupportedFunctionLanguages("sql,java")));
    functionAndTypeManager.createFunction(SQL_FUNCTION_SQUARE, true);
    functionAndTypeManager.createFunction(THRIFT_FUNCTION_FOO, true);
    functionAndTypeManager.createFunction(SQL_FUNCTION_ADD_1_TO_INT_ARRAY, true);
    functionAndTypeManager.createFunction(SQL_FUNCTION_ADD_1_TO_BIGINT_ARRAY, true);
    this.tester = tester;
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) NoopSqlFunctionExecutor(com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor) RuleTester(com.facebook.presto.sql.planner.iterative.rule.test.RuleTester) SqlFunctionExecutors(com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors) InMemoryFunctionNamespaceManager(com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager) SqlInvokedFunctionNamespaceManagerConfig(com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig) BeforeTest(org.testng.annotations.BeforeTest)

Example 17 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class TestRewriteFilterWithExternalFunctionToProject method setup.

@BeforeClass
public void setup() {
    FunctionAndTypeManager functionAndTypeManager = getFunctionManager();
    functionAndTypeManager.addFunctionNamespace("unittest", new InMemoryFunctionNamespaceManager("unittest", new SqlFunctionExecutors(ImmutableMap.of(SQL, FunctionImplementationType.SQL, JAVA, THRIFT), new NoopSqlFunctionExecutor()), new SqlInvokedFunctionNamespaceManagerConfig().setSupportedFunctionLanguages("sql,java")));
    functionAndTypeManager.createFunction(FUNCTION_TANGENT, true);
    functionAndTypeManager.createFunction(FUNCTION_REMOTE_FOO, true);
}
Also used : FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) NoopSqlFunctionExecutor(com.facebook.presto.functionNamespace.execution.NoopSqlFunctionExecutor) SqlFunctionExecutors(com.facebook.presto.functionNamespace.execution.SqlFunctionExecutors) InMemoryFunctionNamespaceManager(com.facebook.presto.functionNamespace.testing.InMemoryFunctionNamespaceManager) SqlInvokedFunctionNamespaceManagerConfig(com.facebook.presto.functionNamespace.SqlInvokedFunctionNamespaceManagerConfig) BeforeClass(org.testng.annotations.BeforeClass)

Example 18 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class CountAggregationBenchmark method createOperatorFactories.

@Override
protected List<? extends OperatorFactory> createOperatorFactories() {
    OperatorFactory tableScanOperator = createTableScanOperator(0, new PlanNodeId("test"), "orders", "orderkey");
    FunctionAndTypeManager functionAndTypeManager = localQueryRunner.getMetadata().getFunctionAndTypeManager();
    InternalAggregationFunction countFunction = functionAndTypeManager.getAggregateFunctionImplementation(functionAndTypeManager.lookupFunction("count", fromTypes(BIGINT)));
    AggregationOperatorFactory aggregationOperator = new AggregationOperatorFactory(1, new PlanNodeId("test"), Step.SINGLE, ImmutableList.of(countFunction.bind(ImmutableList.of(0), Optional.empty())), false);
    return ImmutableList.of(tableScanOperator, aggregationOperator);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) OperatorFactory(com.facebook.presto.operator.OperatorFactory) AggregationOperatorFactory(com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory) AggregationOperatorFactory(com.facebook.presto.operator.AggregationOperator.AggregationOperatorFactory) InternalAggregationFunction(com.facebook.presto.operator.aggregation.InternalAggregationFunction)

Example 19 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class PlanPrinter method formatFragment.

private static String formatFragment(FunctionAndTypeManager functionAndTypeManager, Session session, PlanFragment fragment, Optional<StageInfo> stageInfo, Optional<Map<PlanNodeId, PlanNodeStats>> planNodeStats, boolean verbose) {
    StringBuilder builder = new StringBuilder();
    builder.append(format("Fragment %s [%s]\n", fragment.getId(), fragment.getPartitioning()));
    if (stageInfo.isPresent()) {
        StageExecutionStats stageExecutionStats = stageInfo.get().getLatestAttemptExecutionInfo().getStats();
        List<TaskInfo> tasks = stageInfo.get().getLatestAttemptExecutionInfo().getTasks();
        double avgPositionsPerTask = tasks.stream().mapToLong(task -> task.getStats().getProcessedInputPositions()).average().orElse(Double.NaN);
        double squaredDifferences = tasks.stream().mapToDouble(task -> Math.pow(task.getStats().getProcessedInputPositions() - avgPositionsPerTask, 2)).sum();
        double sdAmongTasks = Math.sqrt(squaredDifferences / tasks.size());
        builder.append(indentString(1)).append(format("CPU: %s, Scheduled: %s, Input: %s (%s); per task: avg.: %s std.dev.: %s, Output: %s (%s)\n", stageExecutionStats.getTotalCpuTime().convertToMostSuccinctTimeUnit(), stageExecutionStats.getTotalScheduledTime().convertToMostSuccinctTimeUnit(), formatPositions(stageExecutionStats.getProcessedInputPositions()), stageExecutionStats.getProcessedInputDataSize(), formatDouble(avgPositionsPerTask), formatDouble(sdAmongTasks), formatPositions(stageExecutionStats.getOutputPositions()), stageExecutionStats.getOutputDataSize()));
    }
    PartitioningScheme partitioningScheme = fragment.getPartitioningScheme();
    builder.append(indentString(1)).append(format("Output layout: [%s]\n", Joiner.on(", ").join(partitioningScheme.getOutputLayout())));
    builder.append(indentString(1));
    boolean replicateNullsAndAny = partitioningScheme.isReplicateNullsAndAny();
    if (replicateNullsAndAny) {
        builder.append(format("Output partitioning: %s (replicate nulls and any) [%s]%s\n", partitioningScheme.getPartitioning().getHandle(), Joiner.on(", ").join(partitioningScheme.getPartitioning().getArguments()), formatHash(partitioningScheme.getHashColumn())));
    } else {
        builder.append(format("Output partitioning: %s [%s]%s\n", partitioningScheme.getPartitioning().getHandle(), Joiner.on(", ").join(partitioningScheme.getPartitioning().getArguments()), formatHash(partitioningScheme.getHashColumn())));
    }
    builder.append(indentString(1)).append(format("Stage Execution Strategy: %s\n", fragment.getStageExecutionDescriptor().getStageExecutionStrategy()));
    TypeProvider typeProvider = TypeProvider.fromVariables(fragment.getVariables());
    builder.append(textLogicalPlan(fragment.getRoot(), typeProvider, Optional.of(fragment.getStageExecutionDescriptor()), functionAndTypeManager, fragment.getStatsAndCosts(), session, planNodeStats, 1, verbose)).append("\n");
    return builder.toString();
}
Also used : TaskInfo(com.facebook.presto.execution.TaskInfo) ValuesNode(com.facebook.presto.spi.plan.ValuesNode) StageInfo(com.facebook.presto.execution.StageInfo) StageExecutionDescriptor(com.facebook.presto.operator.StageExecutionDescriptor) Map(java.util.Map) IndexJoinNode(com.facebook.presto.sql.planner.plan.IndexJoinNode) PartitioningScheme(com.facebook.presto.sql.planner.PartitioningScheme) OrderingScheme(com.facebook.presto.spi.plan.OrderingScheme) StageExecutionStats(com.facebook.presto.execution.StageExecutionStats) StageInfo.getAllStages(com.facebook.presto.execution.StageInfo.getAllStages) InterpretedFunctionInvoker(com.facebook.presto.sql.InterpretedFunctionInvoker) LateralJoinNode(com.facebook.presto.sql.planner.plan.LateralJoinNode) RowNumberNode(com.facebook.presto.sql.planner.plan.RowNumberNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) TextRenderer.formatDouble(com.facebook.presto.sql.planner.planPrinter.TextRenderer.formatDouble) Set(java.util.Set) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) ConnectorSession(com.facebook.presto.spi.ConnectorSession) LimitNode(com.facebook.presto.spi.plan.LimitNode) Stream(java.util.stream.Stream) OperatorNotFoundException(com.facebook.presto.metadata.OperatorNotFoundException) ProjectNode(com.facebook.presto.spi.plan.ProjectNode) TextRenderer.indentString(com.facebook.presto.sql.planner.planPrinter.TextRenderer.indentString) ApplyNode(com.facebook.presto.sql.planner.plan.ApplyNode) AssignUniqueId(com.facebook.presto.sql.planner.plan.AssignUniqueId) CAST(com.facebook.presto.metadata.CastType.CAST) Joiner(com.google.common.base.Joiner) Iterables(com.google.common.collect.Iterables) SINGLE_DISTRIBUTION(com.facebook.presto.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION) Slice(io.airlift.slice.Slice) GroupIdNode(com.facebook.presto.sql.planner.plan.GroupIdNode) Assignments(com.facebook.presto.spi.plan.Assignments) DistinctLimitNode(com.facebook.presto.spi.plan.DistinctLimitNode) PlanCostEstimate(com.facebook.presto.cost.PlanCostEstimate) ArrayList(java.util.ArrayList) TableWriterMergeNode(com.facebook.presto.sql.planner.plan.TableWriterMergeNode) Lists(com.google.common.collect.Lists) LogicalRowExpressions(com.facebook.presto.expressions.LogicalRowExpressions) InternalPlanVisitor(com.facebook.presto.sql.planner.plan.InternalPlanVisitor) TableHandle(com.facebook.presto.spi.TableHandle) FunctionResolution(com.facebook.presto.sql.relational.FunctionResolution) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) Functions(com.google.common.base.Functions) PlanNodeStatsEstimate(com.facebook.presto.cost.PlanNodeStatsEstimate) WindowNode(com.facebook.presto.sql.planner.plan.WindowNode) Session(com.facebook.presto.Session) Domain(com.facebook.presto.common.predicate.Domain) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) SemiJoinNode(com.facebook.presto.sql.planner.plan.SemiJoinNode) TopNNode(com.facebook.presto.spi.plan.TopNNode) PlanNodeStatsSummarizer.aggregateStageStats(com.facebook.presto.sql.planner.planPrinter.PlanNodeStatsSummarizer.aggregateStageStats) TaskInfo(com.facebook.presto.execution.TaskInfo) DynamicFilters.extractDynamicFilters(com.facebook.presto.expressions.DynamicFilters.extractDynamicFilters) ExpressionTreeUtils.createSymbolReference(com.facebook.presto.sql.analyzer.ExpressionTreeUtils.createSymbolReference) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) IntersectNode(com.facebook.presto.spi.plan.IntersectNode) AggregationNode(com.facebook.presto.spi.plan.AggregationNode) ExplainAnalyzeNode(com.facebook.presto.sql.planner.plan.ExplainAnalyzeNode) SpatialJoinNode(com.facebook.presto.sql.planner.plan.SpatialJoinNode) RemoteSourceNode(com.facebook.presto.sql.planner.plan.RemoteSourceNode) SortNode(com.facebook.presto.sql.planner.plan.SortNode) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) MetadataDeleteNode(com.facebook.presto.sql.planner.plan.MetadataDeleteNode) TableWriterNode(com.facebook.presto.sql.planner.plan.TableWriterNode) Duration(io.airlift.units.Duration) GraphvizPrinter(com.facebook.presto.util.GraphvizPrinter) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) StatisticAggregations(com.facebook.presto.sql.planner.plan.StatisticAggregations) TopNRowNumberNode(com.facebook.presto.sql.planner.plan.TopNRowNumberNode) IndexSourceNode(com.facebook.presto.sql.planner.plan.IndexSourceNode) CallExpression(com.facebook.presto.spi.relation.CallExpression) OutputNode(com.facebook.presto.sql.planner.plan.OutputNode) ImmutableSet(com.google.common.collect.ImmutableSet) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Range(com.facebook.presto.common.predicate.Range) Preconditions.checkState(com.google.common.base.Preconditions.checkState) List(java.util.List) SampleNode(com.facebook.presto.sql.planner.plan.SampleNode) Optional(java.util.Optional) JoinNodeUtils(com.facebook.presto.sql.planner.optimizations.JoinNodeUtils) Arrays.stream(java.util.Arrays.stream) MarkDistinctNode(com.facebook.presto.spi.plan.MarkDistinctNode) DynamicFilterExtractResult(com.facebook.presto.expressions.DynamicFilters.DynamicFilterExtractResult) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) UnionNode(com.facebook.presto.spi.plan.UnionNode) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) TextRenderer.formatPositions(com.facebook.presto.sql.planner.planPrinter.TextRenderer.formatPositions) RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) Function(java.util.function.Function) ExceptNode(com.facebook.presto.spi.plan.ExceptNode) FilterNode(com.facebook.presto.spi.plan.FilterNode) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) LinkedList(java.util.LinkedList) UnnestNode(com.facebook.presto.sql.planner.plan.UnnestNode) Type(com.facebook.presto.common.type.Type) GroupReference(com.facebook.presto.sql.planner.iterative.GroupReference) SourceLocation(com.facebook.presto.spi.SourceLocation) Partitioning(com.facebook.presto.sql.planner.Partitioning) RowExpression(com.facebook.presto.spi.relation.RowExpression) JoinNode(com.facebook.presto.sql.planner.plan.JoinNode) SubPlan(com.facebook.presto.sql.planner.SubPlan) CaseFormat(com.google.common.base.CaseFormat) ComparisonExpression(com.facebook.presto.sql.tree.ComparisonExpression) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) DeleteNode(com.facebook.presto.sql.planner.plan.DeleteNode) JsonPlanFragment(com.facebook.presto.sql.planner.planPrinter.JsonRenderer.JsonPlanFragment) PlanNode(com.facebook.presto.spi.plan.PlanNode) UPPER_UNDERSCORE(com.google.common.base.CaseFormat.UPPER_UNDERSCORE) Collectors.toList(java.util.stream.Collectors.toList) Expression(com.facebook.presto.sql.tree.Expression) StatsAndCosts(com.facebook.presto.cost.StatsAndCosts) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) TableFinishNode(com.facebook.presto.sql.planner.plan.TableFinishNode) EnforceSingleRowNode(com.facebook.presto.sql.planner.plan.EnforceSingleRowNode) ExchangeNode(com.facebook.presto.sql.planner.plan.ExchangeNode) StatisticsWriterNode(com.facebook.presto.sql.planner.plan.StatisticsWriterNode) PartitioningScheme(com.facebook.presto.sql.planner.PartitioningScheme) TypeProvider(com.facebook.presto.sql.planner.TypeProvider) StageExecutionStats(com.facebook.presto.execution.StageExecutionStats)

Example 20 with FunctionAndTypeManager

use of com.facebook.presto.metadata.FunctionAndTypeManager in project presto by prestodb.

the class TestPageProcessorCompiler method testSanityFilterOnDictionary.

@Test
public void testSanityFilterOnDictionary() {
    FunctionAndTypeManager functionAndTypeManager = createTestMetadataManager().getFunctionAndTypeManager();
    CallExpression lengthVarchar = new CallExpression("length", functionAndTypeManager.lookupFunction("length", fromTypes(VARCHAR)), BIGINT, ImmutableList.of(field(0, VARCHAR)));
    FunctionHandle lessThan = functionAndTypeManager.resolveOperator(LESS_THAN, fromTypes(BIGINT, BIGINT));
    CallExpression filter = new CallExpression(LESS_THAN.name(), lessThan, BOOLEAN, ImmutableList.of(lengthVarchar, constant(10L, BIGINT)));
    PageProcessor processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.of(filter), ImmutableList.of(field(0, VARCHAR)), false, MAX_BATCH_SIZE).get();
    Page page = new Page(createDictionaryBlock(createExpectedValues(10), 100));
    Page outputPage = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertEquals(outputPage.getPositionCount(), 100);
    assertTrue(outputPage.getBlock(0) instanceof DictionaryBlock);
    DictionaryBlock dictionaryBlock = (DictionaryBlock) outputPage.getBlock(0);
    assertEquals(dictionaryBlock.getDictionary().getPositionCount(), 10);
    // test filter caching
    Page outputPage2 = getOnlyElement(processor.process(null, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), page)).orElseThrow(() -> new AssertionError("page is not present"));
    assertEquals(outputPage2.getPositionCount(), 100);
    assertTrue(outputPage2.getBlock(0) instanceof DictionaryBlock);
    DictionaryBlock dictionaryBlock2 = (DictionaryBlock) outputPage2.getBlock(0);
    // both output pages must have the same dictionary
    assertEquals(dictionaryBlock2.getDictionary(), dictionaryBlock.getDictionary());
}
Also used : PageProcessor(com.facebook.presto.operator.project.PageProcessor) FunctionAndTypeManager(com.facebook.presto.metadata.FunctionAndTypeManager) DictionaryBlock(com.facebook.presto.common.block.DictionaryBlock) BlockAssertions.createLongDictionaryBlock(com.facebook.presto.block.BlockAssertions.createLongDictionaryBlock) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) CallExpression(com.facebook.presto.spi.relation.CallExpression) FunctionHandle(com.facebook.presto.spi.function.FunctionHandle) Test(org.testng.annotations.Test)

Aggregations

FunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager)62 Test (org.testng.annotations.Test)31 FunctionAndTypeManager.createTestFunctionAndTypeManager (com.facebook.presto.metadata.FunctionAndTypeManager.createTestFunctionAndTypeManager)26 Type (com.facebook.presto.common.type.Type)24 RowExpression (com.facebook.presto.spi.relation.RowExpression)13 ImmutableList (com.google.common.collect.ImmutableList)13 FunctionHandle (com.facebook.presto.spi.function.FunctionHandle)12 CallExpression (com.facebook.presto.spi.relation.CallExpression)12 Block (com.facebook.presto.common.block.Block)11 ArrayType (com.facebook.presto.common.type.ArrayType)11 Optional (java.util.Optional)11 BeforeClass (org.testng.annotations.BeforeClass)11 Page (com.facebook.presto.common.Page)10 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)10 List (java.util.List)10 DBI (org.skife.jdbi.v2.DBI)8 Bootstrap (com.facebook.airlift.bootstrap.Bootstrap)6 JsonBinder.jsonBinder (com.facebook.airlift.json.JsonBinder.jsonBinder)6 JsonCodecBinder.jsonCodecBinder (com.facebook.airlift.json.JsonCodecBinder.jsonCodecBinder)6 JsonModule (com.facebook.airlift.json.JsonModule)6