Skip to content

Commit a43e24d

Browse files
committed
Bound() -> Nested(), etc
1 parent 2509106 commit a43e24d

File tree

5 files changed

+50
-50
lines changed

5 files changed

+50
-50
lines changed

src/link.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ struct LinkContext
1414
Base.ImmutableDict{Tuple{Symbol, Int}, Vector{SQLNode}}(),
1515
nothing)
1616

17-
LinkContext(ctx::LinkContext; refs = missing, cte_refs = missing, knot_refs = missing) =
17+
LinkContext(ctx::LinkContext; refs = ctx.refs, cte_refs = ctx.cte_refs, knot_refs = ctx.knot_refs) =
1818
new(ctx.dialect,
1919
ctx.defs,
20-
coalesce(refs, ctx.refs),
21-
coalesce(cte_refs, ctx.cte_refs),
22-
coalesce(knot_refs, ctx.knot_refs))
20+
refs,
21+
cte_refs,
22+
knot_refs)
2323
end
2424

2525
function link(n::SQLNode)
@@ -93,9 +93,9 @@ function dismantle_scalar(n::BindNode, ctx)
9393
BindNode(over = over′, args = args′, label_map = n.label_map)
9494
end
9595

96-
function dismantle_scalar(n::BoundNode, ctx)
96+
function dismantle_scalar(n::NestedNode, ctx)
9797
over′ = dismantle_scalar(n.over, ctx)
98-
BoundNode(over = over′, name = n.name)
98+
NestedNode(over = over′, name = n.name)
9999
end
100100

101101
function dismantle(n::DefineNode, ctx)
@@ -219,7 +219,7 @@ end
219219
function link(n::AsNode, ctx)
220220
refs = SQLNode[]
221221
for ref in ctx.refs
222-
if @dissect(ref, over |> Bound(name = name))
222+
if @dissect(ref, over |> Nested(name = name))
223223
@assert name == n.name
224224
push!(refs, over)
225225
else
@@ -276,13 +276,13 @@ end
276276
function link(n::FromTableExpressionNode, ctx)
277277
refs = ctx.cte_refs[(n.name, n.depth)]
278278
for ref in ctx.refs
279-
push!(refs, Bound(over = ref, name = n.name))
279+
push!(refs, Nested(over = ref, name = n.name))
280280
end
281281
n
282282
end
283283

284284
function link(n::GroupNode, ctx)
285-
has_aggregates = any(ref -> @dissect(ref, Agg() || Agg() |> Bound()), ctx.refs)
285+
has_aggregates = any(ref -> @dissect(ref, Agg() || Agg() |> Nested()), ctx.refs)
286286
if !has_aggregates && isempty(n.by)
287287
return link(FromNothing(), ctx)
288288
end
@@ -294,7 +294,7 @@ function link(n::GroupNode, ctx)
294294
if has_aggregates
295295
ctx′ = LinkContext(ctx, refs = refs)
296296
for ref in ctx.refs
297-
if (@dissect(ref, nothing |> Agg(args = args, filter = filter) |> Bound(name = name)) && name === n.name) ||
297+
if (@dissect(ref, nothing |> Agg(args = args, filter = filter) |> Nested(name = name)) && name === n.name) ||
298298
(@dissect(ref, nothing |> Agg(args = args, filter = filter)) && n.name === nothing)
299299
gather!(args, ctx′)
300300
if filter !== nothing
@@ -353,7 +353,7 @@ function link(n::IterateNode, ctx)
353353
end
354354

355355
function route(r::JoinRouter, ref::SQLNode)
356-
if @dissect(ref, over |> Bound(name = name)) && name in r.label_set
356+
if @dissect(ref, over |> Nested(name = name)) && name in r.label_set
357357
return 1
358358
end
359359
if @dissect(ref, Get(name = name)) && name in r.label_set
@@ -418,7 +418,7 @@ function link(n::PartitionNode, ctx)
418418
ctx′ = LinkContext(ctx, refs = imm_refs)
419419
has_aggregates = false
420420
for ref in ctx.refs
421-
if (@dissect(ref, nothing |> Agg(args = args, filter = filter) |> Bound(name = name)) && name === n.name) ||
421+
if (@dissect(ref, nothing |> Agg(args = args, filter = filter) |> Nested(name = name)) && name === n.name) ||
422422
(@dissect(ref, nothing |> Agg(args = args, filter = filter)) && n.name === nothing)
423423
gather!(args, ctx′)
424424
if filter !== nothing
@@ -526,7 +526,7 @@ gather!(n::AbstractSQLNode, ctx) =
526526
gather!(n, ctx, refs) =
527527
gather!(n, LinkContext(ctx, refs = refs))
528528

529-
function gather!(n::Union{AggregateNode, GetNode, BoundNode}, ctx)
529+
function gather!(n::Union{AggregateNode, GetNode, NestedNode}, ctx)
530530
push!(ctx.refs, n)
531531
nothing
532532
end

src/nodes.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,8 +460,8 @@ struct TransliterateContext
460460
TransliterateContext(mod::Module, src::LineNumberNode, decl::Bool = false) =
461461
new(mod, src, decl)
462462

463-
TransliterateContext(ctx::TransliterateContext; src = missing, decl = missing) =
464-
new(ctx.mod, coalesce(src, ctx.src), coalesce(decl, ctx.decl))
463+
TransliterateContext(ctx::TransliterateContext; src = ctx.src, decl = ctx.decl) =
464+
new(ctx.mod, src, decl)
465465
end
466466

467467
"""

src/nodes/internal.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,23 @@ function PrettyPrinting.quoteof(n::LinkedNode, ctx::QuoteContext)
8686
ex
8787
end
8888

89-
# Get(over = Get(:a), name = :b) => Bound(over = Get(:b), name = :a)
90-
mutable struct BoundNode <: AbstractSQLNode
89+
# Get(over = Get(:a), name = :b) => Nested(over = Get(:b), name = :a)
90+
mutable struct NestedNode <: AbstractSQLNode
9191
over::SQLNode
9292
name::Symbol
9393

94-
BoundNode(; over, name) =
94+
NestedNode(; over, name) =
9595
new(over, name)
9696
end
9797

98-
Bound(args...; kws...) =
99-
BoundNode(args...; kws...) |> SQLNode
98+
Nested(args...; kws...) =
99+
NestedNode(args...; kws...) |> SQLNode
100100

101-
dissect(scr::Symbol, ::typeof(Bound), pats::Vector{Any}) =
102-
dissect(scr, BoundNode, pats)
101+
dissect(scr::Symbol, ::typeof(Nested), pats::Vector{Any}) =
102+
dissect(scr, NestedNode, pats)
103103

104-
PrettyPrinting.quoteof(n::BoundNode, ctx::QuoteContext) =
105-
Expr(:call, nameof(Bound), Expr(:kw, :over, quoteof(n.over, ctx)), Expr(:kw, :name, QuoteNode(n.name)))
104+
PrettyPrinting.quoteof(n::NestedNode, ctx::QuoteContext) =
105+
Expr(:call, nameof(Nested), Expr(:kw, :over, quoteof(n.over, ctx)), Expr(:kw, :name, QuoteNode(n.name)))
106106

107107
# A generic From node is specialized to FromNothing, FromTable,
108108
# FromTableExpression, FromKnot, FromValues, or FromFunction.

src/resolve.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,17 @@ struct ResolveContext
2020

2121
ResolveContext(
2222
ctx::ResolveContext;
23-
row_type = missing,
24-
cte_types = missing,
25-
knot_type = missing,
26-
implicit_knot = missing) =
23+
row_type = ctx.row_type,
24+
cte_types = ctx.cte_types,
25+
knot_type = ctx.knot_type,
26+
implicit_knot = ctx.implicit_knot) =
2727
new(ctx.dialect,
2828
ctx.tables,
2929
ctx.path,
30-
coalesce(row_type, ctx.row_type),
31-
coalesce(cte_types, ctx.cte_types),
32-
coalesce(knot_type, ctx.knot_type),
33-
coalesce(implicit_knot, ctx.implicit_knot))
30+
row_type,
31+
cte_types,
32+
knot_type,
33+
implicit_knot)
3434
end
3535

3636
get_path(ctx::ResolveContext) =
@@ -100,9 +100,9 @@ function resolve_scalar(n::TabularNode, ctx)
100100
Resolved(ScalarType(), over = n′)
101101
end
102102

103-
function rebind(node, base, ctx)
103+
function unnest(node, base, ctx)
104104
while @dissect(node, over |> Get(name = name))
105-
base = Bound(over = base, name = name)
105+
base = Nested(over = base, name = name)
106106
node = over
107107
end
108108
if node !== nothing
@@ -113,7 +113,7 @@ end
113113

114114
function resolve_scalar(n::AggregateNode, ctx)
115115
if n.over !== nothing
116-
n′ = rebind(n.over, Agg(name = n.name, args = n.args, filter = n.filter), ctx)
116+
n′ = unnest(n.over, Agg(name = n.name, args = n.args, filter = n.filter), ctx)
117117
return resolve_scalar(n′, ctx)
118118
end
119119
t = ctx.row_type.group
@@ -179,7 +179,7 @@ function resolve_scalar(n::BindNode, ctx)
179179
Resolved(type(over′), over = n′)
180180
end
181181

182-
function resolve_scalar(n::BoundNode, ctx)
182+
function resolve_scalar(n::NestedNode, ctx)
183183
t = get(ctx.row_type.fields, n.name, EmptyType())
184184
if !(t isa RowType)
185185
error_type =
@@ -189,7 +189,7 @@ function resolve_scalar(n::BoundNode, ctx)
189189
throw(ReferenceError(error_type, name = n.name, path = get_path(ctx)))
190190
end
191191
over′ = resolve_scalar(n.over, ctx, t)
192-
n′ = BoundNode(over = over′, name = n.name)
192+
n′ = NestedNode(over = over′, name = n.name)
193193
Resolved(type(over′), over = n′)
194194
end
195195

@@ -284,7 +284,7 @@ end
284284

285285
function resolve_scalar(n::GetNode, ctx)
286286
if n.over !== nothing
287-
n′ = rebind(n.over, Get(name = n.name), ctx)
287+
n′ = unnest(n.over, Get(name = n.name), ctx)
288288
return resolve_scalar(n′, ctx)
289289
end
290290
t = get(ctx.row_type.fields, n.name, EmptyType())

src/translate.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,17 +160,17 @@ struct TranslateContext
160160
Dict{Symbol, SQLClause}(),
161161
Dict{Int, SQLClause}())
162162

163-
function TranslateContext(ctx::TranslateContext; cte_map = missing, knot = missing, refs = missing, vars = missing, subs = missing)
163+
function TranslateContext(ctx::TranslateContext; cte_map = ctx.cte_map, knot = ctx.knot, refs = ctx.refs, vars = ctx.vars, subs = ctx.subs)
164164
new(ctx.dialect,
165165
ctx.defs,
166166
ctx.aliases,
167167
ctx.recursive,
168168
ctx.ctes,
169-
coalesce(cte_map, ctx.cte_map),
170-
coalesce(knot, ctx.knot),
171-
coalesce(refs, ctx.refs),
172-
coalesce(vars, ctx.vars),
173-
coalesce(subs, ctx.subs))
169+
cte_map,
170+
knot,
171+
refs,
172+
vars,
173+
subs)
174174
end
175175
end
176176

@@ -390,7 +390,7 @@ end
390390
function assemble(n::AsNode, ctx)
391391
refs′ = SQLNode[]
392392
for ref in ctx.refs
393-
if @dissect(ref, over |> Bound())
393+
if @dissect(ref, over |> Nested())
394394
push!(refs′, over)
395395
else
396396
push!(refs′, ref)
@@ -399,7 +399,7 @@ function assemble(n::AsNode, ctx)
399399
base = assemble(n.over, TranslateContext(ctx, refs = refs′))
400400
repl′ = Dict{SQLNode, Symbol}()
401401
for ref in ctx.refs
402-
if @dissect(ref, over |> Bound())
402+
if @dissect(ref, over |> Nested())
403403
repl′[ref] = base.repl[over]
404404
else
405405
repl′[ref] = base.repl[ref]
@@ -491,7 +491,7 @@ assemble(::FromNothingNode, ctx) =
491491
function unwrap_repl(a::Assemblage)
492492
repl′ = Dict{SQLNode, Symbol}()
493493
for (ref, name) in a.repl
494-
@dissect(ref, over |> Bound()) || error()
494+
@dissect(ref, over |> Nested()) || error()
495495
repl′[over] = name
496496
end
497497
Assemblage(a.name, a.clause, cols = a.cols, repl = repl′)
@@ -592,7 +592,7 @@ function assemble(n::FromValuesNode, ctx)
592592
end
593593

594594
function assemble(n::GroupNode, ctx)
595-
has_aggregates = any(ref -> @dissect(ref, Agg() || Agg() |> Bound()), ctx.refs)
595+
has_aggregates = any(ref -> @dissect(ref, Agg() || Agg() |> Nested()), ctx.refs)
596596
if isempty(n.by) && !has_aggregates
597597
return assemble(nothing, ctx)
598598
end
@@ -612,7 +612,7 @@ function assemble(n::GroupNode, ctx)
612612
push!(trns, ref => by[n.label_map[name]])
613613
elseif @dissect(ref, nothing |> Agg())
614614
push!(trns, ref => translate(ref, ctx, subs))
615-
elseif @dissect(ref, (over := nothing |> Agg()) |> Bound())
615+
elseif @dissect(ref, (over := nothing |> Agg()) |> Nested())
616616
push!(trns, ref => translate(over, ctx, subs))
617617
end
618618
end
@@ -852,7 +852,7 @@ function assemble(n::PartitionNode, ctx)
852852
if @dissect(ref, nothing |> Agg()) && n.name === nothing
853853
push!(trns, ref => partition |> translate(ref, ctx′))
854854
has_aggregates = true
855-
elseif @dissect(ref, (over := nothing |> Agg()) |> Bound(name = name)) && name === n.name
855+
elseif @dissect(ref, (over := nothing |> Agg()) |> Nested(name = name)) && name === n.name
856856
push!(trns, ref => partition |> translate(over, ctx′))
857857
has_aggregates = true
858858
else

0 commit comments

Comments
 (0)