8000 fix: handle missing 'connector' field in WITH clause with CONNECTION (#21691) by github-actions[bot] · Pull Request #21694 · risingwavelabs/risingwave · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: handle missing 'connector' field in WITH clause with CONNECTION (#21691) #21694

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
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
8 changes: 8 additions & 0 deletions e2e_test/source_inline/connection/ddl.slt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ insert into data_table values (1, 'a'), (2, 'b'), (3, 'c');
statement ok
flush;

statement error missing field 'connector' in WITH clause
create sink sink_kafka from data_table with (
connection = conn,
topic = 'connection_ddl_1'
) format plain encode json (
force_append_only='true'
);

statement ok
create sink sink_kafka from data_table with (
connector = 'kafka',
Expand Down
7 changes: 6 additions & 1 deletion src/frontend/src/handler/create_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,12 @@ pub async fn gen_sink_plan(

// if not using connection, we don't need to check connector match connection type
if !matches!(connection_type, PbConnectionType::Unspecified) {
let connector = resolved_with_options.get_connector().unwrap();
let Some(connector) = resolved_with_options.get_connector() else {
return Err(RwError::from(ErrorCode::ProtocolError(format!(
"missing field '{}' in WITH clause",
CONNECTOR_TYPE_KEY
))));
};
Comment on lines +117 to +122
Copy link
Preview
Copilot AI May 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a safe extraction pattern rather than unwrap() prevents a possible panic due to a missing connector field, with an explicit error message referencing CONNECTOR_TYPE_KEY.

Suggested change
let Some(connector) = resolved_with_options.get_connector() else {
return Err(RwError::from(ErrorCode::ProtocolError(format!(
"missing field '{}' in WITH clause",
CONNECTOR_TYPE_KEY
))));
};
let connector = resolved_with_options
.get_connector()
.ok_or_else(|| {
RwError::from(ErrorCode::ProtocolError(format!(
"missing field '{}' in WITH clause",
CONNECTOR_TYPE_KEY
)))
})?;

Copilot uses AI. Check for mistakes.

check_connector_match_connection_type(connector.as_str(), &connection_type)?;
}

Expand Down
7 changes: 6 additions & 1 deletion src/frontend/src/handler/create_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,12 @@ pub async fn bind_create_source_or_table_with_connector(

// if not using connection, we don't need to check connector match connection type
if !matches!(connection_type, PbConnectionType::Unspecified) {
let connector = with_properties.get_connector().unwrap();
let Some(connector) = with_properties.get_connector() else {
Copy link
Preview
Copilot AI May 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replacing unwrap() with pattern matching avoids a potential runtime panic when the connector field is missing. The use of a proper error message with UPSTREAM_SOURCE_KEY improves error handling.

Copilot uses AI. Check for mistakes.

return Err(RwError::from(ProtocolError(format!(
"missing field '{}' in WITH clause",
UPSTREAM_SOURCE_KEY
))));
};
check_connector_match_connection_type(connector.as_str(), &connection_type)?;
}

Expand Down
0