Search in sources :

Example 6 with GenericInMemoryCatalog

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

the class JavaCatalogTableTest method testResolvingProctimeOfCustomTableSql.

@Test
public void testResolvingProctimeOfCustomTableSql() throws Exception {
    if (!isStreamingMode) {
        // proctime not supported in batch
        return;
    }
    TableTestUtil testUtil = getTestUtil();
    TableEnvironment tableEnvironment = testUtil.getTableEnv();
    GenericInMemoryCatalog genericInMemoryCatalog = new GenericInMemoryCatalog("in-memory");
    genericInMemoryCatalog.createTable(new ObjectPath("default", "testTable"), new CustomCatalogTable(isStreamingMode), false);
    tableEnvironment.registerCatalog("testCatalog", genericInMemoryCatalog);
    testUtil.verifyExecPlan("SELECT COUNT(*) FROM testCatalog.`default`.testTable " + "GROUP BY TUMBLE(proctime, INTERVAL '10' MINUTE)");
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) TableTestUtil(org.apache.flink.table.planner.utils.TableTestUtil) TableEnvironment(org.apache.flink.table.api.TableEnvironment) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) Test(org.junit.Test)

Example 7 with GenericInMemoryCatalog

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

the class CatalogITCase method testCreateCatalog.

@Test
public void testCreateCatalog() {
    String name = "c1";
    TableEnvironment tableEnv = getTableEnvironment();
    String ddl = String.format("create catalog %s with('type'='%s')", name, GenericInMemoryCatalogFactoryOptions.IDENTIFIER);
    tableEnv.executeSql(ddl);
    assertTrue(tableEnv.getCatalog(name).isPresent());
    assertTrue(tableEnv.getCatalog(name).get() instanceof GenericInMemoryCatalog);
}
Also used : TableEnvironment(org.apache.flink.table.api.TableEnvironment) StreamTableEnvironment(org.apache.flink.table.api.bridge.java.StreamTableEnvironment) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) Test(org.junit.Test)

Example 8 with GenericInMemoryCatalog

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

the class CatalogITCase method testGetTablesFromGivenCatalogDatabase.

@Test
public void testGetTablesFromGivenCatalogDatabase() throws Exception {
    final Catalog c1 = new GenericInMemoryCatalog("c1", "default");
    final Catalog c2 = new GenericInMemoryCatalog("c2", "d2");
    final CatalogManager catalogManager = CatalogManagerMocks.preparedCatalogManager().defaultCatalog("c2", c2).build();
    catalogManager.registerCatalog("c1", c1);
    final CatalogTable catalogTable = CatalogTable.of(Schema.newBuilder().build(), null, new ArrayList<>(), new HashMap<>());
    c1.createDatabase("d1", new CatalogDatabaseImpl(new HashMap<>(), null), true);
    c1.createTable(new ObjectPath("d1", "t1"), catalogTable, true);
    c2.createTable(new ObjectPath(catalogManager.getCurrentDatabase(), "t2"), catalogTable, true);
    assertThat(catalogManager.getCurrentCatalog()).isEqualTo("c2");
    assertThat(catalogManager.getCurrentDatabase()).isEqualTo("d2");
    assertThat(catalogManager.listTables()).containsExactlyInAnyOrder("t2");
    assertThat(catalogManager.listTables("c1", "d1")).containsExactlyInAnyOrder("t1");
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) HashMap(java.util.HashMap) CatalogTable(org.apache.flink.table.catalog.CatalogTable) Catalog(org.apache.flink.table.catalog.Catalog) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) CatalogManager(org.apache.flink.table.catalog.CatalogManager) CatalogDatabaseImpl(org.apache.flink.table.catalog.CatalogDatabaseImpl) Test(org.junit.Test)

Example 9 with GenericInMemoryCatalog

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

the class TableEnvironmentImpl method create.

private static TableEnvironmentImpl create(EnvironmentSettings settings, Configuration configuration) {
    // temporary solution until FLINK-15635 is fixed
    final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    // use configuration to init table config
    final TableConfig tableConfig = new TableConfig();
    tableConfig.addConfiguration(configuration);
    final ModuleManager moduleManager = new ModuleManager();
    final CatalogManager catalogManager = CatalogManager.newBuilder().classLoader(classLoader).config(tableConfig.getConfiguration()).defaultCatalog(settings.getBuiltInCatalogName(), new GenericInMemoryCatalog(settings.getBuiltInCatalogName(), settings.getBuiltInDatabaseName())).build();
    final FunctionCatalog functionCatalog = new FunctionCatalog(tableConfig, catalogManager, moduleManager);
    final ExecutorFactory executorFactory = FactoryUtil.discoverFactory(classLoader, ExecutorFactory.class, settings.getExecutor());
    final Executor executor = executorFactory.create(configuration);
    final Planner planner = PlannerFactoryUtil.createPlanner(settings.getPlanner(), executor, tableConfig, moduleManager, catalogManager, functionCatalog);
    return new TableEnvironmentImpl(catalogManager, moduleManager, tableConfig, executor, functionCatalog, planner, settings.isStreamingMode(), classLoader);
}
Also used : FunctionCatalog(org.apache.flink.table.catalog.FunctionCatalog) Executor(org.apache.flink.table.delegation.Executor) ExecutorFactory(org.apache.flink.table.delegation.ExecutorFactory) TableConfig(org.apache.flink.table.api.TableConfig) Planner(org.apache.flink.table.delegation.Planner) ModuleManager(org.apache.flink.table.module.ModuleManager) CatalogManager(org.apache.flink.table.catalog.CatalogManager) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog)

Example 10 with GenericInMemoryCatalog

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

the class StreamTableEnvironmentImpl method create.

public static StreamTableEnvironment create(StreamExecutionEnvironment executionEnvironment, EnvironmentSettings settings, TableConfig tableConfig) {
    // temporary solution until FLINK-15635 is fixed
    final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
    final ModuleManager moduleManager = new ModuleManager();
    final CatalogManager catalogManager = CatalogManager.newBuilder().classLoader(classLoader).config(tableConfig.getConfiguration()).defaultCatalog(settings.getBuiltInCatalogName(), new GenericInMemoryCatalog(settings.getBuiltInCatalogName(), settings.getBuiltInDatabaseName())).executionConfig(executionEnvironment.getConfig()).build();
    final FunctionCatalog functionCatalog = new FunctionCatalog(tableConfig, catalogManager, moduleManager);
    final Executor executor = lookupExecutor(classLoader, settings.getExecutor(), executionEnvironment);
    final Planner planner = PlannerFactoryUtil.createPlanner(settings.getPlanner(), executor, tableConfig, moduleManager, catalogManager, functionCatalog);
    return new StreamTableEnvironmentImpl(catalogManager, moduleManager, functionCatalog, tableConfig, executionEnvironment, planner, executor, settings.isStreamingMode(), classLoader);
}
Also used : FunctionCatalog(org.apache.flink.table.catalog.FunctionCatalog) Executor(org.apache.flink.table.delegation.Executor) Planner(org.apache.flink.table.delegation.Planner) ModuleManager(org.apache.flink.table.module.ModuleManager) AbstractStreamTableEnvironmentImpl(org.apache.flink.table.api.bridge.internal.AbstractStreamTableEnvironmentImpl) CatalogManager(org.apache.flink.table.catalog.CatalogManager) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog)

Aggregations

GenericInMemoryCatalog (org.apache.flink.table.catalog.GenericInMemoryCatalog)13 Test (org.junit.Test)8 ObjectPath (org.apache.flink.table.catalog.ObjectPath)6 TableEnvironment (org.apache.flink.table.api.TableEnvironment)5 CatalogManager (org.apache.flink.table.catalog.CatalogManager)5 FunctionCatalog (org.apache.flink.table.catalog.FunctionCatalog)5 CatalogTable (org.apache.flink.table.catalog.CatalogTable)4 ModuleManager (org.apache.flink.table.module.ModuleManager)4 HashMap (java.util.HashMap)3 CatalogDatabaseImpl (org.apache.flink.table.catalog.CatalogDatabaseImpl)3 TableTestUtil (org.apache.flink.table.planner.utils.TableTestUtil)3 Configuration (org.apache.flink.configuration.Configuration)2 Table (org.apache.flink.table.api.Table)2 TableConfig (org.apache.flink.table.api.TableConfig)2 Catalog (org.apache.flink.table.catalog.Catalog)2 CatalogBaseTable (org.apache.flink.table.catalog.CatalogBaseTable)2 Executor (org.apache.flink.table.delegation.Executor)2 Planner (org.apache.flink.table.delegation.Planner)2 URLClassLoader (java.net.URLClassLoader)1 CalciteSchemaBuilder.asRootSchema (org.apache.calcite.jdbc.CalciteSchemaBuilder.asRootSchema)1