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 9dc39a7893a9..20870cad13c9 100644 --- a/core/src/main/java/org/apache/calcite/runtime/ResultSetEnumerable.java +++ b/core/src/main/java/org/apache/calcite/runtime/ResultSetEnumerable.java @@ -91,30 +91,32 @@ public class ResultSetEnumerable extends AbstractEnumerable { } }; } else { - //noinspection unchecked - return (Function0) () -> { - try { - final List 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 Object[] convertColumns(ResultSet resultSet, ResultSetMetaData metaData, + int columnCount) { + final List 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, @@ -423,21 +425,23 @@ private static class ResultSetEnumerator implements Enumerator { } }; } - //noinspection unchecked - return (Function0) () -> { - try { - final List 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 Object[] convertPrimitiveColumns(Primitive[] primitives, + ResultSet resultSet, int columnCount) { + final List 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.