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(avro): fix parsing of avro ref type #14781

Merged
merged 2 commits into from
Jan 25, 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
12 changes: 12 additions & 0 deletions src/connector/src/parser/avro/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ fn avro_type_mapping(schema: &Schema) -> anyhow::Result<DataType> {

avro_type_mapping(nested_schema)?
}
Schema::Ref { name } => {
if name.name == DBZ_VARIABLE_SCALE_DECIMAL_NAME
&& name.namespace == Some(DBZ_VARIABLE_SCALE_DECIMAL_NAMESPACE.into())
{
DataType::Decimal
} else {
return Err(anyhow::format_err!(
"unsupported type in Avro: {:?}",
schema
));
}
}
_ => {
return Err(anyhow::format_err!(
"unsupported type in Avro: {:?}",
Expand Down
59 changes: 59 additions & 0 deletions src/connector/src/parser/debezium/avro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ mod tests {
use risingwave_common::row::{OwnedRow, Row};
use risingwave_common::types::{DataType, ScalarImpl};
use risingwave_pb::catalog::StreamSourceInfo;
use risingwave_pb::data::data_type::TypeName;
use risingwave_pb::plan_common::{PbEncodeType, PbFormatType};

use super::*;
Expand Down Expand Up @@ -256,6 +257,64 @@ mod tests {
assert_eq!(names, vec!["id".to_owned()])
}

#[test]
fn test_ref_avro_type() {
let test_schema_str = r#"{
"type": "record",
"name": "Key",
"namespace": "dbserver1.inventory.customers",
"fields": [{
"name": "id",
"type": "int"
},
{
"name": "unconstrained_decimal",
"type": [
"null",
{
"type": "record",
"name": "VariableScaleDecimal",
"namespace": "io.debezium.data",
"fields": [
{
"name": "scale",
"type": "int"
},
{
"name": "value",
"type": "bytes"
}
],
"connect.doc": "Variable scaled decimal",
"connect.name": "io.debezium.data.VariableScaleDecimal",
"connect.version": 1
}
],
"default": null
},
{
"name": "unconstrained_numeric",
"type": [
"null",
"io.debezium.data.VariableScaleDecimal"
],
"default": null
}
],
"connect.name": "dbserver1.inventory.customers.Key"
}
"#;
let schema = Schema::parse_str(test_schema_str).unwrap();
let columns = avro_schema_to_column_descs(&schema).unwrap();
for col in &columns {
let dtype = col.column_type.as_ref().unwrap();
println!("name = {}, type = {:?}", col.name, dtype.type_name);
if col.name.contains("unconstrained") {
assert_eq!(dtype.type_name, TypeName::Decimal as i32);
}
}
}

#[test]
fn test_map_to_columns() {
let outer_schema = get_outer_schema();
Expand Down
Loading