Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TConsensusGroupId> processResponseOfOneDataNode(
Expand All @@ -210,13 +201,11 @@ protected List<TConsensusGroupId> processResponseOfOneDataNode(
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()) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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(
Expand Down
Loading