Skip to content

Hive: Parse and correctly display SKEWED BY clauses - #2395

Open
wenxiaojie1 wants to merge 5 commits into
apache:mainfrom
wenxiaojie1:fix-hive-skewed-by-display
Open

wenxiaojie1 wants to merge 5 commits into
apache:mainfrom
wenxiaojie1:fix-hive-skewed-by-display

Conversation

@wenxiaojie1

@wenxiaojie1 wenxiaojie1 commented Jul 2, 2026 •

Copy link
Copy Markdown

Fixes #1499.

Example: CREATE TABLE t (id STRING) SKEWED BY (id) ON ('a', 'b') STORED AS DIRECTORIES.

  • Store skewed column identifiers and constant value tuples instead of column definitions.
  • Parse skewed clauses for Hive/Generic ordinary and external tables.
  • Preserve PARTITIONED BY -> CLUSTERED BY -> SKEWED BY order, including combined partitioned/skewed tables.
  • Replace the invalid AST-only display test with valid SQL round trips and malformed-input regression tests.
  • Correct the public SKEWED AST fields and add a combined partitioned/skewed variant.

Syntax checked against the official Hive DDL and Hive 4.0.1 grammar.

Checks: cargo test --all-features (1707 passed), cargo fmt --all -- --check, cargo +nightly clippy --all-targets --all-features -- -D warnings.
Local fuzzing is blocked by Windows/MSVC libFuzzer linker errors; no iterations completed. Upstream CI requires maintainer approval.

AI assistance was used for implementation and tests.

Comment thread tests/sqlparser_hive.rs Outdated
Comment on lines +231 to +249
fn display_create_table_with_skewed_by() {
let column = |name| ColumnDef {
name: Ident::new(name),
data_type: DataType::String(None),
options: vec![],
};
let stmt = CreateTableBuilder::new(ObjectName::from(vec![Ident::new("test")]))
.columns(vec![column("id")])
.hive_distribution(HiveDistributionStyle::SKEWED {
columns: vec![column("id")],
on: vec![column("id")],
stored_as_directories: true,
})
.build();

assert_eq!(
stmt.to_string(),
"CREATE TABLE test (id STRING) SKEWED BY (id STRING) ON (id STRING) STORED AS DIRECTORIES"
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@wenxiaojie1 wenxiaojie1 Aug 7, 2026 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Thanks. I tried the verified_stmt form, but the current Hive parser rejects this syntax with Expected: end of statement, found: SKEWED. Issue #1499 explicitly notes that SKEWED BY cannot currently be parsed. I kept the explicit AST construction so the test remains scoped to the reported display bug rather than adding parser support in this PR. The focused test still passes.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

not sure I follow, if the parser doesn't accept the syntax then sounds like something more fundamental is wrong if the test was valid?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That separation is intentional for this issue. #1499 explicitly notes that SKEWED BY cannot currently be parsed and reports the extra ) in the existing CreateTable display path. HiveDistributionStyle::SKEWED is nevertheless a public AST variant that callers can construct programmatically (including through CreateTableBuilder), so its malformed SQL output is independently observable.

The AST-construction test exercises that exact display regression without expanding this small fix into parser support; parse_hive_distribution still has the separate TODO: Support parsing for SKEWED distribution style. If parser support is intended to be a prerequisite for fixing the formatter, I can revise the scope, but I read #1499 as deliberately limited to stringification.

Comment thread tests/sqlparser_hive.rs Outdated
@codecov-commenter

codecov-commenter commented Oct 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.15596% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.30%. Comparing base (7b5821d) to head (555932a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/ast/ddl.rs 70.83% 0 Missing and 7 partials ⚠️
src/parser/mod.rs 90.78% 2 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2395      +/-   ##
==========================================
+ Coverage   81.24%   81.30%   +0.06%     
==========================================
  Files          42       42              
  Lines       33901    34003     +102     
  Branches    33901    34003     +102     
==========================================
+ Hits        27543    27647     +104     
+ Misses       2792     2783       -9     
- Partials     3566     3573       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@LucaCappelletti94 LucaCappelletti94 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Removing the extra ) is correct, but the new test can't catch a wrong rendering, and that is why CI is currently not red.

It builds the AST by hand and compares to_string() with a hand-written string that matches what the printer emits, and since the parser has no SKEWED BY support at this time, nothing reads that string back. That is why CI is green even though the expected string is invalid Hive. Hive 4.0.1 rejects CREATE TABLE test (id STRING) SKEWED BY (id STRING) ON (id STRING) STORED AS DIRECTORIES with ParseException line 1:42 extraneous input 'STRING' expecting ) near '(' in skewed value element.

The cause is the AST shape. Hive's SKEWED BY takes bare column names and its ON takes constant values such as ON ('a', 'b'), while HiveDistributionStyle::SKEWED stores both as Vec<ColumnDef>. No value of the current variant renders a valid ON clause, and even SKEWED BY (id) ON (id) is rejected. This is the more fundamental problem @iffyio pointed at.

Could you change SKEWED to hold the column identifiers and the skewed value tuples, parse it in parse_hive_distribution, and test it with hive().verified_stmt(...)? Hive also expects SKEWED BY after CLUSTERED BY ... INTO n BUCKETS, while the display writes it before, so the round trip should cover that order too.

@LucaCappelletti94 LucaCappelletti94 added enhancement New feature or request waiting on contributor The review needs further refinements by its author labels Oct 17, 2026
@wenxiaojie1 wenxiaojie1 changed the title Fix Hive SKEWED BY display Hive: Parse and correctly display SKEWED BY clauses Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Hive waiting on contributor The review needs further refinements by its author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

typo in Hive SKEWED BY stringification

4 participants