mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
Renamed Query to Opt; added multiple Opt test
This commit is contained in:
parent
45abad5147
commit
465028e9c3
3 changed files with 42 additions and 11 deletions
2
api.go
2
api.go
|
|
@ -121,7 +121,7 @@ func (api *API) Query(ctx context.Context, req *QueryRequest) (QueryResponse, er
|
|||
|
||||
// Fill column attributes if requested.
|
||||
// execOpts.ColumnAttrs and execOpts.ExcludeColumns are out params from api.server.executor.Execute
|
||||
if execOpts.ColumnAttrs && !execOpts.ExcludeColumns {
|
||||
if execOpts.ColumnAttrs {
|
||||
// Consolidate all column ids across all calls.
|
||||
var columnIDs []uint64
|
||||
for _, result := range results {
|
||||
|
|
|
|||
|
|
@ -194,8 +194,8 @@ func (e *executor) executeCall(ctx context.Context, index string, c *pql.Call, s
|
|||
case "TopN":
|
||||
e.Holder.Stats.CountWithCustomTags(c.Name, 1, 1.0, []string{indexTag})
|
||||
return e.executeTopN(ctx, index, c, shards, opt)
|
||||
case "Query":
|
||||
return e.executeQueryCall(ctx, index, c, shards, opt)
|
||||
case "Opt":
|
||||
return e.executeOptCall(ctx, index, c, shards, opt)
|
||||
default:
|
||||
e.Holder.Stats.CountWithCustomTags(c.Name, 1, 1.0, []string{indexTag})
|
||||
return e.executeBitmapCall(ctx, index, c, shards, opt)
|
||||
|
|
@ -221,7 +221,7 @@ func (e *executor) validateCallArgs(c *pql.Call) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (e *executor) executeQueryCall(ctx context.Context, index string, c *pql.Call, shards []uint64, opt *execOptions) (interface{}, error) {
|
||||
func (e *executor) executeOptCall(ctx context.Context, index string, c *pql.Call, shards []uint64, opt *execOptions) (interface{}, error) {
|
||||
optCopy := &execOptions{}
|
||||
*optCopy = *opt
|
||||
if arg, ok := c.Args["columnAttrs"]; ok {
|
||||
|
|
@ -234,7 +234,6 @@ func (e *executor) executeQueryCall(ctx context.Context, index string, c *pql.Ca
|
|||
if arg, ok := c.Args["excludeRowAttrs"]; ok {
|
||||
if value, ok := arg.(bool); ok {
|
||||
optCopy.ExcludeRowAttrs = value
|
||||
opt.ExcludeRowAttrs = value
|
||||
} else {
|
||||
return nil, errors.New("Query(): excludeRowAttrs must be a bool")
|
||||
}
|
||||
|
|
@ -242,7 +241,6 @@ func (e *executor) executeQueryCall(ctx context.Context, index string, c *pql.Ca
|
|||
if arg, ok := c.Args["excludeColumns"]; ok {
|
||||
if value, ok := arg.(bool); ok {
|
||||
optCopy.ExcludeColumns = value
|
||||
opt.ExcludeColumns = value
|
||||
} else {
|
||||
return nil, errors.New("Query(): excludeColumns must be a bool")
|
||||
}
|
||||
|
|
@ -261,7 +259,6 @@ func (e *executor) executeQueryCall(ctx context.Context, index string, c *pql.Ca
|
|||
} else {
|
||||
return nil, errors.New("Query(): shards must be a list of unsigned integers")
|
||||
}
|
||||
|
||||
}
|
||||
return e.executeCall(ctx, index, c.Children[0], shards, optCopy)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1371,7 +1371,7 @@ func TestExecutor_QueryCall(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if res, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `Query(Row(f=10), excludeRowAttrs=true)`}); err != nil {
|
||||
if res, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `Opt(Row(f=10), excludeRowAttrs=true)`}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if bits := res.Results[0].(*pilosa.Row).Columns(); !reflect.DeepEqual(bits, []uint64{100}) {
|
||||
t.Fatalf("unexpected columns: %+v", bits)
|
||||
|
|
@ -1397,7 +1397,7 @@ func TestExecutor_QueryCall(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if res, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `Query(Row(f=10), excludeColumns=true)`}); err != nil {
|
||||
if res, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `Opt(Row(f=10), excludeColumns=true)`}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if bits := res.Results[0].(*pilosa.Row).Columns(); !reflect.DeepEqual(bits, []uint64{}) {
|
||||
t.Fatalf("unexpected columns: %+v", bits)
|
||||
|
|
@ -1427,7 +1427,7 @@ func TestExecutor_QueryCall(t *testing.T) {
|
|||
{ID: 100, Attrs: map[string]interface{}{"foo": "bar"}},
|
||||
}
|
||||
|
||||
if res, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `Query(Row(f=10), columnAttrs=true)`}); err != nil {
|
||||
if res, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `Opt(Row(f=10), columnAttrs=true)`}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if bits := res.Results[0].(*pilosa.Row).Columns(); !reflect.DeepEqual(bits, []uint64{100}) {
|
||||
t.Fatalf("unexpected columns: %+v", bits)
|
||||
|
|
@ -1454,10 +1454,44 @@ func TestExecutor_QueryCall(t *testing.T) {
|
|||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if res, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `Query(Row(f=10), shards=[0, 2])`}); err != nil {
|
||||
if res, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `Opt(Row(f=10), shards=[0, 2])`}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if bits := res.Results[0].(*pilosa.Row).Columns(); !reflect.DeepEqual(bits, []uint64{100, ShardWidth * 2}) {
|
||||
t.Fatalf("unexpected columns: %+v", bits)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("multipleOpt", func(t *testing.T) {
|
||||
c := test.MustRunCluster(t, 1)
|
||||
defer c.Close()
|
||||
hldr := test.Holder{Holder: c[0].Server.Holder()}
|
||||
|
||||
// Set columns for rows 0, 10, & 20 across two shards.
|
||||
if idx, err := hldr.CreateIndex("i", pilosa.IndexOptions{}); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if _, err := idx.CreateField("f", pilosa.OptFieldTypeDefault()); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if _, err := c[0].API.Query(context.Background(), &pilosa.QueryRequest{Index: "i", Query: `
|
||||
Set(100, f=10)
|
||||
SetRowAttrs(f, 10, foo="bar")
|
||||
`}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
req := &pilosa.QueryRequest{
|
||||
Index: "i",
|
||||
Query: `Opt(Row(f=10), excludeColumns=true)Opt(Row(f=10), excludeRowAttrs=true)`,
|
||||
}
|
||||
if res, err := c[0].API.Query(context.Background(), req); err != nil {
|
||||
t.Fatal(err)
|
||||
} else if bits := res.Results[0].(*pilosa.Row).Columns(); !reflect.DeepEqual(bits, []uint64{}) {
|
||||
t.Fatalf("unexpected columns: %+v", bits)
|
||||
} else if attrs := res.Results[0].(*pilosa.Row).Attrs; !reflect.DeepEqual(attrs, map[string]interface{}{"foo": "bar"}) {
|
||||
t.Fatalf("unexpected attrs: %s", spew.Sdump(attrs))
|
||||
} else if bits := res.Results[1].(*pilosa.Row).Columns(); !reflect.DeepEqual(bits, []uint64{100}) {
|
||||
t.Fatalf("unexpected columns: %+v", bits)
|
||||
} else if attrs := res.Results[1].(*pilosa.Row).Attrs; !reflect.DeepEqual(attrs, map[string]interface{}{}) {
|
||||
t.Fatalf("unexpected attrs: %s", spew.Sdump(attrs))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue