Skip to content

Commit 8a25b28

Browse files
committed
Make nested records visible
1 parent ab9f959 commit 8a25b28

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

src/link.jl

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,26 @@ struct LinkContext
2222
knot_refs)
2323
end
2424

25-
function link(n::SQLNode)
26-
@dissect(n, WithContext(over = over, catalog = catalog)) || throw(ILLFormedError())
27-
ctx = LinkContext(catalog)
28-
t = row_type(over)
25+
function _select(t::RowType)
2926
refs = SQLNode[]
3027
for (f, ft) in t.fields
3128
if ft isa ScalarType
3229
push!(refs, Get(f))
30+
else
31+
nested_refs = _select(ft)
32+
for nested_ref in nested_refs
33+
push!(refs, Nested(over = nested_ref, name = f))
34+
end
3335
end
3436
end
37+
refs
38+
end
39+
40+
function link(n::SQLNode)
41+
@dissect(n, WithContext(over = over, catalog = catalog)) || throw(ILLFormedError())
42+
ctx = LinkContext(catalog)
43+
t = row_type(over)
44+
refs = _select(t)
3545
over′ = Linked(refs, over = link(dismantle(over, ctx), ctx, refs))
3646
WithContext(over = over′, catalog = catalog, defs = ctx.defs)
3747
end
@@ -539,12 +549,9 @@ end
539549
function gather!(n::IsolatedNode, ctx)
540550
def = ctx.defs[n.idx]
541551
!@dissect(def, Linked()) || return
542-
refs = SQLNode[]
543-
for (f, ft) in n.type.fields
544-
if ft isa ScalarType
545-
push!(refs, Get(f))
546-
break
547-
end
552+
refs = _select(n.type)
553+
if !isempty(refs)
554+
refs = refs[1:1]
548555
end
549556
def′ = Linked(refs, over = link(def, ctx, refs))
550557
ctx.defs[n.idx] = def′

0 commit comments

Comments
 (0)