This is an automated email from the ASF dual-hosted git repository.
szita pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new c6a2d79 HIVE-21812: Implement get partition related methods on
temporary tables (Laszlo Pinter, reviewed by Marta Kuczora, Adam Szita)
addendum #1
c6a2d79 is described below
commit c6a2d799c8fdd1cd88825bb825a161efe0fa0ed1
Author: Laszlo Pinter <[email protected]>
AuthorDate: Fri Jun 14 11:45:14 2019 +0200
HIVE-21812: Implement get partition related methods on temporary tables
(Laszlo Pinter, reviewed by Marta Kuczora, Adam Szita) addendum #1
---
...nHiveMetastoreClientGetPartitionsTempTable.java | 190 +++++++++++++++++++++
...ditionalIgnoreOnSessionHiveMetastoreClient.java | 36 ++++
.../hive/metastore/client/CustomIgnoreRule.java | 44 +++++
3 files changed, 270 insertions(+)
diff --git
a/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestSessionHiveMetastoreClientGetPartitionsTempTable.java
b/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestSessionHiveMetastoreClientGetPartitionsTempTable.java
new file mode 100644
index 0000000..d35621a
--- /dev/null
+++
b/ql/src/test/org/apache/hadoop/hive/ql/metadata/TestSessionHiveMetastoreClientGetPartitionsTempTable.java
@@ -0,0 +1,190 @@
+/*
+ * 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 com.google.common.collect.Lists;
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.IMetaStoreClient;
+import org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest;
+import org.apache.hadoop.hive.metastore.api.Partition;
+import org.apache.hadoop.hive.metastore.api.Table;
+import org.apache.hadoop.hive.metastore.api.PrincipalPrivilegeSet;
+import org.apache.hadoop.hive.metastore.api.PrivilegeGrantInfo;
+import org.apache.hadoop.hive.metastore.api.MetaException;
+import org.apache.hadoop.hive.metastore.api.NoSuchObjectException;
+import org.apache.hadoop.hive.metastore.client.CustomIgnoreRule;
+import org.apache.hadoop.hive.metastore.client.TestGetPartitions;
+import org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder;
+import org.apache.hadoop.hive.metastore.client.builder.TableBuilder;
+import org.apache.hadoop.hive.metastore.minihms.AbstractMetaStoreService;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.thrift.TException;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Test class for get partitions related methods on temporary tables.
+ */
+@RunWith(Parameterized.class)
+@Category(MetastoreCheckinTest.class)
+public class TestSessionHiveMetastoreClientGetPartitionsTempTable extends
TestGetPartitions {
+
+ private HiveConf conf;
+
+ private static final String USER_NAME = "user0";
+ private static final List<String> GROUPS = Lists.newArrayList("group0",
"group1");
+ private static final String PART_PRIV = "PARTITION_LEVEL_PRIVILEGE";
+
+ public TestSessionHiveMetastoreClientGetPartitionsTempTable(String name,
AbstractMetaStoreService metaStore) {
+ super(name, metaStore);
+ ignoreRule = new CustomIgnoreRule();
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ initHiveConf();
+ SessionState.start(conf);
+ super.setClient(Hive.get(conf).getMSC());
+ getClient().dropDatabase(DB_NAME, true, true, true);
+ }
+
+ private void initHiveConf() throws HiveException {
+ conf = Hive.get().getConf();
+ conf.setBoolVar(HiveConf.ConfVars.METASTORE_FASTPATH, true);
+ }
+
+ @Override
+ protected Table createTestTable(IMetaStoreClient client, String dbName,
String tableName,
+ List<String> partCols, boolean setPartitionLevelPrivileges) throws
TException {
+ TableBuilder builder =
+ new
TableBuilder().setDbName(dbName).setTableName(tableName).addCol("id",
"int").addCol("name", "string")
+ .setTemporary(true);
+
+ partCols.forEach(col -> builder.addPartCol(col, "string"));
+ Table table = builder.build(conf);
+
+ if (setPartitionLevelPrivileges) {
+ table.putToParameters(PART_PRIV, "true");
+ }
+
+ client.createTable(table);
+ return table;
+ }
+
+ @Override
+ protected void addPartition(IMetaStoreClient client, Table table,
List<String> values) throws TException {
+ PartitionBuilder builder = new PartitionBuilder().inTable(table);
+ values.forEach(builder::addValue);
+ Partition partition = builder.build(conf);
+ if (table.getParameters().containsKey(PART_PRIV) &&
table.getParameters().get(PART_PRIV).equals("true")) {
+ PrincipalPrivilegeSet privileges = new PrincipalPrivilegeSet();
+ Map<String, List<PrivilegeGrantInfo>> userPrivileges = new HashMap<>();
+ userPrivileges.put(USER_NAME, new ArrayList<>());
+ privileges.setUserPrivileges(userPrivileges);
+
+ Map<String, List<PrivilegeGrantInfo>> groupPrivileges = new HashMap<>();
+ GROUPS.forEach(g -> groupPrivileges.put(g, new ArrayList<>()));
+ privileges.setGroupPrivileges(groupPrivileges);
+ partition.setPrivileges(privileges);
+ }
+ client.add_partition(partition);
+ }
+
+ @Test(expected = MetaException.class)
+ @Override
+ public void testGetPartitionsByNamesEmptyParts() throws Exception {
+ createTable4PartColsParts(getClient());
+ getClient().getPartitionsByNames(DB_NAME, TABLE_NAME,
Lists.newArrayList("", ""));
+ }
+
+ @Test(expected = MetaException.class)
+ @Override
+ public void testGetPartitionsByNamesNullDbName() throws Exception {
+ super.testGetPartitionsByNamesNullDbName();
+ }
+
+ @Test(expected = MetaException.class)
+ @Override
+ public void testGetPartitionsByNamesNullTblName() throws Exception {
+ super.testGetPartitionsByNamesNullTblName();
+ }
+
+ @Test
+ @Override
+ public void testGetPartitionWithAuthInfo() throws Exception {
+ createTable3PartCols1PartAuthOn(getClient());
+ Partition partition = getClient()
+ .getPartitionWithAuthInfo(DB_NAME, TABLE_NAME,
Lists.newArrayList("1997", "05", "16"), USER_NAME, GROUPS);
+ assertNotNull(partition);
+ assertAuthInfoReturned(USER_NAME, GROUPS, partition);
+ }
+
+ @Test
+ @Override
+ public void testGetPartitionWithAuthInfoEmptyUserGroup() throws Exception {
+ createTable3PartCols1PartAuthOn(getClient());
+ Partition partition = getClient()
+ .getPartitionWithAuthInfo(DB_NAME, TABLE_NAME,
Lists.newArrayList("1997", "05", "16"), "",
+ Lists.newArrayList());
+ assertNotNull(partition);
+ assertAuthInfoReturned(USER_NAME, GROUPS, partition);
+ }
+
+ @Test(expected = MetaException.class)
+ @Override
+ public void testGetPartitionWithAuthInfoNullDbName()
+ throws Exception {
+ super.testGetPartitionWithAuthInfoNullDbName();
+ }
+
+ @Test(expected = MetaException.class)
+ @Override
+ public void testGetPartitionWithAuthInfoNullTblName()
+ throws Exception {
+ super.testGetPartitionWithAuthInfoNullTblName();
+ }
+
+ @Test(expected = NoSuchObjectException.class)
+ @Override
+ public void testGetPartitionWithAuthInfoNullGroups()
+ throws Exception {
+ super.testGetPartitionWithAuthInfoNullGroups();
+ }
+
+ private void assertAuthInfoReturned(String userName, List<String> groups,
Partition partition) {
+ PrincipalPrivilegeSet privileges = partition.getPrivileges();
+ assertNotNull(privileges);
+ assertTrue(privileges.getUserPrivileges().containsKey(userName));
+ for (String group : groups) {
+ assertTrue(privileges.getGroupPrivileges().containsKey(group));
+ }
+ }
+
+}
diff --git
a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/ConditionalIgnoreOnSessionHiveMetastoreClient.java
b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/ConditionalIgnoreOnSessionHiveMetastoreClient.java
new file mode 100644
index 0000000..99039b0
--- /dev/null
+++
b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/ConditionalIgnoreOnSessionHiveMetastoreClient.java
@@ -0,0 +1,36 @@
+/*
+ * 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.metastore.client;
+
+import java.lang.annotation.Inherited;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * This annotation provides a way to skip the execution of seome tests,
+ * when a certain runtime criteria is met. It should be used together with
{@link CustomIgnoreRule}.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.METHOD)
+@Inherited
+public @interface ConditionalIgnoreOnSessionHiveMetastoreClient {
+
+}
diff --git
a/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/CustomIgnoreRule.java
b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/CustomIgnoreRule.java
new file mode 100644
index 0000000..ac2a7d3
--- /dev/null
+++
b/standalone-metastore/metastore-server/src/test/java/org/apache/hadoop/hive/metastore/client/CustomIgnoreRule.java
@@ -0,0 +1,44 @@
+/*
+ * 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.metastore.client;
+
+import org.junit.Assume;
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+/**
+ * This rule checks the existance of {@link
ConditionalIgnoreOnSessionHiveMetastoreClient} annotation.
+ * If the annotation is present, skips the execution of the test.
+ */
+public class CustomIgnoreRule implements TestRule {
+ @Override public Statement apply(Statement statement, Description
description) {
+ return new Statement() {
+ @Override public void evaluate() throws Throwable {
+ ConditionalIgnoreOnSessionHiveMetastoreClient annotation =
+
description.getAnnotation(ConditionalIgnoreOnSessionHiveMetastoreClient.class);
+ if (annotation != null) {
+ Assume.assumeTrue("Test is ignored", false);
+ } else {
+ statement.evaluate();
+ }
+ }
+ };
+ }
+}