77import com .clickhouse .client .api .Client ;
88import com .clickhouse .client .api .command .CommandSettings ;
99import com .clickhouse .client .api .data_formats .RowBinaryFormatWriter ;
10+ import com .clickhouse .client .api .data_formats .internal .BinaryStreamReader ;
1011import com .clickhouse .client .api .enums .Protocol ;
1112import com .clickhouse .client .api .insert .InsertResponse ;
1213import com .clickhouse .client .api .insert .InsertSettings ;
@@ -141,7 +142,7 @@ public void writeNumbersTest() throws Exception {
141142 System .out .println ("Random seed: " + seed );
142143
143144 Field [][] rows = new Field [][] {{
144- new Field ("id" , 1 ),
145+ new Field ("id" , 1 ), //Row ID
145146 new Field ("int8" , rand .nextInt (256 ) - 128 ), new Field ("int8_nullable" ), new Field ("int8_default" ).set (3 ), //Int8
146147 new Field ("int16" , rand .nextInt (65536 ) - 32768 ), new Field ("int16_nullable" ), new Field ("int16_default" ).set (3 ), //Int16
147148 new Field ("int32" , rand .nextInt ()), new Field ("int32_nullable" ), new Field ("int32_default" ).set (3 ), //Int32
@@ -161,7 +162,61 @@ public void writeNumbersTest() throws Exception {
161162 new Field ("decimal64" , new BigDecimal (new BigInteger (18 , rand ) + "." + rand .nextInt (100000 , 1000000 ))), new Field ("decimal64_nullable" ), new Field ("decimal64_default" ).set ("3.000000" ), //Decimal64
162163 new Field ("decimal128" , new BigDecimal (new BigInteger (20 , rand ) + "." + rand .nextLong (10000000 , 100000000 ))), new Field ("decimal128_nullable" ), new Field ("decimal128_default" ).set ("3.00000000" ), //Decimal128
163164 new Field ("decimal256" , new BigDecimal (new BigInteger (57 , rand ) + "." + rand .nextLong (1000000000 , 10000000000L ))), new Field ("decimal256_nullable" ), new Field ("decimal256_default" ).set ("3.0000000000" ) //Decimal256
164- }
165+ }, {
166+ new Field ("id" , 2 ), //Row ID
167+ new Field ("int8" , rand .nextInt (256 ) - 128 ), new Field ("int8_nullable" ), new Field ("int8_default" ).set (3 ), //Int8
168+ new Field ("int16" , rand .nextInt (65536 ) - 32768 ), new Field ("int16_nullable" ), new Field ("int16_default" ).set (3 ), //Int16
169+ new Field ("int32" , rand .nextInt ()), new Field ("int32_nullable" ), new Field ("int32_default" ).set (3 ), //Int32
170+ new Field ("int64" , rand .nextLong ()), new Field ("int64_nullable" ), new Field ("int64_default" ).set (3 ), //Int64
171+ new Field ("int128" , new BigInteger (127 , rand )), new Field ("int128_nullable" ), new Field ("int128_default" ).set (3 ), //Int128
172+ new Field ("int256" , new BigInteger (255 , rand )), new Field ("int256_nullable" ), new Field ("int256_default" ).set (3 ), //Int256
173+ new Field ("uint8" , rand .nextInt (256 )), new Field ("uint8_nullable" ), new Field ("uint8_default" ).set (3 ), //UInt8
174+ new Field ("uint16" , rand .nextInt (65536 )), new Field ("uint16_nullable" ), new Field ("uint16_default" ).set (3 ), //UInt16
175+ new Field ("uint32" , rand .nextInt () & 0xFFFFFFFFL ), new Field ("uint32_nullable" ), new Field ("uint32_default" ).set (3 ), //UInt32
176+ new Field ("uint64" , BigInteger .valueOf (rand .nextLong (Long .MAX_VALUE ))), new Field ("uint64_nullable" ), new Field ("uint64_default" ).set (3 ), //UInt64
177+ new Field ("uint128" , new BigInteger (128 , rand )), new Field ("uint128_nullable" ), new Field ("uint128_default" ).set (3 ), //UInt128
178+ new Field ("uint256" , new BigInteger (256 , rand )), new Field ("uint256_nullable" ), new Field ("uint256_default" ).set (3 ), //UInt256
179+ new Field ("float32" , rand .nextFloat ()), new Field ("float32_nullable" ), new Field ("float32_default" ).set ("3.0" ), //Float32
180+ new Field ("float64" , rand .nextDouble ()), new Field ("float64_nullable" ), new Field ("float64_default" ).set ("3.0" ), //Float64
181+ new Field ("decimal" , new BigDecimal (new BigInteger (5 , rand ) + "." + rand .nextInt (10 ,100 ))), new Field ("decimal_nullable" ), new Field ("decimal_default" ).set ("3.00" ), //Decimal(4)
182+ new Field ("decimal32" , new BigDecimal (new BigInteger (7 , rand ) + "." + rand .nextInt (1000 , 10000 ))), new Field ("decimal32_nullable" ), new Field ("decimal32_default" ).set ("3.0000" ), //Decimal32
183+ new Field ("decimal64" , new BigDecimal (new BigInteger (18 , rand ) + "." + rand .nextInt (100000 , 1000000 ))), new Field ("decimal64_nullable" ), new Field ("decimal64_default" ).set ("3.000000" ), //Decimal64
184+ new Field ("decimal128" , new BigDecimal (new BigInteger (20 , rand ) + "." + rand .nextLong (10000000 , 100000000 ))), new Field ("decimal128_nullable" ), new Field ("decimal128_default" ).set ("3.00000000" ), //Decimal128
185+ new Field ("decimal256" , new BigDecimal (new BigInteger (57 , rand ) + "." + rand .nextLong (1000000000 , 10000000000L ))), new Field ("decimal256_nullable" ), new Field ("decimal256_default" ).set ("3.0000000000" ) //Decimal256
186+ }};
187+
188+ writeTest (tableName , tableCreate , rows );
189+ }
190+
191+
192+ @ Test (groups = { "integration" })
193+ public void writeStringsTest () throws Exception {
194+ String tableName = "rowBinaryFormatWriterTest_writeNumbersTest_" + UUID .randomUUID ().toString ().replace ('-' , '_' );
195+ String tableCreate = "CREATE TABLE \" " + tableName + "\" " +
196+ " (id Int32, " +
197+ " string String, string_nullable Nullable(String), string_default String DEFAULT '3', " +
198+ " fixed_string FixedString(10), fixed_string_nullable Nullable(FixedString(10)), fixed_string_default FixedString(10) DEFAULT 'tenletters', " +
199+ " uuid UUID, uuid_nullable Nullable(UUID), uuid_default UUID DEFAULT '61f0c404-5cb3-11e7-907b-a6006ad3dba0', " +
200+ " enum8 Enum8('a' = 1, 'b' = 2), enum8_nullable Nullable(Enum8('a' = 1, 'b' = 2)), enum8_default Enum8('a' = 1, 'b' = 2) DEFAULT 'a', " +
201+ " enum16 Enum16('a' = 1, 'b' = 2), enum16_nullable Nullable(Enum16('a' = 1, 'b' = 2)), enum16_default Enum16('a' = 1, 'b' = 2) DEFAULT 'a', " +
202+ " ) Engine = MergeTree ORDER BY id" ;
203+
204+ // Insert random (valid) values
205+ Field [][] rows = new Field [][] {{
206+ new Field ("id" , 1 ), //Row ID
207+ new Field ("string" , RandomStringUtils .randomAlphabetic (1024 )), new Field ("string_nullable" ), new Field ("string_default" ).set ("3" ), //String
208+ new Field ("fixed_string" , RandomStringUtils .randomAlphabetic (10 )), new Field ("fixed_string_nullable" ), new Field ("fixed_string_default" ).set ("tenletters" ), //FixedString
209+ new Field ("uuid" , UUID .randomUUID ()), new Field ("uuid_nullable" ), new Field ("uuid_default" ).set ("61f0c404-5cb3-11e7-907b-a6006ad3dba0" ), //UUID
210+ new Field ("enum8" , "a" ), new Field ("enum8_nullable" ), new Field ("enum8_default" ).set ("a" ), //Enum8
211+ new Field ("enum16" , "b" ), new Field ("enum16_nullable" ), new Field ("enum16_default" ).set ("a" ) //Enum16
212+ }, {
213+ new Field ("id" , 2 ), //Row ID
214+ new Field ("string" , RandomStringUtils .randomAlphabetic (1024 )), new Field ("string_nullable" ), new Field ("string_default" ).set ("3" ), //String
215+ new Field ("fixed_string" , RandomStringUtils .randomAlphabetic (10 )), new Field ("fixed_string_nullable" ), new Field ("fixed_string_default" ).set ("tenletters" ), //FixedString
216+ new Field ("uuid" , UUID .randomUUID ()), new Field ("uuid_nullable" ), new Field ("uuid_default" ).set ("61f0c404-5cb3-11e7-907b-a6006ad3dba0" ), //UUID
217+ new Field ("enum8" , "a" ), new Field ("enum8_nullable" ), new Field ("enum8_default" ).set ("a" ), //Enum8
218+ new Field ("enum16" , "b" ), new Field ("enum16_nullable" ), new Field ("enum16_default" ).set ("a" ) //Enum16
219+ }
165220 };
166221
167222 writeTest (tableName , tableCreate , rows );
0 commit comments