You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@drill.apache.org by jn...@apache.org on 2015/01/27 00:05:01 UTC
[2/2] drill git commit: DRILL-1655: Fix CanNotPlan issue when join
Mongodb and other datasource,
by ensuring Mongodb plugin return one single instance for each table
reference.
DRILL-1655: Fix CanNotPlan issue when join Mongodb and other datasource, by ensuring Mongodb plugin return one single instance for each table reference.
Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/0abe2738
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/0abe2738
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/0abe2738
Branch: refs/heads/master
Commit: 0abe27387bb7bbcbabd140f569a54c17cd353df0
Parents: 3c6d0ef
Author: Jinfeng Ni <jn...@maprtech.com>
Authored: Fri Jan 23 18:22:16 2015 -0800
Committer: Jinfeng Ni <jn...@maprtech.com>
Committed: Mon Jan 26 08:12:38 2015 -0800
----------------------------------------------------------------------
.../store/mongo/schema/MongoDatabaseSchema.java | 23 ++++++++++++++++----
.../store/mongo/schema/MongoSchemaFactory.java | 15 +++++++++++--
2 files changed, 32 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/drill/blob/0abe2738/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/schema/MongoDatabaseSchema.java
----------------------------------------------------------------------
diff --git a/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/schema/MongoDatabaseSchema.java b/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/schema/MongoDatabaseSchema.java
index 298d1a9..5e63d81 100644
--- a/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/schema/MongoDatabaseSchema.java
+++ b/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/schema/MongoDatabaseSchema.java
@@ -18,10 +18,14 @@
package org.apache.drill.exec.store.mongo.schema;
import java.util.List;
+import java.util.Map;
import java.util.Set;
+import java.util.concurrent.ConcurrentMap;
+import com.google.common.collect.Maps;
import net.hydromatic.optiq.Table;
+import org.apache.drill.exec.planner.logical.DrillTable;
import org.apache.drill.exec.store.AbstractSchema;
import org.apache.drill.exec.store.mongo.MongoStoragePluginConfig;
import org.apache.drill.exec.store.mongo.schema.MongoSchemaFactory.MongoSchema;
@@ -32,23 +36,34 @@ public class MongoDatabaseSchema extends AbstractSchema {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory
.getLogger(MongoDatabaseSchema.class);
private final MongoSchema mongoSchema;
- private final Set<String> tables;
+ private final Set<String> tableNames;
+
+ private final Map<String, DrillTable> drillTables = Maps.newHashMap();
public MongoDatabaseSchema(List<String> tableList, MongoSchema mongoSchema,
String name) {
super(mongoSchema.getSchemaPath(), name);
this.mongoSchema = mongoSchema;
- this.tables = Sets.newHashSet(tableList);
+ this.tableNames = Sets.newHashSet(tableList);
}
@Override
public Table getTable(String tableName) {
- return mongoSchema.getDrillTable(this.name, tableName);
+ if (!tableNames.contains(tableName)) { // table does not exist
+ return null;
+ }
+
+ if (! drillTables.containsKey(tableName)) {
+ drillTables.put(tableName, mongoSchema.getDrillTable(this.name, tableName));
+ }
+
+ return drillTables.get(tableName);
+
}
@Override
public Set<String> getTableNames() {
- return tables;
+ return tableNames;
}
@Override
http://git-wip-us.apache.org/repos/asf/drill/blob/0abe2738/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/schema/MongoSchemaFactory.java
----------------------------------------------------------------------
diff --git a/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/schema/MongoSchemaFactory.java b/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/schema/MongoSchemaFactory.java
index 4abc372..32c42ba 100644
--- a/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/schema/MongoSchemaFactory.java
+++ b/contrib/storage-mongo/src/main/java/org/apache/drill/exec/store/mongo/schema/MongoSchemaFactory.java
@@ -21,10 +21,12 @@ import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
+import com.google.common.collect.Maps;
import net.hydromatic.optiq.Schema;
import net.hydromatic.optiq.SchemaPlus;
@@ -34,6 +36,7 @@ import org.apache.drill.exec.planner.logical.DynamicDrillTable;
import org.apache.drill.exec.rpc.user.UserSession;
import org.apache.drill.exec.store.AbstractSchema;
import org.apache.drill.exec.store.SchemaFactory;
+import org.apache.drill.exec.store.dfs.WorkspaceSchemaFactory;
import org.apache.drill.exec.store.mongo.MongoCnxnManager;
import org.apache.drill.exec.store.mongo.MongoScanSpec;
import org.apache.drill.exec.store.mongo.MongoStoragePlugin;
@@ -126,6 +129,8 @@ public class MongoSchemaFactory implements SchemaFactory {
class MongoSchema extends AbstractSchema {
+ private final Map<String, MongoDatabaseSchema> schemaMap = Maps.newHashMap();
+
public MongoSchema(String name) {
super(ImmutableList.<String> of(), name);
}
@@ -134,8 +139,14 @@ public class MongoSchemaFactory implements SchemaFactory {
public Schema getSubSchema(String name) {
List<String> tables;
try {
- tables = tableNameLoader.get(name);
- return new MongoDatabaseSchema(tables, this, name);
+ if (! schemaMap.containsKey(name)) {
+ tables = tableNameLoader.get(name);
+ schemaMap.put(name, new MongoDatabaseSchema(tables, this, name));
+ }
+
+ return schemaMap.get(name);
+
+ //return new MongoDatabaseSchema(tables, this, name);
} catch (ExecutionException e) {
logger.warn("Failure while attempting to access MongoDataBase '{}'.",
name, e.getCause());