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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations