Skip to content

Commit

Permalink
spi-search:add fn query_metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Oct 16, 2023
1 parent 6260ec1 commit 145ba06
Show file tree
Hide file tree
Showing 9 changed files with 1,100 additions and 9 deletions.
3 changes: 3 additions & 0 deletions basic/src/dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ impl BasicQueryCondInfo {
}
BasicQueryOpKind::In => check_val.as_array().map(|check_val_arr| check_val_arr.contains(&cond.value)).unwrap_or(false),
BasicQueryOpKind::NotIn => check_val.as_array().map(|check_val_arr| check_val_arr.contains(&cond.value)).unwrap_or(false),
BasicQueryOpKind::IsNUll => false,
BasicQueryOpKind::IsNotNUll => false,
BasicQueryOpKind::IsNullOrEmpty => false,
},
None => false,
})
Expand Down
1 change: 1 addition & 0 deletions spi/spi-search/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ spi-es = ["tardis/web-client"]
serde.workspace = true
tardis = { workspace = true, features = ["reldb-postgres", "web-server", "web-client"] }
bios-basic = { path = "../../basic", features = ["default"] }
strum = { workerspace = true, features = ["derive"] }

[dev-dependencies]
tardis = { workspace = true, features = ["test"] }
Expand Down
10 changes: 9 additions & 1 deletion spi/spi-search/src/api/ci/search_ci_item_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tardis::web::poem_openapi::param::Path;
use tardis::web::poem_openapi::payload::Json;
use tardis::web::web_resp::{TardisApiResult, TardisPage, TardisResp, Void};

use crate::dto::search_item_dto::{SearchItemAddReq, SearchItemModifyReq, SearchItemSearchReq, SearchItemSearchResp};
use crate::dto::search_item_dto::{SearchItemAddReq, SearchItemModifyReq, SearchItemSearchReq, SearchItemSearchResp, SearchQueryMetricsReq, SearchQueryMetricsResp};
use crate::serv::search_item_serv;

#[derive(Clone)]
Expand Down Expand Up @@ -45,4 +45,12 @@ impl SearchCiItemApi {
let resp = search_item_serv::search(&mut search_req.0, &funs, &ctx.0).await?;
TardisResp::ok(resp)
}

/// Query Metrics
#[oai(path = "/metrics", method = "put")]
async fn query_metrics(&self, query_req: Json<SearchQueryMetricsReq>, ctx: TardisContextExtractor) -> TardisApiResult<SearchQueryMetricsResp> {
let funs = crate::get_tardis_inst();
let resp = search_item_serv::query_metrics(&query_req.0, &funs, &ctx.0).await?;
TardisResp::ok(resp)
}
}
228 changes: 228 additions & 0 deletions spi/spi-search/src/dto/search_item_dto.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::HashMap;

use crate::search_enumeration::{SearchDataTypeKind, SearchQueryAggFunKind, SearchQueryTimeWindowKind};
use bios_basic::{basic_enumeration::BasicQueryOpKind, dto::BasicQueryCondInfo};
use serde::{Deserialize, Serialize};
use tardis::{
Expand Down Expand Up @@ -244,3 +245,230 @@ pub struct SearchItemSearchResp {
pub rank_title: f32,
pub rank_content: f32,
}

#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)]
pub struct SearchQueryMetricsReq {
pub tag: String,
pub kind: String,
pub select: Vec<SearchQueryMetricsSelectReq>,
pub ignore_distinct: Option<bool>,
pub group: Vec<SearchQueryDimensionGroupReq>,
pub ignore_group_rollup: Option<bool>,
pub _where: Option<Vec<Vec<SearchQueryMetricsWhereReq>>>,
pub dimension_order: Option<Vec<SearchQueryDimensionOrderReq>>,
pub metrics_order: Option<Vec<SearchQueryMetricsOrderReq>>,
pub group_order: Option<Vec<SearchQueryDimensionGroupOrderReq>>,
pub group_agg: Option<bool>,
pub having: Option<Vec<SearchQueryMetricsHavingReq>>,
pub start_time: DateTime<Utc>,
pub end_time: DateTime<Utc>,
// Search context for record permission filtering
pub ctx: SearchItemSearchCtxReq,
pub limit: Option<u32>,
}

#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)]
pub struct SearchQueryMetricsSelectReq {
pub in_ext: Option<bool>,
pub multi_values: Option<bool>,
pub data_type: SearchDataTypeKind,
/// Measure column key
pub code: String,
/// Aggregate function
pub fun: SearchQueryAggFunKind,
}

#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)]
pub struct SearchQueryDimensionGroupReq {
pub in_ext: Option<bool>,
pub multi_values: Option<bool>,
pub data_type: SearchDataTypeKind,
/// Dimension column key
pub code: String,
/// Time window function
pub time_window: Option<SearchQueryTimeWindowKind>,
}

#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)]
pub struct SearchQueryMetricsWhereReq {
pub in_ext: Option<bool>,
pub multi_values: Option<bool>,
pub data_type: SearchDataTypeKind,
/// Dimension or measure column key
pub code: String,
/// Operator
pub op: BasicQueryOpKind,
/// Value
pub value: Value,
/// Time window function
pub time_window: Option<SearchQueryTimeWindowKind>,
}

#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)]
pub struct SearchQueryDimensionOrderReq {
pub in_ext: Option<bool>,
/// Dimension column key
pub code: String,
/// Sort direction
pub asc: bool,
}

#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)]
pub struct SearchQueryMetricsOrderReq {
pub in_ext: Option<bool>,
/// Measure column key
pub code: String,
pub fun: SearchQueryAggFunKind,
/// Sort direction
pub asc: bool,
}

#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)]
pub struct SearchQueryDimensionGroupOrderReq {
pub in_ext: Option<bool>,
/// Dimension column key
pub code: String,
/// Time window function
pub time_window: Option<SearchQueryTimeWindowKind>,
/// Sort direction
pub asc: bool,
}
#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)]
pub struct SearchQueryMetricsHavingReq {
pub in_ext: Option<bool>,
pub multi_values: Option<bool>,
pub data_type: SearchDataTypeKind,
/// Measure Column key
pub code: String,
/// Aggregate function
pub fun: SearchQueryAggFunKind,
/// Operator
pub op: BasicQueryOpKind,
/// Value
pub value: Value,
}

/// Query Metrics Response
#[derive(poem_openapi::Object, Serialize, Deserialize, Debug)]
pub struct SearchQueryMetricsResp {
/// Fact key
pub from: String,
/// Show names
///
/// key = alias name, value = show name
///
/// The format of the alias: `field name__<function name>`
pub show_names: HashMap<String, String>,
/// Group
///
/// Format with only one level (single dimension):
/// map
/// ```
/// {
/// "":{ // The root group
/// "alias name1":value,
/// "alias name...":value,
/// },
/// "<group name1>" {
/// "alias name1":value,
/// "alias name...":value,
/// }
/// "<group name...>" {
/// "alias name1":value,
/// "alias name...":value,
/// }
/// }
/// ```
/// array
/// ```
/// [
/// {
/// "name": "<group name1>",
/// "value": value
/// },
///
/// ]
/// ```
///
/// Format with multiple levels (multiple dimensions):
/// ```
/// {
/// "":{ // The root group
/// "": {
/// "alias name1":value,
/// "alias name...":value,
/// }
/// },
/// "<group name1>" {
/// "": {
/// "alias name1":value,
/// "alias name...":value,
/// },
/// "<sub group name...>": {
/// "alias name1":value,
/// "alias name...":value,
/// }
/// }
/// "<group name...>" {
/// "": {
/// "alias name1":value,
/// "alias name...":value,
/// },
/// "<sub group name...>": {
/// "alias name1":value,
/// "alias name...":value,
/// }
/// }
/// }
/// ```
///
/// # Example
/// ```
/// {
/// "from": "req",
/// "show_names": {
/// "ct__date": "创建时间",
/// "act_hours__sum": "实例工时",
/// "status__": "状态",
/// "plan_hours__sum": "计划工时"
/// },
/// "group": {
/// "": {
/// "": {
/// "act_hours__sum": 180,
/// "plan_hours__sum": 330
/// }
/// },
/// "2023-01-01": {
/// "": {
/// "act_hours__sum": 120,
/// "plan_hours__sum": 240
/// },
/// "open": {
/// "act_hours__sum": 80,
/// "plan_hours__sum": 160
/// },
/// "close": {
/// "act_hours__sum": 40,
/// "plan_hours__sum": 80
/// }
/// }
/// "2023-01-02": {
/// "": {
/// "act_hours__sum": 60,
/// "plan_hours__sum": 90
/// },
/// "open": {
/// "act_hours__sum": 40,
/// "plan_hours__sum": 60
/// },
/// "progress": {
/// "act_hours__sum": 20,
/// "plan_hours__sum": 30
/// }
/// }
/// }
/// }
/// ```
pub group: Value,
}
1 change: 1 addition & 0 deletions spi/spi-search/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod api;
pub mod dto;
pub mod search_config;
pub mod search_constants;
pub mod search_enumeration;
pub mod search_initializer;
pub(crate) use crate::search_initializer::get_tardis_inst;
mod serv;
Loading

0 comments on commit 145ba06

Please sign in to comment.