[ 
https://issues.apache.org/jira/browse/CALCITE-5376?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17631886#comment-17631886
 ] 

Julian Hyde commented on CALCITE-5376:
--------------------------------------

Let's assume that there are no parser changes. The "Function 
'FIRST(`customers`.`age`, 0)' can only be used in MATCH_RECOGNIZE" error is 
probably coming during validation, not parsing.

It's probably best to define FIRST and LAST as separate functions, in 
SqlLibraryOperators, even though they have the same names as the FIRST and LAST 
functions used in MATCH_RECOGNIZE.  They couldn't be called FIRST and LAST, and 
therefore the validator or sql-to-rel would need to resolve to the appropriate 
function based on whether we are inside MATCH_RECOGNIZE.

> Support Spark’s FIRST and LAST functions
> ----------------------------------------
>
>                 Key: CALCITE-5376
>                 URL: https://issues.apache.org/jira/browse/CALCITE-5376
>             Project: Calcite
>          Issue Type: Task
>            Reporter: Sophie
>            Priority: Major
>
> Following on from the mailing list thread - 
> [https://lists.apache.org/thread/3rk8zo5r38c6gpj7j0oy0453cxwlmnm7]
>  
> Spark has the following function definition for FIRST and LAST
> [https://spark.apache.org/docs/3.0.1/api/sql/index.html#first]
> [https://spark.apache.org/docs/3.0.1/api/sql/index.html#last] 
>  
> At the moment trying to use these functions with a query like 
> {code:java}
> select first(age) from customers{code}
> gives an error along the lines of
> {code:java}
> Function 'FIRST(`customers`.`age`, 0)' can only be used in 
> MATCH_RECOGNIZE{code}
>  
> In terms of testing, I can reproduce the error using BabelQuidemTest and 
> setting up a case for spark.
>  
> Given that Spark’s first function is very similar to the FIRST_VALUE 
> function, I think SqlFirstLastValueAggFunction is probably a useful starting 
> point, but some pointers about where to look would be helpful. Particularly 
> around potential parser changes.
>  
> Thanks in advance



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to