This is an automated email from the ASF dual-hosted git repository.

jiangtian pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/tsfile.git


The following commit(s) were added to refs/heads/develop by this push:
     new 1f95562c Add check for writing unsupported type of value in tablet 
(#709)
1f95562c is described below

commit 1f95562caa9c87cea4579eb31402a824b73035c7
Author: Haonan <[email protected]>
AuthorDate: Mon Jan 19 15:48:19 2026 +0800

    Add check for writing unsupported type of value in tablet (#709)
---
 .../java/org/apache/tsfile/enums/TSDataType.java   |  4 ++
 .../org/apache/tsfile/write/record/Tablet.java     |  9 ++--
 .../org/apache/tsfile/write/record/TabletTest.java | 51 ++++++++++++++++++++++
 3 files changed, 61 insertions(+), 3 deletions(-)

diff --git a/java/common/src/main/java/org/apache/tsfile/enums/TSDataType.java 
b/java/common/src/main/java/org/apache/tsfile/enums/TSDataType.java
index 2a670379..2c411522 100644
--- a/java/common/src/main/java/org/apache/tsfile/enums/TSDataType.java
+++ b/java/common/src/main/java/org/apache/tsfile/enums/TSDataType.java
@@ -590,6 +590,10 @@ public enum TSDataType {
     return this == TEXT || this == STRING || this == BLOB || this == OBJECT;
   }
 
+  public boolean isTextStringOrBlob() {
+    return this == TEXT || this == STRING || this == BLOB;
+  }
+
   // Indicating the statistics don't contain values, such as first, last, min, 
max...
   public boolean hasNoValueInStatistics() {
     return this == BLOB || this == OBJECT;
diff --git 
a/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java 
b/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java
index 89b6f2a6..08142301 100644
--- a/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java
+++ b/java/tsfile/src/main/java/org/apache/tsfile/write/record/Tablet.java
@@ -509,7 +509,8 @@ public class Tablet implements Accountable {
 
   @TsFileApi
   public void addValue(int rowIndex, int columnIndex, String val) {
-    if (!(values[columnIndex] instanceof Binary[])) {
+    if (!(values[columnIndex] instanceof Binary[])
+        || !schemas.get(columnIndex).getType().isTextStringOrBlob()) {
       throw new IllegalArgumentException(
           "The data type of column index " + columnIndex + " is not 
TEXT/STRING/BLOB");
     }
@@ -529,7 +530,8 @@ public class Tablet implements Accountable {
 
   @TsFileApi
   public void addValue(int rowIndex, int columnIndex, byte[] val) {
-    if (!(values[columnIndex] instanceof Binary[])) {
+    if (!(values[columnIndex] instanceof Binary[])
+        || !schemas.get(columnIndex).getType().isTextStringOrBlob()) {
       throw new IllegalArgumentException(
           "The data type of column index " + columnIndex + " is not 
TEXT/STRING/BLOB");
     }
@@ -562,7 +564,8 @@ public class Tablet implements Accountable {
   }
 
   public void addValue(int rowIndex, int columnIndex, boolean isEOF, long 
offset, byte[] content) {
-    if (!(values[columnIndex] instanceof Binary[])) {
+    if (!(values[columnIndex] instanceof Binary[])
+        || schemas.get(columnIndex).getType() != TSDataType.OBJECT) {
       throw new IllegalArgumentException(
           "The data type of column index " + columnIndex + " is not OBJECT");
     }
diff --git 
a/java/tsfile/src/test/java/org/apache/tsfile/write/record/TabletTest.java 
b/java/tsfile/src/test/java/org/apache/tsfile/write/record/TabletTest.java
index 25828400..65911c18 100644
--- a/java/tsfile/src/test/java/org/apache/tsfile/write/record/TabletTest.java
+++ b/java/tsfile/src/test/java/org/apache/tsfile/write/record/TabletTest.java
@@ -288,6 +288,57 @@ public class TabletTest {
     Assert.fail();
   }
 
+  @Test
+  public void testWriteWrongType2() {
+    final String deviceId = "root.sg";
+    final List<IMeasurementSchema> measurementSchemas = new ArrayList<>();
+    measurementSchemas.add(new MeasurementSchema("s0", TSDataType.INT32));
+    measurementSchemas.add(new MeasurementSchema("s1", TSDataType.INT64));
+    measurementSchemas.add(new MeasurementSchema("s2", TSDataType.FLOAT));
+    measurementSchemas.add(new MeasurementSchema("s3", TSDataType.DOUBLE));
+    measurementSchemas.add(new MeasurementSchema("s4", TSDataType.BOOLEAN));
+    measurementSchemas.add(new MeasurementSchema("s5", TSDataType.TEXT));
+    measurementSchemas.add(new MeasurementSchema("s6", TSDataType.STRING));
+    measurementSchemas.add(new MeasurementSchema("s7", TSDataType.BLOB));
+    measurementSchemas.add(new MeasurementSchema("s8", TSDataType.TIMESTAMP));
+    measurementSchemas.add(new MeasurementSchema("s9", TSDataType.DATE));
+    measurementSchemas.add(new MeasurementSchema("s10", TSDataType.OBJECT));
+
+    Tablet tablet = new Tablet(deviceId, measurementSchemas);
+    addValueWithException2(tablet, 0, 0, 1L);
+    addValueWithException2(tablet, 1, 0, "1");
+    addValueWithException2(tablet, 2, 0, 0.1d);
+    addValueWithException2(tablet, 3, 0, 0.1f);
+    addValueWithException2(tablet, 4, 0, "1");
+    addValueWithException2(tablet, 5, 0, 1L);
+    addValueWithException2(tablet, 6, 0, 1L);
+    addValueWithException2(tablet, 7, 0, 1L);
+    addValueWithException2(tablet, 8, 0, "str");
+    addValueWithException2(tablet, 9, 0, 1L);
+    addValueWithException2(tablet, 10, 0, "str");
+  }
+
+  private void addValueWithException2(Tablet tablet, int columnIndex, int 
rowIndex, Object value) {
+    try {
+      if (value instanceof Integer) {
+        tablet.addValue(rowIndex, columnIndex, (int) value);
+      } else if (value instanceof Double) {
+        tablet.addValue(rowIndex, columnIndex, (double) value);
+      } else if (value instanceof Long) {
+        tablet.addValue(rowIndex, columnIndex, (long) value);
+      } else if (value instanceof Float) {
+        tablet.addValue(rowIndex, columnIndex, (float) value);
+      } else if (value instanceof String) {
+        tablet.addValue(rowIndex, columnIndex, (String) value);
+      } else {
+        throw new IllegalArgumentException("Unsupported type: " + 
value.getClass());
+      }
+    } catch (IllegalArgumentException e) {
+      return;
+    }
+    Assert.fail();
+  }
+
   @Test
   public void testSerializeDateColumnWithNullValue() throws IOException {
     final List<IMeasurementSchema> measurementSchemas = new ArrayList<>();

Reply via email to