[docs] Add metadata column example for mysql-cdc and mongodb-cdc connector

pull/588/head
Leonard Xu 3 years ago committed by Leonard Xu
parent 29a441a571
commit 39944c9ecd

@ -255,7 +255,6 @@ Available Metadata
The following format metadata can be exposed as read-only (VIRTUAL) columns in a table definition.
<div class="highlight">
<table class="colwidths-auto docutils">
<thead>
<tr>
@ -282,8 +281,29 @@ The following format metadata can be exposed as read-only (VIRTUAL) columns in a
</tr>
</tbody>
</table>
</div>
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<STRING>, -- array
price ROW<amount DECIMAL(10,2), currency STRING>, -- embedded document
suppliers ARRAY<ROW<name STRING, address STRING>>, -- 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
--------

@ -256,7 +256,6 @@ Available Metadata
The following format metadata can be exposed as read-only (VIRTUAL) columns in a table definition.
<div class="highlight">
<table class="colwidths-auto docutils">
<thead>
<tr>
@ -283,8 +282,30 @@ The following format metadata can be exposed as read-only (VIRTUAL) columns in a
</tr>
</tbody>
</table>
</div>
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
--------

@ -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(),

@ -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(),

Loading…
Cancel
Save