refactor(query): tests from query/tests to query/src (#973)

* refactor(query): tests from query/tests to query/src

* chore(query): address rust fmt issues

* chore(query): add licence header
This commit is contained in:
Eugene Tolbakov
2023-02-12 12:55:17 +00:00
committed by GitHub
parent e77a7f253c
commit c06e04afbb
14 changed files with 83 additions and 55 deletions

View File

@@ -26,6 +26,8 @@ pub mod plan;
pub mod planner;
pub mod query_engine;
pub mod sql;
#[cfg(test)]
mod tests;
pub use crate::datafusion::DfContextProviderAdapter;
pub use crate::query_engine::{

27
src/query/src/tests.rs Normal file
View File

@@ -0,0 +1,27 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
mod argmax_test;
mod argmin_test;
mod mean_test;
mod my_sum_udaf_example;
mod percentile_test;
mod polyval_test;
mod query_engine_test;
mod scipy_stats_norm_cdf_test;
mod scipy_stats_norm_pdf;
mod time_range_filter_test;
mod function;
mod pow;

View File

@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
mod function;
use std::sync::Arc;
use common_query::Output;
@@ -22,11 +20,13 @@ use common_recordbatch::{util, RecordBatch};
use datatypes::for_all_primitive_types;
use datatypes::prelude::*;
use datatypes::types::WrapperType;
use query::error::Result;
use query::parser::QueryLanguageParser;
use query::QueryEngine;
use session::context::QueryContext;
use crate::error::Result;
use crate::parser::QueryLanguageParser;
use crate::tests::function;
use crate::QueryEngine;
#[tokio::test]
async fn test_argmax_aggregator() -> Result<()> {
common_telemetry::init_default_ut_logging();

View File

@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
mod function;
use std::sync::Arc;
use common_query::Output;
@@ -22,11 +20,13 @@ use common_recordbatch::{util, RecordBatch};
use datatypes::for_all_primitive_types;
use datatypes::prelude::*;
use datatypes::types::WrapperType;
use query::error::Result;
use query::parser::QueryLanguageParser;
use query::QueryEngine;
use session::context::QueryContext;
use crate::error::Result;
use crate::parser::QueryLanguageParser;
use crate::tests::function;
use crate::QueryEngine;
#[tokio::test]
async fn test_argmin_aggregator() -> Result<()> {
common_telemetry::init_default_ut_logging();

View File

@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
// FIXME(yingwen): Consider move all tests under query/tests to query/src so we could reuse
// more codes.
use std::sync::Arc;
use catalog::local::{MemoryCatalogManager, MemoryCatalogProvider, MemorySchemaProvider};
@@ -26,13 +24,13 @@ use datatypes::prelude::*;
use datatypes::schema::{ColumnSchema, Schema};
use datatypes::types::WrapperType;
use datatypes::vectors::Helper;
use query::parser::QueryLanguageParser;
use query::query_engine::QueryEngineFactory;
use query::QueryEngine;
use rand::Rng;
use session::context::QueryContext;
use table::test_util::MemTable;
use crate::parser::QueryLanguageParser;
use crate::{QueryEngine, QueryEngineFactory};
pub fn create_query_engine() -> Arc<dyn QueryEngine> {
let schema_provider = Arc::new(MemorySchemaProvider::new());
let catalog_provider = Arc::new(MemoryCatalogProvider::new());

View File

@@ -12,8 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
mod function;
use std::sync::Arc;
use common_query::Output;
@@ -25,11 +23,13 @@ use datatypes::types::WrapperType;
use datatypes::value::OrderedFloat;
use format_num::NumberFormat;
use num_traits::AsPrimitive;
use query::error::Result;
use query::parser::QueryLanguageParser;
use query::QueryEngine;
use session::context::QueryContext;
use crate::error::Result;
use crate::parser::QueryLanguageParser;
use crate::tests::function;
use crate::QueryEngine;
#[tokio::test]
async fn test_mean_aggregator() -> Result<()> {
common_telemetry::init_default_ut_logging();

View File

@@ -32,12 +32,13 @@ use datatypes::types::{LogicalPrimitiveType, WrapperType};
use datatypes::vectors::Helper;
use datatypes::with_match_primitive_type_id;
use num_traits::AsPrimitive;
use query::error::Result;
use query::parser::QueryLanguageParser;
use query::QueryEngineFactory;
use session::context::QueryContext;
use table::test_util::MemTable;
use crate::error::Result;
use crate::parser::QueryLanguageParser;
use crate::QueryEngineFactory;
#[derive(Debug, Default)]
struct MySumAccumulator<T, SumT> {
sum: SumT,

View File

@@ -13,7 +13,7 @@
// limitations under the License.
use std::sync::Arc;
mod function;
use catalog::local::{MemoryCatalogManager, MemoryCatalogProvider, MemorySchemaProvider};
use catalog::{CatalogList, CatalogProvider, SchemaProvider};
use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME};
@@ -26,12 +26,14 @@ use datatypes::schema::{ColumnSchema, Schema};
use datatypes::vectors::Int32Vector;
use function::{create_query_engine, get_numbers_from_table};
use num_traits::AsPrimitive;
use query::error::Result;
use query::parser::QueryLanguageParser;
use query::{QueryEngine, QueryEngineFactory};
use session::context::QueryContext;
use table::test_util::MemTable;
use crate::error::Result;
use crate::parser::QueryLanguageParser;
use crate::tests::function;
use crate::{QueryEngine, QueryEngineFactory};
#[tokio::test]
async fn test_percentile_aggregator() -> Result<()> {
common_telemetry::init_default_ut_logging();

View File

@@ -13,7 +13,6 @@
// limitations under the License.
use std::sync::Arc;
mod function;
use common_query::Output;
use common_recordbatch::error::Result as RecordResult;
@@ -22,11 +21,13 @@ use datatypes::for_all_primitive_types;
use datatypes::prelude::*;
use datatypes::types::WrapperType;
use num_traits::AsPrimitive;
use query::error::Result;
use query::parser::QueryLanguageParser;
use query::QueryEngine;
use session::context::QueryContext;
use crate::error::Result;
use crate::parser::QueryLanguageParser;
use crate::tests::function;
use crate::QueryEngine;
#[tokio::test]
async fn test_polyval_aggregator() -> Result<()> {
common_telemetry::init_default_ut_logging();

View File

@@ -12,13 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.
mod pow;
// This is used to suppress the warning: function `create_query_engine` is never used.
// FIXME(yingwen): We finally need to refactor these tests and move them to `query/src`
// so tests can share codes with other mods.
#[allow(unused)]
mod function;
use std::sync::Arc;
use catalog::local::{MemoryCatalogManager, MemoryCatalogProvider, MemorySchemaProvider};
@@ -34,18 +27,18 @@ use datafusion_expr::logical_plan::builder::LogicalPlanBuilder;
use datatypes::prelude::*;
use datatypes::schema::{ColumnSchema, Schema};
use datatypes::vectors::UInt32Vector;
use query::error::{QueryExecutionSnafu, Result};
use query::parser::QueryLanguageParser;
use query::plan::LogicalPlan;
use query::query_engine::options::QueryOptions;
use query::query_engine::QueryEngineFactory;
use session::context::QueryContext;
use snafu::ResultExt;
use table::table::adapter::DfTableProviderAdapter;
use table::table::numbers::NumbersTable;
use table::test_util::MemTable;
use crate::pow::pow;
use crate::error::{QueryExecutionSnafu, Result};
use crate::parser::QueryLanguageParser;
use crate::plan::LogicalPlan;
use crate::query_engine::options::QueryOptions;
use crate::query_engine::QueryEngineFactory;
use crate::tests::pow::pow;
#[tokio::test]
async fn test_datafusion_query_engine() -> Result<()> {

View File

@@ -13,7 +13,6 @@
// limitations under the License.
use std::sync::Arc;
mod function;
use common_query::Output;
use common_recordbatch::error::Result as RecordResult;
@@ -21,13 +20,15 @@ use common_recordbatch::{util, RecordBatch};
use datatypes::for_all_primitive_types;
use datatypes::types::WrapperType;
use num_traits::AsPrimitive;
use query::error::Result;
use query::parser::QueryLanguageParser;
use query::QueryEngine;
use session::context::QueryContext;
use statrs::distribution::{ContinuousCDF, Normal};
use statrs::statistics::Statistics;
use crate::error::Result;
use crate::parser::QueryLanguageParser;
use crate::tests::function;
use crate::QueryEngine;
#[tokio::test]
async fn test_scipy_stats_norm_cdf_aggregator() -> Result<()> {
common_telemetry::init_default_ut_logging();

View File

@@ -13,7 +13,6 @@
// limitations under the License.
use std::sync::Arc;
mod function;
use common_query::Output;
use common_recordbatch::error::Result as RecordResult;
@@ -21,13 +20,15 @@ use common_recordbatch::{util, RecordBatch};
use datatypes::for_all_primitive_types;
use datatypes::types::WrapperType;
use num_traits::AsPrimitive;
use query::error::Result;
use query::parser::QueryLanguageParser;
use query::QueryEngine;
use session::context::QueryContext;
use statrs::distribution::{Continuous, Normal};
use statrs::statistics::Statistics;
use crate::error::Result;
use crate::parser::QueryLanguageParser;
use crate::tests::function;
use crate::QueryEngine;
#[tokio::test]
async fn test_scipy_stats_norm_pdf_aggregator() -> Result<()> {
common_telemetry::init_default_ut_logging();

View File

@@ -26,7 +26,6 @@ use common_time::Timestamp;
use datatypes::data_type::ConcreteDataType;
use datatypes::schema::{ColumnSchema, Schema, SchemaRef};
use datatypes::vectors::{Int64Vector, TimestampMillisecondVector};
use query::QueryEngineRef;
use session::context::QueryContext;
use table::metadata::{FilterPushDownType, TableInfoRef};
use table::predicate::TimeRangePredicateBuilder;
@@ -34,6 +33,9 @@ use table::test_util::MemTable;
use table::Table;
use tokio::sync::RwLock;
use crate::parser::QueryLanguageParser;
use crate::{QueryEngineFactory, QueryEngineRef};
struct MemTableWrapper {
inner: MemTable,
filter: RwLock<Vec<Expr>>,
@@ -115,7 +117,7 @@ fn create_test_engine() -> TimeRangeTester {
.register_catalog("greptime".to_string(), default_catalog)
.unwrap();
let engine = query::QueryEngineFactory::new(catalog_list).query_engine();
let engine = QueryEngineFactory::new(catalog_list).query_engine();
TimeRangeTester { engine, table }
}
@@ -126,7 +128,7 @@ struct TimeRangeTester {
impl TimeRangeTester {
async fn check(&self, sql: &str, expect: TimestampRange) {
let stmt = query::parser::QueryLanguageParser::parse_sql(sql).unwrap();
let stmt = QueryLanguageParser::parse_sql(sql).unwrap();
let _ = self
.engine
.execute(