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

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


The following commit(s) were added to refs/heads/master by this push:
     new 52715f18e48 Verify nonexist measurement in an exist device if it 
exists. (#17093)
52715f18e48 is described below

commit 52715f18e48e1d0863c2dce9b3cd054dc4f4a01c
Author: libo <[email protected]>
AuthorDate: Wed Jan 28 14:25:18 2026 +0800

    Verify nonexist measurement in an exist device if it exists. (#17093)
    
    * Verify nonexist measurement in an exist device if it exists.
    
    * Remove spare codes, and optimize codes.
    
    * Correct IT.
    
    * Make code spotless.
    
    * Correct the logic that verify path if it exist.
---
 .../db/it/schema/IoTDBAlterTimeSeriesTypeIT.java   | 18 ++++++++++
 .../schema/AlterTimeSeriesDataTypeProcedure.java   | 41 +++++++++++-----------
 2 files changed, 38 insertions(+), 21 deletions(-)

diff --git 
a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAlterTimeSeriesTypeIT.java
 
b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAlterTimeSeriesTypeIT.java
index 181fd2da2b2..8f08d2c1dd3 100644
--- 
a/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAlterTimeSeriesTypeIT.java
+++ 
b/integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAlterTimeSeriesTypeIT.java
@@ -445,6 +445,24 @@ public class IoTDBAlterTimeSeriesTypeIT {
       } catch (StatementExecutionException e) {
         assertEquals("508: Path [" + database + ".non_exist.s1] does not 
exist", e.getMessage());
       }
+
+      // Make the "non_exist" device exist, test the  "nonexist" measurement 
if it can be altered
+      // data type.
+      try {
+        session.executeNonQueryStatement(
+            "CREATE TIMESERIES " + database + ".d1.int32 WITH DATATYPE=INT32");
+        session.executeNonQueryStatement(
+            "ALTER TIMESERIES " + database + ".d1.nonexistent SET DATA TYPE 
STRING");
+        fail("Should throw exception");
+      } catch (StatementExecutionException e) {
+        assertEquals(
+            "507: Alter timeseries "
+                + database
+                + ".d1.nonexistent data type to STRING in schema regions 
failed. Failures: {DataNodeId: 1=[TSStatus(code:508, message:Path ["
+                + database
+                + ".d1.nonexistent] does not exist)]}",
+            e.getMessage());
+      }
     }
   }
 
diff --git 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/schema/AlterTimeSeriesDataTypeProcedure.java
 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/schema/AlterTimeSeriesDataTypeProcedure.java
index 2bbfde0e142..59398f147fd 100644
--- 
a/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/schema/AlterTimeSeriesDataTypeProcedure.java
+++ 
b/iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/schema/AlterTimeSeriesDataTypeProcedure.java
@@ -179,22 +179,13 @@ public class AlterTimeSeriesDataTypeProcedure
             env.getConfigManager().getRelatedSchemaRegionGroup(patternTree, 
false),
             false,
             CnToDnAsyncRequestType.ALTER_TIMESERIES_DATATYPE,
-            ((dataNodeLocation, consensusGroupIdList) -> {
-              ByteBuffer measurementPathBuffer = null;
-              try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
-                measurementPath.serialize(baos);
-                measurementPathBuffer = ByteBuffer.wrap(baos.toByteArray());
-              } catch (IOException ignored) {
-                // ByteArrayOutputStream won't throw IOException
-              }
-
-              return new TAlterTimeSeriesReq(
-                  consensusGroupIdList,
-                  queryId,
-                  measurementPathBuffer,
-                  operationType,
-                  ByteBuffer.wrap(stream.toByteArray()));
-            })) {
+            ((dataNodeLocation, consensusGroupIdList) ->
+                new TAlterTimeSeriesReq(
+                    consensusGroupIdList,
+                    queryId,
+                    measurementPathBytes,
+                    operationType,
+                    prepareDataTypeBytesData()))) {
 
           @Override
           protected List<TConsensusGroupId> processResponseOfOneDataNode(
@@ -210,13 +201,11 @@ public class AlterTimeSeriesDataTypeProcedure
             if (response.getCode() == 
TSStatusCode.MULTIPLE_ERROR.getStatusCode()) {
               final List<TSStatus> subStatus = response.getSubStatus();
               for (int i = 0; i < subStatus.size(); i++) {
-                if (subStatus.get(i).getCode() != 
TSStatusCode.SUCCESS_STATUS.getStatusCode()
-                    && !(subStatus.get(i).getCode()
-                        == TSStatusCode.PATH_NOT_EXIST.getStatusCode())) {
+                if (subStatus.get(i).getCode() != 
TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
                   failedRegionList.add(consensusGroupIdList.get(i));
                 }
               }
-            } else if (!(response.getCode() == 
TSStatusCode.PATH_NOT_EXIST.getStatusCode())) {
+            } else {
               failedRegionList.addAll(consensusGroupIdList);
             }
             if (!failedRegionList.isEmpty()) {
@@ -331,7 +320,7 @@ public class AlterTimeSeriesDataTypeProcedure
 
   public void setMeasurementPath(final MeasurementPath measurementPath) {
     this.measurementPath = measurementPath;
-    measurementPathBytes = prepareMeasurementPathBytesData(measurementPath);
+    this.measurementPathBytes = 
prepareMeasurementPathBytesData(measurementPath);
   }
 
   public static ByteBuffer prepareMeasurementPathBytesData(final 
MeasurementPath measurementPath) {
@@ -356,6 +345,16 @@ public class AlterTimeSeriesDataTypeProcedure
     return ByteBuffer.wrap(byteArrayOutputStream.toByteArray());
   }
 
+  public ByteBuffer prepareDataTypeBytesData() {
+    final ByteArrayOutputStream stream = new ByteArrayOutputStream(1);
+    try {
+      ReadWriteIOUtils.write(dataType, stream);
+    } catch (final IOException ignored) {
+      // ByteArrayOutputStream won't throw IOException
+    }
+    return ByteBuffer.wrap(stream.toByteArray());
+  }
+
   @Override
   public void serialize(final DataOutputStream stream) throws IOException {
     stream.writeShort(

Reply via email to