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