Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
Interval data type
Browse files Browse the repository at this point in the history
  • Loading branch information
kimmolinna committed Oct 5, 2021
1 parent c0c61b0 commit b923a37
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DuckDB"
uuid = "d2f5444f-75bc-4fdf-ac35-56f514c445e1"
authors = ["Kimmo Linna <[email protected]>"]
version = "0.2.1"
version = "0.2.2"

[deps]
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
Expand Down
4 changes: 3 additions & 1 deletion src/DuckDB.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function toDataFrame(result)
print("invalid type for column - \""*name*"\"")
else
mask = unsafe_wrap(Array,columns[i].nullmask,rows)
data = unsafe_wrap(Array,(Ptr{DUCKDB_TYPES[type]}(columns[i].data)),rows)
data = unsafe_wrap(Array,Ptr{DUCKDB_TYPES[type]}(columns[i].data),rows)
bmask=reinterpret(Bool,mask)

if 0!=sum(mask)
Expand All @@ -33,6 +33,8 @@ function toDataFrame(result)
data = Dates.Time.(Dates.Nanosecond.(data.*1000))
elseif type == DUCKDB_TYPE_TIMESTAMP
data = Dates.epochms2datetime.((data./1000).+62167219200000)
elseif type == DUCKDB_TYPE_INTERVAL
data = map(x -> Dates.CompoundPeriod(Dates.Month(x.months),Dates.Day(x.days),Dates.Microsecond(x.micros)),data)
elseif type == DUCKDB_TYPE_VARCHAR
data = unsafe_string.(data)
end
Expand Down
8 changes: 4 additions & 4 deletions src/consts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ end
struct duckdb_interval
months::Int32
days::Int32
micros::Int32
micros::Int64
end

"""
Expand Down Expand Up @@ -121,8 +121,8 @@ DUCKDB_TYPES = Dict(
DUCKDB_TYPE_TIMESTAMP => Int64,
DUCKDB_TYPE_DATE => Int32,
DUCKDB_TYPE_TIME => Int64,
DUCKDB_TYPE_INTERVAL => Ref{duckdb_interval},
DUCKDB_TYPE_HUGEINT => Ref{duckdb_hugeint},
DUCKDB_TYPE_INTERVAL => duckdb_interval,
DUCKDB_TYPE_HUGEINT => duckdb_hugeint,
DUCKDB_TYPE_VARCHAR => Ptr{UInt8},
DUCKDB_TYPE_BLOB => Ref{duckdb_blob}
DUCKDB_TYPE_BLOB => duckdb_blob
)
33 changes: 29 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import DuckDB
con = DuckDB.connect(":memory:")
res = DuckDB.execute(con,"CREATE TABLE integers(date DATE, data INTEGER);")
res = DuckDB.execute(con,"INSERT INTO integers VALUES ('2021-09-27', 4), ('2021-09-28', 6), ('2021-09-29', 8);")
res = DuckDB.execute(con,"SELECT * FROM integers;")

res = DuckDB.execute(con,"CREATE TABLE interval(interval INTERVAL);")
res = DuckDB.execute(con,"""
INSERT INTO interval VALUES
(INTERVAL 5 HOUR),
(INTERVAL 12 MONTH),
(INTERVAL 12 MICROSECOND),
(INTERVAL 1 YEAR);
""")
res = DuckDB.execute(con,"SELECT * FROM interval;")
res = DuckDB.toDataFrame(res)


res = DuckDB.execute(con,"CREATE TABLE timestamp(timestamp TIMESTAMP, data HUGEINT);")
res = DuckDB.execute(con,"""
INSERT INTO timestamp VALUES
('2021-09-27 11:30:00.000', -170141183460469231731687303715884105727),
('2021-09-28 12:30:00.000', 0),
('2021-09-29 13:30:00.000', 170141183460469231731687303715884105727);
""")
res = DuckDB.execute(con,"SELECT * FROM timestamp;")
res = DuckDB.toDataFrame(res)

res = DuckDB.execute(con,"CREATE TABLE timestamp(timestamp TIMESTAMP , data INTEGER);")
res = DuckDB.execute(con,"INSERT INTO timestamp VALUES ('2021-09-27 11:30:00.000', 4), ('2021-09-28 12:30:00.000', 6), ('2021-09-29 13:30:00.000', 8);")
res = DuckDB.execute(con,"SELECT * FROM timestamp;")
Expand All @@ -13,4 +31,11 @@ res = DuckDB.toDataFrame(res)
res = DuckDB.execute(con, "CREATE TABLE items(item VARCHAR, value DECIMAL(10,2), count INTEGER);")
res = DuckDB.execute(con, "INSERT INTO items VALUES ('jeans', 20.0, 1), ('hammer', 42.2, 2);")
res = DuckDB.execute(con, "SELECT * FROM items;")
res = DuckDB.toDataFrame(res)
res = DuckDB.toDataFrame(res)

res = DuckDB.execute(con,"CREATE TABLE integers(date DATE, data INTEGER);")
res = DuckDB.execute(con,"INSERT INTO integers VALUES ('2021-09-27', 4), ('2021-09-28', 6), ('2021-09-29', 8);")
res = DuckDB.execute(con,"SELECT * FROM integers;")
res = DuckDB.toDataFrame(res)

DuckDB.disconnect(con)

2 comments on commit b923a37

@kimmolinna
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/46116

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.2 -m "<description of version>" b923a37bbb92aaa7e98732f2c798e5aa63187f8d
git push origin v0.2.2

Also, note the warning: This looks like a new registration that registers version 0.2.2.
Ideally, you should register an initial release with 0.0.1, 0.1.0 or 1.0.0 version numbers
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

Please sign in to comment.