You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2018/03/20 20:44:15 UTC
[17/21] impala git commit: IMPALA-6655: Add owner information on
database creation
IMPALA-6655: Add owner information on database creation
Add owner information on database creation.
> create database foo;
> describe database extended foo;
+---------+----------+---------+
| name | location | comment |
+---------+----------+---------+
| foo | | |
| Owner: | | |
| | user1 | USER |
+---------+----------+---------+
Testing:
- Ran end-to-end query and metadata tests
Change-Id: Id74ec9bd3cb7954999305e9cd9085cbf50921a78
Reviewed-on: http://gerrit.cloudera.org:8080/9637
Reviewed-by: Fredy Wijaya <fw...@cloudera.com>
Reviewed-by: Alex Behm <al...@cloudera.com>
Tested-by: Impala Public Jenkins
Project: http://git-wip-us.apache.org/repos/asf/impala/repo
Commit: http://git-wip-us.apache.org/repos/asf/impala/commit/614d0ff5
Tree: http://git-wip-us.apache.org/repos/asf/impala/tree/614d0ff5
Diff: http://git-wip-us.apache.org/repos/asf/impala/diff/614d0ff5
Branch: refs/heads/2.x
Commit: 614d0ff566df3623d978610d3ddb281242ff7a8c
Parents: cea50c6
Author: Fredy Wijaya <fw...@cloudera.com>
Authored: Tue Mar 13 16:31:23 2018 -0500
Committer: Impala Public Jenkins <im...@gerrit.cloudera.org>
Committed: Sun Mar 18 21:03:22 2018 +0000
----------------------------------------------------------------------
common/thrift/JniCatalog.thrift | 3 +++
.../java/org/apache/impala/analysis/CreateDbStmt.java | 11 +++++++++++
.../org/apache/impala/service/CatalogOpExecutor.java | 3 +++
.../functional-query/queries/QueryTest/describe-db.test | 10 ++++++++++
tests/common/impala_test_suite.py | 3 ++-
5 files changed, 29 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/impala/blob/614d0ff5/common/thrift/JniCatalog.thrift
----------------------------------------------------------------------
diff --git a/common/thrift/JniCatalog.thrift b/common/thrift/JniCatalog.thrift
index 4edf4d2..371475b 100644
--- a/common/thrift/JniCatalog.thrift
+++ b/common/thrift/JniCatalog.thrift
@@ -88,6 +88,9 @@ struct TCreateDbParams {
// Do not throw an error if a database of the same name already exists.
4: optional bool if_not_exists
+
+ // Owner of the database
+ 5: required string owner
}
// Parameters of CREATE DATA SOURCE commands
http://git-wip-us.apache.org/repos/asf/impala/blob/614d0ff5/fe/src/main/java/org/apache/impala/analysis/CreateDbStmt.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/analysis/CreateDbStmt.java b/fe/src/main/java/org/apache/impala/analysis/CreateDbStmt.java
index c803910..f71f269 100644
--- a/fe/src/main/java/org/apache/impala/analysis/CreateDbStmt.java
+++ b/fe/src/main/java/org/apache/impala/analysis/CreateDbStmt.java
@@ -17,6 +17,7 @@
package org.apache.impala.analysis;
+import com.google.common.base.Preconditions;
import org.apache.hadoop.fs.permission.FsAction;
import org.apache.impala.authorization.Privilege;
import org.apache.impala.catalog.Db;
@@ -32,6 +33,8 @@ public class CreateDbStmt extends StatementBase {
private final HdfsUri location_;
private final String comment_;
private final boolean ifNotExists_;
+ // Database owner. Set during analysis.
+ private String owner_;
/**
* Creates a database with the given name.
@@ -74,6 +77,7 @@ public class CreateDbStmt extends StatementBase {
params.setComment(getComment());
params.setLocation(location_ == null ? null : location_.toString());
params.setIf_not_exists(getIfNotExists());
+ params.setOwner(getOwner());
return params;
}
@@ -96,5 +100,12 @@ public class CreateDbStmt extends StatementBase {
if (location_ != null) {
location_.analyze(analyzer, Privilege.ALL, FsAction.READ_WRITE);
}
+ owner_ = analyzer.getUser().getName();
}
+
+ /**
+ * Can only be called after analysis, returns the owner of this database (the user from
+ * the current session).
+ */
+ public String getOwner() { return Preconditions.checkNotNull(owner_); }
}
http://git-wip-us.apache.org/repos/asf/impala/blob/614d0ff5/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
----------------------------------------------------------------------
diff --git a/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java b/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
index c3b15a1..9ccfa50 100644
--- a/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
+++ b/fe/src/main/java/org/apache/impala/service/CatalogOpExecutor.java
@@ -46,6 +46,7 @@ import org.apache.hadoop.hive.metastore.api.LongColumnStatsData;
import org.apache.hadoop.hive.metastore.api.MetaException;
import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.PrincipalType;
import org.apache.hadoop.hive.metastore.api.SerDeInfo;
import org.apache.hadoop.hive.metastore.api.StorageDescriptor;
import org.apache.hadoop.hive.metastore.api.StringColumnStatsData;
@@ -956,6 +957,8 @@ public class CatalogOpExecutor {
if (params.getLocation() != null) {
db.setLocationUri(params.getLocation());
}
+ db.setOwnerName(params.getOwner());
+ db.setOwnerType(PrincipalType.USER);
if (LOG.isTraceEnabled()) LOG.trace("Creating database " + dbName);
Db newDb = null;
synchronized (metastoreDdlLock_) {
http://git-wip-us.apache.org/repos/asf/impala/blob/614d0ff5/testdata/workloads/functional-query/queries/QueryTest/describe-db.test
----------------------------------------------------------------------
diff --git a/testdata/workloads/functional-query/queries/QueryTest/describe-db.test b/testdata/workloads/functional-query/queries/QueryTest/describe-db.test
index 8f55325..027e19a 100644
--- a/testdata/workloads/functional-query/queries/QueryTest/describe-db.test
+++ b/testdata/workloads/functional-query/queries/QueryTest/describe-db.test
@@ -31,6 +31,8 @@ string, string, string
---- QUERY
describe database extended impala_test_desc_db1
---- RESULTS
+'','$USER','USER'
+'Owner: ','',''
'impala_test_desc_db1','$NAMENODE/test-warehouse/impala_test_desc_db1.db',''
---- TYPES
string, string, string
@@ -38,6 +40,8 @@ string, string, string
---- QUERY
describe database extended impala_test_desc_db2
---- RESULTS
+'','$USER','USER'
+'Owner: ','',''
'impala_test_desc_db2','$NAMENODE/test-warehouse/impala_test_desc_db2.db','test comment'
---- TYPES
string, string, string
@@ -45,6 +49,8 @@ string, string, string
---- QUERY
describe database extended impala_test_desc_db3
---- RESULTS
+'','$USER','USER'
+'Owner: ','',''
'impala_test_desc_db3','$NAMENODE/testdb',''
---- TYPES
string, string, string
@@ -52,6 +58,8 @@ string, string, string
---- QUERY
describe database extended impala_test_desc_db4
---- RESULTS
+'','$USER','USER'
+'Owner: ','',''
'impala_test_desc_db4','$NAMENODE/test2.db','test comment'
---- TYPES
string, string, string
@@ -59,6 +67,8 @@ string, string, string
---- QUERY
describe database formatted impala_test_desc_db4
---- RESULTS
+'','$USER','USER'
+'Owner: ','',''
'impala_test_desc_db4','$NAMENODE/test2.db','test comment'
---- TYPES
string, string, string
http://git-wip-us.apache.org/repos/asf/impala/blob/614d0ff5/tests/common/impala_test_suite.py
----------------------------------------------------------------------
diff --git a/tests/common/impala_test_suite.py b/tests/common/impala_test_suite.py
index bdd524f..28d9c2e 100644
--- a/tests/common/impala_test_suite.py
+++ b/tests/common/impala_test_suite.py
@@ -291,7 +291,8 @@ class ImpalaTestSuite(BaseTestSuite):
replace_filenames_with_placeholder = False
test_section[section_name] = test_section[section_name] \
.replace('$NAMENODE', NAMENODE) \
- .replace('$IMPALA_HOME', IMPALA_HOME)
+ .replace('$IMPALA_HOME', IMPALA_HOME) \
+ .replace('$USER', getuser())
if use_db:
test_section[section_name] = test_section[section_name].replace('$DATABASE', use_db)
verify_raw_results(test_section, result, vector.get_value('table_format').file_format,