You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by bluejoe <bl...@cnic.cn> on 2016/09/07 03:30:29 UTC

Why varchar columns in where FILTER are transformed to 'CAST($1):....'?

Hi, all
I wrote a custom ScannableTable and override the scan(context, filters) method to implement the searching function.
When I sent a SQL command like

select * from PERSONS where NAME=‘bluejoe’ and AGE>30

In the filters parameter, I found the filter on column `AGE` is parsed properly like `>($2, 30)`

While the filter on column `NAME` is parsed as:

=(CAST($1):CHAR(7) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary" NOT NULL, 'bluejoe’)

Why the column identifier`NAME` is transformed? How can I get the real column $1? Or is there anyway to prevent the transformation?

Many thanks!

Best regards,
Zhihong SHEN
———————————————
Zhihong SHEN, Ph. D., Senior Engineer
Big Data Application Service Technology Laboratory,
Computer Network Information Center, Chinese Academy of Sciences
office phone:+86-10-58812516
mobile:+86-13671116520


Re: Why varchar columns in where FILTER are transformed to 'CAST($1):....'?

Posted by Julian Hyde <jh...@apache.org>.
Unlike Java, whose strings are always in the UNICODE character set,
SQL's strings can be in a variety of character sets. When you perform
the '=' operation, both arguments need to be the same type. The
character literal 'bluejoe' implicitly has character set  "ISO-8859-1"
and collation "ISO-8859-1$en_US$primary", and I guess the NAME column
has something else, so Calcite adds a cast to allow them to be
compared.

On Tue, Sep 6, 2016 at 8:30 PM, bluejoe <bl...@cnic.cn> wrote:
> Hi, all
> I wrote a custom ScannableTable and override the scan(context, filters) method to implement the searching function.
> When I sent a SQL command like
>
> select * from PERSONS where NAME=‘bluejoe’ and AGE>30
>
> In the filters parameter, I found the filter on column `AGE` is parsed properly like `>($2, 30)`
>
> While the filter on column `NAME` is parsed as:
>
> =(CAST($1):CHAR(7) CHARACTER SET "ISO-8859-1" COLLATE "ISO-8859-1$en_US$primary" NOT NULL, 'bluejoe’)
>
> Why the column identifier`NAME` is transformed? How can I get the real column $1? Or is there anyway to prevent the transformation?
>
> Many thanks!
>
> Best regards,
> Zhihong SHEN
> ———————————————
> Zhihong SHEN, Ph. D., Senior Engineer
> Big Data Application Service Technology Laboratory,
> Computer Network Information Center, Chinese Academy of Sciences
> office phone:+86-10-58812516
> mobile:+86-13671116520
>