partitionKeys = table.getPartitionKeys();
bucket = getHiveBucket(table, tupleDomain.extractFixedValues());
}
catch (NoSuchObjectException e) {
throw new TableNotFoundException(tableName);
}
ImmutableMap.Builder<String, ConnectorColumnHandle> partitionKeysByNameBuilder = ImmutableMap.builder();
List<String> filterPrefix = new ArrayList<>();
for (int i = 0; i < partitionKeys.size(); i++) {
FieldSchema field = partitionKeys.get(i);
HiveColumnHandle columnHandle = new HiveColumnHandle(connectorId, field.getName(), i, getSupportedHiveType(field.getType()), -1, true);
partitionKeysByNameBuilder.put(field.getName(), columnHandle);
// only add to prefix if all previous keys have a value
if (filterPrefix.size() == i && !tupleDomain.isNone()) {
Domain domain = tupleDomain.getDomains().get(columnHandle);
if (domain != null && domain.getRanges().getRangeCount() == 1) {
// We intentionally ignore whether NULL is in the domain since partition keys can never be NULL
Range range = Iterables.getOnlyElement(domain.getRanges());
if (range.isSingleValue()) {
Comparable<?> value = range.getLow().getValue();
checkArgument(value instanceof Boolean || value instanceof Slice || value instanceof Double || value instanceof Long,
"Only Boolean, Slice (UTF8 String), Double and Long partition keys are supported");
if (value instanceof Slice) {
filterPrefix.add(((Slice) value).toStringUtf8());
}
else {
filterPrefix.add(value.toString());
}
}
}
}
}
// fetch the partition names
List<String> partitionNames;
try {
if (partitionKeys.isEmpty()) {
partitionNames = ImmutableList.of(UNPARTITIONED_ID);
}
else if (filterPrefix.isEmpty()) {
partitionNames = metastore.getPartitionNames(tableName.getSchemaName(), tableName.getTableName());
}
else {
partitionNames = metastore.getPartitionNamesByParts(tableName.getSchemaName(), tableName.getTableName(), filterPrefix);
}
}
catch (NoSuchObjectException e) {
throw new TableNotFoundException(tableName);
}
// do a final pass to filter based on fields that could not be used to build the prefix
Map<String, ConnectorColumnHandle> partitionKeysByName = partitionKeysByNameBuilder.build();
List<ConnectorPartition> partitions = FluentIterable.from(partitionNames)