@@ -74,6 +74,10 @@ def init_conns():
74
74
"boolean" : [
75
75
"boolean" ,
76
76
],
77
+ "json" : [
78
+ "json" ,
79
+ "jsonb"
80
+ ]
77
81
},
78
82
db .MySQL : {
79
83
# https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
@@ -199,6 +203,9 @@ def init_conns():
199
203
"boolean" : [
200
204
"boolean" ,
201
205
],
206
+ "json" : [
207
+ "super" ,
208
+ ]
202
209
},
203
210
db .Oracle : {
204
211
"int" : [
@@ -469,12 +476,28 @@ def __iter__(self):
469
476
return (uuid .uuid1 (i ) for i in range (self .max ))
470
477
471
478
479
+ class JsonFaker :
480
+ MANUAL_FAKES = [
481
+ '{"keyText": "text", "keyInt": 3, "keyFloat": 5.4445, "keyBoolean": true}' ,
482
+ ]
483
+
484
+ def __init__ (self , max ):
485
+ self .max = max
486
+
487
+ def __iter__ (self ):
488
+ return iter (self .MANUAL_FAKES [: self .max ])
489
+
490
+ def __len__ (self ):
491
+ return min (self .max , len (self .MANUAL_FAKES ))
492
+
493
+
472
494
TYPE_SAMPLES = {
473
495
"int" : IntFaker (N_SAMPLES ),
474
496
"datetime" : DateTimeFaker (N_SAMPLES ),
475
497
"float" : FloatFaker (N_SAMPLES ),
476
498
"uuid" : UUID_Faker (N_SAMPLES ),
477
499
"boolean" : BooleanFaker (N_SAMPLES ),
500
+ "json" : JsonFaker (N_SAMPLES )
478
501
}
479
502
480
503
@@ -546,7 +569,7 @@ def expand_params(testcase_func, param_num, param):
546
569
return name
547
570
548
571
549
- def _insert_to_table (conn , table_path , values , type ):
572
+ def _insert_to_table (conn , table_path , values , coltype ):
550
573
tbl = table (table_path )
551
574
552
575
current_n_rows = conn .query (tbl .count (), int )
@@ -555,31 +578,34 @@ def _insert_to_table(conn, table_path, values, type):
555
578
return
556
579
elif current_n_rows > 0 :
557
580
conn .query (drop_table (table_name ))
558
- _create_table_with_indexes (conn , table_path , type )
581
+ _create_table_with_indexes (conn , table_path , coltype )
559
582
560
583
# if BENCHMARK and N_SAMPLES > 10_000:
561
584
# description = f"{conn.name}: {table}"
562
585
# values = rich.progress.track(values, total=N_SAMPLES, description=description)
563
586
564
- if type == "boolean" :
587
+ if coltype == "boolean" :
565
588
values = [(i , bool (sample )) for i , sample in values ]
566
- elif re .search (r"(time zone|tz)" , type ):
589
+ elif re .search (r"(time zone|tz)" , coltype ):
567
590
values = [(i , sample .replace (tzinfo = timezone .utc )) for i , sample in values ]
568
591
569
592
if isinstance (conn , db .Clickhouse ):
570
- if type .startswith ("DateTime64" ):
593
+ if coltype .startswith ("DateTime64" ):
571
594
values = [(i , f"{ sample .replace (tzinfo = None )} " ) for i , sample in values ]
572
595
573
- elif type == "DateTime" :
596
+ elif coltype == "DateTime" :
574
597
# Clickhouse's DateTime does not allow to store micro/milli/nano seconds
575
598
values = [(i , str (sample )[:19 ]) for i , sample in values ]
576
599
577
- elif type .startswith ("Decimal(" ):
578
- precision = int (type [8 :].rstrip (")" ).split ("," )[1 ])
600
+ elif coltype .startswith ("Decimal(" ):
601
+ precision = int (coltype [8 :].rstrip (")" ).split ("," )[1 ])
579
602
values = [(i , round (sample , precision )) for i , sample in values ]
580
- elif isinstance (conn , db .BigQuery ) and type == "datetime" :
603
+ elif isinstance (conn , db .BigQuery ) and coltype == "datetime" :
581
604
values = [(i , Code (f"cast(timestamp '{ sample } ' as datetime)" )) for i , sample in values ]
582
605
606
+ if isinstance (conn , db .Redshift ) and coltype == "json" :
607
+ values = [(i , Code (f"JSON_PARSE('{ sample } ')" )) for i , sample in values ]
608
+
583
609
insert_rows_in_batches (conn , tbl , values , columns = ["id" , "col" ])
584
610
conn .query (commit )
585
611
0 commit comments