Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1495,7 +1495,7 @@ primitiveType
dataType
: complex=ARRAY (LT dataType GT)? #complexDataType
| complex=MAP (LT dataType COMMA dataType GT)? #complexDataType
| complex=STRUCT ((LT complexColTypeList? GT) | NEQ)? #complexDataType
| complex=STRUCT ((LT complexColTypeList? GT) | NEQ {((SqlBaseLexer) getTokenStream().getTokenSource()).decComplexTypeLevelCounter();})? #complexDataType
| primitiveType #primitiveDataType
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1164,4 +1164,27 @@ class SparkSqlParserSuite extends AnalysisTest with SharedSparkSession {
}
}
}

test("SPARK-52709: STRUCT<> should not corrupt complex_type_level_counter") {
// STRUCT<> is tokenized as STRUCT + NEQ by the lexer. The parser must decrement
// the complex_type_level_counter so that subsequent >> is recognized as shift-right.
// Without the fix, this throws a parse error because >> is not recognized.
parser.parsePlan("SELECT CAST(null AS STRUCT<>), 2 >> 1")

// Multiple empty structs should not corrupt the counter
parser.parsePlan("SELECT CAST(null AS STRUCT<>), CAST(null AS STRUCT<>), 4 >> 2")

// Empty struct with unsigned shift right
parser.parsePlan("SELECT CAST(null AS STRUCT<>), 8 >>> 2")

// ARRAY with <> as not-equal operator should still work
parser.parsePlan("SELECT ARRAY(1 <> 2)")

// Nested complex types with >> should still work
parser.parsePlan("SELECT CAST(null AS MAP<STRING, ARRAY<INT>>)")

// Mix of empty struct and nested complex types
parser.parsePlan(
"SELECT CAST(null AS STRUCT<>), CAST(null AS MAP<STRING, ARRAY<INT>>), 2 >> 1")
}
}