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

Sophie edited comment on CALCITE-5376 at 11/17/22 5:14 PM:
-----------------------------------------------------------

Thanks for this. 

Just to make sure I understand, would the idea be to do something similar to 
defining the function to be something along the lines of this, given that it 
would be an aggregate function? 
{code:java}
@LibraryOperator(libraries = {SPARK})
public static final SqlAggFunction FIRST =
new SqlFirstLastValueAggFunction(SqlKind.FIRST_VALUE);{code}
But probably not with SqlFirstLastValueAggFunction, but the equivalent

And the validator change might be around SqlValidatorImpl.validateCall where 
there's a check with SqlFunctionCategory.MATCH_RECOGNIZE?

Is there a better place for testing this than BabelQuidemTest?


was (Author: JIRAUSER298340):
Thanks for this. 

Just to make sure I understand, would the idea be to do something similar to 
defining the function to be something along the lines of this, given that it 
would be an aggregate function? 
{code:java}
@LibraryOperator(libraries = {SPARK})
public static final SqlAggFunction FIRST =
new SparkSqlFirstLastValueAggFunction(SqlKind.FIRST_VALUE);{code}
And the validator change might be around SqlValidatorImpl.validateCall where 
there's a check with SqlFunctionCategory.MATCH_RECOGNIZE?

Is there a better place for testing this than BabelQuidemTest?

> 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