[
https://issues.apache.org/jira/browse/CALCITE-6789?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17913700#comment-17913700
]
Chenrui commented on CALCITE-6789:
----------------------------------
Below is my test case. I tested it, and my query did not invoke the convert
method of CsvEnumerator.
{code:java}
@Test
public void testCsvQuery() throws Exception {
final String path = resourcePath("sales");
CsvSchema csvSchema = new CsvSchema(new File(path),
org.apache.calcite.adapter.csv.CsvTable.Flavor.SCANNABLE);
Properties info = new Properties();
info.setProperty("caseSensitive", "false");
info.setProperty("conformance", "MYSQL_5");
Connection connection = DriverManager.getConnection("jdbc:calcite:", info);
CalciteConnection calciteConnection =
connection.unwrap(CalciteConnection.class);
calciteConnection.getProperties().put("sqlConformance",
SqlConformanceEnum.MYSQL_5);
SchemaPlus rootSchema = calciteConnection.getRootSchema();
rootSchema.add("csv", csvSchema);
String sql = "select 名称,sum(age) from csv.test group by 名称";
Statement statement = calciteConnection.createStatement();
ResultSet resultSet = statement.executeQuery(sql);
}{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)