Search in sources :

Example 1 with GenericInMemoryCatalog

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

the class SimpleCatalogFactory method createCatalog.

@Override
public Catalog createCatalog(Context context) {
    final Configuration configuration = Configuration.fromMap(context.getOptions());
    final String database = configuration.getString(DEFAULT_DATABASE);
    final String tableName = configuration.getString(TABLE_NAME);
    final GenericInMemoryCatalog genericInMemoryCatalog = new GenericInMemoryCatalog(context.getName(), database);
    StreamTableSource<Row> tableSource = new StreamTableSource<Row>() {

        @Override
        public DataStream<Row> getDataStream(StreamExecutionEnvironment execEnv) {
            return execEnv.fromCollection(TABLE_CONTENTS).returns(new RowTypeInfo(new TypeInformation[] { Types.INT(), Types.STRING() }, new String[] { "id", "string" }));
        }

        @Override
        public TableSchema getTableSchema() {
            return TableSchema.builder().field("id", DataTypes.INT()).field("string", DataTypes.STRING()).build();
        }

        @Override
        public DataType getProducedDataType() {
            return DataTypes.ROW(DataTypes.FIELD("id", DataTypes.INT()), DataTypes.FIELD("string", DataTypes.STRING())).notNull();
        }
    };
    try {
        genericInMemoryCatalog.createTable(new ObjectPath(database, tableName), ConnectorCatalogTable.source(tableSource, false), false);
    } catch (Exception e) {
        throw new WrappingRuntimeException(e);
    }
    return genericInMemoryCatalog;
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException) Configuration(org.apache.flink.configuration.Configuration) StreamExecutionEnvironment(org.apache.flink.streaming.api.environment.StreamExecutionEnvironment) Row(org.apache.flink.types.Row) RowTypeInfo(org.apache.flink.api.java.typeutils.RowTypeInfo) StreamTableSource(org.apache.flink.table.sources.StreamTableSource) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) TypeInformation(org.apache.flink.api.common.typeinfo.TypeInformation) WrappingRuntimeException(org.apache.flink.util.WrappingRuntimeException)

Example 2 with GenericInMemoryCatalog

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

the class SessionContext method create.

// --------------------------------------------------------------------------------------------
// Helper method to create
// --------------------------------------------------------------------------------------------
public static SessionContext create(DefaultContext defaultContext, String sessionId) {
    // --------------------------------------------------------------------------------------------------------------
    // Init config
    // --------------------------------------------------------------------------------------------------------------
    Configuration configuration = defaultContext.getFlinkConfig().clone();
    // --------------------------------------------------------------------------------------------------------------
    // Init classloader
    // --------------------------------------------------------------------------------------------------------------
    URLClassLoader classLoader = ClientUtils.buildUserCodeClassLoader(defaultContext.getDependencies(), Collections.emptyList(), SessionContext.class.getClassLoader(), configuration);
    // --------------------------------------------------------------------------------------------------------------
    // Init session state
    // --------------------------------------------------------------------------------------------------------------
    ModuleManager moduleManager = new ModuleManager();
    final EnvironmentSettings settings = EnvironmentSettings.fromConfiguration(configuration);
    CatalogManager catalogManager = CatalogManager.newBuilder().classLoader(classLoader).config(configuration).defaultCatalog(settings.getBuiltInCatalogName(), new GenericInMemoryCatalog(settings.getBuiltInCatalogName(), settings.getBuiltInDatabaseName())).build();
    FunctionCatalog functionCatalog = new FunctionCatalog(configuration, catalogManager, moduleManager);
    SessionState sessionState = new SessionState(catalogManager, moduleManager, functionCatalog);
    // --------------------------------------------------------------------------------------------------------------
    // Init ExecutionContext
    // --------------------------------------------------------------------------------------------------------------
    ExecutionContext executionContext = new ExecutionContext(configuration, classLoader, sessionState);
    return new SessionContext(defaultContext, sessionId, configuration, classLoader, sessionState, executionContext);
}
Also used : FunctionCatalog(org.apache.flink.table.catalog.FunctionCatalog) EnvironmentSettings(org.apache.flink.table.api.EnvironmentSettings) Configuration(org.apache.flink.configuration.Configuration) URLClassLoader(java.net.URLClassLoader) ModuleManager(org.apache.flink.table.module.ModuleManager) CatalogManager(org.apache.flink.table.catalog.CatalogManager) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog)

Example 3 with GenericInMemoryCatalog

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

the class SqlToOperationConverterTest method prepareTable.

private void prepareTable(boolean managedTable, boolean hasPartition, boolean hasConstraint) throws Exception {
    Catalog catalog = new GenericInMemoryCatalog("default", "default");
    catalogManager.registerCatalog("cat1", catalog);
    catalog.createDatabase("db1", new CatalogDatabaseImpl(new HashMap<>(), null), true);
    Schema.Builder builder = Schema.newBuilder().column("a", DataTypes.STRING().notNull()).column("b", DataTypes.BIGINT().notNull()).column("c", DataTypes.BIGINT());
    Map<String, String> options = new HashMap<>();
    options.put("k", "v");
    if (!managedTable) {
        options.put("connector", "dummy");
    }
    CatalogTable catalogTable = CatalogTable.of(hasConstraint ? builder.primaryKeyNamed("ct1", "a", "b").build() : builder.build(), "tb1", hasPartition ? Arrays.asList("b", "c") : Collections.emptyList(), Collections.unmodifiableMap(options));
    catalogManager.setCurrentCatalog("cat1");
    catalogManager.setCurrentDatabase("db1");
    ObjectIdentifier tableIdentifier = ObjectIdentifier.of("cat1", "db1", "tb1");
    catalogManager.createTable(catalogTable, tableIdentifier, true);
}
Also used : HashMap(java.util.HashMap) TableSchema(org.apache.flink.table.api.TableSchema) OperationMatchers.withSchema(org.apache.flink.table.planner.utils.OperationMatchers.withSchema) CatalogManagerCalciteSchema(org.apache.flink.table.planner.catalog.CatalogManagerCalciteSchema) Schema(org.apache.flink.table.api.Schema) CalciteSchemaBuilder.asRootSchema(org.apache.calcite.jdbc.CalciteSchemaBuilder.asRootSchema) CatalogTable(org.apache.flink.table.catalog.CatalogTable) Catalog(org.apache.flink.table.catalog.Catalog) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) FunctionCatalog(org.apache.flink.table.catalog.FunctionCatalog) GenericInMemoryCatalog(org.apache.flink.table.catalog.GenericInMemoryCatalog) CatalogDatabaseImpl(org.apache.flink.table.catalog.CatalogDatabaseImpl) ObjectIdentifier(org.apache.flink.table.catalog.ObjectIdentifier)

Example 4 with GenericInMemoryCatalog

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

the class JavaCatalogTableTest method testResolvingSchemaOfCustomCatalogTableTableApi.

@Test
public void testResolvingSchemaOfCustomCatalogTableTableApi() 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);
    Table table = tableEnvironment.from("testCatalog.`default`.testTable").window(Tumble.over(lit(10).minute()).on($("rowtime")).as("w")).groupBy($("w")).select(lit(1).count());
    testUtil.verifyExecPlan(table);
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) CatalogTable(org.apache.flink.table.catalog.CatalogTable) Table(org.apache.flink.table.api.Table) CatalogBaseTable(org.apache.flink.table.catalog.CatalogBaseTable) 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 5 with GenericInMemoryCatalog

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

the class JavaCatalogTableTest method testResolvingProctimeOfCustomTableTableApi.

@Test
public void testResolvingProctimeOfCustomTableTableApi() 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);
    Table table = tableEnvironment.from("testCatalog.`default`.testTable").window(Tumble.over(lit(10).minute()).on($("proctime")).as("w")).groupBy($("w")).select(lit(1).count());
    testUtil.verifyExecPlan(table);
}
Also used : ObjectPath(org.apache.flink.table.catalog.ObjectPath) CatalogTable(org.apache.flink.table.catalog.CatalogTable) Table(org.apache.flink.table.api.Table) CatalogBaseTable(org.apache.flink.table.catalog.CatalogBaseTable) 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