[GitHub] [flink] bowenli86 commented on a change in pull request #8449: [FLINK-12235][hive] Support Hive partition in HiveCatalog

2019-05-22 Thread GitBox
bowenli86 commented on a change in pull request #8449: [FLINK-12235][hive] 
Support Hive partition in HiveCatalog
URL: https://github.com/apache/flink/pull/8449#discussion_r286602063
 
 

 ##
 File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/HiveCatalog.java
 ##
 @@ -740,10 +745,13 @@ public void alterPartition(ObjectPath tablePath, 
CatalogPartitionSpec partitionS
checkNotNull(partitionSpec, "CatalogPartitionSpec cannot be 
null");
checkNotNull(newPartition, "New partition cannot be null");
 
+   checkArgument(newPartition instanceof HiveCatalogPartition, 
"Currently only supports HiveCatalogPartition");
 
 Review comment:
   ditto


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [flink] bowenli86 commented on a change in pull request #8449: [FLINK-12235][hive] Support Hive partition in HiveCatalog

2019-05-22 Thread GitBox
bowenli86 commented on a change in pull request #8449: [FLINK-12235][hive] 
Support Hive partition in HiveCatalog
URL: https://github.com/apache/flink/pull/8449#discussion_r286601953
 
 

 ##
 File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/HiveCatalog.java
 ##
 @@ -639,8 +640,12 @@ public void createPartition(ObjectPath tablePath, 
CatalogPartitionSpec partition
checkNotNull(partitionSpec, "CatalogPartitionSpec cannot be 
null");
checkNotNull(partition, "Partition cannot be null");
 
+   checkArgument(partition instanceof HiveCatalogPartition, 
"Currently only supports HiveCatalogPartition");
 
 Review comment:
   We currently throw `CatalogException` if the type doesn't match. 
`checkArgument()` will throw `IllegalArgumentException`. 


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:
us...@infra.apache.org


With regards,
Apache Git Services


[GitHub] [flink] bowenli86 commented on a change in pull request #8449: [FLINK-12235][hive] Support Hive partition in HiveCatalog

2019-05-22 Thread GitBox
bowenli86 commented on a change in pull request #8449: [FLINK-12235][hive] 
Support Hive partition in HiveCatalog
URL: https://github.com/apache/flink/pull/8449#discussion_r286608694
 
 

 ##
 File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/HiveCatalog.java
 ##
 @@ -616,44 +619,279 @@ private  static Table instantiateHiveTable(ObjectPath 
tablePath, CatalogBaseTabl
// -- partitions --
 
@Override
-   public void createPartition(ObjectPath tablePath, CatalogPartitionSpec 
partitionSpec, CatalogPartition partition, boolean ignoreIfExists)
-   throws TableNotExistException, 
TableNotPartitionedException, PartitionSpecInvalidException, 
PartitionAlreadyExistsException, CatalogException {
-   throw new UnsupportedOperationException();
+   public boolean partitionExists(ObjectPath tablePath, 
CatalogPartitionSpec partitionSpec)
+   throws CatalogException {
+   checkNotNull(tablePath, "Table path cannot be null");
+   checkNotNull(partitionSpec, "CatalogPartitionSpec cannot be 
null");
+   try {
+   return getHivePartition(tablePath, partitionSpec) != 
null;
+   } catch (NoSuchObjectException | TableNotExistException | 
PartitionSpecInvalidException e) {
+   return false;
+   } catch (TException e) {
+   throw new CatalogException(
+   String.format("Failed to get partition %s of 
table %s", partitionSpec, tablePath), e);
+   }
}
 
@Override
-   public void dropPartition(ObjectPath tablePath, CatalogPartitionSpec 
partitionSpec, boolean ignoreIfNotExists)
-   throws PartitionNotExistException, CatalogException {
-   throw new UnsupportedOperationException();
+   public void createPartition(ObjectPath tablePath, CatalogPartitionSpec 
partitionSpec, CatalogPartition partition, boolean ignoreIfExists)
+   throws TableNotExistException, 
TableNotPartitionedException, PartitionSpecInvalidException, 
PartitionAlreadyExistsException, CatalogException {
+   checkNotNull(tablePath, "Table path cannot be null");
+   checkNotNull(partitionSpec, "CatalogPartitionSpec cannot be 
null");
+   checkNotNull(partition, "Partition cannot be null");
+
+   checkArgument(partition instanceof HiveCatalogPartition, 
"Currently only supports HiveCatalogPartition");
+
+   Table hiveTable = getHiveTable(tablePath);
+
+   ensureTableAndPartitionMatch(hiveTable, partition);
+
+   ensurePartitionedTable(tablePath, hiveTable);
+
+   try {
+   
client.add_partition(instantiateHivePartition(hiveTable, partitionSpec, 
partition));
+   } catch (AlreadyExistsException e) {
+   if (!ignoreIfExists) {
+   throw new 
PartitionAlreadyExistsException(catalogName, tablePath, partitionSpec);
+   }
+   } catch (TException e) {
+   throw new CatalogException(
+   String.format("Failed to create partition %s of 
table %s", partitionSpec, tablePath));
+   }
}
 
@Override
-   public void alterPartition(ObjectPath tablePath, CatalogPartitionSpec 
partitionSpec, CatalogPartition newPartition, boolean ignoreIfNotExists)
+   public void dropPartition(ObjectPath tablePath, CatalogPartitionSpec 
partitionSpec, boolean ignoreIfNotExists)
throws PartitionNotExistException, CatalogException {
-   throw new UnsupportedOperationException();
+   checkNotNull(tablePath, "Table path cannot be null");
+   checkNotNull(partitionSpec, "CatalogPartitionSpec cannot be 
null");
+   try {
+   Table hiveTable = getHiveTable(tablePath);
+   client.dropPartition(tablePath.getDatabaseName(), 
tablePath.getObjectName(),
+   getOrderedFullPartitionValues(partitionSpec, 
getFieldNames(hiveTable.getPartitionKeys()), tablePath), true);
+   } catch (NoSuchObjectException e) {
+   if (!ignoreIfNotExists) {
+   throw new 
PartitionNotExistException(catalogName, tablePath, partitionSpec, e);
+   }
+   } catch (MetaException | TableNotExistException | 
PartitionSpecInvalidException e) {
+   throw new PartitionNotExistException(catalogName, 
tablePath, partitionSpec, e);
+   } catch (TException e) {
+   throw new CatalogException(
+   String.format("Failed to drop partition %s of 
table %s", partitionSpec, tablePath));
+ 

[GitHub] [flink] bowenli86 commented on a change in pull request #8449: [FLINK-12235][hive] Support Hive partition in HiveCatalog

2019-05-22 Thread GitBox
bowenli86 commented on a change in pull request #8449: [FLINK-12235][hive] 
Support Hive partition in HiveCatalog
URL: https://github.com/apache/flink/pull/8449#discussion_r286602271
 
 

 ##
 File path: 
flink-connectors/flink-connector-hive/src/main/java/org/apache/flink/table/catalog/hive/HiveCatalog.java
 ##
 @@ -770,6 +778,16 @@ public void alterPartition(ObjectPath tablePath, 
CatalogPartitionSpec partitionS
}
}
 
+   // make sure both table and partition are generic, or neither is
+   private void ensureTableAndPartitionMatch(Table hiveTable, 
CatalogPartition catalogPartition) {
+   boolean isGeneric = 
Boolean.valueOf(hiveTable.getParameters().get(FLINK_PROPERTY_IS_GENERIC));
+   if ((isGeneric && catalogPartition instanceof 
HiveCatalogPartition) ||
+   (!isGeneric && catalogPartition instanceof 
GenericCatalogPartition)) {
+   throw new 
IllegalArgumentException(String.format("Cannot handle %s partition for %s 
table",
 
 Review comment:
   throw `CatalogException`


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:
us...@infra.apache.org


With regards,
Apache Git Services