Repository navigation
Conversation
Dynamic values encode a type descriptor followed by the value. An empty list was encoded as Array(Nothing) without the zero array-length byte, so the driver could not decode its own output and ClickHouse rejected the insert with ATTEMPT_TO_READ_AFTER_EOF. Emit the varint zero length and cover the wire format, adjacent columns, truncated payloads, byte-by-byte incremental decoding, and a live insert. Fixes plausible#454
ruslandoga
reviewed
Nov 27, 2026
| %Date{} -> [0x0F | encode(:date, value)] | ||
| %NaiveDateTime{} -> [0x11 | encode(:datetime, value)] | ||
| [] -> [0x1E, 0x00] | ||
| [] -> [0x1E, 0x00, 0] |
Collaborator
There was a problem hiding this comment.
Suggested change
| [] -> [0x1E, 0x00, 0] | |
| [] -> [0x1E, 0, 0] |
Collaborator
There was a problem hiding this comment.
and maybe we could add a comment what these two zeroes mean
Collaborator
|
Thank you for the fix! |
Collaborator
|
Could you also please update the changelog and add this PR to the Unreleased section 3c0c4c3? |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #454
Root cause
Ch.RowBinary.encode(:dynamic, [])atlib/ch/row_binary.ex:478emitted only theArray(Nothing)type descriptor (0x1E, 0x00) and omitted thevarintarray-length byte. The Dynamic wire format is<type descriptor><value>, so an empty array must be<<0x1E, 0x00, 0x00>>. Without the trailing zero the driver cannot decode its own output, and ClickHouse rejects the insert withATTEMPT_TO_READ_AFTER_EOF(or, as observed on 26.11,Serialization is not implemented for type Nothing).%NaiveDateTime{} -> [0x11 | encode(:datetime, value)] - [] -> [0x1E, 0x00] + [] -> [0x1E, 0x00, 0] endTests
test/ch/row_binary_test.exs:511asserts the exact three-byte wire format, round-trips, and that a truncated two-byte payload still reports incomplete data.test/ch/row_binary_test.exs:517covers an empty Dynamic array adjacent to a following column, so the missing length cannot swallow the next field's bytes.dynamicbyte-by-byte test now includes empty arrays (and two of them in one row), which exercises every split throughdecode_rows_continue/3.test/ch/dynamic_test.exs:37restores the previously commented-out live insert assertion for[].Evidence (local, ClickHouse 26.11.4.11, Elixir 1.20.5 / OTP 29)
Before the fix, with the new tests applied to
master:After the fix:
Full suite, compared against a clean
mastercheckout:The 6 failures are identical and pre-existing in this environment (4 ×
Ch.HTTPTestuser-agent assertions, 2 ×Ch.ConnectionTest"select with params"; the local ClickHouse reports timezoneAsia/Singapore).mix format --check-formattedandmix compile --warnings-as-errorspass.