You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2023/01/17 07:51:47 UTC

[GitHub] [doris] wangshuo128 commented on a diff in pull request #15976: [fix](nereids)fix bug of invalid column in olap scan node when a materialized view is selected

wangshuo128 commented on code in PR #15976:
URL: https://github.com/apache/doris/pull/15976#discussion_r1071863398


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java:
##########
@@ -214,12 +215,27 @@ public LogicalOlapScan withSelectedPartitionIds(List<Long> selectedPartitionIds)
                 selectedIndexId, indexSelected, preAggStatus, manuallySpecifiedPartitions);
     }
 
+    /**
+     * create a logical scan node based on selected index
+     */
     public LogicalOlapScan withMaterializedIndexSelected(PreAggStatus preAgg, long indexId) {
-        return new LogicalOlapScan(id, (Table) table, qualifier, Optional.empty(), Optional.of(getLogicalProperties()),
+        LogicalProperties newLogicalProperties = new LogicalProperties(
+                Suppliers.ofInstance(getLogicalProperties().getOutput()),
+                Suppliers.ofInstance(
+                        filterSlotsOfSelectedIndex(getLogicalProperties().getNonUserVisibleOutput(), indexId)));
+        return new LogicalOlapScan(id, (Table) table, qualifier, Optional.empty(), Optional.of(newLogicalProperties),
                 selectedPartitionIds, partitionPruned, selectedTabletIds, tabletPruned,
                 indexId, true, preAgg, manuallySpecifiedPartitions);
     }
 
+    private List<Slot> filterSlotsOfSelectedIndex(List<Slot> slots, long indexId) {
+        return slots.stream()
+                .filter(slot -> ((SlotReference) slot).getColumn().isPresent() && getTable()
+                        .getIndexIdToMeta().get(indexId).getSchema()
+                        .contains(((SlotReference) slot).getColumn().get())).collect(
+                        Collectors.toList());

Review Comment:
   ```suggestion
           ImmutableSet<Column> selectIndexColumns = ImmutableSet.copyOf(
                   getTable().getIndexIdToMeta().get(indexId).getSchema());
           return slots.stream()
                   .filter(slot -> ((SlotReference) slot).getColumn().isPresent()
                           && selectIndexColumns.contains(((SlotReference) slot).getColumn().get()))
                   .collect(ImmutableList.toImmutableList());
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org