Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: revise project operator field name #3274

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions internal/topo/operator/project_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ import (
)

type ProjectOp struct {
ColNames [][]string // list of [col, table]
AliasNames []string // list of alias name
ExprNames []string // list of expr name
ExceptNames []string // list of except name
WindowFuncNames map[string]ast.Field
ColNames [][]string // list of [col, table]
AliasNames []string // list of alias name
ExprNames []string // list of expr name
ExceptNames []string // list of except name
// OtherFieldNames store the field calculated by other operators, eg: window function
OtherFieldNames map[string]ast.Field
AllWildcard bool
WildcardEmitters map[string]bool
AliasFields ast.Fields
Expand Down Expand Up @@ -138,7 +139,7 @@ func (pp *ProjectOp) project(row xsql.RawRow, ve *xsql.ValuerEval) error {
// Do not set value during calculations

for _, f := range pp.ExprFields {
if _, ok := pp.WindowFuncNames[f.Name]; ok {
if _, ok := pp.OtherFieldNames[f.Name]; ok {
vi, _ := row.Value(f.Name, "")
pp.kvs = append(pp.kvs, f.Name, vi)
continue
Expand All @@ -159,7 +160,7 @@ func (pp *ProjectOp) project(row xsql.RawRow, ve *xsql.ValuerEval) error {
}
}
for _, f := range pp.AliasFields {
if _, ok := pp.WindowFuncNames[f.AName]; ok {
if _, ok := pp.OtherFieldNames[f.AName]; ok {
vi, _ := row.Value(f.AName, "")
pp.kvs = append(pp.kvs, f.AName, vi)
continue
Expand Down
8 changes: 6 additions & 2 deletions internal/topo/planner/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func buildOps(lp LogicalPlan, tp *topo.Topo, options *def.RuleOption, sources ma
case *OrderPlan:
op = Transform(&operator.OrderOp{SortFields: t.SortFields}, fmt.Sprintf("%d_order", newIndex), options)
case *ProjectPlan:
op = Transform(&operator.ProjectOp{ColNames: t.colNames, AliasNames: t.aliasNames, AliasFields: t.aliasFields, ExprFields: t.exprFields, ExceptNames: t.exceptNames, IsAggregate: t.isAggregate, AllWildcard: t.allWildcard, WildcardEmitters: t.wildcardEmitters, ExprNames: t.exprNames, SendMeta: t.sendMeta, LimitCount: t.limitCount, EnableLimit: t.enableLimit, WindowFuncNames: t.windowFuncNames}, fmt.Sprintf("%d_project", newIndex), options)
op = Transform(&operator.ProjectOp{ColNames: t.colNames, AliasNames: t.aliasNames, AliasFields: t.aliasFields, ExprFields: t.exprFields, ExceptNames: t.exceptNames, IsAggregate: t.isAggregate, AllWildcard: t.allWildcard, WildcardEmitters: t.wildcardEmitters, ExprNames: t.exprNames, SendMeta: t.sendMeta, LimitCount: t.limitCount, EnableLimit: t.enableLimit, OtherFieldNames: t.otherFieldNames}, fmt.Sprintf("%d_project", newIndex), options)
case *ProjectSetPlan:
op = Transform(&operator.ProjectSetOperator{SrfMapping: t.SrfMapping, LimitCount: t.limitCount, EnableLimit: t.enableLimit}, fmt.Sprintf("%d_projectset", newIndex), options)
case *WindowFuncPlan:
Expand Down Expand Up @@ -562,7 +562,7 @@ func createLogicalPlan(stmt *ast.SelectStatement, opt *def.RuleOption, store kv.
limitCount = int(stmt.Limit.(*ast.LimitExpr).LimitCount.Val)
}
p = ProjectPlan{
windowFuncNames: windowFuncFields,
otherFieldNames: packOtherField(windowFuncFields),
fields: fields,
isAggregate: xsql.WithAggFields(stmt),
sendMeta: opt.SendMetaToSink,
Expand Down Expand Up @@ -591,6 +591,10 @@ func createLogicalPlan(stmt *ast.SelectStatement, opt *def.RuleOption, store kv.
return optimize(p)
}

func packOtherField(windowFuncFields map[string]ast.Field) map[string]ast.Field {
return windowFuncFields
}

// extractSRFMapping extracts the set-returning-function in the field
func extractSRFMapping(stmt *ast.SelectStatement) map[string]struct{} {
m := make(map[string]struct{})
Expand Down
4 changes: 2 additions & 2 deletions internal/topo/planner/planner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ func Test_createLogicalPlan(t *testing.T) {
},
},
},
windowFuncNames: map[string]ast.Field{
otherFieldNames: map[string]ast.Field{
"index": {
Name: "row_number",
AName: "index",
Expand Down Expand Up @@ -449,7 +449,7 @@ func Test_createLogicalPlan(t *testing.T) {
},
},
},
windowFuncNames: map[string]ast.Field{
otherFieldNames: map[string]ast.Field{
"row_number": {
Name: "row_number",
Expr: &ast.Call{
Expand Down
6 changes: 3 additions & 3 deletions internal/topo/planner/projectPlan.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type ProjectPlan struct {
aliasNames []string
exprNames []string
exceptNames []string
windowFuncNames map[string]ast.Field
otherFieldNames map[string]ast.Field
wildcardEmitters map[string]bool
aliasFields ast.Fields
exprFields ast.Fields
Expand Down Expand Up @@ -68,8 +68,8 @@ func (p ProjectPlan) Init() *ProjectPlan {
}
p.baseLogicalPlan.self = &p
p.baseLogicalPlan.setPlanType(PROJECT)
if len(p.windowFuncNames) < 1 {
p.windowFuncNames = nil
if len(p.otherFieldNames) < 1 {
p.otherFieldNames = nil
}
return &p
}
Expand Down
Loading