Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/dolthub/eventsapi_schema v0.0.0-20250725194025-a087efa1ee55
github.com/dolthub/flatbuffers/v23 v23.3.3-dh.2
github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad
github.com/dolthub/go-mysql-server v0.20.1-0.20250807172251-c76b4ab0b9c8
github.com/dolthub/go-mysql-server v0.20.1-0.20250808203856-b2556a731d9b
github.com/dolthub/sqllogictest/go v0.0.0-20240618184124-ca47f9354216
github.com/dolthub/vitess v0.0.0-20250730174048-497aebb8cea7
github.com/fatih/color v1.13.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,8 @@ github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad h1:66ZPawHszN
github.com/dolthub/go-icu-regex v0.0.0-20250327004329-6799764f2dad/go.mod h1:ylU4XjUpsMcvl/BKeRRMXSH7e7WBrPXdSLvnRJYrxEA=
github.com/dolthub/go-mysql-server v0.20.1-0.20250807172251-c76b4ab0b9c8 h1:MRwXXSGmTxG2nNQzWeFs4AOevCpn6fTVdrDX5+1rZhM=
github.com/dolthub/go-mysql-server v0.20.1-0.20250807172251-c76b4ab0b9c8/go.mod h1:D/E/y9q6i4mryN12JhvaKlFZnSSWD1X1tx+CFsUcgp8=
github.com/dolthub/go-mysql-server v0.20.1-0.20250808203856-b2556a731d9b h1:tpo0kv/l8grlUujwUnZ00fL9RX3SdcWJWrqbh7LL7o4=
github.com/dolthub/go-mysql-server v0.20.1-0.20250808203856-b2556a731d9b/go.mod h1:D/E/y9q6i4mryN12JhvaKlFZnSSWD1X1tx+CFsUcgp8=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63 h1:OAsXLAPL4du6tfbBgK0xXHZkOlos63RdKYS3Sgw/dfI=
github.com/dolthub/gozstd v0.0.0-20240423170813-23a2903bca63/go.mod h1:lV7lUeuDhH5thVGDCKXbatwKy2KW80L4rMT46n+Y2/Q=
github.com/dolthub/ishell v0.0.0-20240701202509-2b217167d718 h1:lT7hE5k+0nkBdj/1UOSFwjWpNxf+LCApbRHgnCA17XE=
Expand Down
61 changes: 60 additions & 1 deletion testing/go/enginetest/query_converter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,32 @@ func convertTypeDef(columnType sqlparser.ColumnType) tree.ResolvableTypeReferenc
case "set":
panic(fmt.Sprintf("unhandled type: %s", columnType.Type))
case "bit":
panic(fmt.Sprintf("unhandled type: %s", columnType.Type))
// Support for MySQL BIT type conversion (dolt#9641)
// See: https://github.com/dolthub/dolt/issues/9641
// Map BIT types to appropriately sized integers for MySQL compatibility
width := int32FromSqlVal(columnType.Length)

var intOid oid.Oid
var intWidth int32
switch {
case width <= 16:
intOid = oid.T_int2
intWidth = 16
case width <= 32:
intOid = oid.T_int4
intWidth = 32
default:
intOid = oid.T_int8
intWidth = 64
}

return &types.T{
InternalType: types.InternalType{
Family: types.IntFamily,
Width: intWidth,
Oid: intOid,
},
}
case "json":
return &types.T{
InternalType: types.InternalType{
Expand Down Expand Up @@ -1568,3 +1593,37 @@ func TestBoolValSupport(t *testing.T) {
require.Contains(t, result[0], "CREATE TABLE", "Result should contain CREATE TABLE")
require.Contains(t, result[0], "false", "Result should contain converted boolean literal")
}

// TestBitTypeSupport tests that query converter can handle BIT types
// Related to dolt#9641: UNION queries with BIT fields need doltgres BIT type support
// See: https://github.com/dolthub/dolt/issues/9641
func TestBitTypeSupport(t *testing.T) {
// Test the exact table creation from the dolt#9641 regression test
// Before the fix: panics with "unhandled type: bit"
// After the fix: should convert successfully without panic, BIT(1) -> int2
result := convertQuery("CREATE TABLE bit_union_test_9641 (id INT PRIMARY KEY, flag BIT(1))")

// Should not panic and should return converted query
require.NotEmpty(t, result, "Query conversion should succeed and return converted SQL")
require.Len(t, result, 1, "Should return exactly one converted statement")
require.Contains(t, result[0], "CREATE TABLE", "Result should contain CREATE TABLE")
// BIT(1) is now converted to SMALLINT for MySQL compatibility with 0/1 values
require.Contains(t, result[0], "SMALLINT", "Result should contain SMALLINT type conversion")

// Test BIT(8) conversion to integer
bitResult := convertQuery("CREATE TABLE bit_test (id INT PRIMARY KEY, data BIT(8))")
require.NotEmpty(t, bitResult, "BIT(8) query should convert successfully")
require.Contains(t, bitResult[0], "CREATE TABLE", "Result should contain CREATE TABLE")

// Test INSERT query with BIT values - this would also exercise BIT type handling
insertResult := convertQuery("INSERT INTO bit_union_test_9641 VALUES (1, 0), (2, 1)")
require.NotEmpty(t, insertResult, "INSERT query should convert successfully")
require.Len(t, insertResult, 1, "Should return exactly one INSERT statement")
require.Contains(t, insertResult[0], "INSERT INTO", "Result should contain INSERT")

// Test the exact UNION query from dolt#9641 that was causing the issue
unionResult := convertQuery("SELECT flag FROM bit_union_test_9641 WHERE id = 1 UNION SELECT NULL as flag")
require.NotEmpty(t, unionResult, "UNION query should convert successfully")
require.Len(t, unionResult, 1, "Should return exactly one UNION statement")
require.Contains(t, unionResult[0], "UNION", "Result should contain UNION")
}
Loading