Search in sources :

Example 11 with GenericInMemoryCatalog

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

the class SqlToOperationConverterTest method testAlterDatabase.

@Test
public void testAlterDatabase() throws Exception {
    catalogManager.registerCatalog("cat1", new GenericInMemoryCatalog("default", "default"));
    catalogManager.getCatalog("cat1").get().createDatabase("db1", new CatalogDatabaseImpl(new HashMap<>(), "db1_comment"), true);
    final String sql = "alter database cat1.db1 set ('k1'='v1', 'K2'='V2')";
    Operation operation = parse(sql, SqlDialect.DEFAULT);
    assertThat(operation).isInstanceOf(AlterDatabaseOperation.class);
    Map<String, String> properties = new HashMap<>();
    properties.put("k1", "v1");
    properties.put("K2", "V2");
    AlterDatabaseOperation alterDatabaseOperation = (AlterDatabaseOperation) operation;
    assertThat(alterDatabaseOperation.getDatabaseName()).isEqualTo("db1");
    assertThat(alterDatabaseOperation.getCatalogName()).isEqualTo("cat1");
    assertThat(alterDatabaseOperation.getCatalogDatabase().getComment()).isEqualTo("db1_comment");
    assertThat(alterDatabaseOperation.getCatalogDatabase().getProperties()).isEqualTo(properties);
}
Also used : AlterDatabaseOperation(org.apache.flink.table.operations.ddl.AlterDatabaseOperation) HashMap(java.util.HashMap) OperationMatchers.isCreateTableOperation(org.apache.flink.table.planner.utils.OperationMatchers.isCreateTableOperation) DropDatabaseOperation(org.apache.flink.table.operations.ddl.DropDatabaseOperation) SinkModifyOperation(org.apache.flink.table.operations.SinkModifyOperation) AlterTableOptionsOperation(org.apache.flink.table.operations.ddl.AlterTableOptionsOperation) AlterTableDropConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableDropConstraintOperation) UseCatalogOperation(org.apache.flink.table.operations.UseCatalogOperation) UseDatabaseOperation(org.apache.flink.table.operations.UseDatabaseOperation) CreateViewOperation(org.apache.flink.table.operations.ddl.CreateViewOperation) ShowJarsOperation(org.apache.flink.table.operations.command.ShowJarsOperation) AlterDatabaseOperation(org.apache.flink.table.operations.ddl.AlterDatabaseOperation) QueryOperation(org.apache.flink.table.operations.QueryOperation) EndStatementSetOperation(org.apache.flink.table.operations.EndStatementSetOperation) UseModulesOperation(org.apache.flink.table.operations.UseModulesOperation) ShowFunctionsOperation(org.apache.flink.table.operations.ShowFunctionsOperation) CreateDatabaseOperation(org.apache.flink.table.operations.ddl.CreateDatabaseOperation) SetOperation(org.apache.flink.table.operations.command.SetOperation) LoadModuleOperation(org.apache.flink.table.operations.LoadModuleOperation) Operation(org.apache.flink.table.operations.Operation) ShowModulesOperation(org.apache.flink.table.operations.ShowModulesOperation) SourceQueryOperation(org.apache.flink.table.operations.SourceQueryOperation) UnloadModuleOperation(org.apache.flink.table.operations.UnloadModuleOperation) CreateTableOperation(org.apache.flink.table.operations.ddl.CreateTableOperation) RemoveJarOperation(org.apache.flink.table.operations.command.RemoveJarOperation) BeginStatementSetOperation(org.apache.flink.table.operations.BeginStatementSetOperation) AddJarOperation(org.apache.flink.table.operations.command.AddJarOperation) AlterTableAddConstraintOperation(org.apache.flink.table.operations.ddl.AlterTableAddConstraintOperation) ExplainOperation(org.apache.flink.table.operations.ExplainOperation) ResetOperation(org.apache.flink.table.operations.command.ResetOperation) StatementSetOperation(org.apache.flink.table.operations.StatementSetOperation) AlterTableRenameOperation(org.apache.flink.table.operations.ddl.AlterTableRenameOperation) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) CatalogDatabaseImpl(org.apache.flink.table.catalog.CatalogDatabaseImpl) Test(org.junit.Test)

Example 12 with GenericInMemoryCatalog

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

the class LookupKeySerdeTest method testLookupKey.

@Test
public void testLookupKey() throws IOException {
    TableConfig tableConfig = TableConfig.getDefault();
    ModuleManager moduleManager = new ModuleManager();
    CatalogManager catalogManager = CatalogManager.newBuilder().classLoader(Thread.currentThread().getContextClassLoader()).config(tableConfig.getConfiguration()).defaultCatalog("default_catalog", new GenericInMemoryCatalog("default_db")).build();
    FlinkContext flinkContext = new FlinkContextImpl(false, tableConfig, moduleManager, new FunctionCatalog(tableConfig, catalogManager, moduleManager), catalogManager, null);
    SerdeContext serdeCtx = new SerdeContext(null, flinkContext, Thread.currentThread().getContextClassLoader(), FlinkTypeFactory.INSTANCE(), FlinkSqlOperatorTable.instance());
    ObjectReader objectReader = JsonSerdeUtil.createObjectReader(serdeCtx);
    ObjectWriter objectWriter = JsonSerdeUtil.createObjectWriter(serdeCtx);
    LookupJoinUtil.LookupKey[] lookupKeys = new LookupJoinUtil.LookupKey[] { new LookupJoinUtil.ConstantLookupKey(new BigIntType(), new RexBuilder(FlinkTypeFactory.INSTANCE()).makeLiteral("a")), new LookupJoinUtil.FieldRefLookupKey(3) };
    for (LookupJoinUtil.LookupKey lookupKey : lookupKeys) {
        LookupJoinUtil.LookupKey result = objectReader.readValue(objectWriter.writeValueAsString(lookupKey), LookupJoinUtil.LookupKey.class);
        assertEquals(lookupKey, result);
    }
}
Also used : FunctionCatalog(org.apache.flink.table.catalog.FunctionCatalog) ObjectWriter(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectWriter) BigIntType(org.apache.flink.table.types.logical.BigIntType) ModuleManager(org.apache.flink.table.module.ModuleManager) FlinkContext(org.apache.flink.table.planner.calcite.FlinkContext) CatalogManager(org.apache.flink.table.catalog.CatalogManager) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) LookupJoinUtil(org.apache.flink.table.planner.plan.utils.LookupJoinUtil) FlinkContextImpl(org.apache.flink.table.planner.calcite.FlinkContextImpl) TableConfig(org.apache.flink.table.api.TableConfig) RexBuilder(org.apache.calcite.rex.RexBuilder) ObjectReader(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ObjectReader) Test(org.junit.Test)

Example 13 with GenericInMemoryCatalog

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

the class JavaCatalogTableTest method testResolvingSchemaOfCustomCatalogTableSql.

@Test
public void testResolvingSchemaOfCustomCatalogTableSql() throws Exception {
    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);
    tableEnvironment.executeSql("CREATE VIEW testTable2 AS SELECT * FROM testCatalog.`default`.testTable");
    testUtil.verifyExecPlan("SELECT COUNT(*) FROM testTable2 GROUP BY TUMBLE(rowtime, 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)

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