apache / datafusion-sqlparser-rs

Extensible SQL Lexer and Parser for Rust
Apache License 2.0
2.8k stars 541 forks source link

tests/sqlparser_common.rs / parse_create_view_with_options gives different results with ClickHouseDialect #1449

Open joshuawarner32 opened 1 month ago

joshuawarner32 commented 1 month ago

When changing the test to include ClickHouseDialect, it fails like so:

---- parse_create_view_with_columns stdout ----
thread 'parse_create_view_with_columns' panicked at src/test_utils.rs:77:21:
assertion `left == right` failed: Parse results with DatabricksDialect are different from ClickHouseDialect
  left: Ok([CreateView { or_replace: false, materialized: false, name: ObjectName([Ident { value: "v", quote_style: None }]), columns: [ViewColumnDef { name: Ident { value: "has", quote_style: None }, data_type: None, options: None }, ViewColumnDef { name: Ident { value: "cols", quote_style: None }, data_type: None, options: None }], query: Query { with: None, body: Select(Select { distinct: None, top: None, projection: [UnnamedExpr(Value(Number("1", false))), UnnamedExpr(Value(Number("2", false)))], into: None, from: [], lateral_views: [], prewhere: None, selection: None, group_by: Expressions([], []), cluster_by: [], distribute_by: [], sort_by: [], having: None, named_window: [], qualify: None, window_before_qualify: false, value_table_mode: None, connect_by: None }), order_by: None, limit: None, limit_by: [], offset: None, fetch: None, locks: [], for_clause: None, settings: None, format_clause: None }, options: None, cluster_by: [], comment: None, with_no_schema_binding: false, if_not_exists: false, temporary: false, to: None }])
 right: Err(ParserError("Expected: a data type name, found: ,"))
stack backtrace:
   0: rust_begin_unwind
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/std/src/panicking.rs:652:5
   1: core::panicking::panic_fmt
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/panicking.rs:72:14
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/panicking.rs:363:5
   4: sqlparser::test_utils::TestedDialects::one_of_identical_results::{{closure}}
             at ./src/test_utils.rs:77:21
   5: core::iter::adapters::map::map_fold::{{closure}}
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/iter/adapters/map.rs:89:21
   6: <core::slice::iter::Iter<T> as core::iter::traits::iterator::Iterator>::fold
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/slice/iter/macros.rs:230:27
   7: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/iter/adapters/map.rs:129:9
   8: sqlparser::test_utils::TestedDialects::one_of_identical_results
             at ./src/test_utils.rs:74:9
   9: sqlparser::test_utils::TestedDialects::parse_sql_statements
             at ./src/test_utils.rs:101:9
  10: sqlparser::test_utils::TestedDialects::one_statement_parses_to
             at ./src/test_utils.rs:132:30
  11: sqlparser::test_utils::TestedDialects::verified_stmt
             at ./src/test_utils.rs:161:9
  12: sqlparser_common::parse_create_view_with_columns
             at ./tests/sqlparser_common.rs:6799:11
  13: sqlparser_common::parse_create_view_with_columns::{{closure}}
             at ./tests/sqlparser_common.rs:6796:36
  14: core::ops::function::FnOnce::call_once
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/ops/function.rs:250:5
  15: core::ops::function::FnOnce::call_once
             at /rustc/051478957371ee0084a7c0913941d2a8c4757bb9/library/core/src/ops/function.rs:250:5
git-hulk commented 1 month ago

There are two potential issues:

  1. all_dialects doesn't contain the ClickHouse dialect for now
  2. ClickHouse's create view requires the data type after the column name

I think we can add the ClickHouse dialect and fix those test cases. cc @alamb

joshuawarner32 commented 1 month ago

Ah yeah sorry - this goes with #1447; should have added that context there. I added ClickHouse to all_dialects in that PR and manually excluded it from the one test that failed. I filed this to make sure that doesn't get forgotten.

git-hulk commented 1 month ago

@joshuawarner32 Great!