Skip to content
Open
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 @@ -359,6 +359,12 @@ private void autoCreateDatabase()
final PartialPath devicePath = new PartialPath(device);

final String[] devicePrefixNodes = devicePath.getNodes();
for (final String node : devicePrefixNodes) {
if (node == null || node.isEmpty()) {
throw new LoadAnalyzeException(
new IllegalPathException(devicePath.getFullPath()).getMessage());
}
}
if (devicePrefixNodes.length < databasePrefixNodesLength) {
throw new LoadAnalyzeException(
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,35 @@ public void testTreeSchemaVerifierShouldThrowMismatchWhenVerifyingDataType() thr
}
}

@Test
public void testTreeSchemaVerifierShouldRejectDeviceWithEmptyPathNode() throws Exception {
final File tsFile = File.createTempFile("load-tree-illegal-device", ".tsfile");

try (final LoadTsFileAnalyzer analyzer =
new LoadTsFileAnalyzer(
LoadTsFileStatement.createUnchecked(tsFile.getAbsolutePath()),
false,
new MPPQueryContext(new QueryId("load_tree_illegal_device_test")))) {
final TreeSchemaAutoCreatorAndVerifier verifier =
new TreeSchemaAutoCreatorAndVerifier(analyzer);
try {
final IDeviceID device = new StringArrayDeviceID(new String[] {"root", ""});
getTreeSchemaCache(verifier)
.addTimeSeries(device, new MeasurementSchema("s1", TSDataType.INT32));

final InvocationTargetException exception =
Assert.assertThrows(
InvocationTargetException.class,
() -> getAutoCreateDatabaseMethod().invoke(verifier));
Assert.assertTrue(exception.getCause() instanceof LoadAnalyzeException);
} finally {
verifier.close();
}
} finally {
Assert.assertTrue(tsFile.delete());
}
}

@Test
public void testPipeGeneratedLoadMissingSchemaShouldBeTemporaryWhenAutoCreateDisabled()
throws Exception {
Expand Down Expand Up @@ -316,6 +345,13 @@ private Method getVerifyTreeSchemaMethod() throws NoSuchMethodException {
return method;
}

private Method getAutoCreateDatabaseMethod() throws NoSuchMethodException {
final Method method =
TreeSchemaAutoCreatorAndVerifier.class.getDeclaredMethod("autoCreateDatabase");
method.setAccessible(true);
return method;
}

private org.apache.iotdb.commons.queryengine.plan.relational.metadata.TableSchema
createTableSchema(final TSDataType fieldType) {
return new org.apache.iotdb.commons.queryengine.plan.relational.metadata.TableSchema(
Expand Down
Loading