@@ -263,6 +263,108 @@ public void testLoad() throws Exception {
263263 }
264264 }
265265
266+ @ Test
267+ // Shall succeed with tablet conversion
268+ public void testLoadWithAlignmentMismatch () throws Exception {
269+ registerSchema ();
270+
271+ final long writtenPoint1 ;
272+ // device 0, sg 0
273+ try (final TsFileGenerator generator =
274+ new TsFileGenerator (new File (tmpDir , "1-0-0-0.tsfile" ))) {
275+ // Wrong, with 04-07 non-exist
276+ generator .registerAlignedTimeseries (
277+ SchemaConfig .DEVICE_0 ,
278+ Arrays .asList (
279+ SchemaConfig .MEASUREMENT_00 ,
280+ SchemaConfig .MEASUREMENT_01 ,
281+ SchemaConfig .MEASUREMENT_02 ,
282+ SchemaConfig .MEASUREMENT_03 ,
283+ SchemaConfig .MEASUREMENT_04 ,
284+ SchemaConfig .MEASUREMENT_05 ,
285+ SchemaConfig .MEASUREMENT_06 ,
286+ SchemaConfig .MEASUREMENT_07 ));
287+ generator .generateData (SchemaConfig .DEVICE_0 , 100000 , PARTITION_INTERVAL / 10_000 , false );
288+ writtenPoint1 = generator .getTotalNumber ();
289+ }
290+
291+ final long writtenPoint2 ;
292+ // device 2, device 3, device4, sg 1
293+ try (final TsFileGenerator generator =
294+ new TsFileGenerator (new File (tmpDir , "2-0-0-0.tsfile" ))) {
295+ // right
296+ generator .registerTimeseries (
297+ SchemaConfig .DEVICE_2 , Collections .singletonList (SchemaConfig .MEASUREMENT_20 ));
298+ // right
299+ generator .registerTimeseries (
300+ SchemaConfig .DEVICE_3 , Collections .singletonList (SchemaConfig .MEASUREMENT_30 ));
301+ // Wrong, with 06 non-exist
302+ generator .registerTimeseries (
303+ SchemaConfig .DEVICE_4 ,
304+ Arrays .asList (SchemaConfig .MEASUREMENT_40 , SchemaConfig .MEASUREMENT_06 ));
305+ generator .generateData (SchemaConfig .DEVICE_2 , 10000 , PARTITION_INTERVAL / 10_000 , false );
306+ generator .generateData (SchemaConfig .DEVICE_3 , 10000 , PARTITION_INTERVAL / 10_000 , false );
307+ generator .generateData (SchemaConfig .DEVICE_4 , 10000 , PARTITION_INTERVAL / 10_000 , true );
308+ for (int i = 0 ; i < 1000 ; i ++) {
309+ generator .generateData (SchemaConfig .DEVICE_4 , 1 , PARTITION_INTERVAL - 10 , true );
310+ }
311+ writtenPoint2 = generator .getTotalNumber ();
312+ }
313+
314+ try (final Connection connection = EnvFactory .getEnv ().getConnection ();
315+ final Statement statement = connection .createStatement ()) {
316+
317+ try {
318+ statement .execute (
319+ String .format (
320+ "load \" %s\" with ('database-level'='2', 'convert-on-type-mismatch'='false')" ,
321+ tmpDir .getAbsolutePath () + File .separator + "1-0-0-0.tsfile" ));
322+ Assert .fail ();
323+ } catch (final Exception e ) {
324+ Assert .assertTrue (
325+ e .getMessage ()
326+ .contains (
327+ "TimeSeries under this device is not aligned, please use createTimeSeries or change device. (Path: root.sg.test_0.d_0)." ));
328+ }
329+
330+ try {
331+ statement .execute (
332+ String .format (
333+ "load \" %s\" with ('database-level'='2', 'convert-on-type-mismatch'='false')" ,
334+ tmpDir .getAbsolutePath () + File .separator + "2-0-0-0.tsfile" ));
335+ Assert .fail ();
336+ } catch (final Exception e ) {
337+ Assert .assertTrue (
338+ e .getMessage ()
339+ .contains (
340+ "TimeSeries under this device is aligned, please use createAlignedTimeSeries or change device. (Path: root.sg.test_1.a_4)." ));
341+ }
342+
343+ statement .execute (String .format ("load \" %s\" sglevel=2" , tmpDir .getAbsolutePath ()));
344+
345+ try (final ResultSet resultSet =
346+ statement .executeQuery ("select count(*) from root.sg.** group by level=1,2" )) {
347+ if (resultSet .next ()) {
348+ long sg1Count = resultSet .getLong ("count(root.sg.test_0.*.*)" );
349+ Assert .assertEquals (writtenPoint1 , sg1Count );
350+ long sg2Count = resultSet .getLong ("count(root.sg.test_1.*.*)" );
351+ Assert .assertEquals (writtenPoint2 , sg2Count );
352+ } else {
353+ Assert .fail ("This ResultSet is empty." );
354+ }
355+ }
356+ }
357+
358+ // Try to delete after loading. Expect no deadlock
359+ try (final Connection connection = EnvFactory .getEnv ().getConnection ();
360+ final Statement statement = connection .createStatement ()) {
361+ statement .execute (
362+ String .format (
363+ "delete timeseries %s.%s" ,
364+ SchemaConfig .DEVICE_0 , SchemaConfig .MEASUREMENT_00 .getMeasurementName ()));
365+ }
366+ }
367+
266368 @ Test
267369 public void testLoadAcrossMultipleTimePartitions () throws Exception {
268370 registerSchema ();
0 commit comments