@@ -199,30 +199,34 @@ def cast(branch, alias: Optional[List[str]] = None, key=None):
199199 data_type = type_key
200200 if "Custom" in data_type :
201201 data_type = branch ["data_type" ]["Custom" ][0 ][0 ]["Identifier" ]["value" ].upper ()
202- if data_type == "Timestamp" :
202+ lower_data_type = data_type .lower ()
203+ upper_data_type = data_type .upper ()
204+ if lower_data_type == "timestamp" :
203205 data_type = "TIMESTAMP"
204- elif data_type == "Date " :
206+ elif lower_data_type == "date " :
205207 data_type = "DATE"
206- elif "Varchar " in data_type :
208+ elif "varchar " in lower_data_type :
207209 data_type = "VARCHAR"
208- elif "Decimal " in data_type :
210+ elif "decimal " in lower_data_type :
209211 data_type = "DECIMAL"
210212 if "PrecisionAndScale" in branch ["data_type" ]["Decimal" ]:
211213 precision = branch ["data_type" ]["Decimal" ]["PrecisionAndScale" ][0 ]
212214 scale = branch ["data_type" ]["Decimal" ]["PrecisionAndScale" ][1 ]
213215 args .append (build_literal_node (precision ))
214216 args .append (build_literal_node (scale ))
215- elif "Integer " in data_type :
217+ elif "integer " in lower_data_type :
216218 data_type = "INTEGER"
217- elif "Double " in data_type :
219+ elif "double " in lower_data_type :
218220 data_type = "DOUBLE"
219- elif "Boolean " in data_type :
221+ elif "boolean " in lower_data_type :
220222 data_type = "BOOLEAN"
221- elif "STRUCT " in data_type :
223+ elif "struct " in lower_data_type :
222224 data_type = "STRUCT"
223- elif "Blob " in data_type :
225+ elif "blob " in lower_data_type :
224226 data_type = "BLOB"
225- elif "Array" in data_type :
227+ elif any (token in lower_data_type for token in ("varbinary" , "binary" , "raw" )):
228+ data_type = "VARBINARY"
229+ elif "array" in lower_data_type :
226230 element_key = branch ["data_type" ]["Array" ].get ("AngleBracket" , {"Varchar" : None })
227231 if isinstance (element_key , dict ):
228232 element_key = next (iter (element_key ))
@@ -231,23 +235,19 @@ def cast(branch, alias: Optional[List[str]] = None, key=None):
231235 args .append (element_key )
232236 data_type = "ARRAY"
233237 else :
234- if data_type in ("String " , "Char " , "Text " , "Nvarchar " ):
238+ if upper_data_type in ("STRING " , "CHAR " , "TEXT " , "NVARCHAR " ):
235239 raise SqlError (
236240 f"Unsupported type for CAST - '{ data_type .upper ()} '. Did you mean 'VARCHAR'?"
237241 )
238- if data_type in ("Float " , "Numeric " , "Real " ):
242+ if upper_data_type in ("FLOAT " , "NUMERIC " , "REAL " ):
239243 raise SqlError (
240244 f"Unsupported type for CAST - '{ data_type .upper ()} '. Did you mean 'DOUBLE'?"
241245 )
242- if data_type in ("Binary" , "Raw" , "VarBinary" ):
243- raise SqlError (
244- f"Unsupported type for CAST - '{ data_type .upper ()} '. Did you mean 'BLOB'?"
245- )
246- if data_type in ("Int" , "SmallInt" , "TinyInt" , "BigInt" , "BYTE" ):
246+ if upper_data_type in ("INT" , "SMALLINT" , "TINYINT" , "BIGINT" , "BYTE" ):
247247 raise SqlError (
248248 f"Unsupported type for CAST - '{ data_type .upper ()} '. Did you mean 'INTEGER'?"
249249 )
250- if data_type in ("Bool " , "Bit " ):
250+ if upper_data_type in ("BOOL " , "BIT " ):
251251 raise SqlError (
252252 f"Unsupported type for CAST - '{ data_type .upper ()} '. Did you mean 'BOOLEAN'?"
253253 )
0 commit comments