Search in sources :

Example 1 with DUMMY_OFFLOADED

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()));
}
Also used : HiveTableHandle(io.prestosql.plugin.hive.HiveTableHandle) HivePushdownUtil.getDataSourceColumns(io.prestosql.plugin.hive.rule.HivePushdownUtil.getDataSourceColumns) HiveTypeTranslator(io.prestosql.plugin.hive.HiveTypeTranslator) HashMap(java.util.HashMap) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) ImmutableList(com.google.common.collect.ImmutableList) OmniExpressionChecker(com.huawei.boostkit.omnidata.expression.OmniExpressionChecker) Map(java.util.Map) Type(io.prestosql.spi.type.Type) RowExpressionNodeInliner.replaceExpression(io.prestosql.expressions.RowExpressionNodeInliner.replaceExpression) Symbol(io.prestosql.spi.plan.Symbol) BiMap(com.google.common.collect.BiMap) DUMMY_OFFLOADED_COLUMN_INDEX(io.prestosql.plugin.hive.HiveColumnHandle.DUMMY_OFFLOADED_COLUMN_INDEX) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) TableScanNode(io.prestosql.spi.plan.TableScanNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) HiveType(io.prestosql.plugin.hive.HiveType) ProjectNode(io.prestosql.spi.plan.ProjectNode) HiveOffloadExpression(io.prestosql.plugin.hive.HiveOffloadExpression) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) DUMMY_OFFLOADED(io.prestosql.plugin.hive.HiveColumnHandle.ColumnType.DUMMY_OFFLOADED) RowExpression(io.prestosql.spi.relation.RowExpression) Optional(java.util.Optional) ImmutableBiMap.toImmutableBiMap(com.google.common.collect.ImmutableBiMap.toImmutableBiMap) TypeSignature(io.prestosql.spi.type.TypeSignature) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) HashMap(java.util.HashMap) Symbol(io.prestosql.spi.plan.Symbol) RowExpression(io.prestosql.spi.relation.RowExpression) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) TypeSignature(io.prestosql.spi.type.TypeSignature) HiveTableHandle(io.prestosql.plugin.hive.HiveTableHandle) HiveTypeTranslator(io.prestosql.plugin.hive.HiveTypeTranslator) TableScanNode(io.prestosql.spi.plan.TableScanNode) VariableReferenceExpression(io.prestosql.spi.relation.VariableReferenceExpression) HiveOffloadExpression(io.prestosql.plugin.hive.HiveOffloadExpression) HiveTableHandle(io.prestosql.plugin.hive.HiveTableHandle) TableHandle(io.prestosql.spi.metadata.TableHandle) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) HiveType(io.prestosql.plugin.hive.HiveType) HashMap(java.util.HashMap) Map(java.util.Map) BiMap(com.google.common.collect.BiMap) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableBiMap.toImmutableBiMap(com.google.common.collect.ImmutableBiMap.toImmutableBiMap) HiveColumnHandle(io.prestosql.plugin.hive.HiveColumnHandle)

Aggregations

BiMap (com.google.common.collect.BiMap)1 ImmutableBiMap.toImmutableBiMap (com.google.common.collect.ImmutableBiMap.toImmutableBiMap)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 OmniExpressionChecker (com.huawei.boostkit.omnidata.expression.OmniExpressionChecker)1 RowExpressionNodeInliner.replaceExpression (io.prestosql.expressions.RowExpressionNodeInliner.replaceExpression)1 HiveColumnHandle (io.prestosql.plugin.hive.HiveColumnHandle)1 DUMMY_OFFLOADED (io.prestosql.plugin.hive.HiveColumnHandle.ColumnType.DUMMY_OFFLOADED)1 DUMMY_OFFLOADED_COLUMN_INDEX (io.prestosql.plugin.hive.HiveColumnHandle.DUMMY_OFFLOADED_COLUMN_INDEX)1 HiveOffloadExpression (io.prestosql.plugin.hive.HiveOffloadExpression)1 HiveTableHandle (io.prestosql.plugin.hive.HiveTableHandle)1 HiveType (io.prestosql.plugin.hive.HiveType)1 HiveTypeTranslator (io.prestosql.plugin.hive.HiveTypeTranslator)1 HivePushdownUtil.getDataSourceColumns (io.prestosql.plugin.hive.rule.HivePushdownUtil.getDataSourceColumns)1 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)1 ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)1 TableHandle (io.prestosql.spi.metadata.TableHandle)1 ProjectNode (io.prestosql.spi.plan.ProjectNode)1 Symbol (io.prestosql.spi.plan.Symbol)1 TableScanNode (io.prestosql.spi.plan.TableScanNode)1