Skip to content

Commit

Permalink
spi-search: fix group multi_values.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Oct 19, 2023
1 parent 2699b3d commit aab3424
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 2 additions & 4 deletions spi/spi-search/src/search_enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,8 @@ impl SearchDataTypeKind {
)
}

pub(crate) fn to_pg_group(&self, column_name: &str, multi_values: bool, time_window_fun: &Option<SearchQueryTimeWindowKind>) -> Option<String> {
if multi_values {
Some(format!("unnest({})", column_name))
} else if let Some(time_window_fun) = time_window_fun {
pub(crate) fn to_pg_group(&self, column_name: &str, time_window_fun: &Option<SearchQueryTimeWindowKind>) -> Option<String> {
if let Some(time_window_fun) = time_window_fun {
if self != &SearchDataTypeKind::Date && self != &SearchDataTypeKind::DateTime {
return None;
}
Expand Down
15 changes: 10 additions & 5 deletions spi/spi-search/src/serv/pg/search_pg_item_serv.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::collections::HashMap;

use bios_basic::{basic_enumeration::BasicQueryOpKind, dto::BasicQueryCondInfo, helper::db_helper, spi::spi_funs::SpiBsInst};
use tardis::{
basic::{dto::TardisContext, error::TardisError, result::TardisResult},
chrono::Utc,
Expand All @@ -9,10 +8,12 @@ use tardis::{
sea_orm::{FromQueryResult, Value},
},
serde_json::{self, json, Map},
web::web_resp::TardisPage,
TardisFuns, TardisFunsInst,
TardisFuns,
TardisFunsInst, web::web_resp::TardisPage,
};

use bios_basic::{basic_enumeration::BasicQueryOpKind, dto::BasicQueryCondInfo, helper::db_helper, spi::spi_funs::SpiBsInst};

use crate::dto::search_item_dto::{
AdvBasicQueryCondInfo, SearchItemAddReq, SearchItemModifyReq, SearchItemSearchQScopeKind, SearchItemSearchReq, SearchItemSearchResp, SearchQueryMetricsReq,
SearchQueryMetricsResp,
Expand Down Expand Up @@ -1096,7 +1097,11 @@ pub async fn query_metrics(query_req: &SearchQueryMetricsReq, funs: &TardisFunsI
}
for group in &query_req.group {
if group.in_ext.unwrap_or(true) {
sql_part_inner_selects.push(format!("fact.ext ->> '{}' AS {}", &group.code, &group.code));
if group.multi_values.unwrap_or(false) {
sql_part_inner_selects.push(format!("jsonb_array_elements(fact.ext -> '{}') AS {}", &group.code, &group.code));
}else {
sql_part_inner_selects.push(format!("fact.ext ->> '{}' AS {}", &group.code, &group.code));
}
} else {
sql_part_inner_selects.push(format!("fact.{} AS {}", &group.code, &group.code));
}
Expand All @@ -1107,7 +1112,7 @@ pub async fn query_metrics(query_req: &SearchQueryMetricsReq, funs: &TardisFunsI
// (column name with fun, alias name, show name)
let mut sql_part_group_infos = vec![];
for group in &query_req.group {
if let Some(column_name_with_fun) = group.data_type.to_pg_group(&format!("_.{}", &group.code), group.multi_values.unwrap_or(false), &group.time_window) {
if let Some(column_name_with_fun) = group.data_type.to_pg_group(&format!("_.{}", &group.code), &group.time_window) {
let alias_name = format!(
"{}{}{FUNCTION_SUFFIX_FLAG}{}",
group.code,
Expand Down

0 comments on commit aab3424

Please sign in to comment.