snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
148
server/pkg/dal/optimization.go
Normal file
148
server/pkg/dal/optimization.go
Normal file
@@ -0,0 +1,148 @@
|
||||
package dal
|
||||
|
||||
import "fmt"
|
||||
|
||||
type (
|
||||
// opCost provides a general idea of expensive an operation is for a
|
||||
// specific pipeline step.
|
||||
//
|
||||
// dsSize provides a general idea of how large an underlaying dataset is.
|
||||
opCost int
|
||||
dsSize int
|
||||
|
||||
OpAnalysis struct {
|
||||
ScanCost opCost
|
||||
SearchCost opCost
|
||||
FilterCost opCost
|
||||
SortCost opCost
|
||||
|
||||
OutputSize dsSize
|
||||
}
|
||||
|
||||
ppStepWrap struct {
|
||||
step PipelineStep
|
||||
|
||||
parent *ppStepWrap
|
||||
child []*ppStepWrap
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
pipelineOptimizers = []func(Pipeline) (Pipeline, error){
|
||||
pipelineClobberSteps,
|
||||
}
|
||||
)
|
||||
|
||||
const (
|
||||
// operation computation indicators
|
||||
CostUnknown opCost = iota
|
||||
CostFree
|
||||
CostCheep
|
||||
CostAcceptable
|
||||
CostExpensive
|
||||
CostInfinite
|
||||
)
|
||||
|
||||
const (
|
||||
// dataset size indicators
|
||||
SizeUnknown dsSize = iota
|
||||
SizeTiny
|
||||
SizeSmall
|
||||
SizeMedium
|
||||
SizeLarge
|
||||
)
|
||||
|
||||
const (
|
||||
OpAnalysisIterate string = "iterate"
|
||||
OpAnalysisAggregate string = "aggregate"
|
||||
OpAnalysisJoin string = "join"
|
||||
)
|
||||
|
||||
// wrapPpSteps wraps the pipeline steps in a more processing friendly format
|
||||
// and returns a slice of leave nodes
|
||||
//
|
||||
// @todo the pipeline representation might change which will make this obsolete
|
||||
func wrapPpSteps(pp Pipeline) (leaves []*ppStepWrap) {
|
||||
ix := make(map[PipelineStep]*ppStepWrap)
|
||||
|
||||
for _, p := range pp {
|
||||
ix[p] = &ppStepWrap{step: p}
|
||||
}
|
||||
|
||||
for _, p := range pp {
|
||||
switch c := p.(type) {
|
||||
case *Aggregate:
|
||||
ix[p].child = append(ix[p].child, ix[c.rel])
|
||||
ix[c.rel].parent = ix[p]
|
||||
|
||||
case *Join:
|
||||
ix[p].child = append(ix[p].child, ix[c.relLeft])
|
||||
ix[c.relLeft].parent = ix[p]
|
||||
|
||||
ix[p].child = append(ix[p].child, ix[c.relRight])
|
||||
ix[c.relRight].parent = ix[p]
|
||||
|
||||
case *Link:
|
||||
ix[p].child = append(ix[p].child, ix[c.relLeft])
|
||||
ix[c.relLeft].parent = ix[p]
|
||||
|
||||
ix[p].child = append(ix[p].child, ix[c.relRight])
|
||||
ix[c.relRight].parent = ix[p]
|
||||
|
||||
case *Datasource:
|
||||
continue
|
||||
|
||||
default:
|
||||
panic(fmt.Errorf("impossible state: unknown pipeline step type %v", p))
|
||||
}
|
||||
}
|
||||
|
||||
for _, a := range ix {
|
||||
if len(a.child) == 0 {
|
||||
leaves = append(leaves, a)
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// unwrapPpSteps unwraps the wrapped pipeline step into the classic Pipeline
|
||||
//
|
||||
// @todo the pipeline representation might change which will make this obsolete
|
||||
func unwrapPpSteps(n *ppStepWrap, seen map[*ppStepWrap]bool) (out Pipeline) {
|
||||
for i, c := range n.child {
|
||||
switch s := n.step.(type) {
|
||||
case *Aggregate:
|
||||
s.rel = c.step
|
||||
s.RelSource = c.step.Identifier()
|
||||
case *Join:
|
||||
if i == 0 {
|
||||
s.relLeft = c.step
|
||||
s.RelLeft = c.step.Identifier()
|
||||
} else {
|
||||
s.relRight = c.step
|
||||
s.RelRight = c.step.Identifier()
|
||||
}
|
||||
case *Link:
|
||||
if i == 0 {
|
||||
s.relLeft = c.step
|
||||
s.RelLeft = c.step.Identifier()
|
||||
} else {
|
||||
s.relRight = c.step
|
||||
s.RelRight = c.step.Identifier()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @todo potentially cancancel sooner
|
||||
if !seen[n] {
|
||||
out = append(out, n.step)
|
||||
}
|
||||
seen[n] = true
|
||||
|
||||
if n.parent != nil {
|
||||
out = append(unwrapPpSteps(n.parent, seen), out...)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
Reference in New Issue
Block a user