@@ -7208,6 +7208,12 @@ def _build_table_properties_exp(
72087208 "Doris table property 'order_by' is only supported on UNIQUE KEY tables. "
72097209 "For DUPLICATE KEY or AGGREGATE KEY tables, sort order is determined by the key columns."
72107210 )
7211+ doris_ver = self ._get_doris_version ()
7212+ if doris_ver is not None and doris_ver < (4 , 1 ):
7213+ raise SQLMeshError (
7214+ f"Doris table property 'order_by' / 'cluster_by' (custom sort key on UNIQUE KEY tables) "
7215+ f"requires Apache Doris 4.1+ (detected Doris { doris_ver [0 ]} .{ doris_ver [1 ]} )."
7216+ )
72117217 mow_val = self ._extract_str_value (
72127218 table_properties_copy .get ("enable_unique_key_merge_on_write" )
72137219 )
@@ -7624,6 +7630,18 @@ def _to_sql(self, expression: exp.Expr, quote: bool = True, **kwargs: t.Any) ->
76247630 expression = cast_node
76257631 else :
76267632 ts_node .replace (cast_node )
7633+ if any (
7634+ not (
7635+ isinstance (m .args .get ("keys" ), exp .Array )
7636+ and isinstance (m .args .get ("values" ), exp .Array )
7637+ )
7638+ and (m .args .get ("keys" ) is not None or m .args .get ("values" ) is not None )
7639+ for m in expression .find_all (exp .Map )
7640+ ):
7641+ self ._get_doris_version ()
7642+ doris_version = getattr (self , "_doris_version" , None )
7643+ if doris_version and "dialect" not in kwargs :
7644+ kwargs ["dialect" ] = f"{ self .dialect } , version={ '.' .join (str (p ) for p in doris_version )} "
76277645 if expression .find (exp .DataType ):
76287646 expression = expression .copy ()
76297647 for dtype in reversed (list (expression .find_all (exp .DataType ))):
@@ -7654,9 +7672,13 @@ def _to_sql(self, expression: exp.Expr, quote: bool = True, **kwargs: t.Any) ->
76547672 dtype .set ("expressions" , [exp .DataTypeParam (this = exp .Literal .number (6 ))])
76557673 elif dtype .is_type ("struct" ):
76567674 new_field_sqls : t .List [str ] = []
7657- for field in dtype .expressions :
7675+ for idx , field in enumerate ( dtype .expressions , start = 1 ) :
76587676 if isinstance (field , exp .ColumnDef ) and field .args .get ("kind" ):
7659- field_id = field .this .copy ()
7677+ field_id = (
7678+ field .this .copy ()
7679+ if isinstance (field .this , exp .Expr )
7680+ else exp .to_identifier (f"col{ idx } " )
7681+ )
76607682 if quote and isinstance (field_id , exp .Identifier ):
76617683 field_id .set ("quoted" , True )
76627684 field_name_sql = super ()._to_sql (
@@ -7666,6 +7688,19 @@ def _to_sql(self, expression: exp.Expr, quote: bool = True, **kwargs: t.Any) ->
76667688 field .args ["kind" ], quote = quote , pretty = False , ** kwargs
76677689 )
76687690 new_field_sqls .append (f"{ field_name_sql } : { field_kind_sql } " )
7691+ elif isinstance (field , exp .DataType ) or (
7692+ isinstance (field , exp .DataTypeParam )
7693+ and isinstance (field .this , exp .DataType )
7694+ ):
7695+ raw_kind = field .this if isinstance (field , exp .DataTypeParam ) else field
7696+ field_id = exp .to_identifier (f"col{ idx } " , quoted = quote )
7697+ field_name_sql = super ()._to_sql (
7698+ field_id , quote = False , pretty = False , ** kwargs
7699+ )
7700+ field_kind_sql = super ()._to_sql (
7701+ raw_kind , quote = quote , pretty = False , ** kwargs
7702+ )
7703+ new_field_sqls .append (f"{ field_name_sql } : { field_kind_sql } " )
76697704 else :
76707705 new_field_sqls .append (
76717706 super ()._to_sql (field , quote = quote , pretty = False , ** kwargs )
@@ -7678,18 +7713,6 @@ def _to_sql(self, expression: exp.Expr, quote: bool = True, **kwargs: t.Any) ->
76787713 expression = struct_replacement
76797714 else :
76807715 dtype .replace (struct_replacement )
7681- if any (
7682- not (
7683- isinstance (m .args .get ("keys" ), exp .Array )
7684- and isinstance (m .args .get ("values" ), exp .Array )
7685- )
7686- and (m .args .get ("keys" ) is not None or m .args .get ("values" ) is not None )
7687- for m in expression .find_all (exp .Map )
7688- ):
7689- self ._get_doris_version ()
7690- doris_version = getattr (self , "_doris_version" , None )
7691- if doris_version and "dialect" not in kwargs :
7692- kwargs ["dialect" ] = f"{ self .dialect } , version={ '.' .join (str (p ) for p in doris_version )} "
76937716 return super ()._to_sql (expression , quote = quote , ** kwargs )
76947717
76957718 def _build_distributed_by_exp (
0 commit comments