Skip to content

Commit 7fcd55c

Browse files
authored
Merge pull request #15 from RelationalAI/nhd-empty-true-relations
Add support for empty "true" relations, e.g. `:x, true`
2 parents 3e7752f + 77b9f85 commit 7fcd55c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/results.jl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,17 @@ _getrow(relation::Relation) = getfield(relation, :_getrow)
126126
# `Tuple` of values. This function "lowers" symbols from type space to values
127127
# in the corresponding position in the tuple.
128128
function _make_getrow(relkey, columns)
129+
if columns == [[]]
130+
# Special case for when the relation is `true` in rel (only contains `()`):
131+
# This means that the relation is _only specialized values_, so we can just return
132+
# the specialized values from the relkey directly.
133+
return row -> _relname_to_symbol.(Tuple(relkey))
134+
end
129135
col = 1
130136
getters = []
131137
for item in relkey
132138
if startswith(item, ":") # symbol
133-
let sym = Symbol(item[2:end])
139+
let sym = _relname_to_symbol(item)
134140
push!(getters, _ -> sym)
135141
end
136142
else
@@ -140,10 +146,11 @@ function _make_getrow(relkey, columns)
140146
col += 1
141147
end
142148
end
143-
@assert col == length(columns) + 1
149+
@assert col == length(columns) + 1 "for $relkey: $col != $(length(columns) + 1)"
144150
@assert length(getters) == length(relkey)
145151
return row -> Tuple(getter(row) for getter in getters)
146152
end
153+
_relname_to_symbol(relname::String) = Symbol(relname[2:end])
147154

148155
Base.eltype(::Relation) = RelRow
149156
Base.getindex(relation::Relation, key::Int) = getrow(relation, key)

0 commit comments

Comments
 (0)