You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@calcite.apache.org by James <xu...@gmail.com> on 2017/06/13 15:25:29 UTC

Is it possible to make an integer literal using RexBuilder?

Hi all,

I want to make an integer literal to feed to the string POSITION
function(POSITION(string1 IN string2)) for unittesting, but I can't find
the right function to do this. The best try I ever had is:

    rexBuilder.makeLiteral(1,
typeFactory.createSqlType(SqlTypeName.INTEGER), false)

But it returns a DECIMAL literal.

My question is: is it possible to make an integer literal using RexBuilder?
If yes, then how? If not, then what's the reason?

Thanks in advance.
James

Re: Is it possible to make an integer literal using RexBuilder?

Posted by Julian Hyde <jh...@apache.org>.
Yes, all non-floating point numeric literals will have SqlTypeName of DECIMAL when created using RexBuilder.makeLiteral. It is trying to achieve the same affect as if the user wrote “1” in SQL.

If you need it to be an INTEGER, you should call RexBuilder.makeCast on the result.
 

> On Jun 13, 2017, at 8:25 AM, James <xu...@gmail.com> wrote:
> 
> Hi all,
> 
> I want to make an integer literal to feed to the string POSITION
> function(POSITION(string1 IN string2)) for unittesting, but I can't find
> the right function to do this. The best try I ever had is:
> 
>    rexBuilder.makeLiteral(1,
> typeFactory.createSqlType(SqlTypeName.INTEGER), false)
> 
> But it returns a DECIMAL literal.
> 
> My question is: is it possible to make an integer literal using RexBuilder?
> If yes, then how? If not, then what's the reason?
> 
> Thanks in advance.
> James