Search in sources :

Example 71 with ObjectPath

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

the class MySqlCatalogITCase method testGetTables_TableNotExistException.

@Test
public void testGetTables_TableNotExistException() throws TableNotExistException {
    String anyTableNotExist = "anyTable";
    assertThatThrownBy(() -> catalog.getTable(new ObjectPath(TEST_DB, anyTableNotExist))).satisfies(anyCauseMatches(TableNotExistException.class, String.format("Table (or view) %s.%s does not exist in Catalog", TEST_DB, anyTableNotExist)));
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) TableNotExistException(org.apache.flink.table.catalog.exceptions.TableNotExistException) Test(org.junit.Test)

Example 72 with ObjectPath

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

the class TableEnvironmentTest method testCreateTableFromDescriptor.

@Test
public void testCreateTableFromDescriptor() throws Exception {
    final TableEnvironmentMock tEnv = TableEnvironmentMock.getStreamingInstance();
    final String catalog = tEnv.getCurrentCatalog();
    final String database = tEnv.getCurrentDatabase();
    final Schema schema = Schema.newBuilder().column("f0", DataTypes.INT()).build();
    tEnv.createTable("T", TableDescriptor.forConnector("fake").schema(schema).option("a", "Test").build());
    final ObjectPath objectPath = new ObjectPath(database, "T");
    assertThat(tEnv.getCatalog(catalog).orElseThrow(AssertionError::new).tableExists(objectPath)).isTrue();
    final CatalogBaseTable catalogTable = tEnv.getCatalog(catalog).orElseThrow(AssertionError::new).getTable(objectPath);
    assertThat(catalogTable).isInstanceOf(CatalogTable.class);
    assertThat(catalogTable.getUnresolvedSchema()).isEqualTo(schema);
    assertThat(catalogTable.getOptions()).contains(entry("connector", "fake"), entry("a", "Test"));
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) CatalogBaseTable(org.apache.flink.table.catalog.CatalogBaseTable) TableEnvironmentMock(org.apache.flink.table.utils.TableEnvironmentMock) Test(org.junit.jupiter.api.Test)

Example 73 with ObjectPath

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

the class SqlToOperationConverterTest method after.

@After
public void after() throws TableNotExistException {
    final ObjectPath path1 = new ObjectPath(catalogManager.getCurrentDatabase(), "t1");
    final ObjectPath path2 = new ObjectPath(catalogManager.getCurrentDatabase(), "t2");
    catalog.dropTable(path1, true);
    catalog.dropTable(path2, true);
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) After(org.junit.After)

Example 74 with ObjectPath

use of org.apache.flink.table.catalog.ObjectPath 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)

Example 75 with ObjectPath

use of org.apache.flink.table.catalog.ObjectPath 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)

Aggregations

ObjectPath (org.apache.flink.table.catalog.ObjectPath)81 Test (org.junit.Test)52 CatalogBaseTable (org.apache.flink.table.catalog.CatalogBaseTable)32 CatalogTable (org.apache.flink.table.catalog.CatalogTable)29 HashMap (java.util.HashMap)21 CatalogTableImpl (org.apache.flink.table.catalog.CatalogTableImpl)20 TableSchema (org.apache.flink.table.api.TableSchema)19 TableEnvironment (org.apache.flink.table.api.TableEnvironment)17 CatalogPartitionSpec (org.apache.flink.table.catalog.CatalogPartitionSpec)12 Table (org.apache.hadoop.hive.metastore.api.Table)12 Configuration (org.apache.flink.configuration.Configuration)11 SqlCreateHiveTable (org.apache.flink.sql.parser.hive.ddl.SqlCreateHiveTable)11 TableNotExistException (org.apache.flink.table.catalog.exceptions.TableNotExistException)9 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 GenericInMemoryCatalog (org.apache.flink.table.catalog.GenericInMemoryCatalog)8 LinkedHashMap (java.util.LinkedHashMap)7 Catalog (org.apache.flink.table.catalog.Catalog)7 ContextResolvedTable (org.apache.flink.table.catalog.ContextResolvedTable)6 ObjectIdentifier (org.apache.flink.table.catalog.ObjectIdentifier)6