Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f6afc4e
Remove the code check port is occupied, and resolve the problem that …
zerolbsony Dec 9, 2025
5b9fc58
Merge branch 'master' of github.com:zerolbsony/iotdb
zerolbsony Dec 10, 2025
b0c3bfa
Adjust column name with the same as "desc regions"
zerolbsony Dec 10, 2025
d9fafc9
Merge branch 'master' of github.com:zerolbsony/iotdb
zerolbsony Dec 19, 2025
f9b7f9d
Only delete data, but don't delete tsfile when performing a drop colu…
zerolbsony Dec 19, 2025
8c92be6
Fix NPE
zerolbsony Dec 19, 2025
8b91c88
Don't delete tsfile when use tag as a where clause in the delete stat…
zerolbsony Dec 21, 2025
bdb9396
stash
zerolbsony Dec 31, 2025
0de2ba8
Merge branch 'master' of github.com:zerolbsony/iotdb
zerolbsony Dec 31, 2025
0d3c0b3
Merge branch 'master' of github.com:zerolbsony/iotdb
zerolbsony Jan 4, 2026
8a06414
Merge branch 'master' into improve_optimize_delete_tsfile
zerolbsony Jan 4, 2026
7eef316
Won't delete according tsfile files directly if IDPredicate type is n…
zerolbsony Jan 5, 2026
660b5e6
Merge branch 'master' of github.com:zerolbsony/iotdb
zerolbsony Jan 5, 2026
e570fda
Merge branch 'master' into improve_optimize_delete_tsfile
zerolbsony Jan 5, 2026
524cc4c
Occur incompatible exception when merging statistics, need to rewrite…
zerolbsony Jan 8, 2026
a9f3fb5
Don't merge statistics when two types are not compatible;
zerolbsony Jan 9, 2026
a864880
Fix out of bounds problem from unit test.
zerolbsony Jan 9, 2026
2c250e1
Use a constant variable instead of frequently creating a empty Binary…
zerolbsony Jan 9, 2026
77034e4
Merge branch 'master' of github.com:zerolbsony/iotdb
zerolbsony Jan 10, 2026
267c1bd
Merge branch 'master' into improve_optimize_delete_tsfile
zerolbsony Jan 10, 2026
b2927fc
When the statement to execute is to drop a column, put it in the mods…
zerolbsony Jan 11, 2026
080b69d
Repair and add the logic involve DATE data type.
zerolbsony Jan 11, 2026
9ba0fda
Fix problem that out of bounds in the SchemaUtilsTest.
zerolbsony Jan 12, 2026
87a4da5
In order to avoid get chunkMetadata of other index in the array, wish…
zerolbsony Jan 12, 2026
bdf8543
Fix the issue "Only the target component should be written, not all o…
zerolbsony Jan 12, 2026
14f88e3
Fix unit test.
zerolbsony Jan 12, 2026
517ffad
Fix unit test.
zerolbsony Jan 12, 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
Expand Up @@ -33,8 +33,11 @@
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.rpc.StatementExecutionException;

import org.apache.tsfile.enums.ColumnCategory;
import org.apache.tsfile.enums.TSDataType;
import org.apache.tsfile.read.common.RowRecord;
import org.apache.tsfile.read.common.TimeRange;
import org.apache.tsfile.write.record.Tablet;
import org.awaitility.Awaitility;
import org.junit.After;
import org.junit.AfterClass;
Expand All @@ -60,6 +63,7 @@
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Random;
Expand All @@ -74,6 +78,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.apache.iotdb.relational.it.session.IoTDBSessionRelationalIT.genValue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
Expand Down Expand Up @@ -2289,6 +2294,159 @@ public void testMultiDeviceCompletelyDeleteTable() throws SQLException {
cleanData(testNum);
}

@Test
public void testDeleteDataByTag() throws IoTDBConnectionException, StatementExecutionException {
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnectionWithDB("test")) {
session.executeNonQueryStatement(
"CREATE TABLE IF NOT EXISTS delete_by_tag (deviceId STRING TAG, s1 INT32 FIELD)");

session.executeNonQueryStatement(
"insert into delete_by_tag (time, deviceId, s1) values (1, 'sensor', 1)");
session.executeNonQueryStatement(
"insert into delete_by_tag (time, deviceId, s1) values (2, 'sensor', 2)");
session.executeNonQueryStatement(
"insert into delete_by_tag (time, deviceId, s1) values (3, 'sensor', 3)");
session.executeNonQueryStatement(
"insert into delete_by_tag (time, deviceId, s1) values (4, 'sensor', 4)");

session.executeNonQueryStatement("DELETE FROM delete_by_tag WHERE deviceId = 'sensor'");

SessionDataSet dataSet =
session.executeQueryStatement("select * from delete_by_tag order by time");
assertFalse(dataSet.hasNext());

session.executeNonQueryStatement(
"insert into delete_by_tag (time, deviceId, s1) values (1, 'sensor', 1)");
session.executeNonQueryStatement(
"insert into delete_by_tag (time, deviceId, s1) values (2, 'sensor', 2)");
session.executeNonQueryStatement(
"insert into delete_by_tag (time, deviceId, s1) values (3, 'sensor', 3)");
session.executeNonQueryStatement(
"insert into delete_by_tag (time, deviceId, s1) values (4, 'sensor', 4)");
session.executeNonQueryStatement("FLUSH");

session.executeNonQueryStatement("DELETE FROM delete_by_tag WHERE deviceId = 'sensor'");

dataSet = session.executeQueryStatement("select * from delete_by_tag order by time");
assertFalse(dataSet.hasNext());
} finally {
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnectionWithDB("test")) {
session.executeNonQueryStatement("DROP TABLE IF EXISTS delete_by_tag");
}
}
}

@Test
public void testDropAndAlter() throws IoTDBConnectionException, StatementExecutionException {
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnectionWithDB("test")) {
session.executeNonQueryStatement("CREATE TABLE IF NOT EXISTS drop_and_alter (s1 int32)");

// time=1 and time=2 are INT32 and deleted by drop column
Tablet tablet =
new Tablet(
"drop_and_alter",
Collections.singletonList("s1"),
Collections.singletonList(TSDataType.INT32),
Collections.singletonList(ColumnCategory.FIELD));
tablet.addTimestamp(0, 1);
tablet.addValue("s1", 0, genValue(TSDataType.INT32, 1));
session.insert(tablet);
tablet.reset();

session.executeNonQueryStatement("FLUSH");

tablet =
new Tablet(
"drop_and_alter",
Collections.singletonList("s1"),
Collections.singletonList(TSDataType.INT32),
Collections.singletonList(ColumnCategory.FIELD));
tablet.addTimestamp(0, 2);
tablet.addValue("s1", 0, genValue(TSDataType.INT32, 2));
session.insert(tablet);
tablet.reset();

session.executeNonQueryStatement("ALTER TABLE drop_and_alter DROP COLUMN s1");

// time=3 and time=4 are STRING
tablet =
new Tablet(
"drop_and_alter",
Collections.singletonList("s1"),
Collections.singletonList(TSDataType.STRING),
Collections.singletonList(ColumnCategory.FIELD));
tablet.addTimestamp(0, 3);
tablet.addValue("s1", 0, genValue(TSDataType.STRING, 3));
session.insert(tablet);
tablet.reset();

session.executeNonQueryStatement("FLUSH");

tablet =
new Tablet(
"drop_and_alter",
Collections.singletonList("s1"),
Collections.singletonList(TSDataType.STRING),
Collections.singletonList(ColumnCategory.FIELD));
tablet.addTimestamp(0, 4);
tablet.addValue("s1", 0, genValue(TSDataType.STRING, 4));
session.insert(tablet);
tablet.reset();

session.executeNonQueryStatement("ALTER TABLE drop_and_alter DROP COLUMN s1");
session.executeNonQueryStatement("ALTER TABLE drop_and_alter ADD COLUMN s1 TEXT");

// time=5 and time=6 are TEXT
tablet =
new Tablet(
"drop_and_alter",
Collections.singletonList("s1"),
Collections.singletonList(TSDataType.TEXT),
Collections.singletonList(ColumnCategory.FIELD));
tablet.addTimestamp(0, 5);
tablet.addValue("s1", 0, genValue(TSDataType.STRING, 5));
session.insert(tablet);
tablet.reset();

session.executeNonQueryStatement("FLUSH");

tablet =
new Tablet(
"drop_and_alter",
Collections.singletonList("s1"),
Collections.singletonList(TSDataType.TEXT),
Collections.singletonList(ColumnCategory.FIELD));
tablet.addTimestamp(0, 6);
tablet.addValue("s1", 0, genValue(TSDataType.STRING, 6));
session.insert(tablet);
tablet.reset();

SessionDataSet dataSet =
session.executeQueryStatement("select * from drop_and_alter order by time");
// s1 is dropped but the time should remain
RowRecord rec;
int cnt = 0;
for (int i = 1; i < 7; i++) {
rec = dataSet.next();
assertEquals(i, rec.getFields().get(0).getLongV());
LOGGER.error(
"time is {}, value is {}, value type is {}",
rec.getFields().get(0).getLongV(),
rec.getFields().get(1),
rec.getFields().get(1).getDataType());
// assertNull(rec.getFields().get(1).getDataType());
// Assert.assertEquals(TSDataType.TEXT, rec.getFields().get(1).getDataType());
cnt++;
}
Assert.assertEquals(6, cnt);
assertFalse(dataSet.hasNext());
} finally {
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnectionWithDB("test")) {
session.executeNonQueryStatement("DROP TABLE IF EXISTS drop_and_alter");
}
}
}

private static void prepareDatabase() {
try (Connection connection = EnvFactory.getEnv().getConnection(BaseEnv.TABLE_SQL_DIALECT);
Statement statement = connection.createStatement()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ private void doWriteAndAlter(TSDataType from, TSDataType to)
throws IoTDBConnectionException, StatementExecutionException {
try (ITableSession session = EnvFactory.getEnv().getTableSessionConnectionWithDB("test")) {
session.executeNonQueryStatement("SET CONFIGURATION enable_unseq_space_compaction='false'");
session.executeNonQueryStatement("SET CONFIGURATION enable_seq_space_compaction='false'");
if (from == TSDataType.DATE && !to.isCompatible(from)) {
throw new NotSupportedException("Not supported DATE type.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,19 @@ public AbstractAlignedTimeSeriesMetadata generateTimeSeriesMetadata(
modified = (modified || alignedChunkMetadata.isModified());
TSDataType targetDataType = alignedFullPath.getSchemaList().get(index).getType();
if (targetDataType.equals(TSDataType.STRING)
&& (alignedChunkMetadata.getValueChunkMetadataList().stream()
.filter(iChunkMetadata -> iChunkMetadata.getDataType() != targetDataType)
.count()
> 0)) {
&& ((alignedChunkMetadata.getValueChunkMetadataList().get(index) != null)
&& (alignedChunkMetadata.getValueChunkMetadataList().get(index).getDataType()
!= targetDataType))) {
// create new statistics object via new data type, and merge statistics information
alignedChunkMetadata =
SchemaUtils.rewriteAlignedChunkMetadataStatistics(alignedChunkMetadata, targetDataType);
SchemaUtils.rewriteAlignedChunkMetadataStatistics(
alignedChunkMetadata, index, targetDataType);
alignedChunkMetadata.setModified(true);
}
if (!useFakeStatistics) {
timeStatistics.mergeStatistics(alignedChunkMetadata.getTimeChunkMetadata().getStatistics());
for (int i = 0; i < valueTimeSeriesMetadataList.size(); i++) {
if (alignedChunkMetadata.getValueChunkMetadataList().get(i) != null) {
if (!alignedChunkMetadata.getValueChunkMetadataList().isEmpty()
&& alignedChunkMetadata.getValueChunkMetadataList().get(i) != null) {
exist[i] = true;
valueTimeSeriesMetadataList
.get(i)
Expand Down Expand Up @@ -542,8 +542,18 @@ public ITimeSeriesMetadata generateTimeSeriesMetadata(
boolean isModified = false;
for (IChunkMetadata chunkMetadata : chunkMetadataList) {
isModified = (isModified || chunkMetadata.isModified());
TSDataType targetDataType = fullPath.getMeasurementSchema().getType();
if (targetDataType.equals(TSDataType.STRING)
&& (chunkMetadata.getDataType() != targetDataType)) {
// create new statistics object via new data type, and merge statistics information
SchemaUtils.rewriteNonAlignedChunkMetadataStatistics(
(ChunkMetadata) chunkMetadata, targetDataType);
chunkMetadata.setModified(true);
}
if (!useFakeStatistics) {
seriesStatistics.mergeStatistics(chunkMetadata.getStatistics());
if (chunkMetadata != null && targetDataType.isCompatible(chunkMetadata.getDataType())) {
seriesStatistics.mergeStatistics(chunkMetadata.getStatistics());
}
continue;
}
startTime = Math.min(startTime, chunkMetadata.getStartTime());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
import org.apache.iotdb.db.storageengine.dataregion.memtable.IMemTable;
import org.apache.iotdb.db.storageengine.dataregion.memtable.TsFileProcessor;
import org.apache.iotdb.db.storageengine.dataregion.memtable.TsFileProcessorInfo;
import org.apache.iotdb.db.storageengine.dataregion.modification.IDPredicate;
import org.apache.iotdb.db.storageengine.dataregion.modification.ModEntry;
import org.apache.iotdb.db.storageengine.dataregion.modification.ModificationFile;
import org.apache.iotdb.db.storageengine.dataregion.modification.TableDeletionEntry;
Expand Down Expand Up @@ -3235,18 +3236,14 @@ private void deleteDataInSealedFiles(Collection<TsFileResource> sealedTsFiles, M
List<TsFileResource> deletedByMods = new ArrayList<>();
List<TsFileResource> deletedByFiles = new ArrayList<>();
boolean isDropMeasurementExist = false;
boolean isDropTagExist = false;
IDPredicate.IDPredicateType idPredicateType = null;

if (deletion instanceof TableDeletionEntry) {
TableDeletionEntry entry = (TableDeletionEntry) deletion;
isDropMeasurementExist = !entry.getPredicate().getMeasurementNames().isEmpty();
} else {
TreeDeletionEntry entry = (TreeDeletionEntry) deletion;
if (entry.getPathPattern() instanceof MeasurementPath) {
Map<String, String> tagMap = ((MeasurementPath) entry.getPathPattern()).getTagMap();
isDropTagExist = (tagMap != null) && !tagMap.isEmpty();
}
TableDeletionEntry tableDeletionEntry = (TableDeletionEntry) deletion;
isDropMeasurementExist = !tableDeletionEntry.getPredicate().getMeasurementNames().isEmpty();
idPredicateType = tableDeletionEntry.getPredicate().getIdPredicateType();
}

for (TsFileResource sealedTsFile : sealedTsFiles) {
if (canSkipDelete(sealedTsFile, deletion)) {
continue;
Expand Down Expand Up @@ -3310,7 +3307,9 @@ private void deleteDataInSealedFiles(Collection<TsFileResource> sealedTsFiles, M
fileStartTime,
fileEndTime);
}
if (isFileFullyMatchedByTime(deletion, fileStartTime, fileEndTime)) {
if (isFileFullyMatchedByTime(deletion, fileStartTime, fileEndTime)
&& idPredicateType.equals(IDPredicate.IDPredicateType.NOP)
&& !isDropMeasurementExist) {
++matchSize;
} else {
deletedByMods.add(sealedTsFile);
Expand Down Expand Up @@ -3343,7 +3342,7 @@ private void deleteDataInSealedFiles(Collection<TsFileResource> sealedTsFiles, M
} // else do nothing
}

if (!deletedByFiles.isEmpty() && !isDropMeasurementExist && !isDropTagExist) {
if (!deletedByFiles.isEmpty()) {
deleteTsFileCompletely(deletedByFiles);
if (logger.isDebugEnabled()) {
logger.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ public IDPredicate getIdPredicate() {
return idPredicate;
}

public IDPredicate.IDPredicateType getIdPredicateType() {
return this.idPredicate.type;
}

public String getTableName() {
return tableName;
}
Expand Down
Loading
Loading