fix: struct metadata parsing for nested decimal fields#982
Conversation
| private static String[] splitFields(String metadata) { | ||
| int depth = 0; | ||
| int angleBracketDepth = 0; | ||
| int parenDepth = 0; |
There was a problem hiding this comment.
there is a case to be made that just a single
int depth = 0; would work correctly here, and the code below just needs to be
if (ch == '<' || ch == '(') {
depth ++;
}
else if (ch == '>' || ch == ')') {
depth --;
}
Which would simplify the change set even more.
Let me know if you prefer a minimal diff over the explicit variable names.
|
@jayantsing-db can we get a review on this PR? 🙏🏻 |
|
Thanks, approved. I will take care of merging it. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a bug in the JDBC driver's metadata parsing for nested decimal fields within struct types. The driver was failing with an ArrayIndexOutOfBoundsException when parsing complex struct metadata containing decimal types with precision and scale parameters due to improper comma splitting that didn't account for parentheses depth.
- Fixed the
splitFieldsmethod to track both angle bracket and parentheses depth when parsing struct metadata - Added comprehensive test coverage for various combinations of decimal fields in struct types
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/main/java/com/databricks/jdbc/api/impl/MetadataParser.java | Enhanced field splitting logic to properly handle parentheses depth alongside angle bracket depth |
| src/test/java/com/databricks/jdbc/api/impl/MetadataParserTest.java | Added 6 new test cases covering decimal fields in simple, nested, and complex struct scenarios |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Signed-off-by: Jayant Singh <jayant.singh@databricks.com>
Description
When parsing Struct<Decimal(10,20)>, the driver currently raises an exception:
This occurs because the current implementation does not expect nested comma's in datatypes.
By tracking the Depth of the
()characters, we can successfully parse complex datatypes.Issue:
#981
Testing
Unit tests expanded and local testing done.
Additional Notes to the Reviewer
This is a bug in the implementation of the MetaDataParser and is pretty direct to re-produce and correct.