diff --git a/core/src/main/java/org/apache/calcite/runtime/ResultSetEnumerable.java b/core/src/main/java/org/apache/calcite/runtime/ResultSetEnumerable.java index 2c434aa23a6a..3f4e4808b833 100644 --- a/core/src/main/java/org/apache/calcite/runtime/ResultSetEnumerable.java +++ b/core/src/main/java/org/apache/calcite/runtime/ResultSetEnumerable.java @@ -94,30 +94,32 @@ public class ResultSetEnumerable extends AbstractEnumerable { } }; } else { - //noinspection unchecked - return (Function0<@Nullable Object>) () -> { - try { - final List<@Nullable Object> list = new ArrayList<>(); - for (int i = 0; i < columnCount; i++) { - if (metaData.getColumnType(i + 1) == Types.TIMESTAMP) { - long v = resultSet.getLong(i + 1); - if (v == 0 && resultSet.wasNull()) { - list.add(null); - } else { - list.add(v); - } - } else { - list.add(resultSet.getObject(i + 1)); - } - } - return list.toArray(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - }; + return () -> convertColumns(resultSet, metaData, columnCount); } }; + private static @Nullable Object[] convertColumns(ResultSet resultSet, ResultSetMetaData metaData, + int columnCount) { + final List<@Nullable Object> list = new ArrayList<>(columnCount); + try { + for (int i = 0; i < columnCount; i++) { + if (metaData.getColumnType(i + 1) == Types.TIMESTAMP) { + long v = resultSet.getLong(i + 1); + if (v == 0 && resultSet.wasNull()) { + list.add(null); + } else { + list.add(v); + } + } else { + list.add(resultSet.getObject(i + 1)); + } + } + return list.toArray(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + private ResultSetEnumerable( DataSource dataSource, String sql, @@ -433,21 +435,23 @@ public void close() { } }; } - //noinspection unchecked - return (Function0<@Nullable Object>) () -> { - try { - final List<@Nullable Object> list = new ArrayList<>(); - for (int i = 0; i < columnCount; i++) { - list.add(primitives[i].jdbcGet(resultSet, i + 1)); - } - return list.toArray(); - } catch (SQLException e) { - throw new RuntimeException(e); - } - }; + return () -> convertPrimitiveColumns(primitives, resultSet, columnCount); }; } + private static @Nullable Object [] convertPrimitiveColumns(Primitive[] primitives, + ResultSet resultSet, int columnCount) { + final List<@Nullable Object> list = new ArrayList<>(columnCount); + try { + for (int i = 0; i < columnCount; i++) { + list.add(primitives[i].jdbcGet(resultSet, i + 1)); + } + return list.toArray(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + } + /** * Consumer for decorating a {@link PreparedStatement}, that is, setting * its parameters.