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

fix(lookup): table plan and update problem #2927

Merged
merged 2 commits into from
Jun 14, 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
3 changes: 2 additions & 1 deletion internal/processor/stream.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2023 EMQ Technologies Co., Ltd.
// Copyright 2021-2024 EMQ Technologies Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -160,6 +160,7 @@ func (p *StreamProcessor) RecoverLookupTable() (err error) {

func (p *StreamProcessor) execSave(stmt *ast.StreamStmt, statement string, replace bool) error {
if stmt.StreamType == ast.TypeTable && stmt.Options.KIND == ast.StreamKindLookup {
_ = lookup.DropInstance(string(stmt.Name))
log.Infof("Creating lookup table %s", stmt.Name)
err := lookup.CreateInstance(string(stmt.Name), stmt.Options.TYPE, stmt.Options)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion internal/topo/lookup/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ func DropInstance(name string) error {
return fmt.Errorf("lookup table %s is still in use, stop all using rules before dropping it", name)
}
delete(instances, name)
return nil
contextLogger := conf.Log
ctx := kctx.WithValue(kctx.Background(), kctx.LoggerKey, contextLogger)
return i.ls.Close(ctx)
} else {
return nil
}
Expand Down
16 changes: 6 additions & 10 deletions internal/topo/planner/lookupPlan.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2023 EMQ Technologies Co., Ltd.
// Copyright 2021-2024 EMQ Technologies Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -135,12 +135,14 @@ func (p *LookupPlan) validateAndExtractCondition() bool {
return false
}
kset[lref.Name] = struct{}{}
p.keys = append(p.keys, lref.Name)
p.valvars = append(p.valvars, rref)
} else if string(rref.StreamName) == strName {
if _, ok := kset[rref.Name]; ok {
return false
}
kset[rref.Name] = struct{}{}
p.keys = append(p.keys, rref.Name)
p.valvars = append(p.valvars, lref)
} else {
continue
Expand All @@ -151,6 +153,7 @@ func (p *LookupPlan) validateAndExtractCondition() bool {
return false
}
kset[lref.Name] = struct{}{}
p.keys = append(p.keys, lref.Name)
p.valvars = append(p.valvars, c.RHS)
} else {
continue
Expand All @@ -161,6 +164,7 @@ func (p *LookupPlan) validateAndExtractCondition() bool {
return false
}
kset[rref.Name] = struct{}{}
p.keys = append(p.keys, rref.Name)
p.valvars = append(p.valvars, c.LHS)
} else {
continue
Expand All @@ -169,15 +173,7 @@ func (p *LookupPlan) validateAndExtractCondition() bool {
continue
}
}
if len(kset) > 0 {
p.keys = make([]string, 0, len(kset))
for k := range kset {
p.keys = append(p.keys, k)
}
sort.Strings(p.keys)
return true
}
return false
return len(kset) > 0
}

// flatConditions flat the join condition. Only binary condition of EQ and AND are allowed
Expand Down
Loading