From 228a88787d40fabe21be126fa0c45a378d15d260 Mon Sep 17 00:00:00 2001 From: elianddb Date: Fri, 8 Aug 2025 21:49:40 +0000 Subject: [PATCH 1/6] add bit support and test --- go.mod | 2 +- go.sum | 2 + testing/go/enginetest/query_converter_test.go | 38 ++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/go.mod b/go.mod index 1709be421b..17df49b27b 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index b718734093..5dd5f8fbd8 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/testing/go/enginetest/query_converter_test.go b/testing/go/enginetest/query_converter_test.go index 7fd83d9e38..e5a3d9f42a 100644 --- a/testing/go/enginetest/query_converter_test.go +++ b/testing/go/enginetest/query_converter_test.go @@ -1120,7 +1120,15 @@ 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 to PostgreSQL BIT type (dolt#9641) + // See: https://github.com/dolthub/dolt/issues/9641 + return &types.T{ + InternalType: types.InternalType{ + Family: types.BitFamily, + Width: int32FromSqlVal(columnType.Length), + Oid: oid.T_bit, + }, + } case "json": return &types.T{ InternalType: types.InternalType{ @@ -1568,3 +1576,31 @@ 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 + 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") + require.Contains(t, result[0], "bit", "Result should contain BIT type conversion") + + // 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") +} From 1bacdc48117eeffa11a95a7b027add2ff7a070c8 Mon Sep 17 00:00:00 2001 From: elianddb Date: Fri, 8 Aug 2025 22:10:40 +0000 Subject: [PATCH 2/6] add bit map --- testing/go/enginetest/query_converter_test.go | 35 +++++++++++++++---- 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/testing/go/enginetest/query_converter_test.go b/testing/go/enginetest/query_converter_test.go index e5a3d9f42a..514df535b5 100644 --- a/testing/go/enginetest/query_converter_test.go +++ b/testing/go/enginetest/query_converter_test.go @@ -1120,13 +1120,30 @@ func convertTypeDef(columnType sqlparser.ColumnType) tree.ResolvableTypeReferenc case "set": panic(fmt.Sprintf("unhandled type: %s", columnType.Type)) case "bit": - // Support for MySQL BIT type conversion to PostgreSQL BIT type (dolt#9641) + // 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.BitFamily, - Width: int32FromSqlVal(columnType.Length), - Oid: oid.T_bit, + Family: types.IntFamily, + Width: intWidth, + Oid: intOid, }, } case "json": @@ -1583,14 +1600,20 @@ func TestBoolValSupport(t *testing.T) { 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 + // 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") - require.Contains(t, result[0], "bit", "Result should contain BIT type conversion") + // 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)") From 0b3434443c5f35faaabb18011c1a5e35b154f4ea Mon Sep 17 00:00:00 2001 From: elianddb Date: Fri, 8 Aug 2025 22:16:15 +0000 Subject: [PATCH 3/6] run fmt script --- testing/go/enginetest/query_converter_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testing/go/enginetest/query_converter_test.go b/testing/go/enginetest/query_converter_test.go index 514df535b5..5387a2323a 100644 --- a/testing/go/enginetest/query_converter_test.go +++ b/testing/go/enginetest/query_converter_test.go @@ -1124,7 +1124,7 @@ func convertTypeDef(columnType sqlparser.ColumnType) tree.ResolvableTypeReferenc // 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 { @@ -1138,7 +1138,7 @@ func convertTypeDef(columnType sqlparser.ColumnType) tree.ResolvableTypeReferenc intOid = oid.T_int8 intWidth = 64 } - + return &types.T{ InternalType: types.InternalType{ Family: types.IntFamily, From d01f2e7806ebf331f094074a03b32acc536118b1 Mon Sep 17 00:00:00 2001 From: elianddb Date: Mon, 11 Aug 2025 17:06:39 +0000 Subject: [PATCH 4/6] rm extra comments --- testing/go/enginetest/query_converter_test.go | 36 +++++++------------ 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/testing/go/enginetest/query_converter_test.go b/testing/go/enginetest/query_converter_test.go index 5387a2323a..476ce9f828 100644 --- a/testing/go/enginetest/query_converter_test.go +++ b/testing/go/enginetest/query_converter_test.go @@ -1594,36 +1594,26 @@ func TestBoolValSupport(t *testing.T) { 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 +// TestBitTypeSupport tests BIT type conversion for dolt#9641 compatibility // 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))") + require.NotEmpty(t, result) + require.Len(t, result, 1) + require.Contains(t, result[0], "CREATE TABLE") + require.Contains(t, result[0], "SMALLINT") - // 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") + require.NotEmpty(t, bitResult) + require.Contains(t, bitResult[0], "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") + require.NotEmpty(t, insertResult) + require.Len(t, insertResult, 1) + require.Contains(t, insertResult[0], "INSERT INTO") - // 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") + require.NotEmpty(t, unionResult) + require.Len(t, unionResult, 1) + require.Contains(t, unionResult[0], "UNION") } From 96a2aa828f929ed480a780c9085e636422f17633 Mon Sep 17 00:00:00 2001 From: elianddb Date: Mon, 11 Aug 2025 17:08:05 +0000 Subject: [PATCH 5/6] switch to if-else --- testing/go/enginetest/query_converter_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/testing/go/enginetest/query_converter_test.go b/testing/go/enginetest/query_converter_test.go index 476ce9f828..8be5f00127 100644 --- a/testing/go/enginetest/query_converter_test.go +++ b/testing/go/enginetest/query_converter_test.go @@ -1127,14 +1127,13 @@ func convertTypeDef(columnType sqlparser.ColumnType) tree.ResolvableTypeReferenc var intOid oid.Oid var intWidth int32 - switch { - case width <= 16: + if width <= 16 { intOid = oid.T_int2 intWidth = 16 - case width <= 32: + } else if width <= 32 { intOid = oid.T_int4 intWidth = 32 - default: + } else { intOid = oid.T_int8 intWidth = 64 } From b3f4aba96f517b08fbc9af478b6bccee1d009b15 Mon Sep 17 00:00:00 2001 From: elianddb Date: Mon, 11 Aug 2025 19:46:39 +0000 Subject: [PATCH 6/6] reset go.mod/sum --- go.mod | 2 +- go.sum | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/go.mod b/go.mod index 17df49b27b..1709be421b 100644 --- a/go.mod +++ b/go.mod @@ -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.20250808203856-b2556a731d9b + github.com/dolthub/go-mysql-server v0.20.1-0.20250807172251-c76b4ab0b9c8 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 diff --git a/go.sum b/go.sum index 5dd5f8fbd8..b718734093 100644 --- a/go.sum +++ b/go.sum @@ -285,8 +285,6 @@ 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=