1+ import logging
12import decimal
23from abc import ABC , abstractmethod
34from typing import Sequence , Optional , Tuple , Union , Dict , List
45from datetime import datetime
56
67from runtype import dataclass
78
8- from data_diff .utils import ArithAlphanumeric , ArithUUID , CaseAwareMapping
9+ from data_diff .utils import ArithAlphanumeric , ArithUUID , CaseAwareMapping , CaseInsensitiveDict , CaseSensitiveDict
910
1011
1112DbPath = Tuple [str , ...]
1213DbKey = Union [int , str , bytes , ArithUUID , ArithAlphanumeric ]
1314DbTime = datetime
1415
16+ logger = logging .getLogger ("databases" )
17+
1518
1619class ColType :
1720 supported = True
@@ -129,6 +132,8 @@ class UnknownColType(ColType):
129132
130133
131134class AbstractDatabase (ABC ):
135+ name : str
136+
132137 @abstractmethod
133138 def quote (self , s : str ):
134139 "Quote SQL name (implementation specific)"
@@ -144,6 +149,11 @@ def concat(self, l: List[str]) -> str:
144149 "Provide SQL for concatenating a bunch of column into a string"
145150 ...
146151
152+ @abstractmethod
153+ def is_distinct_from (self , a : str , b : str ) -> str :
154+ "Provide SQL for a comparison where NULL = NULL is true"
155+ ...
156+
147157 @abstractmethod
148158 def timestamp_value (self , t : DbTime ) -> str :
149159 "Provide SQL for the given timestamp value"
@@ -270,3 +280,15 @@ def _normalize_table_path(self, path: DbPath) -> DbPath:
270280
271281
272282Schema = CaseAwareMapping
283+
284+
285+ def create_schema (db : AbstractDatabase , table_path : DbPath , schema : dict , case_sensitive : bool ) -> CaseAwareMapping :
286+ logger .debug (f"[{ db .name } ] Schema = { schema } " )
287+
288+ if case_sensitive :
289+ return CaseSensitiveDict (schema )
290+
291+ if len ({k .lower () for k in schema }) < len (schema ):
292+ logger .warning (f'Ambiguous schema for { db } :{ "." .join (table_path )} | Columns = { ", " .join (list (schema ))} ' )
293+ logger .warning ("We recommend to disable case-insensitivity (set --case-sensitive)." )
294+ return CaseInsensitiveDict (schema )
0 commit comments