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

feat: Revert "feat(sink): support format encode syntax for sink into table (#14134) #14258

Merged
merged 1 commit into from
Dec 28, 2023
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
4 changes: 2 additions & 2 deletions e2e_test/sink/sink_into_table.slt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ statement error Only append-only sinks can sink to a table without primary keys.
create sink s1 into t_row_id_as_primary_key as select v1, v2 from t_s1;

statement ok
create sink s1 into t_row_id_as_primary_key as select v1, v2 from t_s1 FORMAT PLAIN ENCODE NATIVE(force_append_only='true');
create sink s1 into t_row_id_as_primary_key as select v1, v2 from t_s1 with (type = 'append-only', force_append_only = 'true');

statement ok
flush;
Expand Down Expand Up @@ -154,7 +154,7 @@ statement error Only append-only sinks can sink to a table without primary keys.
create sink s2 into t_append_only as select v1, v2 from t_s2;

statement ok
create sink s2 into t_append_only as select v1, v2 from t_s2 FORMAT PLAIN ENCODE NATIVE(force_append_only='true');
create sink s2 into t_append_only as select v1, v2 from t_s2 with (type = 'append-only', force_append_only = 'true');

statement ok
flush;
Expand Down
5 changes: 1 addition & 4 deletions src/connector/src/sink/catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ pub enum SinkEncode {
Protobuf,
Avro,
Template,
Native,
}

impl SinkFormatDesc {
Expand Down Expand Up @@ -180,7 +179,6 @@ impl SinkFormatDesc {
SinkEncode::Protobuf => E::Protobuf,
SinkEncode::Avro => E::Avro,
SinkEncode::Template => E::Template,
SinkEncode::Native => E::Native,
};
let options = self
.options
Expand Down Expand Up @@ -218,8 +216,7 @@ impl TryFrom<PbSinkFormatDesc> for SinkFormatDesc {
E::Protobuf => SinkEncode::Protobuf,
E::Template => SinkEncode::Template,
E::Avro => SinkEncode::Avro,
E::Native => SinkEncode::Native,
e @ (E::Unspecified | E::Csv | E::Bytes) => {
e @ (E::Unspecified | E::Native | E::Csv | E::Bytes) => {
return Err(SinkError::Config(anyhow!(
"sink encode unsupported: {}",
e.as_str_name()
Expand Down
2 changes: 0 additions & 2 deletions src/connector/src/sink/formatter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ impl SinkFormatterImpl {
AppendOnlyFormatter::new(Some(key_encoder), val_encoder),
))
}
SinkEncode::Native => err_unsupported(),
}
}
SinkFormat::Debezium => {
Expand Down Expand Up @@ -252,7 +251,6 @@ impl SinkFormatterImpl {
Ok(SinkFormatterImpl::UpsertAvro(formatter))
}
SinkEncode::Protobuf => err_unsupported(),
SinkEncode::Native => err_unsupported(),
}
}
}
Expand Down
35 changes: 8 additions & 27 deletions src/frontend/src/handler/create_sink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,23 +173,13 @@ pub fn gen_sink_plan(
}
None => match with_options.get(SINK_TYPE_OPTION) {
// Case B: old syntax `type = '...'`
Some(t) => {
if !allow_old_sink_type_syntax(&connector) {
return Err(ErrorCode::BindError(format!(
"connector {} does not support `type = '...'`, please use syntax `FORMAT ... ENCODE ...` instead.",
connector
))
.into());
} else {
SinkFormatDesc::from_legacy_type(&connector, t)?.map(|mut f| {
session.notice_to_user("Consider using the newer syntax `FORMAT ... ENCODE ...` instead of `type = '...'`.");
if let Some(v) = with_options.get(SINK_USER_FORCE_APPEND_ONLY_OPTION) {
f.options.insert(SINK_USER_FORCE_APPEND_ONLY_OPTION.into(), v.into());
}
f
})
Some(t) => SinkFormatDesc::from_legacy_type(&connector, t)?.map(|mut f| {
session.notice_to_user("Consider using the newer syntax `FORMAT ... ENCODE ...` instead of `type = '...'`.");
if let Some(v) = with_options.get(SINK_USER_FORCE_APPEND_ONLY_OPTION) {
f.options.insert(SINK_USER_FORCE_APPEND_ONLY_OPTION.into(), v.into());
}
}
f
}),
// Case C: no format + encode required
None => None,
},
Expand Down Expand Up @@ -255,7 +245,7 @@ pub fn gen_sink_plan(
|| sink_catalog.sink_type == SinkType::ForceAppendOnly)
{
return Err(RwError::from(ErrorCode::BindError(
"Only append-only sinks can sink to a table without primary keys. Please try to add \"FORMAT PLAIN ENCODE NATIVE\"".to_string(),
"Only append-only sinks can sink to a table without primary keys.".to_string(),
)));
}

Expand Down Expand Up @@ -591,8 +581,7 @@ fn bind_sink_format_desc(value: ConnectorSchema) -> Result<SinkFormatDesc> {
E::Protobuf => SinkEncode::Protobuf,
E::Avro => SinkEncode::Avro,
E::Template => SinkEncode::Template,
E::Native => SinkEncode::Native,
e @ (E::Csv | E::Bytes) => {
e @ (E::Native | E::Csv | E::Bytes) => {
return Err(ErrorCode::BindError(format!("sink encode unsupported: {e}")).into());
}
};
Expand Down Expand Up @@ -637,17 +626,9 @@ static CONNECTORS_COMPATIBLE_FORMATS: LazyLock<HashMap<String, HashMap<Format, V
Format::Plain => vec![Encode::Json,Encode::Template],
Format::Upsert => vec![Encode::Json,Encode::Template],
),
"table" => hashmap!(
Format::Plain => vec![Encode::Native],
Format::Upsert => vec![Encode::Native],
),
))
});

pub fn allow_old_sink_type_syntax(connector: &str) -> bool {
!matches!(connector, "table")
}

pub fn validate_compatibility(connector: &str, format_desc: &ConnectorSchema) -> Result<()> {
let compatible_formats = CONNECTORS_COMPATIBLE_FORMATS
.get(connector)
Expand Down
1 change: 0 additions & 1 deletion src/sqlparser/src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,6 @@ pub const RESERVED_FOR_TABLE_ALIAS: &[Keyword] = &[
Keyword::SET,
Keyword::RETURNING,
Keyword::EMIT,
Keyword::FORMAT,
];

/// Can't be used as a column alias, so that `SELECT <expr> alias`
Expand Down
Loading