feat: Frontend show tables and databases (#504)

* feat: Frontend show tables and databases

Co-authored-by: luofucong <luofucong@greptime.com>
This commit is contained in:
LFC
2022-11-15 14:21:50 +08:00
committed by GitHub
parent 6e93c5e1de
commit 2c0d2da5a7
16 changed files with 299 additions and 239 deletions

View File

@@ -4,10 +4,12 @@ use std::any::Any;
use std::sync::Arc;
use arrow::array::Array;
use arrow::compute;
use arrow::datatypes::DataType as ArrowDataType;
use datafusion_common::ScalarValue;
use snafu::OptionExt;
use snafu::{OptionExt, ResultExt};
use crate::arrow_array::StringArray;
use crate::error::{ConversionSnafu, Result, UnknownVectorSnafu};
use crate::scalars::*;
use crate::vectors::date::DateVector;
@@ -193,6 +195,16 @@ impl Helper {
pub fn try_into_vectors(arrays: &[ArrayRef]) -> Result<Vec<VectorRef>> {
arrays.iter().map(Self::try_into_vector).collect()
}
pub fn like_utf8(names: Vec<String>, s: &str) -> Result<VectorRef> {
let array = StringArray::from_slice(&names);
let filter =
compute::like::like_utf8_scalar(&array, s).context(error::ArrowComputeSnafu)?;
let result = compute::filter::filter(&array, &filter).context(error::ArrowComputeSnafu)?;
Helper::try_into_vector(result)
}
}
#[cfg(test)]
@@ -250,4 +262,29 @@ mod tests {
assert_eq!(Value::DateTime(DateTime::new(42)), vector.get(i));
}
}
#[test]
fn test_like_utf8() {
fn assert_vector(expected: Vec<&str>, actual: &VectorRef) {
let actual = actual.as_any().downcast_ref::<StringVector>().unwrap();
assert_eq!(*actual, StringVector::from(expected));
}
let names: Vec<String> = vec!["greptime", "hello", "public", "world"]
.into_iter()
.map(|x| x.to_string())
.collect();
let ret = Helper::like_utf8(names.clone(), "%ll%").unwrap();
assert_vector(vec!["hello"], &ret);
let ret = Helper::like_utf8(names.clone(), "%time").unwrap();
assert_vector(vec!["greptime"], &ret);
let ret = Helper::like_utf8(names.clone(), "%ld").unwrap();
assert_vector(vec!["world"], &ret);
let ret = Helper::like_utf8(names, "%").unwrap();
assert_vector(vec!["greptime", "hello", "public", "world"], &ret);
}
}