bigquery_functions/
lib.rs1use std::str::FromStr;
2
3mod json_types;
4pub mod types;
5
6pub fn get_bigquery_function_names() -> Vec<String> {
8 let contents = include_str!("../output/function_names.json");
9 let function_names: Vec<String> = serde_json::from_str(&contents).unwrap();
10 return function_names;
11}
12
13pub fn get_bigquery_function_categories() -> Vec<String> {
15 let contents = include_str!("../output/categories.json");
16 let categories: Vec<String> = serde_json::from_str(&contents).unwrap();
17 return categories;
18}
19
20pub fn get_bigquery_functions() -> Vec<types::Function> {
22 let contents = include_str!("../output/functions.json");
23 let functions: Vec<json_types::Function> = serde_json::from_str(&contents).unwrap();
24
25 let converted_functions = functions
26 .into_iter()
27 .map(|function| {
28 types::Function::new(
29 function.name,
30 function
31 .arguments
32 .into_iter()
33 .map(|argument| {
34 types::Argument::new(argument.name, argument.supported_argument_type)
35 })
36 .collect(),
37 types::Category::from_str(&function.category)
38 .unwrap_or(types::Category::NoCategory),
39 function.description_markdown,
40 )
41 })
42 .collect();
43
44 return converted_functions;
45}
46
47pub fn get_distinct_allowed_categories() -> [types::Category; 3] {
48 [
49 types::Category::Aggregate,
50 types::Category::Approximate_aggregate,
51 types::Category::HyperLogLog,
52 ]
53}
54
55#[cfg(test)]
56mod tests {
57 use super::*;
58 use crate::types::Category;
59
60 #[test]
61 fn test_get_bigquery_function_names() {
62 let function_names = get_bigquery_function_names();
63 assert_eq!(function_names.len(), 300);
64 }
65
66 #[test]
67 fn test_get_bigquery_function_categories() {
68 let categories = get_bigquery_function_categories();
69 assert_eq!(categories.len(), 25);
70 }
71
72 #[test]
73 fn test_get_bigquery_functions() {
74 let functions = get_bigquery_functions();
75 assert_eq!(functions.len(), 300);
76 }
77
78 #[test]
79 fn test_get_distinct_allowed_categories() {
80 let categories = get_distinct_allowed_categories();
81 assert_eq!(categories.len(), 3);
82 assert!(categories.contains(&Category::Aggregate));
83 assert!(categories.contains(&Category::Approximate_aggregate));
84 assert!(categories.contains(&Category::HyperLogLog));
85 }
86}