/
with.go
48 lines (41 loc) · 1.26 KB
/
with.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package logical
import (
"context"
"github.com/cube2222/octosql/physical"
)
type With struct {
cteNames []string
cteNodes []Node
source Node
}
func NewWith(cteNames []string, cteNodes []Node, source Node) *With {
return &With{
cteNames: cteNames,
cteNodes: cteNodes,
source: source,
}
}
func (node *With) Typecheck(ctx context.Context, env physical.Environment, logicalEnv Environment) (physical.Node, map[string]string) {
newCTEs := make(map[string]CommonTableExpression)
for k, v := range logicalEnv.CommonTableExpressions {
newCTEs[k] = v
}
for i := range node.cteNodes {
cte, mapping := node.cteNodes[i].Typecheck(ctx, env, Environment{
CommonTableExpressions: newCTEs,
TableValuedFunctions: logicalEnv.TableValuedFunctions,
UniqueVariableNames: logicalEnv.UniqueVariableNames,
UniqueNameGenerator: logicalEnv.UniqueNameGenerator,
})
newCTEs[node.cteNames[i]] = CommonTableExpression{
Node: cte,
UniqueVariableMapping: mapping,
}
}
return node.source.Typecheck(ctx, env, Environment{
CommonTableExpressions: newCTEs,
TableValuedFunctions: logicalEnv.TableValuedFunctions,
UniqueVariableNames: logicalEnv.UniqueVariableNames,
UniqueNameGenerator: logicalEnv.UniqueNameGenerator,
})
}