feat: support different types for CompatReader (#3745)

* feat: support different types for `CompatReader`

* chore: only compare whether we need: (data_type)

* fix: optimize code based on review suggestions

- add unit test `test_safe_cast_to_null` to test safely cast
- add DataType to projected_fields
- remove TODO

* fix: assert_eq fail on `projection.rs`

* style: codefmt

* style: fix the code based on review suggestions
This commit is contained in:
Kould
2024-04-24 14:27:52 +08:00
committed by GitHub
parent 20a933e395
commit 42e7403fcc
5 changed files with 235 additions and 85 deletions

View File

@@ -207,4 +207,21 @@ mod tests {
assert!(c.is_null(2));
}
}
#[test]
fn test_safe_cast_to_null() {
let string_vector = Arc::new(StringVector::from(vec![
Some("1"),
Some("hello"),
Some(&i64::MAX.to_string()),
None,
])) as VectorRef;
let to_type = ConcreteDataType::int32_datatype();
let b = string_vector.cast(&to_type).unwrap();
let c = b.as_any().downcast_ref::<Int32Vector>().unwrap();
assert_eq!(Value::Int32(1), c.get(0));
assert_eq!(Value::Null, c.get(1));
assert_eq!(Value::Null, c.get(2));
assert_eq!(Value::Null, c.get(3));
}
}