static DataFrame.Builder builder(Class... cls) { DataFrame.Builder builder = builder(); for (Class c : cls) { builder.add(Vector.Builder.of(c)); } return builder; }
@Override public DataFrame parse(Supplier<? extends DataFrame.Builder> supplier) { Check.state(url != null, "No database provided"); Check.state(query != null, "No query provided"); try { Connection connection = DriverManager.getConnection(url, properties); PreparedStatement stmt = connection.prepareStatement(query); ResultSet resultSet = stmt.executeQuery(); ObjectIndex.Builder index = new ObjectIndex.Builder(); if (header != null) { header.forEach(index::add); } else { ResultSetMetaData metaData = resultSet.getMetaData(); for (int i = 0; i < metaData.getColumnCount(); i++) { // index starts with 1 String columnLabel = metaData.getColumnLabel(i + 1); Object remappedColumnLabel = headerReMap.get(columnLabel); if (remappedColumnLabel != null) { index.add(remappedColumnLabel); } else { index.add(columnLabel); } } } SqlEntryReader entryReader = new SqlEntryReader(resultSet); DataFrame.Builder builder = supplier.get(); List<Class<?>> columnTypes; if (types != null) { columnTypes = types; } else { columnTypes = entryReader.getTypes(); } columnTypes.stream().map(VectorType::of).forEach(builder::add); builder.readAll(entryReader); builder.setColumnIndex(index.build()); return builder.build(); } catch (SQLException e) { throw new EntryReaderException(e); } }