Skip to content

Commit f8bcf2a

Browse files
authored
Fix that the row deletion mark is mistakenly use (#14138)
* fix that the row deletion mark is mistakenly use * spotless * fix tests
1 parent 466c0d9 commit f8bcf2a

File tree

2 files changed

+42
-11
lines changed

2 files changed

+42
-11
lines changed

integration-test/src/test/java/org/apache/iotdb/db/it/IoTDBDeletionIT.java

+31-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public void testDeleteDataFromEmptySeries() throws SQLException {
388388
statement.execute(
389389
"DELETE FROM root.ln10.wf01.wt01.status,root.sg.wf01.wt01.status WHERE time >2022-10-11 10:20:50;");
390390

391-
try (ResultSet resultSet = statement.executeQuery("select ** from root")) {
391+
try (ResultSet resultSet = statement.executeQuery("select ** from root.ln10")) {
392392
int cnt = 0;
393393
while (resultSet.next()) {
394394
cnt++;
@@ -437,6 +437,36 @@ public void testDelSeriesWithSpecialSymbol() throws SQLException {
437437
}
438438
}
439439

440+
@Test
441+
public void testDelAfterUpdate() throws SQLException {
442+
try (Connection connection = EnvFactory.getEnv().getConnection();
443+
Statement statement = connection.createStatement()) {
444+
statement.execute("CREATE ALIGNED TIMESERIES root.ln12.d1 (status int32)");
445+
statement.execute("INSERT INTO root.ln12.d1(timestamp, status) VALUES(1, 1)");
446+
statement.execute("INSERT INTO root.ln12.d1(timestamp, status) VALUES(2, 2)");
447+
statement.execute("INSERT INTO root.ln12.d1(timestamp, status) VALUES(3, 3)");
448+
statement.execute("INSERT INTO root.ln12.d1(timestamp, status) VALUES(2, 2)");
449+
450+
try (ResultSet resultSet = statement.executeQuery("select status from root.ln12.d1")) {
451+
int cnt = 0;
452+
while (resultSet.next()) {
453+
cnt++;
454+
}
455+
Assert.assertEquals(3, cnt);
456+
}
457+
458+
statement.execute("DELETE FROM root.ln12.d1.* WHERE time <= 2");
459+
460+
try (ResultSet resultSet = statement.executeQuery("select status from root.ln12.d1")) {
461+
int cnt = 0;
462+
while (resultSet.next()) {
463+
cnt++;
464+
}
465+
Assert.assertEquals(1, cnt);
466+
}
467+
}
468+
}
469+
440470
private static void prepareSeries() {
441471
try (Connection connection = EnvFactory.getEnv().getConnection();
442472
Statement statement = connection.createStatement()) {

iotdb-core/datanode/src/main/java/org/apache/iotdb/db/utils/datastructure/AlignedTVList.java

+11-10
Original file line numberDiff line numberDiff line change
@@ -493,30 +493,28 @@ public boolean getBooleanByValueIndex(int rowIndex, int columnIndex) {
493493
/**
494494
* Get whether value is null at the given position in AlignedTvList.
495495
*
496-
* @param rowIndex value index inside this column
496+
* @param unsortedRowIndex value index inside this column
497497
* @param columnIndex index of the column
498498
* @return boolean
499499
*/
500-
public boolean isNullValue(int rowIndex, int columnIndex) {
501-
if (rowIndex >= rowCount) {
500+
public boolean isNullValue(int unsortedRowIndex, int columnIndex) {
501+
if (unsortedRowIndex >= rowCount) {
502502
return false;
503503
}
504-
if (allValueColDeletedMap != null && allValueColDeletedMap.isMarked(rowIndex)) {
505-
return true;
506-
}
507-
if (isTimeDeleted(rowIndex)) {
504+
if (allValueColDeletedMap != null && allValueColDeletedMap.isMarked(unsortedRowIndex)) {
508505
return true;
509506
}
507+
510508
if (values.get(columnIndex) == null) {
511509
return true;
512510
}
513511
if (bitMaps == null
514512
|| bitMaps.get(columnIndex) == null
515-
|| bitMaps.get(columnIndex).get(rowIndex / ARRAY_SIZE) == null) {
513+
|| bitMaps.get(columnIndex).get(unsortedRowIndex / ARRAY_SIZE) == null) {
516514
return false;
517515
}
518-
int arrayIndex = rowIndex / ARRAY_SIZE;
519-
int elementIndex = rowIndex % ARRAY_SIZE;
516+
int arrayIndex = unsortedRowIndex / ARRAY_SIZE;
517+
int elementIndex = unsortedRowIndex % ARRAY_SIZE;
520518
List<BitMap> columnBitMaps = bitMaps.get(columnIndex);
521519
return columnBitMaps.get(arrayIndex).isMarked(elementIndex);
522520
}
@@ -1424,6 +1422,9 @@ public BitMap getTimeColDeletedMap() {
14241422
return timeColDeletedMap;
14251423
}
14261424

1425+
/**
1426+
* @param rowIndex should be the sorted index.
1427+
*/
14271428
public boolean isTimeDeleted(int rowIndex) {
14281429
int bitmapIndex = getValueIndex(rowIndex);
14291430
if (timeColDeletedMap == null || timeColDeletedMap.getSize() <= bitmapIndex) {

0 commit comments

Comments
 (0)