@@ -61,14 +61,16 @@ function FunSQL.resolve(n::UndefineNode, ctx)
6161 end
6262 end
6363 fields = FunSQL. FieldTypeMap()
64+ private_fields = copy(t. private_fields)
6465 for (f, ft) in t. fields
6566 if f in keys(n. label_map)
67+ delete!(private_fields, f)
6668 continue
6769 end
6870 fields[f] = ft
6971 end
7072 q′ = FunSQL. Padding(tail = tail′)
71- FunSQL. Resolved(FunSQL. RowType(fields, t. group), tail = q′)
73+ FunSQL. Resolved(FunSQL. RowType(fields, t. group, private_fields ), tail = q′)
7274end
7375
7476mutable struct TryGetNode <: FunSQL.AbstractSQLNode
@@ -160,14 +162,15 @@ function FunSQL.resolve(n::ExplainConceptIdNode, ctx)
160162 left_join(
161163 from(concept). define(args = $ (n. args)). as($ alias),
162164 $ f == $ alias. concept_id,
163- optional = true )
165+ optional = true ,
166+ private = true )
164167 end
165168 defs = [Symbol(" $prefix$label " ) => @funsql($ alias.$ label) for label in keys(n. label_map)]
166169 dup_field_aliases = [first(def) for def in defs if haskey(t. fields, first(def))]
167170 if ! isempty(dup_field_aliases)
168171 q = q |> Undefine(names = dup_field_aliases)
169172 end
170- q = q |> FunSQL. Define(args = defs, after = f)
173+ q = q |> FunSQL. Define(args = defs, after = f, private = (f in t . private_fields) )
171174 if n. replace
172175 q = q |> Undefine(f)
173176 end
@@ -180,19 +183,21 @@ mutable struct SummaryNode <: FunSQL.TabularNode
180183 type:: Bool
181184 top_k:: Int
182185 nested:: Bool
186+ private:: Bool
183187 exact:: Bool
184188
185- SummaryNode(; names = Symbol[], type = true , top_k = 0 , nested = false , exact = false ) =
186- new(names, type, top_k, nested, exact)
189+ SummaryNode(; names = Symbol[], type = true , top_k = 0 , nested = false , private = false , exact = false ) =
190+ new(names, type, top_k, nested, private, exact)
187191end
188192
189- SummaryNode(names... ; type = true , top_k = 0 , nested = false , exact = false ) =
190- SummaryNode(names = Symbol[names... ], type = type, top_k = top_k, nested = nested, exact = exact)
193+ SummaryNode(names... ; type = true , top_k = 0 , nested = false , private = false , exact = false ) =
194+ SummaryNode(names = Symbol[names... ], type = type, top_k = top_k, nested = nested, private = private, exact = exact)
191195
192196const Summary = FunSQL. SQLQueryCtor{SummaryNode}(:Summary)
193197
194198const funsql_summary = Summary
195199const funsql_density = Summary
200+ const funsql_summarize = Summary
196201
197202function FunSQL. PrettyPrinting. quoteof(n:: SummaryNode , ctx:: FunSQL.QuoteContext )
198203 ex = Expr(:call, :Summary, FunSQL. quoteof(n. names, ctx). .. )
@@ -205,6 +210,9 @@ function FunSQL.PrettyPrinting.quoteof(n::SummaryNode, ctx::FunSQL.QuoteContext)
205210 if n. nested
206211 push!(ex. args, Expr(:kw, :nested, n. nested))
207212 end
213+ if n. private
214+ push!(ex. args, Expr(:kw, :private, n. private))
215+ end
208216 if n. exact
209217 push!(ex. args, Expr(:kw, :exact, n. exact))
210218 end
@@ -224,7 +232,7 @@ function FunSQL.resolve(n::SummaryNode, ctx)
224232 end
225233 end
226234 names = isempty(n. names) ? Set(keys(t. fields)) : Set(n. names)
227- cases = _summary_cases(t, names, n. nested)
235+ cases = _summary_cases(t, names, n. nested || n . private )
228236 if isempty(cases) && ! n. nested
229237 cases = _summary_cases(t, names, true )
230238 end
@@ -255,20 +263,23 @@ function FunSQL.resolve(n::SummaryNode, ctx)
255263 q = @funsql begin
256264 $ tail′
257265 group()
258- cross_join(summary_case => from(explode(sequence(1 , $ max_i)), columns = [index]))
266+ cross_join(
267+ summary_case => from(explode(sequence(1 , $ max_i)), columns = [index]),
268+ private = true )
259269 define(args = $ args)
260270 end
261271 FunSQL. resolve(q, ctx)
262272end
263273
264- function _summary_cases(t, name_set, nested )
274+ function _summary_cases(t, name_set, private )
265275 cases = Tuple{String, FunSQL. SQLQuery}[]
266276 for (f, ft) in t. fields
267277 f in name_set || continue
278+ ! (f in t. private_fields) || private || continue
268279 if ft isa FunSQL. ScalarType
269280 push!(cases, (String(f), FunSQL. Get(f)))
270- elseif ft isa FunSQL. RowType && nested
271- subcases = _summary_cases(ft, Set(keys(ft. fields)), nested )
281+ elseif ft isa FunSQL. RowType
282+ subcases = _summary_cases(ft, Set(keys(ft. fields)), private )
272283 for (n, q) in subcases
273284 push!(cases, (" $f .$n " , FunSQL. Get(f) |> q))
274285 end
@@ -507,7 +518,7 @@ function resolve_concept_id(cat::FunSQL.SQLCatalog, n::AssertValidConceptNode)
507518 m != = nothing && m. concept_cache != = nothing || return
508519 (conn, dir) = m. concept_cache
509520 db = FunSQL. SQLConnection(conn, catalog = cat)
510- q = @funsql concept($ (n. condition)). order(concept_id). limit(3 )
521+ q = @funsql concept() . filter( $ (n. condition)). order(concept_id). limit(3 )
511522 sql = FunSQL. render(db, q)
512523 key = bytes2hex(sha256(sql))
513524 filename = joinpath(dir, key * " .arrow" )
0 commit comments