[ 
https://issues.apache.org/jira/browse/CALCITE-3587?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16996068#comment-16996068
 ] 

Julian Hyde commented on CALCITE-3587:
--------------------------------------

[~danny0405] is correct. You should call {{makeExactLiteral}}. I guess when you 
called {{makeLiteral(Object, RelDataType, boolean))}} it gave an error. If so, 
the error was correct. You should not call it with a Java {{float}} value for a 
SQL {{DECIMAL}} type. Java {{float}} is inexact - it probably has value 
12.2999999998 or something - and therefore the correct type for a {{DECIMAL}} 
literal is a {{java.math.BigDecimal}}.

If you change your test from {{builder.makeLiteral(12.3, type, false)}} to 
{{builder.makeExactLiteral(new BigDecimal("12.3"), type)}} I think it will 
succeed.

> RexBuilder may lose decimal fraction for creating literal with DECIMAL type
> ---------------------------------------------------------------------------
>
>                 Key: CALCITE-3587
>                 URL: https://issues.apache.org/jira/browse/CALCITE-3587
>             Project: Calcite
>          Issue Type: Bug
>            Reporter: Wang Yanlin
>            Assignee: Wang Yanlin
>            Priority: Major
>              Labels: pull-request-available
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> this test
> {code:java}
> // RexBuilderTest
> @Test public void testDecimal() {
> final RelDataTypeFactory typeFactory =
> new SqlTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
> final RelDataType type = typeFactory.createSqlType(SqlTypeName.DECIMAL, 4, 2);
> final RexBuilder builder = new RexBuilder(typeFactory);
> final RexLiteral literal = (RexLiteral) builder.makeLiteral(12.3, type, 
> false);
> Comparable value = literal.getValue();
> assertThat(value.toString(), is("12.3"));
> }
> {code}
> fails with message 
> {code:java}
> java.lang.AssertionError: 
> Expected: is "12.3"
>      but: was "12"
> Expected :12.3
> Actual   :12
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to