diff --git a/Cargo.lock b/Cargo.lock index 477b312d0dc6..d5a23d1a340e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4584,9 +4584,9 @@ dependencies = [ [[package]] name = "sqlparser" -version = "0.52.0" +version = "0.53.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9a875d8cd437cc8a97e9aeaeea352ec9a19aea99c23e9effb17757291de80b08" +checksum = "05a528114c392209b3264855ad491fcce534b94a38771b0a0b97a79379275ce8" dependencies = [ "log", ] diff --git a/Cargo.toml b/Cargo.toml index 0a234107339b..adf529a7b960 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -77,7 +77,7 @@ serde_json = "1" simd-json = { version = "0.14", features = ["known-key"] } simdutf8 = "0.1.4" slotmap = "1" -sqlparser = "0.52" +sqlparser = "0.53" stacker = "0.1" streaming-iterator = "0.1.9" strength_reduce = "0.2" diff --git a/crates/polars-sql/src/context.rs b/crates/polars-sql/src/context.rs index 3a3a4cd8b7aa..1957e5c62e51 100644 --- a/crates/polars-sql/src/context.rs +++ b/crates/polars-sql/src/context.rs @@ -566,6 +566,8 @@ impl SQLContext { | JoinOperator::LeftOuter(constraint) | JoinOperator::RightOuter(constraint) | JoinOperator::Inner(constraint) + | JoinOperator::Anti(constraint) + | JoinOperator::Semi(constraint) | JoinOperator::LeftAnti(constraint) | JoinOperator::LeftSemi(constraint) | JoinOperator::RightAnti(constraint) @@ -592,9 +594,9 @@ impl SQLContext { JoinOperator::RightOuter(_) => JoinType::Right, JoinOperator::Inner(_) => JoinType::Inner, #[cfg(feature = "semi_anti_join")] - JoinOperator::LeftAnti(_) | JoinOperator::RightAnti(_) => JoinType::Anti, + JoinOperator::Anti(_) | JoinOperator::LeftAnti(_) | JoinOperator::RightAnti(_) => JoinType::Anti, #[cfg(feature = "semi_anti_join")] - JoinOperator::LeftSemi(_) | JoinOperator::RightSemi(_) => JoinType::Semi, + JoinOperator::Semi(_) | JoinOperator::LeftSemi(_) | JoinOperator::RightSemi(_) => JoinType::Semi, join_type => polars_bail!(SQLInterface: "join type '{:?}' not currently supported", join_type), }, )? @@ -1028,10 +1030,10 @@ impl SQLContext { .columns .iter() .map(|c| { - if c.value.is_empty() { + if c.name.value.is_empty() { None } else { - Some(PlSmallStr::from_str(c.value.as_str())) + Some(PlSmallStr::from_str(c.name.value.as_str())) } }) .collect(); @@ -1399,7 +1401,8 @@ impl SQLContext { ) } else { let existing_columns: Vec<_> = schema.iter_names().collect(); - let new_columns: Vec<_> = alias.columns.iter().map(|c| c.value.clone()).collect(); + let new_columns: Vec<_> = + alias.columns.iter().map(|c| c.name.value.clone()).collect(); Ok(lf.rename(existing_columns, new_columns, true)) } } diff --git a/crates/polars-sql/src/functions.rs b/crates/polars-sql/src/functions.rs index 988ef74692e2..7af0e95a4dec 100644 --- a/crates/polars-sql/src/functions.rs +++ b/crates/polars-sql/src/functions.rs @@ -13,11 +13,13 @@ use polars_plan::plans::{typed_lit, LiteralValue}; use polars_plan::prelude::LiteralValue::Null; use polars_plan::prelude::{col, cols, lit, StrptimeOptions}; use polars_utils::pl_str::PlSmallStr; +use sqlparser::ast::helpers::attached_token::AttachedToken; use sqlparser::ast::{ DateTimeField, DuplicateTreatment, Expr as SQLExpr, Function as SQLFunction, FunctionArg, FunctionArgExpr, FunctionArgumentClause, FunctionArgumentList, FunctionArguments, Ident, OrderByExpr, Value as SQLValue, WindowSpec, WindowType, }; +use sqlparser::tokenizer::Span; use crate::sql_expr::{adjust_one_indexed_param, parse_extract_date_part, parse_sql_expr}; use crate::SQLContext; @@ -1058,6 +1060,7 @@ impl SQLFunctionVisitor<'_> { &DateTimeField::Custom(Ident { value: p.to_string(), quote_style: None, + span: Span::empty(), }), ) }, @@ -1511,7 +1514,7 @@ impl SQLFunctionVisitor<'_> { f(parse_sql_expr(sql_expr, self.ctx, self.active_schema)?) }, [FunctionArgExpr::Wildcard] => f(parse_sql_expr( - &SQLExpr::Wildcard, + &SQLExpr::Wildcard(AttachedToken::empty()), self.ctx, self.active_schema, )?), @@ -1813,6 +1816,7 @@ fn _extract_func_args( .iter() .map(|arg| match arg { FunctionArg::Named { arg, .. } => arg, + FunctionArg::ExprNamed { arg, .. } => arg, FunctionArg::Unnamed(arg) => arg, }) .collect(); diff --git a/crates/polars-sql/src/sql_expr.rs b/crates/polars-sql/src/sql_expr.rs index 4f0f44b826fb..028677a9506a 100644 --- a/crates/polars-sql/src/sql_expr.rs +++ b/crates/polars-sql/src/sql_expr.rs @@ -246,7 +246,7 @@ impl SQLExprVisitor<'_> { }, SQLExpr::UnaryOp { op, expr } => self.visit_unary_op(op, expr), SQLExpr::Value(value) => self.visit_literal(value), - SQLExpr::Wildcard => Ok(Expr::Wildcard), + SQLExpr::Wildcard(_) => Ok(Expr::Wildcard), e @ SQLExpr::Case { .. } => self.visit_case_when_then(e), other => { polars_bail!(SQLInterface: "expression {:?} is not currently supported", other) diff --git a/py-polars/tests/unit/sql/test_joins.py b/py-polars/tests/unit/sql/test_joins.py index 8b3b968991a2..4042fb149f6a 100644 --- a/py-polars/tests/unit/sql/test_joins.py +++ b/py-polars/tests/unit/sql/test_joins.py @@ -23,6 +23,10 @@ def foods_ipc_path() -> Path: "SELECT * FROM tbl_a LEFT SEMI JOIN tbl_b USING (a,c)", pl.DataFrame({"a": [2], "b": [0], "c": ["y"]}), ), + ( + "SELECT * FROM tbl_a SEMI JOIN tbl_b USING (a,c)", + pl.DataFrame({"a": [2], "b": [0], "c": ["y"]}), + ), ( "SELECT * FROM tbl_a LEFT SEMI JOIN tbl_b USING (a)", pl.DataFrame({"a": [1, 2, 3], "b": [4, 0, 6], "c": ["w", "y", "z"]}), @@ -31,6 +35,10 @@ def foods_ipc_path() -> Path: "SELECT * FROM tbl_a LEFT ANTI JOIN tbl_b USING (a)", pl.DataFrame(schema={"a": pl.Int64, "b": pl.Int64, "c": pl.String}), ), + ( + "SELECT * FROM tbl_a ANTI JOIN tbl_b USING (a)", + pl.DataFrame(schema={"a": pl.Int64, "b": pl.Int64, "c": pl.String}), + ), ( "SELECT * FROM tbl_a LEFT SEMI JOIN tbl_b USING (b) LEFT SEMI JOIN tbl_c USING (c)", pl.DataFrame({"a": [1, 3], "b": [4, 6], "c": ["w", "z"]}),