From 36055c51726264c43110c2225ba9bdc2fdcce5f2 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 11 Jun 2014 13:36:41 +0200 Subject: More numbers for estimating duration --- src/database/BrandAnalyzerQueue.java | 4 ++++ src/main/Analyzor.java | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/src/database/BrandAnalyzerQueue.java b/src/database/BrandAnalyzerQueue.java index 21d0290..f6b0a40 100644 --- a/src/database/BrandAnalyzerQueue.java +++ b/src/database/BrandAnalyzerQueue.java @@ -49,6 +49,7 @@ public class BrandAnalyzerQueue implements Runnable { } private void fillQueue() throws SQLException, InterruptedException { + int count = 0; while (data.next()) { List brands = checker.getBrands(data.getString("text")); // if there is no brand, add a dummy so we know it got checked @@ -58,7 +59,10 @@ public class BrandAnalyzerQueue implements Runnable { long tweetid = data.getLong("tweetid"); Result result = new Result(tweetid, brands); queue.put(result); + ++count; } + getLogger().log(Level.INFO, "Finished with queuing " + count + + " analyses of tweets"); } public Result next() { diff --git a/src/main/Analyzor.java b/src/main/Analyzor.java index 9e26c97..2589e66 100644 --- a/src/main/Analyzor.java +++ b/src/main/Analyzor.java @@ -254,6 +254,20 @@ public class Analyzor { writer.close(); } + /** + * @return The number of rows that would be returned by the query. + */ + private int getQuerySize(String query) throws SQLException { + PreparedStatement statement; + String countQuery = "WITH q AS (" + query + ") SELECT COUNT(*) FROM q"; + statement = connection.prepareStatement(countQuery); + ResultSet result = statement.executeQuery(); + result.next(); + int count = result.getInt("count"); + result.close(); + return count; + } + /** * Obtain the brands of select tweet texts. * @@ -275,6 +289,11 @@ public class Analyzor { if (queryText.isEmpty()) { queryText = "SELECT tweetid, text FROM tweet"; } + + // print expected count, this will increase the initial startup time + // (5s for 10M results), but will give an accurate ETA estimator + System.out.println("Expected query size: " + getQuerySize(queryText)); + // allow the use of cursors for less memory usage connection.setAutoCommit(false); statement = connection.prepareStatement(queryText); -- cgit v1.2.1