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;
}
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());
}
Aggregations