Skip to content

fix: struct metadata parsing for nested decimal fields#982

Merged
jayantsing-db merged 5 commits into
databricks:mainfrom
sshpuntoff:fix-decimal-parsing-in-struct-metadata
Sep 9, 2025
Merged

fix: struct metadata parsing for nested decimal fields#982
jayantsing-db merged 5 commits into
databricks:mainfrom
sshpuntoff:fix-decimal-parsing-in-struct-metadata

Conversation

@sshpuntoff
Copy link
Copy Markdown
Contributor

@sshpuntoff sshpuntoff commented Sep 5, 2025

Description

When parsing Struct<Decimal(10,20)>, the driver currently raises an exception:

  java.lang.ArrayIndexOutOfBoundsException: Index 1 out of bounds for length 1
      at com.databricks.jdbc.api.impl.MetadataParser.parseStructMetadata(MetadataParser.java:30)
      at com.databricks.jdbc.api.impl.ComplexDataTypeParser.parseToStruct(ComplexDataTypeParser.java:104)
      at com.databricks.jdbc.api.impl.ComplexDataTypeParser.convertValueNode(ComplexDataTypeParser.java:131)
      at com.databricks.jdbc.api.impl.ComplexDataTypeParser.parseToArray(ComplexDataTypeParser.java:73)

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.

private static String[] splitFields(String metadata) {
int depth = 0;
int angleBracketDepth = 0;
int parenDepth = 0;
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@josecsotomorales
Copy link
Copy Markdown
Contributor

@jayantsing-db can we get a review on this PR? 🙏🏻

@jayantsing-db
Copy link
Copy Markdown
Collaborator

Thanks, approved. I will take care of merging it.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 splitFields method 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.

Comment thread src/main/java/com/databricks/jdbc/api/impl/MetadataParser.java
Signed-off-by: Jayant Singh <jayant.singh@databricks.com>
@jayantsing-db jayantsing-db enabled auto-merge (squash) September 9, 2025 17:53
@jayantsing-db jayantsing-db merged commit 30c2476 into databricks:main Sep 9, 2025
12 of 13 checks passed
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.

4 participants