drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject [7/9] drill git commit: DRILL-4230: Fixing query failures when mongo collection is empty
Date Tue, 16 Feb 2016 21:10:56 GMT
DRILL-4230: Fixing query failures when mongo collection is empty


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/a9383eef
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/a9383eef
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/a9383eef

Branch: refs/heads/drill-1.5.0-rc3
Commit: a9383eef8289456d243e2175009ea19620e64f31
Parents: 88edebd
Author: Kamesh <kam.iitkgp@gmail.com>
Authored: Fri Jan 1 14:39:29 2016 +0530
Committer: Jason Altekruse <altekrusejason@gmail.com>
Committed: Tue Feb 9 08:05:15 2016 -0800

----------------------------------------------------------------------
 .../apache/drill/exec/store/mongo/MongoGroupScan.java | 14 ++++++++------
 .../drill/exec/store/mongo/MongoTestConstants.java    |  1 +
 .../apache/drill/exec/store/mongo/MongoTestSuit.java  |  2 ++
 .../drill/exec/store/mongo/TestMongoQueries.java      |  6 ++++++
 4 files changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/a9383eef/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/MongoGroupScan.java
----------------------------------------------------------------------
diff --git a/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/MongoGroupScan.java
b/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/MongoGroupScan.java
index 92a2bc7..46123c4 100644
--- a/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/MongoGroupScan.java
+++ b/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/MongoGroupScan.java
@@ -499,12 +499,14 @@ public class MongoGroupScan extends AbstractGroupScan implements
     try{
       MongoClient client = storagePlugin.getClient();
       MongoDatabase db = client.getDatabase(scanSpec.getDbName());
-      MongoCollection<Document> collection = db.getCollection(scanSpec
-          .getCollectionName());
-      String json = collection.find().first().toJson();
-      float approxDiskCost = json.getBytes().length * collection.count();
-      return new ScanStats(GroupScanProperty.EXACT_ROW_COUNT,
-          collection.count(), 1, approxDiskCost);
+      MongoCollection<Document> collection = db.getCollection(scanSpec.getCollectionName());
+      long numDocs = collection.count();
+      float approxDiskCost = 0;
+      if (numDocs != 0) {
+        String json = collection.find().first().toJson();
+        approxDiskCost = json.getBytes().length * numDocs;
+      }
+      return new ScanStats(GroupScanProperty.EXACT_ROW_COUNT, numDocs, 1, approxDiskCost);
     } catch (Exception e) {
       throw new DrillRuntimeException(e.getMessage(), e);
     }

http://git-wip-us.apache.org/repos/asf/drill/blob/a9383eef/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/MongoTestConstants.java
----------------------------------------------------------------------
diff --git a/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/MongoTestConstants.java
b/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/MongoTestConstants.java
index 73d1470..0ff031a 100644
--- a/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/MongoTestConstants.java
+++ b/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/MongoTestConstants.java
@@ -37,6 +37,7 @@ public interface MongoTestConstants {
 
   public static final String DONUTS_COLLECTION = "donuts";
   public static final String EMPINFO_COLLECTION = "empinfo";
+  public static final String EMPTY_COLLECTION = "empty";
   public static final String SCHEMA_CHANGE_COLLECTION = "schema_change";
 
   public static final String DONUTS_DATA = "donuts.json";

http://git-wip-us.apache.org/repos/asf/drill/blob/a9383eef/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/MongoTestSuit.java
----------------------------------------------------------------------
diff --git a/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/MongoTestSuit.java
b/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/MongoTestSuit.java
index 74ff7d0..01ee915 100644
--- a/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/MongoTestSuit.java
+++ b/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/MongoTestSuit.java
@@ -115,6 +115,7 @@ public class MongoTestSuit implements MongoTestConstants {
         throw new Exception(" Error while starting shrded cluster. ", e);
       }
       createDbAndCollections(DONUTS_DB, DONUTS_COLLECTION, "id");
+      createDbAndCollections(EMPLOYEE_DB, EMPTY_COLLECTION, "field_2");
     }
 
     private static IMongodConfig crateConfigServerConfig(int configServerPort,
@@ -187,6 +188,7 @@ public class MongoTestSuit implements MongoTestConstants {
       mongoClient = new MongoClient(new ServerAddress(LOCALHOST, MONGOS_PORT));
       createDbAndCollections(EMPLOYEE_DB, EMPINFO_COLLECTION, "employee_id");
       createDbAndCollections(EMPLOYEE_DB, SCHEMA_CHANGE_COLLECTION, "field_2");
+      createDbAndCollections(EMPLOYEE_DB, EMPTY_COLLECTION, "field_2");
     }
 
     private static void cleanup() {

http://git-wip-us.apache.org/repos/asf/drill/blob/a9383eef/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/TestMongoQueries.java
----------------------------------------------------------------------
diff --git a/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/TestMongoQueries.java
b/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/TestMongoQueries.java
index bb0c883..fdbc2bc 100644
--- a/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/TestMongoQueries.java
+++ b/contrib/storage-mongo/src/test/java/org/apache/drill/exec/store/mongo/TestMongoQueries.java
@@ -60,6 +60,12 @@ public class TestMongoQueries extends MongoTestBase {
   }
 
   @Test
+  public void testEmptyCollection() throws Exception {
+    String queryString = String.format(TEST_STAR_QUERY_UNSHARDED_DB, EMPLOYEE_DB, EMPTY_COLLECTION);
+    runMongoSQLVerifyCount(queryString, 0);
+  }
+
+  @Test
   public void testUnShardedDBInShardedClusterWithProjectionAndFilter() throws Exception {
     String queryString = String.format(TEST_STAR_QUERY_UNSHARDED_DB_PROJECT_FILTER,
         DONUTS_DB, DONUTS_COLLECTION);


Mime
View raw message