Thank you. I’ll take a look. For what it's worth, I take issue the people (not you - they are in Spark and/or Presto) who originally describe this feature as ‘lambdas’, ‘higher-order functions’ or ‘function values’. The lambdas can only be used within that particular function call, not passed around as a value, and are therefore no more lambdas than the filter ‘e -> e.sal > 10’ in the query ’select * from emp as e where e.sal > 10’.
The so-called ‘higher-order functions’ are all built-in, and work by supporting a particular syntax in the parser. There is no ability to define your own higher-order function (the equivalent of MAP, FILTER or EXISTS), and no ability to treat the lambdas as function values that can be passed to another function. The bitter irony is that SQL has always supported the MAP and FILTER higher-order functions with a constant argument: these are the project and filter relational operators. All the ‘lambda’ feature does is apply those operators to nested collections, using syntax reminiscent of a real functional programming language. But the good news is that, now that I have come to terms with the fact that this feature does not really intend to make SQL into a functional programming language, and can see that it doesn’t require vast changes to the type system and execution model, I am happy to consider adding it to Calcite SQL. Also good news: my dissatisfaction led me to create Morel, which is both a real functional programming language and a real query language. Julian > On Nov 13, 2023, at 4:11 AM, Hongyu Guo <guohongyu...@gmail.com> wrote: > > Hi devs, > > I have opened a PR regarding lambda expressions, Calcite will support > lambda expressions like `(a, b) - > a+ b` in function parameters if this PR > is merged. > > This PR includes the following: > - Parse, validation, SqlToRel and RelToSql for lambda expressions. > - Execution of higher-order functions for EnumerableConvention. > - Addition of the EXISTS function to verify the correctness of the > execution results of higher-order functions. > > For more details, please refer to the following links: > [1] https://github.com/apache/calcite > [2] https://issues.apache.org/jira/browse/CALCITE-3679 > [3] https://issues.apache.org/jira/browse/CALCITE-6116 > > Best, > Hongyu