Skip to content

Commit

Permalink
test: move InsertMapOfFixedStrArrayStr under build flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ernado committed May 24, 2022
1 parent 193e950 commit 3dd10d7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 50 deletions.
65 changes: 65 additions & 0 deletions query_raw_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
})
}
50 changes: 0 additions & 50 deletions query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down Expand Up @@ -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",
}
Expand Down Expand Up @@ -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",
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3dd10d7

Please sign in to comment.