Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(frontend): fix primary key check for cdc table #17006

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions e2e_test/source/cdc/cdc.share_stream.slt
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ statement error Should not create MATERIALIZED VIEW or SELECT directly on shared
create materialized view mv as select * from mysql_mytest;

statement error The upstream table name must contain database name prefix*
create table products_test ( id INT,
create table products_test ( id INT PRIMARY KEY,
name STRING,
description STRING,
PRIMARY KEY (id)
description STRING
) from mysql_mytest table 'products';

statement ok
Expand Down Expand Up @@ -233,12 +232,11 @@ CREATE TABLE IF NOT EXISTS postgres_all_types(

statement error The upstream table name must contain schema name prefix*
CREATE TABLE person_new (
id int,
id int PRIMARY KEY,
name varchar,
email_address varchar,
credit_card varchar,
city varchar,
PRIMARY KEY (id)
city varchar
) FROM pg_source TABLE 'person';

statement ok
Expand Down
5 changes: 5 additions & 0 deletions src/frontend/src/handler/create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,7 @@ pub(crate) fn gen_create_table_plan_for_cdc_source(
with_version_column: Option<String>,
include_column_options: IncludeOption,
) -> Result<(PlanRef, PbTable)> {
// cdc table must have primary key constraint or primary key column
if !constraints.iter().any(|c| {
matches!(
c,
Expand All @@ -751,6 +752,10 @@ pub(crate) fn gen_create_table_plan_for_cdc_source(
..
}
)
}) && !column_defs.iter().any(|col| {
col.options
.iter()
.any(|opt| matches!(opt.option, ColumnOption::Unique { is_primary: true }))
}) {
return Err(ErrorCode::NotSupported(
"CDC table without primary key constraint is not supported".to_owned(),
Expand Down
Loading