3434from data_diff .abcs .database_types import (
3535 Array ,
3636 Struct ,
37- AbstractDialect ,
3837 AbstractTable ,
3938 ColType ,
4039 Integer ,
@@ -104,7 +103,7 @@ class Compiler(AbstractCompiler):
104103 _counter : List = field (default_factory = lambda : [0 ])
105104
106105 @property
107- def dialect (self ) -> AbstractDialect :
106+ def dialect (self ) -> "Dialect" :
108107 return self .database .dialect
109108
110109 # TODO: DEPRECATED: Remove once the dialect is used directly in all places.
@@ -221,7 +220,7 @@ def optimizer_hints(self, hints: str) -> str:
221220 return f"/*+ { hints } */ "
222221
223222
224- class BaseDialect (AbstractDialect ):
223+ class BaseDialect (abc . ABC ):
225224 SUPPORTS_PRIMARY_KEY = False
226225 SUPPORTS_INDEXES = False
227226 TYPE_CLASSES : Dict [str , type ] = {}
@@ -230,6 +229,7 @@ class BaseDialect(AbstractDialect):
230229 PLACEHOLDER_TABLE = None # Used for Oracle
231230
232231 def parse_table_name (self , name : str ) -> DbPath :
232+ "Parse the given table name into a DbPath"
233233 return parse_table_name (name )
234234
235235 def compile (self , compiler : Compiler , elem , params = None ) -> str :
@@ -638,12 +638,14 @@ def render_inserttotable(self, c: Compiler, elem: InsertToTable) -> str:
638638 def offset_limit (
639639 self , offset : Optional [int ] = None , limit : Optional [int ] = None , has_order_by : Optional [bool ] = None
640640 ) -> str :
641+ "Provide SQL fragment for limit and offset inside a select"
641642 if offset :
642643 raise NotImplementedError ("No support for OFFSET in query" )
643644
644645 return f"LIMIT { limit } "
645646
646647 def concat (self , items : List [str ]) -> str :
648+ "Provide SQL for concatenating a bunch of columns into a string"
647649 assert len (items ) > 1
648650 joined_exprs = ", " .join (items )
649651 return f"concat({ joined_exprs } )"
@@ -653,24 +655,31 @@ def to_comparable(self, value: str, coltype: ColType) -> str:
653655 return value
654656
655657 def is_distinct_from (self , a : str , b : str ) -> str :
658+ "Provide SQL for a comparison where NULL = NULL is true"
656659 return f"{ a } is distinct from { b } "
657660
658661 def timestamp_value (self , t : DbTime ) -> str :
662+ "Provide SQL for the given timestamp value"
659663 return f"'{ t .isoformat ()} '"
660664
661665 def random (self ) -> str :
666+ "Provide SQL for generating a random number betweein 0..1"
662667 return "random()"
663668
664669 def current_timestamp (self ) -> str :
670+ "Provide SQL for returning the current timestamp, aka now"
665671 return "current_timestamp()"
666672
667673 def current_database (self ) -> str :
674+ "Provide SQL for returning the current default database."
668675 return "current_database()"
669676
670677 def current_schema (self ) -> str :
678+ "Provide SQL for returning the current default schema."
671679 return "current_schema()"
672680
673681 def explain_as_text (self , query : str ) -> str :
682+ "Provide SQL for explaining a query, returned as table(varchar)"
674683 return f"EXPLAIN { query } "
675684
676685 def _constant_value (self , v ):
@@ -719,7 +728,7 @@ def parse_type(
719728 numeric_precision : int = None ,
720729 numeric_scale : int = None ,
721730 ) -> ColType :
722- """ "" "
731+ "Parse type info as returned by the database "
723732
724733 cls = self ._parse_type_repr (type_repr )
725734 if cls is None :
@@ -762,6 +771,7 @@ def _convert_db_precision_to_digits(self, p: int) -> int:
762771
763772 @classmethod
764773 def load_mixins (cls , * abstract_mixins ) -> Self :
774+ "Load a list of mixins that implement the given abstract mixins"
765775 mixins = {m for m in cls .MIXINS if issubclass (m , abstract_mixins )}
766776
767777 class _DialectWithMixins (cls , * mixins , * abstract_mixins ):
@@ -771,6 +781,30 @@ class _DialectWithMixins(cls, *mixins, *abstract_mixins):
771781 return _DialectWithMixins ()
772782
773783
784+ @property
785+ @abstractmethod
786+ def name (self ) -> str :
787+ "Name of the dialect"
788+
789+ @property
790+ @abstractmethod
791+ def ROUNDS_ON_PREC_LOSS (self ) -> bool :
792+ "True if db rounds real values when losing precision, False if it truncates."
793+
794+ @abstractmethod
795+ def quote (self , s : str ):
796+ "Quote SQL name"
797+
798+ @abstractmethod
799+ def to_string (self , s : str ) -> str :
800+ # TODO rewrite using cast_to(x, str)
801+ "Provide SQL for casting a column to string"
802+
803+ @abstractmethod
804+ def set_timezone_to_utc (self ) -> str :
805+ "Provide SQL for setting the session timezone to UTC"
806+
807+
774808T = TypeVar ("T" , bound = BaseDialect )
775809
776810
0 commit comments