1919
2020package org .apache .iotdb .db .queryengine .plan .analyze .load ;
2121
22+ import org .apache .iotdb .commons .path .PartialPath ;
2223import org .apache .iotdb .commons .queryengine .plan .relational .metadata .ColumnSchema ;
2324import org .apache .iotdb .commons .schema .table .column .TsTableColumnCategory ;
2425import org .apache .iotdb .db .conf .IoTDBDescriptor ;
2526import org .apache .iotdb .db .exception .load .LoadAnalyzeTypeMismatchException ;
2627import org .apache .iotdb .db .exception .load .LoadRuntimeOutOfMemoryException ;
2728import org .apache .iotdb .db .queryengine .common .MPPQueryContext ;
2829import org .apache .iotdb .db .queryengine .common .QueryId ;
30+ import org .apache .iotdb .db .queryengine .common .schematree .ClusterSchemaTree ;
31+ import org .apache .iotdb .db .queryengine .common .schematree .ISchemaTree ;
2932import org .apache .iotdb .db .queryengine .plan .relational .sql .ast .LoadTsFile ;
33+ import org .apache .iotdb .db .queryengine .plan .statement .crud .LoadTsFileStatement ;
3034import org .apache .iotdb .db .storageengine .dataregion .tsfile .TsFileResource ;
3135
3236import org .apache .tsfile .enums .ColumnCategory ;
@@ -149,6 +153,51 @@ public void testTableSchemaCacheShouldNotThrowMismatchWhenSkippingDataTypeVerifi
149153 }
150154 }
151155
156+ @ Test
157+ public void testTreeSchemaVerifierShouldThrowMismatchWhenVerifyingDataType () throws Exception {
158+ final File tsFile = new File ("load-tree-type-mismatch.tsfile" );
159+ if (tsFile .exists ()) {
160+ Assert .assertTrue (tsFile .delete ());
161+ }
162+ Assert .assertTrue (tsFile .createNewFile ());
163+
164+ try (final LoadTsFileAnalyzer analyzer =
165+ new LoadTsFileAnalyzer (
166+ LoadTsFileStatement .createUnchecked (tsFile .getAbsolutePath ()),
167+ false ,
168+ new MPPQueryContext (new QueryId ("load_tree_test" )))) {
169+ final TreeSchemaAutoCreatorAndVerifier verifier =
170+ new TreeSchemaAutoCreatorAndVerifier (analyzer );
171+ try {
172+ final IDeviceID device = IDeviceID .Factory .DEFAULT_FACTORY .create ("root.sg.d1" );
173+ final LoadTsFileTreeSchemaCache schemaCache = getTreeSchemaCache (verifier );
174+ schemaCache .addTimeSeries (device , new MeasurementSchema ("s1" , TSDataType .BOOLEAN ));
175+ schemaCache .addIsAlignedCache (device , true , true );
176+
177+ final ClusterSchemaTree schemaTree = new ClusterSchemaTree ();
178+ schemaTree .appendSingleMeasurement (
179+ new PartialPath ("root.sg.d1.s1" ),
180+ new MeasurementSchema ("s1" , TSDataType .INT32 ),
181+ null ,
182+ null ,
183+ null ,
184+ true );
185+
186+ final InvocationTargetException exception =
187+ Assert .assertThrows (
188+ InvocationTargetException .class ,
189+ () -> getVerifyTreeSchemaMethod ().invoke (verifier , schemaTree ));
190+ Assert .assertTrue (exception .getCause () instanceof LoadAnalyzeTypeMismatchException );
191+ } finally {
192+ verifier .close ();
193+ }
194+ } finally {
195+ if (tsFile .exists ()) {
196+ Assert .assertTrue (tsFile .delete ());
197+ }
198+ }
199+ }
200+
152201 private void writeTableTsFileWithMixedDevices (final File tsFile ) throws Exception {
153202 if (tsFile .exists ()) {
154203 Assert .assertTrue (tsFile .delete ());
@@ -203,6 +252,14 @@ private void injectTableSchemaCache(
203252 tableSchemaCacheField .set (analyzer , schemaCache );
204253 }
205254
255+ private LoadTsFileTreeSchemaCache getTreeSchemaCache (
256+ final TreeSchemaAutoCreatorAndVerifier verifier ) throws Exception {
257+ final Field schemaCacheField =
258+ TreeSchemaAutoCreatorAndVerifier .class .getDeclaredField ("schemaCache" );
259+ schemaCacheField .setAccessible (true );
260+ return (LoadTsFileTreeSchemaCache ) schemaCacheField .get (verifier );
261+ }
262+
206263 private LoadTsFileTableSchemaCache createTableSchemaCache (final boolean shouldVerifyDataType )
207264 throws LoadRuntimeOutOfMemoryException {
208265 return new LoadTsFileTableSchemaCache (
@@ -219,6 +276,13 @@ private Method getVerifyTableDataTypeMethod() throws NoSuchMethodException {
219276 return method ;
220277 }
221278
279+ private Method getVerifyTreeSchemaMethod () throws NoSuchMethodException {
280+ final Method method =
281+ TreeSchemaAutoCreatorAndVerifier .class .getDeclaredMethod ("verifySchema" , ISchemaTree .class );
282+ method .setAccessible (true );
283+ return method ;
284+ }
285+
222286 private org .apache .iotdb .commons .queryengine .plan .relational .metadata .TableSchema
223287 createTableSchema (final TSDataType fieldType ) {
224288 return new org .apache .iotdb .commons .queryengine .plan .relational .metadata .TableSchema (
0 commit comments