Skip to content

Commit

Permalink
clamp max/min second
Browse files Browse the repository at this point in the history
  • Loading branch information
TCeason committed Nov 13, 2024
1 parent b1f4fce commit d7bca52
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 31 deletions.
12 changes: 6 additions & 6 deletions src/query/functions/src/scalars/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,22 +621,22 @@ fn register_string_to_date(registry: &mut FunctionRegistry) {
fn register_timestamp_to_date(registry: &mut FunctionRegistry) {
registry.register_passthrough_nullable_1_arg::<TimestampType, DateType, _, _>(
"to_date",
|ctx, _| {
|ctx, domain| {
FunctionDomain::Domain(SimpleDomain {
min: calc_timestamp_to_date(-30610224000000000, ctx.jiff_tz.clone()),
max: calc_timestamp_to_date(253402207200000000, ctx.jiff_tz.clone()),
min: calc_timestamp_to_date(domain.max, ctx.jiff_tz.clone()),
max: calc_timestamp_to_date(domain.min, ctx.jiff_tz.clone()),
})
},
eval_timestamp_to_date,
);
registry.register_combine_nullable_1_arg::<TimestampType, DateType, _, _>(
"try_to_date",
|ctx, _| {
|ctx, domain| {
FunctionDomain::Domain(NullableDomain {
has_null: false,
value: Some(Box::new(SimpleDomain {
min: calc_timestamp_to_date(-30610224000000000, ctx.jiff_tz.clone()),
max: calc_timestamp_to_date(253402207200000000, ctx.jiff_tz.clone()),
min: calc_timestamp_to_date(domain.min, ctx.jiff_tz.clone()),
max: calc_timestamp_to_date(domain.max, ctx.jiff_tz.clone()),
})),
})
},
Expand Down
27 changes: 2 additions & 25 deletions src/query/service/src/sessions/query_ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ use databend_storages_common_session::SessionState;
use databend_storages_common_session::TxnManagerRef;
use databend_storages_common_table_meta::meta::Location;
use databend_storages_common_table_meta::meta::TableSnapshot;
use jiff::tz;
use jiff::tz::TimeZone;
use jiff::Zoned;
use log::debug;
Expand Down Expand Up @@ -762,31 +761,9 @@ impl TableContext for QueryContext {
let tz_string = settings.get_timezone()?;
let tz = TzFactory::instance().get_by_name(&tz_string)?;
let jiff_tz = TimeZone::get(&tz_string).map_err(|e| {
let mut valid_tz = vec![];
for tz in tz::db().available() {
valid_tz.push(tz);
}
use std::fs;

// 读取 /etc 目录
println!("/usr/share/zoneinfo");
let mut path = Vec::new();
let mut er = Vec::new();
match fs::read_dir("/usr/share/zoneinfo") {
Ok(entries) => {
for entry in entries {
match entry {
Ok(entry) => path.push(format!("{}", entry.path().display())),
Err(err) => er.push(format!(" read with err: {}", err)),
}
}
}
Err(err) => er.push(format!("read /usr/share/zoneinfo: {}", err)),
}

ErrorCode::InvalidTimezone(format!(
"Timezone has been checked and should be valid {:?} , path is {:?}, err is {:?} but got error: {}",
valid_tz, path, er, e
"Timezone has been checked and should be valid but got error: {}",
e
))
})?;
let now = Zoned::now().with_time_zone(TimeZone::UTC);
Expand Down

0 comments on commit d7bca52

Please sign in to comment.