-
Notifications
You must be signed in to change notification settings - Fork 618
Accept 1/0 for boolean configuration values #2740
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
base: main
Are you sure you want to change the base?
Conversation
| Assert.assertTrue(ClickHouseUtils.parseBoolean("true")); | ||
| Assert.assertFalse(ClickHouseUtils.parseBoolean("false")); | ||
|
|
||
| // unrecognized values should be parsed as false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chernser shouldn't we throw an exception for unrecognized values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is an unrecognized value, then we should also follow the behavior pattern of other configs in this case.
For example, the default_query_settings config accepts a set of settings, else null by default. Now, if someone sets a random setting that is not used by Clickhouse then does it throw an error, or simply ignores that?
Similarly, jdbc_sql_parser accepts 1 of 3 enum constants. Does it throw an error if any other value is passed?
If we throw an exception only for boolean types and simply ignore for other types, then it will create inconsistent behaviour. Please let me know your thoughts on this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kailash360 both mentioned settings are not validated but should.
jdbc_sql_parser will throw exception later while creating connection. That is not correct and we will fix it.
Most Client configurations validated in the Builder.
Please add throwing exception if boolean value is not what we expect.
Thanks!
|
@kailash360 |
|
@kailash360 We currently still supporting java 8. |
| * @param value string value | ||
| * @return parsed boolean, or {@code false} if value is null or unrecognized | ||
| */ | ||
| public static boolean parseBoolean(String value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this method to client-v2
I suggest utilizing ValueConverters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PS: clickhouse-data is an old package that we may deprecate so V2 should minimize dependencies on it. Besides clickhouse-data relates to client-v1 and this method is not used there.
chernser
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please apply suggested changes.
Thanks!
Summary
This PR standardizes boolean parsing across modules so configuration values accept both
true/falseand1/0(withnull/unrecognized values treated as false). This improves compatibility with tools and environments that only emit numeric booleans.Closes
Checklist
Delete items not relevant to your PR:
1and0for boolean properties #2730Note
Medium Risk
Behavior changes for boolean parsing in config and value conversion paths could alter outcomes for previously non-standard string values, though the change is small and well-covered by new tests.
Overview
Standardizes boolean parsing across
clickhouse-data,client-v2, andjdbc-v2by introducingClickHouseUtils.parseBoolean(String)(supportstrue/falseand1/0, defaults tofalsefor null/unknown) and routing existing boolean parsing through it.Updates client config parsing (
ClientConfigProperties.parseValue), string-to-boolean conversions in serialization/value conversion helpers (SerializerUtils,ValueConverters), and JDBC driver flags (JdbcConfiguration) to use the new parser, and adds targeted unit tests covering numeric and textual boolean inputs.Written by Cursor Bugbot for commit 3128606. This will update automatically on new commits. Configure here.