zhengshiJ commented on code in PR #17853: URL: https://github.com/apache/doris/pull/17853#discussion_r1138329039
########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java: ########## @@ -302,23 +306,42 @@ public List<Slot> computeOutput() { @Override public List<Slot> computeNonUserVisibleOutput() { - // if (getTable().getIndexIdToMeta().size() == 1) { - // return ImmutableList.of(); - // } - Set<String> baseSchemaColNames = table.getBaseSchema().stream() - .map(Column::getName) - .collect(Collectors.toSet()); - OlapTable olapTable = (OlapTable) table; - // extra columns in materialized index, such as `mv_bitmap_union_xxx` return olapTable.getVisibleIndexIdToMeta().values() .stream() .filter(index -> index.getIndexId() != ((OlapTable) table).getBaseIndexId()) - .flatMap(index -> index.getSchema() - .stream() - .filter(col -> !baseSchemaColNames.contains(col.getName())) - ) - .map(col -> SlotReference.fromColumn(col, qualified())) + .flatMap(index -> index.getSchema().stream()) + .map(col -> { + if (mvNameToSlot.containsKey(col.getName())) { + return mvNameToSlot.get(col.getName()); + } + Slot slot = SlotReference.fromColumn(col, qualified()); + mvNameToSlot.put(col.getName(), slot); + return slot; + }) + .collect(ImmutableList.toImmutableList()); + } + + /** + * Get the slot under the index, + * and create a new slotReference for the slot that has not appeared in the materialized view. + */ + public List<Slot> getOutputWithIndex(long mvIndex) { Review Comment: done ########## fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/logical/LogicalOlapScan.java: ########## @@ -302,23 +306,42 @@ public List<Slot> computeOutput() { @Override public List<Slot> computeNonUserVisibleOutput() { - // if (getTable().getIndexIdToMeta().size() == 1) { - // return ImmutableList.of(); - // } - Set<String> baseSchemaColNames = table.getBaseSchema().stream() - .map(Column::getName) - .collect(Collectors.toSet()); - OlapTable olapTable = (OlapTable) table; - // extra columns in materialized index, such as `mv_bitmap_union_xxx` return olapTable.getVisibleIndexIdToMeta().values() .stream() .filter(index -> index.getIndexId() != ((OlapTable) table).getBaseIndexId()) - .flatMap(index -> index.getSchema() - .stream() - .filter(col -> !baseSchemaColNames.contains(col.getName())) - ) - .map(col -> SlotReference.fromColumn(col, qualified())) + .flatMap(index -> index.getSchema().stream()) + .map(col -> { + if (mvNameToSlot.containsKey(col.getName())) { + return mvNameToSlot.get(col.getName()); + } + Slot slot = SlotReference.fromColumn(col, qualified()); + mvNameToSlot.put(col.getName(), slot); + return slot; + }) + .collect(ImmutableList.toImmutableList()); + } + + /** + * Get the slot under the index, + * and create a new slotReference for the slot that has not appeared in the materialized view. + */ + public List<Slot> getOutputWithIndex(long mvIndex) { + if (mvIndex == ((OlapTable) table).getBaseIndexId()) { + return getOutput(); + } + + OlapTable olapTable = (OlapTable) table; + return olapTable.getVisibleIndexIdToMeta().get(mvIndex).getSchema() + .stream() + .map(col -> { + if (mvNameToSlot.containsKey(col.getName())) { + return mvNameToSlot.get(col.getName()); + } + Slot slot = SlotReference.fromColumn(col, qualified()); + mvNameToSlot.put(col.getName(), slot); + return slot; Review Comment: done -- 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-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org