Skip to content

Commit

Permalink
fix pk check
Browse files Browse the repository at this point in the history
  • Loading branch information
StrikeW committed May 29, 2024
1 parent 6172211 commit 63deb54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
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

0 comments on commit 63deb54

Please sign in to comment.