summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-06-11 13:36:41 +0200
committerPeter Wu <peter@lekensteyn.nl>2014-06-11 13:36:41 +0200
commit36055c51726264c43110c2225ba9bdc2fdcce5f2 (patch)
tree0f939a4f1516a0bf467a57d7b6cf267a14abcb69
parent072c59d7dc3389e84f715ac46033ab43a4971db6 (diff)
downloadGoldfarmer-36055c51726264c43110c2225ba9bdc2fdcce5f2.tar.gz
More numbers for estimating duration
-rw-r--r--src/database/BrandAnalyzerQueue.java4
-rw-r--r--src/main/Analyzor.java19
2 files changed, 23 insertions, 0 deletions
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<String> 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
@@ -255,6 +255,20 @@ public class Analyzor {
}
/**
+ * @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.
*
* @param queryText The rows to select.
@@ -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);