Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
f9eee27
add information schema table
shuwenwei Oct 27, 2025
9e8b71a
fix
shuwenwei Oct 27, 2025
b471127
update InformationSchema
shuwenwei Oct 28, 2025
0a8c04f
Merge branch 'iotdb_master' into table_disk_usage_statistics
shuwenwei Oct 28, 2025
687bc24
add pushdown limit offset
shuwenwei Oct 31, 2025
1699e44
remove showDiskUsageStatement from table model
shuwenwei Nov 13, 2025
098392d
add it
shuwenwei Nov 14, 2025
ccfb4ec
Merge branch 'iotdb_master' into table_disk_usage_statistics
shuwenwei Nov 17, 2025
3fbf6a3
fix
shuwenwei Dec 3, 2025
b6787b4
fix
shuwenwei Dec 10, 2025
880718f
fix
shuwenwei Dec 10, 2025
03b0f2c
Merge branch 'iotdb_master' into table_disk_usage_statistics
shuwenwei Dec 10, 2025
640f998
fix conflict
shuwenwei Jan 8, 2026
a71f0d7
Merge branch 'iotdb_master' into table_disk_usage_statistics
shuwenwei Jan 8, 2026
524c727
add cache
shuwenwei Jan 15, 2026
3e3f682
compact
shuwenwei Jan 16, 2026
6575e6e
fix
shuwenwei Jan 19, 2026
8f2de96
Merge branch 'iotdb_master' into table_disk_usage_statistics_with_cache
shuwenwei Jan 19, 2026
991a1b6
record table size for when generating tsfile
shuwenwei Jan 19, 2026
dfc7929
use ServiceLoader
shuwenwei Jan 20, 2026
aafbb1c
add interface for object file table size cache
shuwenwei Jan 20, 2026
2b87ce7
refactor
shuwenwei Jan 20, 2026
3c63c68
add abstract cache writer
shuwenwei Jan 21, 2026
79d39aa
refactor
shuwenwei Jan 22, 2026
c3945c6
refactor
shuwenwei Jan 22, 2026
d641d10
throw exception
shuwenwei Jan 22, 2026
d3ec980
move constant to parent class
shuwenwei Jan 22, 2026
50bcedd
refactor
shuwenwei Jan 22, 2026
3a91c80
refactor
shuwenwei Jan 22, 2026
d661431
refactor
shuwenwei Jan 23, 2026
cd4837b
fix bug
shuwenwei Jan 23, 2026
3f919a2
add future
shuwenwei Jan 23, 2026
69f7da0
fix bug
shuwenwei Jan 26, 2026
71a6633
add methods
shuwenwei Jan 26, 2026
2d7d721
use public constructor
shuwenwei Jan 26, 2026
7ac968c
fix cache writer lifecycle
shuwenwei Jan 26, 2026
8b115ea
rename
shuwenwei Jan 26, 2026
7305468
add comments
shuwenwei Jan 26, 2026
51336a3
close
shuwenwei Jan 27, 2026
b698859
add ut
shuwenwei Jan 27, 2026
415e426
fix bug
shuwenwei Jan 27, 2026
83482fa
add ut
shuwenwei Jan 28, 2026
3210de1
fix bug
shuwenwei Jan 28, 2026
3cdec0d
add metric
shuwenwei Jan 28, 2026
dfd2078
fix bug
shuwenwei Jan 30, 2026
a18f763
add statistics
shuwenwei Feb 3, 2026
48ac272
fix
shuwenwei Feb 3, 2026
79b1bb9
add config
shuwenwei Feb 3, 2026
56e9bf2
remove stale code
shuwenwei Feb 3, 2026
325f513
Merge branch 'iotdb_master' into table_disk_usage_statistics_with_cache
shuwenwei Feb 3, 2026
eda148d
fix bug
shuwenwei Feb 3, 2026
34efb01
modify TableDiskUsageSupplier
shuwenwei Feb 3, 2026
0bbf45d
fix
shuwenwei Feb 4, 2026
0076b6b
use final
shuwenwei Feb 4, 2026
eda01fe
refactor
shuwenwei Feb 4, 2026
d4d641c
fix
shuwenwei Feb 4, 2026
8ea69e7
fix bug
shuwenwei Feb 4, 2026
271bd12
fix bug
shuwenwei Feb 5, 2026
07246a8
fix
shuwenwei Feb 5, 2026
66328b3
update tsfile version
shuwenwei Feb 5, 2026
0877c14
fix ut
shuwenwei Feb 5, 2026
398cf2b
fix copilot review comments
shuwenwei Feb 5, 2026
d7fafe4
fix bug
shuwenwei Feb 6, 2026
dd60404
fix bug
shuwenwei Feb 6, 2026
e7785f3
fix it
shuwenwei Feb 6, 2026
4a3bca1
fix it
shuwenwei Feb 6, 2026
a19bd11
fix sort
shuwenwei Feb 6, 2026
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
@@ -0,0 +1,163 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.iotdb.db.it;

import org.apache.iotdb.isession.ISession;
import org.apache.iotdb.isession.SessionDataSet;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.ClusterIT;
import org.apache.iotdb.itbase.category.LocalStandaloneIT;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.fail;

@RunWith(IoTDBTestRunner.class)
@Category({LocalStandaloneIT.class, ClusterIT.class})
public class IoTDBShowDiskUsageIT {

@BeforeClass
public static void setUp() throws Exception {
EnvFactory.getEnv().initClusterEnvironment();

try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
for (int i = 0; i < 20; i++) {
session.executeNonQueryStatement(
"insert into root.test.d" + i + "(time, s0, s1, s2) values (" + i + ",1, 1, 1)");
}
session.executeNonQueryStatement(
"insert into root.test.d0(time,s0,s1) aligned values (-1,1,1)");
session.executeNonQueryStatement("flush");
}
}

@AfterClass
public static void tearDown() throws Exception {
EnvFactory.getEnv().cleanClusterEnvironment();
}

@Test
public void test1() {

try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
SessionDataSet sessionDataSet =
session.executeQueryStatement("show disk_usage from root.test.**");
SessionDataSet.DataIterator iterator = sessionDataSet.iterator();
long sum = 0;
Map<Long, Long> timePartitionSizes = new HashMap<>();
while (iterator.next()) {
long timePartition = iterator.getLong("TimePartition");
long size = iterator.getLong("SizeInBytes");
timePartitionSizes.compute(timePartition, (k, v) -> v == null ? size : v + size);
sum += size;
}
Assert.assertTrue(sum > 0);
Assert.assertTrue(timePartitionSizes.containsKey(0L));
Assert.assertTrue(timePartitionSizes.containsKey(-1L));
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void test2() {
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
SessionDataSet sessionDataSet =
session.executeQueryStatement("show disk_usage from root.test.** limit 2");
SessionDataSet.DataIterator iterator = sessionDataSet.iterator();
int count = 0;
while (iterator.next()) {
count++;
}
Assert.assertEquals(2, count);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void test3() {
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
SessionDataSet sessionDataSet =
session.executeQueryStatement(
"show disk_usage from root.test.** order by TimePartition desc");
SessionDataSet.DataIterator iterator = sessionDataSet.iterator();
long previousTimePartition = Long.MAX_VALUE;
while (iterator.next()) {
long currentTimePartition = iterator.getLong("TimePartition");
Assert.assertTrue(currentTimePartition <= previousTimePartition);
previousTimePartition = currentTimePartition;
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void test4() {
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
SessionDataSet sessionDataSet =
session.executeQueryStatement(
"show disk_usage from root.test.** where TimePartition < 0 or DataNodeId >= 2");
SessionDataSet.DataIterator iterator = sessionDataSet.iterator();
while (iterator.next()) {
Assert.assertTrue(
iterator.getLong("TimePartition") < 0 || iterator.getLong("DataNodeId") >= 2);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void test5() {
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
SessionDataSet sessionDataSet =
session.executeQueryStatement(
"show disk_usage from root.test.** order by TimePartition desc limit 2");
SessionDataSet.DataIterator iterator = sessionDataSet.iterator();
long previousTimePartition = Long.MAX_VALUE;
int count = 0;
while (iterator.next()) {
count++;
long currentTimePartition = iterator.getLong("TimePartition");
Assert.assertTrue(currentTimePartition <= previousTimePartition);
previousTimePartition = currentTimePartition;
}
Assert.assertEquals(2, count);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.iotdb.relational.it;

import org.apache.iotdb.isession.ITableSession;
import org.apache.iotdb.isession.SessionDataSet;
import org.apache.iotdb.it.env.EnvFactory;
import org.apache.iotdb.it.framework.IoTDBTestRunner;
import org.apache.iotdb.itbase.category.TableClusterIT;
import org.apache.iotdb.itbase.category.TableLocalStandaloneIT;

import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;

import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.fail;

@RunWith(IoTDBTestRunner.class)
@Category({TableLocalStandaloneIT.class, TableClusterIT.class})
public class IoTDBShowDiskUsageTableIT {

@BeforeClass
public static void setUp() throws Exception {
EnvFactory.getEnv().initClusterEnvironment();
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) {
session.executeNonQueryStatement("create database test");
session.executeNonQueryStatement("use test");
session.executeNonQueryStatement(
"create table t1(tag1 string tag, s0 int32 field, s1 int32 field)");
session.executeNonQueryStatement(
"create table t2(tag1 string tag, s0 int32 field, s1 int32 field)");
session.executeNonQueryStatement(
"create view v1(tag1 string tag, s0 int32 field, s1 int32 field) as root.test.**");
for (int i = 0; i < 20; i++) {
session.executeNonQueryStatement(
"insert into t1(time,tag1,s0,s1) values (" + i + ", 'd" + i + "', 1, 1)");
}
session.executeNonQueryStatement("insert into t1(time,tag1,s0,s1) values (-1,'d1',1,1)");
session.executeNonQueryStatement("flush");
}
}

@AfterClass
public static void tearDown() throws Exception {
EnvFactory.getEnv().cleanClusterEnvironment();
}

@Test
public void test1() {
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) {
SessionDataSet sessionDataSet =
session.executeQueryStatement(
"select * from information_schema.table_disk_usage where database = 'test'");
SessionDataSet.DataIterator iterator = sessionDataSet.iterator();
long sum = 0;
Map<Long, Long> timePartitionSizes = new HashMap<>();
Map<String, Long> tableSizes = new HashMap<>();
while (iterator.next()) {
String table = iterator.getString("table_name");
long timePartition = iterator.getLong("time_partition");
long size = iterator.getLong("size_in_bytes");
timePartitionSizes.compute(timePartition, (k, v) -> v == null ? size : v + size);
tableSizes.compute(table, (k, v) -> v == null ? size : v + size);
sum += size;
}
Assert.assertTrue(sum > 0);
Assert.assertEquals(2, tableSizes.size());
Assert.assertEquals(0L, (long) tableSizes.get("t2"));
Assert.assertFalse(tableSizes.containsKey("v1"));
Assert.assertTrue(timePartitionSizes.containsKey(0L));
Assert.assertTrue(timePartitionSizes.containsKey(-1L));
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void test2() {
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) {
SessionDataSet sessionDataSet =
session.executeQueryStatement(
"select * from information_schema.table_disk_usage where database = 'test' limit 2");
SessionDataSet.DataIterator iterator = sessionDataSet.iterator();
int count = 0;
while (iterator.next()) {
count++;
}
Assert.assertEquals(2, count);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void test3() {
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) {
SessionDataSet sessionDataSet =
session.executeQueryStatement(
"select * from information_schema.table_disk_usage where database = 'test' order by time_partition desc");
SessionDataSet.DataIterator iterator = sessionDataSet.iterator();
long previousTimePartition = Long.MAX_VALUE;
while (iterator.next()) {
long currentTimePartition = iterator.getLong("time_partition");
Assert.assertTrue(currentTimePartition <= previousTimePartition);
previousTimePartition = currentTimePartition;
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void test4() {
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) {
SessionDataSet sessionDataSet =
session.executeQueryStatement(
"select * from information_schema.table_disk_usage where database = 'test' and (time_partition < 0 or datanode_id >= 2)");
SessionDataSet.DataIterator iterator = sessionDataSet.iterator();
while (iterator.next()) {
Assert.assertTrue(
iterator.getLong("time_partition") < 0 || iterator.getLong("datanode_id") >= 2);
}
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void test5() {
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnection()) {
SessionDataSet sessionDataSet =
session.executeQueryStatement(
"select * from information_schema.table_disk_usage where database = 'test' order by time_partition desc limit 2");
SessionDataSet.DataIterator iterator = sessionDataSet.iterator();
long previousTimePartition = Long.MAX_VALUE;
int count = 0;
while (iterator.next()) {
count++;
long currentTimePartition = iterator.getLong("time_partition");
Assert.assertTrue(currentTimePartition <= previousTimePartition);
previousTimePartition = currentTimePartition;
}
Assert.assertEquals(2, count);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ public void testInformationSchema() throws SQLException {
"regions,INF,",
"services,INF,",
"subscriptions,INF,",
"table_disk_usage,INF,",
"tables,INF,",
"topics,INF,",
"views,INF,"));
Expand Down Expand Up @@ -566,6 +567,17 @@ public void testInformationSchema() throws SQLException {
"mpp_port,INT32,ATTRIBUTE,",
"data_consensus_port,INT32,ATTRIBUTE,",
"schema_consensus_port,INT32,ATTRIBUTE,")));
TestUtils.assertResultSetEqual(
statement.executeQuery("desc table_disk_usage"),
"ColumnName,DataType,Category,",
new HashSet<>(
Arrays.asList(
"database,STRING,FIELD,",
"table_name,STRING,FIELD,",
"datanode_id,INT32,FIELD,",
"region_id,INT32,FIELD,",
"time_partition,INT64,FIELD,",
"size_in_bytes,INT64,FIELD,")));

// Only root user is allowed
Assert.assertThrows(SQLException.class, () -> statement.execute("select * from regions"));
Expand All @@ -580,6 +592,8 @@ public void testInformationSchema() throws SQLException {
Assert.assertThrows(SQLException.class, () -> statement.execute("select * from data_nodes"));
Assert.assertThrows(
SQLException.class, () -> statement.executeQuery("select * from pipe_plugins"));
Assert.assertThrows(
SQLException.class, () -> statement.executeQuery("select * from table_disk_usage"));

// Filter out not self-created pipes
TestUtils.assertResultSetEqual(
Expand Down Expand Up @@ -645,6 +659,7 @@ public void testInformationSchema() throws SQLException {
"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,table_disk_usage,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,connections,INF,USING,null,SYSTEM VIEW,",
Expand All @@ -655,7 +670,7 @@ public void testInformationSchema() throws SQLException {
TestUtils.assertResultSetEqual(
statement.executeQuery("count devices from tables where status = 'USING'"),
"count(devices),",
Collections.singleton("22,"));
Collections.singleton("23,"));
TestUtils.assertResultSetEqual(
statement.executeQuery(
"select * from columns where table_name = 'queries' or database = 'test'"),
Expand Down
Loading
Loading