Manage Environment Catalogs in Confluent Manager for Apache Flink
Starting with version 2.4.0, Confluent Manager for Apache Flink® (CMF) provides an environment catalog for every environment. The environment catalog is a writable Flink SQL catalog that stores metadata you create with Data Definition Language (DDL) statements, such as user-defined functions, tables that use custom connectors, and views.
The built-in Kafka catalogs cannot store this metadata. The catalogs expose Kafka
topics as tables and derive their schemas from Schema Registry, but they do not accept
CREATE FUNCTION or CREATE VIEW, and they cannot store tables that are
backed by systems other than Kafka. The environment catalog fills that gap. You
register functions, custom-connector tables, and views in it. Because the
catalog is scoped to a single environment, the objects you create are visible
only within that environment.
Note
The environment catalog stores metadata only. You deliver the function and connector code by uploading it to artifact management and referencing it from your DDL.
How it works
When the environment catalog is enabled, CMF adds one catalog to every environment automatically. You do not create or delete it.
The catalog name is
_env_followed by the environment name. For example, environmentprodhas the catalog_env_prod. The_env_prefix keeps the name from colliding with your Kafka catalogs.Each environment catalog includes a
defaultdatabase that CMF creates automatically and that you cannot delete. CMF creates it the first time a statement in the environment opens the catalog, not when the environment is created. You can create additional databases withCREATE DATABASEand drop them withDROP DATABASE.CMF stores the catalog’s objects (functions, tables, and views) in its own database. No Schema Registry or Kafka cluster is required.
The objects you can create in the environment catalog are:
Functions: scalar, table, and aggregate user-defined functions, registered with
CREATE FUNCTION. See User-Defined Functions in Confluent Manager for Apache Flink.Tables: tables backed by custom connectors and formats, created with
CREATE TABLE ... WITH ('connector' = '...'). See Custom Connectors and Formats in Confluent Manager for Apache Flink.Views: named queries, created with
CREATE VIEW. A view can read tables from any catalog in the environment, including the Kafka catalogs. Available starting with version 2.5.0. For more information, see Views in Confluent Manager for Apache Flink. For a view that applies table options such asscan.bounded.modeto a table, see known limitations of batch statements.
Enable the environment catalog
The environment catalog is an opt-in feature and is disabled by default. Enable it in your Helm values file:
cmf:
sql:
environmentCatalog:
enabled: true
While the feature is disabled, the environment catalog is not registered, and the catalog endpoint returns HTTP 404.
To register and use functions or custom connectors, also enable artifact management, which stores the JAR files that your DDL references. See User-Defined Functions in Confluent Manager for Apache Flink and Custom Connectors and Formats in Confluent Manager for Apache Flink. With both features enabled, all statements of environments that have artifacts compile on compile workers. See Compile workers.
Important
The environment catalog runtime is included in the cp-flink-sql image
starting with version 1.19-cp9. Compute pools must run
confluentinc/cp-flink-sql:1.19-cp9 or later. Statements that use the
environment catalog fail on earlier images, such as 1.19-cp8, even when
you enable the feature in CMF. The recommended image is
confluentinc/cp-flink-sql:1.19-cp11, which includes the latest bug fixes
validated with this CMF release. Set the pool’s image field
accordingly. See Manage Compute Pools in Confluent Manager for Apache Flink.
Use the environment catalog
To create or use objects in the environment catalog, set the statement’s current
catalog and database to the environment catalog and its default database.
With the Confluent CLI, pass the --catalog and --database flags:
confluent flink statement create show-functions \
--url http://cmf:8080 \
--environment prod \
--compute-pool pool \
--catalog _env_prod \
--database default \
--sql "SHOW USER FUNCTIONS;"
With the REST API, set the current catalog and database in the statement’s properties:
{
"apiVersion": "cmf.confluent.io/v1",
"kind": "Statement",
"metadata": {
"name": "show-functions"
},
"spec": {
"statement": "SHOW USER FUNCTIONS;",
"computePoolName": "pool",
"properties": {
"sql.current-catalog": "_env_prod",
"sql.current-database": "default"
}
}
}
Within the environment catalog you can run function DDL (CREATE FUNCTION,
DROP FUNCTION), table DDL (CREATE TABLE, ALTER TABLE, DROP TABLE),
view DDL (CREATE VIEW, ALTER VIEW, DROP VIEW), database DDL
(CREATE DATABASE, DROP DATABASE), and queries (SELECT,
INSERT INTO) that reference those objects.
Inspect the environment catalog with the REST API
CMF exposes a read-only description of an environment catalog and its databases through the REST API:
curl -v -X GET http://cmf:8080/cmf/api/v1/environments/prod/catalog
The response contains the catalog name and its databases. CMF creates the
default database on first use. Until a statement has run in the
environment, the list of databases can be empty. The response does not list the
functions, tables, or views in the catalog. To list them, run a
SHOW USER FUNCTIONS;, SHOW TABLES;, or SHOW VIEWS; statement
against the catalog. The endpoint returns HTTP 404 when the environment catalog
feature is disabled.
Limitations
CREATE TABLE AS(CTAS) andCREATE OR REPLACE TABLE AS(RTAS) statements are not supported in the environment catalog.UPDATEandDELETEstatements are not supported, in line with Flink SQL, which does not support these DML statements in streaming mode. UseINSERT INTOto write rows andSELECTto read them.CREATE TEMPORARY FUNCTIONandCREATE TEMPORARY SYSTEM FUNCTIONare not supported. Register functions withCREATE FUNCTIONinstead.The environment catalog and its
defaultdatabase cannot be renamed or deleted.User-defined functions must be implemented in Java. See User-Defined Functions in Confluent Manager for Apache Flink.
You can’t delete an environment while the
defaultdatabase of its environment catalog holds functions, tables, or views, or while the catalog holds databases you created. Drop them first. For more information, see Configure Environments in Confluent Manager for Apache Flink.