aboutsummaryrefslogtreecommitdiff
path: root/exec/java-exec/src/main/java/org/apache/drill
diff options
context:
space:
mode:
authorArina Ielchiieva <arina.yelchiyeva@gmail.com>2017-02-02 11:47:19 +0000
committerParth Chandra <pchandra@maprtech.com>2017-02-03 17:42:45 -0800
commit1ec3edf01575f302b765b62317ca16c1547dbe10 (patch)
tree506c36cd5bca9311c04614a11d394f380b9008db /exec/java-exec/src/main/java/org/apache/drill
parentc8fbc386c93484b05307f77efe88333746cb8a5e (diff)
DRILL-5238: CTTAS: unable to resolve temporary table if workspace is indicated without schema
This closes #736
Diffstat (limited to 'exec/java-exec/src/main/java/org/apache/drill')
-rw-r--r--exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryContext.java4
-rw-r--r--exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java46
-rw-r--r--exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserSession.java8
3 files changed, 41 insertions, 17 deletions
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryContext.java b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryContext.java
index 101600ccd..4ee8a9d7d 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryContext.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryContext.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -93,7 +93,7 @@ public class QueryContext implements AutoCloseable, OptimizerRulesContext, Schem
plannerSettings.setNumEndPoints(drillbitContext.getBits().size());
table = new DrillOperatorTable(getFunctionRegistry(), drillbitContext.getOptionManager());
- queryContextInfo = Utilities.createQueryContextInfo(session.getDefaultSchemaName(), session.getSessionId());
+ queryContextInfo = Utilities.createQueryContextInfo(session.getDefaultSchemaPath(), session.getSessionId());
contextInformation = new ContextInformation(session.getCredentials(), queryContextInfo);
allocator = drillbitContext.getAllocator().newChildAllocator(
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java
index d20fc060e..3e3226d3e 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/SqlConverter.java
@@ -480,25 +480,27 @@ public class SqlConverter {
private boolean allowTemporaryTables;
DrillCalciteCatalogReader(CalciteSchema rootSchema,
- boolean caseSensitive,
- List<String> defaultSchema,
- JavaTypeFactory typeFactory,
- DrillConfig drillConfig,
- UserSession session) {
+ boolean caseSensitive,
+ List<String> defaultSchema,
+ JavaTypeFactory typeFactory,
+ DrillConfig drillConfig,
+ UserSession session) {
super(rootSchema, caseSensitive, defaultSchema, typeFactory);
this.drillConfig = drillConfig;
this.session = session;
this.allowTemporaryTables = true;
}
- /** Disallow temporary tables presence in sql statement (ex: in view definitions) */
+ /**
+ * Disallow temporary tables presence in sql statement (ex: in view definitions)
+ */
public void disallowTemporaryTables() {
this.allowTemporaryTables = false;
}
/**
* If schema is not indicated (only one element in the list) or schema is default temporary workspace,
- * we need to check among session temporary tables first in default temporary workspace.
+ * we need to check among session temporary tables in default temporary workspace first.
* If temporary table is found and temporary tables usage is allowed, its table instance will be returned,
* otherwise search will be conducted in original workspace.
*
@@ -509,8 +511,8 @@ public class SqlConverter {
@Override
public RelOptTableImpl getTable(final List<String> names) {
RelOptTableImpl temporaryTable = null;
- String schemaPath = SchemaUtilites.getSchemaPath(names.subList(0, names.size() - 1));
- if (names.size() == 1 || SchemaUtilites.isTemporaryWorkspace(schemaPath, drillConfig)) {
+
+ if (mightBeTemporaryTable(names, session.getDefaultSchemaPath(), drillConfig)) {
String temporaryTableName = session.resolveTemporaryTableName(names.get(names.size() - 1));
if (temporaryTableName != null) {
List<String> temporaryNames = Lists.newArrayList(temporarySchema, temporaryTableName);
@@ -528,5 +530,31 @@ public class SqlConverter {
}
return super.getTable(names);
}
+
+ /**
+ * We should check if passed table is temporary or not if:
+ * <li>schema is not indicated (only one element in the names list)<li/>
+ * <li>current schema or indicated schema is default temporary workspace<li/>
+ *
+ * Examples (where dfs.tmp is default temporary workspace):
+ * <li>select * from t<li/>
+ * <li>select * from dfs.tmp.t<li/>
+ * <li>use dfs; select * from tmp.t<li/>
+ *
+ * @param names list of schema and table names, table name is always the last element
+ * @param defaultSchemaPath current schema path set using USE command
+ * @param drillConfig drill config
+ * @return true if check for temporary table should be done, false otherwise
+ */
+ private boolean mightBeTemporaryTable(List<String> names, String defaultSchemaPath, DrillConfig drillConfig) {
+ if (names.size() == 1) {
+ return true;
+ }
+
+ String schemaPath = SchemaUtilites.getSchemaPath(names.subList(0, names.size() - 1));
+ return SchemaUtilites.isTemporaryWorkspace(schemaPath, drillConfig) ||
+ SchemaUtilites.isTemporaryWorkspace(
+ SchemaUtilites.SCHEMA_PATH_JOINER.join(defaultSchemaPath, schemaPath), drillConfig);
+ }
}
}
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserSession.java b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserSession.java
index 27bf3e9a9..c1e577df9 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserSession.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserSession.java
@@ -65,8 +65,8 @@ public class UserSession implements Closeable {
private boolean supportComplexTypes = false;
private UserCredentials credentials;
- private Map<String, String> properties;
private OptionManager sessionOptions;
+ private final Map<String, String> properties;
private final AtomicInteger queryCount;
private final String sessionId;
@@ -121,7 +121,6 @@ public class UserSession implements Closeable {
}
public Builder withUserProperties(UserProperties properties) {
- userSession.properties = Maps.newHashMap();
if (properties != null) {
for (int i = 0; i < properties.getPropertiesCount(); i++) {
final Property property = properties.getProperties(i);
@@ -157,6 +156,7 @@ public class UserSession implements Closeable {
sessionId = UUID.randomUUID().toString();
temporaryTables = Maps.newConcurrentMap();
temporaryLocations = Maps.newConcurrentMap();
+ properties = Maps.newHashMap();
}
public boolean isSupportComplexTypes() {
@@ -189,10 +189,6 @@ public class UserSession implements Closeable {
return properties.get(IMPERSONATION_TARGET);
}
- public String getDefaultSchemaName() {
- return getProp(SCHEMA);
- }
-
public void incrementQueryCount(final QueryCountIncrementer incrementer) {
assert incrementer != null;
queryCount.incrementAndGet();