risingwave_common/util/
schema_check.rs1use itertools::Itertools;
16
17use crate::array::{ArrayImpl, ArrayRef};
18use crate::for_all_variants;
19use crate::types::DataType;
20
21pub fn schema_check<'a, T, C>(data_types: T, columns: C) -> Result<(), String>
23where
24 T: IntoIterator<Item = &'a DataType>,
25 C: IntoIterator<Item = &'a ArrayRef>,
26{
27 for (i, pair) in data_types
28 .into_iter()
29 .zip_longest(columns.into_iter().map(|c| &**c))
30 .enumerate()
31 {
32 macro_rules! matches {
33 ($( { $data_type:ident, $variant_name:ident, $suffix_name:ident, $scalar:ty, $scalar_ref:ty, $array:ty, $builder:ty }),*) => {
34 match (pair.as_ref().left(), pair.as_ref().right()) {
35 $( (Some(DataType::$data_type { .. }), Some(ArrayImpl::$variant_name(_))) => continue, )*
36 (data_type, array) => {
37 let array_ident = array.map(|a| a.get_ident());
38 return Err(format!(
39 "column type mismatched at position {i}: expected {data_type:?}, found {array_ident:?}"
40 ));
41 }
42 }
43 }
44 }
45
46 for_all_variants! { matches }
47 }
48
49 Ok(())
50}