You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@drill.apache.org by ja...@apache.org on 2014/05/08 04:50:48 UTC
[5/5] git commit: DRILL-438: Add support for Views (CREATE,
DROP and select)
DRILL-438: Add support for Views (CREATE, DROP and select)
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/b7bf00cb
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/b7bf00cb
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/b7bf00cb
Branch: refs/heads/master
Commit: b7bf00cbbdc410861061e59b122a40083b527564
Parents: cd4f281
Author: vkorukanti <ve...@gmail.com>
Authored: Thu Apr 24 11:57:44 2014 -0700
Committer: Jacques Nadeau <ja...@apache.org>
Committed: Wed May 7 19:18:42 2014 -0700
----------------------------------------------------------------------
.../exec/store/hbase/HBaseSchemaFactory.java | 11 +-
.../exec/store/hbase/HBaseStoragePlugin.java | 5 +-
exec/java-exec/src/main/codegen/data/Parser.tdd | 7 +-
.../src/main/codegen/includes/parserImpls.ftl | 52 ++++
.../apache/drill/exec/ops/FragmentContext.java | 12 +-
.../org/apache/drill/exec/ops/QueryContext.java | 2 +-
.../drill/exec/planner/logical/DrillOptiq.java | 1 +
.../exec/planner/logical/DrillViewTable.java | 66 +++++
.../drill/exec/planner/sql/DrillSqlWorker.java | 17 +-
.../exec/planner/sql/handlers/ViewHandler.java | 146 +++++++++++
.../exec/planner/sql/parser/DrillSqlCall.java | 39 +++
.../exec/planner/sql/parser/SqlCreateView.java | 100 ++++++++
.../planner/sql/parser/SqlDescribeTable.java | 11 +-
.../exec/planner/sql/parser/SqlDropView.java | 65 +++++
.../exec/planner/sql/parser/SqlShowSchemas.java | 10 +-
.../exec/planner/sql/parser/SqlShowTables.java | 11 +-
.../exec/planner/sql/parser/SqlUseSchema.java | 11 +-
.../types/DrillFixedRelDataTypeImpl.java | 104 ++++++++
.../apache/drill/exec/rpc/user/UserSession.java | 5 +
.../apache/drill/exec/rpc/user/ViewStore.java | 93 +++++++
.../apache/drill/exec/store/AbstractSchema.java | 17 +-
.../apache/drill/exec/store/SchemaFactory.java | 3 +-
.../drill/exec/store/StoragePluginRegistry.java | 5 +-
.../drill/exec/store/dfs/FileSystemPlugin.java | 10 +-
.../exec/store/dfs/FileSystemSchemaFactory.java | 19 +-
.../exec/store/dfs/WorkspaceSchemaFactory.java | 35 ++-
.../exec/store/hive/HiveStoragePlugin.java | 6 +-
.../store/hive/schema/HiveDatabaseSchema.java | 5 +-
.../store/hive/schema/HiveSchemaFactory.java | 8 +-
.../store/ischema/InfoSchemaStoragePlugin.java | 9 +-
.../exec/store/mock/MockStorageEngine.java | 3 +-
.../drill/exec/store/sys/SystemTablePlugin.java | 7 +-
.../java/org/apache/drill/PlanningBase.java | 2 +-
.../org/apache/drill/TestTpchSingleMode.java | 2 +-
.../drill/exec/store/TestOrphanSchema.java | 3 +-
.../drill/exec/store/ischema/OrphanSchema.java | 3 +-
.../src/test/resources/queries/tpch/15.sql | 2 +
.../apache/drill/jdbc/test/TestJdbcQuery.java | 251 ++++++++++++++++++-
38 files changed, 1082 insertions(+), 76 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseSchemaFactory.java
----------------------------------------------------------------------
diff --git a/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseSchemaFactory.java b/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseSchemaFactory.java
index 7f67f83..c4ac08c 100644
--- a/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseSchemaFactory.java
+++ b/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseSchemaFactory.java
@@ -19,14 +19,17 @@ package org.apache.drill.exec.store.hbase;
import java.io.IOException;
import java.util.Collections;
+import java.util.List;
import java.util.Set;
+import com.google.common.collect.ImmutableList;
import net.hydromatic.optiq.Schema;
import net.hydromatic.optiq.SchemaPlus;
+import net.hydromatic.optiq.Table;
import org.apache.drill.exec.planner.logical.DrillTable;
import org.apache.drill.exec.planner.logical.DynamicDrillTable;
-import org.apache.drill.exec.rpc.user.DrillUser;
+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.hadoop.hbase.HTableDescriptor;
@@ -46,7 +49,7 @@ public class HBaseSchemaFactory implements SchemaFactory {
}
@Override
- public void registerSchemas(DrillUser user, SchemaPlus parent) {
+ public void registerSchemas(UserSession session, SchemaPlus parent) {
HBaseSchema schema = new HBaseSchema(schemaName);
SchemaPlus hPlus = parent.add(schemaName, schema);
schema.setHolder(hPlus);
@@ -55,7 +58,7 @@ public class HBaseSchemaFactory implements SchemaFactory {
class HBaseSchema extends AbstractSchema {
public HBaseSchema(String name) {
- super(name);
+ super(ImmutableList.<String>of(), name);
}
public void setHolder(SchemaPlus plusOfThis) {
@@ -72,7 +75,7 @@ public class HBaseSchemaFactory implements SchemaFactory {
}
@Override
- public DrillTable getTable(String name) {
+ public Table getTable(String name) {
Object selection = new HBaseScanSpec(name);
return new DynamicDrillTable(plugin, schemaName, selection, plugin.getConfig());
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseStoragePlugin.java
----------------------------------------------------------------------
diff --git a/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseStoragePlugin.java b/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseStoragePlugin.java
index c1fb6af..ea1550d 100644
--- a/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseStoragePlugin.java
+++ b/contrib/storage-hbase/src/main/java/org/apache/drill/exec/store/hbase/HBaseStoragePlugin.java
@@ -27,6 +27,7 @@ import org.apache.drill.common.JSONOptions;
import org.apache.drill.exec.rpc.user.DrillUser;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.logical.StoragePluginConfig;
+import org.apache.drill.exec.rpc.user.UserSession;
import org.apache.drill.exec.server.DrillbitContext;
import org.apache.drill.exec.store.AbstractStoragePlugin;
import org.apache.drill.exec.store.StoragePluginOptimizerRule;
@@ -67,8 +68,8 @@ public class HBaseStoragePlugin extends AbstractStoragePlugin {
}
@Override
- public void registerSchemas(DrillUser user, SchemaPlus parent) {
- schemaFactory.registerSchemas(user, parent);
+ public void registerSchemas(UserSession session, SchemaPlus parent) {
+ schemaFactory.registerSchemas(session, parent);
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/codegen/data/Parser.tdd
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/data/Parser.tdd b/exec/java-exec/src/main/codegen/data/Parser.tdd
index 4f47795..176ee79 100644
--- a/exec/java-exec/src/main/codegen/data/Parser.tdd
+++ b/exec/java-exec/src/main/codegen/data/Parser.tdd
@@ -29,9 +29,10 @@
# List of keywords.
keywords: [
"DATABASES",
+ "REPLACE",
"SCHEMAS",
"SHOW",
- "TABLES"
+ "TABLES",
"USE"
]
@@ -40,7 +41,9 @@
"SqlShowTables()",
"SqlShowSchemas()",
"SqlDescribeTable()",
- "SqlUseSchema()"
+ "SqlUseSchema()",
+ "SqlCreateOrReplaceView()",
+ "SqlDropView()"
]
# List of methods for parsing custom literals.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/codegen/includes/parserImpls.ftl
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/codegen/includes/parserImpls.ftl b/exec/java-exec/src/main/codegen/includes/parserImpls.ftl
index cd5ee72..5b6e2b5 100644
--- a/exec/java-exec/src/main/codegen/includes/parserImpls.ftl
+++ b/exec/java-exec/src/main/codegen/includes/parserImpls.ftl
@@ -113,3 +113,55 @@ SqlNode SqlUseSchema():
return new SqlUseSchema(pos, schema);
}
}
+
+/**
+ * Parses a create view or replace existing view statement.
+ * CREATE [OR REPLACE] VIEW view_name AS select_statement
+ */
+SqlNode SqlCreateOrReplaceView() :
+{
+ SqlParserPos pos;
+ boolean replaceView = false;
+ SqlIdentifier viewName;
+ SqlNode query;
+ SqlNodeList fieldList = null;
+}
+{
+ <CREATE> { pos = getPos(); }
+ [ <OR> <REPLACE> { replaceView = true; } ]
+ <VIEW>
+ viewName = CompoundIdentifier()
+ [
+ <LPAREN>
+ fieldList = SimpleIdentifierCommaList()
+ <RPAREN>
+ {
+ for(SqlNode node : fieldList)
+ {
+ if (((SqlIdentifier)node).isStar())
+ throw new ParseException("View's field list has a '*', which is invalid.");
+ }
+ }
+ ]
+ <AS>
+ query = OrderedQueryOrExpr(ExprContext.ACCEPT_QUERY)
+ {
+ return new SqlCreateView(pos, viewName, fieldList, query, replaceView);
+ }
+}
+
+/**
+ * Parses a drop view statement.
+ * DROP VIEW view_name;
+ */
+SqlNode SqlDropView() :
+{
+ SqlParserPos pos;
+}
+{
+ <DROP> { pos = getPos(); }
+ <VIEW>
+ {
+ return new SqlDropView(pos, CompoundIdentifier());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
index 2a6ab0e..38d76e0 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/ops/FragmentContext.java
@@ -123,9 +123,15 @@ public class FragmentContext implements Closeable {
}
public SchemaPlus getRootSchema(){
- SchemaPlus root = Frameworks.createRootSchema();
- context.getStorage().getSchemaFactory().registerSchemas(null, root);
- return root;
+ if (connection == null) {
+ fail(new UnsupportedOperationException("Schema tree can only be created in root fragment. " +
+ "This is a non-root fragment."));
+ return null;
+ } else {
+ SchemaPlus root = Frameworks.createRootSchema();
+ context.getStorage().getSchemaFactory().registerSchemas(connection.getSession(), root);
+ return root;
+ }
}
/**
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/ops/QueryContext.java
----------------------------------------------------------------------
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 f6ce04f..e3d2f54 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
@@ -79,7 +79,7 @@ public class QueryContext{
public SchemaPlus getRootSchema(){
SchemaPlus rootSchema = Frameworks.createRootSchema();
- drillbitContext.getSchemaFactory().registerSchemas(session.getUser(), rootSchema);
+ drillbitContext.getSchemaFactory().registerSchemas(session, rootSchema);
return rootSchema;
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
index 2e61970..aee6da4 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillOptiq.java
@@ -249,6 +249,7 @@ public class DrillOptiq {
case "INTERVAL_YEAR_MONTH": castType = Types.required(MinorType.INTERVALYEAR); break;
case "INTERVAL_DAY_TIME": castType = Types.required(MinorType.INTERVALDAY); break;
+ case "ANY": return arg; // Type will be same as argument.
default: castType = Types.required(MinorType.valueOf(call.getType().getSqlTypeName().getName()));
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillViewTable.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillViewTable.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillViewTable.java
new file mode 100644
index 0000000..6415869
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/logical/DrillViewTable.java
@@ -0,0 +1,66 @@
+/**
+ * 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
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.logical;
+
+import com.google.common.collect.ImmutableList;
+import net.hydromatic.optiq.impl.ViewTable;
+import org.apache.drill.exec.planner.types.DrillFixedRelDataTypeImpl;
+import org.apache.drill.exec.planner.types.RelDataTypeDrillImpl;
+import org.apache.drill.exec.planner.types.RelDataTypeHolder;
+import org.eigenbase.rel.RelNode;
+import org.eigenbase.relopt.RelOptTable;
+import org.eigenbase.relopt.RelOptTable.ToRelContext;
+import org.eigenbase.relopt.RelOptUtil;
+import org.eigenbase.reltype.*;
+
+import java.util.List;
+
+public class DrillViewTable extends ViewTable {
+ private RelDataType rowType;
+ private boolean starSchema = false; // is the view schema "*"?
+ private RelDataTypeHolder holder = new RelDataTypeHolder();
+
+ public DrillViewTable(String viewSql, List<String> schemaPath, RelDataType rowType) {
+ super(Object.class, null, viewSql, schemaPath);
+
+ this.rowType = rowType;
+ if (rowType.getFieldCount() == 1 && rowType.getFieldNames().get(0).equals("*"))
+ starSchema = true;
+ }
+
+ @Override
+ public RelDataType getRowType(RelDataTypeFactory typeFactory) {
+ // if the view's schema is a "*" schema, create dynamic row type. Otherwise create fixed row type.
+ if (starSchema)
+ return new RelDataTypeDrillImpl(holder, typeFactory);
+
+ return rowType;
+ }
+
+ @Override
+ public RelNode toRel(ToRelContext context, RelOptTable relOptTable) {
+ RelDataType rowType = relOptTable.getRowType();
+ RelNode rel = context.expandView(rowType, getViewSql(), getSchemaPath());
+
+ // if the View's field list is not "*", try to create a cast.
+ if (!starSchema)
+ return RelOptUtil.createCastRel(rel, rowType, true);
+
+ return rel;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java
index 048d116..6e9a00f 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/DrillSqlWorker.java
@@ -34,17 +34,10 @@ import org.apache.drill.exec.physical.PhysicalPlan;
import org.apache.drill.exec.planner.logical.DrillRuleSets;
import org.apache.drill.exec.planner.physical.DrillDistributionTraitDef;
import org.apache.drill.exec.planner.sql.handlers.DefaultSqlHandler;
-import org.apache.drill.exec.planner.sql.handlers.DescribeTableHandler;
import org.apache.drill.exec.planner.sql.handlers.ExplainHandler;
import org.apache.drill.exec.planner.sql.handlers.SetOptionHandler;
-import org.apache.drill.exec.planner.sql.handlers.ShowSchemasHandler;
-import org.apache.drill.exec.planner.sql.handlers.ShowTablesHandler;
import org.apache.drill.exec.planner.sql.handlers.SqlHandler;
-import org.apache.drill.exec.planner.sql.handlers.UseSchemaHandler;
-import org.apache.drill.exec.planner.sql.parser.SqlDescribeTable;
-import org.apache.drill.exec.planner.sql.parser.SqlShowSchemas;
-import org.apache.drill.exec.planner.sql.parser.SqlShowTables;
-import org.apache.drill.exec.planner.sql.parser.SqlUseSchema;
+import org.apache.drill.exec.planner.sql.parser.DrillSqlCall;
import org.apache.drill.exec.planner.sql.parser.impl.DrillParserImpl;
import org.apache.drill.exec.store.StoragePluginRegistry;
import org.eigenbase.rel.RelCollationTraitDef;
@@ -113,10 +106,10 @@ public class DrillSqlWorker {
handler = new SetOptionHandler(context);
break;
case OTHER:
- if (sqlNode instanceof SqlShowTables){ handler = new ShowTablesHandler(planner, context); break; }
- else if (sqlNode instanceof SqlShowSchemas){ handler = new ShowSchemasHandler(planner, context); break; }
- else if (sqlNode instanceof SqlDescribeTable){ handler = new DescribeTableHandler(planner, context); break; }
- else if (sqlNode instanceof SqlUseSchema){ handler = new UseSchemaHandler(context); break; }
+ if (sqlNode instanceof DrillSqlCall) {
+ handler = ((DrillSqlCall)sqlNode).getSqlHandler(planner, context);
+ break;
+ }
// fallthrough
default:
handler = new DefaultSqlHandler(planner, context);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
new file mode 100644
index 0000000..a78c54f
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/ViewHandler.java
@@ -0,0 +1,146 @@
+/**
+ * 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
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.sql.handlers;
+
+import java.io.IOException;
+import java.util.List;
+
+import com.google.common.base.Joiner;
+import net.hydromatic.optiq.SchemaPlus;
+import net.hydromatic.optiq.impl.ViewTable;
+import net.hydromatic.optiq.tools.Planner;
+import net.hydromatic.optiq.tools.RelConversionException;
+import net.hydromatic.optiq.tools.ValidationException;
+
+import org.apache.drill.exec.ops.QueryContext;
+import org.apache.drill.exec.physical.PhysicalPlan;
+import org.apache.drill.exec.planner.logical.DrillViewTable;
+import org.apache.drill.exec.planner.sql.DirectPlan;
+import org.apache.drill.exec.planner.sql.parser.SqlCreateView;
+import org.apache.drill.exec.planner.sql.parser.SqlDropView;
+import org.apache.drill.exec.planner.types.DrillFixedRelDataTypeImpl;
+import org.apache.drill.exec.store.AbstractSchema;
+import org.eigenbase.rel.RelNode;
+import org.eigenbase.reltype.RelDataType;
+import org.eigenbase.sql.SqlNode;
+
+public abstract class ViewHandler implements SqlHandler{
+ static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ViewHandler.class);
+
+ protected Planner planner;
+ protected QueryContext context;
+
+ public ViewHandler(Planner planner, QueryContext context) {
+ this.planner = planner;
+ this.context = context;
+ }
+
+ /** From a given SchemaPlus return a mutable Drill schema object AbstractSchema if exists. Otherwise throw errors. */
+ protected static AbstractSchema getDrillSchema(SchemaPlus schemaPlus) throws Exception{
+ AbstractSchema drillSchema;
+ try {
+ drillSchema = schemaPlus.unwrap(AbstractSchema.class);
+ } catch(ClassCastException e) {
+ throw new Exception(String.format("Can't create view in schema '%s'", schemaPlus.getName()), e);
+ }
+
+ if (!drillSchema.isMutable())
+ throw new Exception(String.format("Views are not allowed in schema '%s'", schemaPlus.getName()));
+
+ return drillSchema;
+ }
+
+ /** Handler for Create View DDL command */
+ public static class CreateView extends ViewHandler {
+
+ public CreateView(Planner planner, QueryContext context) {
+ super(planner, context);
+ }
+
+ @Override
+ public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException {
+ SqlCreateView createView = DefaultSqlHandler.unwrap(sqlNode, SqlCreateView.class);
+
+ try {
+ AbstractSchema drillSchema = getDrillSchema(context.getNewDefaultSchema());
+
+ String viewSql = createView.getQuery().toString();
+
+ SqlNode validatedQuery = planner.validate(createView.getQuery());
+ RelNode validatedRelNode = planner.convert(validatedQuery);
+
+ // If view's field list is specified then its size should match view's query field list size.
+ RelDataType queryRowType = validatedRelNode.getRowType();
+
+ List<String> viewFieldNames = createView.getFieldNames();
+ if (viewFieldNames.size() > 0) {
+ // number of fields match.
+ if (viewFieldNames.size() != queryRowType.getFieldCount())
+ throw new Exception("View's field list and View's query field list have different counts.");
+
+ // make sure View's query field list has no "*"
+ for(String field : queryRowType.getFieldNames()) {
+ if (field.equals("*"))
+ throw new Exception("View's query field list has a '*', which is invalid when View's field list is specified.");
+ }
+
+ queryRowType = new DrillFixedRelDataTypeImpl(planner.getTypeFactory(), viewFieldNames);
+ }
+
+ ViewTable viewTable = new DrillViewTable(viewSql, drillSchema.getSchemaPath(), queryRowType);
+
+ String schemaPath = Joiner.on(".").join(drillSchema.getSchemaPath());
+
+ boolean replaced = context.getSession().getViewStore().addView(
+ schemaPath, createView.getViewName(), viewTable, createView.getReplace());
+
+ String summary = String.format("View '%s' %s successfully in '%s' schema",
+ createView.getViewName(), replaced ? "replaced" : "created", schemaPath);
+
+ return DirectPlan.createDirectPlan(context, true, summary);
+ } catch(Exception e) {
+ logger.error("Failed to create view '{}'", createView.getViewName(), e);
+ return DirectPlan.createDirectPlan(context, false, String.format("Error: %s", e.getMessage()));
+ }
+ }
+ }
+
+ /** Handler for Drop View DDL command. */
+ public static class DropView extends ViewHandler {
+ public DropView(QueryContext context) {
+ super(null, context);
+ }
+
+ @Override
+ public PhysicalPlan getPlan(SqlNode sqlNode) throws ValidationException, RelConversionException, IOException {
+ SqlDropView createView = DefaultSqlHandler.unwrap(sqlNode, SqlDropView.class);
+
+ try {
+ AbstractSchema drillSchema = getDrillSchema(context.getNewDefaultSchema());
+ String schemaPath = Joiner.on(".").join(drillSchema.getSchemaPath());
+ context.getSession().getViewStore().dropView(schemaPath, createView.getViewName());
+
+ return DirectPlan.createDirectPlan(context, true,
+ String.format("View '%s' deleted successfully from '%s' schema", createView.getViewName(), schemaPath));
+ } catch(Exception e) {
+ logger.debug("Failed to delete view {}", createView.getViewName(), e);
+ return DirectPlan.createDirectPlan(context, false, String.format("Error: %s", e.getMessage()));
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/DrillSqlCall.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/DrillSqlCall.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/DrillSqlCall.java
new file mode 100644
index 0000000..32f57b4
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/DrillSqlCall.java
@@ -0,0 +1,39 @@
+/**
+ * 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
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.sql.parser;
+
+import net.hydromatic.optiq.tools.Planner;
+import org.apache.drill.exec.ops.QueryContext;
+import org.apache.drill.exec.planner.sql.handlers.DefaultSqlHandler;
+import org.apache.drill.exec.planner.sql.handlers.SqlHandler;
+import org.eigenbase.sql.SqlCall;
+import org.eigenbase.sql.parser.SqlParserPos;
+
+/**
+ * SqlCall interface with addition of method to get the handler.
+ */
+public abstract class DrillSqlCall extends SqlCall {
+
+ public DrillSqlCall(SqlParserPos pos) {
+ super(pos);
+ }
+
+ public SqlHandler getSqlHandler(Planner planner, QueryContext context) {
+ return new DefaultSqlHandler(planner, context);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlCreateView.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlCreateView.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlCreateView.java
new file mode 100644
index 0000000..b124e1d
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlCreateView.java
@@ -0,0 +1,100 @@
+/**
+ * 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
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.sql.parser;
+
+import com.google.common.collect.Lists;
+import com.google.common.collect.ImmutableList;
+import net.hydromatic.optiq.tools.Planner;
+import org.apache.drill.exec.ops.QueryContext;
+import org.apache.drill.exec.planner.sql.handlers.SqlHandler;
+import org.apache.drill.exec.planner.sql.handlers.ViewHandler;
+import org.eigenbase.sql.*;
+import org.eigenbase.sql.parser.SqlParserPos;
+
+import java.util.List;
+
+public class SqlCreateView extends DrillSqlCall {
+ public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("CREATE_VIEW", SqlKind.OTHER);
+
+ private SqlIdentifier viewName;
+ private SqlNodeList fieldList;
+ private SqlNode query;
+ private boolean replaceView;
+
+ public SqlCreateView(SqlParserPos pos, SqlIdentifier viewName, SqlNodeList fieldList,
+ SqlNode query, boolean replaceView) {
+ super(pos);
+ this.viewName = viewName;
+ this.query = query;
+ this.replaceView = replaceView;
+ this.fieldList = fieldList;
+ }
+
+ @Override
+ public SqlOperator getOperator() {
+ return OPERATOR;
+ }
+
+ @Override
+ public List<SqlNode> getOperandList() {
+ return ImmutableList.of(viewName, fieldList, query,
+ SqlLiteral.createBoolean(replaceView, SqlParserPos.ZERO));
+ }
+
+ @Override
+ public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
+ writer.keyword("CREATE");
+ if (replaceView) {
+ writer.keyword("OR");
+ writer.keyword("REPLACE");
+ }
+ writer.keyword("VIEW");
+ viewName.unparse(writer, leftPrec, rightPrec);
+ if (fieldList != null && fieldList.size() > 0) {
+ writer.keyword("(");
+ fieldList.get(0).unparse(writer, leftPrec, rightPrec);
+ for(int i=1; i<fieldList.size(); i++) {
+ writer.keyword(",");
+ fieldList.get(i).unparse(writer, leftPrec, rightPrec);
+ }
+ writer.keyword(")");
+ }
+ writer.keyword("AS");
+ query.unparse(writer, leftPrec, rightPrec);
+ }
+
+ @Override
+ public SqlHandler getSqlHandler(Planner planner, QueryContext context) {
+ return new ViewHandler.CreateView(planner, context);
+ }
+
+ public String getViewName() { return viewName.getSimple(); }
+
+ public List<String> getFieldNames() {
+ if (fieldList == null) return ImmutableList.of();
+
+ List<String> fieldNames = Lists.newArrayList();
+ for(SqlNode node : fieldList.getList()) {
+ fieldNames.add(node.toString());
+ }
+ return fieldNames;
+ }
+
+ public SqlNode getQuery() { return query; }
+ public boolean getReplace() { return replaceView; }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlDescribeTable.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlDescribeTable.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlDescribeTable.java
index 24c2d03..0a666de 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlDescribeTable.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlDescribeTable.java
@@ -18,6 +18,10 @@
package org.apache.drill.exec.planner.sql.parser;
import com.google.common.collect.Lists;
+import net.hydromatic.optiq.tools.Planner;
+import org.apache.drill.exec.ops.QueryContext;
+import org.apache.drill.exec.planner.sql.handlers.DescribeTableHandler;
+import org.apache.drill.exec.planner.sql.handlers.SqlHandler;
import org.eigenbase.sql.*;
import org.eigenbase.sql.parser.SqlParserPos;
@@ -27,7 +31,7 @@ import java.util.List;
* Sql parser tree node to represent statement:
* { DESCRIBE | DESC } tblname [col_name | wildcard ]
*/
-public class SqlDescribeTable extends SqlCall {
+public class SqlDescribeTable extends DrillSqlCall {
private final SqlIdentifier table;
private final SqlIdentifier column;
@@ -66,6 +70,11 @@ public class SqlDescribeTable extends SqlCall {
if (columnQualifier != null) columnQualifier.unparse(writer, leftPrec, rightPrec);
}
+ @Override
+ public SqlHandler getSqlHandler(Planner planner, QueryContext context) {
+ return new DescribeTableHandler(planner, context);
+ }
+
public SqlIdentifier getTable() { return table; }
public SqlIdentifier getColumn() { return column; }
public SqlNode getColumnQualifier() { return columnQualifier; }
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlDropView.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlDropView.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlDropView.java
new file mode 100644
index 0000000..8ba7edd
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlDropView.java
@@ -0,0 +1,65 @@
+/**
+ * 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
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.sql.parser;
+
+import com.google.common.collect.ImmutableList;
+import net.hydromatic.optiq.tools.Planner;
+import org.apache.drill.exec.ops.QueryContext;
+import org.apache.drill.exec.planner.sql.handlers.SqlHandler;
+import org.apache.drill.exec.planner.sql.handlers.ViewHandler.DropView;
+import org.eigenbase.sql.*;
+import org.eigenbase.sql.parser.SqlParserPos;
+
+import java.util.List;
+
+public class SqlDropView extends DrillSqlCall {
+ public static final SqlSpecialOperator OPERATOR = new SqlSpecialOperator("DROP_VIEW", SqlKind.OTHER);
+
+ private SqlIdentifier viewName;
+
+ public SqlDropView(SqlParserPos pos, SqlIdentifier viewName) {
+ super(pos);
+ this.viewName = viewName;
+ }
+
+ @Override
+ public SqlOperator getOperator() {
+ return OPERATOR;
+ }
+
+ @Override
+ public List<SqlNode> getOperandList() {
+ return ImmutableList.of((SqlNode)viewName);
+ }
+
+ @Override
+ public void unparse(SqlWriter writer, int leftPrec, int rightPrec) {
+ writer.keyword("DROP");
+ writer.keyword("VIEW");
+ viewName.unparse(writer, leftPrec, rightPrec);
+ }
+
+ @Override
+ public SqlHandler getSqlHandler(Planner planner, QueryContext context) {
+ return new DropView(context);
+ }
+
+ public String getViewName() {
+ return viewName.toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlShowSchemas.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlShowSchemas.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlShowSchemas.java
index 526ae04..aa212a7 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlShowSchemas.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlShowSchemas.java
@@ -20,7 +20,8 @@ package org.apache.drill.exec.planner.sql.parser;
import com.google.common.collect.Lists;
import net.hydromatic.optiq.tools.Planner;
import org.apache.drill.exec.ops.QueryContext;
-import org.apache.drill.exec.planner.sql.handlers.DefaultSqlHandler;
+import org.apache.drill.exec.planner.sql.handlers.ShowSchemasHandler;
+import org.apache.drill.exec.planner.sql.handlers.SqlHandler;
import org.eigenbase.sql.*;
import org.eigenbase.sql.parser.SqlParserPos;
@@ -30,7 +31,7 @@ import java.util.List;
* Sql parse tree node to represent statement:
* SHOW {DATABASES | SCHEMAS} [LIKE 'pattern' | WHERE expr]
*/
-public class SqlShowSchemas extends SqlCall {
+public class SqlShowSchemas extends DrillSqlCall {
private final SqlNode likePattern;
private final SqlNode whereClause;
@@ -68,6 +69,11 @@ public class SqlShowSchemas extends SqlCall {
if (whereClause != null) whereClause.unparse(writer, leftPrec, rightPrec);
}
+ @Override
+ public SqlHandler getSqlHandler(Planner planner, QueryContext context) {
+ return new ShowSchemasHandler(planner, context);
+ }
+
public SqlNode getLikePattern() { return likePattern; }
public SqlNode getWhereClause() { return whereClause; }
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlShowTables.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlShowTables.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlShowTables.java
index aad5ca5..e3be378 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlShowTables.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlShowTables.java
@@ -18,6 +18,10 @@
package org.apache.drill.exec.planner.sql.parser;
import com.google.common.collect.Lists;
+import net.hydromatic.optiq.tools.Planner;
+import org.apache.drill.exec.ops.QueryContext;
+import org.apache.drill.exec.planner.sql.handlers.ShowTablesHandler;
+import org.apache.drill.exec.planner.sql.handlers.SqlHandler;
import org.eigenbase.sql.*;
import org.eigenbase.sql.parser.SqlParserPos;
@@ -27,7 +31,7 @@ import java.util.List;
* Sql parse tree node to represent statement:
* SHOW TABLES [{FROM | IN} db_name] [LIKE 'pattern' | WHERE expr]
*/
-public class SqlShowTables extends SqlCall {
+public class SqlShowTables extends DrillSqlCall {
private final SqlIdentifier db;
private final SqlNode likePattern;
@@ -69,6 +73,11 @@ public class SqlShowTables extends SqlCall {
if (whereClause != null) whereClause.unparse(writer, leftPrec, rightPrec);
}
+ @Override
+ public SqlHandler getSqlHandler(Planner planner, QueryContext context) {
+ return new ShowTablesHandler(planner, context);
+ }
+
public SqlIdentifier getDb() { return db; }
public SqlNode getLikePattern() { return likePattern; }
public SqlNode getWhereClause() { return whereClause; }
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlUseSchema.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlUseSchema.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlUseSchema.java
index a48963e..92d3aff 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlUseSchema.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/parser/SqlUseSchema.java
@@ -18,6 +18,10 @@
package org.apache.drill.exec.planner.sql.parser;
import com.google.common.collect.ImmutableList;
+import net.hydromatic.optiq.tools.Planner;
+import org.apache.drill.exec.ops.QueryContext;
+import org.apache.drill.exec.planner.sql.handlers.SqlHandler;
+import org.apache.drill.exec.planner.sql.handlers.UseSchemaHandler;
import org.eigenbase.sql.*;
import org.eigenbase.sql.parser.SqlParserPos;
@@ -26,7 +30,7 @@ import java.util.List;
/**
* Sql parser tree node to represent <code>USE SCHEMA</code> statement.
*/
-public class SqlUseSchema extends SqlCall {
+public class SqlUseSchema extends DrillSqlCall {
public static final SqlSpecialOperator OPERATOR =
new SqlSpecialOperator("USE_SCHEMA", SqlKind.OTHER);
@@ -54,6 +58,11 @@ public class SqlUseSchema extends SqlCall {
schema.unparse(writer, leftPrec, rightPrec);
}
+ @Override
+ public SqlHandler getSqlHandler(Planner planner, QueryContext context) {
+ return new UseSchemaHandler(context);
+ }
+
/**
* Get the schema name. A schema identifier can contain more than one level of schema.
* Ex: "dfs.home" identifier contains two levels "dfs" and "home".
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/planner/types/DrillFixedRelDataTypeImpl.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/planner/types/DrillFixedRelDataTypeImpl.java b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/types/DrillFixedRelDataTypeImpl.java
new file mode 100644
index 0000000..f20a174
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/planner/types/DrillFixedRelDataTypeImpl.java
@@ -0,0 +1,104 @@
+/**
+ * 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
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.planner.types;
+
+import com.google.common.collect.Lists;
+import org.eigenbase.reltype.RelDataTypeFactory;
+import org.eigenbase.reltype.RelDataTypeField;
+import org.eigenbase.reltype.RelDataTypeFieldImpl;
+import org.eigenbase.reltype.RelDataTypeImpl;
+import org.eigenbase.reltype.RelDataTypePrecedenceList;
+import org.eigenbase.sql.type.SqlTypeExplicitPrecedenceList;
+import org.eigenbase.sql.type.SqlTypeName;
+
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Implements RowType for fixed field list with ANY type.
+ */
+public class DrillFixedRelDataTypeImpl extends RelDataTypeImpl {
+ private List<RelDataTypeField> fields = Lists.newArrayList();
+ private final RelDataTypeFactory typeFactory;
+
+ public DrillFixedRelDataTypeImpl(RelDataTypeFactory typeFactory, List<String> columnNames) {
+ this.typeFactory = typeFactory;
+
+ // Add the initial list of columns.
+ for (String column : columnNames)
+ addField(column);
+ computeDigest();
+ }
+
+ private void addField(String columnName) {
+ RelDataTypeField newField = new RelDataTypeFieldImpl(
+ columnName, fields.size(), typeFactory.createSqlType(SqlTypeName.ANY));
+ fields.add(newField);
+ }
+
+ @Override
+ public List<RelDataTypeField> getFieldList() {
+ return fields;
+ }
+
+ @Override
+ public int getFieldCount() {
+ return fields.size();
+ }
+
+ @Override
+ public RelDataTypeField getField(String fieldName, boolean caseSensitive) {
+ // return the field with given name if available.
+ for (RelDataTypeField f : fields) {
+ if (fieldName.equalsIgnoreCase(f.getName())) {
+ return f;
+ }
+ }
+ return null;
+ }
+
+ @Override
+ public List<String> getFieldNames() {
+ List<String> fieldNames = Lists.newArrayList();
+ for(RelDataTypeField f : fields){
+ fieldNames.add(f.getName());
+ }
+
+ return fieldNames;
+ }
+
+ @Override
+ public SqlTypeName getSqlTypeName() {
+ return SqlTypeName.ANY;
+ }
+
+ @Override
+ public RelDataTypePrecedenceList getPrecedenceList() {
+ return new SqlTypeExplicitPrecedenceList((List<SqlTypeName>) (List) Collections.emptyList());
+ }
+
+ @Override
+ protected void generateTypeString(StringBuilder sb, boolean withDetail) {
+ sb.append("(DrillFixedRecordRow" + getFieldNames() + ")");
+ }
+
+ @Override
+ public boolean isStruct() {
+ return true;
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/UserSession.java
----------------------------------------------------------------------
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 86c4bad..1607179 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
@@ -41,11 +41,14 @@ public class UserSession {
private UserCredentials credentials;
private Map<String, String> properties;
private OptionManager options;
+ private ViewStore viewStore;
public UserSession(OptionManager systemOptions, UserCredentials credentials, UserProperties properties) throws IOException{
this.credentials = credentials;
this.options = new SessionOptionManager(systemOptions);
this.properties = Maps.newHashMap();
+ this.viewStore = new ViewStore();
+
if (properties == null) return;
for (int i=0; i<properties.getPropertiesCount(); i++) {
Property prop = properties.getProperties(i);
@@ -61,6 +64,8 @@ public class UserSession {
return user;
}
+ public ViewStore getViewStore() { return viewStore; }
+
/**
* Update the schema path for the session.
* @param fullPath The desired path to set to.
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/ViewStore.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/ViewStore.java b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/ViewStore.java
new file mode 100644
index 0000000..f5de489
--- /dev/null
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/rpc/user/ViewStore.java
@@ -0,0 +1,93 @@
+/**
+ * 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
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.drill.exec.rpc.user;
+
+import com.google.common.collect.*;
+import net.hydromatic.optiq.impl.ViewTable;
+
+import java.util.Collections;
+import java.util.Map;
+
+/**
+ * ViewStore for holding and managing the views created in a user session.
+ *
+ * Note: Currently these views are for session only and doesn't persist across session.
+ */
+public class ViewStore {
+ // Map of views associated in a schema
+ private Map<String, Map<String, ViewTable>> viewMap = Maps.newHashMap();
+
+ /**
+ * Get all views belonging to the given schema.
+ * @param schemaPath
+ * @return Map of (viewName, ViewTable) entries.
+ */
+ public Map<String, ViewTable> getViews(String schemaPath) {
+ if (viewMap.containsKey(schemaPath))
+ return viewMap.get(schemaPath);
+
+ return Collections.emptyMap();
+ }
+
+ /**
+ * Add the given view to store.
+ *
+ * @param schemaPath
+ * @param viewName Name of the view.
+ * @param view {@link ViewTable} object.
+ * @param replace If a view with given name already exists, replace it.
+ * @return True if a view is replaced.
+ */
+ public boolean addView(String schemaPath, String viewName, ViewTable view, boolean replace) throws ViewAlreadyExistsException {
+ if (!viewMap.containsKey(schemaPath)) {
+ Map<String, ViewTable> viewNameMap = Maps.newHashMap();
+ viewMap.put(schemaPath, viewNameMap);
+ }
+
+ boolean replaced = false;
+ if (viewMap.get(schemaPath).get(viewName) != null) {
+ if (replace)
+ replaced = true;
+ else
+ throw new ViewAlreadyExistsException(schemaPath, viewName);
+ }
+ viewMap.get(schemaPath).put(viewName, view);
+
+ return replaced;
+ }
+
+ /** Delete the ViewTable with given parameters from store. */
+ public void dropView(String schemaPath, String viewName) throws NoSuchViewExistsException {
+ if (viewMap.containsKey(schemaPath) && viewMap.get(schemaPath).containsKey(viewName))
+ viewMap.get(schemaPath).remove(viewName);
+ else
+ throw new NoSuchViewExistsException(schemaPath, viewName);
+ }
+
+ public static class ViewAlreadyExistsException extends Exception {
+ public ViewAlreadyExistsException(String schemaPath, String viewName){
+ super(String.format("Schema '%s' already contains a view view name '%s'.", schemaPath, viewName));
+ }
+ }
+
+ public static class NoSuchViewExistsException extends Exception {
+ public NoSuchViewExistsException(String schemaPath, String viewName){
+ super(String.format("Schema '%s' has no view named '%s'", schemaPath, viewName));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java
index 64087f5..5806ca7 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/AbstractSchema.java
@@ -19,24 +19,31 @@ package org.apache.drill.exec.store;
import java.util.Collection;
import java.util.Collections;
+import java.util.List;
import java.util.Set;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Lists;
import net.hydromatic.linq4j.expressions.DefaultExpression;
import net.hydromatic.linq4j.expressions.Expression;
import net.hydromatic.optiq.Function;
import net.hydromatic.optiq.Schema;
import net.hydromatic.optiq.SchemaPlus;
+import net.hydromatic.optiq.Table;
import org.apache.drill.exec.planner.logical.DrillTable;
public abstract class AbstractSchema implements Schema{
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(AbstractSchema.class);
+ protected final List<String> schemaPath;
protected final String name;
private static final Expression EXPRESSION = new DefaultExpression(Object.class);
- public AbstractSchema(String name) {
- super();
+ public AbstractSchema(List<String> parentSchemaPath, String name) {
+ schemaPath = Lists.newArrayList();
+ schemaPath.addAll(parentSchemaPath);
+ schemaPath.add(name);
this.name = name;
}
@@ -44,6 +51,10 @@ public abstract class AbstractSchema implements Schema{
return name;
}
+ public List<String> getSchemaPath() {
+ return schemaPath;
+ }
+
@Override
public Collection<Function> getFunctions(String name) {
return Collections.emptyList();
@@ -70,7 +81,7 @@ public abstract class AbstractSchema implements Schema{
}
@Override
- public DrillTable getTable(String name){
+ public Table getTable(String name){
return null;
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/store/SchemaFactory.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/SchemaFactory.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/SchemaFactory.java
index 60ccbe8..5acbe78 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/SchemaFactory.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/SchemaFactory.java
@@ -20,9 +20,10 @@ package org.apache.drill.exec.store;
import net.hydromatic.optiq.SchemaPlus;
import org.apache.drill.exec.rpc.user.DrillUser;
+import org.apache.drill.exec.rpc.user.UserSession;
public interface SchemaFactory {
static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(SchemaFactory.class);
- public void registerSchemas(DrillUser user, SchemaPlus parent);
+ public void registerSchemas(UserSession session, SchemaPlus parent);
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java
index 948c74f..ad9a7db 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/StoragePluginRegistry.java
@@ -44,6 +44,7 @@ import org.apache.drill.exec.exception.DrillbitStartupException;
import org.apache.drill.exec.planner.logical.DrillRuleSets;
import org.apache.drill.exec.planner.logical.StoragePlugins;
import org.apache.drill.exec.rpc.user.DrillUser;
+import org.apache.drill.exec.rpc.user.UserSession;
import org.apache.drill.exec.server.DrillbitContext;
import org.apache.drill.exec.store.dfs.FileSystemPlugin;
import org.apache.drill.exec.store.dfs.FormatPlugin;
@@ -223,9 +224,9 @@ public class StoragePluginRegistry implements Iterable<Map.Entry<String, Storage
public class DrillSchemaFactory implements SchemaFactory{
@Override
- public void registerSchemas(DrillUser user, SchemaPlus parent) {
+ public void registerSchemas(UserSession session, SchemaPlus parent) {
for(Map.Entry<String, StoragePlugin> e : plugins.entrySet()){
- e.getValue().registerSchemas(user, parent);
+ e.getValue().registerSchemas(session, parent);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemPlugin.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemPlugin.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemPlugin.java
index dd0cef4..6ade4ee 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemPlugin.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemPlugin.java
@@ -83,16 +83,16 @@ public class FileSystemPlugin extends AbstractStoragePlugin{
List<WorkspaceSchemaFactory> factories = null;
if(config.workspaces == null || config.workspaces.isEmpty()){
- factories = Collections.singletonList(new WorkspaceSchemaFactory(this, "default", name, fs, "/", matchers));
+ factories = Collections.singletonList(new WorkspaceSchemaFactory(this, "default", name, fs, "/", matchers, true/*TODO*/));
}else{
factories = Lists.newArrayList();
for(Map.Entry<String, String> space : config.workspaces.entrySet()){
- factories.add(new WorkspaceSchemaFactory(this, space.getKey(), name, fs, space.getValue(), matchers));
+ factories.add(new WorkspaceSchemaFactory(this, space.getKey(), name, fs, space.getValue(), matchers, true/*TODO*/));
}
// if the "default" workspace is not given add one.
if (!config.workspaces.containsKey("default")) {
- factories.add(new WorkspaceSchemaFactory(this, "default", name, fs, "/", matchers));
+ factories.add(new WorkspaceSchemaFactory(this, "default", name, fs, "/", matchers, true/*TODO*/));
}
}
this.schemaFactory = new FileSystemSchemaFactory(name, factories);
@@ -130,8 +130,8 @@ public class FileSystemPlugin extends AbstractStoragePlugin{
}
@Override
- public void registerSchemas(DrillUser user, SchemaPlus parent) {
- schemaFactory.registerSchemas(user, parent);
+ public void registerSchemas(UserSession session, SchemaPlus parent) {
+ schemaFactory.registerSchemas(session, parent);
}
public FormatPlugin getFormatPlugin(String name){
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
index 93bac0c..92a1efc 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/FileSystemSchemaFactory.java
@@ -22,12 +22,15 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import com.google.common.collect.ImmutableList;
import net.hydromatic.optiq.Function;
import net.hydromatic.optiq.Schema;
import net.hydromatic.optiq.SchemaPlus;
+import net.hydromatic.optiq.Table;
import org.apache.drill.exec.planner.logical.DrillTable;
import org.apache.drill.exec.rpc.user.DrillUser;
+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.WorkspaceSchema;
@@ -52,8 +55,8 @@ public class FileSystemSchemaFactory implements SchemaFactory{
}
@Override
- public void registerSchemas(DrillUser user, SchemaPlus parent) {
- FileSystemSchema schema = new FileSystemSchema(schemaName);
+ public void registerSchemas(UserSession session, SchemaPlus parent) {
+ FileSystemSchema schema = new FileSystemSchema(schemaName, session);
SchemaPlus plusOfThis = parent.add(schema.getName(), schema);
schema.setPlus(plusOfThis);
}
@@ -63,10 +66,10 @@ public class FileSystemSchemaFactory implements SchemaFactory{
private final WorkspaceSchema defaultSchema;
private final Map<String, WorkspaceSchema> schemaMap = Maps.newHashMap();
- public FileSystemSchema(String name) {
- super(name);
+ public FileSystemSchema(String name, UserSession session) {
+ super(ImmutableList.<String>of(), name);
for(WorkspaceSchemaFactory f : factories){
- WorkspaceSchema s = f.createSchema();
+ WorkspaceSchema s = f.createSchema(getSchemaPath(), session);
schemaMap.put(s.getName(), s);
}
@@ -80,7 +83,7 @@ public class FileSystemSchemaFactory implements SchemaFactory{
}
@Override
- public DrillTable getTable(String name) {
+ public Table getTable(String name) {
return defaultSchema.getTable(name);
}
@@ -109,6 +112,10 @@ public class FileSystemSchemaFactory implements SchemaFactory{
return defaultSchema.getTableNames();
}
+ @Override
+ public boolean isMutable() {
+ return defaultSchema.isMutable();
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java
index 1551e5a..cbaf651 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/dfs/WorkspaceSchemaFactory.java
@@ -21,10 +21,14 @@ import java.io.IOException;
import java.util.List;
import java.util.Set;
+import com.google.common.base.Joiner;
+import com.google.common.collect.Sets;
+import net.hydromatic.optiq.Table;
import org.apache.drill.common.exceptions.ExecutionSetupException;
import org.apache.drill.exec.planner.logical.DrillTable;
import org.apache.drill.exec.planner.logical.DynamicDrillTable;
import org.apache.drill.exec.planner.sql.ExpandingConcurrentMap;
+import org.apache.drill.exec.rpc.user.UserSession;
import org.apache.drill.exec.store.AbstractSchema;
import org.apache.drill.exec.store.dfs.shim.DrillFileSystem;
import org.apache.hadoop.fs.Path;
@@ -42,9 +46,10 @@ public class WorkspaceSchemaFactory implements ExpandingConcurrentMap.MapValueFa
private final String storageEngineName;
private final String schemaName;
private final FileSystemPlugin plugin;
+ private final boolean isMutable;
public WorkspaceSchemaFactory(FileSystemPlugin plugin, String schemaName, String storageEngineName, DrillFileSystem fileSystem, String path,
- List<FormatMatcher> formatMatchers) throws ExecutionSetupException {
+ List<FormatMatcher> formatMatchers, boolean isMutable) throws ExecutionSetupException {
this.fs = fileSystem;
this.plugin = plugin;
this.root = new Path(path);
@@ -58,10 +63,11 @@ public class WorkspaceSchemaFactory implements ExpandingConcurrentMap.MapValueFa
}
this.storageEngineName = storageEngineName;
this.schemaName = schemaName;
+ this.isMutable = isMutable;
}
- public WorkspaceSchema createSchema() {
- return new WorkspaceSchema(schemaName);
+ public WorkspaceSchema createSchema(List<String> parentSchemaPath, UserSession session) {
+ return new WorkspaceSchema(parentSchemaPath, schemaName, isMutable, session);
}
@Override
@@ -105,21 +111,32 @@ public class WorkspaceSchemaFactory implements ExpandingConcurrentMap.MapValueFa
public class WorkspaceSchema extends AbstractSchema {
private ExpandingConcurrentMap<String, DrillTable> tables = new ExpandingConcurrentMap<String, DrillTable>(WorkspaceSchemaFactory.this);
-
- public WorkspaceSchema(String name) {
- super(name);
+ private boolean isMutable;
+ private UserSession session;
+
+ public WorkspaceSchema(List<String> parentSchemaPath, String name, boolean isMutable, UserSession session) {
+ super(parentSchemaPath, name);
+ this.isMutable = isMutable;
+ this.session = session;
}
@Override
public Set<String> getTableNames() {
- return tables.keySet();
+ return Sets.union(tables.keySet(), session.getViewStore().getViews(Joiner.on(".").join(getSchemaPath())).keySet());
}
@Override
- public DrillTable getTable(String name) {
- return tables.get(name);
+ public Table getTable(String name) {
+ if (tables.containsKey(name))
+ return tables.get(name);
+
+ return session.getViewStore().getViews(Joiner.on(".").join(getSchemaPath())).get(name);
}
+ @Override
+ public boolean isMutable() {
+ return isMutable;
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePlugin.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePlugin.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePlugin.java
index 0a70b20..6d5f6d2 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePlugin.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/HiveStoragePlugin.java
@@ -25,8 +25,8 @@ import net.hydromatic.optiq.SchemaPlus;
import org.apache.drill.common.JSONOptions;
import org.apache.drill.common.exceptions.ExecutionSetupException;
-import org.apache.drill.exec.rpc.user.DrillUser;
import org.apache.drill.common.expression.SchemaPath;
+import org.apache.drill.exec.rpc.user.UserSession;
import org.apache.drill.exec.server.DrillbitContext;
import org.apache.drill.exec.store.AbstractStoragePlugin;
import org.apache.drill.exec.store.hive.schema.HiveSchemaFactory;
@@ -74,8 +74,8 @@ public class HiveStoragePlugin extends AbstractStoragePlugin {
}
@Override
- public void registerSchemas(DrillUser user, SchemaPlus parent) {
- schemaFactory.registerSchemas(user, parent);
+ public void registerSchemas(UserSession session, SchemaPlus parent) {
+ schemaFactory.registerSchemas(session, parent);
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveDatabaseSchema.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveDatabaseSchema.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveDatabaseSchema.java
index 3608ea7..4390d74 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveDatabaseSchema.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveDatabaseSchema.java
@@ -20,6 +20,7 @@ package org.apache.drill.exec.store.hive.schema;
import java.util.List;
import java.util.Set;
+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.hive.schema.HiveSchemaFactory.HiveSchema;
@@ -36,13 +37,13 @@ public class HiveDatabaseSchema extends AbstractSchema{
List<String> tableList, //
HiveSchema hiveSchema, //
String name) {
- super(name);
+ super(hiveSchema.getSchemaPath(), name);
this.hiveSchema = hiveSchema;
this.tables = Sets.newHashSet(tableList);
}
@Override
- public DrillTable getTable(String tableName) {
+ public Table getTable(String tableName) {
return hiveSchema.getDrillTable(this.name, tableName);
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveSchemaFactory.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveSchemaFactory.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveSchemaFactory.java
index 7b30a41..4b22942 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveSchemaFactory.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/hive/schema/HiveSchemaFactory.java
@@ -23,12 +23,14 @@ import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
+import com.google.common.collect.ImmutableList;
import net.hydromatic.optiq.Schema;
import net.hydromatic.optiq.SchemaPlus;
import org.apache.drill.common.exceptions.ExecutionSetupException;
import org.apache.drill.exec.planner.logical.DrillTable;
import org.apache.drill.exec.rpc.user.DrillUser;
+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.hive.HiveReadEntry;
@@ -171,7 +173,7 @@ public class HiveSchemaFactory implements SchemaFactory {
}
@Override
- public void registerSchemas(DrillUser user, SchemaPlus parent) {
+ public void registerSchemas(UserSession session, SchemaPlus parent) {
HiveSchema schema = new HiveSchema(schemaName);
SchemaPlus hPlus = parent.add(schemaName, schema);
schema.setHolder(hPlus);
@@ -182,7 +184,7 @@ public class HiveSchemaFactory implements SchemaFactory {
private HiveDatabaseSchema defaultSchema;
public HiveSchema(String name) {
- super(name);
+ super(ImmutableList.<String>of(), name);
getSubSchema("default");
}
@@ -223,7 +225,7 @@ public class HiveSchemaFactory implements SchemaFactory {
}
@Override
- public DrillTable getTable(String name) {
+ public net.hydromatic.optiq.Table getTable(String name) {
if(defaultSchema == null){
return super.getTable(name);
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaStoragePlugin.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaStoragePlugin.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaStoragePlugin.java
index e7e3f37..ecf5a8b 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaStoragePlugin.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/ischema/InfoSchemaStoragePlugin.java
@@ -22,13 +22,16 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import com.google.common.collect.ImmutableList;
import net.hydromatic.optiq.SchemaPlus;
+import net.hydromatic.optiq.Table;
import org.apache.drill.common.JSONOptions;
import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.logical.StoragePluginConfig;
import org.apache.drill.exec.planner.logical.DrillTable;
import org.apache.drill.exec.rpc.user.DrillUser;
+import org.apache.drill.exec.rpc.user.UserSession;
import org.apache.drill.exec.server.DrillbitContext;
import org.apache.drill.exec.store.AbstractSchema;
import org.apache.drill.exec.store.AbstractStoragePlugin;
@@ -66,7 +69,7 @@ public class InfoSchemaStoragePlugin extends AbstractStoragePlugin{
}
@Override
- public void registerSchemas(DrillUser user, SchemaPlus parent) {
+ public void registerSchemas(UserSession session, SchemaPlus parent) {
ISchema s = new ISchema(parent, this);
parent.add(s.getName(), s);
}
@@ -74,7 +77,7 @@ public class InfoSchemaStoragePlugin extends AbstractStoragePlugin{
private class ISchema extends AbstractSchema{
private Map<String, InfoSchemaDrillTable> tables;
public ISchema(SchemaPlus parent, InfoSchemaStoragePlugin plugin){
- super("INFORMATION_SCHEMA");
+ super(ImmutableList.<String>of(), "INFORMATION_SCHEMA");
Map<String, InfoSchemaDrillTable> tbls = Maps.newHashMap();
for(SelectedTable tbl : SelectedTable.values()){
tbls.put(tbl.name(), new InfoSchemaDrillTable(plugin, "INFORMATION_SCHEMA", tbl, config));
@@ -83,7 +86,7 @@ public class InfoSchemaStoragePlugin extends AbstractStoragePlugin{
}
@Override
- public DrillTable getTable(String name) {
+ public Table getTable(String name) {
return tables.get(name);
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/store/mock/MockStorageEngine.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/mock/MockStorageEngine.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/mock/MockStorageEngine.java
index 4fe1d1b..1adbacc 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/mock/MockStorageEngine.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/mock/MockStorageEngine.java
@@ -28,6 +28,7 @@ import org.apache.drill.common.expression.SchemaPath;
import org.apache.drill.common.logical.StoragePluginConfig;
import org.apache.drill.exec.physical.base.AbstractGroupScan;
import org.apache.drill.exec.rpc.user.DrillUser;
+import org.apache.drill.exec.rpc.user.UserSession;
import org.apache.drill.exec.server.DrillbitContext;
import org.apache.drill.exec.store.AbstractStoragePlugin;
import org.apache.drill.exec.store.mock.MockGroupScanPOP.MockScanEntry;
@@ -55,7 +56,7 @@ public class MockStorageEngine extends AbstractStoragePlugin {
}
@Override
- public void registerSchemas(DrillUser user, SchemaPlus parent) {
+ public void registerSchemas(UserSession session, SchemaPlus parent) {
}
@Override
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePlugin.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePlugin.java b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePlugin.java
index 7fb8b6c..fd3a898 100644
--- a/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePlugin.java
+++ b/exec/java-exec/src/main/java/org/apache/drill/exec/store/sys/SystemTablePlugin.java
@@ -22,6 +22,7 @@ import java.util.Iterator;
import java.util.List;
import java.util.Set;
+import com.google.common.collect.ImmutableList;
import net.hydromatic.optiq.SchemaPlus;
import org.apache.drill.common.JSONOptions;
@@ -30,7 +31,7 @@ import org.apache.drill.common.logical.StoragePluginConfig;
import org.apache.drill.exec.ops.FragmentContext;
import org.apache.drill.exec.physical.base.AbstractGroupScan;
import org.apache.drill.exec.planner.logical.DrillTable;
-import org.apache.drill.exec.rpc.user.DrillUser;
+import org.apache.drill.exec.rpc.user.UserSession;
import org.apache.drill.exec.server.DrillbitContext;
import org.apache.drill.exec.server.options.DrillConfigIterator;
import org.apache.drill.exec.server.options.OptionValue;
@@ -60,7 +61,7 @@ public class SystemTablePlugin extends AbstractStoragePlugin{
}
@Override
- public void registerSchemas(DrillUser user, SchemaPlus parent) {
+ public void registerSchemas(UserSession session, SchemaPlus parent) {
parent.add(schema.getName(), schema);
}
@@ -89,7 +90,7 @@ public class SystemTablePlugin extends AbstractStoragePlugin{
private Set<String> tableNames;
public SystemSchema() {
- super("sys");
+ super(ImmutableList.<String>of(), "sys");
Set<String> names = Sets.newHashSet();
for(SystemTable t : SystemTable.values()){
names.add(t.getTableName());
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java b/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java
index 6770ee7..e030da5 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/PlanningBase.java
@@ -94,7 +94,7 @@ public class PlanningBase extends ExecTest{
registry.init();
final FunctionImplementationRegistry functionRegistry = new FunctionImplementationRegistry(config);
final SchemaPlus root = Frameworks.createRootSchema();
- registry.getSchemaFactory().registerSchemas(null, root);
+ registry.getSchemaFactory().registerSchemas(new UserSession(null, null, null), root);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/test/java/org/apache/drill/TestTpchSingleMode.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/TestTpchSingleMode.java b/exec/java-exec/src/test/java/org/apache/drill/TestTpchSingleMode.java
index a459bef..63a5727 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/TestTpchSingleMode.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/TestTpchSingleMode.java
@@ -111,7 +111,7 @@ public class TestTpchSingleMode extends BaseTestQuery{
}
@Test
- @Ignore // requires views.
+ @Ignore // Fails with CannotPlanException
public void tpch15() throws Exception{
testSingleMode("queries/tpch/15.sql");
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestOrphanSchema.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestOrphanSchema.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestOrphanSchema.java
index d7e74cb..864793a 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestOrphanSchema.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/TestOrphanSchema.java
@@ -25,6 +25,7 @@ import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.exec.ExecTest;
import org.apache.drill.exec.cache.LocalCache;
import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.rpc.user.UserSession;
import org.apache.drill.exec.server.DrillbitContext;
import org.junit.Test;
@@ -56,7 +57,7 @@ public class TestOrphanSchema extends ExecTest {
StoragePluginRegistry r = new StoragePluginRegistry(bitContext);
SchemaPlus plus = Frameworks.createRootSchema();
r.init();
- r.getSchemaFactory().registerSchemas(null, plus);
+ r.getSchemaFactory().registerSchemas(new UserSession(null, null, null), plus);
printSchema(plus, 0);
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/OrphanSchema.java
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/OrphanSchema.java b/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/OrphanSchema.java
index 1f1b367..b4ed88a 100644
--- a/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/OrphanSchema.java
+++ b/exec/java-exec/src/test/java/org/apache/drill/exec/store/ischema/OrphanSchema.java
@@ -25,6 +25,7 @@ import net.hydromatic.optiq.tools.Frameworks;
import org.apache.drill.common.config.DrillConfig;
import org.apache.drill.exec.cache.LocalCache;
import org.apache.drill.exec.memory.TopLevelAllocator;
+import org.apache.drill.exec.rpc.user.UserSession;
import org.apache.drill.exec.server.DrillbitContext;
import org.apache.drill.exec.store.StoragePluginRegistry;
import org.junit.Test;
@@ -55,7 +56,7 @@ public class OrphanSchema {
StoragePluginRegistry r = new StoragePluginRegistry(bitContext);
r.init();
SchemaPlus plus = Frameworks.createRootSchema();
- r.getSchemaFactory().registerSchemas(null, plus);
+ r.getSchemaFactory().registerSchemas(new UserSession(null, null, null), plus);
return plus;
}
http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/b7bf00cb/exec/java-exec/src/test/resources/queries/tpch/15.sql
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/test/resources/queries/tpch/15.sql b/exec/java-exec/src/test/resources/queries/tpch/15.sql
index 251631d..0ffa896 100644
--- a/exec/java-exec/src/test/resources/queries/tpch/15.sql
+++ b/exec/java-exec/src/test/resources/queries/tpch/15.sql
@@ -1,4 +1,6 @@
-- tpch15 using 1395599672 as a seed to the RNG
+use dfs.`default`; -- views can only be created in dfs schema
+
create view revenue0 (supplier_no, total_revenue) as
select
l_suppkey,