From 30b2a5a686135af090cf7e757070143f36cdff84 Mon Sep 17 00:00:00 2001 From: wenxiaojie1 <18635488134@163.com> Date: Thu, 2 Jul 2026 18:16:03 +0800 Subject: [PATCH] Fix Hive SKEWED BY display --- src/ast/ddl.rs | 2 +- tests/sqlparser_hive.rs | 31 +++++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/ast/ddl.rs b/src/ast/ddl.rs index 346627c68..44d53fe54 100644 --- a/src/ast/ddl.rs +++ b/src/ast/ddl.rs @@ -3204,7 +3204,7 @@ impl fmt::Display for CreateTable { } => { write!( f, - " SKEWED BY ({})) ON ({})", + " SKEWED BY ({}) ON ({})", display_comma_separated(columns), display_comma_separated(on) )?; diff --git a/tests/sqlparser_hive.rs b/tests/sqlparser_hive.rs index 21e76e23b..2ff02a316 100644 --- a/tests/sqlparser_hive.rs +++ b/tests/sqlparser_hive.rs @@ -20,11 +20,12 @@ //! Test SQL syntax specific to Hive. The parser based on the generic dialect //! is also tested (on the inputs it can handle). +use sqlparser::ast::helpers::stmt_create_table::CreateTableBuilder; use sqlparser::ast::{ - ClusteredBy, CommentDef, CreateFunction, CreateFunctionBody, CreateFunctionUsing, CreateTable, - Expr, Function, FunctionArgumentList, FunctionArguments, Ident, ObjectName, OrderByExpr, - OrderByOptions, OrderBySort, SelectItem, Set, Statement, TableFactor, UnaryOperator, Use, - Value, + ClusteredBy, ColumnDef, CommentDef, CreateFunction, CreateFunctionBody, CreateFunctionUsing, + CreateTable, DataType, Expr, Function, FunctionArgumentList, FunctionArguments, + HiveDistributionStyle, Ident, ObjectName, OrderByExpr, OrderByOptions, OrderBySort, SelectItem, + Set, Statement, TableFactor, UnaryOperator, Use, Value, }; use sqlparser::dialect::{AnsiDialect, GenericDialect, HiveDialect}; use sqlparser::parser::ParserError; @@ -226,6 +227,28 @@ fn create_table_with_clustered_by() { ); } +#[test] +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" + ); +} + // Turning off this test until we can parse identifiers starting with numbers :( #[test] fn test_identifier() {