Skip to content

Conversation

sshpuntoff
Copy link

@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.

@@ -94,25 +94,33 @@ public static String parseMapMetadata(String metadata) {
* @return an array of field definitions in the STRUCT
*/
private static String[] splitFields(String metadata) {
int depth = 0;
int angleBracketDepth = 0;
int parenDepth = 0;
Copy link
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.

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.

1 participant