Search in sources :

Example 1 with PartitionAlreadyExistsException

use of org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException in project flink by apache.

the class HiveCatalog method createPartition.

@Override
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");
    Table hiveTable = getHiveTable(tablePath);
    ensurePartitionedTable(tablePath, hiveTable);
    // partition doesn't have connector property, so check the table
    boolean isHiveTable = isHiveTable(hiveTable.getParameters());
    if (!isHiveTable) {
        throw new CatalogException("Currently only supports partition for hive tables");
    }
    try {
        client.add_partition(instantiateHivePartition(hiveTable, partitionSpec, partition));
    } catch (AlreadyExistsException e) {
        if (!ignoreIfExists) {
            throw new PartitionAlreadyExistsException(getName(), tablePath, partitionSpec);
        }
    } catch (TException e) {
        throw new CatalogException(String.format("Failed to create partition %s of table %s", partitionSpec, tablePath), e);
    }
}
Also used : TException(org.apache.thrift.TException) CatalogTable(org.apache.flink.table.catalog.CatalogTable) SqlCreateHiveTable(org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable) Table(org.apache.hadoop.hive.metastore.api.Table) CatalogBaseTable(org.apache.flink.table.catalog.CatalogBaseTable) AlreadyExistsException(org.apache.hadoop.hive.metastore.api.AlreadyExistsException) PartitionAlreadyExistsException(org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException) CatalogException(org.apache.flink.table.catalog.exceptions.CatalogException) PartitionAlreadyExistsException(org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException)

Aggregations

SqlCreateHiveTable (org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable)1 CatalogBaseTable (org.apache.flink.table.catalog.CatalogBaseTable)1 CatalogTable (org.apache.flink.table.catalog.CatalogTable)1 CatalogException (org.apache.flink.table.catalog.exceptions.CatalogException)1 PartitionAlreadyExistsException (org.apache.flink.table.catalog.exceptions.PartitionAlreadyExistsException)1 AlreadyExistsException (org.apache.hadoop.hive.metastore.api.AlreadyExistsException)1 Table (org.apache.hadoop.hive.metastore.api.Table)1 TException (org.apache.thrift.TException)1