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

fixed issue with null in legacy driver's json response deserializer + test #879

Merged
merged 1 commit into from
Apr 4, 2022

Conversation

debychkov
Copy link
Contributor

Hi, it seems, that I missed one corner case in #862

If there is NaN in response it is written as null in json "data", and my deserializer didn't check that.

This time I ran my fix through our internal tests (with wide selection of prod-like queries), and it seems that now response is deserialized like it used to before.

Example with NaN:

        String connectionUrl = "jdbc:clickhouse://localhost:8123/default";
        ClickHouseConnection clickHouseConnection = (ClickHouseConnection) DataSourceUtils.getConnection(
                new ClickHouseDataSource(connectionUrl, new ClickHouseProperties()));
        ClickHouseResponse clickHouseResponse = clickHouseConnection.createStatement().executeQueryClickhouseResponse("SELECT 0/0 AS n");

It failed with exception:

Exception in thread "main" java.lang.IllegalArgumentException: unexpected jsonElementType: null
	at ru.yandex.clickhouse.response.ClickHouseResponseGsonDeserializer.getAsString(ClickHouseResponseGsonDeserializer.java:82)
	at ru.yandex.clickhouse.response.ClickHouseResponseGsonDeserializer.lambda$getAsStringArray$2(ClickHouseResponseGsonDeserializer.java:69)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at ru.yandex.clickhouse.response.ClickHouseResponseGsonDeserializer.getAsStringArray(ClickHouseResponseGsonDeserializer.java:68)
	at ru.yandex.clickhouse.response.ClickHouseResponseGsonDeserializer.lambda$deserialize$1(ClickHouseResponseGsonDeserializer.java:32)
	at java.base/java.lang.Iterable.forEach(Iterable.java:75)
	at ru.yandex.clickhouse.response.ClickHouseResponseGsonDeserializer.deserialize(ClickHouseResponseGsonDeserializer.java:31)
	at ru.yandex.clickhouse.response.ClickHouseResponseGsonDeserializer.deserialize(ClickHouseResponseGsonDeserializer.java:14)
	at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:69)

@debychkov
Copy link
Contributor Author

One failed test, but I don't think it is related to my pr

Error:  Tests run: 251, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 18.907 s <<< FAILURE! - in TestSuite
Error:  com.clickhouse.jdbc.ClickHousePreparedStatementTest.testInsertWithFunction  Time elapsed: 0.021 s  <<< FAILURE!
java.sql.BatchUpdateException: 
Code: 441. DB::Exception: Invalid IPv6 value: while executing 'FUNCTION if(isNull(IPv4ToIPv6(toIPv4(_dummy_0))) : 3, defaultValueOfTypeName('IPv6') :: 2, _CAST(IPv4ToIPv6(toIPv4(_dummy_0)), 'IPv6') :: 5) -> if(isNull(IPv4ToIPv6(toIPv4(_dummy_0))), defaultValueOfTypeName('IPv6'), _CAST(IPv4ToIPv6(toIPv4(_dummy_0)), 'IPv6')) IPv6 : 1': While executing ValuesBlockInputFormat. (CANNOT_PARSE_DOMAIN_VALUE_FROM_STRING) (version 22.3.2.1)
, server ClickHouseNode(addr=http:localhost:49176, db=test_preparedstatement)@-1017961213
	at com.clickhouse.jdbc.ClickHousePreparedStatementTest.testInsertWithFunction(ClickHousePreparedStatementTest.java:920)

@zhicwu
Copy link
Contributor

zhicwu commented Mar 20, 2022

Thank you @debychkov! I'll merge the pull request after some more testing(null value, NaN and ±Inf etc.).

As to the build failure, it's irrelevant since it's a server side issue. I filed ClickHouse/ClickHouse#35449 hoping it will be fixed soon.

@zhicwu zhicwu merged commit 9140754 into ClickHouse:develop Apr 4, 2022
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