@@ -554,6 +554,54 @@ public void testAdvancedWriter() throws Exception {
554
554
}
555
555
}
556
556
557
+ @ Test
558
+ public void testWriterWithMaterialize () throws Exception {
559
+ String tableName = "table_name_with_materialize" ;
560
+ String tableCreate = "CREATE TABLE \" " + tableName + "\" " +
561
+ " (name String, " +
562
+ " v1 Float32, " +
563
+ " v2 Float32, " +
564
+ " attrs Nullable(String), " +
565
+ " corrected_time DateTime('UTC') DEFAULT now()," +
566
+ " special_attr Nullable(Int8) DEFAULT -1," +
567
+ " name_lower String MATERIALIZED lower(name)," +
568
+ " name_lower_alias String ALIAS lower(name)," +
569
+ " unhexed String EPHEMERAL," +
570
+ " hexed FixedString(4) DEFAULT unhex(unhexed)" +
571
+ " ) Engine = MergeTree ORDER by (name)" ;
572
+
573
+ initTable (tableName , tableCreate );
574
+
575
+ ZonedDateTime correctedTime = Instant .now ().atZone (ZoneId .of ("UTC" ));
576
+ Object [][] rows = new Object [][] {
577
+ {"foo1" , 0.3f , 0.6f , "a=1,b=2,c=5" , correctedTime , 10 , "Z��" },
578
+ {"foo2" , 0.6f , 0.1f , "a=1,b=2,c=5" , correctedTime , null , "Z��" },
579
+ {"foo3" , 0.7f , 0.4f , "a=1,b=2,c=5" , null , null , "Z��" },
580
+ {"foo4" , 0.8f , 0.5f , null , null , null , "Z��" },
581
+ };
582
+
583
+ TableSchema schema = client .getTableSchema (tableName );
584
+
585
+ ClickHouseFormat format = ClickHouseFormat .RowBinaryWithDefaults ;
586
+ try (InsertResponse response = client .insert (tableName , out -> {
587
+ RowBinaryFormatWriter w = new RowBinaryFormatWriter (out , schema , format );
588
+ for (Object [] row : rows ) {
589
+ for (int i = 0 ; i < row .length ; i ++) {
590
+ w .setValue (i + 1 , row [i ]);
591
+ }
592
+ w .commitRow ();
593
+ }
594
+ }, format , new InsertSettings ()).get ()) {
595
+ System .out .println ("Rows written: " + response .getWrittenRows ());
596
+ }
597
+
598
+ List <GenericRecord > records = client .queryAll ("SELECT * FROM \" " + tableName + "\" " );
599
+
600
+ for (GenericRecord record : records ) {
601
+ System .out .println ("> " + record .getString (1 ) + ", " + record .getFloat (2 ) + ", " + record .getFloat (3 ));
602
+ }
603
+ }
604
+
557
605
@ Test
558
606
public void testCollectionInsert () throws Exception {
559
607
String tableName = "very_long_table_name_with_uuid_" + UUID .randomUUID ().toString ().replace ('-' , '_' );
@@ -705,6 +753,33 @@ public void testPOJOWithDynamicType() throws Exception {
705
753
}
706
754
}
707
755
756
+ @ Test (groups = { "integration" }, enabled = true )
757
+ public void insertSimplePOJOsWithMaterializeColumn () throws Exception {
758
+ String tableName = "simple_pojo_table_with_materialize_column" ;
759
+ String createSQL = SimplePOJO .generateTableCreateSQL (tableName );
760
+ String uuid = UUID .randomUUID ().toString ();
761
+
762
+ initTable (tableName , createSQL );
763
+
764
+ client .register (SimplePOJO .class , client .getTableSchema (tableName ));
765
+ List <Object > simplePOJOs = new ArrayList <>();
766
+
767
+ for (int i = 0 ; i < 1000 ; i ++) {
768
+ simplePOJOs .add (new SimplePOJO ());
769
+ }
770
+ settings .setQueryId (uuid );
771
+ InsertResponse response = client .insert (tableName , simplePOJOs , settings ).get (EXECUTE_CMD_TIMEOUT , TimeUnit .SECONDS );
772
+
773
+ OperationMetrics metrics = response .getMetrics ();
774
+ assertEquals (simplePOJOs .size (), metrics .getMetric (ServerMetrics .NUM_ROWS_WRITTEN ).getLong ());
775
+ assertEquals (simplePOJOs .size (), response .getWrittenRows ());
776
+ assertTrue (metrics .getMetric (ClientMetrics .OP_DURATION ).getLong () > 0 );
777
+ assertTrue (metrics .getMetric (ClientMetrics .OP_SERIALIZATION ).getLong () > 0 );
778
+ assertEquals (metrics .getQueryId (), uuid );
779
+ assertEquals (response .getQueryId (), uuid );
780
+ }
781
+
782
+
708
783
protected void initTable (String tableName , String createTableSQL ) throws Exception {
709
784
initTable (tableName , createTableSQL , new CommandSettings ());
710
785
}
0 commit comments