Improve frame def. grouping logic based on model step
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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<String>, last_name<String>", f.Columns.String())
|
||||
h.a.Len(f.Rows, 3)
|
||||
|
||||
f = ff[1]
|
||||
h.a.Equal("f2", f.Name)
|
||||
h.a.Equal("first_name<String>, last_name<String>", f.Columns.String())
|
||||
h.a.Len(f.Rows, 1)
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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'"
|
||||
}]
|
||||
}
|
||||
Reference in New Issue
Block a user