use of org.apache.flink.table.catalog.exceptions.TableNotExistException in project flink by apache.
the class HiveCatalogITCase method testTableWithPrimaryKey.
@Test
public void testTableWithPrimaryKey() {
TableEnvironment tableEnv = TableEnvironment.create(EnvironmentSettings.inStreamingMode());
tableEnv.getConfig().getConfiguration().setInteger(TABLE_EXEC_RESOURCE_DEFAULT_PARALLELISM, 1);
tableEnv.registerCatalog("catalog1", hiveCatalog);
tableEnv.useCatalog("catalog1");
final String createTable = "CREATE TABLE pk_src (\n" + " uuid varchar(40) not null,\n" + " price DECIMAL(10, 2),\n" + " currency STRING,\n" + " ts6 TIMESTAMP(6),\n" + " ts AS CAST(ts6 AS TIMESTAMP(3)),\n" + " WATERMARK FOR ts AS ts,\n" + " constraint ct1 PRIMARY KEY(uuid) NOT ENFORCED)\n" + " WITH (\n" + " 'connector.type' = 'filesystem'," + " 'connector.path' = 'file://fakePath'," + " 'format.type' = 'csv')";
tableEnv.executeSql(createTable);
TableSchema tableSchema = tableEnv.getCatalog(tableEnv.getCurrentCatalog()).map(catalog -> {
try {
final ObjectPath tablePath = ObjectPath.fromString(catalog.getDefaultDatabase() + '.' + "pk_src");
return catalog.getTable(tablePath).getSchema();
} catch (TableNotExistException e) {
return null;
}
}).orElse(null);
assertThat(tableSchema).isNotNull();
assertThat(tableSchema.getPrimaryKey()).hasValue(UniqueConstraint.primaryKey("ct1", Collections.singletonList("uuid")));
tableEnv.executeSql("DROP TABLE pk_src");
}
use of org.apache.flink.table.catalog.exceptions.TableNotExistException in project flink by apache.
the class HiveCatalog method getPartitionColumnStatistics.
@Override
public CatalogColumnStatistics getPartitionColumnStatistics(ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws PartitionNotExistException, CatalogException {
try {
Partition partition = getHivePartition(tablePath, partitionSpec);
Table hiveTable = getHiveTable(tablePath);
String partName = getEscapedPartitionName(tablePath, partitionSpec, hiveTable);
List<String> partNames = new ArrayList<>();
partNames.add(partName);
Map<String, List<ColumnStatisticsObj>> partitionColumnStatistics = client.getPartitionColumnStatistics(partition.getDbName(), partition.getTableName(), partNames, getFieldNames(partition.getSd().getCols()));
List<ColumnStatisticsObj> columnStatisticsObjs = partitionColumnStatistics.get(partName);
if (columnStatisticsObjs != null && !columnStatisticsObjs.isEmpty()) {
return new CatalogColumnStatistics(HiveStatsUtil.createCatalogColumnStats(columnStatisticsObjs, hiveVersion));
} else {
return CatalogColumnStatistics.UNKNOWN;
}
} catch (TableNotExistException | PartitionSpecInvalidException e) {
throw new PartitionNotExistException(getName(), tablePath, partitionSpec);
} catch (TException e) {
throw new CatalogException(String.format("Failed to get table stats of table %s 's partition %s", tablePath.getFullName(), String.valueOf(partitionSpec)), e);
}
}
use of org.apache.flink.table.catalog.exceptions.TableNotExistException in project flink by apache.
the class HiveCatalog method getPartition.
@Override
public CatalogPartition getPartition(ObjectPath tablePath, CatalogPartitionSpec partitionSpec) throws PartitionNotExistException, CatalogException {
checkNotNull(tablePath, "Table path cannot be null");
checkNotNull(partitionSpec, "CatalogPartitionSpec cannot be null");
try {
Partition hivePartition = getHivePartition(tablePath, partitionSpec);
Map<String, String> properties = hivePartition.getParameters();
properties.put(SqlCreateHiveTable.TABLE_LOCATION_URI, hivePartition.getSd().getLocation());
String comment = properties.remove(HiveCatalogConfig.COMMENT);
return new CatalogPartitionImpl(properties, comment);
} catch (NoSuchObjectException | MetaException | TableNotExistException | PartitionSpecInvalidException e) {
throw new PartitionNotExistException(getName(), tablePath, partitionSpec, e);
} catch (TException e) {
throw new CatalogException(String.format("Failed to get partition %s of table %s", partitionSpec, tablePath), e);
}
}
use of org.apache.flink.table.catalog.exceptions.TableNotExistException in project flink by apache.
the class HiveCatalog method alterPartitionColumnStatistics.
@Override
public void alterPartitionColumnStatistics(ObjectPath tablePath, CatalogPartitionSpec partitionSpec, CatalogColumnStatistics columnStatistics, boolean ignoreIfNotExists) throws PartitionNotExistException, CatalogException {
try {
Partition hivePartition = getHivePartition(tablePath, partitionSpec);
Table hiveTable = getHiveTable(tablePath);
String partName = getEscapedPartitionName(tablePath, partitionSpec, hiveTable);
client.updatePartitionColumnStatistics(HiveStatsUtil.createPartitionColumnStats(hivePartition, partName, columnStatistics.getColumnStatisticsData(), hiveVersion));
} catch (TableNotExistException | PartitionSpecInvalidException e) {
if (!ignoreIfNotExists) {
throw new PartitionNotExistException(getName(), tablePath, partitionSpec, e);
}
} catch (TException e) {
throw new CatalogException(String.format("Failed to alter table column stats of table %s 's partition %s", tablePath.getFullName(), String.valueOf(partitionSpec)), e);
}
}
use of org.apache.flink.table.catalog.exceptions.TableNotExistException in project flink by apache.
the class HiveCatalog method partitionExists.
// ------ partitions ------
@Override
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);
}
}
Aggregations