43
43
import java .util .ArrayList ;
44
44
import java .util .Arrays ;
45
45
import java .util .List ;
46
+ import java .util .Objects ;
46
47
import java .util .Random ;
47
48
import java .util .concurrent .ThreadLocalRandom ;
48
49
@@ -407,7 +408,7 @@ public void testCloneWithExistedTable() throws Exception {
407
408
tEnv .executeSql ("CREATE DATABASE test" );
408
409
// create a paimon table with the same name
409
410
int ddlIndex = ThreadLocalRandom .current ().nextInt (0 , 4 );
410
- tEnv .executeSql (ddls ()[ddlIndex ]);
411
+ tEnv .executeSql (ddls (format )[ddlIndex ]);
411
412
412
413
List <String > args =
413
414
new ArrayList <>(
@@ -428,7 +429,7 @@ public void testCloneWithExistedTable() throws Exception {
428
429
"--target_catalog_conf" ,
429
430
"warehouse=" + warehouse ));
430
431
431
- if (ddlIndex < 3 ) {
432
+ if (ddlIndex < 4 ) {
432
433
assertThatThrownBy (() -> createAction (CloneAction .class , args ).run ())
433
434
.rootCause ()
434
435
.hasMessageContaining (exceptionMsg ()[ddlIndex ]);
@@ -499,31 +500,48 @@ public void testCloneWithNotExistedDatabase() throws Exception {
499
500
Assertions .assertThatList (r1 ).containsExactlyInAnyOrderElementsOf (r2 );
500
501
}
501
502
502
- private String [] ddls () {
503
+ private String [] ddls (String format ) {
503
504
// has primary key
504
505
String ddl0 =
505
506
"CREATE TABLE test.test_table (id string, id2 int, id3 int, PRIMARY KEY (id, id2, id3) NOT ENFORCED) "
506
- + "PARTITIONED BY (id2, id3) with ('bucket' = '-1');" ;
507
+ + "PARTITIONED BY (id2, id3) with ('bucket' = '-1', 'file.format' = '"
508
+ + format
509
+ + ");" ;
507
510
// has different partition keys
508
511
String ddl1 =
509
512
"CREATE TABLE test.test_table (id string, id2 int, id3 int) "
510
- + "PARTITIONED BY (id, id3) with ('bucket' = '-1');" ;
513
+ + "PARTITIONED BY (id, id3) with ('bucket' = '-1', 'file.format' = '"
514
+ + format
515
+ + "');" ;
511
516
// size of fields is different
512
517
String ddl2 =
513
518
"CREATE TABLE test.test_table (id2 int, id3 int) "
514
- + "PARTITIONED BY (id2, id3) with ('bucket' = '-1');" ;
515
- // normal
519
+ + "PARTITIONED BY (id2, id3) with ('bucket' = '-1', 'file.format' = '"
520
+ + format
521
+ + "');" ;
522
+
523
+ // different format
516
524
String ddl3 =
525
+ "CREATE TABLE test.test_table (id2 int, id3 int) "
526
+ + "PARTITIONED BY (id2, id3) with ('bucket' = '-1', 'file.format' = '"
527
+ + randomFormat (format )
528
+ + "');" ;
529
+
530
+ // normal
531
+ String ddl4 =
517
532
"CREATE TABLE test.test_table (id string, id2 int, id3 int) "
518
- + "PARTITIONED BY (id2, id3) with ('bucket' = '-1');" ;
519
- return new String [] {ddl0 , ddl1 , ddl2 , ddl3 };
533
+ + "PARTITIONED BY (id2, id3) with ('bucket' = '-1', 'file.format' = '"
534
+ + format
535
+ + "');" ;
536
+ return new String [] {ddl0 , ddl1 , ddl2 , ddl3 , ddl4 };
520
537
}
521
538
522
539
private String [] exceptionMsg () {
523
540
return new String [] {
524
541
"Can not clone data to existed paimon table which has primary keys" ,
525
542
"source table partition keys is not compatible with existed paimon table partition keys." ,
526
- "source table partition keys is not compatible with existed paimon table partition keys."
543
+ "source table partition keys is not compatible with existed paimon table partition keys." ,
544
+ "source table format is not compatible with existed paimon table format."
527
545
};
528
546
}
529
547
@@ -549,13 +567,18 @@ private static String data(int i) {
549
567
private String randomFormat () {
550
568
ThreadLocalRandom random = ThreadLocalRandom .current ();
551
569
int i = random .nextInt (3 );
552
- if (i == 0 ) {
553
- return "orc" ;
554
- } else if (i == 1 ) {
555
- return "parquet" ;
556
- } else {
557
- return "avro" ;
570
+ String [] formats = new String [] {"orc" , "parquet" , "avro" };
571
+ return formats [i ];
572
+ }
573
+
574
+ private String randomFormat (String excludedFormat ) {
575
+ ThreadLocalRandom random = ThreadLocalRandom .current ();
576
+ int i = random .nextInt (3 );
577
+ String [] formats = new String [] {"orc" , "parquet" , "avro" };
578
+ if (Objects .equals (excludedFormat , formats [i ])) {
579
+ return formats [(i + 1 ) % 3 ];
558
580
}
581
+ return formats [i ];
559
582
}
560
583
561
584
protected FileStoreTable paimonTable (
0 commit comments