From 39944c9ecdff87e5f554875c0a6c0243ee7e3d1b Mon Sep 17 00:00:00 2001 From: Leonard Xu Date: Tue, 9 Nov 2021 10:43:35 +0800 Subject: [PATCH] [docs] Add metadata column example for mysql-cdc and mongodb-cdc connector --- docs/content/connectors/mongodb-cdc.md | 24 ++++++++++++++++-- docs/content/connectors/mysql-cdc.md | 25 +++++++++++++++++-- .../table/MongoDBTableFactoryTest.java | 2 +- .../table/MySqlTableSourceFactoryTest.java | 2 +- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/docs/content/connectors/mongodb-cdc.md b/docs/content/connectors/mongodb-cdc.md index 5678a9097..c03be03ce 100644 --- a/docs/content/connectors/mongodb-cdc.md +++ b/docs/content/connectors/mongodb-cdc.md @@ -255,7 +255,6 @@ Available Metadata The following format metadata can be exposed as read-only (VIRTUAL) columns in a table definition. -
@@ -282,8 +281,29 @@ The following format metadata can be exposed as read-only (VIRTUAL) columns in a
-
+The extended CREATE TABLE example demonstrates the syntax for exposing these metadata fields: +```sql +CREATE TABLE products ( + db_name STRING METADATA FROM 'database_name' VIRTUAL, + table_name STRING METADATA FROM 'table_name' VIRTUAL, + operation_ts TIMESTAMP_LTZ(3) METADATA FROM 'op_ts' VIRTUAL, + _id STRING, // must be declared + name STRING, + weight DECIMAL(10,3), + tags ARRAY, -- array + price ROW, -- embedded document + suppliers ARRAY>, -- embedded documents + PRIMARY KEY(_id) NOT ENFORCED +) WITH ( + 'connector' = 'mongodb-cdc', + 'hosts' = 'localhost:27017,localhost:27018,localhost:27019', + 'username' = 'flinkuser', + 'password' = 'flinkpw', + 'database' = 'inventory', + 'collection' = 'products' +); +``` Features -------- diff --git a/docs/content/connectors/mysql-cdc.md b/docs/content/connectors/mysql-cdc.md index 368e2240a..c698fffd8 100644 --- a/docs/content/connectors/mysql-cdc.md +++ b/docs/content/connectors/mysql-cdc.md @@ -256,7 +256,6 @@ Available Metadata The following format metadata can be exposed as read-only (VIRTUAL) columns in a table definition. -
@@ -283,8 +282,30 @@ The following format metadata can be exposed as read-only (VIRTUAL) columns in a
-
+The extended CREATE TABLE example demonstrates the syntax for exposing these metadata fields: +```sql +CREATE TABLE products ( + db_name STRING METADATA FROM 'database_name' VIRTUAL, + table_name STRING METADATA FROM 'table_name' VIRTUAL, + operation_ts TIMESTAMP_LTZ(3) METADATA FROM 'op_ts' VIRTUAL, + order_id INT, + order_date TIMESTAMP(0), + customer_name STRING, + price DECIMAL(10, 5), + product_id INT, + order_status BOOLEAN, + PRIMARY KEY(order_id) NOT ENFORCED +) WITH ( + 'connector' = 'mysql-cdc', + 'hostname' = 'localhost', + 'port' = '3306', + 'username' = 'root', + 'password' = '123456', + 'database-name' = 'mydb', + 'table-name' = 'orders' +); +``` Features -------- diff --git a/flink-connector-mongodb-cdc/src/test/java/com/ververica/cdc/connectors/mongodb/table/MongoDBTableFactoryTest.java b/flink-connector-mongodb-cdc/src/test/java/com/ververica/cdc/connectors/mongodb/table/MongoDBTableFactoryTest.java index 2365cd2e7..870deb86c 100644 --- a/flink-connector-mongodb-cdc/src/test/java/com/ververica/cdc/connectors/mongodb/table/MongoDBTableFactoryTest.java +++ b/flink-connector-mongodb-cdc/src/test/java/com/ververica/cdc/connectors/mongodb/table/MongoDBTableFactoryTest.java @@ -69,7 +69,7 @@ public class MongoDBTableFactoryTest { Column.physical("ccc", DataTypes.DOUBLE()), Column.physical("ddd", DataTypes.DECIMAL(31, 18)), Column.physical("eee", DataTypes.TIMESTAMP(3)), - Column.metadata("time", DataTypes.TIMESTAMP(3), "op_ts", true), + Column.metadata("time", DataTypes.TIMESTAMP_LTZ(3), "op_ts", true), Column.metadata( "_database_name", DataTypes.STRING(), "database_name", true)), Collections.emptyList(), diff --git a/flink-connector-mysql-cdc/src/test/java/com/ververica/cdc/connectors/mysql/table/MySqlTableSourceFactoryTest.java b/flink-connector-mysql-cdc/src/test/java/com/ververica/cdc/connectors/mysql/table/MySqlTableSourceFactoryTest.java index fa16dbd40..c33aa44c0 100644 --- a/flink-connector-mysql-cdc/src/test/java/com/ververica/cdc/connectors/mysql/table/MySqlTableSourceFactoryTest.java +++ b/flink-connector-mysql-cdc/src/test/java/com/ververica/cdc/connectors/mysql/table/MySqlTableSourceFactoryTest.java @@ -79,7 +79,7 @@ public class MySqlTableSourceFactoryTest { Column.physical("id", DataTypes.BIGINT().notNull()), Column.physical("name", DataTypes.STRING()), Column.physical("count", DataTypes.DECIMAL(38, 18)), - Column.metadata("time", DataTypes.TIMESTAMP(3), "op_ts", true), + Column.metadata("time", DataTypes.TIMESTAMP_LTZ(3), "op_ts", true), Column.metadata( "database_name", DataTypes.STRING(), "database_name", true)), Collections.emptyList(),