-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #104 from go-faster/feat/col-map-of
feat(proto): implement Map(K, V)
- Loading branch information
Showing
7 changed files
with
179 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
00000000 02 00 00 00 00 00 00 00 05 00 00 00 00 00 00 00 |................| | ||
00000010 03 62 61 7a 03 66 6f 6f 07 64 69 73 6c 69 6b 65 |.baz.foo.dislike| | ||
00000020 04 6c 69 6b 65 06 72 65 73 75 6c 74 05 68 65 6c |.like.result.hel| | ||
00000030 6c 6f 03 62 61 72 03 32 30 30 03 31 30 30 08 31 |lo.bar.200.100.1| | ||
00000040 30 30 30 20 2d 20 37 |000 - 7| |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,61 @@ | ||
package proto | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/go-faster/ch/internal/gold" | ||
) | ||
|
||
func TestColMapOf(t *testing.T) { | ||
v := ColMapOf[string, string]{ | ||
Keys: &ColStr{}, | ||
Values: &ColStr{}, | ||
Keys: &ColStr{}, Values: &ColStr{}, | ||
} | ||
_, _ = v.Get("foo") | ||
require.Equal(t, ColumnType("Map(String, String)"), v.Type()) | ||
v.Append(map[string]string{ | ||
"foo": "bar", | ||
"baz": "hello", | ||
}) | ||
v.Append(map[string]string{ | ||
"like": "100", | ||
"dislike": "200", | ||
"result": "1000 - 7", | ||
}) | ||
const rows = 2 | ||
|
||
var buf Buffer | ||
v.EncodeColumn(&buf) | ||
|
||
t.Run("Golden", func(t *testing.T) { | ||
gold.Bytes(t, buf.Buf, "col_map_of_str_str") | ||
}) | ||
t.Run("Ok", func(t *testing.T) { | ||
br := bytes.NewReader(buf.Buf) | ||
r := NewReader(br) | ||
dec := &ColMapOf[string, string]{ | ||
Keys: &ColStr{}, Values: &ColStr{}, | ||
} | ||
require.NoError(t, dec.DecodeColumn(r, rows)) | ||
for i := 0; i < rows; i++ { | ||
require.Equal(t, v.Row(i), v.Row(i)) | ||
} | ||
dec.Reset() | ||
require.Equal(t, 0, dec.Rows()) | ||
}) | ||
t.Run("ErrUnexpectedEOF", func(t *testing.T) { | ||
r := NewReader(bytes.NewReader(nil)) | ||
dec := &ColMapOf[string, string]{ | ||
Keys: &ColStr{}, Values: &ColStr{}, | ||
} | ||
require.ErrorIs(t, dec.DecodeColumn(r, rows), io.ErrUnexpectedEOF) | ||
}) | ||
t.Run("NoShortRead", func(t *testing.T) { | ||
dec := &ColMapOf[string, string]{ | ||
Keys: &ColStr{}, Values: &ColStr{}, | ||
} | ||
requireNoShortRead(t, buf.Buf, colAware(dec, rows)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters