Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions datafusion/functions/src/datetime/now.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ impl ScalarUDFImpl for NowFunc {
fn return_field_from_args(&self, _args: ReturnFieldArgs) -> Result<FieldRef> {
Ok(Field::new(
self.name(),
Timestamp(Nanosecond, Some("+00:00".into())),
Timestamp(Nanosecond, Some("+00".into())),
false,
)
.into())
Expand All @@ -106,8 +106,16 @@ impl ScalarUDFImpl for NowFunc {
.execution_props()
.query_execution_start_time
.timestamp_nanos_opt();

let timezone = info
.execution_props()
.config_options
.as_ref()
.map(|opts| opts.execution.time_zone.as_str())
.unwrap_or("+00");

Ok(ExprSimplifyResult::Simplified(Expr::Literal(
ScalarValue::TimestampNanosecond(now_ts, Some("+00:00".into())),
ScalarValue::TimestampNanosecond(now_ts, Some(timezone.into())),
None,
)))
}
Expand Down
2 changes: 1 addition & 1 deletion datafusion/sqllogictest/test_files/dates.slt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ g
h

## Plan error when compare Utf8 and timestamp in where clause
statement error DataFusion error: type_coercion\ncaused by\nError during planning: Cannot coerce arithmetic expression Timestamp\(Nanosecond, Some\("\+00:00"\)\) \+ Utf8 to valid types
statement error DataFusion error: type_coercion\ncaused by\nError during planning: Cannot coerce arithmetic expression Timestamp\(Nanosecond, Some\("\+00"\)\) \+ Utf8 to valid types
select i_item_desc from test
where d3_date > now() + '5 days';

Expand Down
10 changes: 10 additions & 0 deletions datafusion/sqllogictest/test_files/timestamps.slt
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ true
##########
## Current time Tests
##########
statement ok
SET TIME ZONE = '+08'

query T
select arrow_typeof(now());
----
Timestamp(Nanosecond, Some("+08"))

statement ok
SET TIME ZONE = '+00'

query B
select cast(now() as time) = current_time();
Expand Down
Loading