use of io.prestosql.plugin.hive.HiveOffloadExpression in project boostkit-bigdata by kunpengcompute.
the class PageSourceUtil method buildColumnsProjections.
public static List<RowExpression> buildColumnsProjections(HiveOffloadExpression expression, List<HiveColumnHandle> columns, Map<VariableReferenceExpression, Integer> layoutMap, Map<VariableReferenceExpression, Integer> projectionsLayout) {
checkArgument(projectionsLayout.isEmpty(), "buildColumnsProjections: input reference error.");
int channel = 0;
ImmutableList.Builder<RowExpression> builder = ImmutableList.builder();
if (!expression.getProjections().isEmpty()) {
for (Map.Entry<Symbol, RowExpression> entry : expression.getProjections().entrySet()) {
RowExpression rowExpression = VariableToChannelTranslator.translate(entry.getValue(), layoutMap);
builder.add(rowExpression);
projectionsLayout.put(new VariableReferenceExpression(entry.getKey().getName(), rowExpression.getType()), channel++);
}
return builder.build();
}
Map<String, Integer> nameMap = layoutMap.entrySet().stream().collect(toMap(key -> key.getKey().getName(), val -> val.getValue()));
Map<String, Type> typeMap = layoutMap.entrySet().stream().collect(toMap(key -> key.getKey().getName(), val -> val.getKey().getType()));
Set<String> columnSet = new HashSet<>();
for (HiveColumnHandle columnHandle : columns) {
if (columnHandle.getHiveColumnIndex() == DUMMY_OFFLOADED_COLUMN_INDEX) {
continue;
}
if (columnSet.add(columnHandle.getName())) {
Type type = typeMap.get(columnHandle.getName());
InputReferenceExpression inputReferenceExpression = new InputReferenceExpression(nameMap.get(columnHandle.getName()), type);
projectionsLayout.put(new VariableReferenceExpression(columnHandle.getName(), type), channel++);
builder.add(inputReferenceExpression);
}
}
return builder.build();
}
use of io.prestosql.plugin.hive.HiveOffloadExpression 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()));
}
use of io.prestosql.plugin.hive.HiveOffloadExpression in project boostkit-bigdata by kunpengcompute.
the class TestHivePushdownUtil method matchFilterOffload.
protected static void matchFilterOffload(PlanNode node, RowExpression predicate) {
HiveOffloadExpression expression = getCheckedOffloadExpression(node);
assertTrue(expression.isPresent());
assertEquals(predicate, expression.getFilterExpression());
}
use of io.prestosql.plugin.hive.HiveOffloadExpression in project boostkit-bigdata by kunpengcompute.
the class TestHivePushdownUtil method matchLimitOffload.
protected static void matchLimitOffload(PlanNode node, long count) {
HiveOffloadExpression expression = getCheckedOffloadExpression(node);
assertTrue(expression.isPresent());
assertEquals(count, expression.getLimit().getAsLong());
}
use of io.prestosql.plugin.hive.HiveOffloadExpression in project boostkit-bigdata by kunpengcompute.
the class TestHivePushdownUtil method getCheckedOffloadExpression.
private static HiveOffloadExpression getCheckedOffloadExpression(PlanNode node) {
assertTrue(node instanceof TableScanNode);
ConnectorTableHandle tableHandle = ((TableScanNode) node).getTable().getConnectorHandle();
assertTrue(tableHandle instanceof HiveTableHandle);
HiveOffloadExpression hiveOffloadExpression = ((HiveTableHandle) tableHandle).getOffloadExpression();
return hiveOffloadExpression;
}
Aggregations