[
https://issues.apache.org/jira/browse/CALCITE-6789?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17913701#comment-17913701
]
Chenrui commented on CALCITE-6789:
----------------------------------
The exception stack trace is as follows:
{code:java}
java.lang.NumberFormatException
at java.math.BigDecimal.<init>(BigDecimal.java:599)
at java.math.BigDecimal.<init>(BigDecimal.java:383)
at java.math.BigDecimal.<init>(BigDecimal.java:809)
at
org.apache.calcite.linq4j.tree.Primitive.charToDecimalCast(Primitive.java:433)
at Baz$1$1.current(Unknown Source)
at
org.apache.calcite.linq4j.EnumerableDefaults.groupBy_(EnumerableDefaults.java:1166)
at
org.apache.calcite.linq4j.EnumerableDefaults.groupBy(EnumerableDefaults.java:781)
at
org.apache.calcite.linq4j.DefaultEnumerable.groupBy(DefaultEnumerable.java:311)
at Baz.bind(Unknown Source)
at
org.apache.calcite.jdbc.CalcitePrepare$CalciteSignature.enumerable(CalcitePrepare.java:367)
at
org.apache.calcite.jdbc.CalciteConnectionImpl.enumerable(CalciteConnectionImpl.java:335)
at
org.apache.calcite.jdbc.CalciteMetaImpl._createIterable(CalciteMetaImpl.java:657)
at
org.apache.calcite.jdbc.CalciteMetaImpl.createIterable(CalciteMetaImpl.java:648)
at
org.apache.calcite.avatica.AvaticaResultSet.execute(AvaticaResultSet.java:184)
at
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:64)
at
org.apache.calcite.jdbc.CalciteResultSet.execute(CalciteResultSet.java:43)
at
org.apache.calcite.avatica.AvaticaConnection$1.execute(AvaticaConnection.java:669)
at
org.apache.calcite.jdbc.CalciteMetaImpl.prepareAndExecute(CalciteMetaImpl.java:717)
at
org.apache.calcite.avatica.AvaticaConnection.prepareAndExecuteInternal(AvaticaConnection.java:677)
at
org.apache.calcite.avatica.AvaticaStatement.executeInternal(AvaticaStatement.java:157)
at
org.apache.calcite.avatica.AvaticaStatement.executeQuery(AvaticaStatement.java:228)
at org.apache.calcite.test.CsvTest.testCsvQuery(CsvTest.java:1196){code}
> 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)