Maybe I don't express myself clearly. If I input a literal 1.23, I just want to get 1.23 whatever its type is, but the getValue2() returns 123 AS long. Is the only way to judge its type before and invoke literal.getValueAs(Double.class)?
Danny Chan <[email protected]> 于2020年3月5日周四 下午10:20写道: > Literal actually does not have a exact data type, 1.23 can be both float or > decimal, in order not to lose precision,we represent it as decimal > internal. > > Xiangwei Wei <[email protected]>于2020年3月5日 周四下午5:09写道: > > > Thank you for reply. What I want is a getValue() method which returns > > exactly the value of literal based on its type. You are right that I can > > use literal.getValueAs(Double.class) to get a Double value, but maybe > it's > > better to provide a method like what I say. What do you think? > > > > Julian Hyde <[email protected]> 于2020年3月5日周四 下午2:20写道: > > > > > As the java doc says, RexLiteral.getValue2 returns values in the form > > that > > > the calculator builder needs them. That may not be the form that you > need > > > them. In which case, don’t use that method. > > > > > > If you want a Double, have you tried literal.getValueAs(Double.class)? > > > > > > (We don’t tend to use Float and Double much because when we’re > compiling > > > queries we can’t afford any loss of precision. If the user typed 1.1 we > > > want exactly 1.1, whereas Decimal might be something like > > 1.000000000987.) > > > > > > > On Mar 4, 2020, at 9:43 PM, Xiangwei Wei <[email protected]> > > wrote: > > > > > > > > In RexLiteral.getValue2(), it treats Decimal just by `return > > > > getValueAs(Long.class);`. > > > > In this instance, we can't get a correct double/float value because > > it's > > > > considered as Decimal type here. Is this a problem or is there a > reason > > > > here? > > > > > > > > -- > > > > Best, > > > > Xiangwei Wei > > > > > > > > > > -- > > Best, > > Xiangwei Wei > > > -- Best, Xiangwei Wei
