Search in sources :

Example 6 with ColumnStatisticMetadata

use of io.trino.spi.statistics.ColumnStatisticMetadata in project trino by trinodb.

the class TestTableFinishOperator method testStatisticsAggregation.

@Test
public void testStatisticsAggregation() throws Exception {
    TestTableFinisher tableFinisher = new TestTableFinisher();
    ColumnStatisticMetadata statisticMetadata = new ColumnStatisticMetadata("column", MAX_VALUE);
    StatisticAggregationsDescriptor<Integer> descriptor = new StatisticAggregationsDescriptor<>(ImmutableMap.of(), ImmutableMap.of(), ImmutableMap.of(statisticMetadata, 0));
    Session session = testSessionBuilder().setSystemProperty("statistics_cpu_timer_enabled", "true").build();
    TableExecuteContextManager tableExecuteContextManager = new TableExecuteContextManager();
    TableFinishOperatorFactory operatorFactory = new TableFinishOperatorFactory(0, new PlanNodeId("node"), tableFinisher, new AggregationOperator.AggregationOperatorFactory(1, new PlanNodeId("test"), ImmutableList.of(LONG_MAX.createAggregatorFactory(SINGLE, ImmutableList.of(2), OptionalInt.empty()))), descriptor, tableExecuteContextManager, true, session);
    DriverContext driverContext = createTaskContext(scheduledExecutor, scheduledExecutor, session).addPipelineContext(0, true, true, false).addDriverContext();
    tableExecuteContextManager.registerTableExecuteContextForQuery(driverContext.getPipelineContext().getTaskContext().getQueryContext().getQueryId());
    TableFinishOperator operator = (TableFinishOperator) operatorFactory.createOperator(driverContext);
    List<Type> inputTypes = ImmutableList.of(BIGINT, VARBINARY, BIGINT);
    operator.addInput(rowPagesBuilder(inputTypes).row(4, null, null).build().get(0));
    operator.addInput(rowPagesBuilder(inputTypes).row(5, null, null).build().get(0));
    operator.addInput(rowPagesBuilder(inputTypes).row(null, new byte[] { 1 }, null).build().get(0));
    operator.addInput(rowPagesBuilder(inputTypes).row(null, new byte[] { 2 }, null).build().get(0));
    operator.addInput(rowPagesBuilder(inputTypes).row(null, null, 6).build().get(0));
    operator.addInput(rowPagesBuilder(inputTypes).row(null, null, 7).build().get(0));
    assertThat(driverContext.getMemoryUsage()).as("memoryUsage").isGreaterThan(0);
    assertTrue(operator.isBlocked().isDone(), "isBlocked should be done");
    assertTrue(operator.needsInput(), "needsInput should be true");
    operator.finish();
    assertFalse(operator.isFinished(), "isFinished should be false");
    assertNull(operator.getOutput());
    List<Type> outputTypes = ImmutableList.of(BIGINT);
    assertPageEquals(outputTypes, operator.getOutput(), rowPagesBuilder(outputTypes).row(9).build().get(0));
    assertTrue(operator.isBlocked().isDone(), "isBlocked should be done");
    assertFalse(operator.needsInput(), "needsInput should be false");
    assertTrue(operator.isFinished(), "isFinished should be true");
    operator.close();
    assertEquals(tableFinisher.getFragments(), ImmutableList.of(Slices.wrappedBuffer(new byte[] { 1 }), Slices.wrappedBuffer(new byte[] { 2 })));
    assertEquals(tableFinisher.getComputedStatistics().size(), 1);
    assertEquals(getOnlyElement(tableFinisher.getComputedStatistics()).getColumnStatistics().size(), 1);
    Block expectedStatisticsBlock = new LongArrayBlockBuilder(null, 1).writeLong(7).closeEntry().build();
    assertBlockEquals(BIGINT, getOnlyElement(tableFinisher.getComputedStatistics()).getColumnStatistics().get(statisticMetadata), expectedStatisticsBlock);
    assertEquals(driverContext.getMemoryUsage(), 0, "memoryUsage");
}
Also used : TableFinishOperatorFactory(io.trino.operator.TableFinishOperator.TableFinishOperatorFactory) ColumnStatisticMetadata(io.trino.spi.statistics.ColumnStatisticMetadata) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Type(io.trino.spi.type.Type) TableExecuteContextManager(io.trino.execution.TableExecuteContextManager) Block(io.trino.spi.block.Block) LongArrayBlockBuilder(io.trino.spi.block.LongArrayBlockBuilder) StatisticAggregationsDescriptor(io.trino.sql.planner.plan.StatisticAggregationsDescriptor) Session(io.trino.Session) Test(org.testng.annotations.Test)

Example 7 with ColumnStatisticMetadata

use of io.trino.spi.statistics.ColumnStatisticMetadata in project trino by trinodb.

the class TestStatisticAggregationsDescriptor method testColumnStatisticMetadataKeySerializationRoundTrip.

@Test
public void testColumnStatisticMetadataKeySerializationRoundTrip() {
    for (String column : COLUMNS) {
        for (ColumnStatisticType type : ColumnStatisticType.values()) {
            ColumnStatisticMetadata expected = new ColumnStatisticMetadata(column, type);
            assertEquals(deserialize(serialize(expected)), expected);
        }
    }
}
Also used : ColumnStatisticMetadata(io.trino.spi.statistics.ColumnStatisticMetadata) ColumnStatisticType(io.trino.spi.statistics.ColumnStatisticType) Test(org.testng.annotations.Test)

Example 8 with ColumnStatisticMetadata

use of io.trino.spi.statistics.ColumnStatisticMetadata in project trino by trinodb.

the class TestStatisticAggregationsDescriptor method createTestDescriptor.

private static StatisticAggregationsDescriptor<Symbol> createTestDescriptor() {
    StatisticAggregationsDescriptor.Builder<Symbol> builder = StatisticAggregationsDescriptor.builder();
    SymbolAllocator symbolAllocator = new SymbolAllocator();
    for (String column : COLUMNS) {
        for (ColumnStatisticType type : ColumnStatisticType.values()) {
            builder.addColumnStatistic(new ColumnStatisticMetadata(column, type), testSymbol(symbolAllocator));
        }
        builder.addGrouping(column, testSymbol(symbolAllocator));
    }
    builder.addTableStatistic(ROW_COUNT, testSymbol(symbolAllocator));
    return builder.build();
}
Also used : SymbolAllocator(io.trino.sql.planner.SymbolAllocator) ColumnStatisticMetadata(io.trino.spi.statistics.ColumnStatisticMetadata) Symbol(io.trino.sql.planner.Symbol) ColumnStatisticType(io.trino.spi.statistics.ColumnStatisticType)

Example 9 with ColumnStatisticMetadata

use of io.trino.spi.statistics.ColumnStatisticMetadata in project trino by trinodb.

the class HiveMetadata method createPartitionStatistics.

private PartitionStatistics createPartitionStatistics(Map<String, Type> columnTypes, ComputedStatistics computedStatistics) {
    Map<ColumnStatisticMetadata, Block> computedColumnStatistics = computedStatistics.getColumnStatistics();
    Block rowCountBlock = Optional.ofNullable(computedStatistics.getTableStatistics().get(ROW_COUNT)).orElseThrow(() -> new VerifyException("rowCount not present"));
    verify(!rowCountBlock.isNull(0), "rowCount must never be null");
    long rowCount = BIGINT.getLong(rowCountBlock, 0);
    HiveBasicStatistics rowCountOnlyBasicStatistics = new HiveBasicStatistics(OptionalLong.empty(), OptionalLong.of(rowCount), OptionalLong.empty(), OptionalLong.empty());
    return createPartitionStatistics(rowCountOnlyBasicStatistics, columnTypes, computedColumnStatistics);
}
Also used : ColumnStatisticMetadata(io.trino.spi.statistics.ColumnStatisticMetadata) VerifyException(com.google.common.base.VerifyException) Block(io.trino.spi.block.Block)

Aggregations

ColumnStatisticMetadata (io.trino.spi.statistics.ColumnStatisticMetadata)9 Test (org.testng.annotations.Test)5 ColumnStatisticType (io.trino.spi.statistics.ColumnStatisticType)4 ComputedStatistics (io.trino.spi.statistics.ComputedStatistics)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Slice (io.airlift.slice.Slice)3 Block (io.trino.spi.block.Block)3 ColumnMetadata (io.trino.spi.connector.ColumnMetadata)3 ConnectorMetadata (io.trino.spi.connector.ConnectorMetadata)3 ConnectorOutputTableHandle (io.trino.spi.connector.ConnectorOutputTableHandle)3 ConnectorSession (io.trino.spi.connector.ConnectorSession)3 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)3 SchemaTableName (io.trino.spi.connector.SchemaTableName)3 Type (io.trino.spi.type.Type)3 ImmutableList (com.google.common.collect.ImmutableList)2 Slices.utf8Slice (io.airlift.slice.Slices.utf8Slice)2 ConnectorPageSink (io.trino.spi.connector.ConnectorPageSink)2 TableStatisticType (io.trino.spi.statistics.TableStatisticType)2 StatisticAggregationsDescriptor (io.trino.sql.planner.plan.StatisticAggregationsDescriptor)2 MaterializedResult (io.trino.testing.MaterializedResult)2