Skip to content
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

Fix binary decoders #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jeremyrsmith
Copy link

I did this because many of the binary decoders were incorrect.

  • Remove existing binary decoder tests and replace with integration tests against postgres
    (To verify that they do actually decode the actual PG binary representation)
  • Update existing binary decoders for date/timestamp/time, string, and json
  • Add hstore decoder
  • Add numeric decoder

I did this because many of the binary decoders were incorrect.

- Remove existing binary decoder tests and replace with integration tests against postgres
  (To verify that they do actually decode the actual PG binary representation)
- Update existing binary decoders for date/timestamp/time, string, and json
- Add hstore decoder
- Add numeric decoder
@codecov-io
Copy link

Current coverage is 83.13%

Merging #72 into master will decrease coverage by 3.83%

@@             master        #72   diff @@
==========================================
  Files            18         18          
  Lines           760        836    +76   
  Methods         748        819    +71   
  Messages          0          0          
  Branches         12         17     +5   
==========================================
+ Hits            661        695    +34   
- Misses           99        141    +42   
  Partials          0          0          

Sunburst

Powered by Codecov. Last updated by 0161b7c...63088d4

@@ -23,7 +26,7 @@ object decoders {

implicit val stringElementDecoder: ElementDecoder[String] = new ElementDecoder[String] {
def textDecoder(text: String): String = text
def binaryDecoder(bytes: Array[Byte]): String = bytes.map(_.toChar).mkString
Copy link
Contributor

@penland365 penland365 Jun 28, 2016

Choose a reason for hiding this comment

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

Nice catch. My brain wasn't working when I originally wrote that for some reason.

Copy link
Author

Choose a reason for hiding this comment

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

The binary decoder tests only tested some arbitrary notion of what they should decode. That's why I removed them in favor of integration tests which test against what Postgres is actually going to send.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I missed a decent portion of these. I read the documentation, then went to look at the actual "authorized" Postgres JDBC driver, and the only portion of the code I saw was for dealing w/ the standard Short / Int / Long / Float / Double Big Endian format. If I recall ( from somewhere ), I put some of the other "binary" decoders out as the documentation specified that if no Binary version was found, it was assumed to be the Text Version.

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, for binary decoders you pretty much have to look at the postgres source itself and port it from C to Scala. These were built by porting the *recv functions from backend/utils/adt in the postgres source tree.

val buf = ByteBuffer.wrap(bytes)
Xor.catchNonFatal {
val count = buf.getInt()
val charset = StandardCharsets.UTF_8 //TODO: are we going to support other charsets?
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, we will at some point, but I was putting off updating the current Charset in the Client Dispatcher until I had figured out how I wanted to represent the Connection State Machine.

I just opened #73 for a discussion on it.

Copy link
Author

Choose a reason for hiding this comment

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

finagle-postgres has a pretty battle-tested state machine. I know its other code is somewhat dated/non-idiomatic but the state machine seems pretty robust.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, most of the current machines were written after not so much a copy paste, but a heavy look over from that code base.

Copy link
Author

Choose a reason for hiding this comment

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

I think some benefit could be had from bringing over its state machine - it supports a lot of features currently missing from roc (like the parse-bind-execute query flow)

@penland365
Copy link
Contributor

All of this looks great! I'm super excited to accept a PR for this :) . If you can delete those unit tests that aren't being called, I think this is ready to go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants