Skip to content

Commit 19212e0

Browse files
committed
Rename FromKnot -> FromIterate, IntJoin -> RoutedJoin
1 parent c83dd99 commit 19212e0

File tree

5 files changed

+74
-74
lines changed

5 files changed

+74
-74
lines changed

src/link.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function dismantle(n::FromFunctionNode, ctx)
107107
FromFunction(over = over′, columns = n.columns)
108108
end
109109

110-
dismantle(n::Union{FromKnotNode, FromNothingNode, FromTableExpressionNode, FromTableNode, FromValuesNode}, ctx) =
110+
dismantle(n::Union{FromIterateNode, FromNothingNode, FromTableExpressionNode, FromTableNode, FromValuesNode}, ctx) =
111111
convert(SQLNode, n)
112112

113113
function dismantle_scalar(n::FunctionNode, ctx)
@@ -133,7 +133,7 @@ function dismantle(n::JoinNode, ctx)
133133
over′ = dismantle(n.over, ctx)
134134
joinee′ = dismantle(n.joinee, ctx)
135135
on′ = dismantle_scalar(n.on, ctx)
136-
IntJoin(over = over′, joinee = joinee′, on = on′, router = router, left = n.left, right = n.right, optional = n.optional)
136+
RoutedJoin(over = over′, joinee = joinee′, on = on′, router = router, left = n.left, right = n.right, optional = n.optional)
137137
end
138138

139139
function dismantle(n::LimitNode, ctx)
@@ -268,7 +268,7 @@ end
268268
link(n::Union{FromFunctionNode, FromNothingNode, FromTableNode, FromValuesNode}, ctx) =
269269
convert(SQLNode, n)
270270

271-
function link(n::FromKnotNode, ctx)
271+
function link(n::FromIterateNode, ctx)
272272
append!(ctx.knot_refs, ctx.refs)
273273
n
274274
end
@@ -358,7 +358,7 @@ function route(r::JoinRouter, ref::SQLNode)
358358
return -1
359359
end
360360

361-
function link(n::IntJoinNode, ctx)
361+
function link(n::RoutedJoinNode, ctx)
362362
lrefs = SQLNode[]
363363
rrefs = SQLNode[]
364364
for ref in ctx.refs
@@ -382,7 +382,7 @@ function link(n::IntJoinNode, ctx)
382382
end
383383
over′ = Linked(lrefs, ln_ext_refs, over = link(n.over, ctx, lrefs))
384384
joinee′ = Linked(rrefs, rn_ext_refs, over = link(n.joinee, ctx, rrefs))
385-
IntJoinNode(
385+
RoutedJoinNode(
386386
over = over′,
387387
joinee = joinee′,
388388
on = n.on,

src/nodes/from.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
abstract type AbstractSource
44
end
55

6-
struct KnotSource <: AbstractSource
6+
struct IterateSource <: AbstractSource
77
end
88

99
struct ValuesSource <: AbstractSource
@@ -15,17 +15,17 @@ struct FunctionSource <: AbstractSource
1515
columns::Vector{Symbol}
1616
end
1717

18-
_from_source(source::Union{SQLTable, KnotSource, FunctionSource, ValuesSource, Nothing}) =
18+
_from_source(source::Union{SQLTable, IterateSource, FunctionSource, ValuesSource, Nothing}) =
1919
source
2020

2121
_from_source(source::AbstractString) =
2222
Symbol(source)
2323

2424
_from_source(source::Symbol) =
25-
source === :^ ? KnotSource() : source
25+
source === :^ ? IterateSource() : source
2626

2727
_from_source(::typeof(^)) =
28-
KnotSource()
28+
IterateSource()
2929

3030
function _from_source(node::AbstractSQLNode;
3131
columns::AbstractVector{<:Union{Symbol, AbstractString}})
@@ -51,7 +51,7 @@ function _from_source(source)
5151
end
5252

5353
mutable struct FromNode <: TabularNode
54-
source::Union{SQLTable, Symbol, KnotSource, ValuesSource, FunctionSource, Nothing}
54+
source::Union{SQLTable, Symbol, IterateSource, ValuesSource, FunctionSource, Nothing}
5555

5656
FromNode(; source, kws...) =
5757
new(_from_source(source; kws...))
@@ -230,7 +230,7 @@ function PrettyPrinting.quoteof(n::FromNode, ctx::QuoteContext)
230230
Expr(:call, nameof(From), tex)
231231
elseif source isa Symbol
232232
Expr(:call, nameof(From), QuoteNode(source))
233-
elseif source isa KnotSource
233+
elseif source isa IterateSource
234234
Expr(:call, nameof(From), :^)
235235
elseif source isa ValuesSource
236236
Expr(:call, nameof(From), quoteof(source.columns, ctx))

src/nodes/internal.jl

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ dissect(scr::Symbol, ::typeof(Nested), pats::Vector{Any}) =
104104
PrettyPrinting.quoteof(n::NestedNode, ctx::QuoteContext) =
105105
Expr(:call, nameof(Nested), Expr(:kw, :over, quoteof(n.over, ctx)), Expr(:kw, :name, QuoteNode(n.name)))
106106

107-
# Var() that has the corresponding Bind()
107+
# Var() that found the corresponding Bind()
108108
mutable struct BoundVariableNode <: AbstractSQLNode
109109
name::Symbol
110110
depth::Int
@@ -123,7 +123,7 @@ PrettyPrinting.quoteof(n::BoundVariableNode, ctx::QuoteContext) =
123123
Expr(:call, nameof(BoundVariable), QuoteNode(n.name), n.depth)
124124

125125
# A generic From node is specialized to FromNothing, FromTable,
126-
# FromTableExpression, FromKnot, FromValues, or FromFunction.
126+
# FromTableExpression, FromIterate, FromValues, or FromFunction.
127127
mutable struct FromNothingNode <: TabularNode
128128
end
129129

@@ -168,14 +168,14 @@ FromTableExpression(args...; kws...) =
168168
PrettyPrinting.quoteof(n::FromTableExpressionNode, ctx::QuoteContext) =
169169
Expr(:call, nameof(FromTableExpression), QuoteNode(n.name), n.depth)
170170

171-
mutable struct FromKnotNode <: TabularNode
171+
mutable struct FromIterateNode <: TabularNode
172172
end
173173

174-
FromKnot(args...; kws...) =
175-
FromKnotNode(args...; kws...) |> SQLNode
174+
FromIterate(args...; kws...) =
175+
FromIterateNode(args...; kws...) |> SQLNode
176176

177-
PrettyPrinting.quoteof(n::FromKnotNode, ctx::QuoteContext) =
178-
Expr(:call, nameof(FromKnot))
177+
PrettyPrinting.quoteof(n::FromIterateNode, ctx::QuoteContext) =
178+
Expr(:call, nameof(FromIterate))
179179

180180
mutable struct FromValuesNode <: TabularNode
181181
columns::NamedTuple
@@ -216,7 +216,7 @@ end
216216
PrettyPrinting.quoteof(r::JoinRouter) =
217217
Expr(:call, nameof(JoinRouter), quoteof(r.label_set), quoteof(r.group))
218218

219-
mutable struct IntJoinNode <: TabularNode
219+
mutable struct RoutedJoinNode <: TabularNode
220220
over::Union{SQLNode, Nothing}
221221
joinee::SQLNode
222222
on::SQLNode
@@ -226,18 +226,18 @@ mutable struct IntJoinNode <: TabularNode
226226
lateral::Bool
227227
optional::Bool
228228

229-
IntJoinNode(; over, joinee, on, router, left, right, lateral = false, optional = false) =
229+
RoutedJoinNode(; over, joinee, on, router, left, right, lateral = false, optional = false) =
230230
new(over, joinee, on, router, left, right, lateral, optional)
231231
end
232232

233-
IntJoinNode(joinee, on; over = nothing, router, left = false, right = false, lateral = false, optional = false) =
234-
IntJoinNode(over = over, joinee = joinee, on = on, router, left = left, right = right, lateral = lateral, optional = optional)
233+
RoutedJoinNode(joinee, on; over = nothing, router, left = false, right = false, lateral = false, optional = false) =
234+
RoutedJoinNode(over = over, joinee = joinee, on = on, router, left = left, right = right, lateral = lateral, optional = optional)
235235

236-
IntJoin(args...; kws...) =
237-
IntJoinNode(args...; kws...) |> SQLNode
236+
RoutedJoin(args...; kws...) =
237+
RoutedJoinNode(args...; kws...) |> SQLNode
238238

239-
function PrettyPrinting.quoteof(n::IntJoinNode, ctx::QuoteContext)
240-
ex = Expr(:call, nameof(IntJoin))
239+
function PrettyPrinting.quoteof(n::RoutedJoinNode, ctx::QuoteContext)
240+
ex = Expr(:call, nameof(RoutedJoin))
241241
if !ctx.limit
242242
push!(ex.args, quoteof(n.joinee, ctx))
243243
push!(ex.args, quoteof(n.on, ctx))

src/resolve.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ resolve(ns::Vector{SQLNode}, ctx) =
7171
function resolve(::Nothing, ctx)
7272
t = ctx.knot_type
7373
if t !== nothing && ctx.implicit_knot
74-
n = FromKnot()
74+
n = FromIterate()
7575
else
7676
n = FromNothing()
7777
t = EMPTY_ROW
@@ -278,15 +278,15 @@ function resolve(n::FromNode, ctx)
278278
n′ = FromTable(table = table)
279279
t = RowType(table)
280280
end
281-
elseif source isa KnotSource
281+
elseif source isa IterateSource
282282
t = ctx.knot_type
283283
if t === nothing
284284
throw(
285285
ReferenceError(
286286
REFERENCE_ERROR_TYPE.INVALID_SELF_REFERENCE,
287287
path = get_path(ctx)))
288288
end
289-
n′ = FromKnot()
289+
n′ = FromIterate()
290290
elseif source isa ValuesSource
291291
n′ = FromValues(columns = source.columns)
292292
fields = FieldTypeMap()

src/translate.jl

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ function assemble(n::FromFunctionNode, ctx)
472472
Assemblage(label(n.over), c, cols = cols, repl = repl)
473473
end
474474

475-
function assemble(n::FromKnotNode, ctx)
475+
function assemble(n::FromIterateNode, ctx)
476476
cte_a = ctx.ctes[ctx.knot]
477477
name = cte_a.a.name
478478
alias = allocate_alias(ctx, name)
@@ -635,50 +635,6 @@ function assemble(n::GroupNode, ctx)
635635
return Assemblage(base.name, c, cols = cols, repl = repl)
636636
end
637637

638-
function assemble(n::IntJoinNode, ctx)
639-
left = assemble(n.over, ctx)
640-
if @dissect(left.clause, tail := FROM() || JOIN())
641-
left_alias = nothing
642-
else
643-
left_alias = allocate_alias(ctx, left)
644-
tail = FROM(AS(over = complete(left), name = left_alias))
645-
end
646-
lateral = n.lateral
647-
subs = make_subs(left, left_alias)
648-
if lateral
649-
right = assemble(n.joinee, TranslateContext(ctx, subs = subs))
650-
else
651-
right = assemble(n.joinee, ctx)
652-
end
653-
if @dissect(right.clause, (joinee := (nothing || nothing |> ID()) |> ID() |> AS(name = right_alias, columns = nothing)) |> FROM()) ||
654-
@dissect(right.clause, (joinee := nothing |> ID(name = right_alias)) |> FROM()) ||
655-
@dissect(right.clause, (joinee := FUN() |> AS(name = right_alias)) |> FROM())
656-
for (ref, name) in right.repl
657-
subs[ref] = right.cols[name]
658-
end
659-
if ctx.dialect.has_implicit_lateral
660-
lateral = false
661-
end
662-
else
663-
right_alias = allocate_alias(ctx, right)
664-
joinee = AS(over = complete(right), name = right_alias)
665-
right_cache = Dict{Symbol, SQLClause}()
666-
for (ref, name) in right.repl
667-
subs[ref] = get(right_cache, name) do
668-
ID(over = right_alias, name = name)
669-
end
670-
end
671-
end
672-
on = translate(n.on, ctx, subs)
673-
c = JOIN(over = tail, joinee = joinee, on = on, left = n.left, right = n.right, lateral = lateral)
674-
trns = Pair{SQLNode, SQLClause}[]
675-
for ref in ctx.refs
676-
push!(trns, ref => subs[ref])
677-
end
678-
repl, cols = make_repl_cols(trns)
679-
Assemblage(left.name, c, cols = cols, repl = repl)
680-
end
681-
682638
function assemble(n::IterateNode, ctx)
683639
ctx′ = TranslateContext(ctx, vars = Base.ImmutableDict{Tuple{Symbol, Int}, SQLClause}())
684640
left = assemble(n.over, ctx)
@@ -866,6 +822,50 @@ function assemble(n::PartitionNode, ctx)
866822
Assemblage(base.name, c, cols = cols, repl = repl)
867823
end
868824

825+
function assemble(n::RoutedJoinNode, ctx)
826+
left = assemble(n.over, ctx)
827+
if @dissect(left.clause, tail := FROM() || JOIN())
828+
left_alias = nothing
829+
else
830+
left_alias = allocate_alias(ctx, left)
831+
tail = FROM(AS(over = complete(left), name = left_alias))
832+
end
833+
lateral = n.lateral
834+
subs = make_subs(left, left_alias)
835+
if lateral
836+
right = assemble(n.joinee, TranslateContext(ctx, subs = subs))
837+
else
838+
right = assemble(n.joinee, ctx)
839+
end
840+
if @dissect(right.clause, (joinee := (nothing || nothing |> ID()) |> ID() |> AS(name = right_alias, columns = nothing)) |> FROM()) ||
841+
@dissect(right.clause, (joinee := nothing |> ID(name = right_alias)) |> FROM()) ||
842+
@dissect(right.clause, (joinee := FUN() |> AS(name = right_alias)) |> FROM())
843+
for (ref, name) in right.repl
844+
subs[ref] = right.cols[name]
845+
end
846+
if ctx.dialect.has_implicit_lateral
847+
lateral = false
848+
end
849+
else
850+
right_alias = allocate_alias(ctx, right)
851+
joinee = AS(over = complete(right), name = right_alias)
852+
right_cache = Dict{Symbol, SQLClause}()
853+
for (ref, name) in right.repl
854+
subs[ref] = get(right_cache, name) do
855+
ID(over = right_alias, name = name)
856+
end
857+
end
858+
end
859+
on = translate(n.on, ctx, subs)
860+
c = JOIN(over = tail, joinee = joinee, on = on, left = n.left, right = n.right, lateral = lateral)
861+
trns = Pair{SQLNode, SQLClause}[]
862+
for ref in ctx.refs
863+
push!(trns, ref => subs[ref])
864+
end
865+
repl, cols = make_repl_cols(trns)
866+
Assemblage(left.name, c, cols = cols, repl = repl)
867+
end
868+
869869
function assemble(n::SelectNode, ctx)
870870
base = assemble(n.over, ctx)
871871
if !@dissect(base.clause, SELECT() || UNION())

0 commit comments

Comments
 (0)