Search in sources :

Example 1 with ColumnStatisticMetadata

use of io.prestosql.spi.statistics.ColumnStatisticMetadata in project hetu-core by openlookeng.

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.prestosql.spi.statistics.ColumnStatisticMetadata) ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) Test(org.testng.annotations.Test)

Example 2 with ColumnStatisticMetadata

use of io.prestosql.spi.statistics.ColumnStatisticMetadata in project hetu-core by openlookeng.

the class TestTableFinishOperator method testStatisticsAggregationSnapshot.

@Test
public void testStatisticsAggregationSnapshot() 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();
    TableFinishOperatorFactory operatorFactory = new TableFinishOperatorFactory(0, new PlanNodeId("node"), tableFinisher, new AggregationOperator.AggregationOperatorFactory(1, new PlanNodeId("test"), AggregationNode.Step.SINGLE, ImmutableList.of(LONG_MAX.bind(ImmutableList.of(2), Optional.empty())), true), descriptor, session);
    DriverContext driverContext = createTaskContext(scheduledExecutor, scheduledExecutor, session).addPipelineContext(0, true, true, false).addDriverContext();
    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));
    Object snapshot = operator.capture(operator.getOperatorContext().getDriverContext().getSerde());
    Map<String, Object> snapshotMapping = (Map<String, Object>) SnapshotTestUtil.toFullSnapshotMapping(snapshot);
    assertEquals(snapshotMapping, createExpectedMapping());
    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));
    operator.restore(snapshot, operator.getOperatorContext().getDriverContext().getSerde());
    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.getSystemMemoryUsage()).isGreaterThan(0);
    assertEquals(driverContext.getMemoryUsage(), 0);
    assertTrue(operator.isBlocked().isDone());
    assertTrue(operator.needsInput());
    operator.finish();
    assertFalse(operator.isFinished());
    assertNull(operator.getOutput());
    List<Type> outputTypes = ImmutableList.of(BIGINT);
    assertPageEquals(outputTypes, operator.getOutput(), rowPagesBuilder(outputTypes).row(9).build().get(0));
    assertTrue(operator.isBlocked().isDone());
    assertFalse(operator.needsInput());
    assertTrue(operator.isFinished());
    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);
    TableFinishInfo tableFinishInfo = operator.getInfo();
    assertThat(tableFinishInfo.getStatisticsWallTime().getValue(NANOSECONDS)).isGreaterThan(0);
    assertThat(tableFinishInfo.getStatisticsCpuTime().getValue(NANOSECONDS)).isGreaterThan(0);
    assertEquals(driverContext.getSystemMemoryUsage(), 0);
    assertEquals(driverContext.getMemoryUsage(), 0);
}
Also used : TableFinishOperatorFactory(io.prestosql.operator.TableFinishOperator.TableFinishOperatorFactory) ColumnStatisticMetadata(io.prestosql.spi.statistics.ColumnStatisticMetadata) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) Type(io.prestosql.spi.type.Type) Block(io.prestosql.spi.block.Block) LongArrayBlockBuilder(io.prestosql.spi.block.LongArrayBlockBuilder) StatisticAggregationsDescriptor(io.prestosql.sql.planner.plan.StatisticAggregationsDescriptor) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Example 3 with ColumnStatisticMetadata

use of io.prestosql.spi.statistics.ColumnStatisticMetadata in project hetu-core by openlookeng.

the class StatisticsAggregationPlanner method createStatisticsAggregation.

public TableStatisticAggregation createStatisticsAggregation(TableStatisticsMetadata statisticsMetadata, Map<String, Symbol> columnToSymbolMap) {
    StatisticAggregationsDescriptor.Builder<Symbol> descriptor = StatisticAggregationsDescriptor.builder();
    List<String> groupingColumns = statisticsMetadata.getGroupingColumns();
    List<Symbol> groupingSymbols = groupingColumns.stream().map(columnToSymbolMap::get).collect(toImmutableList());
    for (int i = 0; i < groupingSymbols.size(); i++) {
        descriptor.addGrouping(groupingColumns.get(i), groupingSymbols.get(i));
    }
    ImmutableMap.Builder<Symbol, AggregationNode.Aggregation> aggregations = ImmutableMap.builder();
    StandardFunctionResolution functionResolution = new FunctionResolution(metadata.getFunctionAndTypeManager());
    for (TableStatisticType type : statisticsMetadata.getTableStatistics()) {
        if (type != ROW_COUNT) {
            throw new PrestoException(NOT_SUPPORTED, "Table-wide statistic type not supported: " + type);
        }
        AggregationNode.Aggregation aggregation = new AggregationNode.Aggregation(new CallExpression("count", functionResolution.countFunction(), BIGINT, ImmutableList.of(), Optional.empty()), ImmutableList.of(), false, Optional.empty(), Optional.empty(), Optional.empty());
        Symbol symbol = planSymbolAllocator.newSymbol("rowCount", BIGINT);
        aggregations.put(symbol, aggregation);
        descriptor.addTableStatistic(ROW_COUNT, symbol);
    }
    for (ColumnStatisticMetadata columnStatisticMetadata : statisticsMetadata.getColumnStatistics()) {
        String columnName = columnStatisticMetadata.getColumnName();
        ColumnStatisticType statisticType = columnStatisticMetadata.getStatisticType();
        Symbol inputSymbol = columnToSymbolMap.get(columnName);
        verify(inputSymbol != null, "inputSymbol is null");
        Type inputType = planSymbolAllocator.getTypes().get(inputSymbol);
        verify(inputType != null, "inputType is null for symbol: %s", inputSymbol);
        ColumnStatisticsAggregation aggregation = createColumnAggregation(statisticType, inputSymbol, inputType);
        Symbol symbol = planSymbolAllocator.newSymbol(statisticType + ":" + columnName, aggregation.getOutputType());
        aggregations.put(symbol, aggregation.getAggregation());
        descriptor.addColumnStatistic(columnStatisticMetadata, symbol);
    }
    StatisticAggregations aggregation = new StatisticAggregations(aggregations.build(), groupingSymbols);
    return new TableStatisticAggregation(aggregation, descriptor.build());
}
Also used : ColumnStatisticMetadata(io.prestosql.spi.statistics.ColumnStatisticMetadata) Symbol(io.prestosql.spi.plan.Symbol) PrestoException(io.prestosql.spi.PrestoException) AggregationNode(io.prestosql.spi.plan.AggregationNode) StandardFunctionResolution(io.prestosql.spi.function.StandardFunctionResolution) FunctionResolution(io.prestosql.sql.relational.FunctionResolution) ImmutableMap(com.google.common.collect.ImmutableMap) StatisticAggregations(io.prestosql.sql.planner.plan.StatisticAggregations) ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) TableStatisticType(io.prestosql.spi.statistics.TableStatisticType) Type(io.prestosql.spi.type.Type) ColumnStatisticType(io.prestosql.spi.statistics.ColumnStatisticType) StatisticAggregationsDescriptor(io.prestosql.sql.planner.plan.StatisticAggregationsDescriptor) StandardFunctionResolution(io.prestosql.spi.function.StandardFunctionResolution) TableStatisticType(io.prestosql.spi.statistics.TableStatisticType) CallExpression(io.prestosql.spi.relation.CallExpression)

Example 4 with ColumnStatisticMetadata

use of io.prestosql.spi.statistics.ColumnStatisticMetadata in project boostkit-bigdata by kunpengcompute.

the class HiveMetadata method createPartitionStatistics.

private PartitionStatistics createPartitionStatistics(ConnectorSession session, 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(session, rowCountOnlyBasicStatistics, columnTypes, computedColumnStatistics);
}
Also used : ColumnStatisticMetadata(io.prestosql.spi.statistics.ColumnStatisticMetadata) VerifyException(com.google.common.base.VerifyException) Block(io.prestosql.spi.block.Block)

Example 5 with ColumnStatisticMetadata

use of io.prestosql.spi.statistics.ColumnStatisticMetadata in project hetu-core by openlookeng.

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();
    TableFinishOperatorFactory operatorFactory = new TableFinishOperatorFactory(0, new PlanNodeId("node"), tableFinisher, new AggregationOperator.AggregationOperatorFactory(1, new PlanNodeId("test"), AggregationNode.Step.SINGLE, ImmutableList.of(LONG_MAX.bind(ImmutableList.of(2), Optional.empty())), true), descriptor, session);
    DriverContext driverContext = createTaskContext(scheduledExecutor, scheduledExecutor, session).addPipelineContext(0, true, true, false).addDriverContext();
    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.getSystemMemoryUsage()).isGreaterThan(0);
    assertEquals(driverContext.getMemoryUsage(), 0);
    assertTrue(operator.isBlocked().isDone());
    assertTrue(operator.needsInput());
    operator.finish();
    assertFalse(operator.isFinished());
    assertNull(operator.getOutput());
    List<Type> outputTypes = ImmutableList.of(BIGINT);
    assertPageEquals(outputTypes, operator.getOutput(), rowPagesBuilder(outputTypes).row(9).build().get(0));
    assertTrue(operator.isBlocked().isDone());
    assertFalse(operator.needsInput());
    assertTrue(operator.isFinished());
    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);
    TableFinishInfo tableFinishInfo = operator.getInfo();
    assertThat(tableFinishInfo.getStatisticsWallTime().getValue(NANOSECONDS)).isGreaterThan(0);
    assertThat(tableFinishInfo.getStatisticsCpuTime().getValue(NANOSECONDS)).isGreaterThan(0);
    assertEquals(driverContext.getSystemMemoryUsage(), 0);
    assertEquals(driverContext.getMemoryUsage(), 0);
}
Also used : TableFinishOperatorFactory(io.prestosql.operator.TableFinishOperator.TableFinishOperatorFactory) ColumnStatisticMetadata(io.prestosql.spi.statistics.ColumnStatisticMetadata) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) Type(io.prestosql.spi.type.Type) Block(io.prestosql.spi.block.Block) LongArrayBlockBuilder(io.prestosql.spi.block.LongArrayBlockBuilder) StatisticAggregationsDescriptor(io.prestosql.sql.planner.plan.StatisticAggregationsDescriptor) Session(io.prestosql.Session) Test(org.testng.annotations.Test)

Aggregations

ColumnStatisticMetadata (io.prestosql.spi.statistics.ColumnStatisticMetadata)8 Block (io.prestosql.spi.block.Block)5 ColumnStatisticType (io.prestosql.spi.statistics.ColumnStatisticType)4 Type (io.prestosql.spi.type.Type)4 StatisticAggregationsDescriptor (io.prestosql.sql.planner.plan.StatisticAggregationsDescriptor)3 Test (org.testng.annotations.Test)3 VerifyException (com.google.common.base.VerifyException)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Session (io.prestosql.Session)2 TableFinishOperatorFactory (io.prestosql.operator.TableFinishOperator.TableFinishOperatorFactory)2 LongArrayBlockBuilder (io.prestosql.spi.block.LongArrayBlockBuilder)2 PlanNodeId (io.prestosql.spi.plan.PlanNodeId)2 Symbol (io.prestosql.spi.plan.Symbol)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 MemoryColumnHandle (io.prestosql.plugin.memory.MemoryColumnHandle)1 PrestoException (io.prestosql.spi.PrestoException)1 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)1 StandardFunctionResolution (io.prestosql.spi.function.StandardFunctionResolution)1 AggregationNode (io.prestosql.spi.plan.AggregationNode)1