@@ -204,6 +204,15 @@ class BaseDialect(abc.ABC):
204204 PLACEHOLDER_TABLE = None # Used for Oracle
205205 USE_TOP_INSTEAD_LIMIT : bool = False # True for MsSQL or Teradata
206206
207+ # Some database do not support long string so concatenation might lead to type overflow
208+ PREVENT_OVERFLOW_WHEN_CONCAT = False
209+
210+ _prevent_overflow_when_concat : bool = False
211+
212+ def enable_preventing_type_overflow (self ) -> None :
213+ logger .info ("Preventing type overflow when concatenation is enabled" )
214+ self ._prevent_overflow_when_concat = True
215+
207216 def parse_table_name (self , name : str ) -> DbPath :
208217 "Parse the given table name into a DbPath"
209218 return parse_table_name (name )
@@ -393,10 +402,18 @@ def render_checksum(self, c: Compiler, elem: Checksum) -> str:
393402 return f"sum({ md5 } )"
394403
395404 def render_concat (self , c : Compiler , elem : Concat ) -> str :
405+ if self ._prevent_overflow_when_concat :
406+ items = [
407+ f"{ self .compile (c , Code (self .to_md5 (self .to_string (self .compile (c , expr )))))} " for expr in elem .exprs
408+ ]
409+
396410 # We coalesce because on some DBs (e.g. MySQL) concat('a', NULL) is NULL
397- items = [
398- f"coalesce({ self .compile (c , Code (self .to_string (self .compile (c , expr ))))} , '<null>')" for expr in elem .exprs
399- ]
411+ else :
412+ items = [
413+ f"coalesce({ self .compile (c , Code (self .to_string (self .compile (c , expr ))))} , '<null>')"
414+ for expr in elem .exprs
415+ ]
416+
400417 assert items
401418 if len (items ) == 1 :
402419 return items [0 ]
@@ -770,6 +787,10 @@ def set_timezone_to_utc(self) -> str:
770787 def md5_as_int (self , s : str ) -> str :
771788 "Provide SQL for computing md5 and returning an int"
772789
790+ @abstractmethod
791+ def to_md5 (self , s : str ) -> str :
792+ """Method to calculate MD5"""
793+
773794 @abstractmethod
774795 def normalize_timestamp (self , value : str , coltype : TemporalType ) -> str :
775796 """Creates an SQL expression, that converts 'value' to a normalized timestamp.
0 commit comments