Skip to content

Commit 9ea67f5

Browse files
Omega359alamb
andauthored
Change default time_zone to None (was "+00:00") (#18359)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes - #18204 - #18081 - fixes #18219 as a side effect ## Rationale for this change Default timezone was previously zulu however with the recent change to support default tz in now(), current_date(), etc which used to have no default tz the choice was made to unset the system wide timezone. ## What changes are included in this PR? Code, tests, upgrading doc. ## Are these changes tested? Yes, with existing tests. ## Are there any user-facing changes? Yes. Any query that used to use the default timezone would return a timestamp with a timezone of 'Z' will now return a timestamp without a timezone. This can be changed back to the previous behaviour with the sql ```sql SET TIMEZONE = '+00:00'; ``` --------- Co-authored-by: Andrew Lamb <[email protected]>
1 parent 69e189d commit 9ea67f5

File tree

19 files changed

+98
-64
lines changed

19 files changed

+98
-64
lines changed

datafusion/common/src/config.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,8 @@ config_namespace! {
467467

468468
/// The default time zone
469469
///
470-
/// Some functions, e.g. `EXTRACT(HOUR from SOME_TIME)`, shift the underlying datetime
471-
/// according to this time zone, and then extract the hour
472-
pub time_zone: String, default = "+00:00".into()
470+
/// Some functions, e.g. `now` return timestamps in this time zone
471+
pub time_zone: Option<String>, default = None
473472

474473
/// Parquet options
475474
pub parquet: ParquetOptions, default = Default::default()

datafusion/core/tests/expr_api/simplification.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ fn multiple_now() -> Result<()> {
514514
// expect the same timestamp appears in both exprs
515515
let actual = get_optimized_plan_formatted(plan, &time);
516516
let expected = format!(
517-
"Projection: TimestampNanosecond({}, Some(\"+00:00\")) AS now(), TimestampNanosecond({}, Some(\"+00:00\")) AS t2\n TableScan: test",
517+
"Projection: TimestampNanosecond({}, None) AS now(), TimestampNanosecond({}, None) AS t2\n TableScan: test",
518518
time.timestamp_nanos_opt().unwrap(),
519519
time.timestamp_nanos_opt().unwrap()
520520
);

datafusion/core/tests/user_defined/user_defined_scalar_functions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ async fn test_config_options_work_for_scalar_func() -> Result<()> {
18121812
});
18131813

18141814
let mut config = SessionConfig::new();
1815-
config.options_mut().execution.time_zone = "AEST".into();
1815+
config.options_mut().execution.time_zone = Some("AEST".into());
18161816

18171817
let ctx = SessionContext::new_with_config(config);
18181818

datafusion/functions/src/datetime/current_date.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,14 @@ impl ScalarUDFImpl for CurrentDateFunc {
108108
let days = info
109109
.execution_props()
110110
.config_options()
111-
.and_then(|config| config.execution.time_zone.parse::<Tz>().ok())
111+
.and_then(|config| {
112+
config
113+
.execution
114+
.time_zone
115+
.as_ref()
116+
.map(|tz| tz.parse::<Tz>().ok())
117+
})
118+
.flatten()
112119
.map_or_else(
113120
|| datetime_to_days(&now_ts),
114121
|tz| {

datafusion/functions/src/datetime/current_time.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,14 @@ impl ScalarUDFImpl for CurrentTimeFunc {
104104
let nano = info
105105
.execution_props()
106106
.config_options()
107-
.and_then(|config| config.execution.time_zone.parse::<Tz>().ok())
107+
.and_then(|config| {
108+
config
109+
.execution
110+
.time_zone
111+
.as_ref()
112+
.map(|tz| tz.parse::<Tz>().ok())
113+
})
114+
.flatten()
108115
.map_or_else(
109116
|| datetime_to_time_nanos(&now_ts),
110117
|tz| {
@@ -167,7 +174,11 @@ mod tests {
167174

168175
fn set_session_timezone_env(tz: &str, start_time: DateTime<Utc>) -> MockSimplifyInfo {
169176
let mut config = datafusion_common::config::ConfigOptions::default();
170-
config.execution.time_zone = tz.to_string();
177+
config.execution.time_zone = if tz.is_empty() {
178+
None
179+
} else {
180+
Some(tz.to_string())
181+
};
171182
let mut execution_props =
172183
ExecutionProps::new().with_query_execution_start_time(start_time);
173184
execution_props.config_options = Some(Arc::new(config));

datafusion/functions/src/datetime/now.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use datafusion_macros::user_doc;
3333
#[user_doc(
3434
doc_section(label = "Time and Date Functions"),
3535
description = r#"
36-
Returns the current UTC timestamp.
36+
Returns the current timestamp in the system configured timezone (None by default).
3737
3838
The `now()` return value is determined at query time and will return the same timestamp, no matter when in the query plan the function executes.
3939
"#,
@@ -58,8 +58,7 @@ impl NowFunc {
5858
///
5959
/// Prefer [`NowFunc::new_with_config`] which allows specifying the
6060
/// timezone via [`ConfigOptions`]. This helper now mirrors the
61-
/// canonical default offset (`"+00:00"`) provided by
62-
/// `ConfigOptions::default()`.
61+
/// canonical default offset (None) provided by `ConfigOptions::default()`.
6362
pub fn new() -> Self {
6463
Self::new_with_config(&ConfigOptions::default())
6564
}
@@ -68,7 +67,11 @@ impl NowFunc {
6867
Self {
6968
signature: Signature::nullary(Volatility::Stable),
7069
aliases: vec!["current_timestamp".to_string()],
71-
timezone: Some(Arc::from(config.execution.time_zone.as_str())),
70+
timezone: config
71+
.execution
72+
.time_zone
73+
.as_ref()
74+
.map(|tz| Arc::from(tz.as_str())),
7275
}
7376
}
7477
}
@@ -178,6 +181,6 @@ mod tests {
178181
ScalarValue::TimestampNanosecond(None, configured_now.timezone.clone());
179182

180183
assert_eq!(legacy_scalar, configured_scalar);
181-
assert_eq!(Some("+00:00"), legacy_now.timezone.as_deref());
184+
assert_eq!(None, legacy_now.timezone.as_deref());
182185
}
183186
}

datafusion/sql/src/planner.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
693693
// Timestamp With Time Zone
694694
// INPUT : [SQLDataType] TimestampTz + [Config] Time Zone
695695
// OUTPUT: [ArrowDataType] Timestamp<TimeUnit, Some(Time Zone)>
696-
Some(self.context_provider.options().execution.time_zone.clone())
696+
self.context_provider.options().execution.time_zone.clone()
697697
} else {
698698
// Timestamp Without Time zone
699699
None

datafusion/sqllogictest/test_files/arrow_typeof.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ Timestamp(ns)
6767
query T
6868
SELECT arrow_typeof(now())
6969
----
70-
Timestamp(ns, "+00:00")
70+
Timestamp(ns)
7171

7272
# arrow_typeof_timestamp_date32(
7373
query T

datafusion/sqllogictest/test_files/dates.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ where d3_date > now() + '5 days';
9191
----
9292
DataFusion error: type_coercion
9393
caused by
94-
Error during planning: Cannot coerce arithmetic expression Timestamp(ns, "+00:00") + Utf8 to valid types
94+
Error during planning: Cannot coerce arithmetic expression Timestamp(ns) + Utf8 to valid types
9595

9696

9797
# DATE minus DATE

datafusion/sqllogictest/test_files/ddl.slt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ query TTTTTT
867867
show columns FROM table_with_pk;
868868
----
869869
datafusion public table_with_pk sn Int32 NO
870-
datafusion public table_with_pk ts Timestamp(ns, "+00:00") NO
870+
datafusion public table_with_pk ts Timestamp(ns) NO
871871
datafusion public table_with_pk currency Utf8View NO
872872
datafusion public table_with_pk amount Float32 YES
873873

0 commit comments

Comments
 (0)