Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Yulei-Yang committed Sep 29, 2024
1 parent 3d0e4f6 commit 4a58a0d
Show file tree
Hide file tree
Showing 32 changed files with 409 additions and 93 deletions.
1 change: 0 additions & 1 deletion fe/fe-core/src/main/java/org/apache/doris/alter/Alter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ public Table getTableNullable(String tableName) {
if (table == null) {
table = nameToTable.get(tableName);
}

return table;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions fe/fe-core/src/main/java/org/apache/doris/common/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 12 additions & 3 deletions fe/fe-core/src/main/java/org/apache/doris/load/DeleteHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -264,15 +265,23 @@ public List<List<Comparable>> 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<Comparable> 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -247,6 +249,10 @@ private ExportJob generateExportJob(ConnectContext ctx, Map<String, String> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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) {
Expand Down
39 changes: 36 additions & 3 deletions fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,14 @@ private void handleShowTableId() throws AnalysisException {
if (table != null) {
List<String> 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;
Expand Down Expand Up @@ -902,7 +909,14 @@ private void handleShowPartitionId() throws AnalysisException {
if (partition != null) {
List<String> 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()));
Expand Down Expand Up @@ -1034,7 +1048,14 @@ private void handleShowTableStatus() throws AnalysisException {
}
List<String> 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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -205,6 +206,9 @@ public List<AnalysisInfo> buildAnalysisInfosForDB(DatabaseIf<TableIf> 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()
Expand Down
3 changes: 3 additions & 0 deletions regression-test/data/table_p0/temp_table_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
1,'2024-01-01','Alice'
2,'2024-01-02','Bob'
3,'2024-02-01','Carl'
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
Loading

0 comments on commit 4a58a0d

Please sign in to comment.