8000 fix(iceberg): fix iceberg table engine pk retrieving (#21789) by github-actions[bot] · Pull Request #21795 · risingwavelabs/risingwave · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(iceberg): fix iceberg table engine pk retrieving (#21789) #21795

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

Merged
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
43 changes: 7 additions & 36 deletions src/frontend/src/handler/create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1380,8 +1380,6 @@ pub async fn handle_create_table(
table,
graph,
job_type,
column_defs,
constraints,
table_name,
)
.await?;
Expand All @@ -1399,8 +1397,6 @@ pub async fn create_iceberg_engine_table(
table: PbTable,
graph: StreamFragmentGraph,
job_type: TableJobType,
column_defs: Vec<ColumnDef>,
constraints: Vec<TableConstraint>,
table_name: ObjectName,
) -> Result<()> {
// 1. fetch iceberg engine options from the meta node. Or use iceberg engine connection provided by users.
Expand Down Expand Up @@ -1614,43 +1610,18 @@ pub async fn create_iceberg_engine_table(
}
};

let table_catalog = TableCatalog::from(table.clone());

// Iceberg sinks require a primary key, if none is provided, we will use the _row_id column
// Fetch primary key from columns
let mut pks = column_defs
.into_iter()
.filter(|c| {
c.options
.iter()
.any(|o| matches!(o.option, ColumnOption::Unique { is_primary: true }))
})
.map(|c| c.name.to_string())
let mut pks = table_catalog
.pk_column_names()
.iter()
.map(|c| c.to_string())
.collect::<Vec<String>>();

// Fetch primary key from constraints
if pks.is_empty() {
pks = constraints
.into_iter()
.filter(|c| {
matches!(
c,
TableConstraint::Unique {
is_primary: true,
..
}
)
})
.flat_map(|c| match c {
TableConstraint::Unique { columns, .. } => columns
.into_iter()
.map(|c| c.to_string())
.collect::<Vec<String>>(),
_ => vec![],
})
.collect::<Vec<String>>();
}

// For the table without primary key. We will use `_row_id` as primary key
let sink_from = if pks.is_empty() {
let sink_from = if pks.len() == 1 && pks[0].eq(ROW_ID_COLUMN_NAME) {
pks = vec![RISINGWAVE_ICEBERG_ROW_ID.to_owned()];
let [stmt]: [_; 1] = Parser::parse_sql(&format!(
"select {} as {}, * from {}",
Expand Down
0