Skip to content

Commit c7d205a

Browse files
committed
Add simple test for aggregates.
Also put a little TODO reminder.
1 parent 868ab16 commit c7d205a

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/UDF.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ function finalfunc(init, func, fsym=symbol(string(func)*"_final"))
120120
nm = isdefined(Base,fsym) ? :(Base.$fsym) : fsym
121121
return quote
122122
function $(nm)(context::Ptr{Void}, nargs::Cint, values::Ptr{Ptr{Void}})
123+
# TODO: I don't think arguments are ever passed to this function,
124+
# should we leave them in anyway?
123125
args = [sqlvalue(context, i) for i in 1:nargs]
124126
acptr = sqlite3_aggregate_context(context, 0)
125127
# step function wasn't run

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,12 @@ SQLite.@register db big
207207
r = query(db, "SELECT big(5)")
208208
@test r[1][1] == big(5)
209209

210+
doublesum_step(persist, current) = persist + current
211+
doublesum_final(persist) = 2 * persist
212+
register(db, 0, doublesum_step, doublesum_final, name="doublesum")
213+
r = query(db, "SELECT doublesum(UnitPrice) FROM Track")
214+
s = query(db, "SELECT UnitPrice FROM Track")
215+
@test_approx_eq r[1][1] 2*sum(s[1])
210216

211217
db2 = SQLiteDB()
212218
query(db2, "CREATE TABLE tab1 (r REAL, s INT)")

0 commit comments

Comments
 (0)