@@ -173,7 +173,6 @@ def close(self):
173
173
"Close connection(s) to the database instance. Querying will stop functioning."
174
174
...
175
175
176
-
177
176
@abstractmethod
178
177
def normalize_timestamp (self , value : str , coltype : ColType ) -> str :
179
178
"""Creates an SQL expression, that converts 'value' to a normalized timestamp.
@@ -282,7 +281,12 @@ def _convert_db_precision_to_digits(self, p: int) -> int:
282
281
return math .floor (math .log (2 ** p , 10 ))
283
282
284
283
def _parse_type (
285
- self , type_repr : str , datetime_precision : int = None , numeric_precision : int = None , numeric_scale : int = None
284
+ self ,
285
+ col_name : str ,
286
+ type_repr : str ,
287
+ datetime_precision : int = None ,
288
+ numeric_precision : int = None ,
289
+ numeric_scale : int = None ,
286
290
) -> ColType :
287
291
""" """
288
292
@@ -302,7 +306,7 @@ def _parse_type(
302
306
303
307
elif issubclass (cls , Decimal ):
304
308
if numeric_scale is None :
305
- raise ValueError (f"{ self .name } : Unexpected numeric_scale is NULL, for column of type { type_repr } ." )
309
+ raise ValueError (f"{ self .name } : Unexpected numeric_scale is NULL, for column { col_name } of type { type_repr } ." )
306
310
return cls (precision = numeric_scale )
307
311
308
312
assert issubclass (cls , Float )
@@ -333,7 +337,7 @@ def query_table_schema(self, path: DbPath, filter_columns: Optional[Sequence[str
333
337
rows = [r for r in rows if r [0 ].lower () in accept ]
334
338
335
339
# Return a dict of form {name: type} after normalization
336
- return {row [0 ]: self ._parse_type (* row [ 1 :] ) for row in rows }
340
+ return {row [0 ]: self ._parse_type (* row ) for row in rows }
337
341
338
342
# @lru_cache()
339
343
# def get_table_schema(self, path: DbPath) -> Dict[str, ColType]:
@@ -344,13 +348,10 @@ def _normalize_table_path(self, path: DbPath) -> DbPath:
344
348
if self .default_schema :
345
349
return self .default_schema , path [0 ]
346
350
elif len (path ) != 2 :
347
- raise ValueError (
348
- f"{ self .name } : Bad table path for { self } : '{ '.' .join (path )} '. Expected form: schema.table"
349
- )
351
+ raise ValueError (f"{ self .name } : Bad table path for { self } : '{ '.' .join (path )} '. Expected form: schema.table" )
350
352
351
353
return path
352
354
353
-
354
355
def parse_table_name (self , name : str ) -> DbPath :
355
356
return parse_table_name (name )
356
357
@@ -446,13 +447,14 @@ def md5_to_int(self, s: str) -> str:
446
447
def to_string (self , s : str ):
447
448
return f"{ s } ::varchar"
448
449
449
-
450
450
def normalize_timestamp (self , value : str , coltype : ColType ) -> str :
451
451
if coltype .rounds :
452
452
return f"to_char({ value } ::timestamp({ coltype .precision } ), 'YYYY-mm-dd HH24:MI:SS.US')"
453
453
454
454
timestamp6 = f"to_char({ value } ::timestamp(6), 'YYYY-mm-dd HH24:MI:SS.US')"
455
- return f"RPAD(LEFT({ timestamp6 } , { TIMESTAMP_PRECISION_POS + coltype .precision } ), { TIMESTAMP_PRECISION_POS + 6 } , '0')"
455
+ return (
456
+ f"RPAD(LEFT({ timestamp6 } , { TIMESTAMP_PRECISION_POS + coltype .precision } ), { TIMESTAMP_PRECISION_POS + 6 } , '0')"
457
+ )
456
458
457
459
def normalize_number (self , value : str , coltype : ColType ) -> str :
458
460
return self .to_string (f"{ value } ::decimal(38, { coltype .precision } )" )
@@ -502,9 +504,7 @@ def normalize_timestamp(self, value: str, coltype: ColType) -> str:
502
504
else :
503
505
s = f"date_format(cast({ value } as timestamp(6)), '%Y-%m-%d %H:%i:%S.%f')"
504
506
505
- return (
506
- f"RPAD(RPAD({ s } , { TIMESTAMP_PRECISION_POS + coltype .precision } , '.'), { TIMESTAMP_PRECISION_POS + 6 } , '0')"
507
- )
507
+ return f"RPAD(RPAD({ s } , { TIMESTAMP_PRECISION_POS + coltype .precision } , '.'), { TIMESTAMP_PRECISION_POS + 6 } , '0')"
508
508
509
509
def normalize_number (self , value : str , coltype : ColType ) -> str :
510
510
return self .to_string (f"cast({ value } as decimal(38,{ coltype .precision } ))" )
@@ -517,7 +517,9 @@ def select_table_schema(self, path: DbPath) -> str:
517
517
f"WHERE table_name = '{ table } ' AND table_schema = '{ schema } '"
518
518
)
519
519
520
- def _parse_type (self , type_repr : str , datetime_precision : int = None , numeric_precision : int = None ) -> ColType :
520
+ def _parse_type (
521
+ self , col_name : str , type_repr : str , datetime_precision : int = None , numeric_precision : int = None
522
+ ) -> ColType :
521
523
regexps = {
522
524
r"timestamp\((\d)\)" : Timestamp ,
523
525
r"timestamp\((\d)\) with time zone" : TimestampTZ ,
@@ -607,7 +609,6 @@ def normalize_number(self, value: str, coltype: ColType) -> str:
607
609
return self .to_string (f"cast({ value } as decimal(38, { coltype .precision } ))" )
608
610
609
611
610
-
611
612
class Oracle (ThreadedDatabase ):
612
613
ROUNDS_ON_PREC_LOSS = True
613
614
@@ -661,7 +662,12 @@ def normalize_number(self, value: str, coltype: ColType) -> str:
661
662
return f"to_char({ value } , '{ format_str } ')"
662
663
663
664
def _parse_type (
664
- self , type_repr : str , datetime_precision : int = None , numeric_precision : int = None , numeric_scale : int = None
665
+ self ,
666
+ col_name : str ,
667
+ type_repr : str ,
668
+ datetime_precision : int = None ,
669
+ numeric_precision : int = None ,
670
+ numeric_scale : int = None ,
665
671
) -> ColType :
666
672
""" """
667
673
regexps = {
@@ -720,15 +726,18 @@ def normalize_timestamp(self, value: str, coltype: ColType) -> str:
720
726
us = f"extract(us from { timestamp } )"
721
727
# epoch = Total time since epoch in microseconds.
722
728
epoch = f"{ secs } *1000000 + { ms } *1000 + { us } "
723
- timestamp6 = f"to_char({ epoch } , -6+{ coltype .precision } ) * interval '0.000001 seconds', 'YYYY-mm-dd HH24:MI:SS.US')"
729
+ timestamp6 = (
730
+ f"to_char({ epoch } , -6+{ coltype .precision } ) * interval '0.000001 seconds', 'YYYY-mm-dd HH24:MI:SS.US')"
731
+ )
724
732
else :
725
733
timestamp6 = f"to_char({ value } ::timestamp(6), 'YYYY-mm-dd HH24:MI:SS.US')"
726
- return f"RPAD(LEFT({ timestamp6 } , { TIMESTAMP_PRECISION_POS + coltype .precision } ), { TIMESTAMP_PRECISION_POS + 6 } , '0')"
734
+ return (
735
+ f"RPAD(LEFT({ timestamp6 } , { TIMESTAMP_PRECISION_POS + coltype .precision } ), { TIMESTAMP_PRECISION_POS + 6 } , '0')"
736
+ )
727
737
728
738
def normalize_number (self , value : str , coltype : ColType ) -> str :
729
739
return self .to_string (f"{ value } ::decimal(38,{ coltype .precision } )" )
730
740
731
-
732
741
def select_table_schema (self , path : DbPath ) -> str :
733
742
schema , table = self ._normalize_table_path (path )
734
743
@@ -838,7 +847,9 @@ def normalize_timestamp(self, value: str, coltype: ColType) -> str:
838
847
return f"FORMAT_TIMESTAMP('%F %H:%M:%E6S', { value } )"
839
848
840
849
timestamp6 = f"FORMAT_TIMESTAMP('%F %H:%M:%E6S', { value } )"
841
- return f"RPAD(LEFT({ timestamp6 } , { TIMESTAMP_PRECISION_POS + coltype .precision } ), { TIMESTAMP_PRECISION_POS + 6 } , '0')"
850
+ return (
851
+ f"RPAD(LEFT({ timestamp6 } , { TIMESTAMP_PRECISION_POS + coltype .precision } ), { TIMESTAMP_PRECISION_POS + 6 } , '0')"
852
+ )
842
853
843
854
def normalize_number (self , value : str , coltype : ColType ) -> str :
844
855
if isinstance (coltype , Integer ):
0 commit comments