@@ -554,6 +554,51 @@ public void testAdvancedWriter() throws Exception {
554554 }
555555 }
556556
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+ " ) Engine = MergeTree ORDER by (name)" ;
569+
570+ initTable (tableName , tableCreate );
571+
572+ ZonedDateTime correctedTime = Instant .now ().atZone (ZoneId .of ("UTC" ));
573+ Object [][] rows = new Object [][] {
574+ {"foo1" , 0.3f , 0.6f , "a=1,b=2,c=5" , correctedTime , 10 },
575+ {"foo2" , 0.6f , 0.1f , "a=1,b=2,c=5" , correctedTime , null },
576+ {"foo3" , 0.7f , 0.4f , "a=1,b=2,c=5" , null , null },
577+ {"foo4" , 0.8f , 0.5f , null , null , null },
578+ };
579+
580+ TableSchema schema = client .getTableSchema (tableName );
581+
582+ ClickHouseFormat format = ClickHouseFormat .RowBinaryWithDefaults ;
583+ try (InsertResponse response = client .insert (tableName , out -> {
584+ RowBinaryFormatWriter w = new RowBinaryFormatWriter (out , schema , format );
585+ for (Object [] row : rows ) {
586+ for (int i = 0 ; i < row .length ; i ++) {
587+ w .setValue (i + 1 , row [i ]);
588+ }
589+ w .commitRow ();
590+ }
591+ }, format , new InsertSettings ()).get ()) {
592+ System .out .println ("Rows written: " + response .getWrittenRows ());
593+ }
594+
595+ List <GenericRecord > records = client .queryAll ("SELECT * FROM \" " + tableName + "\" " );
596+
597+ for (GenericRecord record : records ) {
598+ System .out .println ("> " + record .getString (1 ) + ", " + record .getFloat (2 ) + ", " + record .getFloat (3 ));
599+ }
600+ }
601+
557602 @ Test
558603 public void testCollectionInsert () throws Exception {
559604 String tableName = "very_long_table_name_with_uuid_" + UUID .randomUUID ().toString ().replace ('-' , '_' );
0 commit comments