drill-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sudhe...@apache.org
Subject [09/29] drill git commit: DRILL-5088: Set client's codec for toJson
Date Sat, 25 Feb 2017 07:18:02 GMT
DRILL-5088: Set client's codec for toJson

closes #702


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

Branch: refs/heads/master
Commit: b892b997dfa0259550942f076b0afd89b27c9fdf
Parents: 5db557c
Author: chunhui-shi <cshi@maprtech.com>
Authored: Sun Dec 18 00:27:50 2016 -0800
Committer: Sudheesh Katkam <sudheesh@apache.org>
Committed: Fri Feb 24 19:01:40 2017 -0800

----------------------------------------------------------------------
 .../org/apache/drill/exec/store/mongo/MongoGroupScan.java    | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/b892b997/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 43b5c6d..b834193 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
@@ -52,6 +52,8 @@ import org.apache.drill.exec.store.StoragePluginRegistry;
 import org.apache.drill.exec.store.mongo.MongoSubScan.MongoSubScanSpec;
 import org.apache.drill.exec.store.mongo.common.ChunkInfo;
 import org.bson.Document;
+import org.bson.codecs.BsonTypeClassMap;
+import org.bson.codecs.DocumentCodec;
 import org.bson.conversions.Bson;
 import org.bson.types.MaxKey;
 import org.bson.types.MinKey;
@@ -503,7 +505,11 @@ public class MongoGroupScan extends AbstractGroupScan implements
       long numDocs = collection.count();
       float approxDiskCost = 0;
       if (numDocs != 0) {
-        String json = collection.find().first().toJson();
+        //toJson should use client's codec, otherwise toJson could fail on
+        // some types not known to DocumentCodec, e.g. DBRef.
+        final DocumentCodec codec =
+            new DocumentCodec(client.getMongoClientOptions().getCodecRegistry(), new BsonTypeClassMap());
+        String json = collection.find().first().toJson(codec);
         approxDiskCost = json.getBytes().length * numDocs;
       }
       return new ScanStats(GroupScanProperty.EXACT_ROW_COUNT, numDocs, 1, approxDiskCost);


Mime
View raw message