neverchanje / chgcap-rs

A CDC library in Rust.
Apache License 2.0
16 stars 1 forks source link

support `create table like` #14

Open neverchanje opened 9 months ago

neverchanje commented 9 months ago

We need to handle create table new_table like old_table statements, by managing table schemas in a table map and copying the old_table's metadata as a new record in the map.

This task is part of the work of https://github.com/neverchanje/chgcap-rs/issues/4.

Debezium seems having the same issue as discussed in: https://issues.redhat.com/browse/DBZ-1496. But in its unit tests, I find that CREATE TABLE LIKE has been well-tested. I suppose this is a useful feature in the real world and we should support it eventually.

QueryEvent { thread_id: 8, execution_time: 0, schema_len: 5, error_code: 0, status_vars_len: 40, 
status_vars: [
  StatusVar { key: Flags2, value: Ok(Flags2(Flags2(0x0))) }, 
  StatusVar { key: SqlMode, value: Ok(SqlMode(SqlMode(0x0))) }, 
  StatusVar { key: CatalogNz, value: Ok(CatalogNz(RawBytes { value: "std", max_len: "255" })) }, 
  StatusVar { key: Charset, value: Ok(Charset { charset_client: 45, collation_connection: 45, collation_server: 255 }) }, 
  StatusVar { key: DdlLoggedWithXid, value: Ok(DdlLoggedWithXid(143)) },
  StatusVar { key: DefaultCollationForUtf8mb4, value: Ok(DefaultCollationForUtf8mb4(255)) },
  StatusVar { key: SqlRequirePrimaryKey, value: Ok(SqlRequirePrimaryKey(0)) }
],
schema: RawBytes { value: "mysql", max_len: "255" }, __skip: Skip, 
query: RawBytes { value: "CREATE TABLE test_create_table_like LIKE dbz_751_decimal_column_test", max_len: "18446744073709551615" } }

Here is the query event triggered by CREATE TABLE LIKE. For unknown reasons, there is no UpdatedDbNames status value in it.