15 package com.cloudera.impala.catalog;
17 import com.cloudera.impala.thrift.TPartitionStats;
22 import java.util.Iterator;
23 import java.util.List;
25 import org.apache.commons.codec.binary.Base64;
26 import org.apache.thrift.protocol.TCompactProtocol;
27 import org.apache.thrift.TSerializer;
28 import org.apache.thrift.TException;
29 import com.google.common.base.Preconditions;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
33 import com.google.common.collect.Lists;
41 "impala_intermediate_stats_num_chunks";
44 "impala_intermediate_stats_chunk";
49 private final static Logger
LOG = LoggerFactory.getLogger(PartitionStatsUtil.class);
58 if (hmsParameters == null)
return null;
60 if (numChunksStr == null)
return null;
61 int numChunks = Integer.parseInt(numChunksStr);
62 if (numChunks == 0)
return null;
64 Preconditions.checkState(numChunks >= 0);
65 StringBuilder encodedStats =
new StringBuilder();
66 for (
int i = 0; i < numChunks; ++i) {
71 encodedStats.append(chunk);
74 byte[] decodedStats = Base64.decodeBase64(encodedStats.toString());
75 TCompactProtocol.Factory protocolFactory =
new TCompactProtocol.Factory();
76 TPartitionStats ret =
new TPartitionStats();
77 JniUtil.deserializeThrift(protocolFactory, ret, decodedStats);
87 if (partStats == null) {
102 TCompactProtocol.Factory protocolFactory =
new TCompactProtocol.Factory();
103 TSerializer serializer =
new TSerializer(protocolFactory);
104 byte[] serialized = serializer.serialize(partStats);
105 String base64 =
new String(Base64.encodeBase64(serialized));
108 Integer.toString(chunks.size()));
109 for (
int i = 0; i < chunks.size(); ++i) {
112 }
catch (TException e) {
113 LOG.info(
"Error saving partition stats: ", e);
120 for (Iterator<String> it = partition.
getParameters().keySet().iterator();
130 List<String> ret = Lists.newArrayList();
131 while (idx < data.length()) {
132 int remaining = data.length() - idx;
133 int chunkSize = (chunkLen > remaining) ? remaining : chunkLen;
134 ret.add(data.substring(
idx, idx + chunkSize));
static final int HMS_MAX_CHUNKLEN
static final String INTERMEDIATE_STATS_NUM_CHUNKS
Map< String, String > getParameters()
static final String INTERMEDIATE_STATS_CHUNK_PREFIX
static List< String > chunkStringForHms(String data, int chunkLen)
static TPartitionStats partStatsFromParameters(Map< String, String > hmsParameters)
static void partStatsToParameters(TPartitionStats partStats, HdfsPartition partition)
static void deletePartStats(HdfsPartition partition)