bowenli86 commented on a change in pull request #10381: [FLINK-14513][hive]
Implement listPartitionsByFilter to HiveCatalog
URL: https://github.com/apache/flink/pull/10381#discussion_r355105674
##########
File path:
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/HiveCatalog.java
##########
@@ -751,6 +753,34 @@ public void dropPartition(ObjectPath tablePath,
CatalogPartitionSpec partitionSp
}
}
+ public List<CatalogPartitionSpec> listPartitionsByFilter(ObjectPath
tablePath, List<Expression> expressions)
+ throws TableNotExistException,
TableNotPartitionedException, CatalogException {
+ Table hiveTable = getHiveTable(tablePath);
+ ensurePartitionedTable(tablePath, hiveTable);
+ List<String> partColNames =
getFieldNames(hiveTable.getPartitionKeys());
+ String filter = HiveTableUtil.makePartitionFilter(partColNames,
expressions);
+ if (filter == null) {
+ throw new UnsupportedOperationException(
+ "HiveCatalog is unable to handle the
partition filter expressions: " + expressions);
+ }
+ try {
+ PartitionSpecProxy.PartitionIterator partitions =
client.listPartitionSpecsByFilter(
+ tablePath.getDatabaseName(),
tablePath.getObjectName(), filter, (short) -1).getPartitionIterator();
+ List<CatalogPartitionSpec> res = new ArrayList<>();
+ while (partitions.hasNext()) {
+ Partition partition = partitions.next();
+ Map<String, String> spec = new HashMap<>();
+ for (int i = 0; i < partColNames.size(); i++) {
+ spec.put(partColNames.get(i),
partition.getValues().get(i));
+ }
+ res.add(new CatalogPartitionSpec(spec));
+ }
+ return res;
+ } catch (TException e) {
+ throw new UnsupportedOperationException("Failed to list
partition by filter from HMS", e);
Review comment:
who would catch the exception, and do something about it?
I feel it better be a declared exception to notify callers they need to
watch out for it, like a new IllegalFilterException?
UnsupportedOperationException is for operation that is universally unsupported,
but the case here is about input args where some **args** (filters) are
supported while some are not.
Besides, add the filter to error msg?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services