diff --git a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java index 4ebffdf727c8a15..714d314e78c4294 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java +++ b/fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java @@ -502,7 +502,6 @@ public void processAlterTable(AlterTableStmt stmt) throws UserException { switch (tableIf.getType()) { case MATERIALIZED_VIEW: case OLAP: - case TEMP: OlapTable olapTable = (OlapTable) tableIf; needProcessOutsideTableLock = processAlterOlapTable(stmt, olapTable, alterClauses, (Database) dbIf); break; diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeTblStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeTblStmt.java index db98f6af706469e..b30a1c293ad67a3 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeTblStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeTblStmt.java @@ -137,6 +137,7 @@ public void analyze(Analyzer analyzer) throws UserException { DatabaseIf db = catalog.getDbOrAnalysisException(dbName); dbId = db.getId(); table = db.getTableOrAnalysisException(tblName); + isAllColumns = columnNames == null; check(); } @@ -145,6 +146,9 @@ public void check() throws AnalysisException { if (table instanceof View) { throw new AnalysisException("Analyze view is not allowed"); } + //if (table.getType() == TableType.TEMP) { + // throw new AnalysisException("Analyze temporary table is not supported"); + //} checkAnalyzePriv(tableName.getCtl(), tableName.getDb(), tableName.getTbl()); if (columnNames == null) { columnNames = table.getSchemaAllIndexes(false).stream() diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDataStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDataStmt.java index 4b7bcb8ac3ce8e4..20cd37a0d8fa3de 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDataStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDataStmt.java @@ -178,6 +178,10 @@ public int compare(Table t1, Table t2) { PrivPredicate.SHOW)) { continue; } + if (table.getType() == TableType.TEMP && Util.getTempTableConnectionId(table.getName()) + != ConnectContext.get().getConnectionId()) { + continue; + } sortedTables.add(table); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowQueryStatsStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowQueryStatsStmt.java index 723a0ef8629a6c9..a4bd934eab0694e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowQueryStatsStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowQueryStatsStmt.java @@ -25,6 +25,7 @@ import org.apache.doris.common.ErrorCode; import org.apache.doris.common.ErrorReport; import org.apache.doris.common.UserException; +import org.apache.doris.common.util.Util; import org.apache.doris.mysql.privilege.PrivPredicate; import org.apache.doris.qe.ConnectContext; import org.apache.doris.qe.ShowResultSetMetaData; @@ -137,7 +138,14 @@ public void analyze(Analyzer analyzer) throws UserException { stats.forEach((tableName, queryHit) -> { if (Env.getCurrentEnv().getAccessManager() .checkTblPriv(ConnectContext.get(), ctlName, dbName, tableName, PrivPredicate.SHOW)) { - totalRows.add(Arrays.asList(tableName, String.valueOf(queryHit))); + if (Util.isTempTable(tableName)) { + if (Util.isTempTableInCurrentSession(tableName)) { + totalRows.add(Arrays.asList(Util.getTempTableOuterName(tableName), + String.valueOf(queryHit))); + } + } else { + totalRows.add(Arrays.asList(tableName, String.valueOf(queryHit))); + } } }); } else { diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java index 060f3b1b2b3ed3a..e28a06bef78a7cd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/Database.java @@ -577,6 +577,7 @@ public Table getTableNullable(String tableName) { if (table == null) { table = nameToTable.get(tableName); } + return table; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/catalog/DatabaseIf.java b/fe/fe-core/src/main/java/org/apache/doris/catalog/DatabaseIf.java index 34b5cd4f60d5b78..5502e94e2025bdf 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/catalog/DatabaseIf.java +++ b/fe/fe-core/src/main/java/org/apache/doris/catalog/DatabaseIf.java @@ -283,7 +283,7 @@ default OlapTable getOlapTableOrDdlException(String tableName) throws DdlExcepti default OlapTable getOlapTableOrAnalysisException(String tableName) throws AnalysisException { T table = getTableOrAnalysisException(tableName); - if (!(table instanceof OlapTable)) { + if (!(table instanceof OlapTable) && !(table.getType() == TableType.TEMP)) { throw new AnalysisException(ErrorCode.ERR_NOT_OLAP_TABLE.formatErrorMsg(tableName)); } return (OlapTable) table; 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 34d0ad0e6cd175e..ff6ee84c8272a6f 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 @@ -3805,7 +3805,11 @@ public static void getDdlStmt(DdlStmt ddlStmt, String dbName, TableIf table, Lis } } sb.append("\n) ENGINE="); - sb.append(table.getType().name()); + if (table.getType() == TableType.TEMP) { + sb.append("OLAP"); + } else { + sb.append(table.getType().name()); + } if (table instanceof OlapTable) { OlapTable olapTable = (OlapTable) table; diff --git a/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java b/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java index cd30c7afeb7361e..e7ffc0c8e65c779 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java +++ b/fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java @@ -701,4 +701,16 @@ public static String generateTempTableInnerName(String tableName) { public static String getTempTableOuterName(String tableName) { return tableName.indexOf("_#TEMP#_") != -1 ? tableName.split("_#TEMP#_")[1] : tableName; } + + public static int getTempTableConnectionId(String tableName) { + return tableName.indexOf("_#TEMP#_") != -1 ? new Integer(tableName.split("_#TEMP#_")[0]) : -1; + } + + public static boolean isTempTable(String tableName) { + return tableName.indexOf("_#TEMP#_") != -1; + } + + public static boolean isTempTableInCurrentSession(String tableName) { + return getTempTableConnectionId(tableName) == ConnectContext.get().getConnectionId(); + } } diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java index 20f4185bb4d8e12..b8320546c297bcd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/InternalCatalog.java @@ -941,7 +941,11 @@ public void dropTable(DropTableStmt stmt) throws DdlException { } } - dropTableInternal(db, table, stmt.isForceDrop(), watch, costTimes); + if (table.getType() == TableType.TEMP) { + dropTableInternal(db, table, true, watch, costTimes); + } else { + dropTableInternal(db, table, stmt.isForceDrop(), watch, costTimes); + } } catch (UserException e) { throw new DdlException(e.getMessage(), e.getMysqlErrorCode()); } finally { diff --git a/fe/fe-core/src/main/java/org/apache/doris/load/DeleteHandler.java b/fe/fe-core/src/main/java/org/apache/doris/load/DeleteHandler.java index 299dac295dc909b..61c8ec3be771f0d 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/load/DeleteHandler.java +++ b/fe/fe-core/src/main/java/org/apache/doris/load/DeleteHandler.java @@ -29,6 +29,7 @@ import org.apache.doris.common.io.Writable; import org.apache.doris.common.util.ListComparator; import org.apache.doris.common.util.TimeUtils; +import org.apache.doris.common.util.Util; import org.apache.doris.datasource.InternalCatalog; import org.apache.doris.mysql.privilege.PrivPredicate; import org.apache.doris.persist.gson.GsonUtils; @@ -264,15 +265,23 @@ public List> getDeleteInfosByDb(long dbId) { } for (DeleteInfo deleteInfo : deleteInfoList) { + String tableName = deleteInfo.getTableName(); if (!Env.getCurrentEnv().getAccessManager() .checkTblPriv(ConnectContext.get(), InternalCatalog.INTERNAL_CATALOG_NAME, dbName, - deleteInfo.getTableName(), - PrivPredicate.LOAD)) { + tableName, PrivPredicate.LOAD)) { continue; } List info = Lists.newArrayList(); - info.add(deleteInfo.getTableName()); + if (Util.isTempTable(tableName)) { + info.add(Util.getTempTableOuterName(tableName)); + if (!Util.isTempTableInCurrentSession(tableName)) { + continue; + } + } else { + info.add(deleteInfo.getTableName()); + } + if (deleteInfo.isNoPartitionSpecified()) { info.add("*"); } else { diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ExportCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ExportCommand.java index dbf6cf7067e52e7..67402a7d1dac1ae 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ExportCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ExportCommand.java @@ -30,6 +30,7 @@ import org.apache.doris.catalog.Partition; import org.apache.doris.catalog.Table; import org.apache.doris.catalog.TableIf; +import org.apache.doris.catalog.TableIf.TableType; import org.apache.doris.common.Config; import org.apache.doris.common.ErrorCode; import org.apache.doris.common.ErrorReport; @@ -197,8 +198,9 @@ private void checkPartitions(ConnectContext ctx, TableName tblName) throws Analy case OLAP: break; case VIEW: // We support export view, so we do not need to check partition here. + case TEMP: if (this.partitionsNames.size() > 0) { - throw new AnalysisException("Table[" + tblName.getTbl() + "] is VIEW type, " + throw new AnalysisException("Table[" + tblName.getTbl() + "] is " + tblType + " type, " + "do not support export PARTITION."); } return; @@ -247,6 +249,10 @@ private ExportJob generateExportJob(ConnectContext ctx, Map file CatalogIf catalog = ctx.getEnv().getCatalogMgr().getCatalogOrAnalysisException(tblName.getCtl()); DatabaseIf db = catalog.getDbOrAnalysisException(tblName.getDb()); TableIf table = db.getTableOrAnalysisException(tblName.getTbl()); + if (table.getType() == TableType.TEMP) { + throw new AnalysisException("Table[" + tblName.getTbl() + "] is " + + table.getType() + " type, do not support export."); + } exportJob.setDbId(db.getId()); exportJob.setTableName(tblName); diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java index 99d9fb5abb8ff27..04cbea35d437d94 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ConnectContext.java @@ -45,6 +45,7 @@ import org.apache.doris.common.UserException; import org.apache.doris.common.util.DebugUtil; import org.apache.doris.common.util.TimeUtils; +import org.apache.doris.common.util.Util; import org.apache.doris.datasource.CatalogIf; import org.apache.doris.datasource.InternalCatalog; import org.apache.doris.datasource.SessionContext; @@ -316,7 +317,8 @@ public void setOrUpdateInsertResult(long txnId, String label, String db, String if (isTxnModel() && insertResult != null) { insertResult.updateResult(txnStatus, loadedRows, filteredRows); } else { - insertResult = new InsertResult(txnId, label, db, tbl, txnStatus, loadedRows, filteredRows); + insertResult = new InsertResult(txnId, label, db, Util.getTempTableOuterName(tbl), + txnStatus, loadedRows, filteredRows); } } @@ -889,7 +891,6 @@ protected void deleteTempTable() { Database db = Env.getCurrentEnv().getInternalCatalog().getDb(dbName).get(); for (String tableName : dbToTempTableNamesMap.get(dbName)) { try { - //Env.getCurrentEnv().unprotectDropTable(db, db.getTable(tableName).get(), true, false, 0L); Env.getCurrentEnv().getInternalCatalog() .dropTableWithoutCheck(db, db.getTable(tableName).get(), true); } catch (DdlException e) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java index ba0eef7d5baa066..52ea8b0890a0937 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java @@ -872,7 +872,14 @@ private void handleShowTableId() throws AnalysisException { if (table != null) { List row = new ArrayList<>(); row.add(database.getFullName()); - row.add(table.getName()); + if (table.getType() == TableType.TEMP) { + if (!Util.isTempTableInCurrentSession(table.getName())) { + continue; + } + row.add(Util.getTempTableOuterName(table.getName())); + } else { + row.add(table.getName()); + } row.add(String.valueOf(database.getId())); rows.add(row); break; @@ -902,7 +909,14 @@ private void handleShowPartitionId() throws AnalysisException { if (partition != null) { List row = new ArrayList<>(); row.add(database.getFullName()); - row.add(tbl.getName()); + if (tbl.getType() == TableType.TEMP) { + if (!Util.isTempTableInCurrentSession(tbl.getName())) { + continue; + } + row.add(Util.getTempTableOuterName(tbl.getName())); + } else { + row.add(tbl.getName()); + } row.add(partition.getName()); row.add(String.valueOf(database.getId())); row.add(String.valueOf(tbl.getId())); @@ -1034,7 +1048,14 @@ private void handleShowTableStatus() throws AnalysisException { } List row = Lists.newArrayList(); // Name - row.add(table.getName()); + if (table.getType() == TableType.TEMP) { + if (!Util.isTempTableInCurrentSession(table.getName())) { + continue; + } + row.add(Util.getTempTableOuterName(table.getName())); + } else { + row.add(table.getName()); + } // Engine row.add(table.getEngine()); // version @@ -2024,6 +2045,12 @@ private void handleShowTablet() throws AnalysisException { table.readLock(); try { tableName = table.getName(); + if (table.getType() == TableType.TEMP) { + if (!Util.isTempTableInCurrentSession(table.getName())) { + throw new AnalysisException("Unknown tablet: " + tabletId); + } + tableName = Util.getTempTableOuterName(tableName); + } OlapTable olapTable = (OlapTable) table; Partition partition = olapTable.getPartition(partitionId); if (partition == null) { @@ -2526,6 +2553,12 @@ private void handleShowDynamicPartition() throws AnalysisException { DynamicPartitionProperty dynamicPartitionProperty = olapTable.getTableProperty().getDynamicPartitionProperty(); String tableName = olapTable.getName(); + if (olapTable.getType() == TableType.TEMP) { + if (!Util.isTempTableInCurrentSession(tableName)) { + continue; + } + tableName = Util.getTempTableOuterName(tableName); + } ReplicaAllocation replicaAlloc = dynamicPartitionProperty.getReplicaAllocation(); if (replicaAlloc.isNotSet()) { replicaAlloc = olapTable.getDefaultReplicaAllocation(); diff --git a/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisManager.java b/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisManager.java index c2b20707f133e8e..a62fe99b2d57ec9 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisManager.java +++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisManager.java @@ -39,6 +39,7 @@ import org.apache.doris.catalog.ScalarType; import org.apache.doris.catalog.Table; import org.apache.doris.catalog.TableIf; +import org.apache.doris.catalog.TableIf.TableType; import org.apache.doris.catalog.Tablet; import org.apache.doris.catalog.View; import org.apache.doris.common.AnalysisException; @@ -205,6 +206,9 @@ public List buildAnalysisInfosForDB(DatabaseIf db, Analyz if (table instanceof View) { continue; } + if (table.getType() == TableType.TEMP) { + continue; + } TableName tableName = new TableName(db.getCatalog().getName(), db.getFullName(), table.getName()); // columnNames null means to add all visible columns. // Will get all the visible columns in analyzeTblStmt.check() diff --git a/regression-test/data/table_p0/temp_table_data.csv b/regression-test/data/table_p0/temp_table_data.csv new file mode 100644 index 000000000000000..1c1a86d658ff481 --- /dev/null +++ b/regression-test/data/table_p0/temp_table_data.csv @@ -0,0 +1,3 @@ +1,'2024-01-01','Alice' +2,'2024-01-02','Bob' +3,'2024-02-01','Carl' \ No newline at end of file diff --git a/regression-test/suites/cold_heat_separation/empty_table_use_policy/create_table_use_policy.groovy b/regression-test/suites/cold_heat_separation/empty_table_use_policy/create_table_use_policy.groovy index 4e2ef09c99dae26..ed5d5fd07c50959 100644 --- a/regression-test/suites/cold_heat_separation/empty_table_use_policy/create_table_use_policy.groovy +++ b/regression-test/suites/cold_heat_separation/empty_table_use_policy/create_table_use_policy.groovy @@ -92,6 +92,25 @@ suite("create_table_use_policy") { // storage policy is disabled on mow table assertEquals(create_table_use_created_policy.size(), 1); + // success + def create_temp_table_use_created_policy = try_sql """ + CREATE TEMPORARY TABLE IF NOT EXISTS create_temp_table_use_created_policy + ( + k1 BIGINT, + k2 LARGEINT, + v1 VARCHAR(2048) + ) + UNIQUE KEY(k1) + DISTRIBUTED BY HASH (k1) BUCKETS 3 + PROPERTIES( + "storage_policy" = "test_create_table_use_policy", + "replication_num" = "1", + "enable_unique_key_merge_on_write" = "false" + ); + """ + // storage policy is disabled on mow table + assertEquals(create_temp_table_use_created_policy.size(), 1); + sql """ DROP TABLE IF EXISTS create_table_use_created_policy """ diff --git a/regression-test/suites/correctness/test_outer_join_with_subquery.groovy b/regression-test/suites/correctness/test_outer_join_with_subquery.groovy index 43fbfe48167e393..fd2ce0b7e8d83c4 100644 --- a/regression-test/suites/correctness/test_outer_join_with_subquery.groovy +++ b/regression-test/suites/correctness/test_outer_join_with_subquery.groovy @@ -95,54 +95,54 @@ """ order_qt_select """ - with temp1 as (select + with temp as (select t2.data_time from dim_comp_tags t1 left join ods_comp_info_q t2 on t2.stock_code = t1.stock_code group by t2.data_time) select tt1.data_time - from temp1 tt1 - left join temp1 tt2 on tt2.data_time = tt1.data_time order by tt1.data_time; + from temp tt1 + left join temp tt2 on tt2.data_time = tt1.data_time order by tt1.data_time; """ order_qt_select """ - with temp1 as (select + with temp as (select t2.`datev2` from dim_comp_tags t1 left join ods_comp_info_q t2 on t2.stock_code = t1.stock_code group by t2.`datev2`) select tt1.`datev2` - from temp1 tt1 - left join temp1 tt2 on tt2.`datev2` = tt1.`datev2` order by tt1.`datev2`; + from temp tt1 + left join temp tt2 on tt2.`datev2` = tt1.`datev2` order by tt1.`datev2`; """ order_qt_select """ - with temp1 as (select + with temp as (select t2.`datatimev2_1` from dim_comp_tags t1 left join ods_comp_info_q t2 on t2.stock_code = t1.stock_code group by t2.`datatimev2_1`) select tt1.`datatimev2_1` - from temp1 tt1 - left join temp1 tt2 on tt2.`datatimev2_1` = tt1.`datatimev2_1` order by tt1.`datatimev2_1`; + from temp tt1 + left join temp tt2 on tt2.`datatimev2_1` = tt1.`datatimev2_1` order by tt1.`datatimev2_1`; """ order_qt_select """ - with temp1 as (select + with temp as (select t2.`datatimev2_2` from dim_comp_tags t1 left join ods_comp_info_q t2 on t2.stock_code = t1.stock_code group by t2.`datatimev2_2`) select tt1.`datatimev2_2` - from temp1 tt1 - left join temp1 tt2 on tt2.`datatimev2_2` = tt1.`datatimev2_2` order by tt1.`datatimev2_2`; + from temp tt1 + left join temp tt2 on tt2.`datatimev2_2` = tt1.`datatimev2_2` order by tt1.`datatimev2_2`; """ order_qt_select """ - with temp1 as (select + with temp as (select t2.`datatimev2_3` from dim_comp_tags t1 left join ods_comp_info_q t2 on t2.stock_code = t1.stock_code group by t2.`datatimev2_3`) select tt1.`datatimev2_3` - from temp1 tt1 - left join temp1 tt2 on tt2.`datatimev2_3` = tt1.`datatimev2_3` order by tt1.`datatimev2_3`; + from temp tt1 + left join temp tt2 on tt2.`datatimev2_3` = tt1.`datatimev2_3` order by tt1.`datatimev2_3`; """ } diff --git a/regression-test/suites/correctness_p0/test_distinct_agg.groovy b/regression-test/suites/correctness_p0/test_distinct_agg.groovy index a23a7822bf5d521..d69842a5fe6d6bb 100644 --- a/regression-test/suites/correctness_p0/test_distinct_agg.groovy +++ b/regression-test/suites/correctness_p0/test_distinct_agg.groovy @@ -50,7 +50,7 @@ suite("test_distinct_agg") { from test_distinct_agg_t where 1=1 group by k5, k6 - ) AS temp1 where 1=1 + ) AS temp where 1=1 group by k5, k6; ''' result([['1', '2023-01-10', 1L]]) diff --git a/regression-test/suites/correctness_p0/test_union_has_in_predicate.groovy b/regression-test/suites/correctness_p0/test_union_has_in_predicate.groovy index 2df3d37f97498dc..5ecad89c7fe192d 100644 --- a/regression-test/suites/correctness_p0/test_union_has_in_predicate.groovy +++ b/regression-test/suites/correctness_p0/test_union_has_in_predicate.groovy @@ -36,7 +36,7 @@ suite("test_union_has_in_predicate") { """ qt_select """ - with temp1 as( + with temp as( select a as a from @@ -63,7 +63,7 @@ suite("test_union_has_in_predicate") { select a from - temp1 + temp where a in ('1'); """ diff --git a/regression-test/suites/datatype_p0/decimalv3/fix-overflow.groovy b/regression-test/suites/datatype_p0/decimalv3/fix-overflow.groovy index fc58f295db9df1f..4fd294e37d52719 100644 --- a/regression-test/suites/datatype_p0/decimalv3/fix-overflow.groovy +++ b/regression-test/suites/datatype_p0/decimalv3/fix-overflow.groovy @@ -71,7 +71,7 @@ suite("fix-overflow") { * from ( - with temp1 as ( + with temp as ( select sum(financing_amount) / 100000000 as amount, country @@ -96,8 +96,8 @@ suite("fix-overflow") { ) - 1 ) as past_5_cagr from - temp1 t1 - left join temp1 t2 on + temp t1 + left join temp t2 on t2.country = t1.country ) as ret; """ diff --git a/regression-test/suites/javaudf_p0/function_meta/function_query_test.groovy b/regression-test/suites/javaudf_p0/function_meta/function_query_test.groovy index 326e98e0b1dbb7f..5eeb314e3943218 100644 --- a/regression-test/suites/javaudf_p0/function_meta/function_query_test.groovy +++ b/regression-test/suites/javaudf_p0/function_meta/function_query_test.groovy @@ -21,6 +21,6 @@ qt_select1 ''' SELECT java_udf_int_test(1) result; ''' qt_select2 """ SELECT udaf_my_sum_int(user_id) result FROM ${tableName} ORDER BY result; """ - qt_select3 """ SELECT user_id, e1 FROM ${tableName} lateral view udtf_int(user_id) temp1 as e1 order by user_id; """ + qt_select3 """ SELECT user_id, e1 FROM ${tableName} lateral view udtf_int(user_id) temp as e1 order by user_id; """ qt_select4 """ SELECT java_udf_int_test_global_2(user_id) result FROM ${tableName} ORDER BY result; """ } \ No newline at end of file diff --git a/regression-test/suites/javaudf_p0/test_javaudtf_arrayint.groovy b/regression-test/suites/javaudf_p0/test_javaudtf_arrayint.groovy index bb7deb209165f61..07c2dd61f356b55 100644 --- a/regression-test/suites/javaudf_p0/test_javaudtf_arrayint.groovy +++ b/regression-test/suites/javaudf_p0/test_javaudtf_arrayint.groovy @@ -67,7 +67,7 @@ suite("test_javaudtf_arrayint") { "type"="JAVA_UDF" ); """ - qt_select1 """ SELECT user_id, string_col, e1 FROM ${tableName} lateral view udtf_arrayint(array(user_id)) `temp` as e1 order by user_id; """ + qt_select1 """ SELECT user_id, string_col, e1 FROM ${tableName} lateral view udtf_arrayint(array(user_id)) temp as e1 order by user_id; """ } finally { try_sql("DROP FUNCTION IF EXISTS udtf_arrayint(array);") diff --git a/regression-test/suites/javaudf_p0/test_javaudtf_decimal.groovy b/regression-test/suites/javaudf_p0/test_javaudtf_decimal.groovy index 1d6bb6fe6dd6cba..a8fa7e347af36ed 100644 --- a/regression-test/suites/javaudf_p0/test_javaudtf_decimal.groovy +++ b/regression-test/suites/javaudf_p0/test_javaudtf_decimal.groovy @@ -58,8 +58,8 @@ suite("test_javaudtf_decimal") { "type"="JAVA_UDF" ); """ - qt_select1 """ SELECT user_id, cost_1, e1 FROM ${tableName} lateral view udtf_decimal(cost_1) `temp` as e1 order by user_id; """ - qt_select2 """ SELECT user_id, cost_2, e1 FROM ${tableName} lateral view udtf_decimal(cost_2) `temp` as e1 order by user_id; """ + qt_select1 """ SELECT user_id, cost_1, e1 FROM ${tableName} lateral view udtf_decimal(cost_1) temp as e1 order by user_id; """ + qt_select2 """ SELECT user_id, cost_2, e1 FROM ${tableName} lateral view udtf_decimal(cost_2) temp as e1 order by user_id; """ } finally { try_sql("DROP FUNCTION IF EXISTS udtf_decimal(decimal);") diff --git a/regression-test/suites/javaudf_p0/test_javaudtf_double.groovy b/regression-test/suites/javaudf_p0/test_javaudtf_double.groovy index d541eaa5a26236b..4ba8924526e7898 100644 --- a/regression-test/suites/javaudf_p0/test_javaudtf_double.groovy +++ b/regression-test/suites/javaudf_p0/test_javaudtf_double.groovy @@ -61,8 +61,8 @@ suite("test_javaudtf_double") { "type"="JAVA_UDF" ); """ - qt_select1 """ SELECT user_id, double_1, e1 FROM ${tableName} lateral view udtf_double(double_1) `temp` as e1 order by user_id; """ - qt_select2 """ SELECT user_id, double_2, e1 FROM ${tableName} lateral view udtf_double(double_2) `temp` as e1 order by user_id; """ + qt_select1 """ SELECT user_id, double_1, e1 FROM ${tableName} lateral view udtf_double(double_1) temp as e1 order by user_id; """ + qt_select2 """ SELECT user_id, double_2, e1 FROM ${tableName} lateral view udtf_double(double_2) temp as e1 order by user_id; """ } finally { try_sql("DROP FUNCTION IF EXISTS udtf_double(double);") diff --git a/regression-test/suites/javaudf_p0/test_javaudtf_int.groovy b/regression-test/suites/javaudf_p0/test_javaudtf_int.groovy index 93882294843e093..f9d64837a6a6100 100644 --- a/regression-test/suites/javaudf_p0/test_javaudtf_int.groovy +++ b/regression-test/suites/javaudf_p0/test_javaudtf_int.groovy @@ -65,7 +65,7 @@ suite("test_javaudtf_int") { "type"="JAVA_UDF" ); """ - qt_select1 """ SELECT user_id, varchar_col, e1 FROM ${tableName} lateral view udtf_int(user_id) `temp` as e1 order by user_id; """ + qt_select1 """ SELECT user_id, varchar_col, e1 FROM ${tableName} lateral view udtf_int(user_id) temp as e1 order by user_id; """ test { sql """ select udtf_int(1); """ diff --git a/regression-test/suites/javaudf_p0/test_javaudtf_string.groovy b/regression-test/suites/javaudf_p0/test_javaudtf_string.groovy index 51985ea10aee19a..7e3efc18c1a23e3 100644 --- a/regression-test/suites/javaudf_p0/test_javaudtf_string.groovy +++ b/regression-test/suites/javaudf_p0/test_javaudtf_string.groovy @@ -66,7 +66,7 @@ suite("test_javaudtf_string") { "type"="JAVA_UDF" ); """ - qt_select1 """ SELECT user_id, varchar_col, e1 FROM ${tableName} lateral view udtf_string_split(varchar_col, ",") `temp` as e1 order by user_id; """ + qt_select1 """ SELECT user_id, varchar_col, e1 FROM ${tableName} lateral view udtf_string_split(varchar_col, ",") temp as e1 order by user_id; """ sql """DROP FUNCTION IF EXISTS udtf_null_outer(string, string);""" sql """ CREATE TABLES FUNCTION udtf_null(string, string) RETURNS array PROPERTIES ( @@ -76,7 +76,7 @@ suite("test_javaudtf_string") { "type"="JAVA_UDF" ); """ - qt_select2 """ SELECT user_id, varchar_col, e1 FROM ${tableName} lateral view udtf_null(varchar_col, ",") `temp` as e1 order by user_id; """ + qt_select2 """ SELECT user_id, varchar_col, e1 FROM ${tableName} lateral view udtf_null(varchar_col, ",") temp as e1 order by user_id; """ } finally { try_sql("DROP FUNCTION IF EXISTS udtf_string_split(string, string);") diff --git a/regression-test/suites/load_p0/broker_load/test_domain_connection_and_ak_sk_correction.groovy b/regression-test/suites/load_p0/broker_load/test_domain_connection_and_ak_sk_correction.groovy index 8ad5641fa83b896..04b54a441d7f308 100644 --- a/regression-test/suites/load_p0/broker_load/test_domain_connection_and_ak_sk_correction.groovy +++ b/regression-test/suites/load_p0/broker_load/test_domain_connection_and_ak_sk_correction.groovy @@ -66,7 +66,7 @@ suite("test_domain_connection_and_ak_sk_correction", "load_p0") { DATA INFILE("s3://${getS3BucketName()}/regression/tpch/sf1/part.tbl") INTO TABLE ${tableName} COLUMNS TERMINATED BY "|" - (p_partkey, p_name, p_mfgr, p_brand, p_type, p_size, p_container, p_retailprice, p_comment, temp1) + (p_partkey, p_name, p_mfgr, p_brand, p_type, p_size, p_container, p_retailprice, p_comment, temp) ) WITH S3 ( @@ -86,7 +86,7 @@ suite("test_domain_connection_and_ak_sk_correction", "load_p0") { DATA INFILE("s3://${getS3BucketName()}/regression/tpch/sf1/part.tbl") INTO TABLE ${tableName} COLUMNS TERMINATED BY "|" - (p_partkey, p_name, p_mfgr, p_brand, p_type, p_size, p_container, p_retailprice, p_comment, temp1) + (p_partkey, p_name, p_mfgr, p_brand, p_type, p_size, p_container, p_retailprice, p_comment, temp) ) WITH S3 ( @@ -111,7 +111,7 @@ suite("test_domain_connection_and_ak_sk_correction", "load_p0") { DATA INFILE("s3://${getS3BucketName()}/regression/tpch/sf1/part.tbl") INTO TABLE ${tableName} COLUMNS TERMINATED BY "|" - (p_partkey, p_name, p_mfgr, p_brand, p_type, p_size, p_container, p_retailprice, p_comment, temp1 + (p_partkey, p_name, p_mfgr, p_brand, p_type, p_size, p_container, p_retailprice, p_comment, temp ) ) WITH S3 @@ -137,11 +137,11 @@ suite("test_domain_connection_and_ak_sk_correction", "load_p0") { DATA INFILE("s3://${getS3BucketName()}/regression/tpch/sf1/part.tbl") INTO TABLE ${tableName} COLUMNS TERMINATED BY "|" - (p_partkey, p_name, p_mfgr, p_brand, p_type, p_size, p_container, p_retailprice, p_comment, temp1), + (p_partkey, p_name, p_mfgr, p_brand, p_type, p_size, p_container, p_retailprice, p_comment, temp), DATA INFILE("s3://${getS3BucketName()}1/regression/tpch/sf1/orders.tbl.1", "s3://${getS3BucketName()}/regression/tpch/sf1/orders.tbl.2") INTO TABLE ${tableNameOrders} COLUMNS TERMINATED BY "|" - (o_orderkey, o_custkey, o_orderstatus, o_totalprice, o_orderdate, o_orderpriority, o_clerk, o_shippriority, o_comment, temp1) + (o_orderkey, o_custkey, o_orderstatus, o_totalprice, o_orderdate, o_orderpriority, o_clerk, o_shippriority, o_comment, temp) ) WITH S3 ( diff --git a/regression-test/suites/nereids_p0/cte/test_cte_filter_pushdown.groovy b/regression-test/suites/nereids_p0/cte/test_cte_filter_pushdown.groovy index 256a8f387f415e5..795d1ae7e5cf40d 100644 --- a/regression-test/suites/nereids_p0/cte/test_cte_filter_pushdown.groovy +++ b/regression-test/suites/nereids_p0/cte/test_cte_filter_pushdown.groovy @@ -30,7 +30,7 @@ suite("test_cte_filter_pushdown") { select * from ( select m1.* from main m1, main m2 where m1.k1 = m2.k1 - ) temp1 + ) temp where k1 = 1; """ qt_cte_filter_pushdown_2 """ @@ -42,7 +42,7 @@ suite("test_cte_filter_pushdown") { select * from ( select m1.* from main m1, main m2 where m1.k1 = m2.k1 - ) temp1 + ) temp where k1 = 1; """ sql 'set exec_mem_limit=21G' diff --git a/regression-test/suites/nereids_rules_p0/cte/test_cte_filter_pushdown.groovy b/regression-test/suites/nereids_rules_p0/cte/test_cte_filter_pushdown.groovy index 5c04928a3c6be9e..258e220a4a65d06 100644 --- a/regression-test/suites/nereids_rules_p0/cte/test_cte_filter_pushdown.groovy +++ b/regression-test/suites/nereids_rules_p0/cte/test_cte_filter_pushdown.groovy @@ -70,7 +70,7 @@ suite("test_cte_filter_pushdown") { select * from ( select m1.* from main m1, main m2 where m1.k1 = m2.k1 - ) `temp` + ) temp where k1 = 1; """ qt_cte_filter_pushdown_2 """ @@ -82,7 +82,7 @@ suite("test_cte_filter_pushdown") { select * from ( select m1.* from main m1, main m2 where m1.k1 = m2.k1 - ) `temp` + ) temp where k1 = 1; """ sql 'set exec_mem_limit=21G' diff --git a/regression-test/suites/nereids_rules_p0/cte/test_cte_reuse_with_window.groovy b/regression-test/suites/nereids_rules_p0/cte/test_cte_reuse_with_window.groovy index 9243e3e66e8ef10..431aeda754030e3 100644 --- a/regression-test/suites/nereids_rules_p0/cte/test_cte_reuse_with_window.groovy +++ b/regression-test/suites/nereids_rules_p0/cte/test_cte_reuse_with_window.groovy @@ -29,11 +29,11 @@ suite("test_cte_reuse_with_window") { """ sql """ - with temp1 as (select * from test_cte_reuse_with_window) + with temp as (select * from test_cte_reuse_with_window) select * from - (select t.id, row_number() over(order by t.id) as num from temp1 t limit 20) a + (select t.id, row_number() over(order by t.id) as num from temp t limit 20) a left join - (select t.id, row_number() over(order by t.id desc) as num from temp1 t where t.id = 5) b + (select t.id, row_number() over(order by t.id desc) as num from temp t where t.id = 5) b on a.id = b.id """ } diff --git a/regression-test/suites/nereids_rules_p0/eliminate_gby_key/eliminate_gby_key.groovy b/regression-test/suites/nereids_rules_p0/eliminate_gby_key/eliminate_gby_key.groovy index 0fa7f42429852c1..9139fea3c9db4a9 100644 --- a/regression-test/suites/nereids_rules_p0/eliminate_gby_key/eliminate_gby_key.groovy +++ b/regression-test/suites/nereids_rules_p0/eliminate_gby_key/eliminate_gby_key.groovy @@ -50,7 +50,7 @@ suite("eliminate_gby_key") { explain { sql(""" physical plan - with temp1 + with temp as (select substr(t2.c2, 1, 3) t2_c2, t2.c1 t2_c1, t1.c3, @@ -62,7 +62,7 @@ suite("eliminate_gby_key") { t2.c1, t1.c3) select t2_c1 - from temp1; + from temp; """) contains("groupByExpr=[c1#13, c3#18], outputExpr=[c1#13, c3#18]") } @@ -70,7 +70,7 @@ suite("eliminate_gby_key") { explain { sql(""" physical plan - with temp1 + with temp as (select substr(t2.c2, 1, 3) t2_c2, t2.c1 t2_c1, t1.c3, @@ -82,7 +82,7 @@ suite("eliminate_gby_key") { t2.c1, t1.c3) select t2_c2 - from temp1; + from temp; """) contains("groupByExpr=[t2_c2#19, c1#13, c3#18], outputExpr=[t2_c2#19, c1#13, c3#18]") } @@ -90,7 +90,7 @@ suite("eliminate_gby_key") { explain { sql(""" physical plan - with temp1 + with temp as (select substr(t2.c2, 1, 3) t2_c2, t2.c1 t2_c1, t1.c3, @@ -102,7 +102,7 @@ suite("eliminate_gby_key") { t2.c1, t1.c3) select c3 - from temp1; + from temp; """) contains("groupByExpr=[c1#13, c3#18], outputExpr=[c1#13, c3#18]") } @@ -110,7 +110,7 @@ suite("eliminate_gby_key") { explain { sql(""" physical plan - with temp1 + with temp as (select substr(t2.c2, 1, 3) t2_c2, t2.c1 t2_c1, t1.c3, @@ -122,7 +122,7 @@ suite("eliminate_gby_key") { t2.c1, t1.c3) select cnt - from temp1; + from temp; """) contains("groupByExpr=[c1#13, c3#18], outputExpr=[c1#13, c3#18") } @@ -130,7 +130,7 @@ suite("eliminate_gby_key") { explain { sql(""" physical plan - with temp1 + with temp as (select substr(t2.c2, 1, 3) t2_c2, t2.c1 t2_c1, t1.c3, @@ -142,7 +142,7 @@ suite("eliminate_gby_key") { t2.c1, t1.c3) select t2_c2, t2_c1 - from temp1; + from temp; """) contains("groupByExpr=[t2_c2#19, c1#13, c3#18], outputExpr=[t2_c2#19, c1#13, c3#18]") } @@ -150,7 +150,7 @@ suite("eliminate_gby_key") { explain { sql(""" physical plan - with temp1 + with temp as (select substr(t2.c2, 1, 3) t2_c2, t2.c1 t2_c1, t1.c3, @@ -162,7 +162,7 @@ suite("eliminate_gby_key") { t2.c1, t1.c3) select c3, t2_c1 - from temp1; + from temp; """) contains("groupByExpr=[c1#13, c3#18], outputExpr=[c1#13, c3#18]") } @@ -170,7 +170,7 @@ suite("eliminate_gby_key") { explain { sql(""" physical plan - with temp1 + with temp as (select substr(t2.c2, 1, 3) t2_c2, t2.c1 t2_c1, t1.c3, @@ -182,7 +182,7 @@ suite("eliminate_gby_key") { t2.c1, t1.c3) select c3, t2_c2 - from temp1; + from temp; """) contains("groupByExpr=[t2_c2#19, c1#13, c3#18], outputExpr=[t2_c2#19, c1#13, c3#18]") } @@ -190,7 +190,7 @@ suite("eliminate_gby_key") { explain { sql(""" physical plan - with temp1 + with temp as (select substr(t2.c2, 1, 3) t2_c2, t2.c1 t2_c1, t1.c3, @@ -202,7 +202,7 @@ suite("eliminate_gby_key") { t2.c1, t1.c3) select t2_c1, cnt - from temp1; + from temp; """) contains("groupByExpr=[c1#13, c3#18], outputExpr=[c1#13, c3#18") } @@ -210,7 +210,7 @@ suite("eliminate_gby_key") { explain { sql(""" physical plan - with temp1 + with temp as (select substr(t2.c2, 1, 3) t2_c2, t2.c1 t2_c1, t1.c3, @@ -222,7 +222,7 @@ suite("eliminate_gby_key") { t2.c1, t1.c3) select c3, cnt - from temp1; + from temp; """) contains("groupByExpr=[c1#13, c3#18], outputExpr=[c1#13, c3#18") } @@ -230,7 +230,7 @@ suite("eliminate_gby_key") { explain { sql(""" physical plan - with temp1 + with temp as (select substr(t2.c2, 1, 3) t2_c2, t2.c1 t2_c1, t1.c3, @@ -242,7 +242,7 @@ suite("eliminate_gby_key") { t2.c1, t1.c3) select t2_c1, c3, cnt - from temp1; + from temp; """) contains("groupByExpr=[c1#13, c3#18], outputExpr=[c1#13, c3#18") } @@ -250,7 +250,7 @@ suite("eliminate_gby_key") { explain { sql(""" physical plan - with temp1 + with temp as (select substr(t2.c2, 1, 3) t2_c2, t2.c1 t2_c1, t1.c3, @@ -262,7 +262,7 @@ suite("eliminate_gby_key") { t2.c1, t1.c3) select t2_c2, c3, t2_c1 - from temp1; + from temp; """) contains("groupByExpr=[t2_c2#19, c1#13, c3#18], outputExpr=[t2_c2#19, c1#13, c3#18]") } @@ -270,7 +270,7 @@ suite("eliminate_gby_key") { explain { sql(""" physical plan - with temp1 + with temp as (select substr(t2.c2, 1, 3) t2_c2, t2.c1 t2_c1, t1.c3, @@ -282,7 +282,7 @@ suite("eliminate_gby_key") { t2.c1, t1.c3) select t2_c2, c3, t2_c1, cnt - from temp1; + from temp; """) contains("groupByExpr=[t2_c2#19, c1#13, c3#18], outputExpr=[t2_c2#19, c1#13, c3#18,") } diff --git a/regression-test/suites/table_p0/test_temp_table.groovy b/regression-test/suites/table_p0/test_temp_table.groovy index 590763b7379bbe3..2638ff5b20a6c05 100644 --- a/regression-test/suites/table_p0/test_temp_table.groovy +++ b/regression-test/suites/table_p0/test_temp_table.groovy @@ -61,8 +61,9 @@ suite("test_temp_table") { PROPERTIES ('replication_num' = '1'); """ + // temporary table have same name with common olap table sql """ - CREATE TEMP TABLE `t_test_temp_table1` ( + CREATE TEMPORARY TABLE `t_test_temp_table1` ( `id` int, `add_date` date, `name` varchar(32), @@ -76,13 +77,22 @@ suite("test_temp_table") { PARTITION p201703_3000 VALUES [('2017-03-01'), ('2017-04-01')) ) DISTRIBUTED BY HASH(`id`) BUCKETS 1 - PROPERTIES ('replication_num' = '1'); + PROPERTIES ( + 'replication_num' = '1', + 'storage_medium' = 'hdd', + 'storage_cooldown_time' = '2040-11-20 00:00:00', + 'bloom_filter_columns' = 'add_date', + 'enable_unique_key_merge_on_write' = 'true', + 'function_column.sequence_col' = 'add_date' + ); """ - sql """ - create temporary table t_test_temp_table2 PROPERTIES ('replication_num' = '1') as - select * - from t_test_temp_table1; + // create table as + sql """ + create temporary table t_test_temp_table2 PROPERTIES ( + 'replication_num' = '1', 'light_schema_change' = 'true', 'bloom_filter_columns' = 'add_date' + ) + as select * from t_test_temp_table1; """ def show_tables = sql "show tables" @@ -103,6 +113,22 @@ suite("test_temp_table") { } assertTrue(containTempTable) + def desc_result = sql "desc t_test_temp_table2" + assertEquals(desc_result.size(), 3) + + def show_partition_result = sql "show partitions from t_test_temp_table2" + assertEquals(show_partition_result.size(), 1) + + def show_column_result = sql "show full columns from t_test_temp_table2" + assertEquals(show_column_result.size(), 3) + + def show_tablets_result = sql "show tablets from t_test_temp_table1" + assertEquals(show_tablets_result.size(), 3) + + sql "show column stats t_test_temp_table2;" + + sql "show data skew from t_test_temp_table2" + def show_result = sql "show create table t_test_temp_table1" assertEquals(show_result[0][0], "t_test_temp_table1") assertTrue(show_result[0][1].contains("CREATE TEMPORARY TABLE")) @@ -114,25 +140,104 @@ suite("test_temp_table") { insert into t_test_temp_table2 select * from t_test_table_with_data; """ - sql """ - update t_test_temp_table1 set name='Blair' where id=2; - """ + // must be in front of update, update is a kind of insert + def show_insert = sql "show last insert" + containTempTable = false + for(int i = 0; i < show_insert.size(); i++) { + if (show_insert[i][3].equals("t_test_temp_table2")) { + containTempTable = true; + } + } + assertTrue(containTempTable) sql """ - delete from t_test_temp_table1 where id=3; + update t_test_temp_table1 set name='Blair' where id=2; """ sql """ - alter table t_test_temp_table1 add column age int; + delete from t_test_temp_table2 where id=3; """ - def select_result1 = sql "select * from t_test_temp_table1" + def select_result1 = sql "select * from t_test_temp_table2" assertEquals(select_result1.size(), 2) def select_result2 = sql "select t1.* from t_test_temp_table1 t1 join t_test_temp_table2 t2 on t1.id = t2.id and t1.name = t2.name" assertEquals(select_result2.size(), 1) assertEquals(select_result2[0][2], "Alice") + def show_delete = sql "show delete" + containTempTable = false + for(int i = 0; i < show_delete.size(); i++) { + if (show_delete[i][0].equals("t_test_temp_table2")) { + containTempTable = true; + } + } + assertTrue(containTempTable) + + def show_table_status = sql "show table status" + containTempTable = false + for(int i = 0; i < show_table_status.size(); i++) { + if (show_table_status[i][0].equals("t_test_temp_table2")) { + containTempTable = true; + } + } + assertTrue(containTempTable) + + //export + def uuid = UUID.randomUUID().toString() + def outFilePath = """/tmp/test_export_${uuid}""" + + try { + sql """ + EXPORT TABLE t_test_temp_table2 TO "file://${outFilePath}" + PROPERTIES ( + "columns" = "id,name,add_date", + "format" = "parquet" + ) + """ + throw new IllegalStateException("Should throw error") + } catch (Exception ex) { + assertTrue(ex.getMessage().contains("do not support export"), ex.getMessage()) + } + + //outfile + sql """ + select * from t_test_temp_table2 + into outfile "file://${outFilePath}" + """ + + + // temporary table with dynamic partitions and colocate group + sql """ + CREATE TEMPORARY TABLE temp_table_with_dyncmic_partition + ( + k1 DATE + ) + PARTITION BY RANGE(k1) () + DISTRIBUTED BY HASH(k1) + PROPERTIES + ( + "replication_allocation" = "tag.location.default: 1", + "dynamic_partition.enable" = "true", + "dynamic_partition.time_unit" = "DAY", + "dynamic_partition.start" = "-7", + "dynamic_partition.end" = "3", + "dynamic_partition.prefix" = "p", + "dynamic_partition.buckets" = "10", + "colocate_with" = "colocate_group1" + ); + """ + def select_partitions1 = sql "show partitions from temp_table_with_dyncmic_partition" + assertEquals(select_partitions1.size(), 4) + + try { + sql "CREATE MATERIALIZED VIEW mv_mtmv1 as select k1 from temp_table_with_dyncmic_partition" + throw new IllegalStateException("Should throw error") + } catch (Exception ex) { + assertTrue(ex.getMessage().contains("table not found"), ex.getMessage()) + } + def show_create_mv1 = sql "show create materialized view mv_mtmv1 on temp_table_with_dyncmic_partition" + assertEquals(show_create_mv1.size(), 0) // create another session and check temp table related function in it def result2 = connect('root') { @@ -155,10 +260,30 @@ suite("test_temp_table") { // temp table with same name in another db is legal sql """create database if not exists regression_test_temp_table_db2""" sql """ - create temp table regression_test_temp_table_db2.t_test_temp_table1 PROPERTIES ('replication_num' = '1') as + create temporary table regression_test_temp_table_db2.t_test_temp_table1 PROPERTIES ('replication_num' = '1', 'compression' = 'ZSTD') as select * from t_test_table_with_data; """ + + // only show delete info in current session + def show_delete2 = sql "show delete" + containTempTable = false + for(int i = 0; i < show_delete2.size(); i++) { + if (show_delete2[i][0].equals("t_test_temp_table2")) { + containTempTable = true; + } + } + assertFalse(containTempTable) + + // only show table status info in current session + def show_status = sql "show table status" + containTempTable = false + for(int i = 0; i < show_status.size(); i++) { + if (show_status[i][0].equals("t_test_temp_table2")) { + containTempTable = true; + } + } + assertFalse(containTempTable) } // temp tables created by a session will be deleted when the session exit @@ -176,6 +301,86 @@ suite("test_temp_table") { assertEquals(show_result2.size(), 1) assertFalse(show_result2[0][1].contains("CREATE TEMPORARY TABLE")) + // analyze + sql """analyze table t_test_temp_table2 with sample percent 10""" + sleep(6000) + def show_analyze_result1 = sql "show column stats t_test_temp_table2" + assertEquals(show_analyze_result1.size(), 3) + + def show_dynamic_partitions = sql "show dynamic partition tables" + containTempTable = false + for(int i = 0; i < show_dynamic_partitions.size(); i++) { + if (show_dynamic_partitions[i][0].equals("temp_table_with_dyncmic_partition")) { + containTempTable = true; + } + } + assertTrue(containTempTable) + + // truncate + sql "truncate table t_test_temp_table2" + select_result3 = sql "select * from t_test_temp_table2" + assertEquals(select_result3.size(), 0) + + // test stream load + streamLoad { + table 't_test_temp_table2' + set 'column_separator', ',' + file 'temp_table_data.csv' + } + sql "sync" + select_result3 = sql "select * from t_test_temp_table2" + assertEquals(select_result3.size(), 3) + + // truncate + sql "truncate table t_test_temp_table2" + select_result3 = sql "select * from t_test_temp_table2" + assertEquals(select_result3.size(), 0) + + // test mysql load + def filepath = getLoalFilePath "temp_table_data.csv" + sql """ + LOAD DATA LOCAL + INFILE '${filepath}' + INTO TABLE t_test_temp_table2 + COLUMNS TERMINATED BY ',' + """ + sql "sync" + select_result3 = sql "select * from t_test_temp_table2" + assertEquals(select_result3.size(), 3) + + // alter + try { + sql "alter table t_test_temp_table2 rename t_test_temp_table2_new" + throw new IllegalStateException("Should throw error") + } catch (Exception ex) { + assertTrue(ex.getMessage().contains("detailMessage = Do not support alter"), ex.getMessage()) + } + try { + sql "alter table t_test_temp_table2 add column new_col int" + throw new IllegalStateException("Should throw error") + } catch (Exception ex) { + assertTrue(ex.getMessage().contains("detailMessage = Do not support alter"), ex.getMessage()) + } + try { + sql "CREATE INDEX bitmap_index_1 ON t_test_temp_table2 (name) USING BITMAP COMMENT 'bitmap_name';" + throw new IllegalStateException("Should throw error") + } catch (Exception ex) { + assertTrue(ex.getMessage().contains("detailMessage = Do not support alter"), ex.getMessage()) + } + def show_index_2 = sql "show index from t_test_temp_table2" + assertEquals(show_index_2.size(), 0) + + sql """drop table temp_table_with_dyncmic_partition""" + def show_recycle_result1 = sql "show catalog recycle bin" + containTempTable = false + for(int i = 0; i < show_recycle_result1.size(); i++) { + if (show_recycle_result1[i][1].equals("temp_table_with_dyncmic_partition")) { + containTempTable = true; + } + } + assertFalse(containTempTable) + + // clean sql """drop table t_test_temp_table1""" sql """drop table if exists t_test_table_with_data""" sql """drop database regression_test_temp_table_db2"""