| 134 | /// representation. Perhaps the two types can be unified later |
| 135 | #[allow(dead_code)] |
| 136 | pub fn to_internal(&self) -> Result<metadata::Filter, WaCustomError> { |
| 137 | let filter_err = |msg: &str| { |
| 138 | WaCustomError::MetadataError(metadata::Error::UnsupportedFilter(msg.to_string())) |
| 139 | }; |
| 140 | match self { |
| 141 | Self::Comparison { column } => { |
| 142 | if column.len() == 1 { |
| 143 | let (key, cop) = column.iter().next().unwrap(); |
| 144 | let pred = cop.to_predicate(key); |
| 145 | Ok(metadata::Filter::Is(pred)) |
| 146 | } else { |
| 147 | let mut preds = vec![]; |
| 148 | for (key, cop) in column.iter() { |
| 149 | preds.push(cop.to_predicate(key)); |
| 150 | } |
| 151 | Ok(metadata::Filter::And(preds)) |
| 152 | } |
| 153 | } |
| 154 | Self::Logical(LogicalOperator::And(filters)) => { |
| 155 | let mut preds = vec![]; |
| 156 | for f in filters { |
| 157 | match f { |
| 158 | Filter::Comparison { column } => { |
| 159 | for (key, cop) in column.iter() { |
| 160 | preds.push(cop.to_predicate(key)); |
| 161 | } |
| 162 | } |
| 163 | // @NOTE: Nested predicates are not |
| 164 | // supported. |
| 165 | Filter::Logical(_) => { |
| 166 | return Err(filter_err("nested predicates not supported")) |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | Ok(metadata::Filter::And(preds)) |
| 171 | } |
| 172 | Self::Logical(LogicalOperator::Or(filters)) => { |
| 173 | let mut preds = vec![]; |
| 174 | for f in filters { |
| 175 | match f { |
| 176 | Filter::Comparison { column } => { |
| 177 | if column.len() > 1 { |
| 178 | // @NOTE: Mixing And and Or predicates |
| 179 | // is not supported. Perhaps change |
| 180 | // the error type to add a message |
| 181 | return Err(filter_err("mixing and, or predicates not supported")); |
| 182 | } |
| 183 | for (key, cop) in column.iter() { |
| 184 | preds.push(cop.to_predicate(key)); |
| 185 | } |
| 186 | } |
| 187 | // @NOTE: Nested predicates are not |
| 188 | // supported. Perhaps change the error type to |
| 189 | // add a message |
| 190 | Filter::Logical(_) => { |
| 191 | return Err(filter_err("nested predicates not supported")) |
| 192 | } |
| 193 | } |