@@ -1120,7 +1120,31 @@ func convertTypeDef(columnType sqlparser.ColumnType) tree.ResolvableTypeReferenc
11201120 case "set" :
11211121 panic (fmt .Sprintf ("unhandled type: %s" , columnType .Type ))
11221122 case "bit" :
1123- panic (fmt .Sprintf ("unhandled type: %s" , columnType .Type ))
1123+ // Support for MySQL BIT type conversion (dolt#9641)
1124+ // See: https://github.com/dolthub/dolt/issues/9641
1125+ // Map BIT types to appropriately sized integers for MySQL compatibility
1126+ width := int32FromSqlVal (columnType .Length )
1127+
1128+ var intOid oid.Oid
1129+ var intWidth int32
1130+ if width <= 16 {
1131+ intOid = oid .T_int2
1132+ intWidth = 16
1133+ } else if width <= 32 {
1134+ intOid = oid .T_int4
1135+ intWidth = 32
1136+ } else {
1137+ intOid = oid .T_int8
1138+ intWidth = 64
1139+ }
1140+
1141+ return & types.T {
1142+ InternalType : types.InternalType {
1143+ Family : types .IntFamily ,
1144+ Width : intWidth ,
1145+ Oid : intOid ,
1146+ },
1147+ }
11241148 case "json" :
11251149 return & types.T {
11261150 InternalType : types.InternalType {
@@ -1568,3 +1592,27 @@ func TestBoolValSupport(t *testing.T) {
15681592 require .Contains (t , result [0 ], "CREATE TABLE" , "Result should contain CREATE TABLE" )
15691593 require .Contains (t , result [0 ], "false" , "Result should contain converted boolean literal" )
15701594}
1595+
1596+ // TestBitTypeSupport tests BIT type conversion for dolt#9641 compatibility
1597+ // See: https://github.com/dolthub/dolt/issues/9641
1598+ func TestBitTypeSupport (t * testing.T ) {
1599+ result := convertQuery ("CREATE TABLE bit_union_test_9641 (id INT PRIMARY KEY, flag BIT(1))" )
1600+ require .NotEmpty (t , result )
1601+ require .Len (t , result , 1 )
1602+ require .Contains (t , result [0 ], "CREATE TABLE" )
1603+ require .Contains (t , result [0 ], "SMALLINT" )
1604+
1605+ bitResult := convertQuery ("CREATE TABLE bit_test (id INT PRIMARY KEY, data BIT(8))" )
1606+ require .NotEmpty (t , bitResult )
1607+ require .Contains (t , bitResult [0 ], "CREATE TABLE" )
1608+
1609+ insertResult := convertQuery ("INSERT INTO bit_union_test_9641 VALUES (1, 0), (2, 1)" )
1610+ require .NotEmpty (t , insertResult )
1611+ require .Len (t , insertResult , 1 )
1612+ require .Contains (t , insertResult [0 ], "INSERT INTO" )
1613+
1614+ unionResult := convertQuery ("SELECT flag FROM bit_union_test_9641 WHERE id = 1 UNION SELECT NULL as flag" )
1615+ require .NotEmpty (t , unionResult )
1616+ require .Len (t , unionResult , 1 )
1617+ require .Contains (t , unionResult [0 ], "UNION" )
1618+ }
0 commit comments