Skip to content

Commit f609823

Browse files
nicoleeppfchorney
andauthored
Support unbounded ranges (JuliaDatabases#184)
* Support unbounded ranges * Use bounds_type instead of inclusivity * Change inclusivity to bounds_type * Fix interval deprecations * Clean up intervals tests * Address MR comments * Update comment for postgres range normalization * Bump required Intervals.jl version * Update docs Manifest.toml * Update docs Manifest.toml Co-authored-by: Fernando Chorney <[email protected]>
1 parent 5526a30 commit f609823

File tree

5 files changed

+134
-114
lines changed

5 files changed

+134
-114
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ CEnum = "0.2"
2525
DataFrames = "0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.20"
2626
Decimals = "0.4.1"
2727
DocStringExtensions = "0.8.0"
28-
Intervals = "1"
28+
Intervals = "1.3"
2929
IterTools = "1"
3030
LayerDicts = "1"
3131
Memento = "0.10, 0.11, 0.12, 0.13, 1"

docs/Manifest.toml

+56-54
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ version = "0.0.4"
88
uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
99

1010
[[BinaryProvider]]
11-
deps = ["Libdl", "SHA"]
12-
git-tree-sha1 = "5b08ed6036d9d3f0ee6369410b830f8873d4024c"
11+
deps = ["Libdl", "Logging", "SHA"]
12+
git-tree-sha1 = "ecdec412a9abc8db54c0efc5548c64dfce072058"
1313
uuid = "b99e7846-7c00-51b0-8f62-c81ae34c0232"
14-
version = "0.5.8"
14+
version = "0.5.10"
1515

1616
[[CEnum]]
1717
git-tree-sha1 = "62847acab40e6855a9b5905ccb99c2b5cf6b3ebb"
@@ -31,9 +31,9 @@ uuid = "34da2185-b29b-5c13-b0c7-acf172513d20"
3131
version = "2.2.0"
3232

3333
[[DataAPI]]
34-
git-tree-sha1 = "674b67f344687a88310213ddfa8a2b3c76cc4252"
34+
git-tree-sha1 = "176e23402d80e7743fc26c19c681bfb11246af32"
3535
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
36-
version = "1.1.0"
36+
version = "1.3.0"
3737

3838
[[DataFrames]]
3939
deps = ["CategoricalArrays", "Compat", "IteratorInterfaceExtensions", "Missings", "PooledArrays", "Printf", "REPL", "Reexport", "SortingAlgorithms", "Statistics", "StatsBase", "TableTraits", "Tables", "Unicode"]
@@ -43,9 +43,9 @@ version = "0.18.4"
4343

4444
[[DataStructures]]
4545
deps = ["InteractiveUtils", "OrderedCollections"]
46-
git-tree-sha1 = "b7720de347734f4716d1815b00ce5664ed6bbfd4"
46+
git-tree-sha1 = "be680f1ad03c0a03796aa3fda5a2180df7f83b46"
4747
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
48-
version = "0.17.9"
48+
version = "0.17.18"
4949

5050
[[DataValueInterfaces]]
5151
git-tree-sha1 = "bfc1187b79289637fa0ef6d4436ebdfe6905cbd6"
@@ -71,9 +71,9 @@ uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b"
7171

7272
[[DocStringExtensions]]
7373
deps = ["LibGit2", "Markdown", "Pkg", "Test"]
74-
git-tree-sha1 = "88bb0edb352b16608036faadcc071adda068582a"
74+
git-tree-sha1 = "c5714d9bcdba66389612dc4c47ed827c64112997"
7575
uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
76-
version = "0.8.1"
76+
version = "0.8.2"
7777

7878
[[Documenter]]
7979
deps = ["Base64", "DocStringExtensions", "InteractiveUtils", "JSON", "LibGit2", "Logging", "Markdown", "REPL", "Unicode"]
@@ -82,9 +82,9 @@ uuid = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
8282
version = "0.22.6"
8383

8484
[[ExprTools]]
85-
git-tree-sha1 = "08c1f74d9ad03acf0ee84c12c9e665ab1a9a6e33"
85+
git-tree-sha1 = "6f0517056812fd6aa3af23d4b70d5325a2ae4e95"
8686
uuid = "e2ba6199-217a-4e67-a87a-7c52f15ade04"
87-
version = "0.1.0"
87+
version = "0.1.1"
8888

8989
[[EzXML]]
9090
deps = ["BinaryProvider", "Libdl", "Printf"]
@@ -100,20 +100,19 @@ deps = ["Random"]
100100
uuid = "9fa8497b-333b-5362-9e8d-4d0656e87820"
101101

102102
[[Inflate]]
103-
deps = ["Pkg", "Printf", "Random", "Test"]
104-
git-tree-sha1 = "b7ec91c153cf8bff9aff58b39497925d133ef7fd"
103+
git-tree-sha1 = "f5fc07d4e706b84f72d54eedcc1c13d92fb0871c"
105104
uuid = "d25df0c9-e2be-5dd7-82c8-3ad0b3e990b9"
106-
version = "0.1.1"
105+
version = "0.1.2"
107106

108107
[[InteractiveUtils]]
109108
deps = ["LinearAlgebra", "Markdown"]
110109
uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
111110

112111
[[Intervals]]
113-
deps = ["Dates", "Printf", "TimeZones"]
114-
git-tree-sha1 = "30bce135cd5856edc91f146e3b7e60d736bd067b"
112+
deps = ["Dates", "Printf", "RecipesBase", "TimeZones"]
113+
git-tree-sha1 = "a14dc739ddcc620695aa02569bffa68a63e2ea09"
115114
uuid = "d8418881-c3e1-53bb-8760-2df7ec849ed5"
116-
version = "1.0.0"
115+
version = "1.3.0"
117116

118117
[[IterTools]]
119118
git-tree-sha1 = "05110a2ab1fc5f932622ffea2a003221f4782c18"
@@ -126,16 +125,15 @@ uuid = "82899510-4779-5014-852e-03e436cf321d"
126125
version = "1.0.0"
127126

128127
[[JSON]]
129-
deps = ["Dates", "Distributed", "Mmap", "Sockets", "Test", "Unicode"]
130-
git-tree-sha1 = "1f7a25b53ec67f5e9422f1f551ee216503f4a0fa"
128+
deps = ["Dates", "Mmap", "Unicode"]
129+
git-tree-sha1 = "565947e5338efe62a7db0aa8e5de782c623b04cd"
131130
uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
132-
version = "0.20.0"
131+
version = "0.20.1"
133132

134133
[[LaTeXStrings]]
135-
deps = ["Compat"]
136-
git-tree-sha1 = "7ab9b8788cfab2bdde22adf9004bda7ad9954b6c"
134+
git-tree-sha1 = "de44b395389b84fd681394d4e8d39ef14e3a2ea8"
137135
uuid = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
138-
version = "1.0.3"
136+
version = "1.1.0"
139137

140138
[[LayerDicts]]
141139
git-tree-sha1 = "6087ad3521d6278ebe5c27ae55e7bbb15ca312cb"
@@ -149,16 +147,16 @@ uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
149147
deps = ["BinaryProvider", "CEnum", "Dates", "Decimals", "DocStringExtensions", "FileWatching", "Intervals", "IterTools", "LayerDicts", "Libdl", "Memento", "OffsetArrays", "Tables", "TimeZones"]
150148
path = ".."
151149
uuid = "194296ae-ab2e-5f79-8cd4-7183a0a5a0d1"
152-
version = "1.1.0"
150+
version = "1.2.0"
153151

154152
[[Libdl]]
155153
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
156154

157155
[[LightGraphs]]
158-
deps = ["ArnoldiMethod", "Base64", "DataStructures", "DelimitedFiles", "Distributed", "Inflate", "LinearAlgebra", "Markdown", "Random", "SharedArrays", "SimpleTraits", "SparseArrays", "Statistics", "Test"]
159-
git-tree-sha1 = "c7222c370d5cf6d4e08ae40bddd8c0db6852dfb1"
156+
deps = ["ArnoldiMethod", "DataStructures", "Distributed", "Inflate", "LinearAlgebra", "Random", "SharedArrays", "SimpleTraits", "SparseArrays", "Statistics"]
157+
git-tree-sha1 = "6f85a35d2377cb2db1bc448ed0d6340d2bb1ea64"
160158
uuid = "093fc24a-ae57-5d10-9952-331d41423f4d"
161-
version = "1.2.0"
159+
version = "1.3.3"
162160

163161
[[LinearAlgebra]]
164162
deps = ["Libdl"]
@@ -168,20 +166,20 @@ uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
168166
uuid = "56ddb016-857b-54e1-b83d-db4d58db5568"
169167

170168
[[MacroTools]]
171-
deps = ["DataStructures", "Markdown", "Random"]
172-
git-tree-sha1 = "e2fc7a55bb2224e203bbd8b59f72b91323233458"
169+
deps = ["Markdown", "Random"]
170+
git-tree-sha1 = "f7d2e3f654af75f01ec49be82c231c382214223a"
173171
uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09"
174-
version = "0.5.3"
172+
version = "0.5.5"
175173

176174
[[Markdown]]
177175
deps = ["Base64"]
178176
uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
179177

180178
[[Memento]]
181179
deps = ["Dates", "Distributed", "JSON", "Serialization", "Sockets", "Syslogs", "Test", "TimeZones", "UUIDs"]
182-
git-tree-sha1 = "090463b13da88689e5eae6468a6f531a21392175"
180+
git-tree-sha1 = "31921ad09307dd9ad693da3213a218152fadb8f2"
183181
uuid = "f28f55f0-a522-5efc-85c2-fe41dfb9b2d9"
184-
version = "0.12.1"
182+
version = "1.1.0"
185183

186184
[[Missings]]
187185
deps = ["DataAPI"]
@@ -199,15 +197,14 @@ uuid = "78c3b35d-d492-501b-9361-3d52fe80e533"
199197
version = "0.7.1"
200198

201199
[[OffsetArrays]]
202-
git-tree-sha1 = "87d0a91efe29352d5caaa271ae3927083c096e33"
200+
git-tree-sha1 = "ab697473e983a7499f463b696da8e8feb1b20ffd"
203201
uuid = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
204-
version = "0.11.4"
202+
version = "1.1.0"
205203

206204
[[OrderedCollections]]
207-
deps = ["Random", "Serialization", "Test"]
208-
git-tree-sha1 = "c4c13474d23c60d20a67b217f1d7f22a40edf8f1"
205+
git-tree-sha1 = "12ce190210d278e12644bcadf5b21cbdcf225cd3"
209206
uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d"
210-
version = "1.1.0"
207+
version = "1.2.0"
211208

212209
[[Pkg]]
213210
deps = ["Dates", "LibGit2", "Markdown", "Printf", "REPL", "Random", "SHA", "UUIDs"]
@@ -231,6 +228,11 @@ uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
231228
deps = ["Serialization"]
232229
uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
233230

231+
[[RecipesBase]]
232+
git-tree-sha1 = "54f8ceb165a0f6d083f0d12cb4996f5367c6edbc"
233+
uuid = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
234+
version = "1.0.1"
235+
234236
[[Reexport]]
235237
deps = ["Pkg"]
236238
git-tree-sha1 = "7b1d07f411bc8ddb7977ec7f377b97b158514fe0"
@@ -249,9 +251,9 @@ uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383"
249251

250252
[[SimpleTraits]]
251253
deps = ["InteractiveUtils", "MacroTools"]
252-
git-tree-sha1 = "2bdf3b6300a9d66fe29ee8bb51ba100c4df9ecbc"
254+
git-tree-sha1 = "2ee666b24ab8be6a922f9d6c11a86e1a703a7dda"
253255
uuid = "699a6c99-e7fa-54fc-8d76-47d257e15c1d"
254-
version = "0.9.1"
256+
version = "0.9.2"
255257

256258
[[Sockets]]
257259
uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
@@ -268,19 +270,19 @@ uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
268270

269271
[[StaticArrays]]
270272
deps = ["LinearAlgebra", "Random", "Statistics"]
271-
git-tree-sha1 = "5a3bcb6233adabde68ebc97be66e95dcb787424c"
273+
git-tree-sha1 = "5c06c0aeb81bef54aed4b3f446847905eb6cbda0"
272274
uuid = "90137ffa-7385-5640-81b9-e52037218182"
273-
version = "0.12.1"
275+
version = "0.12.3"
274276

275277
[[Statistics]]
276278
deps = ["LinearAlgebra", "SparseArrays"]
277279
uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
278280

279281
[[StatsBase]]
280282
deps = ["DataAPI", "DataStructures", "LinearAlgebra", "Missings", "Printf", "Random", "SortingAlgorithms", "SparseArrays", "Statistics"]
281-
git-tree-sha1 = "c53e809e63fe5cf5de13632090bc3520649c9950"
283+
git-tree-sha1 = "19bfcb46245f69ff4013b3df3b977a289852c3a1"
282284
uuid = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
283-
version = "0.32.0"
285+
version = "0.32.2"
284286

285287
[[Syslogs]]
286288
deps = ["Printf", "Sockets"]
@@ -296,31 +298,31 @@ version = "1.0.0"
296298

297299
[[Tables]]
298300
deps = ["DataAPI", "DataValueInterfaces", "IteratorInterfaceExtensions", "LinearAlgebra", "TableTraits", "Test"]
299-
git-tree-sha1 = "951b5be359e92703f886881b175ecfe924d8bd91"
301+
git-tree-sha1 = "aaed7b3b00248ff6a794375ad6adf30f30ca5591"
300302
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
301-
version = "0.2.10"
303+
version = "0.2.11"
302304

303305
[[Test]]
304306
deps = ["Distributed", "InteractiveUtils", "Logging", "Random"]
305307
uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
306308

307309
[[TikzGraphs]]
308-
deps = ["LightGraphs", "Test", "TikzPictures"]
309-
git-tree-sha1 = "244e76babc8c358c8eb93617bcb6789f5cd8cb8b"
310+
deps = ["LaTeXStrings", "LightGraphs", "TikzPictures"]
311+
git-tree-sha1 = "e64460dce33354e2247bfae60da7474e4470cdc2"
310312
uuid = "b4f28e30-c73f-5eaf-a395-8a9db949a742"
311-
version = "1.0.1"
313+
version = "1.1.0"
312314

313315
[[TikzPictures]]
314-
deps = ["LaTeXStrings", "Test"]
315-
git-tree-sha1 = "01a44f70c9b1d592968538e5de528e079f2418b6"
316+
deps = ["LaTeXStrings"]
317+
git-tree-sha1 = "5d83146b4dd45f553de3478a0a8c20c5f8a3cdb2"
316318
uuid = "37f6aa50-8035-52d0-81c2-5a1d08754b2d"
317-
version = "3.0.5"
319+
version = "3.1.0"
318320

319321
[[TimeZones]]
320-
deps = ["Dates", "EzXML", "Mocking", "Printf", "Serialization", "Unicode"]
321-
git-tree-sha1 = "fec20d06d8139c686e6e3ad026bc9cf60bf0c795"
322+
deps = ["Dates", "EzXML", "Mocking", "Printf", "RecipesBase", "Serialization", "Unicode"]
323+
git-tree-sha1 = "db7bc2051d4c2e5f336409224df81485c00de6cb"
322324
uuid = "f269a46b-ccf7-5d73-abea-4c690281aa53"
323-
version = "1.0.0"
325+
version = "1.2.0"
324326

325327
[[UUIDs]]
326328
deps = ["Random"]

src/parsing.jl

+13-10
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,11 @@ _DEFAULT_TYPE_MAP[:tstzrange] = Interval{ZonedDateTime}
369369
_DEFAULT_TYPE_MAP[:daterange] = Interval{Date}
370370

371371
# Matches anything but the start or end of an interval or a comma
372-
const RANGE_ITEM = "[^\\[\\(\\]\\),]+"
373-
# Makes sure the string starts and ends with a bracket or parentheses, has two items in the
374-
# interval, and a comma to separate the two items.
372+
const RANGE_ITEM = "[^\\[\\(\\]\\),]*"
373+
# Makes sure the string starts and ends with a bracket or parentheses and a comma separates
374+
# the items in the interval
375375
const RANGE_REGEX = Regex("^([\\[\\(])($RANGE_ITEM),($RANGE_ITEM)([\\]\\)])\$")
376-
get_inclusivity(ch) = ch in ("[", "]") ? true : false
376+
get_bounds_type(ch::AbstractString) = ch in ("[", "]") ? Closed : Open
377377

378378
function pqparse(::Type{Interval{T}}, str::AbstractString) where {T}
379379
if str == "empty"
@@ -387,14 +387,17 @@ function pqparse(::Type{Interval{T}}, str::AbstractString) where {T}
387387
matched = matched.captures
388388
end
389389

390-
start_inclusivity = get_inclusivity(matched[1])
391-
end_inclusivity = get_inclusivity(matched[4])
392-
393390
# Datetime formats have quotes around them so we strip those out
394-
start = pqparse(T, strip(matched[2], ['"']))
395-
endpoint = pqparse(T, strip(matched[3], ['"']))
391+
start = strip(matched[2], ['"'])
392+
endpoint = strip(matched[3], ['"'])
393+
394+
start = isempty(start) ? nothing : pqparse(T, start)
395+
endpoint = isempty(endpoint) ? nothing : pqparse(T, endpoint)
396+
397+
start_bounds = start === nothing ? Unbounded : get_bounds_type(matched[1])
398+
end_bounds = endpoint === nothing ? Unbounded : get_bounds_type(matched[4])
396399

397-
return Interval(start, endpoint, start_inclusivity, end_inclusivity)
400+
return Interval{T, start_bounds, end_bounds}(start, endpoint)
398401
end
399402

400403
## arrays

src/results.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,14 @@ _array_element(el::AbstractString) = "\"$el\""
359359
_array_element(el::Missing) = "NULL"
360360
_array_element(el) = string_parameter(el)
361361

362-
function string_parameter(interval::AbstractInterval)
363-
inc = inclusivity(interval)
364362

363+
function string_parameter(interval::AbstractInterval)
365364
io = IOBuffer()
366-
print(io, first(inc) ? '[' : '(')
367-
print(io, string_parameter(first(interval)), ", ")
368-
print(io, string_parameter(last(interval)))
369-
print(io, last(inc) ? ']' : ')')
365+
L, R = bounds_types(interval)
366+
print(io, L === Closed ? '[' : '(')
367+
print(io, L === Unbounded ? "" : string_parameter(first(interval)), ",")
368+
print(io, R === Unbounded ? "" : " " * string_parameter(last(interval)))
369+
print(io, R === Closed ? ']' : ')')
370370

371371
return String(take!(io))
372372
end

0 commit comments

Comments
 (0)