Fix pkg/dal tests
This commit is contained in:
parent
625d4c2e0f
commit
3f15fa2a82
@ -80,9 +80,11 @@ func (def *Aggregate) init(ctx context.Context) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
def.filter, err = toInternalFilter(def.Filter)
|
||||
if err != nil {
|
||||
return
|
||||
if def.Filter != nil {
|
||||
def.filter, err = toInternalFilter(def.Filter)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if len(def.SourceAttributes) == 0 {
|
||||
|
||||
@ -65,9 +65,11 @@ func (def *Datasource) init(ctx context.Context, s iterProvider) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
def.filter, err = toInternalFilter(def.Filter)
|
||||
if err != nil {
|
||||
return
|
||||
if def.Filter != nil {
|
||||
def.filter, err = toInternalFilter(def.Filter)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
iter, model, err := s(ctx, def.ModelRef, def.filter)
|
||||
|
||||
@ -100,6 +100,13 @@ func (def *Join) init(ctx context.Context) (err error) {
|
||||
def.OutAttributes = append(def.LeftAttributes, def.RightAttributes...)
|
||||
}
|
||||
|
||||
if def.Filter != nil {
|
||||
def.filter, err = toInternalFilter(def.Filter)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,8 @@ package dal
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/cortezaproject/corteza-server/pkg/filter"
|
||||
)
|
||||
|
||||
type (
|
||||
@ -17,8 +19,10 @@ type (
|
||||
RelRight string
|
||||
// @todo allow multiple link predicates; for now (for easier indexing)
|
||||
// only allow one (this is the same as we had before)
|
||||
On LinkPredicate
|
||||
Filter internalFilter
|
||||
On LinkPredicate
|
||||
// @todo consider splitting filter into left and right filter
|
||||
filter internalFilter
|
||||
Filter filter.Filter
|
||||
|
||||
OutLeftAttributes []AttributeMapping
|
||||
OutRightAttributes []AttributeMapping
|
||||
@ -104,6 +108,14 @@ func (def *Link) init(ctx context.Context) (err error) {
|
||||
if len(def.OutRightAttributes) == 0 {
|
||||
def.OutRightAttributes = def.RightAttributes
|
||||
}
|
||||
|
||||
if def.Filter != nil {
|
||||
def.filter, err = toInternalFilter(def.Filter)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
err = def.validate()
|
||||
if err != nil {
|
||||
return
|
||||
@ -116,7 +128,7 @@ func (def *Link) exec(ctx context.Context, left, right Iterator) (_ Iterator, er
|
||||
// @todo adjust the used exec based on other strategies when added
|
||||
exec := &linkLeft{
|
||||
def: *def,
|
||||
filter: def.Filter,
|
||||
filter: def.filter,
|
||||
leftSource: left,
|
||||
rightSource: right,
|
||||
}
|
||||
|
||||
@ -38,7 +38,9 @@ func benchmarkExecAggregate(b *testing.B, n int) {
|
||||
}
|
||||
|
||||
b.StartTimer()
|
||||
_, err := def.Initialize(ctx, buff)
|
||||
err := def.init(ctx)
|
||||
require.NoError(b, err)
|
||||
_, err = def.exec(ctx, buff)
|
||||
require.NoError(b, err)
|
||||
b.StopTimer()
|
||||
|
||||
|
||||
@ -458,9 +458,11 @@ func TestStepAggregate(t *testing.T) {
|
||||
sa.SourceAttributes = saToMapping(tc.sourceAttributes...)
|
||||
sa.Group = saToMapping(tc.group...)
|
||||
sa.OutAttributes = saToMapping(tc.outAttributes...)
|
||||
sa.Filter = tc.f
|
||||
sa.filter = tc.f
|
||||
|
||||
aa, err := sa.Initialize(ctx, b)
|
||||
err := sa.init(ctx)
|
||||
require.NoError(t, err)
|
||||
aa, err := sa.exec(ctx, b)
|
||||
require.NoError(t, err)
|
||||
|
||||
i := 0
|
||||
@ -509,7 +511,7 @@ func TestStepAggregate_cursorCollect_forward(t *testing.T) {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
|
||||
def := Aggregate{
|
||||
Filter: internalFilter{
|
||||
filter: internalFilter{
|
||||
orderBy: c.ss,
|
||||
},
|
||||
Group: saToMapping(c.group...),
|
||||
@ -557,7 +559,7 @@ func TestStepAggregate_cursorCollect_back(t *testing.T) {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
|
||||
def := Aggregate{
|
||||
Filter: internalFilter{
|
||||
filter: internalFilter{
|
||||
orderBy: c.ss,
|
||||
},
|
||||
Group: saToMapping(c.group...),
|
||||
@ -643,10 +645,12 @@ func TestStepAggregate_more(t *testing.T) {
|
||||
d.OutAttributes = saToMapping(tc.outAttributes...)
|
||||
d.SourceAttributes = saToMapping(tc.sourceAttributes...)
|
||||
for _, k := range tc.group {
|
||||
d.Filter.orderBy = append(d.Filter.orderBy, &filter.SortExpr{Column: k.ident})
|
||||
d.filter.orderBy = append(d.filter.orderBy, &filter.SortExpr{Column: k.ident})
|
||||
}
|
||||
|
||||
aa, err := d.Initialize(ctx, buff)
|
||||
err := d.init(ctx)
|
||||
require.NoError(t, err)
|
||||
aa, err := d.exec(ctx, buff)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.True(t, aa.Next(ctx))
|
||||
|
||||
@ -49,11 +49,12 @@ func benchmarkExecJoin_local(b *testing.B, n int) {
|
||||
OutAttributes: saToMapping(attrs...),
|
||||
LeftAttributes: saToMapping(la...),
|
||||
RightAttributes: saToMapping(fa...),
|
||||
Filter: internalFilter{orderBy: filter.SortExprSet{{Column: "f_k"}}},
|
||||
filter: internalFilter{orderBy: filter.SortExprSet{{Column: "f_k"}}},
|
||||
On: JoinPredicate{Left: "l_k", Right: "f_ref"},
|
||||
}
|
||||
|
||||
def.Initialize(ctx, l, f)
|
||||
def.init(ctx)
|
||||
def.exec(ctx, l, f)
|
||||
|
||||
l.Seek(ctx, 0)
|
||||
f.Seek(ctx, 0)
|
||||
|
||||
@ -427,12 +427,14 @@ func TestStepJoinLocal(t *testing.T) {
|
||||
OutAttributes: saToMapping(tc.outAttributes...),
|
||||
LeftAttributes: saToMapping(tc.leftAttributes...),
|
||||
RightAttributes: saToMapping(tc.rightAttributes...),
|
||||
Filter: tc.f,
|
||||
filter: tc.f,
|
||||
|
||||
plan: joinPlan{},
|
||||
}
|
||||
|
||||
xs, err := def.Initialize(ctx, l, f)
|
||||
err := def.init(ctx)
|
||||
require.NoError(t, err)
|
||||
xs, err := def.exec(ctx, l, f)
|
||||
require.NoError(t, err)
|
||||
|
||||
i := 0
|
||||
@ -480,7 +482,7 @@ func TestStepJoinLocal_cursorCollect_forward(t *testing.T) {
|
||||
|
||||
jj := &joinLeft{
|
||||
def: Join{
|
||||
Filter: internalFilter{
|
||||
filter: internalFilter{
|
||||
orderBy: c.ss,
|
||||
},
|
||||
OutAttributes: saToMapping(c.attrs...),
|
||||
@ -525,7 +527,7 @@ func TestStepJoinLocal_cursorCollect_back(t *testing.T) {
|
||||
|
||||
jj := &joinLeft{
|
||||
def: Join{
|
||||
Filter: internalFilter{
|
||||
filter: internalFilter{
|
||||
orderBy: c.ss,
|
||||
},
|
||||
OutAttributes: saToMapping(c.attrs...),
|
||||
@ -622,10 +624,12 @@ func TestStepJoinLocal_more(t *testing.T) {
|
||||
OutAttributes: saToMapping(tc.attributes...),
|
||||
LeftAttributes: saToMapping(tc.localAttributes...),
|
||||
RightAttributes: saToMapping(tc.foreignAttributes...),
|
||||
Filter: tc.f,
|
||||
filter: tc.f,
|
||||
}
|
||||
|
||||
xs, err := def.Initialize(ctx, l, f)
|
||||
err := def.init(ctx)
|
||||
require.NoError(t, err)
|
||||
xs, err := def.exec(ctx, l, f)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.True(t, xs.Next(ctx))
|
||||
|
||||
@ -52,11 +52,12 @@ func benchmarkExecLink_left(b *testing.B, n int) {
|
||||
OutRightAttributes: saToMapping(fattrs...),
|
||||
LeftAttributes: saToMapping(la...),
|
||||
RightAttributes: saToMapping(fa...),
|
||||
Filter: internalFilter{orderBy: filter.SortExprSet{{Column: "f_k"}}},
|
||||
filter: internalFilter{orderBy: filter.SortExprSet{{Column: "f_k"}}},
|
||||
On: LinkPredicate{Left: "l_k", Right: "f_ref"},
|
||||
}
|
||||
|
||||
def.Initialize(ctx, l, f)
|
||||
def.init(ctx)
|
||||
def.exec(ctx, l, f)
|
||||
|
||||
l.Seek(ctx, 0)
|
||||
f.Seek(ctx, 0)
|
||||
|
||||
@ -69,9 +69,9 @@ func TestStepLinkleft(t *testing.T) {
|
||||
},
|
||||
out: []simpleRow{
|
||||
{"l_pk": 1, "l_val": "l1 v1"},
|
||||
{"f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"l_pk": 2, "l_val": "l2 v1"},
|
||||
{"f_pk": 2, "f_fk": 2, "f_val": "f2 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 2, "f_fk": 2, "f_val": "f2 v1"},
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -94,12 +94,12 @@ func TestStepLinkleft(t *testing.T) {
|
||||
},
|
||||
out: []simpleRow{
|
||||
{"l_pk": 1, "l_val": "l1 v1"},
|
||||
{"f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"f_pk": 2, "f_fk": 1, "f_val": "f2 v1"},
|
||||
{"f_pk": 3, "f_fk": 1, "f_val": "f3 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 2, "f_fk": 1, "f_val": "f2 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 3, "f_fk": 1, "f_val": "f3 v1"},
|
||||
|
||||
{"l_pk": 2, "l_val": "l2 v1"},
|
||||
{"f_pk": 4, "f_fk": 2, "f_val": "f4 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 4, "f_fk": 2, "f_val": "f4 v1"},
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -121,7 +121,7 @@ func TestStepLinkleft(t *testing.T) {
|
||||
|
||||
out: []simpleRow{
|
||||
{"l_pk": 1, "l_val": "l1 v1"},
|
||||
{"f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -201,7 +201,7 @@ func TestStepLinkleft(t *testing.T) {
|
||||
|
||||
out: []simpleRow{
|
||||
{"l_pk": 1, "l_const": "c1", "l_val": "l1 v1"},
|
||||
{"f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
},
|
||||
|
||||
f: internalFilter{
|
||||
@ -229,7 +229,7 @@ func TestStepLinkleft(t *testing.T) {
|
||||
|
||||
out: []simpleRow{
|
||||
{"l_pk": 1, "l_const": "c1", "l_val": "l1 v1"},
|
||||
{"f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
},
|
||||
|
||||
f: internalFilter{
|
||||
@ -252,7 +252,7 @@ func TestStepLinkleft(t *testing.T) {
|
||||
},
|
||||
fIn: []simpleRow{
|
||||
{"f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"f_pk": 2, "f_fk": 2, "f_val": "f2 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 2, "f_fk": 2, "f_val": "f2 v1"},
|
||||
},
|
||||
|
||||
out: []simpleRow{},
|
||||
@ -284,7 +284,7 @@ func TestStepLinkleft(t *testing.T) {
|
||||
|
||||
out: []simpleRow{
|
||||
{"l_pk": 1, "l_const_a": "cac1", "l_const_b": "cbc1", "l_val": "l1 v1"},
|
||||
{"f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
},
|
||||
|
||||
f: internalFilter{
|
||||
@ -312,9 +312,9 @@ func TestStepLinkleft(t *testing.T) {
|
||||
|
||||
out: []simpleRow{
|
||||
{"l_pk": 1, "l_const_a": "cac1", "l_const_b": "cbc1", "l_val": "l1 v1"},
|
||||
{"f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"l_pk": 2, "l_const_a": "cac1", "l_const_b": "cbc2", "l_val": "l2 v1"},
|
||||
{"f_pk": 2, "f_fk": 2, "f_val": "f2 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 2, "f_fk": 2, "f_val": "f2 v1"},
|
||||
},
|
||||
|
||||
f: internalFilter{
|
||||
@ -341,9 +341,9 @@ func TestStepLinkleft(t *testing.T) {
|
||||
|
||||
out: []simpleRow{
|
||||
{"l_pk": 1, "l_val": "l1 v1"},
|
||||
{"f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"l_pk": 2, "l_val": "l2 v1"},
|
||||
{"f_pk": 2, "f_fk": 2, "f_val": "f2 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 2, "f_fk": 2, "f_val": "f2 v1"},
|
||||
},
|
||||
|
||||
f: internalFilter{
|
||||
@ -394,7 +394,7 @@ func TestStepLinkleft(t *testing.T) {
|
||||
|
||||
out: []simpleRow{
|
||||
{"l_pk": 2, "l_val": "l2 v1"},
|
||||
{"f_pk": 2, "f_fk": 2, "f_val": "f2 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 2, "f_fk": 2, "f_val": "f2 v1"},
|
||||
},
|
||||
|
||||
f: internalFilter{
|
||||
@ -421,7 +421,7 @@ func TestStepLinkleft(t *testing.T) {
|
||||
|
||||
out: []simpleRow{
|
||||
{"l_pk": 1, "l_val": "l1 v1"},
|
||||
{"f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
},
|
||||
|
||||
f: internalFilter{
|
||||
@ -454,7 +454,7 @@ func TestStepLinkleft(t *testing.T) {
|
||||
},
|
||||
out: []simpleRow{
|
||||
{"l_pk": 2, "l_val": "l2 v1"},
|
||||
{"f_pk": 4, "f_fk": 2, "f_val": "f4 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 4, "f_fk": 2, "f_val": "f4 v1"},
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -482,7 +482,7 @@ func TestStepLinkleft(t *testing.T) {
|
||||
},
|
||||
out: []simpleRow{
|
||||
{"l_pk": 2, "l_val": "l2 v1"},
|
||||
{"f_pk": 4, "f_fk": 2, "f_val": "f4 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 4, "f_fk": 2, "f_val": "f4 v1"},
|
||||
},
|
||||
},
|
||||
{
|
||||
@ -525,16 +525,21 @@ func TestStepLinkleft(t *testing.T) {
|
||||
}
|
||||
|
||||
def := Link{
|
||||
Ident: "foo",
|
||||
Ident: "foo",
|
||||
RelLeft: "left",
|
||||
RelRight: "right",
|
||||
|
||||
On: tc.linkPred,
|
||||
LeftAttributes: saToMapping(tc.leftAttributes...),
|
||||
RightAttributes: saToMapping(tc.rightAttributes...),
|
||||
OutLeftAttributes: saToMapping(tc.leftOutAttributes...),
|
||||
OutRightAttributes: saToMapping(tc.rightOutAttributes...),
|
||||
Filter: tc.f,
|
||||
filter: tc.f,
|
||||
}
|
||||
|
||||
xs, err := def.Initialize(ctx, l, f)
|
||||
err := def.init(ctx)
|
||||
require.NoError(t, err)
|
||||
xs, err := def.exec(ctx, l, f)
|
||||
require.NoError(t, err)
|
||||
|
||||
i := 0
|
||||
@ -599,7 +604,7 @@ func TestStepLinkleft_cursorCollect_forward(t *testing.T) {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
xs := &linkLeft{
|
||||
def: Link{
|
||||
Filter: internalFilter{
|
||||
filter: internalFilter{
|
||||
orderBy: c.ss,
|
||||
},
|
||||
LeftAttributes: saToMapping(c.leftAttrs...),
|
||||
@ -665,7 +670,7 @@ func TestStepLinkleft_cursorCollect_back(t *testing.T) {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
jj := &linkLeft{
|
||||
def: Link{
|
||||
Filter: internalFilter{
|
||||
filter: internalFilter{
|
||||
orderBy: c.ss,
|
||||
},
|
||||
LeftAttributes: saToMapping(c.leftAttrs...),
|
||||
@ -744,11 +749,11 @@ func TestStepLinkleft_more(t *testing.T) {
|
||||
|
||||
out1: []simpleRow{
|
||||
{"l_pk": 1, "l_val": "l1 v1"},
|
||||
{"f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 1, "f_fk": 1, "f_val": "f1 v1"},
|
||||
},
|
||||
out2: []simpleRow{
|
||||
{"l_pk": 2, "l_val": "l2 v1"},
|
||||
{"f_pk": 4, "f_fk": 2, "f_val": "f4 v1"},
|
||||
{"$sys.ref": "right", "f_pk": 4, "f_fk": 2, "f_val": "f4 v1"},
|
||||
},
|
||||
},
|
||||
}
|
||||
@ -767,16 +772,21 @@ func TestStepLinkleft_more(t *testing.T) {
|
||||
}
|
||||
|
||||
def := Link{
|
||||
Ident: "foo",
|
||||
Ident: "foo",
|
||||
RelLeft: "left",
|
||||
RelRight: "right",
|
||||
|
||||
On: tc.linkPred,
|
||||
LeftAttributes: saToMapping(tc.leftAttrs...),
|
||||
RightAttributes: saToMapping(tc.rightAttrs...),
|
||||
OutLeftAttributes: saToMapping(tc.outleftAttrs...),
|
||||
OutRightAttributes: saToMapping(tc.outrightAttrs...),
|
||||
Filter: tc.f,
|
||||
filter: tc.f,
|
||||
}
|
||||
|
||||
xs, err := def.Initialize(ctx, l, f)
|
||||
err := def.init(ctx)
|
||||
require.NoError(t, err)
|
||||
xs, err := def.exec(ctx, l, f)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.True(t, xs.Next(ctx))
|
||||
@ -810,8 +820,8 @@ func TestStepLinkleft_more(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func simpleToRow(in simpleRow) (out *row) {
|
||||
out = &row{}
|
||||
func simpleToRow(in simpleRow) (out *Row) {
|
||||
out = &Row{}
|
||||
for k, v := range in {
|
||||
out.SetValue(k, 0, v)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user