You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Dmitry Sysolyatin <dm...@gmail.com> on 2022/04/28 10:07:46 UTC

Problem with implementing '||' operator for arrays

Hi!
I want the operator '||' to work with arrays not only with strings.
Array concatenation logic was already implemented in ARRAY_CONCAT function.
But if I add a new binary operator:
 -
https://github.com/apache/calcite/commit/6f35521aa67378ab0756fe074cda375e17c7ce96

Added test still fails with the same error as before:
Cannot apply '||' to arguments of type '<INTEGER ARRAY> || <INTEGER
ARRAY>'. Supported form(s): '<STRING> || <STRING>'

What I am doing wrong?

Re: Problem with implementing '||' operator for arrays

Posted by Dmitry Sysolyatin <dm...@gmail.com>.
Ok, thanks
I thought that if I added a binary operator with the same name as CONCAT
then in the case when function signature is different that <STRING> ||
<STRING>, calcite would try to find another function that has suitable
signature. But looks like things are not so easy

On Thu, Apr 28, 2022 at 5:11 PM Benchao Li <li...@apache.org> wrote:

> Hi Dmitry,
>
> I think `SqlLibraryOperators` is designed to extend the standard operator
> table, instead of
> overriding. There is already an operator in `SqlStdOperatorTable`[1], the
> error shows
> that the parser still picks the one in `SqlStdOperatorTable`.
>
> Besides that, '||' is hardcoded in the parser[2]. Hence it's not resolved
> from the operator
> table.
>
> In my opinion, if you want to extends '||' to support ARRAY, you may need
> to change the
> definition in `SqlStdOperatorTable`[1] to achieve that.
>
> [1]
>
> https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java#L263
> [2]
>
> https://github.com/apache/calcite/blob/main/core/src/main/codegen/templates/Parser.jj#L7174
>
> Dmitry Sysolyatin <dm...@gmail.com> 于2022年4月28日周四 18:15写道:
>
> > Hi!
> > I want the operator '||' to work with arrays not only with strings.
> > Array concatenation logic was already implemented in ARRAY_CONCAT
> function.
> > But if I add a new binary operator:
> >  -
> >
> >
> https://github.com/apache/calcite/commit/6f35521aa67378ab0756fe074cda375e17c7ce96
> >
> > Added test still fails with the same error as before:
> > Cannot apply '||' to arguments of type '<INTEGER ARRAY> || <INTEGER
> > ARRAY>'. Supported form(s): '<STRING> || <STRING>'
> >
> > What I am doing wrong?
> >
>
>
> --
>
> Best,
> Benchao Li
>

Re: Problem with implementing '||' operator for arrays

Posted by Benchao Li <li...@apache.org>.
Hi Dmitry,

I think `SqlLibraryOperators` is designed to extend the standard operator
table, instead of
overriding. There is already an operator in `SqlStdOperatorTable`[1], the
error shows
that the parser still picks the one in `SqlStdOperatorTable`.

Besides that, '||' is hardcoded in the parser[2]. Hence it's not resolved
from the operator
table.

In my opinion, if you want to extends '||' to support ARRAY, you may need
to change the
definition in `SqlStdOperatorTable`[1] to achieve that.

[1]
https://github.com/apache/calcite/blob/main/core/src/main/java/org/apache/calcite/sql/fun/SqlStdOperatorTable.java#L263
[2]
https://github.com/apache/calcite/blob/main/core/src/main/codegen/templates/Parser.jj#L7174

Dmitry Sysolyatin <dm...@gmail.com> 于2022年4月28日周四 18:15写道:

> Hi!
> I want the operator '||' to work with arrays not only with strings.
> Array concatenation logic was already implemented in ARRAY_CONCAT function.
> But if I add a new binary operator:
>  -
>
> https://github.com/apache/calcite/commit/6f35521aa67378ab0756fe074cda375e17c7ce96
>
> Added test still fails with the same error as before:
> Cannot apply '||' to arguments of type '<INTEGER ARRAY> || <INTEGER
> ARRAY>'. Supported form(s): '<STRING> || <STRING>'
>
> What I am doing wrong?
>


-- 

Best,
Benchao Li