diff --git a/query_raw_test.go b/query_raw_test.go new file mode 100644 index 00000000..89a4a953 --- /dev/null +++ b/query_raw_test.go @@ -0,0 +1,65 @@ +//go:build (amd64 || arm64) && !purego + +package ch + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" + + "github.com/go-faster/ch/proto" +) + +func TestClient_Query_Raw(t *testing.T) { + ctx := context.Background() + t.Parallel() + + t.Run("InsertMapOfFixedStrArrayStr", func(t *testing.T) { + t.Parallel() + conn := Conn(t) + createTable := Query{ + Body: "CREATE TABLE test_table (v Map(FixedString(16), Array(String))) ENGINE = TinyLog", + } + require.NoError(t, conn.Do(ctx, createTable), "create table") + + type K = [16]byte + data := &proto.ColMapOf[K, []string]{ + Keys: new(proto.ColRawOf[K]), + Values: new(proto.ColStr).Array(), + } + data.AppendArr([]map[K][]string{ + { + K{1: 123, 2: 4}: []string{"Hello", "World"}, + }, + { + K{1: 124, 2: 3}: []string{"Hi"}, + K{1: 124, 2: 1}: []string{"Hello"}, + }, + }) + + insertQuery := Query{ + Body: "INSERT INTO test_table VALUES", + Input: []proto.InputColumn{ + {Name: "v", Data: data}, + }, + } + require.NoError(t, conn.Do(ctx, insertQuery), "insert") + + gotData := &proto.ColMapOf[K, []string]{ + Keys: new(proto.ColRawOf[K]), + Values: new(proto.ColStr).Array(), + } + selectData := Query{ + Body: "SELECT * FROM test_table", + Result: proto.Results{ + {Name: "v", Data: gotData}, + }, + } + require.NoError(t, conn.Do(ctx, selectData), "select") + require.Equal(t, data.Rows(), gotData.Rows()) + for i := 0; i < data.Rows(); i++ { + require.Equal(t, data.Row(i), gotData.Row(i)) + } + }) +} diff --git a/query_test.go b/query_test.go index 7ba82d72..2431ffc8 100644 --- a/query_test.go +++ b/query_test.go @@ -25,7 +25,6 @@ func TestClient_Query(t *testing.T) { t.Parallel() conn := Conn(t) - createTable := Query{ Body: "CREATE TABLE test_table (id UInt8) ENGINE = MergeTree ORDER BY id", } @@ -55,7 +54,6 @@ func TestClient_Query(t *testing.T) { t.Parallel() conn := Conn(t) - createTable := Query{ Body: "CREATE TABLE test_table (id UInt8) ENGINE = MergeTree ORDER BY id", } @@ -156,7 +154,6 @@ func TestClient_Query(t *testing.T) { t.Parallel() conn := Conn(t) - createTable := Query{ Body: "CREATE TABLE test_table (id UInt8) ENGINE = TinyLog", } @@ -764,53 +761,6 @@ func TestClient_Query(t *testing.T) { require.Equal(t, data.Row(i), gotData.Row(i)) } }) - t.Run("InsertMapOfFixedStrArrayStr", func(t *testing.T) { - t.Parallel() - conn := Conn(t) - createTable := Query{ - Body: "CREATE TABLE test_table (v Map(FixedString(16), Array(String))) ENGINE = TinyLog", - } - require.NoError(t, conn.Do(ctx, createTable), "create table") - - type K = [16]byte - data := &proto.ColMapOf[K, []string]{ - Keys: new(proto.ColRawOf[K]), - Values: new(proto.ColStr).Array(), - } - data.AppendArr([]map[K][]string{ - { - K{1: 123, 2: 4}: []string{"Hello", "World"}, - }, - { - K{1: 124, 2: 3}: []string{"Hi"}, - K{1: 124, 2: 1}: []string{"Hello"}, - }, - }) - - insertQuery := Query{ - Body: "INSERT INTO test_table VALUES", - Input: []proto.InputColumn{ - {Name: "v", Data: data}, - }, - } - require.NoError(t, conn.Do(ctx, insertQuery), "insert") - - gotData := &proto.ColMapOf[K, []string]{ - Keys: new(proto.ColRawOf[K]), - Values: new(proto.ColStr).Array(), - } - selectData := Query{ - Body: "SELECT * FROM test_table", - Result: proto.Results{ - {Name: "v", Data: gotData}, - }, - } - require.NoError(t, conn.Do(ctx, selectData), "select") - require.Equal(t, data.Rows(), gotData.Rows()) - for i := 0; i < data.Rows(); i++ { - require.Equal(t, data.Row(i), gotData.Row(i)) - } - }) } func TestClientCompression(t *testing.T) {