Search in sources :

Example 6 with HiveMetadata

use of io.prestosql.plugin.hive.HiveMetadata in project boostkit-bigdata by kunpengcompute.

the class TestHivePushdownUtil method simulationHiveMetadata.

protected static HiveMetadata simulationHiveMetadata() {
    // simulation chain: HiveTransactionManager -> HiveMetadata -> ColumnMetadata + TableStatistics + ColumnStatistics
    ColumnMetadata columnMetadataInt = Mockito.mock(ColumnMetadata.class);
    Mockito.when(columnMetadataInt.getName()).thenReturn(COLUMN_INT.getName());
    Mockito.when(columnMetadataInt.getType()).thenReturn(INTEGER);
    HashMap<String, Object> propertyMap = new HashMap<>();
    propertyMap.put(STORAGE_FORMAT_PROPERTY, HiveStorageFormat.ORC);
    ConnectorTableMetadata connectorTableMetadata = Mockito.mock(ConnectorTableMetadata.class);
    Mockito.when(connectorTableMetadata.getProperties()).thenReturn(propertyMap);
    Map<ColumnHandle, ColumnStatistics> columnStatistics = new HashMap<>();
    ColumnStatistics columnStatisInt = new ColumnStatistics(Estimate.zero(), Estimate.of(DISTINICT_COLUMN_NUM), Estimate.unknown(), Optional.of(new DoubleRange(1, 10)));
    columnStatistics.put(COLUMN_INT, columnStatisInt);
    TableStatistics statistics = new TableStatistics(Estimate.of(OFFLOAD_COLUMN_NUM), 5, 1024, columnStatistics);
    HiveMetadata metadata = Mockito.mock(HiveMetadata.class);
    Mockito.when(metadata.getTableMetadata(OFFLOAD_SESSION, OFFLOAD_HIVE_TABLE_HANDLE)).thenReturn(connectorTableMetadata);
    Mockito.when(metadata.getColumnMetadata(Matchers.eq(OFFLOAD_SESSION), Matchers.eq(OFFLOAD_HIVE_TABLE_HANDLE), Matchers.any(ColumnHandle.class))).thenReturn(columnMetadataInt);
    Map<String, ColumnHandle> columnHandleMap = ImmutableMap.of(COLUMN_INT.getName(), COLUMN_INT);
    Mockito.when(metadata.getColumnHandles(OFFLOAD_SESSION, OFFLOAD_HIVE_TABLE_HANDLE)).thenReturn(columnHandleMap);
    Mockito.when(metadata.getTableStatistics(Matchers.eq(OFFLOAD_SESSION), Matchers.eq(OFFLOAD_HIVE_TABLE_HANDLE), Matchers.any(Constraint.class), Matchers.eq(true))).thenReturn(statistics);
    return metadata;
}
Also used : ColumnStatistics(io.prestosql.spi.statistics.ColumnStatistics) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) HashMap(java.util.HashMap) Constraint(io.prestosql.spi.connector.Constraint) DoubleRange(io.prestosql.spi.statistics.DoubleRange) TableStatistics(io.prestosql.spi.statistics.TableStatistics) HiveMetadata(io.prestosql.plugin.hive.HiveMetadata) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata)

Example 7 with HiveMetadata

use of io.prestosql.plugin.hive.HiveMetadata in project boostkit-bigdata by kunpengcompute.

the class HiveFilterPushdown method pushdownFilter.

private static ConnectorPushdownFilterResult pushdownFilter(HiveMetadata metadata, ConnectorSession session, ConnectorTableHandle tableHandle, RowExpression predicate, Map<String, Type> typesMap, RowExpressionService rowExpressionService, StandardFunctionResolution functionResolution, FunctionMetadataManager functionMetadataManager, FilterStatsCalculatorService filterCalculatorService) {
    checkArgument(!FALSE_CONSTANT.equals(predicate), "Cannot pushdown filter that is always false");
    checkArgument(tableHandle instanceof HiveTableHandle, "Only supports hive TableHandle");
    LogicalRowExpressions logicalRowExpressions = new LogicalRowExpressions(rowExpressionService.getDeterminismEvaluator(), functionResolution, functionMetadataManager);
    ExpressionExtractResult expressionExtractResult = extractOffloadExpression(predicate, logicalRowExpressions, rowExpressionService);
    if (TRUE_CONSTANT.equals(expressionExtractResult.getOffloadExpression())) {
        return new ConnectorPushdownFilterResult(Optional.empty(), TRUE_CONSTANT);
    }
    HiveTableHandle hiveTableHandle = (HiveTableHandle) tableHandle;
    Map<String, ColumnHandle> columnHandlesMap = metadata.getColumnHandles(session, tableHandle);
    HiveOffloadExpression oldOffloadExpression = hiveTableHandle.getOffloadExpression();
    RowExpression filterExpression = TRUE_CONSTANT.equals(oldOffloadExpression.getFilterExpression()) ? expressionExtractResult.getOffloadExpression() : logicalRowExpressions.combineConjuncts(oldOffloadExpression.getFilterExpression(), expressionExtractResult.getOffloadExpression());
    RowExpression optimizedExpression = filterExpression;
    if (true != determineOffloadExpression(optimizedExpression, tableHandle, metadata, session, rowExpressionService, columnHandlesMap, filterCalculatorService, typesMap)) {
        return new ConnectorPushdownFilterResult(Optional.empty(), TRUE_CONSTANT);
    }
    Set<HiveColumnHandle> offloadColumns = HivePushdownUtil.extractAll(optimizedExpression).stream().map(entry -> (HiveColumnHandle) columnHandlesMap.get(entry.getName())).collect(Collectors.toSet());
    Optional<ConnectorTableHandle> newTableHandle = Optional.of(hiveTableHandle.withOffloadExpression(oldOffloadExpression.updateFilter(optimizedExpression, offloadColumns)));
    return new ConnectorPushdownFilterResult(newTableHandle, expressionExtractResult.getRemainingExpression());
}
Also used : ConnectorMetadata(io.prestosql.spi.connector.ConnectorMetadata) HivePartitionManager(io.prestosql.plugin.hive.HivePartitionManager) TableStatistics(io.prestosql.spi.statistics.TableStatistics) HiveTableHandle(io.prestosql.plugin.hive.HiveTableHandle) ConstantExpression(io.prestosql.spi.relation.ConstantExpression) FALSE_CONSTANT(io.prestosql.expressions.LogicalRowExpressions.FALSE_CONSTANT) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle) NullableValue(io.prestosql.spi.predicate.NullableValue) CallExpression(io.prestosql.spi.relation.CallExpression) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) FilterNode(io.prestosql.spi.plan.FilterNode) Map(java.util.Map) FunctionMetadataManager(io.prestosql.spi.function.FunctionMetadataManager) Type(io.prestosql.spi.type.Type) RowExpressionNodeInliner.replaceExpression(io.prestosql.expressions.RowExpressionNodeInliner.replaceExpression) Constraint(io.prestosql.spi.connector.Constraint) BiMap(com.google.common.collect.BiMap) ImmutableSet(com.google.common.collect.ImmutableSet) DomainTranslator(io.prestosql.spi.relation.DomainTranslator) PlanVisitor(io.prestosql.spi.plan.PlanVisitor) TableScanNode(io.prestosql.spi.plan.TableScanNode) Set(java.util.Set) PlanNode(io.prestosql.spi.plan.PlanNode) Collectors(java.util.stream.Collectors) Preconditions.checkState(com.google.common.base.Preconditions.checkState) RowExpressionService(io.prestosql.spi.relation.RowExpressionService) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) HiveOffloadExpression(io.prestosql.plugin.hive.HiveOffloadExpression) Optional(java.util.Optional) LogicalRowExpressions.extractConjuncts(io.prestosql.expressions.LogicalRowExpressions.extractConjuncts) TRUE_CONSTANT(io.prestosql.expressions.LogicalRowExpressions.TRUE_CONSTANT) Logger(io.airlift.log.Logger) HiveSessionProperties(io.prestosql.plugin.hive.HiveSessionProperties) StandardFunctionResolution(io.prestosql.spi.function.StandardFunctionResolution) TableHandle(io.prestosql.spi.metadata.TableHandle) Function(java.util.function.Function) ArrayList(java.util.ArrayList) HiveTransactionManager(io.prestosql.plugin.hive.HiveTransactionManager) LinkedHashMap(java.util.LinkedHashMap) ImmutableList(com.google.common.collect.ImmutableList) OmniExpressionChecker(com.huawei.boostkit.omnidata.expression.OmniExpressionChecker) HivePushdownUtil.isColumnsCanOffload(io.prestosql.plugin.hive.rule.HivePushdownUtil.isColumnsCanOffload) Objects.requireNonNull(java.util.Objects.requireNonNull) ConnectorPlanOptimizer(io.prestosql.spi.ConnectorPlanOptimizer) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) HiveMetadata(io.prestosql.plugin.hive.HiveMetadata) Symbol(io.prestosql.spi.plan.Symbol) HivePushdownUtil.checkStorageFormat(io.prestosql.plugin.hive.rule.HivePushdownUtil.checkStorageFormat) FilterStatsCalculatorService(io.prestosql.spi.plan.FilterStatsCalculatorService) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) TupleDomain(io.prestosql.spi.predicate.TupleDomain) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) SymbolAllocator(io.prestosql.spi.SymbolAllocator) ConnectorTableMetadata(io.prestosql.spi.connector.ConnectorTableMetadata) Estimate(io.prestosql.spi.statistics.Estimate) ValuesNode(io.prestosql.spi.plan.ValuesNode) BASIC_COLUMN_EXTRACTOR(io.prestosql.spi.relation.DomainTranslator.BASIC_COLUMN_EXTRACTOR) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Sets.intersection(com.google.common.collect.Sets.intersection) PlanNodeIdAllocator(io.prestosql.spi.plan.PlanNodeIdAllocator) RowExpression(io.prestosql.spi.relation.RowExpression) ImmutableBiMap.toImmutableBiMap(com.google.common.collect.ImmutableBiMap.toImmutableBiMap) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) LogicalRowExpressions(io.prestosql.expressions.LogicalRowExpressions) RowExpression(io.prestosql.spi.relation.RowExpression) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) HiveTableHandle(io.prestosql.plugin.hive.HiveTableHandle) HiveOffloadExpression(io.prestosql.plugin.hive.HiveOffloadExpression) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle)

Aggregations

HiveMetadata (io.prestosql.plugin.hive.HiveMetadata)7 HiveTransactionManager (io.prestosql.plugin.hive.HiveTransactionManager)4 StandardFunctionResolution (io.prestosql.spi.function.StandardFunctionResolution)4 HiveColumnHandle (io.prestosql.plugin.hive.HiveColumnHandle)3 HivePartitionManager (io.prestosql.plugin.hive.HivePartitionManager)3 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)3 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)3 ConnectorTableMetadata (io.prestosql.spi.connector.ConnectorTableMetadata)3 Constraint (io.prestosql.spi.connector.Constraint)3 FilterStatsCalculatorService (io.prestosql.spi.plan.FilterStatsCalculatorService)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 BiMap (com.google.common.collect.BiMap)2 ImmutableBiMap.toImmutableBiMap (com.google.common.collect.ImmutableBiMap.toImmutableBiMap)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)2 Sets.intersection (com.google.common.collect.Sets.intersection)2 OmniExpressionChecker (com.huawei.boostkit.omnidata.expression.OmniExpressionChecker)2