Skip to content

Commit 91189c6

Browse files
committed
Default the final function in register to identity.
And therefore default the name to the step functions name. README and tests have also been updated.
1 parent 0ddb0e8 commit 91189c6

File tree

3 files changed

+5
-6
lines changed

3 files changed

+5
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ A Julia interface to the SQLite library and support for operations on DataFrames
7777
`drop` is pretty self-explanatory. It's really just a convenience wrapper around `query` to execute a DROP TABLE command, while also calling "VACUUM" to clean out freed memory from the database.
7878

7979
* `register(db::SQLiteDB, func::Function; nargs::Int=-1, name::AbstractString=string(func), isdeterm::Bool=true)`
80-
* `register(db::SQLiteDB, init, step::Function, final::Function; nargs::Int=-1, name::AbstractString=string(final), isdeterm::Bool=true)`
80+
* `register(db::SQLiteDB, init, step::Function, final::Function=identity; nargs::Int=-1, name::AbstractString=string(final), isdeterm::Bool=true)`
8181

8282
Register a scalar (first method) or aggregate (second method) function with a `SQLiteDB`.
8383

@@ -252,7 +252,7 @@ julia> dsum(prev) = 2 * prev
252252
julia> register(db, 0, dsum, dsum)
253253
```
254254

255-
If no name is given the name of the second (final) function is used (in this case "dsum"). You can also use lambdas, the following does the same as the previous code snippet
255+
If no name is given the name of the first (step) function is used (in this case "dsum"). You can also use lambdas, the following does the same as the previous code snippet
256256

257257
```julia
258258
julia> register(db, 0, (p,c) -> p+c, p -> 2p, name="dsum")

src/UDF.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ end
206206

207207
# as above but for aggregate functions
208208
function register(
209-
db::SQLiteDB, init, step::Function, final::Function;
210-
nargs::Int=-1, name::AbstractString=string(final), isdeterm::Bool=true
209+
db::SQLiteDB, init, step::Function, final::Function=identity;
210+
nargs::Int=-1, name::AbstractString=string(step), isdeterm::Bool=true
211211
)
212212
@assert nargs <= 127 "use -1 if > 127 arguments are needed"
213213
nargs < -1 && (nargs = -1)

test/runtests.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,7 @@ s = query(db, "SELECT UnitPrice FROM Track")
215215
@test_approx_eq r[1][1] 2*sum(s[1])
216216

217217
mycount(p, c) = p + 1
218-
mycount(p) = p
219-
register(db, 0, mycount, mycount)
218+
register(db, 0, mycount)
220219
r = query(db, "SELECT mycount(TrackId) FROM PlaylistTrack")
221220
s = query(db, "SELECT count(TrackId) FROM PlaylistTrack")
222221
@test r[1] == s[1]

0 commit comments

Comments
 (0)