-
Notifications
You must be signed in to change notification settings - Fork 615
Fix array tests #2667
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
Fix array tests #2667
Conversation
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.
Other comments (1)
- jdbc-v2/src/test/java/com/clickhouse/jdbc/internal/JdbcUtilsTest.java (62-63) The test for nested arrays is a good addition, but consider adding a test case for arrays with 3 or more dimensions to ensure the implementation handles deeper nesting correctly.
💡 To request another review, post a new comment with "/windsurf-review".
| arrayDimensions = new int[Math.max(dimensions - stack.size() - 1, 1)]; | ||
| arrayDimensions[0] = srcList.size(); |
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.
There's a potential issue with array dimensions handling. If the actual nesting level of the data exceeds the specified dimensions parameter, it could lead to runtime errors. Consider adding validation or handling for cases where the actual nesting is deeper than expected.
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.
what "potential" issue?
| arrayDimensions = new int[Math.max(dimensions - stack.size() - 1, 1)]; | ||
| arrayDimensions[0] = java.lang.reflect.Array.getLength(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.
Similar to the issue in convertList, the array dimensions calculation in convertArray might not handle all edge cases correctly. Consider adding more robust dimension detection or error handling for mismatched array structures.
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.
what cases?
| while (!stack.isEmpty()) { | ||
| ArrayProcessingCursor cursor = stack.pop(); | ||
|
|
||
| for (int i = 0; i < cursor.size; i++) { | ||
| Object value = cursor.getValue(i); | ||
| if (value == null) { | ||
| continue; // no need to set null value | ||
| } else if (value instanceof List<?>) { | ||
| List<?> srcList = (List<?>) value; | ||
| arrayDimensions = new int[Math.max(dimensions - stack.size() - 1, 1)]; | ||
| arrayDimensions[0] = srcList.size(); | ||
| T[] targetArray = (T[]) java.lang.reflect.Array.newInstance(type, arrayDimensions); | ||
| stack.push(new ArrayProcessingCursor(targetArray, value, srcList.size())); | ||
| java.lang.reflect.Array.set(cursor.targetArray, i, targetArray); | ||
| } else { | ||
| java.lang.reflect.Array.set(cursor.targetArray, i, convert(value, type)); | ||
| } | ||
| } | ||
| } |
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.
The stack-based processing approach could potentially cause a StackOverflowError for deeply nested arrays. Consider adding a maximum depth check or using an iterative approach that's less susceptible to stack overflow issues.
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.
This is a iterative approach. Stack used to organize state.
Client V2 CoverageCoverage Report
Class Coverage
|
JDBC V2 CoverageCoverage Report
Class Coverage
|
JDBC V1 CoverageCoverage Report
Class Coverage
|
|
Client V1 CoverageCoverage Report
Class Coverage
|
| ClickHouseColumn column = ClickHouseColumn.of("arr", "Array(Int32)"); | ||
| List<Integer> src = Arrays.asList(1, 2, 3); | ||
| Integer[] dst = JdbcUtils.convertList(src, Integer.class); | ||
| Integer[] dst = JdbcUtils.convertList(src, Integer.class, 1); |
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.
Shouldn't there be a case with nested array as well?
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.
there is another test. But your are right.
We plan to revisit this code and will do more testing then.



Summary
Fixes issue with nested arrays.
Closes #2457
Checklist
Delete items not relevant to your PR: