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

haonan pushed a commit to branch fix_session_error
in repository https://gitbox.apache.org/repos/asf/iotdb.git

commit e658c79bd8b08b0ec1bd27fc509f77e8e1054855
Author: HTHou <[email protected]>
AuthorDate: Thu Feb 6 15:22:37 2025 +0800

    Fix null measurement name in Tablet
---
 .../iotdb/session/it/IoTDBSessionInsertNullIT.java | 58 ++++++++++++++++++++++
 .../java/org/apache/iotdb/session/Session.java     |  6 +++
 .../apache/iotdb/session/SessionConnection.java    |  1 +
 3 files changed, 65 insertions(+)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionInsertNullIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionInsertNullIT.java
index bbee36782fc..4eb14e35c93 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionInsertNullIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/session/it/IoTDBSessionInsertNullIT.java
@@ -35,6 +35,7 @@ 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.Assert;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
@@ -425,4 +426,61 @@ public class IoTDBSessionInsertNullIT {
       fail(e.getMessage());
     }
   }
+
+  @Test
+  public void insertTabletNullMeasurementTest() {
+    try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
+      String deviceId = "root.sg1.clsu.aligned_d1";
+      Tablet tablet =
+          new Tablet(
+              deviceId,
+              Arrays.asList(
+                  new MeasurementSchema("s1", TSDataType.BOOLEAN),
+                  new MeasurementSchema(null, TSDataType.INT32)),
+              1);
+      tablet.addTimestamp(0, 300);
+      tablet.addValue("s1", 0, true);
+      tablet.addValue(null, 0, 1);
+      session.insertAlignedTablet(tablet);
+      fail();
+    } catch (Exception e) {
+      Assert.assertEquals("measurement should be non null value", 
e.getMessage());
+    }
+
+    try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
+      String deviceId = "root.sg1.clsu.aligned_d1";
+      Tablet tablet =
+          new Tablet(
+              deviceId,
+              Arrays.asList(
+                  new MeasurementSchema("s1", TSDataType.BOOLEAN),
+                  new MeasurementSchema(null, TSDataType.INT32)),
+              1);
+      tablet.addTimestamp(0, 300);
+      tablet.addValue(0, 0, true);
+      tablet.addValue(0, 1, 1);
+      session.insertAlignedTablet(tablet);
+      fail();
+    } catch (Exception e) {
+      Assert.assertEquals("measurement should be non null value", 
e.getMessage());
+    }
+
+    try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
+      String deviceId = "root.sg1.clsu.aligned_d1";
+      Tablet tablet =
+          new Tablet(
+              deviceId,
+              Arrays.asList(
+                  new MeasurementSchema("s1", TSDataType.BOOLEAN),
+                  new MeasurementSchema(null, TSDataType.INT32)),
+              1);
+      tablet.addTimestamp(0, 300);
+      tablet.addValue("s1", 0, true);
+      // doesn't insert 2nd measurement
+      session.insertAlignedTablet(tablet);
+      fail();
+    } catch (Exception e) {
+      Assert.assertEquals("measurement should be non null value", 
e.getMessage());
+    }
+  }
 }
diff --git 
a/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java 
b/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java
index 1e65be39082..4be6e53dbf8 100644
--- a/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java
+++ b/iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java
@@ -2960,6 +2960,9 @@ public class Session implements ISession {
     TSInsertTabletReq request = new TSInsertTabletReq();
 
     for (IMeasurementSchema measurementSchema : tablet.getSchemas()) {
+      if (measurementSchema.getMeasurementName() == null) {
+        throw new IllegalArgumentException("measurement should be non null 
value");
+      }
       request.addToMeasurements(measurementSchema.getMeasurementName());
       request.addToTypes(measurementSchema.getType().ordinal());
     }
@@ -3084,6 +3087,9 @@ public class Session implements ISession {
     List<Integer> dataTypes = new ArrayList<>();
     request.setIsAligned(isAligned);
     for (IMeasurementSchema measurementSchema : tablet.getSchemas()) {
+      if (measurementSchema.getMeasurementName() == null) {
+        throw new IllegalArgumentException("measurement should be non null 
value");
+      }
       measurements.add(measurementSchema.getMeasurementName());
       dataTypes.add(measurementSchema.getType().ordinal());
     }
diff --git 
a/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java
 
b/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java
index c0dc516ba11..178065ef42f 100644
--- 
a/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java
+++ 
b/iotdb-client/session/src/main/java/org/apache/iotdb/session/SessionConnection.java
@@ -1093,6 +1093,7 @@ public class SessionConnection {
     if (status != null) {
       RpcUtils.verifySuccess(status);
     } else if (lastTException != null) {
+      reconnect();
       throw new IoTDBConnectionException(lastTException);
     } else {
       throw new IoTDBConnectionException(logForReconnectionFailure());

Reply via email to