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 181fd2da2b25..8f08d2c1dd32 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 void testAlterNonExist() throws IoTDBConnectionException, StatementExecut } 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 2bbfde0e142f..59398f147fd9 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 @@ private boolean alterTimeSeriesDataType(final ConfigNodeProcedureEnv env) { 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 processResponseOfOneDataNode( @@ -210,13 +201,11 @@ protected List processResponseOfOneDataNode( if (response.getCode() == TSStatusCode.MULTIPLE_ERROR.getStatusCode()) { final List 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 MeasurementPath getmeasurementPath() { 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 static ByteBuffer preparePatternTreeBytesData(final PathPatternTree patte 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(