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

xiong duan commented on CALCITE-6789:
-------------------------------------

It is a bug. Welcome to submit PR to fix.

And if you set the CSV title add the datatype like:
{code:java}
ID:long,NAME:string,SEX:string,AGE:int {code}
will work well. On the one hand, it is the changes you made in the description, 
and on the other hand, there may be areas for improvement in the CSV adapter.

 

> A NumberFormatException was thrown when performing an aggregate query on a 
> csv file.
> ------------------------------------------------------------------------------------
>
>                 Key: CALCITE-6789
>                 URL: https://issues.apache.org/jira/browse/CALCITE-6789
>             Project: Calcite
>          Issue Type: Bug
>          Components: csv-adapter, linq4j
>    Affects Versions: 1.38.0
>            Reporter: Chenrui
>            Priority: Major
>
> I have a Csv file as shown below:
> {code:java}
> id, name, sex, age
> 1244275574052069377,CVS--User,,
> 1244451590208847873,CVS--Li Si,,12
> 1245192850573905921,CVS--Zhang San,2,12{code}
> As you can see, both the `sex` and `age` of the first row of data are empty.
> When I use an aggregate SQL statement to query
> {code:java}
> select name, sum(age)  from csv.test group by name{code}
> A NumberFormatException is thrown.
> By tracing the exception stack, it is found that the situation of empty 
> strings is not judged in 
> `{+}{color:#172b4d}org.apache.calcite.linq4j.tree.Primitive#charToDecimalCast{color}{+}`.
> The problem is solved by modifying it using the following method:
> {code:java}
> public static @Nullable Object charToDecimalCast(
>       @Nullable String value, int precision, int scale, RoundingMode 
> roundingMode) {
>     if (value == null || value.isEmpty()) {
>       return null;
>     }
>     BigDecimal result = new BigDecimal(value.trim());
>     return checkOverflow(result, precision, scale, roundingMode);
>   }{code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to