-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query Basic Types in Binary Format #223
Conversation
Got around to testing this. Here's are some results.
In this test, using binary was slower to execute and download and transferred more bytes. All the other metrics are pretty indistinguishable. This makes sense because transferring an integer in string format could save space by having variable length strings, where as transferring it as bytes causes use to transfer all the bytes to represent the number. (an example is the number |
Is this ready to merge into master even though we've only implemented binary for 1 data type? Should we hold off until we implement more? Should we add a warning if someone tries to use binary data? Add a warning in the docs? Or just have a generic catch all implementation that someone can override? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From what I grasped (which is admittedly not much), the PR looks good to me.
Regarding whether to merge and how to signal to users, given that our plan is to only implement a subset of all types for now, we should be fine with merging this, but have clear warnings in place.
In the documentation and docstrings (saying binary format is an experimental feature, listing the types supported), but also the code itself. Ideally we should throw an exception before the query is executed if an unsupported type is requested using binary format, though it's probably not the end of the world if the exception happens after while parsing. As long as we error somewhere.
Currently, if we try parsing something like a decimal, it will error while parsing because instead of parsing something like I could add something like function Base.parse(::Type{T}, pqv::PQValue{R, BINARY}) where {T, R}
error("Parsing for Type $T and OID $R in binary has not been implemented")
end How does that seem? |
Ah, yeah we shouldn't rely on the bytes being parseable or not for different types (I can imagine the same bytes being valid representations of different types). I was assuming that with the existing method signatures we'd get a "no method matching" error if we passed a type that we don't support for binary. If not, then yes it sounds like your proposed solution would achieve that (but better check with @iamed2). |
Adding a not-implemented method is an antipattern; we should rely on errors before dispatch (MethodErrors or other). I think we can accomplish this by restricting a lot of the default/fallback methods to where they're actually applicable. For example, As an aside, it might be useful to have: const PQTextValue{OID} = PQValue{OID,TEXT}
const PQBinaryValue{OID} = PQValue{OID,BINARY} One thing I also see is the column type defaulting to |
I think we should implement, to start:
|
src/parsing.jl
Outdated
|
||
function parse_numeric_array(eltype::Type{T}, str::AbstractString) where T | ||
function parse_numeric_array(eltype::Type{T}, str::AbstractString) where {T} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't put where clauses in brackets if they are in long-form function definitions and fit on a single line.
src/results.jl
Outdated
jl_result.column_oids = col_oids = map(1:num_columns(jl_result)) do col_num | ||
libpq_c.PQftype(jl_result.result, col_num - 1) | ||
end | ||
jl_result.column_oids = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No dangling assignments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please apply this in other places as well. I will make an issue for including specifically chained assignments on one line in BlueStyle as well to be official.
test/runtests.jl
Outdated
@@ -275,6 +292,292 @@ end | |||
close(conn) | |||
end | |||
|
|||
|
|||
@testset "Binary" begin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How close is this test section to tests above? Could any of it be put in a loop over (TEXT, BINARY)
? Especially around the data parsing, could it loop over the data and decide whether to mark it as broken/unimplemented depending on whether the type is part of an implemented list of types? This would help remove duplication of tests and avoid them getting out of sync.
Docstrings should be updated for the Please make this issue: #223 (comment) |
Here's the issue for numeric types #225 |
It seems that most of the coverage misses in the diff are where the formatter added more lines. I don't think any code that I wrote and was being hit before is missed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be sure to squash when (or before) merging!
TODO
This PR is focusing on using LibPQ to query integer values.