[37/50] [abbrv] hive git commit: HIVE-19374: Parse and process ALTER TABLE SET OWNER command syntax (Sergio Pena, reviewed by Vihang Karajgaonkar)

2018-05-15 Thread vgarg
HIVE-19374: Parse and process ALTER TABLE SET OWNER command syntax (Sergio 
Pena, reviewed by Vihang Karajgaonkar)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/14d0690b
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/14d0690b
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/14d0690b

Branch: refs/heads/branch-3
Commit: 14d0690b6af32c1aed8085590f49af941a64bc1c
Parents: ba7155d
Author: Sergio Pena 
Authored: Wed May 9 22:37:09 2018 -0700
Committer: Vineet Garg 
Committed: Mon May 14 11:50:50 2018 -0700

--
 .../ql/metadata/TestAlterTableMetadata.java | 72 
 .../org/apache/hadoop/hive/ql/exec/DDLTask.java |  5 ++
 .../apache/hadoop/hive/ql/metadata/Table.java   | 15 
 .../formatting/JsonMetaDataFormatter.java   |  1 +
 .../formatting/MetaDataFormatUtils.java |  1 +
 .../hive/ql/parse/DDLSemanticAnalyzer.java  | 17 +
 .../apache/hadoop/hive/ql/parse/HiveParser.g|  8 +++
 .../hive/ql/parse/SemanticAnalyzerFactory.java  |  2 +
 .../hadoop/hive/ql/plan/AlterTableDesc.java | 21 +-
 .../hadoop/hive/ql/plan/HiveOperation.java  |  1 +
 .../authorization/plugin/HiveOperationType.java |  1 +
 .../plugin/sqlstd/Operation2Privilege.java  |  2 +
 12 files changed, 145 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/hive/blob/14d0690b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/metadata/TestAlterTableMetadata.java
--
diff --git 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/metadata/TestAlterTableMetadata.java
 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/metadata/TestAlterTableMetadata.java
new file mode 100644
index 000..940a1d3
--- /dev/null
+++ 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/metadata/TestAlterTableMetadata.java
@@ -0,0 +1,72 @@
+/*
+ * 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.hadoop.hive.ql.metadata;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.api.PrincipalType;
+import org.apache.hadoop.hive.ql.DriverFactory;
+import org.apache.hadoop.hive.ql.IDriver;
+import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestAlterTableMetadata {
+  @Test
+  public void testAlterTableOwner() throws HiveException {
+/*
+ * This test verifies that the ALTER TABLE ... SET OWNER command will 
change the
+ * owner metadata of the table in HMS.
+ */
+
+HiveConf conf = new HiveConf(this.getClass());
+conf.set(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "false");
+SessionState.start(conf);
+IDriver driver = DriverFactory.newDriver(conf);
+CommandProcessorResponse resp;
+Table table;
+
+resp = driver.run("create table t1(id int)");
+assertEquals(0, resp.getResponseCode());
+
+// Changes the owner to a user and verify the change
+resp = driver.run("alter table t1 set owner user u1");
+assertEquals(0, resp.getResponseCode());
+
+table = Hive.get(conf).getTable("t1");
+assertEquals(PrincipalType.USER, table.getOwnerType());
+assertEquals("u1", table.getOwner());
+
+// Changes the owner to a group and verify the change
+resp = driver.run("alter table t1 set owner group g1");
+assertEquals(0, resp.getResponseCode());
+
+table = Hive.get(conf).getTable("t1");
+assertEquals(PrincipalType.GROUP, table.getOwnerType());
+assertEquals("g1", table.getOwner());
+
+// Changes the owner to a role and verify the change
+resp = driver.run("alter table t1 set owner role r1");
+assertEquals(0, resp.getResponseCode());
+
+table = Hive.get(conf).getTable("t1");
+assertEquals(PrincipalType.ROLE, table.getOwnerType());
+assertEquals("r1", table.getOwner());
+  }
+}


[37/50] [abbrv] hive git commit: HIVE-19374: Parse and process ALTER TABLE SET OWNER command syntax (Sergio Pena, reviewed by Vihang Karajgaonkar)

2018-05-15 Thread vgarg
HIVE-19374: Parse and process ALTER TABLE SET OWNER command syntax (Sergio 
Pena, reviewed by Vihang Karajgaonkar)


Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/14d0690b
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/14d0690b
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/14d0690b

Branch: refs/heads/branch-3.0.0
Commit: 14d0690b6af32c1aed8085590f49af941a64bc1c
Parents: ba7155d
Author: Sergio Pena 
Authored: Wed May 9 22:37:09 2018 -0700
Committer: Vineet Garg 
Committed: Mon May 14 11:50:50 2018 -0700

--
 .../ql/metadata/TestAlterTableMetadata.java | 72 
 .../org/apache/hadoop/hive/ql/exec/DDLTask.java |  5 ++
 .../apache/hadoop/hive/ql/metadata/Table.java   | 15 
 .../formatting/JsonMetaDataFormatter.java   |  1 +
 .../formatting/MetaDataFormatUtils.java |  1 +
 .../hive/ql/parse/DDLSemanticAnalyzer.java  | 17 +
 .../apache/hadoop/hive/ql/parse/HiveParser.g|  8 +++
 .../hive/ql/parse/SemanticAnalyzerFactory.java  |  2 +
 .../hadoop/hive/ql/plan/AlterTableDesc.java | 21 +-
 .../hadoop/hive/ql/plan/HiveOperation.java  |  1 +
 .../authorization/plugin/HiveOperationType.java |  1 +
 .../plugin/sqlstd/Operation2Privilege.java  |  2 +
 12 files changed, 145 insertions(+), 1 deletion(-)
--


http://git-wip-us.apache.org/repos/asf/hive/blob/14d0690b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/metadata/TestAlterTableMetadata.java
--
diff --git 
a/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/metadata/TestAlterTableMetadata.java
 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/metadata/TestAlterTableMetadata.java
new file mode 100644
index 000..940a1d3
--- /dev/null
+++ 
b/itests/hive-unit/src/test/java/org/apache/hadoop/hive/ql/metadata/TestAlterTableMetadata.java
@@ -0,0 +1,72 @@
+/*
+ * 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.hadoop.hive.ql.metadata;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.api.PrincipalType;
+import org.apache.hadoop.hive.ql.DriverFactory;
+import org.apache.hadoop.hive.ql.IDriver;
+import org.apache.hadoop.hive.ql.processors.CommandProcessorResponse;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class TestAlterTableMetadata {
+  @Test
+  public void testAlterTableOwner() throws HiveException {
+/*
+ * This test verifies that the ALTER TABLE ... SET OWNER command will 
change the
+ * owner metadata of the table in HMS.
+ */
+
+HiveConf conf = new HiveConf(this.getClass());
+conf.set(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY.varname, "false");
+SessionState.start(conf);
+IDriver driver = DriverFactory.newDriver(conf);
+CommandProcessorResponse resp;
+Table table;
+
+resp = driver.run("create table t1(id int)");
+assertEquals(0, resp.getResponseCode());
+
+// Changes the owner to a user and verify the change
+resp = driver.run("alter table t1 set owner user u1");
+assertEquals(0, resp.getResponseCode());
+
+table = Hive.get(conf).getTable("t1");
+assertEquals(PrincipalType.USER, table.getOwnerType());
+assertEquals("u1", table.getOwner());
+
+// Changes the owner to a group and verify the change
+resp = driver.run("alter table t1 set owner group g1");
+assertEquals(0, resp.getResponseCode());
+
+table = Hive.get(conf).getTable("t1");
+assertEquals(PrincipalType.GROUP, table.getOwnerType());
+assertEquals("g1", table.getOwner());
+
+// Changes the owner to a role and verify the change
+resp = driver.run("alter table t1 set owner role r1");
+assertEquals(0, resp.getResponseCode());
+
+table = Hive.get(conf).getTable("t1");
+assertEquals(PrincipalType.ROLE, table.getOwnerType());
+assertEquals("r1", table.getOwner());
+  }