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

[client-v2] Fix reading binary streams #1759

Merged
merged 2 commits into from
Aug 2, 2024
Merged

[client-v2] Fix reading binary streams #1759

merged 2 commits into from
Aug 2, 2024

Conversation

chernser
Copy link
Contributor

@chernser chernser commented Aug 2, 2024

Summary

Problem 1

Some streams return 0 when available() called even when data is available. Some streams may throw EOFException while read some may not. So only check for number of read bytes or result of read() really works.

Problem 2

If we want to wrap a stream of data into collection we must properly implement hasNext(). Because of problem#1 we can not do it easily

Solution

  • Check read() result and throw EOFException
  • Read data up-front. It will give some overhead, but it is simplest solution
  • Logic is based on EOFException what is bad, but can be fixed in future with passing error handler to each read or returning tuples (what will be a memory overhead)
    • If EOFException is throw before reading next record - it assumes that if we at the start of row reaching end of stream indicates that no row is sent by server.

Checklist

Delete items not relevant to your PR:

  • Unit and integration tests covering the common scenarios were added
  • A human-readable description of the changes was provided to include in CHANGELOG
  • For significant changes, documentation in https://github.com/ClickHouse/clickhouse-docs was updated with further explanations or tutorials

@chernser chernser requested review from mzitnik and Paultagoras and removed request for mzitnik August 2, 2024 16:41
@@ -272,8 +272,7 @@ public void testBinaryStreamReader() throws Exception {
schema.addColumn("col3", "String");
schema.addColumn("host", "String");
ClickHouseBinaryFormatReader reader = createBinaryFormatReader(queryResponse, settings, schema);
while (reader.hasNext()) {
Assert.assertNotNull(reader.next());
while (reader.next() != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this check to make sure it actually got a value? In theory it could skip this and pass...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Will fix.

Copy link

sonarcloud bot commented Aug 2, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
18.4% Duplication on New Code (required ≤ 3%)

See analysis details on SonarCloud

@chernser chernser merged commit 5a49f48 into main Aug 2, 2024
65 of 66 checks passed
@chernser chernser deleted the fix_reading_binary branch August 2, 2024 20:43
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.

2 participants