15 package com.cloudera.impala.util;
17 import java.util.List;
19 import org.apache.hadoop.hive.conf.HiveConf;
20 import org.apache.hadoop.hive.metastore.HiveMetaStoreClient;
21 import org.apache.hadoop.hive.metastore.api.MetaException;
22 import org.apache.hadoop.hive.metastore.api.Partition;
23 import org.apache.log4j.Logger;
24 import org.apache.thrift.TException;
27 import com.google.common.base.Preconditions;
28 import com.google.common.collect.Lists;
34 private static final Logger
LOG = Logger.getLogger(MetaStoreUtil.class);
48 HiveConf hiveConf =
new HiveConf(
HdfsTable.class);
49 String strValue = hiveConf.get(
50 HiveConf.ConfVars.METASTORE_BATCH_RETRIEVE_TABLE_PARTITION_MAX.toString());
51 if (strValue != null) {
54 }
catch (NumberFormatException e) {
55 LOG.error(
"Error parsing max partition batch size from HiveConfig: ", e);
59 LOG.error(String.format(
"Invalid value for max partition batch size: %d. Using " +
76 HiveMetaStoreClient client, String dbName, String tblName,
int numRetries)
77 throws MetaException, TException {
78 Preconditions.checkArgument(numRetries >= 0);
83 List<String> partNames = client.listPartitionNames(dbName, tblName, (short) -1);
84 return MetaStoreUtil.fetchPartitionsByName(client, partNames, dbName, tblName);
85 }
catch (MetaException e) {
88 if (retryAttempt < numRetries) {
89 LOG.error(String.format(
"Error fetching partitions for table: %s.%s. " +
90 "Retry attempt: %d/%d", dbName, tblName, retryAttempt, numRetries), e);
107 HiveMetaStoreClient client, List<String> partNames, String dbName, String tblName)
108 throws MetaException, TException {
109 LOG.trace(String.format(
"Fetching %d partitions for: %s.%s using partition " +
112 List<org.apache.hadoop.hive.metastore.api.Partition> fetchedPartitions =
113 Lists.newArrayList();
117 List<String> partsToFetch =
120 fetchedPartitions.addAll(
121 client.getPartitionsByNames(dbName, tblName, partsToFetch));
123 return fetchedPartitions;