@@ -198,7 +198,7 @@ func DuckdbDataType(mysqlType sql.Type) (AnnotatedDuckType, error) {
198198 }
199199}
200200
201- func mysqlDataType (duckType AnnotatedDuckType , numericPrecision uint8 , numericScale uint8 ) sql.Type {
201+ func mysqlDataType (duckType AnnotatedDuckType , numericPrecision uint8 , numericScale uint8 ) ( sql.Type , error ) {
202202 // TODO: The current type mappings are not lossless. We need to store the original type in the column comments.
203203 duckName := strings .TrimSpace (strings .ToUpper (duckType .name ))
204204
@@ -219,7 +219,7 @@ func mysqlDataType(duckType AnnotatedDuckType, numericPrecision uint8, numericSc
219219 intBaseType = sqltypes .Uint8
220220 case "SMALLINT" :
221221 if mysqlName == "YEAR" {
222- return types .Year
222+ return types .Year , nil
223223 }
224224 intBaseType = sqltypes .Int16
225225 case "USMALLINT" :
@@ -240,13 +240,13 @@ func mysqlDataType(duckType AnnotatedDuckType, numericPrecision uint8, numericSc
240240 intBaseType = sqltypes .Int64
241241 case "UBIGINT" :
242242 if mysqlName == "BIT" {
243- return types .MustCreateBitType (duckType .mysql .Precision )
243+ return types .CreateBitType (duckType .mysql .Precision )
244244 }
245245 intBaseType = sqltypes .Uint64
246246 }
247247
248248 if intBaseType != sqltypes .Null {
249- return types .MustCreateNumberTypeWithDisplayWidth (intBaseType , int (duckType .mysql .Display ))
249+ return types .CreateNumberTypeWithDisplayWidth (intBaseType , int (duckType .mysql .Display ))
250250 }
251251
252252 length := int64 (duckType .mysql .Length )
@@ -255,70 +255,79 @@ func mysqlDataType(duckType AnnotatedDuckType, numericPrecision uint8, numericSc
255255
256256 switch duckName {
257257 case "FLOAT" :
258- return types .Float32
258+ return types .Float32 , nil
259259 case "DOUBLE" :
260- return types .Float64
260+ return types .Float64 , nil
261261
262262 case "TIMESTAMP" , "TIMESTAMP_S" , "TIMESTAMP_MS" :
263263 if mysqlName == "DATETIME" {
264- return types .MustCreateDatetimeType (sqltypes .Datetime , precision )
264+ return types .CreateDatetimeType (sqltypes .Datetime , precision )
265265 }
266- return types .MustCreateDatetimeType (sqltypes .Timestamp , precision )
266+ return types .CreateDatetimeType (sqltypes .Timestamp , precision )
267267
268268 case "DATE" :
269- return types .Date
269+ return types .Date , nil
270270 case "INTERVAL" , "TIME" :
271- return types .Time
271+ return types .Time , nil
272272
273273 case "DECIMAL" :
274- return types .MustCreateDecimalType (numericPrecision , numericScale )
274+ return types .CreateDecimalType (numericPrecision , numericScale )
275+
276+ case "UHUGEINT" , "HUGEINT" :
277+ // MySQL does not have these types. We store them as DECIMAL.
278+ return types .CreateDecimalType (39 , 0 )
279+
280+ case "VARINT" :
281+ // MySQL does not have this type. We store it as DECIMAL.
282+ // Here we use the maximum supported precision for DECIMAL in MySQL.
283+ return types .CreateDecimalType (65 , 0 )
275284
276285 case "VARCHAR" :
277286 if mysqlName == "TEXT" {
278287 if length <= types .TinyTextBlobMax {
279- return types .TinyText
288+ return types .TinyText , nil
280289 } else if length <= types .TextBlobMax {
281- return types .Text
290+ return types .Text , nil
282291 } else if length <= types .MediumTextBlobMax {
283- return types .MediumText
292+ return types .MediumText , nil
284293 } else {
285- return types .LongText
294+ return types .LongText , nil
286295 }
287296 } else if mysqlName == "VARCHAR" {
288- return types .MustCreateString (sqltypes .VarChar , length , collation )
297+ return types .CreateString (sqltypes .VarChar , length , collation )
289298 } else if mysqlName == "CHAR" {
290- return types .MustCreateString (sqltypes .Char , length , collation )
299+ return types .CreateString (sqltypes .Char , length , collation )
291300 } else if mysqlName == "SET" {
292- return types .MustCreateSetType (duckType .mysql .Values , collation )
301+ return types .CreateSetType (duckType .mysql .Values , collation )
293302 }
294- return types .Text
303+ return types .Text , nil
295304
296305 case "BLOB" :
297306 if mysqlName == "BLOB" {
298307 if length <= types .TinyTextBlobMax {
299- return types .TinyBlob
308+ return types .TinyBlob , nil
300309 } else if length <= types .TextBlobMax {
301- return types .Blob
310+ return types .Blob , nil
302311 } else if length <= types .MediumTextBlobMax {
303- return types .MediumBlob
312+ return types .MediumBlob , nil
304313 } else {
305- return types .LongBlob
314+ return types .LongBlob , nil
306315 }
307316 } else if mysqlName == "VARBINARY" {
308- return types .MustCreateBinary (sqltypes .VarBinary , length )
317+ return types .CreateBinary (sqltypes .VarBinary , length )
309318 } else if mysqlName == "BINARY" {
310- return types .MustCreateBinary (sqltypes .Binary , length )
319+ return types .CreateBinary (sqltypes .Binary , length )
311320 }
312- return types .Blob
321+ return types .Blob , nil
313322
314323 case "JSON" :
315- return types .JSON
324+ return types .JSON , nil
316325 case "ENUM" :
317- return types .MustCreateEnumType (duckType .mysql .Values , collation )
326+ return types .CreateEnumType (duckType .mysql .Values , collation )
318327 case "SET" :
319- return types .MustCreateSetType (duckType .mysql .Values , collation )
328+ return types .CreateSetType (duckType .mysql .Values , collation )
320329 default :
321- panic ( fmt .Sprintf ("encountered unknown DuckDB type(%v). This is likely a bug - please check the duckdbDataType function for missing type mappings " , duckType ) )
330+ return nil , fmt .Errorf ("encountered unknown DuckDB type(%v)" , duckType )
322331 }
323332}
324333
0 commit comments