zhangbutao commented on code in PR #4501:
URL: https://github.com/apache/hive/pull/4501#discussion_r1271865326
##########
common/src/java/org/apache/hadoop/hive/conf/HiveConf.java:
##########
@@ -1292,7 +1292,7 @@ public static enum ConfVars {
* @deprecated Use MetastoreConf.BATCH_RETRIEVE_MAX
*/
@Deprecated
- METASTORE_BATCH_RETRIEVE_MAX("hive.metastore.batch.retrieve.max", 300,
+ METASTORE_BATCH_RETRIEVE_MAX("hive.metastore.batch.retrieve.max", 1000,
Review Comment:
Do we have any benchmark to verify that 1000 is more reasonable?
##########
ql/src/test/org/apache/hadoop/hive/ql/exec/TestGetPartitionInBatches.java:
##########
@@ -0,0 +1,245 @@
+/*
+ * 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.exec;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.*;
Review Comment:
Please import the specific class. The same as Line32 & Line35 & Line37 &
Line38
##########
ql/src/test/results/clientpositive/llap/temp_table_add_part_multiple.q.out:
##########
@@ -115,5 +115,5 @@ POSTHOOK: Input: default@add_part_test_n1_temp@ds=2010-04-01
#### A masked pattern was here ####
100 100 2010-01-01
200 200 2010-02-01
-500 400 2010-04-01
400 300 2010-03-01
+500 400 2010-04-01
Review Comment:
Why this changed?
##########
ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java:
##########
@@ -4139,27 +4141,42 @@ public List<Partition> getPartitions(Table tbl) throws
HiveException {
}
/**
- * Get all the partitions; unlike {@link #getPartitions(Table)}, does not
include auth.
+ * Get all the partitions in batches; unlike {@link #getPartitions(Table)},
does not include auth.
* @param tbl table for which partitions are needed
* @return list of partition objects
*/
public Set<Partition> getAllPartitionsOf(Table tbl) throws HiveException {
+ int batchSize= MetastoreConf.getIntVar(
+ Hive.get().getConf(), MetastoreConf.ConfVars.BATCH_RETRIEVE_MAX);
+ int maxRetries = HiveConf.getIntVar(conf,
HiveConf.ConfVars.HIVE_GETPARTITIONS_MAX_RETRIES);
+ return getAllPartitionsOf(tbl, batchSize, 2, maxRetries);
+ }
+
+ public Set<Partition> getAllPartitionsOf(Table tbl, int batchSize, int
decayingFactor,
+ int maxRetries) throws HiveException {
if (!tbl.isPartitioned()) {
return Sets.newHashSet(new Partition(tbl));
}
-
- List<org.apache.hadoop.hive.metastore.api.Partition> tParts;
+ Set<Partition> result = new LinkedHashSet<>();
+ RetryUtilities.ExponentiallyDecayingBatchWork batchTask = new
RetryUtilities
+ .ExponentiallyDecayingBatchWork<Void>(batchSize, decayingFactor,
maxRetries) {
+ @Override
+ public Void execute(int size) throws HiveException {
+ try {
+ result.clear();
+ new PartitionIterable(Hive.get(), tbl, null,
size).forEach(result::add);
Review Comment:
Maybe a stupid question: Is there any risk that we only get partial
partitions due to some exception?
##########
ql/src/test/org/apache/hadoop/hive/ql/exec/TestGetPartitionInBatches.java:
##########
@@ -0,0 +1,245 @@
+/*
+ * 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.exec;
+
+import org.apache.hadoop.hive.conf.HiveConf;
+import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
+import org.apache.hadoop.hive.metastore.api.*;
+import org.apache.hadoop.hive.metastore.client.builder.PartitionBuilder;
+import org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat;
+import org.apache.hadoop.hive.ql.metadata.Hive;
+import org.apache.hadoop.hive.ql.metadata.HiveException;
+import org.apache.hadoop.hive.ql.session.SessionState;
+import org.apache.hadoop.hive.ql.stats.StatsUtils;
+import org.apache.hadoop.mapred.TextInputFormat;
+import org.apache.hadoop.util.StringUtils;
+import org.junit.*;
+import org.mockito.ArgumentCaptor;
+
+import java.util.*;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.times;
+
+public class TestGetPartitionInBatches {
+
+ private final String catName = "hive";
+ private final String dbName = "default";
+ private final String tableName = "test_partition_batch";
+ private static HiveConf hiveConf;
+ private static HiveMetaStoreClient db;
+ private static Hive hive;
+ private Table table;
+
+ @BeforeClass
+ public static void setupClass() throws HiveException {
+ hiveConf = new HiveConf(TestMsckCreatePartitionsInBatches.class);
+ hive = Hive.get();
+ SessionState.start(hiveConf);
+ try {
+ db = new HiveMetaStoreClient(hiveConf);
+ } catch (MetaException e) {
+ throw new HiveException(e);
+ }
+ }
+
+ @Before
+ public void before() throws Exception {
+ createPartitionedTable(catName, dbName, tableName);
+ table = db.getTable(catName, dbName, tableName);
+ addPartitions(dbName, tableName);
+ }
+
+ @After
+ public void after() throws Exception {
+ cleanUpTableQuietly(catName, dbName, tableName);
+ }
+
+ private Table createPartitionedTable(String catName, String dbName, String
tableName) throws Exception {
+ try {
+ db.dropTable(catName, dbName, tableName);
+ Table table = new Table();
+ table.setCatName(catName);
+ table.setDbName(dbName);
+ table.setTableName(tableName);
+ FieldSchema col1 = new FieldSchema("key", "string", "");
+ FieldSchema col2 = new FieldSchema("value", "int", "");
+ FieldSchema col3 = new FieldSchema("city", "string", "");
+ StorageDescriptor sd = new StorageDescriptor();
+ sd.setSerdeInfo(new SerDeInfo());
+ sd.setInputFormat(TextInputFormat.class.getCanonicalName());
+
sd.setOutputFormat(HiveIgnoreKeyTextOutputFormat.class.getCanonicalName());
+ sd.setCols(Arrays.asList(col1, col2));
+ table.setPartitionKeys(Arrays.asList(col3));
+ table.setSd(sd);
+ db.createTable(table);
+ return db.getTable(catName, dbName, tableName);
+ } catch (Exception exception) {
+ fail("Unable to drop and create table " +
StatsUtils.getFullyQualifiedTableName(dbName, tableName) + " because "
+ + StringUtils.stringifyException(exception));
+ throw exception;
+ }
+ }
+
+ private void addPartitions(String dbName, String tableName) throws
Exception {
+ List<Partition> partitions = new ArrayList<>();
+ for (int i = 0; i < 30; i++) {
+ partitions.add(buildPartition(dbName, tableName,
String.valueOf(i), table.getSd().getLocation() + "/city=" + String.valueOf(i)));
Review Comment:
```suggestion
partitions.add(buildPartition(dbName, tableName,
String.valueOf(i), table.getSd().getLocation() + "/city=" + i));
```
##########
common/src/java/org/apache/hadoop/hive/conf/HiveConf.java:
##########
@@ -3021,6 +3021,13 @@ public static enum ConfVars {
HIVE_ZOOKEEPER_KILLQUERY_NAMESPACE("hive.zookeeper.killquery.namespace",
"killQueries",
"When kill query coordination is enabled, uses this namespace for
registering queries to kill with zookeeper"),
+ HIVE_GETPARTITIONS_MAX_RETRIES("hive.getpartitions.max.retries", 5,
Review Comment:
In general, we should keep the new property to be closed to make the related
code logic stay the same as before.
But i want to listen more suggestion from othe folks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]