Skip to content

Commit 60e12a0

Browse files
Merge pull request #1567 from disq/fix/prevent-panic-on-slice-key
fix: Prevent panic on slice map keys
2 parents 81d3c10 + 81f3701 commit 60e12a0

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

lib/column/map.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,14 @@ func (col *Map) parse(t Type, tz *time.Location) (_ Interface, err error) {
8383
if col.values, err = Type(strings.TrimSpace(types[1])).Column(col.name, tz); err != nil {
8484
return nil, err
8585
}
86-
col.scanType = reflect.MapOf(
87-
col.keys.ScanType(),
88-
col.values.ScanType(),
89-
)
90-
return col, nil
86+
87+
if col.keys.ScanType().Comparable() {
88+
col.scanType = reflect.MapOf(
89+
col.keys.ScanType(),
90+
col.values.ScanType(),
91+
)
92+
return col, nil
93+
}
9194
}
9295
return nil, &UnsupportedColumnTypeError{
9396
t: t,

tests/issues/1565_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package issues
2+
3+
import (
4+
"context"
5+
"github.com/ClickHouse/clickhouse-go/v2/tests"
6+
"github.com/stretchr/testify/require"
7+
"testing"
8+
)
9+
10+
func TestIssue1565(t *testing.T) {
11+
ctx := context.Background()
12+
13+
conn, err := tests.GetConnection("issues", nil, nil, nil)
14+
require.NoError(t, err)
15+
defer conn.Close()
16+
17+
row := conn.QueryRow(ctx, "SELECT map(['success', 'failure'], [10, 5]) as value")
18+
require.ErrorContains(t, row.Err(), "clickhouse: unsupported column type")
19+
}

0 commit comments

Comments
 (0)