@@ -100,6 +100,12 @@ pub trait Dialect: Send + Sync {
100100 ast:: DataType :: BigInt ( None )
101101 }
102102
103+ /// The SQL type to use for Arrow Int8 unparsing
104+ /// Most dialects use TinyInt, but PostgreSQL prefers SmallInt
105+ fn int8_cast_dtype ( & self ) -> ast:: DataType {
106+ ast:: DataType :: TinyInt ( None )
107+ }
108+
103109 /// The SQL type to use for Arrow Int32 unparsing
104110 /// Most dialects use Integer, but some, like MySQL, require SIGNED
105111 fn int32_cast_dtype ( & self ) -> ast:: DataType {
@@ -345,6 +351,10 @@ impl Dialect for PostgreSqlDialect {
345351 ast:: DataType :: DoublePrecision
346352 }
347353
354+ fn int8_cast_dtype ( & self ) -> ast:: DataType {
355+ ast:: DataType :: SmallInt ( None )
356+ }
357+
348358 fn scalar_function_to_sql_overrides (
349359 & self ,
350360 unparser : & Unparser ,
@@ -664,6 +674,7 @@ pub struct CustomDialect {
664674 large_utf8_cast_dtype : ast:: DataType ,
665675 date_field_extract_style : DateFieldExtractStyle ,
666676 character_length_style : CharacterLengthStyle ,
677+ int8_cast_dtype : ast:: DataType ,
667678 int64_cast_dtype : ast:: DataType ,
668679 int32_cast_dtype : ast:: DataType ,
669680 timestamp_cast_dtype : ast:: DataType ,
@@ -689,6 +700,7 @@ impl Default for CustomDialect {
689700 large_utf8_cast_dtype : ast:: DataType :: Text ,
690701 date_field_extract_style : DateFieldExtractStyle :: DatePart ,
691702 character_length_style : CharacterLengthStyle :: CharacterLength ,
703+ int8_cast_dtype : ast:: DataType :: TinyInt ( None ) ,
692704 int64_cast_dtype : ast:: DataType :: BigInt ( None ) ,
693705 int32_cast_dtype : ast:: DataType :: Integer ( None ) ,
694706 timestamp_cast_dtype : ast:: DataType :: Timestamp ( None , TimezoneInfo :: None ) ,
@@ -748,6 +760,10 @@ impl Dialect for CustomDialect {
748760 self . int64_cast_dtype . clone ( )
749761 }
750762
763+ fn int8_cast_dtype ( & self ) -> ast:: DataType {
764+ self . int8_cast_dtype . clone ( )
765+ }
766+
751767 fn int32_cast_dtype ( & self ) -> ast:: DataType {
752768 self . int32_cast_dtype . clone ( )
753769 }
@@ -839,6 +855,7 @@ pub struct CustomDialectBuilder {
839855 large_utf8_cast_dtype : ast:: DataType ,
840856 date_field_extract_style : DateFieldExtractStyle ,
841857 character_length_style : CharacterLengthStyle ,
858+ int8_cast_dtype : ast:: DataType ,
842859 int64_cast_dtype : ast:: DataType ,
843860 int32_cast_dtype : ast:: DataType ,
844861 timestamp_cast_dtype : ast:: DataType ,
@@ -870,6 +887,7 @@ impl CustomDialectBuilder {
870887 large_utf8_cast_dtype : ast:: DataType :: Text ,
871888 date_field_extract_style : DateFieldExtractStyle :: DatePart ,
872889 character_length_style : CharacterLengthStyle :: CharacterLength ,
890+ int8_cast_dtype : ast:: DataType :: TinyInt ( None ) ,
873891 int64_cast_dtype : ast:: DataType :: BigInt ( None ) ,
874892 int32_cast_dtype : ast:: DataType :: Integer ( None ) ,
875893 timestamp_cast_dtype : ast:: DataType :: Timestamp ( None , TimezoneInfo :: None ) ,
@@ -898,6 +916,7 @@ impl CustomDialectBuilder {
898916 large_utf8_cast_dtype : self . large_utf8_cast_dtype ,
899917 date_field_extract_style : self . date_field_extract_style ,
900918 character_length_style : self . character_length_style ,
919+ int8_cast_dtype : self . int8_cast_dtype ,
901920 int64_cast_dtype : self . int64_cast_dtype ,
902921 int32_cast_dtype : self . int32_cast_dtype ,
903922 timestamp_cast_dtype : self . timestamp_cast_dtype ,
@@ -952,6 +971,12 @@ impl CustomDialectBuilder {
952971 self
953972 }
954973
974+ /// Customize the dialect with a specific SQL type for Int8 casting: TinyInt, SmallInt, etc.
975+ pub fn with_int8_cast_dtype ( mut self , int8_cast_dtype : ast:: DataType ) -> Self {
976+ self . int8_cast_dtype = int8_cast_dtype;
977+ self
978+ }
979+
955980 /// Customize the dialect with a specific SQL type for Float64 casting: DOUBLE, DOUBLE PRECISION, etc.
956981 pub fn with_float64_ast_dtype ( mut self , float64_ast_dtype : ast:: DataType ) -> Self {
957982 self . float64_ast_dtype = float64_ast_dtype;
0 commit comments