Search in sources :

Example 16 with Catalog

use of org.apache.flink.table.catalog.Catalog in project flink by apache.

the class HiveCatalogITCase method testCreateTableLike.

@Test
public void testCreateTableLike() throws Exception {
    TableEnvironment tableEnv = HiveTestUtils.createTableEnvInBatchMode();
    tableEnv.registerCatalog(hiveCatalog.getName(), hiveCatalog);
    tableEnv.useCatalog(hiveCatalog.getName());
    tableEnv.executeSql("create table generic_table (x int) with ('connector'='COLLECTION')");
    tableEnv.useCatalog(EnvironmentSettings.DEFAULT_BUILTIN_CATALOG);
    tableEnv.executeSql(String.format("create table copy like `%s`.`default`.generic_table", hiveCatalog.getName()));
    Catalog builtInCat = tableEnv.getCatalog(EnvironmentSettings.DEFAULT_BUILTIN_CATALOG).get();
    CatalogBaseTable catalogTable = builtInCat.getTable(new ObjectPath(EnvironmentSettings.DEFAULT_BUILTIN_DATABASE, "copy"));
    assertThat(catalogTable.getOptions()).hasSize(1);
    assertThat(catalogTable.getOptions()).containsEntry(FactoryUtil.CONNECTOR.key(), "COLLECTION");
    assertThat(catalogTable.getSchema().getFieldCount()).isEqualTo(1);
    assertThat(catalogTable.getSchema().getFieldNames()).hasSameElementsAs(Collections.singletonList("x"));
    assertThat(catalogTable.getSchema().getFieldDataTypes()).hasSameElementsAs(Collections.singletonList(DataTypes.INT()));
}
Also used : CatalogBaseTable(org.apache.flink.table.catalog.CatalogBaseTable) ObjectPath(org.apache.flink.table.catalog.ObjectPath) TableEnvironment(org.apache.flink.table.api.TableEnvironment) Catalog(org.apache.flink.table.catalog.Catalog) Test(org.junit.Test)

Example 17 with Catalog

use of org.apache.flink.table.catalog.Catalog in project flink by apache.

the class TableEnvironmentImpl method createCatalog.

private TableResultInternal createCatalog(CreateCatalogOperation operation) {
    String exMsg = getDDLOpExecuteErrorMsg(operation.asSummaryString());
    try {
        String catalogName = operation.getCatalogName();
        Map<String, String> properties = operation.getProperties();
        Catalog catalog = FactoryUtil.createCatalog(catalogName, properties, tableConfig.getConfiguration(), userClassLoader);
        catalogManager.registerCatalog(catalogName, catalog);
        return TableResultImpl.TABLE_RESULT_OK;
    } catch (CatalogException e) {
        throw new ValidationException(exMsg, e);
    }
}
Also used : ValidationException(org.apache.flink.table.api.ValidationException) CatalogException(org.apache.flink.table.catalog.exceptions.CatalogException) Catalog(org.apache.flink.table.catalog.Catalog) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) FunctionCatalog(org.apache.flink.table.catalog.FunctionCatalog)

Example 18 with Catalog

use of org.apache.flink.table.catalog.Catalog in project flink by apache.

the class TableEnvironmentImpl method createCatalogFunction.

private TableResultInternal createCatalogFunction(CreateCatalogFunctionOperation createCatalogFunctionOperation) {
    String exMsg = getDDLOpExecuteErrorMsg(createCatalogFunctionOperation.asSummaryString());
    try {
        if (createCatalogFunctionOperation.isTemporary()) {
            functionCatalog.registerTemporaryCatalogFunction(UnresolvedIdentifier.of(createCatalogFunctionOperation.getFunctionIdentifier().toList()), createCatalogFunctionOperation.getCatalogFunction(), createCatalogFunctionOperation.isIgnoreIfExists());
        } else {
            Catalog catalog = getCatalogOrThrowException(createCatalogFunctionOperation.getFunctionIdentifier().getCatalogName());
            catalog.createFunction(createCatalogFunctionOperation.getFunctionIdentifier().toObjectPath(), createCatalogFunctionOperation.getCatalogFunction(), createCatalogFunctionOperation.isIgnoreIfExists());
        }
        return TableResultImpl.TABLE_RESULT_OK;
    } catch (ValidationException e) {
        throw e;
    } catch (FunctionAlreadyExistException e) {
        throw new ValidationException(e.getMessage(), e);
    } catch (Exception e) {
        throw new TableException(exMsg, e);
    }
}
Also used : TableException(org.apache.flink.table.api.TableException) ValidationException(org.apache.flink.table.api.ValidationException) FunctionAlreadyExistException(org.apache.flink.table.catalog.exceptions.FunctionAlreadyExistException) 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 19 with Catalog

use of org.apache.flink.table.catalog.Catalog in project flink by apache.

the class TableEnvironmentImpl method dropCatalogFunction.

private TableResultInternal dropCatalogFunction(DropCatalogFunctionOperation dropCatalogFunctionOperation) {
    String exMsg = getDDLOpExecuteErrorMsg(dropCatalogFunctionOperation.asSummaryString());
    try {
        if (dropCatalogFunctionOperation.isTemporary()) {
            functionCatalog.dropTempCatalogFunction(dropCatalogFunctionOperation.getFunctionIdentifier(), dropCatalogFunctionOperation.isIfExists());
        } else {
            Catalog catalog = getCatalogOrThrowException(dropCatalogFunctionOperation.getFunctionIdentifier().getCatalogName());
            catalog.dropFunction(dropCatalogFunctionOperation.getFunctionIdentifier().toObjectPath(), dropCatalogFunctionOperation.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) 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 20 with Catalog

use of org.apache.flink.table.catalog.Catalog in project flink by apache.

the class FunctionITCase method testAlterFunction.

@Test
public void testAlterFunction() throws Exception {
    String create = "create function f3 as 'org.apache.flink.function.TestFunction'";
    String alter = "alter function f3 as 'org.apache.flink.function.TestFunction2'";
    ObjectPath objectPath = new ObjectPath("default_database", "f3");
    assertTrue(tEnv().getCatalog("default_catalog").isPresent());
    Catalog catalog = tEnv().getCatalog("default_catalog").get();
    tEnv().executeSql(create);
    CatalogFunction beforeUpdate = catalog.getFunction(objectPath);
    assertEquals("org.apache.flink.function.TestFunction", beforeUpdate.getClassName());
    tEnv().executeSql(alter);
    CatalogFunction afterUpdate = catalog.getFunction(objectPath);
    assertEquals("org.apache.flink.function.TestFunction2", afterUpdate.getClassName());
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CatalogFunction(org.apache.flink.table.catalog.CatalogFunction) Catalog(org.apache.flink.table.catalog.Catalog) Test(org.junit.Test)

Aggregations

Catalog (org.apache.flink.table.catalog.Catalog)23 HashMap (java.util.HashMap)10 ValidationException (org.apache.flink.table.api.ValidationException)10 Test (org.junit.Test)9 TableNotExistException (org.apache.flink.table.catalog.exceptions.TableNotExistException)8 GenericInMemoryCatalog (org.apache.flink.table.catalog.GenericInMemoryCatalog)7 ObjectPath (org.apache.flink.table.catalog.ObjectPath)7 TableException (org.apache.flink.table.api.TableException)6 FunctionCatalog (org.apache.flink.table.catalog.FunctionCatalog)6 CatalogException (org.apache.flink.table.catalog.exceptions.CatalogException)6 DatabaseNotExistException (org.apache.flink.table.catalog.exceptions.DatabaseNotExistException)6 HiveCatalog (org.apache.flink.table.catalog.hive.HiveCatalog)6 CatalogTable (org.apache.flink.table.catalog.CatalogTable)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ExecutionException (java.util.concurrent.ExecutionException)4 SqlParserException (org.apache.flink.table.api.SqlParserException)4 DatabaseAlreadyExistException (org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException)4 DatabaseNotEmptyException (org.apache.flink.table.catalog.exceptions.DatabaseNotEmptyException)4