diff --git a/pkg/report/model.go b/pkg/report/model.go index fe0872a48..cae7124c2 100644 --- a/pkg/report/model.go +++ b/pkg/report/model.go @@ -21,6 +21,7 @@ type ( Run(context.Context) error Load(context.Context, ...*FrameDefinition) ([]*Frame, error) Describe(ctx context.Context, source string) (FrameDescriptionSet, error) + GetStep(name string) step } stepSet []step @@ -154,6 +155,17 @@ func (m *model) Describe(ctx context.Context, source string) (out FrameDescripti return ds.Describe(), nil } +// GetStep returns the details of the requested step +func (m *model) GetStep(name string) step { + for _, s := range m.steps { + if s.Name() == name { + return s + } + } + + return nil +} + // Load returns the Frames based on the provided FrameDefinitions // // The Run method must be called before the frames can be provided. diff --git a/system/service/report.go b/system/service/report.go index 4b5fb9c81..e85ce7797 100644 --- a/system/service/report.go +++ b/system/service/report.go @@ -2,6 +2,7 @@ package service import ( "context" + "fmt" "github.com/cortezaproject/corteza-server/pkg/actionlog" "github.com/cortezaproject/corteza-server/pkg/label" @@ -360,9 +361,14 @@ func (svc *report) RunFresh(ctx context.Context, src types.ReportDataSourceSet, continue } + stp := model.GetStep(d.Source) + if stp == nil { + return fmt.Errorf("unknown source: %s", d.Source) + } + // if the current source matches the prev. source, and they both define references, // they fall into the same chunk. - if (d.Source == dd[i-1].Source) && (d.Ref != "" && dd[i-1].Ref != "") { + if stp.Def().Join != nil && (d.Source == dd[i-1].Source) && (d.Ref != "" && dd[i-1].Ref != "") { auxdd = append(auxdd, d) continue } diff --git a/tests/reporter/7002_modeling_multi_ignored_ref_test.go b/tests/reporter/7002_modeling_multi_ignored_ref_test.go new file mode 100644 index 000000000..61a03c5ab --- /dev/null +++ b/tests/reporter/7002_modeling_multi_ignored_ref_test.go @@ -0,0 +1,28 @@ +package reporter + +import ( + "testing" + + "github.com/cortezaproject/corteza-server/pkg/report" +) + +func Test7002_modeling_multi_ignored_ref(t *testing.T) { + var ( + ctx, h, s = setup(t) + m, _, dd = loadScenario(ctx, s, t, h) + ff = loadNoErrMulti(ctx, h, m, dd...) + f *report.Frame + ) + + h.a.Len(ff, 2) + + f = ff[0] + h.a.Equal("f1", f.Name) + h.a.Equal("first_name, last_name", f.Columns.String()) + h.a.Len(f.Rows, 3) + + f = ff[1] + h.a.Equal("f2", f.Name) + h.a.Equal("first_name, last_name", f.Columns.String()) + h.a.Len(f.Rows, 1) +} diff --git a/tests/reporter/main_test.go b/tests/reporter/main_test.go index dc7cb61f6..6b98ada6d 100644 --- a/tests/reporter/main_test.go +++ b/tests/reporter/main_test.go @@ -4,6 +4,7 @@ import ( "context" "encoding/json" "errors" + "fmt" "io/ioutil" "os" "path" @@ -203,9 +204,14 @@ func loadNoErrMulti(ctx context.Context, h helper, m report.M, dd ...*report.Fra continue } + stp := m.GetStep(d.Source) + if stp == nil { + h.a.FailNow(fmt.Sprintf("unknown source: %s", d.Source)) + } + // if the current source matches the prev. source, and they both define references, // they fall into the same chunk. - if (d.Source == dd[i-1].Source) && (d.Ref != "" && dd[i-1].Ref != "") { + if stp.Def().Join != nil && (d.Source == dd[i-1].Source) && (d.Ref != "" && dd[i-1].Ref != "") { auxdd = append(auxdd, d) continue } diff --git a/tests/reporter/testdata/S7002_modeling_multi_ignored_ref/report.json b/tests/reporter/testdata/S7002_modeling_multi_ignored_ref/report.json new file mode 100644 index 000000000..202836355 --- /dev/null +++ b/tests/reporter/testdata/S7002_modeling_multi_ignored_ref/report.json @@ -0,0 +1,34 @@ +{ + "handle": "testing_report", + "sources": [ + { "step": { "load": { + "name": "users", + "source": "composeRecords", + "definition": { + "module": "user", + "namespace": "ns" + } + }}} + ], + "frames": [{ + "name": "f1", + "source": "users", + "ref": "users", + "columns": [ + { "name": "first_name", "label": "first_name" }, + { "name": "last_name", "label": "last_name" } + ], + "sort": "first_name ASC", + "filter": "first_name == 'Maria'" + }, { + "name": "f2", + "source": "users", + "ref": "users", + "columns": [ + { "name": "first_name", "label": "first_name" }, + { "name": "last_name", "label": "last_name" } + ], + "sort": "first_name ASC", + "filter": "first_name == 'Sascha'" + }] +}