xuefuz commented on a change in pull request #8449: [FLINK-12235][hive] Support
partition related operations in HiveCatalog
URL: https://github.com/apache/flink/pull/8449#discussion_r284822727
##########
File path:
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/HiveCatalog.java
##########
@@ -200,44 +200,56 @@ protected Table createHiveTable(ObjectPath tablePath,
CatalogBaseTable table) {
// ------ partitions ------
@Override
- public void createPartition(ObjectPath tablePath, CatalogPartitionSpec
partitionSpec, CatalogPartition partition, boolean ignoreIfExists)
- throws TableNotExistException,
TableNotPartitionedException, PartitionSpecInvalidException,
PartitionAlreadyExistsException, CatalogException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void dropPartition(ObjectPath tablePath, CatalogPartitionSpec
partitionSpec, boolean ignoreIfNotExists)
- throws PartitionNotExistException, CatalogException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public void alterPartition(ObjectPath tablePath, CatalogPartitionSpec
partitionSpec, CatalogPartition newPartition, boolean ignoreIfNotExists)
- throws PartitionNotExistException, CatalogException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public List<CatalogPartitionSpec> listPartitions(ObjectPath tablePath)
- throws TableNotExistException,
TableNotPartitionedException, CatalogException {
- throw new UnsupportedOperationException();
+ protected void validateCatalogPartition(CatalogPartition
catalogPartition) throws CatalogException {
+ if (!(catalogPartition instanceof HiveCatalogPartition)) {
+ throw new CatalogException(String.format("%s can only
handle %s but got %s", getClass().getSimpleName(),
+ HiveCatalogPartition.class.getSimpleName(),
catalogPartition.getClass().getSimpleName()));
+ }
}
@Override
- public List<CatalogPartitionSpec> listPartitions(ObjectPath tablePath,
CatalogPartitionSpec partitionSpec)
- throws TableNotExistException,
TableNotPartitionedException, CatalogException {
- throw new UnsupportedOperationException();
- }
+ protected Partition createHivePartition(Table hiveTable,
CatalogPartitionSpec partitionSpec, CatalogPartition catalogPartition)
+ throws PartitionSpecInvalidException {
+ Partition partition = new Partition();
+ List<String> partCols =
getFieldNames(hiveTable.getPartitionKeys());
+ List<String> partValues = getFullPartitionValues(new
ObjectPath(hiveTable.getDbName(), hiveTable.getTableName()),
+ partitionSpec, partCols);
+ // validate partition values
+ for (int i = 0; i < partCols.size(); i++) {
+ if
(StringUtils.isNullOrWhitespaceOnly(partValues.get(i))) {
+ throw new
PartitionSpecInvalidException(catalogName, partCols,
+ new ObjectPath(hiveTable.getDbName(),
hiveTable.getTableName()), partitionSpec);
+ }
+ }
+ HiveCatalogPartition hiveCatalogPartition =
(HiveCatalogPartition) catalogPartition;
Review comment:
Do we need to validate the casting is valid?
----------------------------------------------------------------
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