Skip to content

Commit

Permalink
spi-search:fix date.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljl committed Oct 17, 2023
1 parent 4e07a20 commit e66997f
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions spi/spi-search/src/search_enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,29 +358,29 @@ impl SearchQueryTimeWindowKind {
pub fn to_sql(&self, column_name: &str, is_date_time: bool) -> String {
if is_date_time {
match self {
SearchQueryTimeWindowKind::Date => format!("date(timezone('UTC', {column_name}))"),
SearchQueryTimeWindowKind::Date => format!("date(timezone('UTC', {column_name}::timestamp))"),
// SearchQueryTimeWindowKind::Hour => format!("date_part('hour',timezone('UTC', {column_name}))"),
SearchQueryTimeWindowKind::Hour => format!(
"CONCAT(date_part('year', timezone('UTC', {column_name})), '-',
LPAD(date_part('month', timezone('UTC', {column_name}))::text, 2, '0'), '-',
LPAD(date_part('day', timezone('UTC', {column_name}))::text, 2, '0'), ' ',
LPAD(date_part('hour', timezone('UTC', {column_name}))::text, 2, '0'))"
"CONCAT(date_part('year', timezone('UTC', {column_name}::timestamp)), '-',
LPAD(date_part('month', timezone('UTC', {column_name}::timestamp))::text, 2, '0'), '-',
LPAD(date_part('day', timezone('UTC', {column_name}::timestamp))::text, 2, '0'), ' ',
LPAD(date_part('hour', timezone('UTC', {column_name}::timestamp))::text, 2, '0'))"
),
// SearchQueryTimeWindowKind::Day => format!("date_part('day',timezone('UTC', {column_name}))"),
SearchQueryTimeWindowKind::Day => format!(
"CONCAT(date_part('year', timezone('UTC', {column_name})), '-',
LPAD(date_part('month', timezone('UTC', {column_name}))::text, 2, '0'), '-',
LPAD(date_part('day', timezone('UTC', {column_name}))::text, 2, '0'))"
"CONCAT(date_part('year', timezone('UTC', {column_name}::timestamp)), '-',
LPAD(date_part('month', timezone('UTC', {column_name}::timestamp))::text, 2, '0'), '-',
LPAD(date_part('day', timezone('UTC', {column_name}::timestamp))::text, 2, '0'))"
),
SearchQueryTimeWindowKind::Week => format!(
"CONCAT(date_part('year', timezone('UTC', {column_name})), ' ',
date_part('week', timezone('UTC', {column_name})))"
"CONCAT(date_part('year', timezone('UTC', {column_name}::timestamp)), ' ',
date_part('week', timezone('UTC', {column_name}::timestamp)))"
),
// SearchQueryTimeWindowKind::Month => format!("date_part('month',timezone('UTC', {column_name}))"),
SearchQueryTimeWindowKind::Month => {
format!("CONCAT(date_part('year', timezone('UTC',{column_name})), '-',LPAD(date_part('month', timezone('UTC', {column_name}))::text, 2, '0'))")
format!("CONCAT(date_part('year', timezone('UTC',{column_name}::timestamp)), '-',LPAD(date_part('month', timezone('UTC', {column_name}::timestamp))::text, 2, '0'))")
}
SearchQueryTimeWindowKind::Year => format!("CONCAT(date_part('year',timezone('UTC', {column_name})),'')"),
SearchQueryTimeWindowKind::Year => format!("CONCAT(date_part('year',timezone('UTC', {column_name}::timestamp)),'')"),
}
} else {
match self {
Expand All @@ -390,24 +390,24 @@ impl SearchQueryTimeWindowKind {
// SearchQueryTimeWindowKind::Month => format!("date_part('month', {column_name})"),
// SearchQueryTimeWindowKind::Year => format!("date_part('year', {column_name})"),
SearchQueryTimeWindowKind::Hour => format!(
"CONCAT(date_part('year', timezone('UTC', {column_name})), '-',
LPAD(date_part('month', timezone('UTC', {column_name}))::text, 2, '0'), '-',
LPAD(date_part('day', timezone('UTC', {column_name}))::text, 2, '0'), ' ',
LPAD(date_part('hour', timezone('UTC', {column_name}))::text, 2, '0'))"
"CONCAT(date_part('year', timezone('UTC', {column_name}::timestamp)), '-',
LPAD(date_part('month', timezone('UTC', {column_name}::timestamp))::text, 2, '0'), '-',
LPAD(date_part('day', timezone('UTC', {column_name}::timestamp))::text, 2, '0'), ' ',
LPAD(date_part('hour', timezone('UTC', {column_name}::timestamp))::text, 2, '0'))"
),
SearchQueryTimeWindowKind::Day => format!(
"CONCAT(date_part('year', timezone('UTC', {column_name})), '-',
LPAD(date_part('month', timezone('UTC', {column_name}))::text, 2, '0'), '-',
LPAD(date_part('day', timezone('UTC', {column_name}))::text, 2, '0'))"
"CONCAT(date_part('year', timezone('UTC', {column_name}::timestamp)), '-',
LPAD(date_part('month', timezone('UTC', {column_name}::timestamp))::text, 2, '0'), '-',
LPAD(date_part('day', timezone('UTC', {column_name}::timestamp))::text, 2, '0'))"
),
SearchQueryTimeWindowKind::Week => format!(
"CONCAT(date_part('year', timezone('UTC', {column_name})), ' ',
date_part('week', timezone('UTC', {column_name})))"
"CONCAT(date_part('year', timezone('UTC', {column_name}::timestamp)), ' ',
date_part('week', timezone('UTC', {column_name}::timestamp)))"
),
SearchQueryTimeWindowKind::Month => {
format!("CONCAT(date_part('year', timezone('UTC',{column_name})), '-',LPAD(date_part('month', timezone('UTC', {column_name}))::text, 2, '0'))")
format!("CONCAT(date_part('year', timezone('UTC',{column_name}::timestamp)), '-',LPAD(date_part('month', timezone('UTC', {column_name}::timestamp))::text, 2, '0'))")
}
SearchQueryTimeWindowKind::Year => format!("CONCAT(date_part('year',timezone('UTC', {column_name})),'')"),
SearchQueryTimeWindowKind::Year => format!("CONCAT(date_part('year',timezone('UTC', {column_name}::timestamp)),'')"),
}
}
}
Expand Down

0 comments on commit e66997f

Please sign in to comment.