Search in sources :

Example 21 with TableNotExistException

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

the class GenericInMemoryCatalog method getTableColumnStatistics.

@Override
public CatalogColumnStatistics getTableColumnStatistics(ObjectPath tablePath) throws TableNotExistException {
    checkNotNull(tablePath);
    if (!tableExists(tablePath)) {
        throw new TableNotExistException(getName(), tablePath);
    }
    CatalogColumnStatistics result = tableColumnStats.get(tablePath);
    return result != null ? result.copy() : CatalogColumnStatistics.UNKNOWN;
}
Also used : TableNotExistException(org.apache.flink.table.catalog.exceptions.TableNotExistException) CatalogColumnStatistics(org.apache.flink.table.catalog.stats.CatalogColumnStatistics)

Example 22 with TableNotExistException

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

the class GenericInMemoryCatalog method alterTableStatistics.

@Override
public void alterTableStatistics(ObjectPath tablePath, CatalogTableStatistics tableStatistics, boolean ignoreIfNotExists) throws TableNotExistException {
    checkNotNull(tablePath);
    checkNotNull(tableStatistics);
    if (tableExists(tablePath)) {
        tableStats.put(tablePath, tableStatistics.copy());
    } else if (!ignoreIfNotExists) {
        throw new TableNotExistException(getName(), tablePath);
    }
}
Also used : TableNotExistException(org.apache.flink.table.catalog.exceptions.TableNotExistException)

Example 23 with TableNotExistException

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

the class GenericInMemoryCatalog method dropTable.

// ------ tables and views ------
@Override
public void dropTable(ObjectPath tablePath, boolean ignoreIfNotExists) throws TableNotExistException {
    checkNotNull(tablePath);
    if (tableExists(tablePath)) {
        tables.remove(tablePath);
        tableStats.remove(tablePath);
        tableColumnStats.remove(tablePath);
        partitions.remove(tablePath);
        partitionStats.remove(tablePath);
        partitionColumnStats.remove(tablePath);
    } else if (!ignoreIfNotExists) {
        throw new TableNotExistException(getName(), tablePath);
    }
}
Also used : TableNotExistException(org.apache.flink.table.catalog.exceptions.TableNotExistException)

Example 24 with TableNotExistException

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

the class DatabaseCalciteSchema method extractTableStats.

private TableStats extractTableStats(ContextResolvedTable lookupResult, ObjectIdentifier identifier) {
    if (lookupResult.isTemporary()) {
        return TableStats.UNKNOWN;
    }
    final Catalog catalog = lookupResult.getCatalog().orElseThrow(IllegalStateException::new);
    final ObjectPath tablePath = identifier.toObjectPath();
    try {
        final CatalogTableStatistics tableStatistics = catalog.getTableStatistics(tablePath);
        final CatalogColumnStatistics columnStatistics = catalog.getTableColumnStatistics(tablePath);
        return convertToTableStats(tableStatistics, columnStatistics);
    } catch (TableNotExistException e) {
        throw new ValidationException(format("Could not get statistic for table: [%s, %s, %s]", identifier.getCatalogName(), tablePath.getDatabaseName(), tablePath.getObjectName()), e);
    }
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) ValidationException(org.apache.flink.table.api.ValidationException) TableNotExistException(org.apache.flink.table.catalog.exceptions.TableNotExistException) Catalog(org.apache.flink.table.catalog.Catalog) CatalogColumnStatistics(org.apache.flink.table.catalog.stats.CatalogColumnStatistics) CatalogTableStatistics(org.apache.flink.table.catalog.stats.CatalogTableStatistics)

Example 25 with TableNotExistException

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

the class TestValuesCatalog method listPartitionsByFilter.

@Override
public List<CatalogPartitionSpec> listPartitionsByFilter(ObjectPath tablePath, List<Expression> filters) throws TableNotExistException, TableNotPartitionedException, CatalogException {
    if (!supportListPartitionByFilter) {
        throw new UnsupportedOperationException("TestValuesCatalog doesn't support list partition by filters");
    }
    List<CatalogPartitionSpec> partitions = listPartitions(tablePath);
    if (partitions.isEmpty()) {
        return partitions;
    }
    CatalogBaseTable table = this.getTable(tablePath);
    TableSchema schema = table.getSchema();
    List<ResolvedExpression> resolvedExpressions = filters.stream().map(filter -> {
        if (filter instanceof ResolvedExpression) {
            return (ResolvedExpression) filter;
        }
        throw new UnsupportedOperationException(String.format("TestValuesCatalog only works with resolved expressions. Get unresolved expression: %s", filter));
    }).collect(Collectors.toList());
    return partitions.stream().filter(partition -> {
        Function<String, Comparable<?>> getter = getValueGetter(partition.getPartitionSpec(), schema);
        return FilterUtils.isRetainedAfterApplyingFilterPredicates(resolvedExpressions, getter);
    }).collect(Collectors.toList());
}
Also used : DataType(org.apache.flink.table.types.DataType) TableNotExistException(org.apache.flink.table.catalog.exceptions.TableNotExistException) FilterUtils(org.apache.flink.table.planner.utils.FilterUtils) IntType(org.apache.flink.table.types.logical.IntType) TableException(org.apache.flink.table.api.TableException) TableSchema(org.apache.flink.table.api.TableSchema) VarCharType(org.apache.flink.table.types.logical.VarCharType) CatalogBaseTable(org.apache.flink.table.catalog.CatalogBaseTable) Expression(org.apache.flink.table.expressions.Expression) ObjectPath(org.apache.flink.table.catalog.ObjectPath) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) CharType(org.apache.flink.table.types.logical.CharType) CatalogPartitionSpec(org.apache.flink.table.catalog.CatalogPartitionSpec) List(java.util.List) TableNotPartitionedException(org.apache.flink.table.catalog.exceptions.TableNotPartitionedException) DoubleType(org.apache.flink.table.types.logical.DoubleType) LogicalType(org.apache.flink.table.types.logical.LogicalType) BooleanType(org.apache.flink.table.types.logical.BooleanType) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) Map(java.util.Map) Optional(java.util.Optional) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) CatalogException(org.apache.flink.table.catalog.exceptions.CatalogException) Function(java.util.function.Function) CatalogBaseTable(org.apache.flink.table.catalog.CatalogBaseTable) TableSchema(org.apache.flink.table.api.TableSchema) ResolvedExpression(org.apache.flink.table.expressions.ResolvedExpression) CatalogPartitionSpec(org.apache.flink.table.catalog.CatalogPartitionSpec)

Aggregations

TableNotExistException (org.apache.flink.table.catalog.exceptions.TableNotExistException)25 CatalogException (org.apache.flink.table.catalog.exceptions.CatalogException)15 TException (org.apache.thrift.TException)11 CatalogBaseTable (org.apache.flink.table.catalog.CatalogBaseTable)10 CatalogTable (org.apache.flink.table.catalog.CatalogTable)10 SqlCreateHiveTable (org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable)8 PartitionSpecInvalidException (org.apache.flink.table.catalog.exceptions.PartitionSpecInvalidException)8 Table (org.apache.hadoop.hive.metastore.api.Table)8 ObjectPath (org.apache.flink.table.catalog.ObjectPath)7 PartitionNotExistException (org.apache.flink.table.catalog.exceptions.PartitionNotExistException)7 CatalogPartition (org.apache.flink.table.catalog.CatalogPartition)6 List (java.util.List)5 NoSuchObjectException (org.apache.hadoop.hive.metastore.api.NoSuchObjectException)5 ArrayList (java.util.ArrayList)4 Catalog (org.apache.flink.table.catalog.Catalog)4 Partition (org.apache.hadoop.hive.metastore.api.Partition)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TableException (org.apache.flink.table.api.TableException)3 TableSchema (org.apache.flink.table.api.TableSchema)3