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

StreamFailureError when querying JSON containing Tuple(Int8, String) #466

Open
martijnthe opened this issue Feb 5, 2025 · 0 comments
Open
Labels
bug Something isn't working

Comments

@martijnthe
Copy link
Contributor

martijnthe commented Feb 5, 2025

Describe the bug

A StreamFailureError is raised when executing a query that contains a column with JSON datatype, containing a Tuple(Int8, String).

Steps to reproduce

Example query:

SELECT '{"k": [123, "xyz"]}'::JSON SETTINGS input_format_json_read_numbers_as_strings = 0;

Apply this patch with unit test case and run the test:

diff --git a/tests/integration_tests/test_dynamic.py b/tests/integration_tests/test_dynamic.py
index bb8df62..f2a1821 100644
--- a/tests/integration_tests/test_dynamic.py
+++ b/tests/integration_tests/test_dynamic.py
@@ -162,3 +162,14 @@ def test_json_str_time(test_client: Client):
         pytest.skip('JSON string/numbers bug before 25.1, skipping')
     result = test_client.query("SELECT '{\"timerange\": \"2025-01-01T00:00:00+0000\"}'::JSON").result_set
     assert result[0][0]['timerange'] == datetime.datetime(2025, 1, 1)
+
+def test_json_mixed_array(test_client: Client):
+    type_available(test_client, 'json')
+    if not test_client.min_version('24.10'):
+        pytest.skip('Complex JSON broken before 24.10')
+
+    # Raises:
+    # clickhouse_connect.driver.exceptions.StreamFailureError: unrecognized data found in stream: `000000000000000101135475706c6528496e74382c20537472696e67290000000000000000017b0378797a0000000000000000`
+    result = test_client.query('SELECT \'{"k": [123, "xyz"]}\'::JSON SETTINGS input_format_json_read_numbers_as_strings = 0')
+    json1 = result.result_set[0][0]
+    assert json1 == {'k': [123, 'xyz']}
                   raise StreamFailureError(extract_error_message(source.last_message)) from None
E                   clickhouse_connect.driver.exceptions.StreamFailureError: unrecognized data found in stream: `000000000000000101135475706c6528496e74382c20537472696e67290000000000000000017b0378797a0000000000000000`

Expected behaviour

The above test should pass and no StreamFailureError should be raised.

Code example

See patch above.

clickhouse-connect and/or ClickHouse server logs

Configuration

Environment

  • clickhouse-connect version: master (8d88b1c)
  • Python version: 3.10
  • Operating system: mac OS

ClickHouse server

  • ClickHouse Server version: 24.12
@martijnthe martijnthe added the bug Something isn't working label Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant