Skip to content

Commit

Permalink
Fix query error after insert an all null aligned tablet and flush (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
HTHou authored Jan 26, 2025
1 parent 25128fc commit 9c9b239
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
import org.apache.tsfile.file.metadata.enums.TSEncoding;
import org.apache.tsfile.read.common.Field;
import org.apache.tsfile.read.common.RowRecord;
import org.apache.tsfile.write.record.Tablet;
import org.apache.tsfile.write.schema.MeasurementSchema;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
Expand Down Expand Up @@ -355,4 +357,72 @@ public void insertAlignedRecordsOfOneDeviceNullTest() {
fail(e.getMessage());
}
}

@Test
public void insertTabletNullTest() {
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
prepareData(session);

String deviceId = "root.sg1.clsu.d1";
Tablet tablet =
new Tablet(
deviceId,
Arrays.asList(
new MeasurementSchema("s1", TSDataType.BOOLEAN),
new MeasurementSchema("s2", TSDataType.INT32)),
3);
tablet.addTimestamp(0, 300);
tablet.addValue("s1", 0, null);
tablet.addValue("s2", 0, null);
tablet.addTimestamp(1, 400);
tablet.addValue("s1", 1, null);
tablet.addValue("s2", 1, null);
tablet.addTimestamp(2, 500);
tablet.addValue("s1", 2, null);
tablet.addValue("s2", 2, null);
session.insertTablet(tablet);
long nums = queryCountRecords(session, "select count(s1) from " + deviceId);
assertEquals(0, nums);
session.executeNonQueryStatement("flush");
nums = queryCountRecords(session, "select count(s1) from " + deviceId);
assertEquals(0, nums);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}

@Test
public void insertAlignedTabletNullTest() {
try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
prepareData(session);

String deviceId = "root.sg1.clsu.aligned_d1";
Tablet tablet =
new Tablet(
deviceId,
Arrays.asList(
new MeasurementSchema("s1", TSDataType.BOOLEAN),
new MeasurementSchema("s2", TSDataType.INT32)),
3);
tablet.addTimestamp(0, 300);
tablet.addValue("s1", 0, null);
tablet.addValue("s2", 0, null);
tablet.addTimestamp(1, 400);
tablet.addValue("s1", 1, null);
tablet.addValue("s2", 1, null);
tablet.addTimestamp(2, 500);
tablet.addValue("s1", 2, null);
tablet.addValue("s2", 2, null);
session.insertAlignedTablet(tablet);
long nums = queryCountRecords(session, "select count(s1) from " + deviceId);
assertEquals(0, nums);
session.executeNonQueryStatement("flush");
nums = queryCountRecords(session, "select count(s1) from " + deviceId);
assertEquals(0, nums);
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void syncFlushMemTable() throws ExecutionException, InterruptedException
for (IDeviceID deviceID : deviceIDList) {
final Map<String, IWritableMemChunk> value = memTableMap.get(deviceID).getMemChunkMap();
// skip the empty device/chunk group
if (memTableMap.get(deviceID).count() == 0 || value.isEmpty()) {
if (memTableMap.get(deviceID).isEmpty() || value.isEmpty()) {
continue;
}
encodingTaskQueue.put(new StartFlushGroupIOTask(deviceID));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,9 @@ public IMeasurementSchema getSchema() {

@Override
public long getMaxTime() {
if (isEmpty()) {
return Long.MIN_VALUE;
}
return list.getMaxTime();
}

Expand Down Expand Up @@ -511,7 +514,15 @@ public long getLastPoint() {

@Override
public boolean isEmpty() {
return list.rowCount() == 0 || measurementIndexMap.isEmpty();
if (list.rowCount() == 0) {
return true;
}
if (ignoreAllNullRows) {
return measurementIndexMap.isEmpty()
|| (list.getAllValueColDeletedMap() != null
&& list.getAllValueColDeletedMap().isAllMarked());
}
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public Map<String, IWritableMemChunk> getMemChunkMap() {

@Override
public boolean isEmpty() {
return memChunkMap.isEmpty();
return memChunkMap.isEmpty() || count() == 0;
}

@Override
Expand Down

0 comments on commit 9c9b239

Please sign in to comment.