-
Notifications
You must be signed in to change notification settings - Fork 562
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v2.27.0 breaks compatibility with OrderedMap for inserts #1365
Comments
Hi @mdonkers Could you please share how does your (it can be anonymized) |
Hey Kuba, Thx for looking into this. Unfortunately our OrderedMap implementation is complex in that it allows wrapping other We're using a
Then for the
I'm expecting that |
Thanks @mdonkers . I will be looking into this week. |
@mdonkers that's very interesting case, because I got a reproducible example: package issues
import (
"context"
"testing"
"github.com/ClickHouse/clickhouse-go/v2/examples/clickhouse_api"
"github.com/ClickHouse/clickhouse-go/v2/tests"
"github.com/stretchr/testify/require"
)
func TestIssue1365(t *testing.T) {
ctx := context.Background()
conn, err := tests.GetConnection("issues", nil, nil, nil)
require.NoError(t, err)
defer conn.Close()
const ddl = `
CREATE TABLE test_1365 (
Col1 Map(LowCardinality(String), Tuple(Value String, Type Enum8('Empty' = 0, 'String' = 1, 'Bool' = 2, 'Int' = 3)))
) Engine MergeTree() ORDER BY tuple()
`
err = conn.Exec(ctx, ddl)
require.NoError(t, err)
defer conn.Exec(ctx, "DROP TABLE test_1365")
mapValue := map[string]string{
"Value": "value1",
"Type": "String",
}
om := clickhouse_api.OrderedMap{}
om.Put("key", mapValue)
batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_1365")
require.NoError(t, err)
require.NoError(t, batch.Append(om))
require.NoError(t, batch.Send())
} However, it fails regardless of the driver's version. I tried every minor version down till
then, this works when you pass
Could you please confirm, before my further investigation, that this error didn't exist for past driver versions? |
Sorry, just back from vacation. And thanks a lot for looking into this! We're currently using But I'm also very confused since I tried upgrading again (to the now released |
Thanks @mdonkers . It's interesting and would confirm my investigation. Please let me know if you are able to reproduce this again. |
Hi @jkaflik , Took a bit of effort, but managed to reproduce. And I understand the issue now (it's more complex than I initially thought). The problem doesn't surface with 'normal'
But I overlooked the When calling What happens now due to the changed code in #1350, is that the Hope this helps... |
(I couldn't initially get it reproduced since we have a |
@mdonkers thanks. That's a good piece of information. I will take a look on this tomorrow. |
@mdonkers, unfortunately (given the short amount of time), I couldn't be able to get this reproduced reliably. I will have a look after my vacation in two weeks. |
@jkaflik no worries! Just came back from vacation myself so I know the feeling with work piling up :-) |
@jkaflik Unfortunately the issue still exists in clickhouse-go v2.28.2. |
There you are : ) 1365_test.go: package issues
import (
"context"
"github.com/ClickHouse/clickhouse-go/v2/lib/column"
"github.com/ClickHouse/clickhouse-go/v2/tests"
"github.com/stretchr/testify/require"
"testing"
)
type T1365OrderedMap int
func (t *T1365OrderedMap) Put(k any, v any) {
if k == "K" && v == "V" {
*t = 0xDEDEDEAD
}
}
func (t *T1365OrderedMap) Iterator() column.MapIterator { return t }
func (t *T1365OrderedMap) Next() bool { *t++; return *t == 1 }
func (t *T1365OrderedMap) Key() any { return "K" }
func (t *T1365OrderedMap) Value() any { return "V" }
func TestIssue1365(t *testing.T) {
ctx := context.Background()
conn, err := tests.GetConnection("issues", nil, nil, nil)
require.NoError(t, err)
defer conn.Close()
const ddl = `
CREATE TABLE test_1365 (
Col1 Array(Map(String,String))
) Engine MergeTree() ORDER BY tuple()
`
err = conn.Exec(ctx, ddl)
require.NoError(t, err)
defer conn.Exec(ctx, "DROP TABLE test_1365")
batch, err := conn.PrepareBatch(ctx, "INSERT INTO test_1365")
require.NoError(t, err)
var writeMaps []column.IterableOrderedMap
writeMaps = append(writeMaps, new(T1365OrderedMap))
writeMaps = append(writeMaps, new(T1365OrderedMap))
err = batch.Append(writeMaps)
require.NoError(t, err)
err = batch.Send()
require.NoError(t, err)
rows, err := conn.Query(ctx, "SELECT * FROM test_1365")
require.NoError(t, err)
require.True(t, rows.Next())
//var readMaps []*T1365OrderedMap
//
//err = rows.Scan(&readMaps)
//require.NoError(t, err)
} Works with |
#1350 feels weird, but the array handling approach itself feels even weirder... Normally, when you're scanning some deeply nested structures, when you encounter a slice, you just iterate over it and recurse to your top-level type dispatcher. But here, array nesting |
There you are. |
Observed
v2.26.0
tov2.27.0
v2.26.0
and everything works fine again.(suspecting #1350 for the change)
We're using an implementation of
OrderedMap
(clickhouse-go/lib/column/map.go
Line 40 in 20fb591
Attributes
Map(LowCardinality(String), Tuple(Value
String,Type
Enum8('Empty' = 0, 'String' = 1, 'Bool' = 2, 'Int' = 3)))`Expected behaviour
Ordered map inserts work, also for nested types
Error log
See above
Details
See above
Environment
clickhouse-go
version: v2.27.0CREATE TABLE
statements for tables involved:The text was updated successfully, but these errors were encountered: