Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9aa0e6d
partial
Caideyipi May 19, 2025
69328e5
Partial
Caideyipi May 19, 2025
c2adf08
Update confignode.thrift
Caideyipi May 19, 2025
741589f
table schema
Caideyipi May 19, 2025
a25d674
Update CreateTableProcedure.java
Caideyipi May 19, 2025
b78baa4
Partial
Caideyipi May 19, 2025
6c8d342
Update ConfigMTree.java
Caideyipi May 19, 2025
fd526e3
Update confignode.thrift
Caideyipi May 19, 2025
abf7572
Partial
Caideyipi May 19, 2025
36cb154
Update ShowCreateTableTask.java
Caideyipi May 19, 2025
832dc6a
Update ShowCreateViewTask.java
Caideyipi May 19, 2025
0d49ba8
partial
Caideyipi May 19, 2025
eedbd1c
Update InformationSchemaUtils.java
Caideyipi May 19, 2025
51aa84d
Partial
Caideyipi May 19, 2025
4e98a2d
Partial
Caideyipi May 20, 2025
e6993aa
Partial
Caideyipi May 20, 2025
8669113
Merge branch 'master' of https://github.com/apache/iotdb into need_la…
Caideyipi May 20, 2025
9f35a60
partial
Caideyipi May 20, 2025
678c34d
Update IdentifierParser.g4
Caideyipi May 20, 2025
d54543a
partial
Caideyipi May 20, 2025
2b51fa2
Partial
Caideyipi May 20, 2025
b3c70ad
Update IoTDBTableIT.java
Caideyipi May 20, 2025
ce420f6
Merge branch 'master' of https://github.com/apache/iotdb into need_la…
Caideyipi May 20, 2025
f5d3d75
Update IoTDBDatabaseIT.java
Caideyipi May 20, 2025
31b094f
Update IoTDBDatabaseIT.java
Caideyipi May 20, 2025
4e9582a
Update IoTDBTableIT.java
Caideyipi May 20, 2025
a46ea18
Refactor
Caideyipi May 20, 2025
8715629
partial
Caideyipi May 20, 2025
bb21903
Update PartitionCache.java
Caideyipi May 20, 2025
3cc569d
Update PartitionCache.java
Caideyipi May 20, 2025
7c23045
Partial
Caideyipi May 20, 2025
504c97c
Partial
Caideyipi May 20, 2025
c5ef08e
Update IoTDBTableIT.java
Caideyipi May 20, 2025
e191f35
Merge branch 'master' of https://github.com/apache/iotdb into need_la…
Caideyipi May 20, 2025
8569987
Update IoTDBTableIT.java
Caideyipi May 20, 2025
040457a
Fix
Caideyipi May 20, 2025
01180dc
Merge branch 'master' of https://github.com/apache/iotdb into need_la…
Caideyipi Oct 27, 2025
fb8aa46
fix-merge
Caideyipi Oct 27, 2025
cdf52b7
fix
Caideyipi Oct 27, 2025
ccc2459
fix
Caideyipi Oct 27, 2025
da3fbc6
fix
Caideyipi Oct 27, 2025
def810d
IT-fix
Caideyipi Oct 27, 2025
3786e3e
Update IoTDBDatabaseIT.java
Caideyipi Oct 27, 2025
dc42172
Merge branch 'master' of https://github.com/apache/iotdb into need_la…
Caideyipi Nov 17, 2025
8a763b4
fix
Caideyipi Nov 20, 2025
efefd90
fix
Caideyipi Dec 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public void testManageDatabase() {

statement.execute("alter database if exists test1 set properties ttl='INF'");
statement.execute("alter database test set properties ttl=default");
statement.execute("alter database test set properties need_last_cache=false");

String[] databaseNames = new String[] {"test"};
String[] TTLs = new String[] {"INF"};
Expand Down Expand Up @@ -160,6 +161,7 @@ public void testManageDatabase() {
assertEquals(timePartitionInterval[cnt], resultSet.getLong(5));
assertEquals(schemaRegionGroupNum[cnt], resultSet.getInt(6));
assertEquals(dataRegionGroupNum[cnt], resultSet.getInt(7));
assertFalse(resultSet.getBoolean(8));
cnt++;
}
assertEquals(databaseNames.length, cnt);
Expand Down Expand Up @@ -424,7 +426,8 @@ public void testInformationSchema() throws SQLException {
"data_replication_factor,INT32,ATTRIBUTE,",
"time_partition_interval,INT64,ATTRIBUTE,",
"schema_region_group_num,INT32,ATTRIBUTE,",
"data_region_group_num,INT32,ATTRIBUTE,")));
"data_region_group_num,INT32,ATTRIBUTE,",
"need_last_cache,BOOLEAN,ATTRIBUTE,")));
TestUtils.assertResultSetEqual(
statement.executeQuery("desc tables"),
"ColumnName,DataType,Category,",
Expand All @@ -435,7 +438,8 @@ public void testInformationSchema() throws SQLException {
"ttl(ms),STRING,ATTRIBUTE,",
"status,STRING,ATTRIBUTE,",
"comment,STRING,ATTRIBUTE,",
"table_type,STRING,ATTRIBUTE,")));
"table_type,STRING,ATTRIBUTE,",
"need_last_cache,BOOLEAN,ATTRIBUTE,")));
TestUtils.assertResultSetEqual(
statement.executeQuery("desc columns"),
"ColumnName,DataType,Category,",
Expand Down Expand Up @@ -603,39 +607,40 @@ public void testInformationSchema() throws SQLException {
statement.execute(
"create table test.test (a tag, b attribute, c int32 comment 'turbine') comment 'test'");
statement.execute(
"CREATE VIEW test.view_table (tag1 STRING TAG,tag2 STRING TAG,s11 INT32 FIELD,s3 INT32 FIELD FROM s2) RESTRICT WITH (ttl=100) AS root.\"a\".**");
"CREATE VIEW test.view_table (tag1 STRING TAG,tag2 STRING TAG,s11 INT32 FIELD,s3 INT32 FIELD FROM s2) RESTRICT WITH (ttl=100, need_last_cache=true) AS root.\"a\".**");

TestUtils.assertResultSetEqual(
statement.executeQuery("select * from databases"),
"database,ttl(ms),schema_replication_factor,data_replication_factor,time_partition_interval,schema_region_group_num,data_region_group_num,",
"database,ttl(ms),schema_replication_factor,data_replication_factor,time_partition_interval,schema_region_group_num,data_region_group_num,need_last_cache,",
new HashSet<>(
Arrays.asList(
"information_schema,INF,null,null,null,null,null,",
"test,INF,1,1,604800000,0,0,")));
"information_schema,INF,null,null,null,null,null,false,",
"test,INF,1,1,604800000,0,0,true,")));
TestUtils.assertResultSetEqual(
statement.executeQuery("show devices from tables where status = 'USING'"),
"database,table_name,ttl(ms),status,comment,table_type,",
"database,table_name,ttl(ms),status,comment,table_type,need_last_cache,",
new HashSet<>(
Arrays.asList(
"information_schema,databases,INF,USING,null,SYSTEM VIEW,",
"information_schema,tables,INF,USING,null,SYSTEM VIEW,",
"information_schema,columns,INF,USING,null,SYSTEM VIEW,",
"information_schema,queries,INF,USING,null,SYSTEM VIEW,",
"information_schema,regions,INF,USING,null,SYSTEM VIEW,",
"information_schema,topics,INF,USING,null,SYSTEM VIEW,",
"information_schema,pipe_plugins,INF,USING,null,SYSTEM VIEW,",
"information_schema,pipes,INF,USING,null,SYSTEM VIEW,",
"information_schema,subscriptions,INF,USING,null,SYSTEM VIEW,",
"information_schema,views,INF,USING,null,SYSTEM VIEW,",
"information_schema,functions,INF,USING,null,SYSTEM VIEW,",
"information_schema,configurations,INF,USING,null,SYSTEM VIEW,",
"information_schema,keywords,INF,USING,null,SYSTEM VIEW,",
"information_schema,nodes,INF,USING,null,SYSTEM VIEW,",
"information_schema,config_nodes,INF,USING,null,SYSTEM VIEW,",
"information_schema,data_nodes,INF,USING,null,SYSTEM VIEW,",
"information_schema,databases,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,tables,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,columns,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,queries,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,regions,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,topics,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,pipe_plugins,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,pipes,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,subscriptions,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,views,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,models,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,functions,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,configurations,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,keywords,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,nodes,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,config_nodes,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,data_nodes,INF,USING,null,SYSTEM VIEW,false,",
"information_schema,connections,INF,USING,null,SYSTEM VIEW,",
"test,test,INF,USING,test,BASE TABLE,",
"test,view_table,100,USING,null,VIEW FROM TREE,")));
"test,test,INF,USING,test,BASE TABLE,true,",
"test,view_table,100,USING,null,VIEW FROM TREE,true,")));
TestUtils.assertResultSetEqual(
statement.executeQuery("count devices from tables where status = 'USING'"),
"count(devices),",
Expand Down Expand Up @@ -686,7 +691,7 @@ public void testInformationSchema() throws SQLException {
statement.executeQuery("select * from views"),
"database,table_name,view_definition,",
Collections.singleton(
"test,view_table,CREATE VIEW \"view_table\" (\"tag1\" STRING TAG,\"tag2\" STRING TAG,\"s11\" INT32 FIELD,\"s3\" INT32 FIELD FROM \"s2\") RESTRICT WITH (ttl=100) AS root.\"a\".**,"));
"test,view_table,CREATE VIEW \"view_table\" (\"tag1\" STRING TAG,\"tag2\" STRING TAG,\"s11\" INT32 FIELD,\"s3\" INT32 FIELD FROM \"s2\") RESTRICT WITH (ttl=100, need_last_cache=true) AS root.\"a\".**,"));

TestUtils.assertResultSetEqual(
statement.executeQuery(
Expand Down Expand Up @@ -814,8 +819,8 @@ public void testDBAuth() throws SQLException {
Collections.singleton("information_schema,INF,null,null,null,"));
TestUtils.assertResultSetEqual(
userStmt.executeQuery("select * from information_schema.databases"),
"database,ttl(ms),schema_replication_factor,data_replication_factor,time_partition_interval,schema_region_group_num,data_region_group_num,",
Collections.singleton("information_schema,INF,null,null,null,null,null,"));
"database,ttl(ms),schema_replication_factor,data_replication_factor,time_partition_interval,schema_region_group_num,data_region_group_num,need_last_cache,",
Collections.singleton("information_schema,INF,null,null,null,null,null,false,"));
}

try (final Connection adminCon = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public void testManageTable() {
String[] ttls = new String[] {"INF"};
String[] statuses = new String[] {"USING"};
String[] comments = new String[] {"test"};
String[] needLastCaches = new String[] {"true"};

statement.execute("use test2");

Expand All @@ -145,6 +146,7 @@ public void testManageTable() {
assertEquals(ttls[cnt], resultSet.getString(2));
assertEquals(statuses[cnt], resultSet.getString(3));
assertEquals(comments[cnt], resultSet.getString(4));
assertEquals(needLastCaches[cnt], resultSet.getString(6));
cnt++;
}
assertEquals(tableNames.length, cnt);
Expand Down Expand Up @@ -189,6 +191,9 @@ public void testManageTable() {

statement.execute("comment on table test1.table1 is 'new_test'");
comments = new String[] {"new_test"};

statement.execute("alter table test1.table1 set properties need_last_cache=false");
needLastCaches = new String[] {"false"};
// using SHOW tables from
try (final ResultSet resultSet = statement.executeQuery("SHOW tables details from test1")) {
int cnt = 0;
Expand All @@ -202,6 +207,7 @@ public void testManageTable() {
assertEquals(tableNames[cnt], resultSet.getString(1));
assertEquals(ttls[cnt], resultSet.getString(2));
assertEquals(comments[cnt], resultSet.getString(4));
assertEquals(needLastCaches[cnt], resultSet.getString(6));
cnt++;
}
assertEquals(tableNames.length, cnt);
Expand Down Expand Up @@ -305,7 +311,7 @@ public void testManageTable() {
statement.executeQuery("show create table table2"),
"Table,Create Table,",
Collections.singleton(
"table2,CREATE TABLE \"table2\" (\"region_id\" STRING TAG,\"plant_id\" STRING TAG,\"color\" STRING ATTRIBUTE,\"temperature\" FLOAT FIELD,\"speed\" DOUBLE FIELD COMMENT 'fast') WITH (ttl=6600000),"));
"table2,CREATE TABLE \"table2\" (\"region_id\" STRING TAG,\"plant_id\" STRING TAG,\"color\" STRING ATTRIBUTE,\"temperature\" FLOAT FIELD,\"speed\" DOUBLE FIELD COMMENT 'fast') WITH (ttl=6600000, need_last_cache=true),"));

try {
statement.execute("alter table table2 add column speed DOUBLE FIELD");
Expand Down Expand Up @@ -656,7 +662,7 @@ public void testTableAuth() throws SQLException {
Assert.assertThrows(SQLException.class, () -> userStmt.execute("select * from db.test"));
TestUtils.assertResultSetEqual(
userStmt.executeQuery("select * from information_schema.tables where database = 'db'"),
"database,table_name,ttl(ms),status,comment,table_type,",
"database,table_name,ttl(ms),status,comment,table_type,need_last_cache,",
Collections.emptySet());
TestUtils.assertResultSetEqual(
userStmt.executeQuery("select * from information_schema.columns where database = 'db'"),
Expand Down Expand Up @@ -939,8 +945,8 @@ public void testTreeViewTable() throws Exception {

TestUtils.assertResultSetEqual(
statement.executeQuery("show tables details"),
"TableName,TTL(ms),Status,Comment,TableType,",
Collections.singleton("view_table,100,USING,comment,VIEW FROM TREE,"));
"TableName,TTL(ms),Status,Comment,TableType,NeedLastCache,",
Collections.singleton("view_table,100,USING,comment,VIEW FROM TREE,true,"));

TestUtils.assertResultSetEqual(
statement.executeQuery("desc view_table"),
Expand Down Expand Up @@ -1075,14 +1081,14 @@ public void testTreeViewTable() throws Exception {
statement.executeQuery("show create view view_table"),
"View,Create View,",
Collections.singleton(
"view_table,CREATE VIEW \"view_table\" (\"tag1\" STRING TAG,\"tag2\" STRING TAG,\"s11\" INT32 FIELD,\"s3\" STRING FIELD FROM \"s2\") RESTRICT WITH (ttl=100) AS root.\"重庆\".**,"));
"view_table,CREATE VIEW \"view_table\" (\"tag1\" STRING TAG,\"tag2\" STRING TAG,\"s11\" INT32 FIELD,\"s3\" STRING FIELD FROM \"s2\") RESTRICT WITH (ttl=100, need_last_cache=true) AS root.\"重庆\".**,"));

// Can also use "show create table"
TestUtils.assertResultSetEqual(
statement.executeQuery("show create table view_table"),
"View,Create View,",
Collections.singleton(
"view_table,CREATE VIEW \"view_table\" (\"tag1\" STRING TAG,\"tag2\" STRING TAG,\"s11\" INT32 FIELD,\"s3\" STRING FIELD FROM \"s2\") RESTRICT WITH (ttl=100) AS root.\"重庆\".**,"));
"view_table,CREATE VIEW \"view_table\" (\"tag1\" STRING TAG,\"tag2\" STRING TAG,\"s11\" INT32 FIELD,\"s3\" STRING FIELD FROM \"s2\") RESTRICT WITH (ttl=100, need_last_cache=true) AS root.\"重庆\".**,"));

statement.execute("create table a ()");
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ keyWords
| MODELS
| MODIFY
| NAN
| NEED_LAST_CACHE
| NODEID
| NODES
| NONE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ databaseAttributesClause

databaseAttributeClause
: databaseAttributeKey operator_eq INTEGER_LITERAL
| NEED_LAST_CACHE operator_eq boolean_literal
;

databaseAttributeKey
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,10 @@ DATA_REGION_GROUP_NUM
: D A T A '_' R E G I O N '_' G R O U P '_' N U M
;

NEED_LAST_CACHE
: N E E D '_' L A S T '_' C A C H E
;

CURRENT_TIMESTAMP
: C U R R E N T '_' T I M E S T A M P
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ public TShowDatabaseResp showDatabase(final GetDatabasePlan getDatabasePlan) {
databaseInfo.setDataReplicationFactor(databaseSchema.getDataReplicationFactor());
databaseInfo.setTimePartitionOrigin(databaseSchema.getTimePartitionOrigin());
databaseInfo.setTimePartitionInterval(databaseSchema.getTimePartitionInterval());
databaseInfo.setNeedLastCache(databaseSchema.isNeedLastCache());
databaseInfo.setMinSchemaRegionNum(
getMinRegionGroupNum(database, TConsensusGroupType.SchemaRegion));
databaseInfo.setMaxSchemaRegionNum(
Expand Down Expand Up @@ -873,6 +874,10 @@ public static TSStatus enrichDatabaseSchemaWithDefaultProperties(
"Failed to create database. The timePartitionInterval should be positive.");
}

if (!databaseSchema.isSetNeedLastCache()) {
databaseSchema.setNeedLastCache(true);
}

if (isSystemDatabase || isAuditDatabase) {
databaseSchema.setMinSchemaRegionGroupNum(1);
} else if (!databaseSchema.isSetMinSchemaRegionGroupNum()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
import static org.apache.iotdb.commons.schema.SchemaConstant.SYSTEM_DATABASE_PATTERN;
import static org.apache.iotdb.commons.schema.table.Audit.TABLE_MODEL_AUDIT_DATABASE;
import static org.apache.iotdb.commons.schema.table.Audit.TREE_MODEL_AUDIT_DATABASE;
import static org.apache.iotdb.commons.schema.table.TsTable.NEED_LAST_CACHE_PROPERTY;
import static org.apache.iotdb.commons.schema.table.TsTable.TTL_PROPERTY;

/**
Expand Down Expand Up @@ -271,6 +272,21 @@ public TSStatus alterDatabase(final DatabaseSchemaPlan plan) {
currentSchema.getTTL());
}

if (alterSchema.isSetNeedLastCache()
&& alterSchema.isNeedLastCache()
!= (!currentSchema.isSetNeedLastCache() || currentSchema.isNeedLastCache())) {
if (!currentSchema.isIsTableModel()) {
result.setCode(TSStatusCode.SEMANTIC_ERROR.getStatusCode());
result.setMessage("The tree model database does not support alter need last cache now.");
return result;
}
currentSchema.setNeedLastCache(alterSchema.isNeedLastCache());
LOGGER.info(
"[SetNeedLastCache] The need last cache flag of Database: {} is adjusted to: {}",
currentSchema.getName(),
currentSchema.isNeedLastCache());
}

mTree
.getDatabaseNodeByDatabasePath(partialPathName)
.getAsMNode()
Expand Down Expand Up @@ -1285,6 +1301,11 @@ public ShowTableResp showTables(final ShowTablePlan plan) {
TreeViewSchema.isTreeViewTable(pair.getLeft())
? TableType.VIEW_FROM_TREE.ordinal()
: TableType.BASE_TABLE.ordinal());
info.setNeedLastCache(
pair.getLeft()
.getPropValue(NEED_LAST_CACHE_PROPERTY)
.map(Boolean::parseBoolean)
.orElse(true));
return info;
})
.collect(Collectors.toList())
Expand Down Expand Up @@ -1333,6 +1354,11 @@ public ShowTable4InformationSchemaResp showTables4InformationSchema() {
TreeViewSchema.isTreeViewTable(pair.getLeft())
? TableType.VIEW_FROM_TREE.ordinal()
: TableType.BASE_TABLE.ordinal());
info.setNeedLastCache(
pair.getLeft()
.getPropValue(NEED_LAST_CACHE_PROPERTY)
.map(Boolean::parseBoolean)
.orElse(true));
return info;
})
.collect(Collectors.toList()))));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,11 @@ public void setTableProperties(
&& databaseNode.getDatabaseSchema().isSetTTL()
&& databaseNode.getDatabaseSchema().getTTL() != Long.MAX_VALUE) {
table.addProp(k, String.valueOf(databaseNode.getDatabaseSchema().getTTL()));
} else if (k.equals(TsTable.NEED_LAST_CACHE_PROPERTY)
&& databaseNode.getDatabaseSchema().isSetNeedLastCache()) {
table.addProp(
TsTable.NEED_LAST_CACHE_PROPERTY,
String.valueOf(databaseNode.getDatabaseSchema().isNeedLastCache()));
} else {
table.removeProp(k);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ protected void checkTableExistence(final ConfigNodeProcedureEnv env) {
&& schema.getTTL() != Long.MAX_VALUE) {
table.addProp(TsTable.TTL_PROPERTY, String.valueOf(schema.getTTL()));
}
if (!table.getPropValue(TsTable.NEED_LAST_CACHE_PROPERTY).isPresent()
&& schema.isSetNeedLastCache()) {
table.addProp(TsTable.NEED_LAST_CACHE_PROPERTY, String.valueOf(schema.isNeedLastCache()));
}
setNextState(CreateTableState.PRE_CREATE);
}
} catch (final MetadataException | DatabaseNotExistsException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ protected void checkTableExistence(final ConfigNodeProcedureEnv env) {
&& schema.getTTL() != Long.MAX_VALUE) {
table.addProp(TsTable.TTL_PROPERTY, String.valueOf(schema.getTTL()));
}
if (!table.getPropValue(TsTable.NEED_LAST_CACHE_PROPERTY).isPresent()
&& schema.isSetNeedLastCache()) {
table.addProp(
TsTable.NEED_LAST_CACHE_PROPERTY, String.valueOf(schema.isNeedLastCache()));
}
setNextState(CreateTableState.PRE_CREATE);
}
} catch (final MetadataException | DatabaseNotExistsException e) {
Expand Down
Loading
Loading