This is an automated email from the ASF dual-hosted git repository.

starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 538c2f5238a [Enhancement](nereids) delete translateToLegacyStmt in 
CreateTableLikeCommand (#53871)
538c2f5238a is described below

commit 538c2f5238a41ff0341e7cf387964ea59f4eb3ff
Author: yaoxiao <[email protected]>
AuthorDate: Tue Jul 29 14:05:36 2025 +0800

    [Enhancement](nereids) delete translateToLegacyStmt in 
CreateTableLikeCommand (#53871)
---
 .../main/java/org/apache/doris/catalog/Env.java    | 404 +++++++++++++++++++++
 .../plans/commands/CreateTableLikeCommand.java     |  33 +-
 .../plans/commands/info/CreateTableLikeInfo.java   |  39 +-
 3 files changed, 454 insertions(+), 22 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java 
b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
index 8b6e53e7ce2..7f19c7903a8 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
@@ -203,6 +203,7 @@ import 
org.apache.doris.nereids.trees.plans.commands.UninstallPluginCommand;
 import 
org.apache.doris.nereids.trees.plans.commands.info.AlterMTMVPropertyInfo;
 import org.apache.doris.nereids.trees.plans.commands.info.AlterMTMVRefreshInfo;
 import org.apache.doris.nereids.trees.plans.commands.info.AlterViewInfo;
+import org.apache.doris.nereids.trees.plans.commands.info.CreateTableLikeInfo;
 import org.apache.doris.nereids.trees.plans.commands.info.CreateViewInfo;
 import org.apache.doris.nereids.trees.plans.commands.info.DropMTMVInfo;
 import org.apache.doris.nereids.trees.plans.commands.info.PartitionNamesInfo;
@@ -3941,6 +3942,409 @@ public class Env {
         }
     }
 
+    /**.
+     *
+     * @param getDdlForLike Get schema for 'create table like' or not. when 
true, without hidden columns.
+     */
+    public static void getCreateTableLikeStmt(CreateTableLikeInfo 
createTableLikeInfo, String dbName,
+                                              TableIf table, List<String> 
createTableStmt,
+                                              List<String> addPartitionStmt, 
List<String> createRollupStmt,
+                                              boolean separatePartition,
+                                              boolean hidePassword, boolean 
getDdlForLike, long specificVersion,
+                                              boolean getBriefDdl, boolean 
getDdlForSync) {
+        StringBuilder sb = new StringBuilder();
+
+        // 1. create table
+        // 1.1 view
+        if (table.getType() == TableType.VIEW) {
+            View view = (View) table;
+
+            sb.append("CREATE VIEW `").append(table.getName()).append("`");
+            if (StringUtils.isNotBlank(table.getComment())) {
+                sb.append(" COMMENT '").append(table.getComment()).append("'");
+            }
+            sb.append(" AS ").append(view.getInlineViewDef());
+            createTableStmt.add(sb + ";");
+            return;
+        }
+
+        // 1.2 other table type
+        sb.append("CREATE ");
+        if (table.getType() == TableType.ODBC || table.getType() == 
TableType.MYSQL
+                || table.getType() == TableType.ELASTICSEARCH || 
table.getType() == TableType.BROKER
+                || table.getType() == TableType.HIVE || table.getType() == 
TableType.JDBC) {
+            sb.append("EXTERNAL ");
+        }
+
+        // create table like a temporary table
+        if (createTableLikeInfo.isTemp()) {
+            sb.append("TEMPORARY ");
+        }
+
+        sb.append(table.getType() != TableType.MATERIALIZED_VIEW ? "TABLE " : 
"MATERIALIZED VIEW ");
+
+        if (!Strings.isNullOrEmpty(dbName)) {
+            sb.append("`").append(dbName).append("`.");
+        }
+        if (table.isTemporary()) {
+            
sb.append("`").append(Util.getTempTableDisplayName(table.getName())).append("`");
+        } else {
+            sb.append("`").append(table.getName()).append("`");
+        }
+
+
+        sb.append(" (\n");
+        int idx = 0;
+        List<Column> columns = table.getBaseSchema(false);
+        for (Column column : columns) {
+            if (idx++ != 0) {
+                sb.append(",\n");
+            }
+            // There MUST BE 2 space in front of each column description line
+            // sqlalchemy requires this to parse SHOW CREATE TABLE stmt.
+            if (table.isManagedTable()) {
+                sb.append("  ").append(
+                        column.toSql(((OlapTable) table).getKeysType() == 
KeysType.UNIQUE_KEYS, true));
+            } else {
+                sb.append("  ").append(column.toSql());
+            }
+        }
+        if (table instanceof OlapTable) {
+            OlapTable olapTable = (OlapTable) table;
+            if (CollectionUtils.isNotEmpty(olapTable.getIndexes())) {
+                for (Index index : olapTable.getIndexes()) {
+                    sb.append(",\n");
+                    sb.append("  ").append(index.toSql());
+                }
+            }
+        }
+        sb.append("\n) ENGINE=");
+        sb.append(table.getType().name());
+
+        if (table instanceof OlapTable) {
+            OlapTable olapTable = (OlapTable) table;
+            // keys
+            String keySql = olapTable.getKeysType().toSql();
+            if (olapTable.isDuplicateWithoutKey()) {
+                // after #18621, use can create a DUP_KEYS olap table without 
key columns
+                // and get a ddl schema without key type and key columns
+            } else {
+                sb.append("\n").append(keySql).append("(");
+                List<String> keysColumnNames = Lists.newArrayList();
+                Map<Integer, String> clusterKeysColumnNamesToId = new 
TreeMap<>();
+                for (Column column : olapTable.getBaseSchema()) {
+                    if (column.isKey()) {
+                        keysColumnNames.add("`" + column.getName() + "`");
+                    }
+                    if (column.isClusterKey()) {
+                        
clusterKeysColumnNamesToId.put(column.getClusterKeyId(), column.getName());
+                    }
+                }
+                sb.append(Joiner.on(", ").join(keysColumnNames)).append(")");
+                // show cluster keys
+                if (!clusterKeysColumnNamesToId.isEmpty()) {
+                    sb.append("\n").append("CLUSTER BY (`");
+                    sb.append(Joiner.on("`, 
`").join(clusterKeysColumnNamesToId.values())).append("`)");
+                }
+            }
+
+            if (specificVersion != -1) {
+                // for copy tablet operation
+                sb.append("\nDISTRIBUTED BY 
HASH(").append(olapTable.getBaseSchema().get(0).getName())
+                    .append(") BUCKETS 1");
+                sb.append("\nPROPERTIES (\n" + "\"replication_num\" = 
\"1\",\n" + "\"version_info\" = \""
+                        + specificVersion + "\"\n" + ")");
+                createTableStmt.add(sb + ";");
+                return;
+            }
+
+            addTableComment(olapTable, sb);
+
+            // partition
+            PartitionInfo partitionInfo = olapTable.getPartitionInfo();
+            List<Long> partitionId = null;
+            if (separatePartition) {
+                partitionId = Lists.newArrayList();
+            }
+            if (!getBriefDdl && (partitionInfo.getType() == PartitionType.RANGE
+                    || partitionInfo.getType() == PartitionType.LIST)) {
+                sb.append("\n").append(partitionInfo.toSql(olapTable, 
partitionId));
+            }
+
+            // distribution
+            DistributionInfo distributionInfo = 
olapTable.getDefaultDistributionInfo();
+            sb.append("\n").append(distributionInfo.toSql());
+
+            // rollup index
+            ArrayList<String> rollupNames = 
createTableLikeInfo.getRollupNames();
+            boolean withAllRollup = createTableLikeInfo.isWithAllRollup();
+            List<Long> addIndexIdList = Lists.newArrayList();
+
+            if (!CollectionUtils.isEmpty(rollupNames)) {
+                for (String rollupName : rollupNames) {
+                    addIndexIdList.add(olapTable.getIndexIdByName(rollupName));
+                }
+            } else if (withAllRollup) {
+                addIndexIdList = olapTable.getIndexIdListExceptBaseIndex();
+            }
+
+            if (!addIndexIdList.isEmpty()) {
+                sb.append("\n").append("rollup (");
+            }
+
+            int size = addIndexIdList.size();
+            int index = 1;
+            for (long indexId : addIndexIdList) {
+                String indexName = olapTable.getIndexNameById(indexId);
+                sb.append("\n").append(indexName).append("(");
+                List<Column> indexSchema = 
olapTable.getSchemaByIndexId(indexId, false);
+                for (int i = 0; i < indexSchema.size(); i++) {
+                    Column column = indexSchema.get(i);
+                    sb.append(column.getName());
+                    if (i != indexSchema.size() - 1) {
+                        sb.append(", ");
+                    }
+                }
+                if (index != size) {
+                    sb.append("),");
+                } else {
+                    sb.append(")");
+                    sb.append("\n)");
+                }
+                index++;
+            }
+
+            // with all rollup
+            do {
+                if (!getDdlForSync) {
+                    break;
+                }
+                List<Long> indexIds = new 
ArrayList<>(olapTable.getIndexIdToMeta().keySet());
+                if (indexIds.size() == 1 && indexIds.get(0) == 
olapTable.getBaseIndexId()) {
+                    break;
+                }
+                indexIds = indexIds.stream().filter(item -> item != 
olapTable.getBaseIndexId())
+                    .collect(Collectors.toList());
+                sb.append("\nROLLUP (\n");
+                for (int i = 0; i < indexIds.size(); i++) {
+                    Long indexId = indexIds.get(i);
+
+                    MaterializedIndexMeta materializedIndexMeta = 
olapTable.getIndexIdToMeta().get(indexId);
+                    String indexName = olapTable.getIndexNameById(indexId);
+                    sb.append(indexName).append(" (");
+
+                    List<Column> indexSchema = 
materializedIndexMeta.getSchema();
+                    for (int j = 0; j < indexSchema.size(); j++) {
+                        Column column = indexSchema.get(j);
+                        sb.append(column.getName());
+                        if (j != indexSchema.size() - 1) {
+                            sb.append(", ");
+                        }
+                    }
+                    sb.append(")");
+                    if (i != indexIds.size() - 1) {
+                        sb.append(",\n");
+                    }
+                }
+                sb.append("\n)");
+            } while (false);
+
+            // properties
+            sb.append("\nPROPERTIES (\n");
+            addOlapTablePropertyInfo(olapTable, sb, separatePartition, 
getDdlForSync, partitionId);
+            sb.append("\n)");
+        } else if (table.getType() == TableType.MYSQL) {
+            MysqlTable mysqlTable = (MysqlTable) table;
+
+            addTableComment(mysqlTable, sb);
+
+            // properties
+            sb.append("\nPROPERTIES (\n");
+            if (mysqlTable.getOdbcCatalogResourceName() == null) {
+                sb.append("\"host\" = 
\"").append(mysqlTable.getHost()).append("\",\n");
+                sb.append("\"port\" = 
\"").append(mysqlTable.getPort()).append("\",\n");
+                sb.append("\"user\" = 
\"").append(mysqlTable.getUserName()).append("\",\n");
+                sb.append("\"password\" = \"").append(hidePassword ? "" : 
mysqlTable.getPasswd()).append("\",\n");
+                sb.append("\"charset\" = 
\"").append(mysqlTable.getCharset()).append("\",\n");
+            } else {
+                sb.append("\"odbc_catalog_resource\" = 
\"").append(mysqlTable.getOdbcCatalogResourceName())
+                    .append("\",\n");
+            }
+            sb.append("\"database\" = 
\"").append(mysqlTable.getMysqlDatabaseName()).append("\",\n");
+            sb.append("\"table\" = 
\"").append(mysqlTable.getMysqlTableName()).append("\"\n");
+            sb.append(")");
+        } else if (table.getType() == TableType.ODBC) {
+            OdbcTable odbcTable = (OdbcTable) table;
+
+            addTableComment(odbcTable, sb);
+
+            // properties
+            sb.append("\nPROPERTIES (\n");
+            if (odbcTable.getOdbcCatalogResourceName() == null) {
+                sb.append("\"host\" = 
\"").append(odbcTable.getHost()).append("\",\n");
+                sb.append("\"port\" = 
\"").append(odbcTable.getPort()).append("\",\n");
+                sb.append("\"user\" = 
\"").append(odbcTable.getUserName()).append("\",\n");
+                sb.append("\"password\" = \"").append(hidePassword ? "" : 
odbcTable.getPasswd()).append("\",\n");
+                sb.append("\"driver\" = 
\"").append(odbcTable.getOdbcDriver()).append("\",\n");
+                sb.append("\"odbc_type\" = 
\"").append(odbcTable.getOdbcTableTypeName()).append("\",\n");
+                sb.append("\"charest\" = 
\"").append(odbcTable.getCharset()).append("\",\n");
+            } else {
+                sb.append("\"odbc_catalog_resource\" = 
\"").append(odbcTable.getOdbcCatalogResourceName())
+                    .append("\",\n");
+            }
+            sb.append("\"database\" = 
\"").append(odbcTable.getOdbcDatabaseName()).append("\",\n");
+            sb.append("\"table\" = 
\"").append(odbcTable.getOdbcTableName()).append("\"\n");
+            sb.append(")");
+        } else if (table.getType() == TableType.BROKER) {
+            BrokerTable brokerTable = (BrokerTable) table;
+
+            addTableComment(brokerTable, sb);
+
+            // properties
+            sb.append("\nPROPERTIES (\n");
+            sb.append("\"broker_name\" = 
\"").append(brokerTable.getBrokerName()).append("\",\n");
+            sb.append("\"path\" = 
\"").append(Joiner.on(",").join(brokerTable.getEncodedPaths())).append("\",\n");
+            sb.append("\"column_separator\" = 
\"").append(brokerTable.getReadableColumnSeparator()).append("\",\n");
+            sb.append("\"line_delimiter\" = 
\"").append(brokerTable.getReadableLineDelimiter()).append("\",\n");
+            sb.append(")");
+            if (!brokerTable.getBrokerProperties().isEmpty()) {
+                sb.append("\nBROKER PROPERTIES (\n");
+                sb.append(new 
PrintableMap<>(brokerTable.getBrokerProperties(), " = ", true, true,
+                        hidePassword).toString());
+                sb.append("\n)");
+            }
+        } else if (table.getType() == TableType.ELASTICSEARCH) {
+            EsTable esTable = (EsTable) table;
+
+            addTableComment(esTable, sb);
+
+            // partition
+            PartitionInfo partitionInfo = esTable.getPartitionInfo();
+            if (partitionInfo.getType() == PartitionType.RANGE) {
+                sb.append("\n");
+                sb.append("PARTITION BY RANGE(");
+                RangePartitionInfo rangePartitionInfo = (RangePartitionInfo) 
partitionInfo;
+                for (Column column : rangePartitionInfo.getPartitionColumns()) 
{
+                    sb.append("`").append(column.getName()).append("`");
+                }
+                sb.append(")\n()");
+            }
+
+            // properties
+            sb.append("\nPROPERTIES (\n");
+            sb.append("\"hosts\" = 
\"").append(esTable.getHosts()).append("\",\n");
+            sb.append("\"user\" = 
\"").append(esTable.getUserName()).append("\",\n");
+            sb.append("\"password\" = \"").append(hidePassword ? "" : 
esTable.getPasswd()).append("\",\n");
+            sb.append("\"index\" = 
\"").append(esTable.getIndexName()).append("\",\n");
+            if (esTable.getMappingType() != null) {
+                sb.append("\"type\" = 
\"").append(esTable.getMappingType()).append("\",\n");
+            }
+            sb.append("\"enable_docvalue_scan\" = 
\"").append(esTable.isEnableDocValueScan()).append("\",\n");
+            sb.append("\"max_docvalue_fields\" = 
\"").append(esTable.getMaxDocValueFields()).append("\",\n");
+            sb.append("\"enable_keyword_sniff\" = 
\"").append(esTable.isEnableKeywordSniff()).append("\",\n");
+            sb.append("\"nodes_discovery\" = 
\"").append(esTable.isNodesDiscovery()).append("\",\n");
+            sb.append("\"http_ssl_enabled\" = 
\"").append(esTable.isHttpSslEnabled()).append("\",\n");
+            sb.append("\"like_push_down\" = 
\"").append(esTable.isLikePushDown()).append("\"\n");
+            sb.append(")");
+        } else if (table.getType() == TableType.HIVE) {
+            HiveTable hiveTable = (HiveTable) table;
+
+            addTableComment(hiveTable, sb);
+
+            // properties
+            sb.append("\nPROPERTIES (\n");
+            sb.append("\"database\" = 
\"").append(hiveTable.getHiveDb()).append("\",\n");
+            sb.append("\"table\" = 
\"").append(hiveTable.getHiveTable()).append("\",\n");
+            sb.append(new PrintableMap<>(hiveTable.getHiveProperties(), " = ", 
true, true, hidePassword).toString());
+            sb.append("\n)");
+        } else if (table.getType() == TableType.JDBC) {
+            JdbcTable jdbcTable = (JdbcTable) table;
+            addTableComment(jdbcTable, sb);
+            sb.append("\nPROPERTIES (\n");
+            sb.append("\"resource\" = 
\"").append(jdbcTable.getResourceName()).append("\",\n");
+            sb.append("\"table\" = 
\"").append(jdbcTable.getJdbcTable()).append("\",\n");
+            sb.append("\"table_type\" = 
\"").append(jdbcTable.getJdbcTypeName()).append("\"");
+            sb.append("\n)");
+        } else if (table.getType() == TableType.ICEBERG_EXTERNAL_TABLE) {
+            addTableComment(table, sb);
+            IcebergExternalTable icebergExternalTable = (IcebergExternalTable) 
table;
+            sb.append("\nLOCATION 
'").append(icebergExternalTable.location()).append("'");
+            sb.append("\nPROPERTIES (");
+            Iterator<Entry<String, String>> iterator = 
icebergExternalTable.properties().entrySet().iterator();
+            while (iterator.hasNext()) {
+                Entry<String, String> prop = iterator.next();
+                sb.append("\n  \"").append(prop.getKey()).append("\" = 
\"").append(prop.getValue()).append("\"");
+                if (iterator.hasNext()) {
+                    sb.append(",");
+                }
+            }
+            sb.append("\n)");
+        }
+
+        createTableStmt.add(sb + ";");
+
+        // 2. add partition
+        if (separatePartition && (table instanceof OlapTable) && ((OlapTable) 
table).getPartitions().size() > 1) {
+            if (((OlapTable) table).getPartitionInfo().getType() == 
PartitionType.RANGE
+                    || ((OlapTable) table).getPartitionInfo().getType() == 
PartitionType.LIST) {
+                OlapTable olapTable = (OlapTable) table;
+                PartitionInfo partitionInfo = olapTable.getPartitionInfo();
+                boolean first = true;
+                for (Map.Entry<Long, PartitionItem> entry : 
partitionInfo.getPartitionItemEntryList(false, true)) {
+                    if (first) {
+                        first = false;
+                        continue;
+                    }
+                    sb = new StringBuilder();
+                    Partition partition = 
olapTable.getPartition(entry.getKey());
+                    sb.append("ALTER TABLE ").append(table.getName());
+                    sb.append(" ADD PARTITION 
").append(partition.getName()).append(" VALUES ");
+                    if (partitionInfo.getType() == PartitionType.RANGE) {
+                        sb.append("[");
+                        sb.append(((RangePartitionItem) 
entry.getValue()).getItems().lowerEndpoint().toSql());
+                        sb.append(", ");
+                        sb.append(((RangePartitionItem) 
entry.getValue()).getItems().upperEndpoint().toSql());
+                        sb.append(")");
+                    } else if (partitionInfo.getType() == PartitionType.LIST) {
+                        sb.append("IN (");
+                        sb.append(((ListPartitionItem) 
entry.getValue()).toSql());
+                        sb.append(")");
+                    }
+                    sb.append("(\"version_info\" = \"");
+                    sb.append(partition.getVisibleVersion()).append("\"");
+                    sb.append(");");
+                    addPartitionStmt.add(sb + ";");
+                }
+            }
+        }
+
+        // 3. rollup
+        if (createRollupStmt != null && (table instanceof OlapTable)) {
+            OlapTable olapTable = (OlapTable) table;
+            for (Map.Entry<Long, MaterializedIndexMeta> entry : 
olapTable.getIndexIdToMeta().entrySet()) {
+                if (entry.getKey() == olapTable.getBaseIndexId()) {
+                    continue;
+                }
+                MaterializedIndexMeta materializedIndexMeta = entry.getValue();
+                sb = new StringBuilder();
+                String indexName = olapTable.getIndexNameById(entry.getKey());
+                sb.append("ALTER TABLE ").append(table.getName()).append(" ADD 
ROLLUP ").append(indexName);
+                sb.append("(");
+
+                List<Column> indexSchema = materializedIndexMeta.getSchema();
+                for (int i = 0; i < indexSchema.size(); i++) {
+                    Column column = indexSchema.get(i);
+                    sb.append(column.getName());
+                    if (i != indexSchema.size() - 1) {
+                        sb.append(", ");
+                    }
+                }
+                sb.append(");");
+                createRollupStmt.add(sb + ";");
+            }
+        }
+    }
+
     /**
      * Get table ddl stmt.
      *
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableLikeCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableLikeCommand.java
index e02790b5adb..ac1cdc99984 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableLikeCommand.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/CreateTableLikeCommand.java
@@ -17,7 +17,6 @@
 
 package org.apache.doris.nereids.trees.plans.commands;
 
-import org.apache.doris.analysis.CreateTableLikeStmt;
 import org.apache.doris.analysis.StmtType;
 import org.apache.doris.catalog.DatabaseIf;
 import org.apache.doris.catalog.Env;
@@ -53,8 +52,7 @@ public class CreateTableLikeCommand extends Command 
implements ForwardWithSync {
     public void run(ConnectContext ctx, StmtExecutor executor) throws 
Exception {
         executor.checkBlockRules();
         info.validate(ctx);
-        CreateTableLikeStmt stmt = info.translateToLegacyStmt();
-        doRun(stmt, ctx, executor);
+        doRun(info, ctx, executor);
     }
 
     @Override
@@ -67,10 +65,11 @@ public class CreateTableLikeCommand extends Command 
implements ForwardWithSync {
         return StmtType.CREATE;
     }
 
-    private void doRun(CreateTableLikeStmt stmt, ConnectContext ctx, 
StmtExecutor executor) throws Exception {
+    private void doRun(CreateTableLikeInfo createTableLikeInfo, ConnectContext 
ctx, StmtExecutor executor)
+            throws Exception {
         try {
-            DatabaseIf db = 
Env.getCurrentInternalCatalog().getDbOrDdlException(stmt.getExistedDbName());
-            TableIf table = 
db.getTableOrDdlException(stmt.getExistedTableName());
+            DatabaseIf db = 
Env.getCurrentInternalCatalog().getDbOrDdlException(createTableLikeInfo.getExistedDbName());
+            TableIf table = 
db.getTableOrDdlException(createTableLikeInfo.getExistedTableName());
 
             if (table.getType() == TableIf.TableType.VIEW) {
                 throw new DdlException("Not support create table from a View");
@@ -80,21 +79,23 @@ public class CreateTableLikeCommand extends Command 
implements ForwardWithSync {
             table.readLock();
             try {
                 if (table.isManagedTable()) {
-                    if (!CollectionUtils.isEmpty(stmt.getRollupNames())) {
+                    if 
(!CollectionUtils.isEmpty(createTableLikeInfo.getRollupNames())) {
                         OlapTable olapTable = (OlapTable) table;
-                        for (String rollupIndexName : stmt.getRollupNames()) {
+                        for (String rollupIndexName : 
createTableLikeInfo.getRollupNames()) {
                             if 
(!olapTable.hasMaterializedIndex(rollupIndexName)) {
                                 throw new DdlException("Rollup index[" + 
rollupIndexName + "] not exists in Table["
-                                        + olapTable.getName() + "]");
+                                    + olapTable.getName() + "]");
                             }
                         }
                     }
-                } else if (!CollectionUtils.isEmpty(stmt.getRollupNames()) || 
stmt.isWithAllRollup()) {
+                } else if 
(!CollectionUtils.isEmpty(createTableLikeInfo.getRollupNames())
+                        || createTableLikeInfo.isWithAllRollup()) {
                     throw new DdlException("Table[" + table.getName() + "] is 
external, not support rollup copy");
                 }
 
-                Env.getDdlStmt(stmt, stmt.getDbName(), table, createTableStmt, 
null, null, false, false, true, -1L,
-                        false, false);
+                Env.getCreateTableLikeStmt(createTableLikeInfo, 
createTableLikeInfo.getDbName(), table, createTableStmt,
+                        null, null, false, false, true, -1L,
+                            false, false);
                 if (createTableStmt.isEmpty()) {
                     
ErrorReport.reportDdlException(ErrorCode.ERROR_CREATE_TABLE_LIKE_EMPTY, 
"CREATE");
                 }
@@ -112,14 +113,16 @@ public class CreateTableLikeCommand extends Command 
implements ForwardWithSync {
                         .parseSingle(createTableStmt.get(0));
                 CreateTableInfo createTableInfo = 
createTableCommand.getCreateTableInfo();
                 createTableCommand = new 
CreateTableCommand(createTableCommand.getCtasQuery(),
-                        
createTableInfo.withTableNameAndIfNotExists(stmt.getTableName(), 
stmt.isIfNotExists()));
+                    
createTableInfo.withTableNameAndIfNotExists(createTableLikeInfo.getTableName(),
+                            createTableLikeInfo.isIfNotExists()));
                 createTableCommand.run(ctx, executor);
             } finally {
                 ctx.setSkipAuth(false);
             }
         } catch (UserException e) {
-            throw new DdlException("Failed to execute CREATE TABLE LIKE " + 
stmt.getExistedTableName() + ". Reason: "
-                    + e.getMessage(), e);
+            throw new DdlException("Failed to execute CREATE TABLE LIKE "
+                + createTableLikeInfo.getExistedTableName() + ". Reason: "
+                + e.getMessage(), e);
         }
     }
 }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableLikeInfo.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableLikeInfo.java
index f24d30ea085..3f486205924 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableLikeInfo.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/info/CreateTableLikeInfo.java
@@ -17,10 +17,8 @@
 
 package org.apache.doris.nereids.trees.plans.commands.info;
 
-import org.apache.doris.analysis.CreateTableLikeStmt;
 import org.apache.doris.catalog.Env;
 import org.apache.doris.common.AnalysisException;
-import org.apache.doris.common.DdlException;
 import org.apache.doris.common.ErrorCode;
 import org.apache.doris.common.ErrorReport;
 import org.apache.doris.common.FeNameFormat;
@@ -52,11 +50,6 @@ public class CreateTableLikeInfo {
         this.withAllRollup = withAllRollup;
     }
 
-    public CreateTableLikeStmt translateToLegacyStmt() throws DdlException {
-        return new CreateTableLikeStmt(ifNotExists, isTemp, 
tableName.transferToTableName(),
-                existedTableName.transferToTableName(), rollupNames, 
withAllRollup);
-    }
-
     /** validate */
     public void validate(ConnectContext ctx) throws AnalysisException {
         existedTableName.analyze(ctx);
@@ -79,4 +72,36 @@ public class CreateTableLikeInfo {
             
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, 
"CREATE");
         }
     }
+
+    public String getExistedDbName() {
+        return existedTableName.getDb();
+    }
+
+    public String getExistedTableName() {
+        return existedTableName.getTbl();
+    }
+
+    public String getDbName() {
+        return tableName.getDb();
+    }
+
+    public String getTableName() {
+        return tableName.getTbl();
+    }
+
+    public boolean isIfNotExists() {
+        return ifNotExists;
+    }
+
+    public ArrayList<String> getRollupNames() {
+        return rollupNames;
+    }
+
+    public boolean isWithAllRollup() {
+        return withAllRollup;
+    }
+
+    public boolean isTemp() {
+        return isTemp;
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to