Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apache Commons CSV performance comparison #11

Open
mageddo opened this issue Feb 16, 2023 · 0 comments
Open

Apache Commons CSV performance comparison #11

mageddo opened this issue Feb 16, 2023 · 0 comments

Comments

@mageddo
Copy link
Member

mageddo commented Feb 16, 2023

Apache Commons CSV --> 01:27

2023-02-16T02:34:38.933511 ProxiedStatement: getConnection
2023-02-16T02:34:39.141314 m=streamSelect, sql=SELECT * FROM TMP, autoCommit=true
2023-02-16T02:34:39.160498 m=streamSelect, status=executed, sql=SELECT * FROM TMP
2023-02-16T02:34:39.586226 status=printingRecords
2023-02-16T02:36:06.345703 status=csvWritten
2023-02-16T02:36:14.271099 status=linesCount, lines=7000000
2023-02-16T02:36:14.271566 m=getWarnings
private int extractQueryToCsv() throws SQLException {
  try {
    CsvTableDaos.streamSelect(this.connection, this.csvStm.getExtractSql(), (rs) -> {
      try (final CSVPrinter printer = this.createCsvPrinter()) {
        Log.log("status=printingRecords");
        printer.printRecords(rs, true);
      }
    });
  } catch (Exception e) {
    throw new SQLException(e);
  }
  Log.log("status=csvWritten");
  try {
    final int lines = Files.countLines(this.csvStm.getFile()) - HEADER_COUNT;
    Log.log("status=linesCount, lines={}", lines);
    return lines;
  } catch (IOException e) {
    throw new SQLException(e);
  }
}

Vanilla BufferedWritter --> 01:08

2023-02-16T02:41:39.530363 ProxiedStatement: getConnection
2023-02-16T02:41:40.230132 m=streamSelect, sql=SELECT * FROM TMP, autoCommit=true
2023-02-16T02:41:40.251840 m=streamSelect, status=executed, sql=SELECT * FROM TMP
2023-02-16T02:42:48.085736 m=getWarnings
2023-02-16T02:42:48.086107 m=clearWarnings
2023-02-16T02:42:48.086320 ProxiedStatement: getWarnings
2023-02-16T02:42:48.086503 ProxiedStatement: clearWarnings
2023-02-16T02:42:48.086680 m=getMetaData
2023-02-16T02:42:48.086866 ProxiedStatement: getUpdateCount
20
private int extractQueryToCsv0() throws SQLException {
  try {
    final BufferedWriter out = java.nio.file.Files.newBufferedWriter(this.csvStm.getFile());
    CsvTableDaos.streamSelect(this.connection, this.csvStm.getExtractSql(), (rs) -> {
//        try (final CSVPrinter printer = this.createCsvPrinter()) {
      final int columns = rs
          .getMetaData()
          .getColumnCount();
      while (rs.next()){
        for (int i = 1; i <= columns; i++) {
          out.write(rs.getString(i));
          out.write(", ");
        }
        out.write('\n');
      }
//          printer.printRecords(rs, true);
//        }
    });
  } catch (Exception e) {
    throw new SQLException(e);
  }
  try {
    return Files.countLines(this.csvStm.getFile()) - HEADER_COUNT;
  } catch (IOException e) {
    throw new SQLException(e);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant