Skip to content

[BUG] MetadataParser unable to parse Struct<Decimal(10, 20)> #981

@sshpuntoff

Description

@sshpuntoff

Describe the bug
The driver throws an ArrayIndexOutOfBoundsException when parsing STRUCT metadata containing DECIMAL fields with precision and scale (e.g., DECIMAL(18,2)). The
MetadataParser.parseStructMetadata() method incorrectly splits STRUCT field definitions at commas inside parentheses, causing malformed field parsing.

To Reproduce
You can simply test the logic in MetaDataParserTest

  @Test
  @DisplayName("parseStructMetadata with DECIMAL precision and scale")
  public void testParseStructMetadata_WithDecimalPrecisionScale() {
    String metadata = "STRUCT<name:STRING, amount:DECIMAL(18,2)>";
    Map<String, String> expected = new LinkedHashMap<>();
    expected.put("name", "STRING");
    expected.put("amount", "DECIMAL(18,2)");

    Map<String, String> actual = MetadataParser.parseStructMetadata(metadata);
    assertEquals(
        expected,
        actual,
        "Parsed struct metadata with DECIMAL precision and scale should handle parentheses correctly.");
  }

Client side logs

  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)

Client Environment (please complete the following information):

  • OS: MAC/Linux
  • Java version 21
  • Java vendor OpenJDK
  • Driver Version

Additional context
Complex datatypes and Arrow must be enabled for this to happen in a run time environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions