Skip to content

Commit

Permalink
test: fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CookiePieWw committed Aug 31, 2024
1 parent 1c279e4 commit ae85538
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 21 deletions.
11 changes: 8 additions & 3 deletions src/datatypes/src/schema/column_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,14 +549,19 @@ mod tests {
assert!(column_schema.metadata.is_empty());

let field = Field::new("test", ArrowDataType::Binary, true);
let field =
field.with_metadata(Metadata::from([(TYPE_KEY.to_string(), "Json".to_string())]));
let field = field.with_metadata(Metadata::from([(
TYPE_KEY.to_string(),
ConcreteDataType::json_datatype().name(),
)]));
let column_schema = ColumnSchema::try_from(&field).unwrap();
assert_eq!("test", column_schema.name);
assert_eq!(ConcreteDataType::json_datatype(), column_schema.data_type);
assert!(column_schema.is_nullable);
assert!(!column_schema.is_time_index);
assert!(column_schema.default_constraint.is_none());
assert!(column_schema.metadata.is_empty());
assert_eq!(
column_schema.metadata.get(TYPE_KEY).unwrap(),
&ConcreteDataType::json_datatype().name()
);
}
}
19 changes: 1 addition & 18 deletions src/datatypes/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ impl Value {
let value_type_id = self.logical_type_id();
let output_type_id = output_type.logical_type_id();
ensure!(
output_type_id == value_type_id || self.is_null(),
output_type_id == value_type_id || self.is_null() || (output_type_id == LogicalTypeId::Json && value_type_id == LogicalTypeId::Binary),
error::ToScalarValueSnafu {
reason: format!(
"expect value to return output_type {output_type_id:?}, actual: {value_type_id:?}",
Expand Down Expand Up @@ -1824,14 +1824,6 @@ mod tests {
&ConcreteDataType::decimal128_datatype(38, 10),
&Value::Decimal128(Decimal128::new(1, 38, 10)),
);

let jsonb_value = jsonb::parse_value(r#"{"key": "value"}"#.as_bytes())
.unwrap()
.to_vec();
check_type_and_value(
&ConcreteDataType::json_datatype(),
&Value::Binary(jsonb_value.into()),
);
}

#[test]
Expand Down Expand Up @@ -1945,15 +1937,6 @@ mod tests {
datatype: ConcreteDataType::int32_datatype(),
}))
);

let jsonb_value =
jsonb::parse_value(r#"{"items":[{"Int32":123}],"datatype":{"Int32":{}}}"#.as_bytes())
.unwrap();
let json_value: serde_json::Value = jsonb_value.clone().into();
assert_eq!(
json_value,
to_json(Value::Binary(jsonb_value.to_vec().into()))
);
}

#[test]
Expand Down

0 comments on commit ae85538

Please sign in to comment.