11package com .clickhouse .client .insert ;
22
33import com .clickhouse .client .api .metadata .TableSchema ;
4+ import com .clickhouse .data .ClickHouseEnum ;
5+ import org .apache .commons .lang3 .RandomStringUtils ;
46
57import java .math .BigDecimal ;
68import java .math .BigInteger ;
@@ -64,7 +66,7 @@ public class SamplePOJO {
6466
6567 public SamplePOJO () {
6668 int8 = RandomGenerator .getDefault ().nextInt (-127 , 128 );
67- int16 = RandomGenerator .getDefault ().nextInt (-32768 ,32768 );
69+ int16 = RandomGenerator .getDefault ().nextInt (-32767 ,32768 );
6870 int32 = RandomGenerator .getDefault ().nextInt ();
6971 int64 = RandomGenerator .getDefault ().nextLong (9223372036854775807L );
7072 int128 = BigInteger .valueOf (RandomGenerator .getDefault ().nextLong ());
@@ -74,8 +76,8 @@ public SamplePOJO() {
7476 uint16 = RandomGenerator .getDefault ().nextInt (0 , 65536 );
7577 uint32 = RandomGenerator .getDefault ().nextLong (0 , 4294967296L );
7678 uint64 = RandomGenerator .getDefault ().nextLong (0 , Long .MAX_VALUE );
77- uint128 = BigInteger .valueOf (RandomGenerator .getDefault ().nextLong ());
78- uint256 = BigInteger .valueOf (RandomGenerator .getDefault ().nextLong ());
79+ uint128 = BigInteger .valueOf (RandomGenerator .getDefault ().nextLong (0 , Long . MAX_VALUE ));
80+ uint256 = BigInteger .valueOf (RandomGenerator .getDefault ().nextLong (0 , Long . MAX_VALUE ));
7981
8082 float32 = RandomGenerator .getDefault ().nextFloat ();
8183 float64 = RandomGenerator .getDefault ().nextDouble ();
@@ -87,8 +89,8 @@ public SamplePOJO() {
8789
8890 bool = RandomGenerator .getDefault ().nextBoolean ();
8991
90- string = "string" + RandomGenerator . getDefault (). nextInt ( );
91- fixedString = "fixed" + RandomGenerator . getDefault (). nextInt ( );
92+ string = RandomStringUtils . randomAlphabetic ( 1 , 512 );
93+ fixedString = RandomStringUtils . randomAlphabetic ( 3 );
9294
9395 date = LocalDate .now ();
9496 date32 = LocalDate .now ();
@@ -98,8 +100,8 @@ public SamplePOJO() {
98100
99101 uuid = UUID .randomUUID ();
100102
101- enum8 = (byte ) RandomGenerator .getDefault ().nextInt ();
102- enum16 = RandomGenerator .getDefault ().nextInt ();
103+ enum8 = (byte ) RandomGenerator .getDefault ().nextInt (0 , 27 );
104+ enum16 = RandomGenerator .getDefault ().nextInt (0 , 27 );
103105
104106 try {
105107 Random random = new Random ();
@@ -115,9 +117,9 @@ public SamplePOJO() {
115117 ipv6 = null ;
116118 }
117119
118- array = List .of ("a" , "b" , "c" );
119- tuple = List .of (1 , 2 , 3 );
120- map = Map .of ("a" , 1 , "b" , 2 , "c" , 3 );
120+ array = List .of ("a" , "b" , "c" , "d" , "e" , "f" , "g" , "h" , "i" , "j" , "k" , "l" , "m" , "n" , "o" , "p" , "q" , "r" , "s" , "t" , "u" , "v" , "w" , "x" , "y" , "z" );
121+ tuple = List .of (1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 );
122+ map = Map .of ("a" , 1 , "b" , 2 , "c" , 3 , "d" , 4 , "e" , 5 , "f" , 6 , "g" , 7 , "h" , 8 , "i" , 9 , "j" , 10 );
121123
122124 inner = new SamplePOJOInner ();
123125 }
@@ -423,7 +425,7 @@ public static TableSchema generateTableSchema(String tableName) {
423425 schema .addColumn ("bool" , "UInt8" );
424426
425427 schema .addColumn ("string" , "String" );
426- schema .addColumn ("fixedString" , "FixedString(10 )" );
428+ schema .addColumn ("fixedString" , "FixedString(3 )" );
427429
428430 schema .addColumn ("date" , "Date" );
429431 schema .addColumn ("date32" , "Date" );
@@ -433,14 +435,14 @@ public static TableSchema generateTableSchema(String tableName) {
433435
434436 schema .addColumn ("uuid" , "UUID" );
435437
436- schema .addColumn ("enum8" , "Enum8('a' = 1, 'b' = 2, 'c' = 3)" );
437- schema .addColumn ("enum16" , "Enum16('a' = 1, 'b' = 2, 'c' = 3)" );
438+ schema .addColumn ("enum8" , "Enum8('a' = 1, 'b' = 2, 'c' = 3, 'd' = 4, 'e' = 5, 'f' = 6, 'g' = 7, 'h' = 8, 'i' = 9, 'j' = 10, 'k' = 11, 'l' = 12, 'm' = 13, 'n' = 14, 'o' = 15, 'p' = 16, 'q' = 17, 'r' = 18, 's' = 19, 't' = 20, 'u' = 21, 'v' = 22, 'w' = 23, 'x' = 24, 'y' = 25, 'z' = 26 )" );
439+ schema .addColumn ("enum16" , "Enum16('a' = 1, 'b' = 2, 'c' = 3, 'd' = 4, 'e' = 5, 'f' = 6, 'g' = 7, 'h' = 8, 'i' = 9, 'j' = 10, 'k' = 11, 'l' = 12, 'm' = 13, 'n' = 14, 'o' = 15, 'p' = 16, 'q' = 17, 'r' = 18, 's' = 19, 't' = 20, 'u' = 21, 'v' = 22, 'w' = 23, 'x' = 24, 'y' = 25, 'z' = 26 )" );
438440
439441 schema .addColumn ("ipv4" , "IPv4" );
440442 schema .addColumn ("ipv6" , "IPv6" );
441443
442444 schema .addColumn ("array" , "Array(String)" );
443- schema .addColumn ("tuple" , "Tuple(Int32, Int32, Int32)" );
445+ schema .addColumn ("tuple" , "Tuple(Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32, Int32 )" );
444446 schema .addColumn ("map" , "Map(String, Int32)" );
445447
446448 return schema ;
@@ -454,16 +456,7 @@ public static String generateTableCreateSQL(String tableName) {
454456 if (i > 0 ) {
455457 sb .append (", " );
456458 }
457- sb .append (schema .getColumns ().get (i ).getColumnName ()).append (" " ).append (schema .getColumns ().get (i ).getDataType ());
458- String type = String .valueOf (schema .getColumns ().get (i ).getDataType ());
459-
460- if (type .startsWith ("Decimal" )) {
461- sb .append ("(" ).append (schema .getColumns ().get (i ).getScale ()).append (")" );
462- }
463-
464- if (type .startsWith ("FixedString" )) {
465- sb .append ("(" ).append (schema .getColumns ().get (i ).getPrecision ()).append (")" );
466- }
459+ sb .append (schema .getColumns ().get (i ).getColumnName ()).append (" " ).append (schema .getColumns ().get (i ).getOriginalTypeName ());
467460 }
468461 sb .append (") ENGINE = Memory" );
469462 return sb .toString ();
0 commit comments