Skip to content

fix: prevent bare partition columns from inheriting the previous item's value - #2518

Merged
manticore-projects merged 1 commit into
JSQLParser:masterfrom
fudianchn:fix/hive-mixed-partition-2500
Aug 31, 2026
Merged

fix: prevent bare partition columns from inheriting the previous item's value#2518
manticore-projects merged 1 commit into
JSQLParser:masterfrom
fudianchn:fix/hive-mixed-partition-2500

Conversation

@fudianchn

Copy link
Copy Markdown
Contributor

AI disclosure: this change was prepared with AI coding agents, reviewed and revised line by line by me.

What

A bare (dynamic) partition column no longer inherits the value expression of the preceding item in a mixed INSERT ... PARTITION (...) list; it keeps null again, as before #2323.

Why

With a static item followed by a bare one, the deparser output silently turned the dynamic column into a constant assignment, changing the statement's semantics for Hive mixed static/dynamic partition writes (#2500).

How

Partitions() declares one valueExpression for the whole production and the optional "=" Expression() unit leaves the previous item's value in place when skipped. The list loop arm now resets valueExpression = null before the optional unit, the same idiom already used by DeclareType, Alias and ColumnsNamesList for their list items. No AST, deparser or visitor change: Partition already renders a bare column when the value is null.

Root cause

Production-level valueExpression in Partitions() is shared across list items and was not reset when an item skipped the optional value (introduced with #2323).

Testing

  • New InsertTest#testInsertMixedStaticAndDynamicPartitions covers the full [BUG] JSQLParser 5.4-SNAPSHOT : Hive : INSERT PARTITION bare column inherits the previous item's value #2500 combination table: static -> bare, bare -> static, static -> bare -> bare, bare -> static -> bare, and INSERT INTO with a numeric value. All wrong rows fail on master and pass with the change; the two correct rows are pinned as guards. Two mutants verified: removing the reset and misplacing it after the optional unit both turn the test red.
  • Local run: gradlew test --tests InsertTest -> 79 passed.
  • No jmh run: performance.sql contains no PARTITION clause, the changed action is not reached by the benchmark.

Verification of the original issue

Insert insert = (Insert) CCJSqlParserUtil.parse(
        "INSERT OVERWRITE TABLE t PARTITION (dtime = '20220403', region) SELECT code, region FROM src");
// before: dtime -> '20220403', region -> '20220403'  (wrong)
// after:  dtime -> '20220403', region -> null        (correct)

Fixes #2500

…'s value

Partitions() shares one production-level valueExpression across list
items, so a bare (dynamic) partition column kept the value of the
preceding item: PARTITION (dtime = '2024-04-03', region) deparsed as
region = '2024-04-03', silently turning a dynamic partition into a
static assignment. Reset the variable per item, same idiom as
DeclareType, Alias and ColumnsNamesList.

Fixes JSQLParser#2500

Signed-off-by: 付典 <fudianchn@gmail.com>
@manticore-projects
manticore-projects merged commit 9a32ff5 into JSQLParser:master Aug 31, 2026
7 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

Thank you much!

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.

[BUG] JSQLParser 5.4-SNAPSHOT : Hive : INSERT PARTITION bare column inherits the previous item's value

2 participants