Skip to content

Commit b128b9a

Browse files
authored
Merge pull request #51 from ExpandingMan/tables
switch from DataStreams to Tables
2 parents fe072f6 + 28cb829 commit b128b9a

File tree

9 files changed

+52
-50
lines changed

9 files changed

+52
-50
lines changed

.travis.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
1+
2+
sudo: required
3+
14
language: julia
5+
6+
services:
7+
- docker
8+
29
os:
10+
- osx
311
- linux
12+
413
julia:
5-
- 0.7
6-
- 1.0
14+
- 1.0
15+
- 1.3
16+
- nightly
17+
18+
matrix:
19+
allow_failures:
20+
- julia: nightly
21+
722
notifications:
823
email: false
9-
# uncomment the following lines to override the default test script
10-
#script:
11-
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
12-
# - julia --check-bounds=yes -e 'Pkg.clone(pwd()); Pkg.build("JDBC"); Pkg.test("JDBC"; coverage=true)'
24+
25+
after_success:
26+
- julia -e 'import Pkg, JDBC; cd(joinpath(dirname(pathof(JDBC)),"..")); Pkg.add("Coverage"); using Coverage; Codecov.submit(process_folder())'
27+
- julia -e 'import Pkg; Pkg.add("Documenter")'
28+
- julia -e 'import JDBC; cd(joinpath(dirname(pathof(JDBC)),"..")); include(joinpath("docs", "make.jl"))'

Project.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
name = "JDBC"
22
uuid = "6042db11-3c3d-5e84-8dba-9cbf74c9ba48"
3-
version = "0.4.1"
3+
version = "0.4.2"
44

55
[deps]
6-
DataStreams = "9a8bc11e-79be-5b39-94d7-1ccc349a1a85"
76
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
87
JavaCall = "494afd89-becb-516b-aafa-70d2670c0337"
8+
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
99

1010
[compat]
11-
DataFrames = "< 0.18.0"
1211
JavaCall = "≥ 0.7.0"
1312
julia = "≥ 0.7.0"
1413

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
This package enables the use of Java JDBC drivers to access databases from within Julia. It uses the [JavaCall.jl](https://github.com/aviks/JavaCall.jl) package to call into Java in order to use the JDBC drivers.
77

88
The API provided by this package consists essentially of two components: a "direct" (i.e. minimally wrapped) interface directly to Java JDBC and a minimal
9-
Julian interface with support for [DataStreams.jl](https://github.com/JuliaData/DataStreams.jl).
9+
Julian interface with support for [Tables.jl](https://github.com/JuliaData/Tables.jl).
1010

1111
This package currently supports only Julia v0.6 and later.
1212

@@ -121,13 +121,13 @@ end
121121
close(csr) # closes Connection, can be called on Connection or Cursor
122122
```
123123

124-
#### `DataStreams` Interface and Creating `DataFrame`s
124+
#### `Tables` Interface and Creating `DataFrame`s
125125

126-
JDBC includes a [DataStreams](https://github.com/JuliaData/DataStreams.jl) interface. A DataStreams `Source` object can be created from a `JDBC.Cursor` or a
127-
`JDBCRowIterator` simply by doing e.g. `JDBC.Source(csr)`. This object implements the DataStreams `Data.Source` interface. It can be useful for retrieving metadata
128-
with `Data.schema`.
126+
JDBC includes a [Tables](https://github.com/JuliaData/Tables.jl) interface. A Tables
127+
`Source` object can be created from a `JDBC.Cursor` or a `JDBCRowIterator` simply by doing
128+
e.g. `JDBC.Source(csr)`. It can be useful for retrieving metadata with `Tables.schema`.
129129

130-
This is also useful for loading data from a database into an object that implements the DataStreams `Data.Sink` interface such as a `DataFrame`. For this we
130+
This is also useful for loading data from a database into another object that implements the Tables interface. For this we
131131
provide also the convenient `JDBC.load` function.
132132

133133
For example, you can do

REQUIRE

Lines changed: 0 additions & 3 deletions
This file was deleted.

appveyor.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
environment:
22
matrix:
3-
- julia_version: 0.7
4-
- julia_version: 1
3+
- julia_version: 1.0
4+
- julia_version: 1.3
55
- julia_version: nightly
66

77
platform:
@@ -12,8 +12,7 @@ platform:
1212
# # (tests will run but not make your overall status red)
1313
matrix:
1414
allow_failures:
15-
- julia_version: nightly
16-
- platform: x86
15+
- julia_version: nightly
1716

1817
branches:
1918
only:

src/JDBC.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ export getTableMetaData, JDBCRowIterator
640640

641641

642642
include("interface.jl")
643-
include("datastreams.jl")
643+
include("tables.jl")
644644

645645

646646
end # module

src/datastreams.jl renamed to src/tables.jl

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using DataStreams
1+
using Tables
22

33
const column_types = Dict(
44
JDBC_COLTYPE_ARRAY=>Array,
@@ -57,41 +57,34 @@ colname(s::Source, col::Int) = getColumnName(s.md, col)
5757
ncols(s::Source) = getColumnCount(s.md)
5858

5959
coltypes(s::Source) = Type[coltype(s, i) for i 1:ncols(s)]
60-
colnames(s::Source) = String[colname(s, i) for i 1:ncols(s)]
60+
colnames(s::Source) = Symbol[Symbol(colname(s, i)) for i 1:ncols(s)]
6161

62-
# WARNING: this does not seem to actually work
63-
Data.reset!(s::Source) = beforeFirst!(s.rs)
62+
Tables.istable(::Type{<:Source}) = true
63+
Tables.rowaccess(::Type{<:Source}) = true
64+
Tables.rows(s::Source) = s
65+
Tables.schema(s::Source) = Tables.Schema(colnames(s), coltypes(s))
6466

65-
Data.isdone(s::Source, row::Int, col::Int) = isdone(s.rs)
66-
67-
Data.schema(s::Source) = Data.Schema(coltypes(s), colnames(s), missing)
68-
69-
Data.accesspattern(s::Source) = Data.Sequential
70-
71-
Data.streamtype(::Type{Source}, ::Type{Data.Field}) = true
72-
Data.streamtype(::Type{Source}, ::Type{Data.Column}) = false
67+
Base.IteratorSize(::Type{<:Source}) = Base.SizeUnknown()
68+
Base.eltype(s::Source) = namedtupletype(Tables.schema(s))
69+
namedtupletype(::Tables.Schema{names, types}) where {names, types} = NamedTuple{names, types}
70+
namedtupletype(s::Source) = namedtupletype(Tables.schema(s))
7371

7472
# TODO currently jdbc_get_method is very inefficient
7573
pullfield(s::Source, col::Int) = jdbc_get_method(getColumnType(s.md, col))(s.rs, col)
7674

77-
# does not store current row number as a persistent state
78-
function Data.streamfrom(s::Source, ::Type{Data.Field}, ::Type{T}, row::Int, col::Int) where T
79-
convert(T, pullfield(s, col))::T
80-
end
81-
function Data.streamfrom(s::Source, ::Type{Data.Field}, ::Type{Union{T, Missing}},
82-
row::Int, col::Int) where T
83-
o = pullfield(s, col)
84-
if wasNull(s.rs)
85-
return missing
86-
end
87-
convert(T, o)::T
75+
jdbcconvert(::Type{T}, s, x) where {T} = convert(T, x)
76+
jdbcconvert(::Type{Union{T, Missing}}, s, x) where {T} = wasNull(s.rs) ? missing : convert(T, x)
77+
78+
function Base.iterate(s::Source, NT::Type{NamedTuple{names, types}}=namedtupletype(s)) where {names, types}
79+
isdone(s.rs) && return nothing
80+
NT(jdbcconvert(fieldtype(types, i), s, pullfield(s, i)) for i 1:fieldcount(types)), NT
8881
end
8982

90-
load(::Type{T}, s::Source) where {T} = Data.close!(Data.stream!(s, T))
83+
load(::Type{T}, s::Source) where {T} = T(Tables.materializer(T)(s))
9184
load(::Type{T}, rs::JResultSet) where {T} = load(T, Source(rs))
9285
load(::Type{T}, stmt::JStatement, query::AbstractString) where {T} = load(T, Source(stmt, query))
9386
load(::Type{T}, csr::Union{JDBC.Cursor,JDBCRowIterator}) where {T} = load(T, Source(csr))
94-
function load(::Type{T}, csr::Cursor, q::AbstractString) where T
87+
function load(::Type{T}, csr::Cursor, q::AbstractString) where {T}
9588
execute!(csr, q)
9689
load(T, csr)
9790
end

test/REQUIRE

Lines changed: 0 additions & 1 deletion
This file was deleted.

test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using JavaCall
33
using JDBC
44
using DataFrames
5-
using DataStreams
65
using Test
76
using Dates
87
import Pkg

0 commit comments

Comments
 (0)