Skip to content

Commit 1d89c66

Browse files
adriangbLucaCappelletti94claude
committed
Address review: DuckDB doc example and link, arrow-only dialect test
All three changes are applied review suggestions from Luca Cappelletti. Co-Authored-By: Luca Cappelletti <7738570+LucaCappelletti94@users.noreply.github.com> Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent c91244d commit 1d89c66

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/dialect/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,14 +547,16 @@ pub trait Dialect: Debug + Any {
547547
/// lambda functions, for example:
548548
///
549549
/// ```sql
550-
/// SELECT transform(array(1, 2, 3), LAMBDA x : x + 1); -- returns [2,3,4]
550+
/// SELECT list_transform([1, 2, 3], lambda x : x + 1); -- returns [2, 3, 4]
551551
/// ```
552552
///
553553
/// This spelling does not claim the `->` token, so it can be enabled by
554554
/// dialects that already give `->` a different meaning, such as PostgreSQL
555555
/// and its derivatives, where `->` is JSON member access. Defaults to
556556
/// [`Self::supports_lambda_functions`], so dialects supporting the `->`
557557
/// spelling accept the `LAMBDA` spelling too unless they say otherwise.
558+
///
559+
/// See <https://duckdb.org/docs/stable/sql/functions/lambda>
558560
fn supports_lambda_keyword_syntax(&self) -> bool {
559561
self.supports_lambda_functions()
560562
}

tests/sqlparser_custom_dialect.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,3 +249,38 @@ fn custom_dialect_lambda_keyword_defaults_to_arrow_support() {
249249
);
250250
}
251251
}
252+
253+
#[test]
254+
fn custom_dialect_lambda_arrow_syntax_without_keyword() {
255+
// Arrow lambdas stay on while the `LAMBDA` keyword spelling is off,
256+
// as in engines like Spark and Snowflake.
257+
#[derive(Debug)]
258+
struct MyDialect {}
259+
260+
impl Dialect for MyDialect {
261+
fn is_identifier_start(&self, ch: char) -> bool {
262+
is_identifier_start(ch)
263+
}
264+
265+
fn is_identifier_part(&self, ch: char) -> bool {
266+
is_identifier_part(ch)
267+
}
268+
269+
fn supports_lambda_functions(&self) -> bool {
270+
true
271+
}
272+
273+
fn supports_lambda_keyword_syntax(&self) -> bool {
274+
false
275+
}
276+
}
277+
278+
let dialect = MyDialect {};
279+
280+
let sql = "SELECT transform(xs, x -> x + 1)";
281+
assert_eq!(
282+
sql,
283+
&format!("{}", Parser::parse_sql(&dialect, sql).unwrap()[0])
284+
);
285+
assert!(Parser::parse_sql(&dialect, "SELECT transform(xs, lambda x : x + 1)").is_err());
286+
}

0 commit comments

Comments
 (0)