datafusion_table_providers/util/
indexes.rs1use std::fmt::{self, Display, Formatter};
2
3#[derive(Debug, Clone, Copy, PartialEq, Default)]
4pub enum IndexType {
5 #[default]
6 Enabled,
7 Unique,
8}
9
10impl From<&str> for IndexType {
11 fn from(index_type: &str) -> Self {
12 match index_type.to_lowercase().as_str() {
13 "unique" => IndexType::Unique,
14 _ => IndexType::Enabled,
15 }
16 }
17}
18
19impl Display for IndexType {
20 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
21 match self {
22 IndexType::Unique => write!(f, "unique"),
23 IndexType::Enabled => write!(f, "enabled"),
24 }
25 }
26}
27
28#[cfg(test)]
29mod tests {
30 use std::collections::HashMap;
31
32 use super::*;
33
34 #[test]
35 fn test_index_type_from_str() {
36 assert_eq!(IndexType::from("unique"), IndexType::Unique);
37 assert_eq!(IndexType::from("enabled"), IndexType::Enabled);
38 assert_eq!(IndexType::from("Enabled"), IndexType::Enabled);
39 assert_eq!(IndexType::from("ENABLED"), IndexType::Enabled);
40 }
41
42 #[test]
43 fn test_indexes_from_option_string() {
44 let indexes_option_str = "index1:unique;index2";
45 let indexes: HashMap<String, IndexType> =
46 crate::util::hashmap_from_option_string(indexes_option_str);
47 assert_eq!(indexes.len(), 2);
48 assert_eq!(indexes.get("index1"), Some(&IndexType::Unique));
49 assert_eq!(indexes.get("index2"), Some(&IndexType::Enabled));
50 }
51}