-
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 #108 from go-faster/feat/col-point
feat(proto): support Point
- Loading branch information
Showing
7 changed files
with
219 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -130,6 +130,7 @@ q := ch.Query{ | |
* Bool | ||
* Tuple(T1, T2, ..., Tn) | ||
* Nullable(T) | ||
* Point | ||
|
||
## Generics | ||
|
||
|
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,50 @@ | ||
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 f0 3f |...............?| | ||
00000010 00 00 00 00 00 00 00 40 00 00 00 00 00 00 08 40 |.......@.......@| | ||
00000020 00 00 00 00 00 00 10 40 00 00 00 00 00 00 14 40 |.......@.......@| | ||
00000030 00 00 00 00 00 00 18 40 00 00 00 00 00 00 1c 40 |.......@.......@| | ||
00000040 00 00 00 00 00 00 20 40 00 00 00 00 00 00 22 40 |...... @......"@| | ||
00000050 00 00 00 00 00 00 24 40 00 00 00 00 00 00 26 40 |......$@......&@| | ||
00000060 00 00 00 00 00 00 28 40 00 00 00 00 00 00 2a 40 |......(@......*@| | ||
00000070 00 00 00 00 00 00 2c 40 00 00 00 00 00 00 2e 40 |......,@.......@| | ||
00000080 00 00 00 00 00 00 30 40 00 00 00 00 00 00 31 40 |[email protected]@| | ||
00000090 00 00 00 00 00 00 32 40 00 00 00 00 00 00 33 40 |[email protected]@| | ||
000000a0 00 00 00 00 00 00 34 40 00 00 00 00 00 00 35 40 |[email protected]@| | ||
000000b0 00 00 00 00 00 00 36 40 00 00 00 00 00 00 37 40 |[email protected]@| | ||
000000c0 00 00 00 00 00 00 38 40 00 00 00 00 00 00 39 40 |[email protected]@| | ||
000000d0 00 00 00 00 00 00 3a 40 00 00 00 00 00 00 3b 40 |......:@......;@| | ||
000000e0 00 00 00 00 00 00 3c 40 00 00 00 00 00 00 3d 40 |......<@......=@| | ||
000000f0 00 00 00 00 00 00 3e 40 00 00 00 00 00 00 3f 40 |......>@......?@| | ||
00000100 00 00 00 00 00 00 40 40 00 00 00 00 00 80 40 40 |......@@......@@| | ||
00000110 00 00 00 00 00 00 41 40 00 00 00 00 00 80 41 40 |[email protected]@| | ||
00000120 00 00 00 00 00 00 42 40 00 00 00 00 00 80 42 40 |[email protected]@| | ||
00000130 00 00 00 00 00 00 43 40 00 00 00 00 00 80 43 40 |[email protected]@| | ||
00000140 00 00 00 00 00 00 44 40 00 00 00 00 00 80 44 40 |[email protected]@| | ||
00000150 00 00 00 00 00 00 45 40 00 00 00 00 00 80 45 40 |[email protected]@| | ||
00000160 00 00 00 00 00 00 46 40 00 00 00 00 00 80 46 40 |[email protected]@| | ||
00000170 00 00 00 00 00 00 47 40 00 00 00 00 00 80 47 40 |[email protected]@| | ||
00000180 00 00 00 00 00 00 48 40 00 00 00 00 00 80 48 40 |[email protected]@| | ||
00000190 00 00 00 00 00 00 00 80 00 00 00 00 00 00 f0 bf |................| | ||
000001a0 00 00 00 00 00 00 00 c0 00 00 00 00 00 00 08 c0 |................| | ||
000001b0 00 00 00 00 00 00 10 c0 00 00 00 00 00 00 14 c0 |................| | ||
000001c0 00 00 00 00 00 00 18 c0 00 00 00 00 00 00 1c c0 |................| | ||
000001d0 00 00 00 00 00 00 20 c0 00 00 00 00 00 00 22 c0 |...... .......".| | ||
000001e0 00 00 00 00 00 00 24 c0 00 00 00 00 00 00 26 c0 |......$.......&.| | ||
000001f0 00 00 00 00 00 00 28 c0 00 00 00 00 00 00 2a c0 |......(.......*.| | ||
00000200 00 00 00 00 00 00 2c c0 00 00 00 00 00 00 2e c0 |......,.........| | ||
00000210 00 00 00 00 00 00 30 c0 00 00 00 00 00 00 31 c0 |......0.......1.| | ||
00000220 00 00 00 00 00 00 32 c0 00 00 00 00 00 00 33 c0 |......2.......3.| | ||
00000230 00 00 00 00 00 00 34 c0 00 00 00 00 00 00 35 c0 |......4.......5.| | ||
00000240 00 00 00 00 00 00 36 c0 00 00 00 00 00 00 37 c0 |......6.......7.| | ||
00000250 00 00 00 00 00 00 38 c0 00 00 00 00 00 00 39 c0 |......8.......9.| | ||
00000260 00 00 00 00 00 00 3a c0 00 00 00 00 00 00 3b c0 |......:.......;.| | ||
00000270 00 00 00 00 00 00 3c c0 00 00 00 00 00 00 3d c0 |......<.......=.| | ||
00000280 00 00 00 00 00 00 3e c0 00 00 00 00 00 00 3f c0 |......>.......?.| | ||
00000290 00 00 00 00 00 00 40 c0 00 00 00 00 00 80 40 c0 |......@.......@.| | ||
000002a0 00 00 00 00 00 00 41 c0 00 00 00 00 00 80 41 c0 |......A.......A.| | ||
000002b0 00 00 00 00 00 00 42 c0 00 00 00 00 00 80 42 c0 |......B.......B.| | ||
000002c0 00 00 00 00 00 00 43 c0 00 00 00 00 00 80 43 c0 |......C.......C.| | ||
000002d0 00 00 00 00 00 00 44 c0 00 00 00 00 00 80 44 c0 |......D.......D.| | ||
000002e0 00 00 00 00 00 00 45 c0 00 00 00 00 00 80 45 c0 |......E.......E.| | ||
000002f0 00 00 00 00 00 00 46 c0 00 00 00 00 00 80 46 c0 |......F.......F.| | ||
00000300 00 00 00 00 00 00 47 c0 00 00 00 00 00 80 47 c0 |......G.......G.| | ||
00000310 00 00 00 00 00 00 48 c0 00 00 00 00 00 80 48 c0 |......H.......H.| |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package proto | ||
|
||
import "github.com/go-faster/errors" | ||
|
||
type Point struct { | ||
X, Y float64 | ||
} | ||
|
||
// Compile-time assertions for ColPoint. | ||
var ( | ||
_ ColInput = ColPoint{} | ||
_ ColResult = (*ColPoint)(nil) | ||
_ Column = (*ColPoint)(nil) | ||
_ ColumnOf[Point] = (*ColPoint)(nil) | ||
) | ||
|
||
type ColPoint struct { | ||
X, Y ColFloat64 | ||
} | ||
|
||
func (c *ColPoint) Append(v Point) { | ||
c.X.Append(v.X) | ||
c.Y.Append(v.Y) | ||
} | ||
|
||
func (c *ColPoint) AppendArr(v []Point) { | ||
for _, vv := range v { | ||
c.Append(vv) | ||
} | ||
} | ||
|
||
func (c ColPoint) Row(i int) Point { | ||
return Point{ | ||
X: c.X.Row(i), | ||
Y: c.Y.Row(i), | ||
} | ||
} | ||
|
||
func (c ColPoint) Type() ColumnType { return ColumnTypePoint } | ||
func (c ColPoint) Rows() int { return c.X.Rows() } | ||
|
||
func (c *ColPoint) DecodeColumn(r *Reader, rows int) error { | ||
if err := c.X.DecodeColumn(r, rows); err != nil { | ||
return errors.Wrap(err, "x") | ||
} | ||
if err := c.Y.DecodeColumn(r, rows); err != nil { | ||
return errors.Wrap(err, "y") | ||
} | ||
return nil | ||
} | ||
|
||
func (c *ColPoint) Reset() { | ||
c.X.Reset() | ||
c.Y.Reset() | ||
} | ||
|
||
func (c ColPoint) EncodeColumn(b *Buffer) { | ||
if b == nil { | ||
return | ||
} | ||
c.X.EncodeColumn(b) | ||
c.Y.EncodeColumn(b) | ||
} |
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,64 @@ | ||
package proto | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/go-faster/ch/internal/gold" | ||
) | ||
|
||
func TestColPoint(t *testing.T) { | ||
t.Parallel() | ||
const rows = 50 | ||
var data ColPoint | ||
for i := 0; i < rows; i++ { | ||
v := Point{ | ||
X: float64(i), | ||
Y: -float64(i), | ||
} | ||
data.Append(v) | ||
require.Equal(t, v, data.Row(i)) | ||
} | ||
|
||
var buf Buffer | ||
data.EncodeColumn(&buf) | ||
t.Run("Golden", func(t *testing.T) { | ||
t.Parallel() | ||
gold.Bytes(t, buf.Buf, "col_point") | ||
}) | ||
t.Run("Ok", func(t *testing.T) { | ||
br := bytes.NewReader(buf.Buf) | ||
r := NewReader(br) | ||
|
||
var dec ColPoint | ||
require.NoError(t, dec.DecodeColumn(r, rows)) | ||
require.Equal(t, data, dec) | ||
require.Equal(t, rows, dec.Rows()) | ||
dec.Reset() | ||
require.Equal(t, 0, dec.Rows()) | ||
require.Equal(t, ColumnTypePoint, dec.Type()) | ||
}) | ||
t.Run("ZeroRows", func(t *testing.T) { | ||
r := NewReader(bytes.NewReader(nil)) | ||
|
||
var dec ColPoint | ||
require.NoError(t, dec.DecodeColumn(r, 0)) | ||
}) | ||
t.Run("ErrUnexpectedEOF", func(t *testing.T) { | ||
r := NewReader(bytes.NewReader(nil)) | ||
|
||
var dec ColPoint | ||
require.ErrorIs(t, dec.DecodeColumn(r, rows), io.ErrUnexpectedEOF) | ||
}) | ||
t.Run("NoShortRead", func(t *testing.T) { | ||
var dec ColPoint | ||
requireNoShortRead(t, buf.Buf, colAware(&dec, rows)) | ||
}) | ||
t.Run("ZeroRowsEncode", func(t *testing.T) { | ||
var v ColPoint | ||
v.EncodeColumn(nil) // should be no-op | ||
}) | ||
} |
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