Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ public Plan visitLogicalOlapScan(LogicalOlapScan olapScan, Void context) {
}
Pair<Boolean, List<Slot>> replaced = replaceExpressions(olapScan.getOutput(), false, true);
if (replaced.first) {
return olapScan.withPrunedTypeSlots(replaced.second);
return olapScan.withCachedOutput(replaced.second);
}
return olapScan;
}
Expand Down Expand Up @@ -718,7 +718,7 @@ private void tryRecordReplaceSlots(Plan plan, Object checkObj, Set<Integer> shou
boolean shouldPrune = false;
for (Slot slot : output) {
int slotId = slot.getExprId().asInt();
if (replacedDataTypes.containsKey(slotId)) {
if (slot.getDataType() instanceof NestedColumnPrunable && replacedDataTypes.containsKey(slotId)) {
shouldReplaceSlots.add(slotId);
shouldPrune = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ public class LogicalOlapScan extends LogicalCatalogRelation implements OlapScan,
*/
private final Map<Pair<Long, String>, Slot> cacheSlotWithSlotName;

/**
* this is the cache output to overwrite the output, the priority is higher than cacheSlotWithSlotName
*/
private final Optional<List<Slot>> cachedOutput;

///////////////////////////////////////////////////////////////////////////
// Members for tablet ids.
///////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -161,7 +166,7 @@ public LogicalOlapScan(RelationId id, OlapTable table, List<String> qualifier) {
table.getPartitionIds(), false,
ImmutableList.of(),
-1, false, PreAggStatus.unset(), ImmutableList.of(), ImmutableList.of(),
Maps.newHashMap(), Optional.empty(), false, ImmutableMap.of(),
Maps.newHashMap(), Optional.empty(), Optional.empty(), false, ImmutableMap.of(),
ImmutableList.of(), ImmutableList.of(), ImmutableList.of(),
ImmutableList.of(), Optional.empty(), ImmutableList.of(), Optional.empty(), "");
}
Expand All @@ -170,7 +175,7 @@ public LogicalOlapScan(RelationId id, OlapTable table, List<String> qualifier, L
List<String> hints, Optional<TableSample> tableSample, Collection<Slot> operativeSlots) {
this(id, table, qualifier, Optional.empty(), Optional.empty(),
table.getPartitionIds(), false, tabletIds,
-1, false, PreAggStatus.unset(), ImmutableList.of(), hints, Maps.newHashMap(),
-1, false, PreAggStatus.unset(), ImmutableList.of(), hints, Maps.newHashMap(), Optional.empty(),
tableSample, false, ImmutableMap.of(), ImmutableList.of(), operativeSlots,
ImmutableList.of(), ImmutableList.of(), Optional.empty(), ImmutableList.of(), Optional.empty(), "");
}
Expand All @@ -183,7 +188,7 @@ public LogicalOlapScan(RelationId id, OlapTable table, List<String> qualifier, L
this(id, table, qualifier, Optional.empty(), Optional.empty(),
// must use specifiedPartitions here for prune partition by sql like 'select * from t partition p1'
specifiedPartitions, false, tabletIds,
-1, false, PreAggStatus.unset(), specifiedPartitions, hints, Maps.newHashMap(),
-1, false, PreAggStatus.unset(), specifiedPartitions, hints, Maps.newHashMap(), Optional.empty(),
tableSample, false, ImmutableMap.of(), ImmutableList.of(), operativeSlots,
ImmutableList.of(), ImmutableList.of(), Optional.empty(),
ImmutableList.of(), Optional.empty(), "");
Expand All @@ -199,7 +204,7 @@ public LogicalOlapScan(RelationId id, OlapTable table, List<String> qualifier, L
this(id, table, qualifier, Optional.empty(), Optional.empty(),
selectedPartitionIds, false, tabletIds,
selectedIndexId, true, preAggStatus,
specifiedPartitions, hints, Maps.newHashMap(), tableSample, true, ImmutableMap.of(),
specifiedPartitions, hints, Maps.newHashMap(), Optional.empty(), tableSample, true, ImmutableMap.of(),
ImmutableList.of(), operativeSlots, ImmutableList.of(), ImmutableList.of(), Optional.empty(),
ImmutableList.of(), Optional.empty(), "");
}
Expand All @@ -213,7 +218,7 @@ public LogicalOlapScan(RelationId id, Table table, List<String> qualifier,
List<Long> selectedTabletIds, long selectedIndexId, boolean indexSelected,
PreAggStatus preAggStatus, List<Long> specifiedPartitions,
List<String> hints, Map<Pair<Long, String>, Slot> cacheSlotWithSlotName,
Optional<TableSample> tableSample, boolean directMvScan,
Optional<List<Slot>> cachedOutput, Optional<TableSample> tableSample, boolean directMvScan,
Map<String, Set<List<String>>> colToSubPathsMap, List<Long> specifiedTabletIds,
Collection<Slot> operativeSlots, List<NamedExpression> virtualColumns,
List<OrderKey> scoreOrderKeys, Optional<Long> scoreLimit,
Expand Down Expand Up @@ -245,6 +250,7 @@ public LogicalOlapScan(RelationId id, Table table, List<String> qualifier,
this.hints = Objects.requireNonNull(hints, "hints can not be null");
this.cacheSlotWithSlotName = Objects.requireNonNull(cacheSlotWithSlotName,
"mvNameToSlot can not be null");
this.cachedOutput = Objects.requireNonNull(cachedOutput, "cachedOutput can not be null");
this.tableSample = tableSample;
this.directMvScan = directMvScan;
this.colToSubPathsMap = colToSubPathsMap;
Expand Down Expand Up @@ -337,8 +343,9 @@ public LogicalOlapScan withGroupExpression(Optional<GroupExpression> groupExpres
groupExpression, Optional.of(getLogicalProperties()),
selectedPartitionIds, partitionPruned, selectedTabletIds,
selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions,
hints, cacheSlotWithSlotName, tableSample, directMvScan, colToSubPathsMap, manuallySpecifiedTabletIds,
operativeSlots, virtualColumns, scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
hints, cacheSlotWithSlotName, cachedOutput, tableSample, directMvScan,
colToSubPathsMap, manuallySpecifiedTabletIds, operativeSlots, virtualColumns,
scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
}

@Override
Expand All @@ -347,8 +354,9 @@ public Plan withGroupExprLogicalPropChildren(Optional<GroupExpression> groupExpr
return new LogicalOlapScan(relationId, (Table) table, qualifier, groupExpression, logicalProperties,
selectedPartitionIds, partitionPruned, selectedTabletIds,
selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions,
hints, cacheSlotWithSlotName, tableSample, directMvScan, colToSubPathsMap, manuallySpecifiedTabletIds,
operativeSlots, virtualColumns, scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
hints, cacheSlotWithSlotName, cachedOutput, tableSample, directMvScan,
colToSubPathsMap, manuallySpecifiedTabletIds, operativeSlots, virtualColumns,
scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
}

/**
Expand All @@ -359,8 +367,9 @@ public LogicalOlapScan withSelectedPartitionIds(List<Long> selectedPartitionIds)
Optional.empty(), Optional.of(getLogicalProperties()),
selectedPartitionIds, true, selectedTabletIds,
selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions,
hints, cacheSlotWithSlotName, tableSample, directMvScan, colToSubPathsMap, manuallySpecifiedTabletIds,
operativeSlots, virtualColumns, scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
hints, cacheSlotWithSlotName, cachedOutput, tableSample, directMvScan,
colToSubPathsMap, manuallySpecifiedTabletIds, operativeSlots, virtualColumns,
scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
}

/**
Expand All @@ -373,7 +382,7 @@ public LogicalOlapScan withMaterializedIndexSelected(long indexId) {
Optional.empty(), Optional.of(getLogicalProperties()),
selectedPartitionIds, partitionPruned, selectedTabletIds,
indexId, true, PreAggStatus.unset(), manuallySpecifiedPartitions, hints, cacheSlotWithSlotName,
tableSample, directMvScan, colToSubPathsMap, manuallySpecifiedTabletIds,
cachedOutput, tableSample, directMvScan, colToSubPathsMap, manuallySpecifiedTabletIds,
operativeSlots, virtualColumns, scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
}

Expand All @@ -385,8 +394,9 @@ public LogicalOlapScan withSelectedTabletIds(List<Long> selectedTabletIds) {
Optional.empty(), Optional.of(getLogicalProperties()),
selectedPartitionIds, partitionPruned, selectedTabletIds,
selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions,
hints, cacheSlotWithSlotName, tableSample, directMvScan, colToSubPathsMap, manuallySpecifiedTabletIds,
operativeSlots, virtualColumns, scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
hints, cacheSlotWithSlotName, cachedOutput, tableSample, directMvScan,
colToSubPathsMap, manuallySpecifiedTabletIds, operativeSlots, virtualColumns, scoreOrderKeys,
scoreLimit, annOrderKeys, annLimit, tableAlias);
}

/**
Expand All @@ -397,8 +407,9 @@ public LogicalOlapScan withPreAggStatus(PreAggStatus preAggStatus) {
Optional.empty(), Optional.of(getLogicalProperties()),
selectedPartitionIds, partitionPruned, selectedTabletIds,
selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions,
hints, cacheSlotWithSlotName, tableSample, directMvScan, colToSubPathsMap, manuallySpecifiedTabletIds,
operativeSlots, virtualColumns, scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
hints, cacheSlotWithSlotName, cachedOutput, tableSample, directMvScan,
colToSubPathsMap, manuallySpecifiedTabletIds, operativeSlots, virtualColumns,
scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
}

/**
Expand All @@ -409,8 +420,9 @@ public LogicalOlapScan withColToSubPathsMap(Map<String, Set<List<String>>> colTo
Optional.empty(), Optional.empty(),
selectedPartitionIds, partitionPruned, selectedTabletIds,
selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions,
hints, cacheSlotWithSlotName, tableSample, directMvScan, colToSubPathsMap, manuallySpecifiedTabletIds,
operativeSlots, virtualColumns, scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
hints, cacheSlotWithSlotName, cachedOutput, tableSample, directMvScan,
colToSubPathsMap, manuallySpecifiedTabletIds, operativeSlots, virtualColumns,
scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
}

/**
Expand All @@ -421,8 +433,9 @@ public LogicalOlapScan withManuallySpecifiedTabletIds(List<Long> manuallySpecifi
Optional.empty(), Optional.of(getLogicalProperties()),
selectedPartitionIds, partitionPruned, selectedTabletIds,
selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions,
hints, cacheSlotWithSlotName, tableSample, directMvScan, colToSubPathsMap, manuallySpecifiedTabletIds,
operativeSlots, virtualColumns, scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
hints, cacheSlotWithSlotName, cachedOutput, tableSample, directMvScan,
colToSubPathsMap, manuallySpecifiedTabletIds, operativeSlots, virtualColumns,
scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
}

@Override
Expand All @@ -432,8 +445,9 @@ public LogicalOlapScan withRelationId(RelationId relationId) {
Optional.empty(), Optional.empty(),
selectedPartitionIds, false, selectedTabletIds,
selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions,
hints, Maps.newHashMap(), tableSample, directMvScan, colToSubPathsMap, selectedTabletIds,
operativeSlots, virtualColumns, scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
hints, Maps.newHashMap(), Optional.empty(), tableSample, directMvScan,
colToSubPathsMap, selectedTabletIds, operativeSlots, virtualColumns, scoreOrderKeys,
scoreLimit, annOrderKeys, annLimit, tableAlias);
}

@Override
Expand All @@ -442,8 +456,9 @@ public LogicalOlapScan withTableAlias(String tableAlias) {
Optional.empty(), Optional.of(getLogicalProperties()),
selectedPartitionIds, partitionPruned, selectedTabletIds,
selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions,
hints, cacheSlotWithSlotName, tableSample, directMvScan, colToSubPathsMap, manuallySpecifiedTabletIds,
operativeSlots, virtualColumns, scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
hints, cacheSlotWithSlotName, cachedOutput, tableSample, directMvScan,
colToSubPathsMap, manuallySpecifiedTabletIds, operativeSlots, virtualColumns,
scoreOrderKeys, scoreLimit, annOrderKeys, annLimit, tableAlias);
}

/**
Expand All @@ -461,7 +476,7 @@ public LogicalOlapScan withVirtualColumns(List<NamedExpression> virtualColumns)
groupExpression, Optional.of(logicalProperties),
selectedPartitionIds, partitionPruned, selectedTabletIds,
selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions,
hints, cacheSlotWithSlotName, tableSample, directMvScan, colToSubPathsMap,
hints, cacheSlotWithSlotName, cachedOutput, tableSample, directMvScan, colToSubPathsMap,
manuallySpecifiedTabletIds, operativeSlots, virtualColumns, scoreOrderKeys, scoreLimit,
annOrderKeys, annLimit, tableAlias);
}
Expand All @@ -485,7 +500,7 @@ public LogicalOlapScan withVirtualColumnsAndTopN(
groupExpression, Optional.of(logicalProperties),
selectedPartitionIds, partitionPruned, selectedTabletIds,
selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions,
hints, cacheSlotWithSlotName, tableSample, directMvScan, colToSubPathsMap,
hints, cacheSlotWithSlotName, cachedOutput, tableSample, directMvScan, colToSubPathsMap,
manuallySpecifiedTabletIds, operativeSlots, virtualColumns, scoreOrderKeys, scoreLimit,
annOrderKeys, annLimit, tableAlias);
}
Expand Down Expand Up @@ -533,6 +548,9 @@ public Optional<String> getSelectedMaterializedIndexName() {

@Override
public List<Slot> computeOutput() {
if (cachedOutput.isPresent()) {
return cachedOutput.get();
}
if (selectedIndexId != ((OlapTable) table).getBaseIndexId()) {
return getOutputByIndex(selectedIndexId);
}
Expand Down Expand Up @@ -817,7 +835,7 @@ public CatalogRelation withOperativeSlots(Collection<Slot> operativeSlots) {
groupExpression, Optional.of(getLogicalProperties()),
selectedPartitionIds, partitionPruned, selectedTabletIds,
selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions,
hints, cacheSlotWithSlotName, tableSample, directMvScan, colToSubPathsMap,
hints, cacheSlotWithSlotName, cachedOutput, tableSample, directMvScan, colToSubPathsMap,
manuallySpecifiedTabletIds, operativeSlots, virtualColumns, scoreOrderKeys, scoreLimit,
annOrderKeys, annLimit, tableAlias);
}
Expand Down Expand Up @@ -852,19 +870,13 @@ private Map<Slot, Slot> constructReplaceMap(MTMV mtmv) {
return replaceMap;
}

/** withPrunedTypeSlots */
public LogicalOlapScan withPrunedTypeSlots(List<Slot> outputSlots) {
Map<Pair<Long, String>, Slot> replaceSlotMap = new HashMap<>();
for (Slot outputSlot : outputSlots) {
Pair<Long, String> key = Pair.of(selectedIndexId, outputSlot.getName());
replaceSlotMap.put(key, outputSlot);
}

/** withCachedOutput */
public LogicalOlapScan withCachedOutput(List<Slot> outputSlots) {
return new LogicalOlapScan(relationId, (Table) table, qualifier,
groupExpression, Optional.empty(),
selectedPartitionIds, partitionPruned, selectedTabletIds,
selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions,
hints, replaceSlotMap, tableSample, directMvScan, colToSubPathsMap,
hints, cacheSlotWithSlotName, Optional.of(outputSlots), tableSample, directMvScan, colToSubPathsMap,
manuallySpecifiedTabletIds, operativeSlots, virtualColumns, scoreOrderKeys, scoreLimit,
annOrderKeys, annLimit, tableAlias);
}
Expand Down
Loading
Loading