Search in sources :

Example 1 with MetadataManager

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

the class TestUnnestOperator method testUnnestNonNumericDoubles.

@Test
public void testUnnestNonNumericDoubles() throws Exception {
    MetadataManager metadata = createTestMetadataManager();
    Type arrayType = metadata.getType(parseTypeSignature("array(double)"));
    Type mapType = metadata.getType(parseTypeSignature("map(bigint,double)"));
    List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType).row(1L, arrayBlockOf(DOUBLE, NEGATIVE_INFINITY, POSITIVE_INFINITY, NaN), mapBlockOf(BIGINT, DOUBLE, ImmutableMap.of(1, NEGATIVE_INFINITY, 2, POSITIVE_INFINITY, 3, NaN))).build();
    OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), false);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, DOUBLE, BIGINT, DOUBLE).row(1L, NEGATIVE_INFINITY, 1L, NEGATIVE_INFINITY).row(1L, POSITIVE_INFINITY, 2L, POSITIVE_INFINITY).row(1L, NaN, 3L, NaN).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : PlanNodeId(com.facebook.presto.sql.planner.plan.PlanNodeId) ArrayType(com.facebook.presto.type.ArrayType) Type(com.facebook.presto.spi.type.Type) MetadataManager(com.facebook.presto.metadata.MetadataManager) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) Page(com.facebook.presto.spi.Page) MaterializedResult(com.facebook.presto.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 2 with MetadataManager

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

the class TestFilterAndProjectOperator method testMergeOutput.

@Test
public void testMergeOutput() {
    List<Page> input = rowPagesBuilder(VARCHAR, BIGINT).addSequencePage(100, 0, 0).addSequencePage(100, 0, 0).addSequencePage(100, 0, 0).addSequencePage(100, 0, 0).build();
    MetadataManager metadata = createTestMetadataManager();
    RowExpression filter = call(EQUAL.name(), metadata.getFunctionAndTypeManager().resolveOperator(EQUAL, fromTypes(BIGINT, BIGINT)), BOOLEAN, field(1, BIGINT), constant(10L, BIGINT));
    ExpressionCompiler compiler = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0));
    Supplier<PageProcessor> processor = compiler.compilePageProcessor(TEST_SESSION.getSqlFunctionProperties(), Optional.of(filter), ImmutableList.of(field(1, BIGINT)));
    OperatorFactory operatorFactory = new FilterAndProjectOperator.FilterAndProjectOperatorFactory(0, new PlanNodeId("test"), processor, ImmutableList.of(BIGINT), new DataSize(64, KILOBYTE), 2);
    List<Page> expected = rowPagesBuilder(BIGINT).row(10L).row(10L).row(10L).row(10L).build();
    assertOperatorEquals(operatorFactory, ImmutableList.of(BIGINT), driverContext, input, expected);
}
Also used : PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) MetadataManager(com.facebook.presto.metadata.MetadataManager) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) PageProcessor(com.facebook.presto.operator.project.PageProcessor) DataSize(io.airlift.units.DataSize) RowExpression(com.facebook.presto.spi.relation.RowExpression) Page(com.facebook.presto.common.Page) ExpressionCompiler(com.facebook.presto.sql.gen.ExpressionCompiler) Test(org.testng.annotations.Test)

Example 3 with MetadataManager

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

the class InCodeGeneratorBenchmark method setup.

@Setup
public void setup() {
    Random random = new Random();
    RowExpression[] arguments = new RowExpression[1 + inListCount];
    switch(type) {
        case StandardTypes.BIGINT:
            prestoType = BIGINT;
            for (int i = 1; i <= inListCount; i++) {
                arguments[i] = constant((long) random.nextInt(), BIGINT);
            }
            break;
        case StandardTypes.DOUBLE:
            prestoType = DOUBLE;
            for (int i = 1; i <= inListCount; i++) {
                arguments[i] = constant(random.nextDouble(), DOUBLE);
            }
            break;
        case StandardTypes.VARCHAR:
            prestoType = VARCHAR;
            for (int i = 1; i <= inListCount; i++) {
                arguments[i] = constant(Slices.utf8Slice(Long.toString(random.nextLong())), VARCHAR);
            }
            break;
        default:
            throw new IllegalStateException();
    }
    arguments[0] = field(0, prestoType);
    RowExpression project = field(0, prestoType);
    PageBuilder pageBuilder = new PageBuilder(ImmutableList.of(prestoType));
    for (int i = 0; i < 10_000; i++) {
        pageBuilder.declarePosition();
        switch(type) {
            case StandardTypes.BIGINT:
                BIGINT.writeLong(pageBuilder.getBlockBuilder(0), random.nextInt());
                break;
            case StandardTypes.DOUBLE:
                DOUBLE.writeDouble(pageBuilder.getBlockBuilder(0), random.nextDouble());
                break;
            case StandardTypes.VARCHAR:
                VARCHAR.writeSlice(pageBuilder.getBlockBuilder(0), Slices.utf8Slice(Long.toString(random.nextLong())));
                break;
        }
    }
    inputPage = pageBuilder.build();
    RowExpression filter = specialForm(IN, BOOLEAN, arguments);
    MetadataManager metadata = MetadataManager.createTestMetadataManager();
    processor = new ExpressionCompiler(metadata, new PageFunctionCompiler(metadata, 0)).compilePageProcessor(SESSION.getSqlFunctionProperties(), Optional.of(filter), ImmutableList.of(project)).get();
}
Also used : MetadataManager(com.facebook.presto.metadata.MetadataManager) Random(java.util.Random) RowExpression(com.facebook.presto.spi.relation.RowExpression) PageBuilder(com.facebook.presto.common.PageBuilder) Setup(org.openjdk.jmh.annotations.Setup)

Example 4 with MetadataManager

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

the class TaskTestUtils method createTestingPlanner.

public static LocalExecutionPlanner createTestingPlanner() {
    MetadataManager metadata = MetadataManager.createTestMetadataManager();
    PageSourceManager pageSourceManager = new PageSourceManager();
    pageSourceManager.addConnectorPageSourceProvider(CONNECTOR_ID, new TestingPageSourceProvider());
    // we don't start the finalizer so nothing will be collected, which is ok for a test
    FinalizerService finalizerService = new FinalizerService();
    NodeScheduler nodeScheduler = new NodeScheduler(new LegacyNetworkTopology(), new InMemoryNodeManager(), new NodeSelectionStats(), new NodeSchedulerConfig().setIncludeCoordinator(true), new NodeTaskMap(finalizerService), new ThrowingNodeTtlFetcherManager(), new NoOpQueryManager(), new SimpleTtlNodeSelectorConfig());
    PartitioningProviderManager partitioningProviderManager = new PartitioningProviderManager();
    NodePartitioningManager nodePartitioningManager = new NodePartitioningManager(nodeScheduler, partitioningProviderManager, new NodeSelectionStats());
    PageFunctionCompiler pageFunctionCompiler = new PageFunctionCompiler(metadata, 0);
    return new LocalExecutionPlanner(metadata, Optional.empty(), pageSourceManager, new IndexManager(), partitioningProviderManager, nodePartitioningManager, new PageSinkManager(), new ConnectorMetadataUpdaterManager(), new ExpressionCompiler(metadata, pageFunctionCompiler), pageFunctionCompiler, new JoinFilterFunctionCompiler(metadata), new IndexJoinLookupStats(), new TaskManagerConfig(), new MemoryManagerConfig(), new GenericSpillerFactory((types, spillContext, memoryContext) -> {
        throw new UnsupportedOperationException();
    }), (types, spillContext, memoryContext) -> {
        throw new UnsupportedOperationException();
    }, (types, partitionFunction, spillContext, memoryContext) -> {
        throw new UnsupportedOperationException();
    }, new BlockEncodingManager(), new PagesIndex.TestingFactory(false), new JoinCompiler(MetadataManager.createTestMetadataManager(), new FeaturesConfig()), new LookupJoinOperators(), new OrderingCompiler(), jsonCodec(TableCommitContext.class), new RowExpressionDeterminismEvaluator(metadata), new NoOpFragmentResultCacheManager(), new ObjectMapper(), (session) -> {
        throw new UnsupportedOperationException();
    });
}
Also used : WarningCollector(com.facebook.presto.spi.WarningCollector) LocalExecutionPlanner(com.facebook.presto.sql.planner.LocalExecutionPlanner) MetadataManager(com.facebook.presto.metadata.MetadataManager) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) NodeSelectionStats(com.facebook.presto.execution.scheduler.nodeSelection.NodeSelectionStats) NodeScheduler(com.facebook.presto.execution.scheduler.NodeScheduler) EventListenerManager(com.facebook.presto.eventlistener.EventListenerManager) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) TableWriteInfo(com.facebook.presto.execution.scheduler.TableWriteInfo) PagesIndex(com.facebook.presto.operator.PagesIndex) StageExecutionDescriptor(com.facebook.presto.operator.StageExecutionDescriptor) PlanFragment(com.facebook.presto.sql.planner.PlanFragment) ThrowingNodeTtlFetcherManager(com.facebook.presto.ttl.nodettlfetchermanagers.ThrowingNodeTtlFetcherManager) NoOpFragmentResultCacheManager(com.facebook.presto.operator.NoOpFragmentResultCacheManager) FinalizerService(com.facebook.presto.util.FinalizerService) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) PartitioningScheme(com.facebook.presto.sql.planner.PartitioningScheme) URI(java.net.URI) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) ConnectorMetadataUpdaterManager(com.facebook.presto.metadata.ConnectorMetadataUpdaterManager) ImmutableSet(com.google.common.collect.ImmutableSet) PageSinkManager(com.facebook.presto.split.PageSinkManager) ImmutableMap(com.google.common.collect.ImmutableMap) ResourceGroupId(com.facebook.presto.spi.resourceGroups.ResourceGroupId) JsonCodec.jsonCodec(com.facebook.airlift.json.JsonCodec.jsonCodec) SOURCE_DISTRIBUTION(com.facebook.presto.sql.planner.SystemPartitioningHandle.SOURCE_DISTRIBUTION) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) List(java.util.List) Optional(java.util.Optional) ConnectorId(com.facebook.presto.spi.ConnectorId) AllowAllAccessControl(com.facebook.presto.security.AllowAllAccessControl) ExpressionCompiler(com.facebook.presto.sql.gen.ExpressionCompiler) NodeSchedulerConfig(com.facebook.presto.execution.scheduler.NodeSchedulerConfig) PlanNodeId(com.facebook.presto.spi.plan.PlanNodeId) OutputBuffers(com.facebook.presto.execution.buffer.OutputBuffers) SINGLE_DISTRIBUTION(com.facebook.presto.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION) SimpleTtlNodeSelectorConfig(com.facebook.presto.execution.scheduler.nodeSelection.SimpleTtlNodeSelectorConfig) RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) LookupJoinOperators(com.facebook.presto.operator.LookupJoinOperators) NoOpQueryManager(com.facebook.presto.dispatcher.NoOpQueryManager) TestingSplit(com.facebook.presto.testing.TestingSplit) LegacyNetworkTopology(com.facebook.presto.execution.scheduler.LegacyNetworkTopology) TEST_SESSION(com.facebook.presto.SessionTestUtils.TEST_SESSION) ImmutableList(com.google.common.collect.ImmutableList) PageSourceManager(com.facebook.presto.split.PageSourceManager) OrderingCompiler(com.facebook.presto.sql.gen.OrderingCompiler) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) GenericSpillerFactory(com.facebook.presto.spiller.GenericSpillerFactory) IndexManager(com.facebook.presto.index.IndexManager) TableHandle(com.facebook.presto.spi.TableHandle) MemoryManagerConfig(com.facebook.presto.memory.MemoryManagerConfig) PlanFragmentId(com.facebook.presto.sql.planner.plan.PlanFragmentId) IndexJoinLookupStats(com.facebook.presto.operator.index.IndexJoinLookupStats) TransactionManager(com.facebook.presto.transaction.TransactionManager) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) Partitioning(com.facebook.presto.sql.planner.Partitioning) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) NodePartitioningManager(com.facebook.presto.sql.planner.NodePartitioningManager) TableCommitContext(com.facebook.presto.operator.TableCommitContext) SplitMonitor(com.facebook.presto.event.SplitMonitor) Executor(java.util.concurrent.Executor) Session(com.facebook.presto.Session) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JoinFilterFunctionCompiler(com.facebook.presto.sql.gen.JoinFilterFunctionCompiler) TestingTransactionHandle(com.facebook.presto.testing.TestingTransactionHandle) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) TestingColumnHandle(com.facebook.presto.testing.TestingMetadata.TestingColumnHandle) TableScanNode(com.facebook.presto.spi.plan.TableScanNode) StatsAndCosts(com.facebook.presto.cost.StatsAndCosts) Split(com.facebook.presto.metadata.Split) TestingTableHandle(com.facebook.presto.testing.TestingMetadata.TestingTableHandle) JoinCompiler(com.facebook.presto.sql.gen.JoinCompiler) PartitioningProviderManager(com.facebook.presto.sql.planner.PartitioningProviderManager) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) FeaturesConfig(com.facebook.presto.sql.analyzer.FeaturesConfig) PartitioningProviderManager(com.facebook.presto.sql.planner.PartitioningProviderManager) NodeSchedulerConfig(com.facebook.presto.execution.scheduler.NodeSchedulerConfig) TableCommitContext(com.facebook.presto.operator.TableCommitContext) PagesIndex(com.facebook.presto.operator.PagesIndex) PageSourceManager(com.facebook.presto.split.PageSourceManager) NodePartitioningManager(com.facebook.presto.sql.planner.NodePartitioningManager) NoOpFragmentResultCacheManager(com.facebook.presto.operator.NoOpFragmentResultCacheManager) OrderingCompiler(com.facebook.presto.sql.gen.OrderingCompiler) NodeScheduler(com.facebook.presto.execution.scheduler.NodeScheduler) GenericSpillerFactory(com.facebook.presto.spiller.GenericSpillerFactory) SimpleTtlNodeSelectorConfig(com.facebook.presto.execution.scheduler.nodeSelection.SimpleTtlNodeSelectorConfig) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PageSinkManager(com.facebook.presto.split.PageSinkManager) LookupJoinOperators(com.facebook.presto.operator.LookupJoinOperators) JoinCompiler(com.facebook.presto.sql.gen.JoinCompiler) RowExpressionDeterminismEvaluator(com.facebook.presto.sql.relational.RowExpressionDeterminismEvaluator) LocalExecutionPlanner(com.facebook.presto.sql.planner.LocalExecutionPlanner) IndexJoinLookupStats(com.facebook.presto.operator.index.IndexJoinLookupStats) JoinFilterFunctionCompiler(com.facebook.presto.sql.gen.JoinFilterFunctionCompiler) MemoryManagerConfig(com.facebook.presto.memory.MemoryManagerConfig) ThrowingNodeTtlFetcherManager(com.facebook.presto.ttl.nodettlfetchermanagers.ThrowingNodeTtlFetcherManager) InMemoryNodeManager(com.facebook.presto.metadata.InMemoryNodeManager) IndexManager(com.facebook.presto.index.IndexManager) NoOpQueryManager(com.facebook.presto.dispatcher.NoOpQueryManager) MetadataManager(com.facebook.presto.metadata.MetadataManager) BlockEncodingManager(com.facebook.presto.common.block.BlockEncodingManager) NodeSelectionStats(com.facebook.presto.execution.scheduler.nodeSelection.NodeSelectionStats) FinalizerService(com.facebook.presto.util.FinalizerService) LegacyNetworkTopology(com.facebook.presto.execution.scheduler.LegacyNetworkTopology) ConnectorMetadataUpdaterManager(com.facebook.presto.metadata.ConnectorMetadataUpdaterManager) ExpressionCompiler(com.facebook.presto.sql.gen.ExpressionCompiler)

Example 5 with MetadataManager

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

the class TestComparisonStatsCalculator method setUp.

@BeforeClass
public void setUp() throws Exception {
    session = testSessionBuilder().build();
    MetadataManager metadata = MetadataManager.createTestMetadataManager();
    filterStatsCalculator = new FilterStatsCalculator(metadata, new ScalarStatsCalculator(metadata), new StatsNormalizer());
    uStats = VariableStatsEstimate.builder().setAverageRowSize(8.0).setDistinctValuesCount(300).setLowValue(0).setHighValue(20).setNullsFraction(0.1).build();
    wStats = VariableStatsEstimate.builder().setAverageRowSize(8.0).setDistinctValuesCount(30).setLowValue(0).setHighValue(20).setNullsFraction(0.1).build();
    xStats = VariableStatsEstimate.builder().setAverageRowSize(4.0).setDistinctValuesCount(40.0).setLowValue(-10.0).setHighValue(10.0).setNullsFraction(0.25).build();
    yStats = VariableStatsEstimate.builder().setAverageRowSize(4.0).setDistinctValuesCount(20.0).setLowValue(0.0).setHighValue(5.0).setNullsFraction(0.5).build();
    zStats = VariableStatsEstimate.builder().setAverageRowSize(4.0).setDistinctValuesCount(5.0).setLowValue(-100.0).setHighValue(100.0).setNullsFraction(0.1).build();
    leftOpenStats = VariableStatsEstimate.builder().setAverageRowSize(4.0).setDistinctValuesCount(50.0).setLowValue(NEGATIVE_INFINITY).setHighValue(15.0).setNullsFraction(0.1).build();
    rightOpenStats = VariableStatsEstimate.builder().setAverageRowSize(4.0).setDistinctValuesCount(50.0).setLowValue(-15.0).setHighValue(POSITIVE_INFINITY).setNullsFraction(0.1).build();
    unknownRangeStats = VariableStatsEstimate.builder().setAverageRowSize(4.0).setDistinctValuesCount(50.0).setLowValue(NEGATIVE_INFINITY).setHighValue(POSITIVE_INFINITY).setNullsFraction(0.1).build();
    emptyRangeStats = VariableStatsEstimate.builder().setAverageRowSize(0.0).setDistinctValuesCount(0.0).setLowValue(NaN).setHighValue(NaN).setNullsFraction(1.0).build();
    varcharStats = VariableStatsEstimate.builder().setAverageRowSize(4.0).setDistinctValuesCount(50.0).setLowValue(NEGATIVE_INFINITY).setHighValue(POSITIVE_INFINITY).setNullsFraction(0.1).build();
    standardInputStatistics = PlanNodeStatsEstimate.builder().addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "u", DOUBLE), uStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "w", DOUBLE), wStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "x", DOUBLE), xStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "y", DOUBLE), yStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "z", DOUBLE), zStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "leftOpen", DOUBLE), leftOpenStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "rightOpen", DOUBLE), rightOpenStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "unknownRange", DOUBLE), unknownRangeStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "emptyRange", DOUBLE), emptyRangeStats).addVariableStatistics(new VariableReferenceExpression(Optional.empty(), "varchar", VarcharType.createVarcharType(10)), varcharStats).setOutputRowCount(1000.0).build();
    types = TypeProvider.fromVariables(ImmutableList.<VariableReferenceExpression>builder().add(new VariableReferenceExpression(Optional.empty(), "u", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "w", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "x", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "y", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "z", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "leftOpen", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "rightOpen", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "unknownRange", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "emptyRange", DOUBLE)).add(new VariableReferenceExpression(Optional.empty(), "varchar", VarcharType.createVarcharType(10))).build());
}
Also used : MetadataManager(com.facebook.presto.metadata.MetadataManager) VariableReferenceExpression(com.facebook.presto.spi.relation.VariableReferenceExpression) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

MetadataManager (com.facebook.presto.metadata.MetadataManager)27 MetadataManager.createTestMetadataManager (com.facebook.presto.metadata.MetadataManager.createTestMetadataManager)15 Test (org.testng.annotations.Test)15 MaterializedResult (com.facebook.presto.testing.MaterializedResult)11 Page (com.facebook.presto.common.Page)8 PlanNodeId (com.facebook.presto.spi.plan.PlanNodeId)8 Type (com.facebook.presto.common.type.Type)7 RowExpression (com.facebook.presto.spi.relation.RowExpression)7 VariableReferenceExpression (com.facebook.presto.spi.relation.VariableReferenceExpression)7 BlockAssertions.createMapType (com.facebook.presto.block.BlockAssertions.createMapType)5 ArrayType (com.facebook.presto.common.type.ArrayType)5 DecimalType.createDecimalType (com.facebook.presto.common.type.DecimalType.createDecimalType)5 RowType (com.facebook.presto.common.type.RowType)5 OperatorFactory (com.facebook.presto.operator.OperatorFactory)5 TestUnnesterUtil.buildExpectedPage (com.facebook.presto.operator.unnest.TestUnnesterUtil.buildExpectedPage)5 ConnectorId (com.facebook.presto.spi.ConnectorId)5 PageFunctionCompiler (com.facebook.presto.sql.gen.PageFunctionCompiler)5 Page (com.facebook.presto.spi.Page)4 ExpressionCompiler (com.facebook.presto.sql.gen.ExpressionCompiler)4 PlanNodeId (com.facebook.presto.sql.planner.plan.PlanNodeId)4