Skip to content

Commit

Permalink
Temporarily patch converters to fix support for LowCardinality strings
Browse files Browse the repository at this point in the history
  • Loading branch information
adamyeats committed Jul 9, 2024
1 parent 55e38ad commit 5d28c1d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/converters/converters.go
Original file line number Diff line number Diff line change
Expand Up @@ -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\(?`),
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions pkg/plugin/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5d28c1d

Please sign in to comment.