Skip to content

Commit ae85538

Browse files
committed
test: fix unit tests
1 parent 1c279e4 commit ae85538

File tree

2 files changed

+9
-21
lines changed

2 files changed

+9
-21
lines changed

src/datatypes/src/schema/column_schema.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -549,14 +549,19 @@ mod tests {
549549
assert!(column_schema.metadata.is_empty());
550550

551551
let field = Field::new("test", ArrowDataType::Binary, true);
552-
let field =
553-
field.with_metadata(Metadata::from([(TYPE_KEY.to_string(), "Json".to_string())]));
552+
let field = field.with_metadata(Metadata::from([(
553+
TYPE_KEY.to_string(),
554+
ConcreteDataType::json_datatype().name(),
555+
)]));
554556
let column_schema = ColumnSchema::try_from(&field).unwrap();
555557
assert_eq!("test", column_schema.name);
556558
assert_eq!(ConcreteDataType::json_datatype(), column_schema.data_type);
557559
assert!(column_schema.is_nullable);
558560
assert!(!column_schema.is_time_index);
559561
assert!(column_schema.default_constraint.is_none());
560-
assert!(column_schema.metadata.is_empty());
562+
assert_eq!(
563+
column_schema.metadata.get(TYPE_KEY).unwrap(),
564+
&ConcreteDataType::json_datatype().name()
565+
);
561566
}
562567
}

src/datatypes/src/value.rs

+1-18
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ impl Value {
321321
let value_type_id = self.logical_type_id();
322322
let output_type_id = output_type.logical_type_id();
323323
ensure!(
324-
output_type_id == value_type_id || self.is_null(),
324+
output_type_id == value_type_id || self.is_null() || (output_type_id == LogicalTypeId::Json && value_type_id == LogicalTypeId::Binary),
325325
error::ToScalarValueSnafu {
326326
reason: format!(
327327
"expect value to return output_type {output_type_id:?}, actual: {value_type_id:?}",
@@ -1824,14 +1824,6 @@ mod tests {
18241824
&ConcreteDataType::decimal128_datatype(38, 10),
18251825
&Value::Decimal128(Decimal128::new(1, 38, 10)),
18261826
);
1827-
1828-
let jsonb_value = jsonb::parse_value(r#"{"key": "value"}"#.as_bytes())
1829-
.unwrap()
1830-
.to_vec();
1831-
check_type_and_value(
1832-
&ConcreteDataType::json_datatype(),
1833-
&Value::Binary(jsonb_value.into()),
1834-
);
18351827
}
18361828

18371829
#[test]
@@ -1945,15 +1937,6 @@ mod tests {
19451937
datatype: ConcreteDataType::int32_datatype(),
19461938
}))
19471939
);
1948-
1949-
let jsonb_value =
1950-
jsonb::parse_value(r#"{"items":[{"Int32":123}],"datatype":{"Int32":{}}}"#.as_bytes())
1951-
.unwrap();
1952-
let json_value: serde_json::Value = jsonb_value.clone().into();
1953-
assert_eq!(
1954-
json_value,
1955-
to_json(Value::Binary(jsonb_value.to_vec().into()))
1956-
);
19571940
}
19581941

19591942
#[test]

0 commit comments

Comments
 (0)