From 5d28c1db231ecc3019eacae2cb7055dc6f5010d3 Mon Sep 17 00:00:00 2001 From: Adam Yeats Date: Fri, 7 Jun 2024 18:10:32 +0100 Subject: [PATCH] Temporarily patch converters to fix support for LowCardinality strings --- pkg/converters/converters.go | 12 ++++++++++++ pkg/plugin/driver_test.go | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/pkg/converters/converters.go b/pkg/converters/converters.go index b65dfd8b..c7825e5d 100644 --- a/pkg/converters/converters.go +++ b/pkg/converters/converters.go @@ -31,6 +31,7 @@ var matchRegexes = map[string]*regexp.Regexp{ "FixedString()": regexp.MustCompile(`^Nullable\(FixedString\(.*\)\)`), "IP": regexp.MustCompile(`^IPv[4,6]`), "LowCardinality()": regexp.MustCompile(`^LowCardinality\(([^)]*)\)`), + "LowCardinality(Nullable)": regexp.MustCompile(`^LowCardinality\(Nullable([^)]*)\)`), "Map()": regexp.MustCompile(`^Map\(.*\)`), "Nested()": regexp.MustCompile(`^Nested\(.*\)`), "Nullable(Date)": regexp.MustCompile(`^Nullable\(Date\(?`), @@ -258,6 +259,17 @@ var Converters = map[string]Converter{ matchRegex: matchRegexes["Point"], scanType: reflect.TypeOf((*interface{})(nil)).Elem(), }, + // // This is a temporary solution to handle LowCardinality types. + // // We'll need to add support for LowCardinality types to `sqlutil` package. + "LowCardinality(String)": { + fieldType: data.FieldTypeString, + scanType: reflect.PointerTo(reflect.TypeOf("")), + }, + "LowCardinality(Nullable(String))": { + fieldType: data.FieldTypeNullableString, + matchRegex: matchRegexes["LowCardinality(Nullable)"], + scanType: reflect.PointerTo(reflect.PointerTo(reflect.TypeOf(""))), + }, } var ClickhouseConverters = ClickHouseConverters() diff --git a/pkg/plugin/driver_test.go b/pkg/plugin/driver_test.go index 41f5ca99..b8cd6b1d 100644 --- a/pkg/plugin/driver_test.go +++ b/pkg/plugin/driver_test.go @@ -958,6 +958,18 @@ func TestLowCardinalityString(t *testing.T) { } } +func TestLowCardinalityNullableString(t *testing.T) { + for name, protocol := range Protocols { + t.Run(fmt.Sprintf("using %s", name), func(t *testing.T) { + conn, close := setupTest(t, "col1 LowCardinality(Nullable(String))", protocol, nil) + defer close(t) + val := "53" + insertData(t, conn, val) + checkRows(t, conn, 1, &val) + }) + } +} + func TestConvertDate32(t *testing.T) { conn := setupConnection(t, clickhouse_sql.Native, nil) canTest, err := plugin.CheckMinServerVersion(conn, 22, 3, 0)