mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
* performance counters * first cut of perf counters and system table fanout and a wire protocol * significantly refactored prometheus support; removed statsd and exprvar * removed node_id * put dax subquery test back * Change Translator.TranslateFieldIDs method to take a dax.TableKeyer There are a bunch of other calls to the Translator interface methods with currently take an `index string`, and those need to be converted to dax.TableKeyer as well. But I need to review each call, because in at least one place I noticed one being called with `result.Index` instead of with the qtbl available. And I don't yet know how those could be different. Co-authored-by: Travis Turner <travis@molecula.com>
144 lines
2.8 KiB
Go
144 lines
2.8 KiB
Go
package wireprotocol_test
|
|
|
|
import (
|
|
"bytes"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
"github.com/molecula/featurebase/v3/pql"
|
|
"github.com/molecula/featurebase/v3/sql3/parser"
|
|
"github.com/molecula/featurebase/v3/sql3/planner/types"
|
|
"github.com/molecula/featurebase/v3/wireprotocol"
|
|
)
|
|
|
|
func TestWireProtocol_Schema(t *testing.T) {
|
|
|
|
s := types.Schema{
|
|
&types.PlannerColumn{
|
|
ColumnName: "col1",
|
|
Type: parser.NewDataTypeID(),
|
|
},
|
|
&types.PlannerColumn{
|
|
ColumnName: "col2",
|
|
Type: parser.NewDataTypeInt(),
|
|
},
|
|
&types.PlannerColumn{
|
|
ColumnName: "col3",
|
|
Type: parser.NewDataTypeDecimal(4),
|
|
},
|
|
&types.PlannerColumn{
|
|
ColumnName: "col4",
|
|
Type: parser.NewDataTypeString(),
|
|
},
|
|
&types.PlannerColumn{
|
|
ColumnName: "col5",
|
|
Type: parser.NewDataTypeStringSet(),
|
|
},
|
|
&types.PlannerColumn{
|
|
ColumnName: "col6",
|
|
Type: parser.NewDataTypeIDSet(),
|
|
},
|
|
&types.PlannerColumn{
|
|
ColumnName: "col7",
|
|
Type: parser.NewDataTypeBool(),
|
|
},
|
|
&types.PlannerColumn{
|
|
ColumnName: "col8",
|
|
Type: parser.NewDataTypeTimestamp(),
|
|
},
|
|
}
|
|
|
|
b, err := wireprotocol.WriteSchema(s)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
rdr := bytes.NewReader(b)
|
|
_, err = wireprotocol.ExpectToken(rdr, wireprotocol.TOKEN_SCHEMA_INFO)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
sr, err := wireprotocol.ReadSchema(rdr)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if diff := cmp.Diff(s, sr); diff != "" {
|
|
t.Fatal(diff)
|
|
}
|
|
}
|
|
|
|
func TestWireProtocol_Row(t *testing.T) {
|
|
|
|
s := types.Schema{
|
|
&types.PlannerColumn{
|
|
ColumnName: "col1",
|
|
Type: parser.NewDataTypeID(),
|
|
},
|
|
&types.PlannerColumn{
|
|
ColumnName: "col2",
|
|
Type: parser.NewDataTypeInt(),
|
|
},
|
|
&types.PlannerColumn{
|
|
ColumnName: "col3",
|
|
Type: parser.NewDataTypeDecimal(4),
|
|
},
|
|
&types.PlannerColumn{
|
|
ColumnName: "col4",
|
|
Type: parser.NewDataTypeString(),
|
|
},
|
|
&types.PlannerColumn{
|
|
ColumnName: "col5",
|
|
Type: parser.NewDataTypeStringSet(),
|
|
},
|
|
&types.PlannerColumn{
|
|
ColumnName: "col6",
|
|
Type: parser.NewDataTypeIDSet(),
|
|
},
|
|
&types.PlannerColumn{
|
|
ColumnName: "col7",
|
|
Type: parser.NewDataTypeBool(),
|
|
},
|
|
&types.PlannerColumn{
|
|
ColumnName: "col8",
|
|
Type: parser.NewDataTypeTimestamp(),
|
|
},
|
|
}
|
|
|
|
r := types.Row{
|
|
int64(1),
|
|
int64(2),
|
|
pql.NewDecimal(123400, 4),
|
|
string("foo"),
|
|
[]string{"bar", "baz"},
|
|
[]int64{10, 20},
|
|
bool(false),
|
|
time.Now().UTC(),
|
|
}
|
|
|
|
b, err := wireprotocol.WriteRow(r, s)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
rdr := bytes.NewReader(b)
|
|
_, err = wireprotocol.ExpectToken(rdr, wireprotocol.TOKEN_ROW)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
rr, err := wireprotocol.ReadRow(rdr, s)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
opt := cmp.Comparer(func(x, y pql.Decimal) bool {
|
|
return x.EqualTo(y)
|
|
})
|
|
|
|
if diff := cmp.Diff(r, rr, opt); diff != "" {
|
|
t.Fatal(diff)
|
|
}
|
|
}
|