You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by Junwei Li <ju...@gmail.com> on 2017/08/04 18:06:48 UTC

How to add user defined operator in Calcite?

Hi,

I am a newbie to Calcite and SQL. Recently, I am trying to develop a
calcite adapter for a new kind of data source. This data source has some
different operators compared to SQL. For example, in SQL, if we want to
find all rows that don't contain a certain keyword:

select * from table where value not like 'abc%'


In this new data source, the query string is:


select * from table where value <> 'abc%'



So in this data source, <> is a new operator.


As of now, I have to manually generate the where clause in the filter rule.
Does Calcite support adding new operator, so that it can automatically
translate? Thanks!


Sincerely,
Junwei Li

Re: How to add user defined operator in Calcite?

Posted by Junwei Li <ju...@gmail.com>.
Thank you so much for your reply, Julian. I will try adding user-defined
function first.

Sincerely,
Junwei Li

On Fri, Aug 4, 2017 at 1:30 PM, Julian Hyde <jh...@apache.org> wrote:

> "<>" is a built-in operator in standard SQL and in Calcite, so that
> might be tricky.
>
> If you were to add a new operator, say "<=>", you'd have to change the
> parser, and also add an entry to the operator table
> (SqlStdOperatorTable or similar).
>
> If you can live with function syntax (as opposed to operator syntax)
> it's easier to use use add a user-defined function.
>
> Julian
>
>
> On Fri, Aug 4, 2017 at 11:06 AM, Junwei Li <ju...@gmail.com>
> wrote:
> > Hi,
> >
> > I am a newbie to Calcite and SQL. Recently, I am trying to develop a
> > calcite adapter for a new kind of data source. This data source has some
> > different operators compared to SQL. For example, in SQL, if we want to
> > find all rows that don't contain a certain keyword:
> >
> > select * from table where value not like 'abc%'
> >
> >
> > In this new data source, the query string is:
> >
> >
> > select * from table where value <> 'abc%'
> >
> >
> >
> > So in this data source, <> is a new operator.
> >
> >
> > As of now, I have to manually generate the where clause in the filter
> rule.
> > Does Calcite support adding new operator, so that it can automatically
> > translate? Thanks!
> >
> >
> > Sincerely,
> > Junwei Li
>

Re: How to add user defined operator in Calcite?

Posted by Julian Hyde <jh...@apache.org>.
"<>" is a built-in operator in standard SQL and in Calcite, so that
might be tricky.

If you were to add a new operator, say "<=>", you'd have to change the
parser, and also add an entry to the operator table
(SqlStdOperatorTable or similar).

If you can live with function syntax (as opposed to operator syntax)
it's easier to use use add a user-defined function.

Julian


On Fri, Aug 4, 2017 at 11:06 AM, Junwei Li <ju...@gmail.com> wrote:
> Hi,
>
> I am a newbie to Calcite and SQL. Recently, I am trying to develop a
> calcite adapter for a new kind of data source. This data source has some
> different operators compared to SQL. For example, in SQL, if we want to
> find all rows that don't contain a certain keyword:
>
> select * from table where value not like 'abc%'
>
>
> In this new data source, the query string is:
>
>
> select * from table where value <> 'abc%'
>
>
>
> So in this data source, <> is a new operator.
>
>
> As of now, I have to manually generate the where clause in the filter rule.
> Does Calcite support adding new operator, so that it can automatically
> translate? Thanks!
>
>
> Sincerely,
> Junwei Li