Support some of pipe operators (#1759)

This commit is contained in:
Simon Vandel Sillesen 2025-05-02 05:13:47 +02:00 committed by GitHub
parent a5b9821d1d
commit e5d2215267
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 427 additions and 21 deletions

View file

@ -489,6 +489,7 @@ fn parse_update_set_from() {
for_clause: None,
settings: None,
format_clause: None,
pipe_operators: vec![],
}),
alias: Some(TableAlias {
name: Ident::new("t2"),
@ -4310,6 +4311,7 @@ fn parse_create_table_as_table() {
for_clause: None,
settings: None,
format_clause: None,
pipe_operators: vec![],
});
match verified_stmt(sql1) {
@ -4335,6 +4337,7 @@ fn parse_create_table_as_table() {
for_clause: None,
settings: None,
format_clause: None,
pipe_operators: vec![],
});
match verified_stmt(sql2) {
@ -6332,6 +6335,7 @@ fn parse_interval_and_or_xor() {
for_clause: None,
settings: None,
format_clause: None,
pipe_operators: vec![],
}))];
assert_eq!(actual_ast, expected_ast);
@ -9467,6 +9471,7 @@ fn parse_merge() {
for_clause: None,
settings: None,
format_clause: None,
pipe_operators: vec![],
}),
alias: Some(TableAlias {
name: Ident {
@ -11344,6 +11349,7 @@ fn parse_unload() {
order_by: None,
settings: None,
format_clause: None,
pipe_operators: vec![],
}),
to: Ident {
value: "s3://...".to_string(),
@ -12564,6 +12570,7 @@ fn test_extract_seconds_ok() {
for_clause: None,
settings: None,
format_clause: None,
pipe_operators: vec![],
}))];
assert_eq!(actual_ast, expected_ast);
@ -14641,6 +14648,7 @@ fn test_select_from_first() {
for_clause: None,
settings: None,
format_clause: None,
pipe_operators: vec![],
};
assert_eq!(expected, ast);
assert_eq!(ast.to_string(), q);
@ -15020,6 +15028,82 @@ fn parse_set_names() {
dialects.verified_stmt("SET NAMES UTF8 COLLATE bogus");
}
#[test]
fn parse_pipeline_operator() {
let dialects = all_dialects_where(|d| d.supports_pipe_operator());
// select pipe operator
dialects.verified_stmt("SELECT * FROM users |> SELECT id");
dialects.verified_stmt("SELECT * FROM users |> SELECT id, name");
dialects.verified_query_with_canonical(
"SELECT * FROM users |> SELECT id user_id",
"SELECT * FROM users |> SELECT id AS user_id",
);
dialects.verified_stmt("SELECT * FROM users |> SELECT id AS user_id");
// extend pipe operator
dialects.verified_stmt("SELECT * FROM users |> EXTEND id + 1 AS new_id");
dialects.verified_stmt("SELECT * FROM users |> EXTEND id AS new_id, name AS new_name");
dialects.verified_query_with_canonical(
"SELECT * FROM users |> EXTEND id user_id",
"SELECT * FROM users |> EXTEND id AS user_id",
);
// set pipe operator
dialects.verified_stmt("SELECT * FROM users |> SET id = id + 1");
dialects.verified_stmt("SELECT * FROM users |> SET id = id + 1, name = name + ' Doe'");
// drop pipe operator
dialects.verified_stmt("SELECT * FROM users |> DROP id");
dialects.verified_stmt("SELECT * FROM users |> DROP id, name");
// as pipe operator
dialects.verified_stmt("SELECT * FROM users |> AS new_users");
// limit pipe operator
dialects.verified_stmt("SELECT * FROM users |> LIMIT 10");
dialects.verified_stmt("SELECT * FROM users |> LIMIT 10 OFFSET 5");
dialects.verified_stmt("SELECT * FROM users |> LIMIT 10 |> LIMIT 5");
dialects.verified_stmt("SELECT * FROM users |> LIMIT 10 |> WHERE true");
// where pipe operator
dialects.verified_stmt("SELECT * FROM users |> WHERE id = 1");
dialects.verified_stmt("SELECT * FROM users |> WHERE id = 1 AND name = 'John'");
dialects.verified_stmt("SELECT * FROM users |> WHERE id = 1 OR name = 'John'");
// aggregate pipe operator full table
dialects.verified_stmt("SELECT * FROM users |> AGGREGATE COUNT(*)");
dialects.verified_query_with_canonical(
"SELECT * FROM users |> AGGREGATE COUNT(*) total_users",
"SELECT * FROM users |> AGGREGATE COUNT(*) AS total_users",
);
dialects.verified_stmt("SELECT * FROM users |> AGGREGATE COUNT(*) AS total_users");
dialects.verified_stmt("SELECT * FROM users |> AGGREGATE COUNT(*), MIN(id)");
// aggregate pipe opeprator with grouping
dialects.verified_stmt(
"SELECT * FROM users |> AGGREGATE SUM(o_totalprice) AS price, COUNT(*) AS cnt GROUP BY EXTRACT(YEAR FROM o_orderdate) AS year",
);
dialects.verified_stmt(
"SELECT * FROM users |> AGGREGATE GROUP BY EXTRACT(YEAR FROM o_orderdate) AS year",
);
dialects
.verified_stmt("SELECT * FROM users |> AGGREGATE GROUP BY EXTRACT(YEAR FROM o_orderdate)");
dialects.verified_stmt("SELECT * FROM users |> AGGREGATE GROUP BY a, b");
dialects.verified_stmt("SELECT * FROM users |> AGGREGATE SUM(c) GROUP BY a, b");
dialects.verified_stmt("SELECT * FROM users |> AGGREGATE SUM(c) ASC");
// order by pipe operator
dialects.verified_stmt("SELECT * FROM users |> ORDER BY id ASC");
dialects.verified_stmt("SELECT * FROM users |> ORDER BY id DESC");
dialects.verified_stmt("SELECT * FROM users |> ORDER BY id DESC, name ASC");
// many pipes
dialects.verified_stmt(
"SELECT * FROM CustomerOrders |> AGGREGATE SUM(cost) AS total_cost GROUP BY customer_id, state, item_type |> EXTEND COUNT(*) OVER (PARTITION BY customer_id) AS num_orders |> WHERE num_orders > 1 |> AGGREGATE AVG(total_cost) AS average GROUP BY state DESC, item_type ASC",
);
}
#[test]
fn parse_multiple_set_statements() -> Result<(), ParserError> {
let dialects = all_dialects_where(|d| d.supports_comma_separated_set_assignments());