use of io.prestosql.plugin.hive.HiveColumnHandle.ColumnType.DUMMY_OFFLOADED in project boostkit-bigdata by kunpengcompute.
the class HiveProjectPushdown method tryProjectPushdown.
protected static Optional<TableScanNode> tryProjectPushdown(ProjectNode plan, Map<String, Type> types) {
if (!(plan.getSource() instanceof TableScanNode)) {
return Optional.empty();
}
TableScanNode tableScanNode = (TableScanNode) plan.getSource();
ConnectorTableHandle tableHandle = tableScanNode.getTable().getConnectorHandle();
if (!(tableHandle instanceof HiveTableHandle) || !(((HiveTableHandle) tableHandle).getOffloadExpression().getProjections().isEmpty())) {
return Optional.empty();
}
Map<Symbol, ColumnHandle> assignments = new HashMap<>();
HiveTypeTranslator hiveTypeTranslator = new HiveTypeTranslator();
for (Map.Entry<Symbol, RowExpression> entry : plan.getAssignments().entrySet()) {
String name = entry.getKey().getName();
HiveType hiveType = HiveType.toHiveType(hiveTypeTranslator, entry.getValue().getType());
TypeSignature typeSignature = entry.getValue().getType().getTypeSignature();
HiveColumnHandle columnHandle = new HiveColumnHandle(name, hiveType, typeSignature, DUMMY_OFFLOADED_COLUMN_INDEX, DUMMY_OFFLOADED, Optional.of("projections pushed down " + name));
assignments.put(entry.getKey(), columnHandle);
}
BiMap<VariableReferenceExpression, VariableReferenceExpression> variableToColumnMapping = tableScanNode.getAssignments().entrySet().stream().collect(toImmutableBiMap(entry -> new VariableReferenceExpression(entry.getKey().getName(), types.get(entry.getKey().getName())), entry -> new VariableReferenceExpression(entry.getValue().getColumnName(), types.get(entry.getKey().getName()))));
ImmutableMap.Builder<Symbol, RowExpression> projections = new ImmutableMap.Builder<>();
for (Map.Entry<Symbol, RowExpression> entry : plan.getAssignments().getMap().entrySet()) {
RowExpression expression = replaceExpression(entry.getValue(), variableToColumnMapping);
if (!OmniExpressionChecker.checkExpression(expression)) {
return Optional.empty();
}
projections.put(entry.getKey(), expression);
}
HiveTableHandle hiveTableHandle = (HiveTableHandle) tableHandle;
HiveOffloadExpression offloadExpression = hiveTableHandle.getOffloadExpression().updateProjections(projections.build(), getDataSourceColumns(tableScanNode));
HiveTableHandle newHiveTableHandle = hiveTableHandle.withOffloadExpression(offloadExpression);
TableHandle newTableHandle = new TableHandle(tableScanNode.getTable().getCatalogName(), newHiveTableHandle, tableScanNode.getTable().getTransaction(), tableScanNode.getTable().getLayout());
return Optional.of(new TableScanNode(tableScanNode.getId(), newTableHandle, ImmutableList.copyOf(assignments.keySet()), assignments, tableScanNode.getEnforcedConstraint(), tableScanNode.getPredicate(), tableScanNode.getStrategy(), tableScanNode.getReuseTableScanMappingId(), tableScanNode.getConsumerTableScanNodeCount(), tableScanNode.isForDelete()));
}
Aggregations