List<PartitionModel> pml = null;
try {
Table tb = tableManager.getTable(t.getName());
if(tb.getPartitionKeysSize()<=0){
//非分区表,添加一个默认分区
PartitionModel pm = new PartitionModel();
pm.setName("默认分区");
pm.setCols(t.getCols());
pm.setCompressed(true);
pm.setFieldDelim(t.getFieldDelim());
pm.setLineDelim(t.getLineDelim());
pm.setInputFormat(t.getInputFormat());
pm.setPath(t.getPath());
pm.setSerDeClass(t.getSerDeClass());
pml = new ArrayList<PartitionModel>(1);
pml.add(pm);
return pml;
}
List<Partition> pl = tableManager.getPartitions(t.getName(), 40);
pml = new ArrayList<PartitionModel>(pl.size());
for (Partition p : pl) {
PartitionModel pm = new PartitionModel();
StorageDescriptor sd = p.getSd();
// 分区字段
List<String> pks = new ArrayList<String>(
tb.getPartitionKeysSize());
Iterator<String> vi = p.getValuesIterator();
// 拼接分区字段
for (FieldSchema fs : tb.getPartitionKeys()) {
pks.add(fs.getName() + "=" + vi.next());
}
pm.setPath(sd.getLocation());
// 用'/'链接每个分区字段作为分区名
pm.setName(StringUtils.join(pks.toArray(), '/'));
pm.setSerDeClass(sd.getSerdeInfo().getSerializationLib());
// 如果分隔符是数字,需要转义为对应的ascll字符
String fieldDelim = tansToStringIfInt(sd.getSerdeInfo()
.getParameters().get(FIELD_DELIMITER_KEY));
String lineDelim = tansToStringIfInt(sd.getSerdeInfo()
.getParameters().get(LINE_DELIMITER_KEY));
pm.setFieldDelim(fieldDelim);
pm.setLineDelim(lineDelim);
pm.setCols(convert(sd.getCols()));
pm.setInputFormat(sd.getInputFormat());
pm.setCompressed(sd.isCompressed());
pml.add(pm);
}
} catch (ZeusException e) {
log.error("获取分区列表出错", e);
throw new GwtException("获取分区列表出错", e);