Code review comment: ```suggestion             this.logicalQuery = (LogicalPlan) logicalQuery.withChildren(cte.get().withChildren(this.logcalQuery.child(0))); ```

Code under review:
public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
        if (!ctx.getSessionVariable().isEnableNereidsDML()) {
            try {
                ctx.getSessionVariable().enableFallbackToOriginalPlannerOnce();
            } catch (Exception e) {
                throw new AnalysisException("failed to set fallback to original planner to true", e);
            }
            throw new AnalysisException("Nereids DML is disabled, will try to fall back to the original planner");
        }

        TableIf targetTableIf = InsertUtils.getTargetTable(logicalQuery, ctx);
        if (!(targetTableIf instanceof OlapTable || targetTableIf instanceof HMSExternalTable)) {
            throw new AnalysisException("insert into overwrite only support OLAP and HMS table."
                    + " But current table type is " + targetTableIf.getType());
        }
        this.logicalQuery = (LogicalPlan) InsertUtils.normalizePlan(logicalQuery, targetTableIf);
        if (cte.isPresent()) {
            this.logicalQuery = (LogicalPlan) logicalQuery.withChildren(cte.get());
        }

        LogicalPlanAdapter logicalPlanAdapter = new LogicalPlanAdapter(logicalQuery, ctx.getStatementContext());
        NereidsPlanner planner = new NereidsPlanner(ctx.getStatementContext());
        planner.plan(logicalPlanAdapter, ctx.getSessionVariable().toThrift());
        executor.checkBlockRules();
        if (ctx.getConnectType() == ConnectType.MYSQL && ctx.getMysqlChannel() != null) {
            ctx.getMysqlChannel().reset();
        }

        Optional<TreeNode<?>> plan = (planner.getPhysicalPlan()
                .<TreeNode<?>>collect(node -> node instanceof PhysicalTableSink)).stream().findAny();
        Preconditions.checkArgument(plan.isPresent(), "insert into command must contain OlapTableSinkNode");
        PhysicalTableSink<?> physicalTableSink = ((PhysicalTableSink<?>) plan.get());
        TableIf targetTable = physicalTableSink.getTargetTable();
        List<String> partitionNames;
        if (physicalTableSink instanceof PhysicalOlapTableSink) {
            InternalDatabaseUtil
                    .checkDatabase(((OlapTable) targetTable).getQualifiedDbName(), ConnectContext.get());
            
            if (!Env.getCurrentEnv().getAccessManager()
                    .checkTblPriv(ConnectContext.get(), targetTable.getDatabase().getCatalog().getName(),
                            ((OlapTable) targetTable).getQualifiedDbName(),
                            targetTable.getName(), PrivPredicate.LOAD)) {
                ErrorReport.reportAnalysisException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR, "LOAD",
                        ConnectContext.get().getQualifiedUser(), ConnectContext.get().getRemoteIP(),
                        ((OlapTable) targetTable).getQualifiedDbName() + ": " + targetTable.getName());
            }
            ConnectContext.get().setSkipAuth(true);
            partitionNames = ((UnboundTableSink<?>) logicalQuery).getPartitions();
            if (CollectionUtils.isEmpty(partitionNames)) {
                partitionNames = Lists.newArrayList(targetTable.getPartitionNames());
            }
        } else {
            
            partitionNames = new ArrayList<>();
        }
        long taskId = 0;
        try {
            if (isAutoDetectOverwrite()) {
                
                taskId = Env.getCurrentEnv().getInsertOverwriteManager().preRegisterTask();
                
                
                insertInto(ctx, executor, taskId);
                Env.getCurrentEnv().getInsertOverwriteManager().taskGroupSuccess(taskId);
            } else {
                List<String> tempPartitionNames = InsertOverwriteUtil.generateTempPartitionNames(partitionNames);
                taskId = Env.getCurrentEnv().getInsertOverwriteManager()
                        .registerTask(targetTable.getDatabase().getId(), targetTable.getId(), tempPartitionNames);
                InsertOverwriteUtil.addTempPartitions(targetTable, partitionNames, tempPartitionNames);
                insertInto(ctx, executor, tempPartitionNames);
                InsertOverwriteUtil.replacePartition(targetTable, partitionNames, tempPartitionNames);
                Env.getCurrentEnv().getInsertOverwriteManager().taskSuccess(taskId);
            }
        } catch (Exception e) {
            LOG.warn("insert into overwrite failed");
            if (isAutoDetectOverwrite()) {
                Env.getCurrentEnv().getInsertOverwriteManager().taskGroupFail(taskId);
            } else {
                Env.getCurrentEnv().getInsertOverwriteManager().taskFail(taskId);
            }
            throw e;
        } finally {
            ConnectContext.get().setSkipAuth(false);
        }
    }

Line commented on: this.logicalQuery = (LogicalPlan) logicalQuery.withChildren(cte.get());

Revised code:
public void run(ConnectContext ctx, StmtExecutor executor) throws Exception {
        if (!ctx.getSessionVariable().isEnableNereidsDML()) {
            try {
                ctx.getSessionVariable().enableFallbackToOriginalPlannerOnce();
            } catch (Exception e) {
                throw new AnalysisException("failed to set fallback to original planner to true", e);
            }
            throw new AnalysisException("Nereids DML is disabled, will try to fall back to the original planner");
        }

        TableIf targetTableIf = InsertUtils.getTargetTable(logicalQuery, ctx);
        if (!(targetTableIf instanceof OlapTable || targetTableIf instanceof HMSExternalTable)) {
            throw new AnalysisException("insert into overwrite only support OLAP and HMS table."
                    + " But current table type is " + targetTableIf.getType());
        }
        this.logicalQuery = (LogicalPlan) InsertUtils.normalizePlan(logicalQuery, targetTableIf);
        if (cte.isPresent()) {
            this.logicalQuery = (LogicalPlan) logicalQuery.withChildren(cte.get().withChildren(
                    this.logicalQuery.child(0)));
        }

        LogicalPlanAdapter logicalPlanAdapter = new LogicalPlanAdapter(logicalQuery, ctx.getStatementContext());
        NereidsPlanner planner = new NereidsPlanner(ctx.getStatementContext());
        planner.plan(logicalPlanAdapter, ctx.getSessionVariable().toThrift());
        executor.checkBlockRules();
        if (ctx.getConnectType() == ConnectType.MYSQL && ctx.getMysqlChannel() != null) {
            ctx.getMysqlChannel().reset();
        }

        Optional<TreeNode<?>> plan = (planner.getPhysicalPlan()
                .<TreeNode<?>>collect(node -> node instanceof PhysicalTableSink)).stream().findAny();
        Preconditions.checkArgument(plan.isPresent(), "insert into command must contain OlapTableSinkNode");
        PhysicalTableSink<?> physicalTableSink = ((PhysicalTableSink<?>) plan.get());
        TableIf targetTable = physicalTableSink.getTargetTable();
        List<String> partitionNames;
        if (physicalTableSink instanceof PhysicalOlapTableSink) {
            InternalDatabaseUtil
                    .checkDatabase(((OlapTable) targetTable).getQualifiedDbName(), ConnectContext.get());
            
            if (!Env.getCurrentEnv().getAccessManager()
                    .checkTblPriv(ConnectContext.get(), targetTable.getDatabase().getCatalog().getName(),
                            ((OlapTable) targetTable).getQualifiedDbName(),
                            targetTable.getName(), PrivPredicate.LOAD)) {
                ErrorReport.reportAnalysisException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR, "LOAD",
                        ConnectContext.get().getQualifiedUser(), ConnectContext.get().getRemoteIP(),
                        ((OlapTable) targetTable).getQualifiedDbName() + ": " + targetTable.getName());
            }
            ConnectContext.get().setSkipAuth(true);
            partitionNames = ((UnboundTableSink<?>) logicalQuery).getPartitions();
            if (CollectionUtils.isEmpty(partitionNames)) {
                partitionNames = Lists.newArrayList(targetTable.getPartitionNames());
            }
        } else {
            
            partitionNames = new ArrayList<>();
        }
        long taskId = 0;
        try {
            if (isAutoDetectOverwrite()) {
                
                taskId = Env.getCurrentEnv().getInsertOverwriteManager().preRegisterTask();
                
                
                insertInto(ctx, executor, taskId);
                Env.getCurrentEnv().getInsertOverwriteManager().taskGroupSuccess(taskId);
            } else {
                List<String> tempPartitionNames = InsertOverwriteUtil.generateTempPartitionNames(partitionNames);
                taskId = Env.getCurrentEnv().getInsertOverwriteManager()
                        .registerTask(targetTable.getDatabase().getId(), targetTable.getId(), tempPartitionNames);
                InsertOverwriteUtil.addTempPartitions(targetTable, partitionNames, tempPartitionNames);
                insertInto(ctx, executor, tempPartitionNames);
                InsertOverwriteUtil.replacePartition(targetTable, partitionNames, tempPartitionNames);
                Env.getCurrentEnv().getInsertOverwriteManager().taskSuccess(taskId);
            }
        } catch (Exception e) {
            LOG.warn("insert into overwrite failed");
            if (isAutoDetectOverwrite()) {
                Env.getCurrentEnv().getInsertOverwriteManager().taskGroupFail(taskId);
            } else {
                Env.getCurrentEnv().getInsertOverwriteManager().taskFail(taskId);
            }
            throw e;
        } finally {
            ConnectContext.get().setSkipAuth(false);
        }
    }