Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HIVE-10843 #40

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions contrib/src/test/results/clientpositive/url_hook.q.out
@@ -1,11 +1,15 @@
PREHOOK: query: SHOW TABLES 'src'
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:default
POSTHOOK: query: SHOW TABLES 'src'
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:default
src
PREHOOK: query: -- changes to dummy derby store.. should return empty result
SHOW TABLES 'src'
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:default
POSTHOOK: query: -- changes to dummy derby store.. should return empty result
SHOW TABLES 'src'
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:default
Expand Up @@ -54,7 +54,7 @@ public static void setUpBeforeClass() throws Exception {
confOverlay.put(ConfVars.PREEXECHOOKS.varname, PreExecHook.class.getName());
confOverlay.put(ConfVars.SEMANTIC_ANALYZER_HOOK.varname,
SemanticAnalysisHook.class.getName());

confOverlay.put(ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "" + Boolean.FALSE);
HiveConf hiveConf = new HiveConf();
miniHiveKdc = MiniHiveKdc.getMiniHiveKdc(hiveConf);
miniHS2 = MiniHiveKdc.getMiniHS2WithKerb(miniHiveKdc, hiveConf);
Expand Down
Expand Up @@ -28,6 +28,7 @@
import junit.framework.Assert;

import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.conf.HiveConf.ConfVars;
import org.apache.hadoop.hive.ql.hooks.ExecuteWithHookContext;
import org.apache.hadoop.hive.ql.hooks.HookContext;
import org.apache.hadoop.hive.ql.hooks.HookContext.HookType;
Expand Down Expand Up @@ -58,6 +59,7 @@ public static class PostExecHook implements ExecuteWithHookContext {
public static String operation;
public static Throwable error;

@Override
public void run(HookContext hookContext) {
try {
if (hookContext.getHookType().equals(HookType.POST_EXEC_HOOK)) {
Expand All @@ -78,6 +80,7 @@ public static class PreExecHook implements ExecuteWithHookContext {
public static String operation;
public static Throwable error;

@Override
public void run(HookContext hookContext) {
try {
if (hookContext.getHookType().equals(HookType.PRE_EXEC_HOOK)) {
Expand Down Expand Up @@ -133,12 +136,13 @@ public void postAnalyze(HiveSemanticAnalyzerHookContext context,
@BeforeClass
public static void setUpBeforeClass() throws Exception {
HiveConf hiveConf = new HiveConf();
hiveConf.setVar(HiveConf.ConfVars.PREEXECHOOKS,
hiveConf.setVar(ConfVars.PREEXECHOOKS,
PreExecHook.class.getName());
hiveConf.setVar(HiveConf.ConfVars.POSTEXECHOOKS,
hiveConf.setVar(ConfVars.POSTEXECHOOKS,
PostExecHook.class.getName());
hiveConf.setVar(HiveConf.ConfVars.SEMANTIC_ANALYZER_HOOK,
hiveConf.setVar(ConfVars.SEMANTIC_ANALYZER_HOOK,
SemanticAnalysisHook.class.getName());
hiveConf.setBoolVar(ConfVars.HIVE_SUPPORT_CONCURRENCY, false);

hiveServer2 = new HiveServer2();
hiveServer2.init(hiveConf);
Expand Down
Expand Up @@ -60,6 +60,7 @@ public class TestHiveAuthorizerCheckInvocation {
protected static Driver driver;
private static final String tableName = TestHiveAuthorizerCheckInvocation.class.getSimpleName()
+ "Table";
private static final String inDbTableName = tableName + "_in_db";
private static final String acidTableName = tableName + "_acid";
private static final String dbName = TestHiveAuthorizerCheckInvocation.class.getSimpleName()
+ "Db";
Expand Down Expand Up @@ -96,6 +97,7 @@ public static void beforeTest() throws Exception {
runCmd("create table " + tableName
+ " (i int, j int, k string) partitioned by (city string, `date` string) ");
runCmd("create database " + dbName);
runCmd("create table " + dbName + "." + inDbTableName + "(i int)");
// Need a separate table for ACID testing since it has to be bucketed and it has to be Acid
runCmd("create table " + acidTableName + " (i int, j int, k int) clustered by (k) into 2 buckets " +
"stored as orc TBLPROPERTIES ('transactional'='true')");
Expand All @@ -111,7 +113,8 @@ public static void afterTests() throws Exception {
// Drop the tables when we're done. This makes the test work inside an IDE
runCmd("drop table if exists " + acidTableName);
runCmd("drop table if exists " + tableName);
runCmd("drop database if exists " + dbName);
runCmd("drop table if exists " + dbName + "." + inDbTableName);
runCmd("drop database if exists " + dbName );
driver.close();
}

Expand Down Expand Up @@ -314,6 +317,35 @@ public void testDelete() throws HiveAuthzPluginException,
assertEquals("j", tableObj.getColumns().get(0));
}

@Test
public void testShowTables() throws HiveAuthzPluginException,
HiveAccessControlException, CommandNeedRetryException {
reset(mockedAuthorizer);
int status = driver.compile("show tables");
assertEquals(0, status);

Pair<List<HivePrivilegeObject>, List<HivePrivilegeObject>> io = getHivePrivilegeObjectInputs();
List<HivePrivilegeObject> inputs = io.getLeft();
assertEquals(1, inputs.size());
HivePrivilegeObject dbObj = inputs.get(0);
assertEquals("default", dbObj.getDbname().toLowerCase());
}

@Test
public void testDescDatabase() throws HiveAuthzPluginException,
HiveAccessControlException, CommandNeedRetryException {
reset(mockedAuthorizer);
int status = driver.compile("describe database " + dbName);
assertEquals(0, status);

Pair<List<HivePrivilegeObject>, List<HivePrivilegeObject>> io = getHivePrivilegeObjectInputs();
List<HivePrivilegeObject> inputs = io.getLeft();
assertEquals(1, inputs.size());
HivePrivilegeObject dbObj = inputs.get(0);
assertEquals(dbName.toLowerCase(), dbObj.getDbname().toLowerCase());
}


private void checkSingleTableInput(List<HivePrivilegeObject> inputs) {
assertEquals("number of inputs", 1, inputs.size());

Expand Down
Expand Up @@ -2068,6 +2068,7 @@ private void analyzeDescDatabase(ASTNode ast) throws SemanticException {

DescDatabaseDesc descDbDesc = new DescDatabaseDesc(ctx.getResFile(),
dbName, isExtended);
inputs.add(new ReadEntity(getDatabase(dbName)));
rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(), descDbDesc), conf));
setFetchTask(createFetchTask(descDbDesc.getSchema()));
}
Expand Down Expand Up @@ -2178,7 +2179,7 @@ private void analyzeShowTables(ASTNode ast) throws SemanticException {
showTblsDesc = new ShowTablesDesc(ctx.getResFile(), dbName);
break;
}

inputs.add(new ReadEntity(getDatabase(dbName)));
rootTasks.add(TaskFactory.get(new DDLWork(getInputs(), getOutputs(),
showTblsDesc), conf));
setFetchTask(createFetchTask(showTblsDesc.getSchema()));
Expand Down
Expand Up @@ -152,6 +152,11 @@ private void checkPrivileges(HiveOperationType hiveOpType, List<HivePrivilegeObj
@Override
public List<HivePrivilegeObject> filterListCmdObjects(List<HivePrivilegeObject> listObjs,
HiveAuthzContext context) {
if (LOG.isDebugEnabled()) {
String msg = "Obtained following objects in filterListCmdObjects " + listObjs + " for user "
+ authenticator.getUserName() + ". Context Info: " + context;
LOG.debug(msg);
}
return listObjs;
}

Expand Down
2 changes: 2 additions & 0 deletions ql/src/test/results/clientnegative/authorization_ctas2.q.out
Expand Up @@ -22,6 +22,8 @@ POSTHOOK: type: SWITCHDATABASE
POSTHOOK: Input: database:ctas_auth
PREHOOK: query: show tables
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:ctas_auth
POSTHOOK: query: show tables
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:ctas_auth
FAILED: HiveAccessControlException Permission denied: Principal [name=user_unauth, type=USER] does not have following privileges for operation CREATETABLE_AS_SELECT [[OBJECT OWNERSHIP] on Object [type=DATABASE, name=ctas_auth]]
2 changes: 2 additions & 0 deletions ql/src/test/results/clientpositive/add_part_exist.q.out
Expand Up @@ -80,8 +80,10 @@ POSTHOOK: Input: default@add_part_test
POSTHOOK: Output: default@add_part_test
PREHOOK: query: SHOW TABLES
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:default
POSTHOOK: query: SHOW TABLES
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:default
alltypesorc
cbo_t1
cbo_t2
Expand Down
4 changes: 4 additions & 0 deletions ql/src/test/results/clientpositive/alter1.q.out
Expand Up @@ -189,8 +189,10 @@ POSTHOOK: Input: default@alter1
POSTHOOK: Output: default@alter1
PREHOOK: query: SHOW TABLES
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:default
POSTHOOK: query: SHOW TABLES
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:default
alltypesorc
cbo_t1
cbo_t2
Expand Down Expand Up @@ -218,8 +220,10 @@ POSTHOOK: type: CREATEDATABASE
POSTHOOK: Output: database:alter1_db
PREHOOK: query: SHOW TABLES alter1_db
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:default
POSTHOOK: query: SHOW TABLES alter1_db
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:default
PREHOOK: query: CREATE TABLE alter1_db.alter1(a INT, b INT)
PREHOOK: type: CREATETABLE
PREHOOK: Output: alter1_db@alter1
Expand Down
4 changes: 4 additions & 0 deletions ql/src/test/results/clientpositive/alter2.q.out
Expand Up @@ -208,8 +208,10 @@ POSTHOOK: Input: default@alter2
POSTHOOK: Output: default@alter2
PREHOOK: query: SHOW TABLES
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:default
POSTHOOK: query: SHOW TABLES
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:default
alltypesorc
cbo_t1
cbo_t2
Expand Down Expand Up @@ -243,8 +245,10 @@ POSTHOOK: type: SWITCHDATABASE
POSTHOOK: Input: database:alter2_db
PREHOOK: query: SHOW TABLES
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:alter2_db
POSTHOOK: query: SHOW TABLES
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:alter2_db
PREHOOK: query: CREATE TABLE alter2(a int, b int) PARTITIONED BY (insertdate string)
PREHOOK: type: CREATETABLE
PREHOOK: Output: alter2_db@alter2
Expand Down
4 changes: 4 additions & 0 deletions ql/src/test/results/clientpositive/alter3.q.out
Expand Up @@ -181,8 +181,10 @@ POSTHOOK: Input: default@alter3_like_renamed
POSTHOOK: Output: default@alter3_like_renamed
PREHOOK: query: SHOW TABLES
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:default
POSTHOOK: query: SHOW TABLES
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:default
alltypesorc
cbo_t1
cbo_t2
Expand Down Expand Up @@ -216,8 +218,10 @@ POSTHOOK: type: SWITCHDATABASE
POSTHOOK: Input: database:alter3_db
PREHOOK: query: SHOW TABLES
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:alter3_db
POSTHOOK: query: SHOW TABLES
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:alter3_db
PREHOOK: query: CREATE TABLE alter3_src (col1 STRING) STORED AS TEXTFILE
PREHOOK: type: CREATETABLE
PREHOOK: Output: alter3_db@alter3_src
Expand Down
4 changes: 4 additions & 0 deletions ql/src/test/results/clientpositive/alter4.q.out
Expand Up @@ -46,8 +46,10 @@ POSTHOOK: Input: default@set_bucketing_test
POSTHOOK: Output: default@set_bucketing_test
PREHOOK: query: SHOW TABLES
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:default
POSTHOOK: query: SHOW TABLES
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:default
alltypesorc
cbo_t1
cbo_t2
Expand Down Expand Up @@ -81,8 +83,10 @@ POSTHOOK: type: SWITCHDATABASE
POSTHOOK: Input: database:alter4_db
PREHOOK: query: SHOW TABLES
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:alter4_db
POSTHOOK: query: SHOW TABLES
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:alter4_db
PREHOOK: query: CREATE TABLE set_bucketing_test (key INT, value STRING) CLUSTERED BY (key) INTO 10 BUCKETS
PREHOOK: type: CREATETABLE
PREHOOK: Output: alter4_db@set_bucketing_test
Expand Down
4 changes: 4 additions & 0 deletions ql/src/test/results/clientpositive/alter5.q.out
Expand Up @@ -122,8 +122,10 @@ POSTHOOK: Input: default@alter5
POSTHOOK: Output: default@alter5
PREHOOK: query: SHOW TABLES
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:default
POSTHOOK: query: SHOW TABLES
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:default
alltypesorc
cbo_t1
cbo_t2
Expand Down Expand Up @@ -157,8 +159,10 @@ POSTHOOK: type: SWITCHDATABASE
POSTHOOK: Input: database:alter5_db
PREHOOK: query: SHOW TABLES
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:alter5_db
POSTHOOK: query: SHOW TABLES
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:alter5_db
PREHOOK: query: create table alter5_src ( col1 string ) stored as textfile
PREHOOK: type: CREATETABLE
PREHOOK: Output: alter5_db@alter5_src
Expand Down
Expand Up @@ -7,8 +7,10 @@ POSTHOOK: Output: database:newDB
#### A masked pattern was here ####
PREHOOK: query: describe database extended newDB
PREHOOK: type: DESCDATABASE
PREHOOK: Input: database:newdb
POSTHOOK: query: describe database extended newDB
POSTHOOK: type: DESCDATABASE
POSTHOOK: Input: database:newdb
newdb location/in/test hive_test_user USER
PREHOOK: query: use newDB
PREHOOK: type: SWITCHDATABASE
Expand Down
6 changes: 6 additions & 0 deletions ql/src/test/results/clientpositive/alter_db_owner.q.out
Expand Up @@ -6,8 +6,10 @@ POSTHOOK: type: CREATEDATABASE
POSTHOOK: Output: database:db_alter_onr
PREHOOK: query: describe database db_alter_onr
PREHOOK: type: DESCDATABASE
PREHOOK: Input: database:db_alter_onr
POSTHOOK: query: describe database db_alter_onr
POSTHOOK: type: DESCDATABASE
POSTHOOK: Input: database:db_alter_onr
db_alter_onr location/in/test hive_test_user USER
#### A masked pattern was here ####
PREHOOK: type: ALTERDATABASE_OWNER
Expand All @@ -17,8 +19,10 @@ POSTHOOK: type: ALTERDATABASE_OWNER
POSTHOOK: Output: database:db_alter_onr
PREHOOK: query: describe database db_alter_onr
PREHOOK: type: DESCDATABASE
PREHOOK: Input: database:db_alter_onr
POSTHOOK: query: describe database db_alter_onr
POSTHOOK: type: DESCDATABASE
POSTHOOK: Input: database:db_alter_onr
db_alter_onr location/in/test user1 USER
#### A masked pattern was here ####
PREHOOK: type: ALTERDATABASE_OWNER
Expand All @@ -28,6 +32,8 @@ POSTHOOK: type: ALTERDATABASE_OWNER
POSTHOOK: Output: database:db_alter_onr
PREHOOK: query: describe database db_alter_onr
PREHOOK: type: DESCDATABASE
PREHOOK: Input: database:db_alter_onr
POSTHOOK: query: describe database db_alter_onr
POSTHOOK: type: DESCDATABASE
POSTHOOK: Input: database:db_alter_onr
db_alter_onr location/in/test role1 ROLE
2 changes: 2 additions & 0 deletions ql/src/test/results/clientpositive/alter_index.q.out
Expand Up @@ -45,8 +45,10 @@ POSTHOOK: type: DROPINDEX
POSTHOOK: Input: default@src
PREHOOK: query: show tables
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:default
POSTHOOK: query: show tables
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:default
alltypesorc
cbo_t1
cbo_t2
Expand Down
Expand Up @@ -10,8 +10,10 @@ POSTHOOK: query: DROP TABLE alter_rename_partition
POSTHOOK: type: DROPTABLE
PREHOOK: query: SHOW TABLES
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:default
POSTHOOK: query: SHOW TABLES
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:default
alltypesorc
cbo_t1
cbo_t2
Expand Down Expand Up @@ -137,8 +139,10 @@ POSTHOOK: Input: default@alter_rename_partition
POSTHOOK: Output: default@alter_rename_partition
PREHOOK: query: SHOW TABLES
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:default
POSTHOOK: query: SHOW TABLES
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:default
alltypesorc
cbo_t1
cbo_t2
Expand Down Expand Up @@ -172,8 +176,10 @@ POSTHOOK: type: SWITCHDATABASE
POSTHOOK: Input: database:alter_rename_partition_db
PREHOOK: query: SHOW TABLES
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:alter_rename_partition_db
POSTHOOK: query: SHOW TABLES
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:alter_rename_partition_db
PREHOOK: query: CREATE TABLE alter_rename_partition_src (col1 STRING) STORED AS TEXTFILE
PREHOOK: type: CREATETABLE
PREHOOK: Output: alter_rename_partition_db@alter_rename_partition_src
Expand Down
Expand Up @@ -26,8 +26,10 @@ POSTHOOK: type: ALTERDATABASE_OWNER
POSTHOOK: Output: database:testdb
PREHOOK: query: desc database testdb
PREHOOK: type: DESCDATABASE
PREHOOK: Input: database:testdb
POSTHOOK: query: desc database testdb
POSTHOOK: type: DESCDATABASE
POSTHOOK: Input: database:testdb
testdb location/in/test testrole ROLE
#### A masked pattern was here ####
-- create table
Expand Down
2 changes: 2 additions & 0 deletions ql/src/test/results/clientpositive/create_view.q.out
Expand Up @@ -214,8 +214,10 @@ STAGE PLANS:

PREHOOK: query: SHOW TABLES 'view.*'
PREHOOK: type: SHOWTABLES
PREHOOK: Input: database:default
POSTHOOK: query: SHOW TABLES 'view.*'
POSTHOOK: type: SHOWTABLES
POSTHOOK: Input: database:default
view1
view2
view3
Expand Down