Skip to content

Commit 52715f1

Browse files
authored
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.
1 parent 8289238 commit 52715f1

2 files changed

Lines changed: 38 additions & 21 deletions

File tree

integration-test/src/test/java/org/apache/iotdb/db/it/schema/IoTDBAlterTimeSeriesTypeIT.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,24 @@ public void testAlterNonExist() throws IoTDBConnectionException, StatementExecut
445445
} catch (StatementExecutionException e) {
446446
assertEquals("508: Path [" + database + ".non_exist.s1] does not exist", e.getMessage());
447447
}
448+
449+
// Make the "non_exist" device exist, test the "nonexist" measurement if it can be altered
450+
// data type.
451+
try {
452+
session.executeNonQueryStatement(
453+
"CREATE TIMESERIES " + database + ".d1.int32 WITH DATATYPE=INT32");
454+
session.executeNonQueryStatement(
455+
"ALTER TIMESERIES " + database + ".d1.nonexistent SET DATA TYPE STRING");
456+
fail("Should throw exception");
457+
} catch (StatementExecutionException e) {
458+
assertEquals(
459+
"507: Alter timeseries "
460+
+ database
461+
+ ".d1.nonexistent data type to STRING in schema regions failed. Failures: {DataNodeId: 1=[TSStatus(code:508, message:Path ["
462+
+ database
463+
+ ".d1.nonexistent] does not exist)]}",
464+
e.getMessage());
465+
}
448466
}
449467
}
450468

iotdb-core/confignode/src/main/java/org/apache/iotdb/confignode/procedure/impl/schema/AlterTimeSeriesDataTypeProcedure.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -179,22 +179,13 @@ private boolean alterTimeSeriesDataType(final ConfigNodeProcedureEnv env) {
179179
env.getConfigManager().getRelatedSchemaRegionGroup(patternTree, false),
180180
false,
181181
CnToDnAsyncRequestType.ALTER_TIMESERIES_DATATYPE,
182-
((dataNodeLocation, consensusGroupIdList) -> {
183-
ByteBuffer measurementPathBuffer = null;
184-
try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
185-
measurementPath.serialize(baos);
186-
measurementPathBuffer = ByteBuffer.wrap(baos.toByteArray());
187-
} catch (IOException ignored) {
188-
// ByteArrayOutputStream won't throw IOException
189-
}
190-
191-
return new TAlterTimeSeriesReq(
192-
consensusGroupIdList,
193-
queryId,
194-
measurementPathBuffer,
195-
operationType,
196-
ByteBuffer.wrap(stream.toByteArray()));
197-
})) {
182+
((dataNodeLocation, consensusGroupIdList) ->
183+
new TAlterTimeSeriesReq(
184+
consensusGroupIdList,
185+
queryId,
186+
measurementPathBytes,
187+
operationType,
188+
prepareDataTypeBytesData()))) {
198189

199190
@Override
200191
protected List<TConsensusGroupId> processResponseOfOneDataNode(
@@ -210,13 +201,11 @@ protected List<TConsensusGroupId> processResponseOfOneDataNode(
210201
if (response.getCode() == TSStatusCode.MULTIPLE_ERROR.getStatusCode()) {
211202
final List<TSStatus> subStatus = response.getSubStatus();
212203
for (int i = 0; i < subStatus.size(); i++) {
213-
if (subStatus.get(i).getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()
214-
&& !(subStatus.get(i).getCode()
215-
== TSStatusCode.PATH_NOT_EXIST.getStatusCode())) {
204+
if (subStatus.get(i).getCode() != TSStatusCode.SUCCESS_STATUS.getStatusCode()) {
216205
failedRegionList.add(consensusGroupIdList.get(i));
217206
}
218207
}
219-
} else if (!(response.getCode() == TSStatusCode.PATH_NOT_EXIST.getStatusCode())) {
208+
} else {
220209
failedRegionList.addAll(consensusGroupIdList);
221210
}
222211
if (!failedRegionList.isEmpty()) {
@@ -331,7 +320,7 @@ public MeasurementPath getmeasurementPath() {
331320

332321
public void setMeasurementPath(final MeasurementPath measurementPath) {
333322
this.measurementPath = measurementPath;
334-
measurementPathBytes = prepareMeasurementPathBytesData(measurementPath);
323+
this.measurementPathBytes = prepareMeasurementPathBytesData(measurementPath);
335324
}
336325

337326
public static ByteBuffer prepareMeasurementPathBytesData(final MeasurementPath measurementPath) {
@@ -356,6 +345,16 @@ public static ByteBuffer preparePatternTreeBytesData(final PathPatternTree patte
356345
return ByteBuffer.wrap(byteArrayOutputStream.toByteArray());
357346
}
358347

348+
public ByteBuffer prepareDataTypeBytesData() {
349+
final ByteArrayOutputStream stream = new ByteArrayOutputStream(1);
350+
try {
351+
ReadWriteIOUtils.write(dataType, stream);
352+
} catch (final IOException ignored) {
353+
// ByteArrayOutputStream won't throw IOException
354+
}
355+
return ByteBuffer.wrap(stream.toByteArray());
356+
}
357+
359358
@Override
360359
public void serialize(final DataOutputStream stream) throws IOException {
361360
stream.writeShort(

0 commit comments

Comments
 (0)