feat(connector): support debezium mongo json - #9250
Conversation
|
Did you test it end-to-end? What does the output look like? |
09bb2af to
1ed5882
Compare
|
Updated your PR description. I didn't find in the code where you handle the bson types. The point is, we need to ensure all types can be handled, whether or not they have the corresponding type in RisingWave. Generally, I recommend parsing the complex types, e.g. Regex, into VARCHAR, if we have no idea how to deal with them. |
bson is handled here doc. The method is used to convert bson types into some more widely used formats for json parser. |
|
match value {
Bson::Double(v) => {
...
},
Bson::RegularExpression(v) => {
...
},
} |
actually, we are storing jsonb type for the payload. As discussed offline, the schema for |
|
We will abandon the and now the expected behavior is create table t ("_id" int, "payload" jsonb) with (...) row format DEBEZIUM_MONGO_JSON;
select (payload->'_id'->'$NumberLong')::int as _id from t; |
| DebeziumJson, // Keyword::DEBEZIUM_JSON | ||
| Json, // Keyword::JSON | ||
| DebeziumJson, // Keyword::DEBEZIUM_JSON | ||
| DebeziumMongoJson, |
There was a problem hiding this comment.
| DebeziumMongoJson, | |
| DebeziumMongoJson, // DEBEZIUM_MONGO_JSON |
Codecov Report
@@ Coverage Diff @@
## main #9250 +/- ##
==========================================
- Coverage 70.74% 70.70% -0.04%
==========================================
Files 1230 1231 +1
Lines 204838 205179 +341
==========================================
+ Hits 144914 145074 +160
- Misses 59924 60105 +181
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 3 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
| let int_str = obj["$numberInt"].as_str().unwrap_or_default(); | ||
| Some(ScalarImpl::Int32(int_str.parse().unwrap_or_default())) |
There was a problem hiding this comment.
The value of field named $numberInt in a well-formed bson must be a string contains an integer. It's safe to unwrap as long as the source message is produced by mongoDB.
| DataType::Jsonb | ||
| | DataType::Varchar | ||
| | DataType::Int32 | ||
| | DataType::Int64 |
There was a problem hiding this comment.
Any doc on key type limits?
There was a problem hiding this comment.
We could extend them if other _id type appears.
| if row_id_index.is_some() { | ||
| return Err(RwError::from(ProtocolError( | ||
| "Primary key must be specified when creating source with row format debezium." | ||
| .to_string(), | ||
| ))); | ||
| } |
There was a problem hiding this comment.
For the case below.
CREATE TABLE mongo_customers (
_id BIGINT, -- NO PRIMARY KEY HERE
payload jsonb
) ...
There was a problem hiding this comment.
actually, we extract _id to make it primary key
There was a problem hiding this comment.
If the user leaves the CREATE TABLE xx (...) blank, we will create _id column and make it be primary key, otherwise we will not help users to create columns.
There was a problem hiding this comment.
If the user leaves the CREATE TABLE xx (...) blank, we will create _id column and make it be primary key
what is the type for _id column?
There was a problem hiding this comment.
If the user leaves the CREATE TABLE xx (...) blank, we will create _id column and make it be primary key
what is the type for
_idcolumn?
varchar. Intended to be mapped from ObjectID, which is the default type for the _id field of a mongoDB docment.
There was a problem hiding this comment.
The important detail, however, is that you can also pass your own _id when inserting a document and it doesn't have to be of type ObjectId. In fact, according to MongoDB document specification, it can be of any type except arrays
from: https://stackoverflow.com/questions/51322231/what-is-the-type-of-id-field-in-mongo-database
_id may not always be a verchar.
4e4dd59 to
752b813
Compare
tabVersion
left a comment
There was a problem hiding this comment.
rest LGTM
note that for this case:
_id MUST be the primary key and the user MUST annotate its type
it would be better to give a type mapping table to demonstrate how to correctly write _id type.
updated in PR comment. |

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.
What's changed and what's your intention?
A new row format
DEBEZIUM_MONGO_JSONis added to our kakfa source. Thus we can load documents from MongoDB via Debezium.Checklist For Contributors
./risedev check(or alias,./risedev c)Checklist For Reviewers
Documentation
Types of user-facing changes
Please keep the types that apply to your changes, and remove the others.
A new row format
DEBEZIUM_MONGO_JSONis added to our kakfa source.The source table schema has following constraints when using the
DEBEZIUM_MONGO_JSONrow format._idand the other is calledpayload. The MongoDB document's_idwill be extracted into the_idcolumn, and the whole document will be inpayloadcolumn.payloadcolumn must bejsonbtype._idcolumn must be the only primary key and its type is mapped. If theObjectIDis used as document's_idfield type, the_idcolumn should bevarchartype. And If theint32orint64is used as document's_idfield , the_idcolumn should beintorbiginttype.Release note