Search in sources :

Example 26 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class TableEnvironmentImpl method registerTableSourceInternal.

@Override
public void registerTableSourceInternal(String name, TableSource<?> tableSource) {
    validateTableSource(tableSource);
    ObjectIdentifier objectIdentifier = catalogManager.qualifyIdentifier(UnresolvedIdentifier.of(name));
    Optional<CatalogBaseTable> table = getTemporaryTable(objectIdentifier);
    if (table.isPresent()) {
        if (table.get() instanceof ConnectorCatalogTable<?, ?>) {
            ConnectorCatalogTable<?, ?> sourceSinkTable = (ConnectorCatalogTable<?, ?>) table.get();
            if (sourceSinkTable.getTableSource().isPresent()) {
                throw new ValidationException(String.format("Table '%s' already exists. Please choose a different name.", name));
            } else {
                // wrapper contains only sink (not source)
                ConnectorCatalogTable sourceAndSink = ConnectorCatalogTable.sourceAndSink(tableSource, sourceSinkTable.getTableSink().get(), !IS_STREAM_TABLE);
                catalogManager.dropTemporaryTable(objectIdentifier, false);
                catalogManager.createTemporaryTable(sourceAndSink, objectIdentifier, false);
            }
        } else {
            throw new ValidationException(String.format("Table '%s' already exists. Please choose a different name.", name));
        }
    } else {
        ConnectorCatalogTable source = ConnectorCatalogTable.source(tableSource, !IS_STREAM_TABLE);
        catalogManager.createTemporaryTable(source, objectIdentifier, false);
    }
}
Also used : CatalogBaseTable(org.apache.flink.table.catalog.CatalogBaseTable) ValidationException(org.apache.flink.table.api.ValidationException) ConnectorCatalogTable(org.apache.flink.table.catalog.ConnectorCatalogTable) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Example 27 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class TableEnvironmentImpl method alterCatalogFunction.

private TableResultInternal alterCatalogFunction(AlterCatalogFunctionOperation alterCatalogFunctionOperation) {
    String exMsg = getDDLOpExecuteErrorMsg(alterCatalogFunctionOperation.asSummaryString());
    try {
        CatalogFunction function = alterCatalogFunctionOperation.getCatalogFunction();
        if (alterCatalogFunctionOperation.isTemporary()) {
            throw new ValidationException("Alter temporary catalog function is not supported");
        } else {
            Catalog catalog = getCatalogOrThrowException(alterCatalogFunctionOperation.getFunctionIdentifier().getCatalogName());
            catalog.alterFunction(alterCatalogFunctionOperation.getFunctionIdentifier().toObjectPath(), function, alterCatalogFunctionOperation.isIfExists());
        }
        return TableResultImpl.TABLE_RESULT_OK;
    } catch (ValidationException e) {
        throw e;
    } catch (FunctionNotExistException e) {
        throw new ValidationException(e.getMessage(), e);
    } catch (Exception e) {
        throw new TableException(exMsg, e);
    }
}
Also used : FunctionNotExistException(org.apache.flink.table.catalog.exceptions.FunctionNotExistException) TableException(org.apache.flink.table.api.TableException) ValidationException(org.apache.flink.table.api.ValidationException) CatalogFunction(org.apache.flink.table.catalog.CatalogFunction) Catalog(org.apache.flink.table.catalog.Catalog) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) FunctionCatalog(org.apache.flink.table.catalog.FunctionCatalog) FunctionAlreadyExistException(org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException) DatabaseNotExistException(org.apache.flink.table.catalog.exceptions.DatabaseNotExistException) TableAlreadyExistException(org.apache.flink.table.catalog.exceptions.TableAlreadyExistException) TableException(org.apache.flink.table.api.TableException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) CatalogException(org.apache.flink.table.catalog.exceptions.CatalogException) FunctionNotExistException(org.apache.flink.table.catalog.exceptions.FunctionNotExistException) DatabaseNotEmptyException(org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException) DatabaseAlreadyExistException(org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException) SqlParserException(org.apache.flink.table.api.SqlParserException) ValidationException(org.apache.flink.table.api.ValidationException) TableNotExistException(org.apache.flink.table.catalog.exceptions.TableNotExistException)

Example 28 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class TableEnvironmentImpl method dropTemporaryTable.

@Override
public boolean dropTemporaryTable(String path) {
    UnresolvedIdentifier unresolvedIdentifier = getParser().parseIdentifier(path);
    ObjectIdentifier identifier = catalogManager.qualifyIdentifier(unresolvedIdentifier);
    try {
        catalogManager.dropTemporaryTable(identifier, false);
        return true;
    } catch (ValidationException e) {
        return false;
    }
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) UnresolvedIdentifier(org.apache.flink.table.catalog.UnresolvedIdentifier) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Example 29 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class CatalogManager method dropTemporaryTableInternal.

private void dropTemporaryTableInternal(ObjectIdentifier objectIdentifier, Predicate<CatalogBaseTable> filter, boolean ignoreIfNotExists) {
    CatalogBaseTable catalogBaseTable = temporaryTables.get(objectIdentifier);
    if (filter.test(catalogBaseTable)) {
        getTemporaryOperationListener(objectIdentifier).ifPresent(l -> l.onDropTemporaryTable(objectIdentifier.toObjectPath()));
        Catalog catalog = catalogs.get(objectIdentifier.getCatalogName());
        ResolvedCatalogBaseTable<?> resolvedTable = resolveCatalogBaseTable(catalogBaseTable);
        managedTableListener.notifyTableDrop(catalog, objectIdentifier, resolvedTable, true, ignoreIfNotExists);
        temporaryTables.remove(objectIdentifier);
    } else if (!ignoreIfNotExists) {
        throw new ValidationException(String.format("Temporary table or view with identifier '%s' does not exist.", objectIdentifier.asSummaryString()));
    }
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException)

Example 30 with ValidationException

use of org.apache.flink.table.api.ValidationException in project flink by apache.

the class DefaultSchemaResolver method adjustRowtimeAttribute.

private Column adjustRowtimeAttribute(List<WatermarkSpec> watermarkSpecs, Column column) {
    final String name = column.getName();
    final DataType dataType = column.getDataType();
    final boolean hasWatermarkSpec = watermarkSpecs.stream().anyMatch(s -> s.getRowtimeAttribute().equals(name));
    if (hasWatermarkSpec && isStreamingMode) {
        switch(dataType.getLogicalType().getTypeRoot()) {
            case TIMESTAMP_WITHOUT_TIME_ZONE:
                final TimestampType originalType = (TimestampType) dataType.getLogicalType();
                final LogicalType rowtimeType = new TimestampType(originalType.isNullable(), TimestampKind.ROWTIME, originalType.getPrecision());
                return column.copy(replaceLogicalType(dataType, rowtimeType));
            case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
                final LocalZonedTimestampType timestampLtzType = (LocalZonedTimestampType) dataType.getLogicalType();
                final LogicalType rowtimeLtzType = new LocalZonedTimestampType(timestampLtzType.isNullable(), TimestampKind.ROWTIME, timestampLtzType.getPrecision());
                return column.copy(replaceLogicalType(dataType, rowtimeLtzType));
            default:
                throw new ValidationException("Invalid data type of expression for rowtime definition. " + "The field must be of type TIMESTAMP(p) or TIMESTAMP_LTZ(p)," + " the supported precision 'p' is from 0 to 3.");
        }
    }
    return column;
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) DataType(org.apache.flink.table.types.DataType) TimestampType(org.apache.flink.table.types.logical.TimestampType) LocalZonedTimestampType(org.apache.flink.table.types.logical.LocalZonedTimestampType) DataTypeUtils.replaceLogicalType(org.apache.flink.table.types.utils.DataTypeUtils.replaceLogicalType) LogicalType(org.apache.flink.table.types.logical.LogicalType)

Aggregations

ValidationException (org.apache.flink.table.api.ValidationException)143 DataType (org.apache.flink.table.types.DataType)25 Test (org.junit.Test)23 HashMap (java.util.HashMap)21 ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)19 LogicalType (org.apache.flink.table.types.logical.LogicalType)18 TableException (org.apache.flink.table.api.TableException)17 List (java.util.List)14 CatalogBaseTable (org.apache.flink.table.catalog.CatalogBaseTable)14 QueryOperation (org.apache.flink.table.operations.QueryOperation)14 LinkedHashMap (java.util.LinkedHashMap)13 DescriptorProperties (org.apache.flink.table.descriptors.DescriptorProperties)13 CatalogTable (org.apache.flink.table.catalog.CatalogTable)12 Expression (org.apache.flink.table.expressions.Expression)12 TableSchema (org.apache.flink.table.api.TableSchema)11 Catalog (org.apache.flink.table.catalog.Catalog)11 ContextResolvedTable (org.apache.flink.table.catalog.ContextResolvedTable)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 Internal (org.apache.flink.annotation.Internal)10