Code review comment: Why still call set method here?

Code under review:
public List<OptExpression> transform(OptExpression input, OptimizerContext context) {
        LogicalScanOperator scanOperator = (LogicalScanOperator) input.getOp();
        ColumnRefSet requiredOutputColumns = context.getTaskContext().get(0).getRequiredColumns();

        Set<ColumnRefOperator> outputColumns =
                scanOperator.getColRefToColumnMetaMap().keySet().stream().filter(requiredOutputColumns::contains)
                        .collect(Collectors.toSet());
        outputColumns.addAll(Utils.extractColumnRef(scanOperator.getPredicate()));

        if (outputColumns.size() == 0) {
            List<ColumnRefOperator> columnRefOperatorList =
                    new ArrayList<>(scanOperator.getColRefToColumnMetaMap().keySet());

            int smallestIndex = -1;
            int smallestColumnLength = Integer.MAX_VALUE;
            for (int index = 0; index < columnRefOperatorList.size(); ++index) {
                if (smallestIndex == -1) {
                    smallestIndex = index;
                }
                Type columnType = columnRefOperatorList.get(index).getType();
                if (columnType.isScalarType()) {
                    int columnLength = columnType.getSlotSize();
                    if (columnLength < smallestColumnLength) {
                        smallestIndex = index;
                        smallestColumnLength = columnLength;
                    }
                }
            }
            Preconditions.checkArgument(smallestIndex != -1);
            outputColumns.add(columnRefOperatorList.get(smallestIndex));
        }

        if (scanOperator.getColRefToColumnMetaMap().keySet().equals(outputColumns)) {
            return Collections.emptyList();
        } else {
            Map<ColumnRefOperator, Column> newColumnRefMap = outputColumns.stream()
                    .collect(Collectors.toMap(identity(), scanOperator.getColRefToColumnMetaMap()::get));
            if (scanOperator instanceof LogicalOlapScanOperator) {
                LogicalOlapScanOperator olapScanOperator = (LogicalOlapScanOperator) scanOperator;
                LogicalOlapScanOperator newScanOperator = new LogicalOlapScanOperator(
                        ((LogicalOlapScanOperator) scanOperator).getOlapTable(),
                        new ArrayList<>(outputColumns),
                        newColumnRefMap,
                        scanOperator.getColumnMetaToColRefMap(),
                        ((LogicalOlapScanOperator) scanOperator).getDistributionSpec(),
                        scanOperator.getLimit(),
                        scanOperator.getPredicate());
                newScanOperator.setSelectedIndexId(olapScanOperator.getSelectedIndexId());
                newScanOperator.setSelectedPartitionId(olapScanOperator.getSelectedPartitionId());
                newScanOperator.setSelectedTabletId(Lists.newArrayList(olapScanOperator.getSelectedTabletId()));
                newScanOperator.setPartitionNames(olapScanOperator.getPartitionNames());
                newScanOperator.setHintsTabletIds(olapScanOperator.getHintsTabletIds());

                return Lists.newArrayList(new OptExpression(newScanOperator));
            } else {
                try {
                    Class<? extends LogicalScanOperator> classType = scanOperator.getClass();
                    LogicalScanOperator newScanOperator =
                            classType.getConstructor(Table.class, List.class, Map.class, Map.class, long.class,
                                    ScalarOperator.class).newInstance(
                                    scanOperator.getTable(), new ArrayList<>(outputColumns),
                                    newColumnRefMap,
                                    scanOperator.getColumnMetaToColRefMap(),
                                    scanOperator.getLimit(),
                                    scanOperator.getPredicate());

                    return Lists.newArrayList(new OptExpression(newScanOperator));
                } catch (Exception e) {
                    throw new StarRocksPlannerException(e.getMessage(), ErrorType.INTERNAL_ERROR);
                }
            }
        }
    }

Line commented on: newScanOperator.setSelectedIndexId(olapScanOperator.getSelectedIndexId());

Revised code:
public List<OptExpression> transform(OptExpression input, OptimizerContext context) {
        LogicalScanOperator scanOperator = (LogicalScanOperator) input.getOp();
        ColumnRefSet requiredOutputColumns = context.getTaskContext().get(0).getRequiredColumns();

        
        
        Set<ColumnRefOperator> outputColumns =
                scanOperator.getColRefToColumnMetaMap().keySet().stream().filter(requiredOutputColumns::contains)
                        .collect(Collectors.toSet());
        outputColumns.addAll(Utils.extractColumnRef(scanOperator.getPredicate()));

        if (outputColumns.size() == 0) {
            List<ColumnRefOperator> columnRefOperatorList =
                    new ArrayList<>(scanOperator.getColRefToColumnMetaMap().keySet());

            int smallestIndex = -1;
            int smallestColumnLength = Integer.MAX_VALUE;
            for (int index = 0; index < columnRefOperatorList.size(); ++index) {
                if (smallestIndex == -1) {
                    smallestIndex = index;
                }
                Type columnType = columnRefOperatorList.get(index).getType();
                if (columnType.isScalarType()) {
                    int columnLength = columnType.getSlotSize();
                    if (columnLength < smallestColumnLength) {
                        smallestIndex = index;
                        smallestColumnLength = columnLength;
                    }
                }
            }
            Preconditions.checkArgument(smallestIndex != -1);
            outputColumns.add(columnRefOperatorList.get(smallestIndex));
        }

        if (scanOperator.getColRefToColumnMetaMap().keySet().equals(outputColumns)) {
            return Collections.emptyList();
        } else {
            Map<ColumnRefOperator, Column> newColumnRefMap = outputColumns.stream()
                    .collect(Collectors.toMap(identity(), scanOperator.getColRefToColumnMetaMap()::get));
            if (scanOperator instanceof LogicalOlapScanOperator) {
                LogicalOlapScanOperator olapScanOperator = (LogicalOlapScanOperator) scanOperator;
                LogicalOlapScanOperator newScanOperator = new LogicalOlapScanOperator(
                        olapScanOperator.getTable(),
                        new ArrayList<>(outputColumns),
                        newColumnRefMap,
                        olapScanOperator.getColumnMetaToColRefMap(),
                        olapScanOperator.getDistributionSpec(),
                        olapScanOperator.getLimit(),
                        olapScanOperator.getPredicate(),
                        olapScanOperator.getSelectedIndexId(),
                        olapScanOperator.getSelectedPartitionId(),
                        olapScanOperator.getPartitionNames(),
                        olapScanOperator.getSelectedTabletId(),
                        olapScanOperator.getHintsTabletIds());

                return Lists.newArrayList(new OptExpression(newScanOperator));
            } else {
                try {
                    Class<? extends LogicalScanOperator> classType = scanOperator.getClass();
                    LogicalScanOperator newScanOperator =
                            classType.getConstructor(Table.class, List.class, Map.class, Map.class, long.class,
                                    ScalarOperator.class).newInstance(
                                    scanOperator.getTable(), new ArrayList<>(outputColumns),
                                    newColumnRefMap,
                                    scanOperator.getColumnMetaToColRefMap(),
                                    scanOperator.getLimit(),
                                    scanOperator.getPredicate());

                    return Lists.newArrayList(new OptExpression(newScanOperator));
                } catch (Exception e) {
                    throw new StarRocksPlannerException(e.getMessage(), ErrorType.INTERNAL_ERROR);
                }
            }
        }
    }