Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
34 changes: 33 additions & 1 deletion datafusion/core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ pub const OPT_COALESCE_TARGET_BATCH_SIZE: &str =
pub const OPT_OPTIMIZER_SKIP_FAILED_RULES: &str =
"datafusion.optimizer.skip_failed_rules";

/// Configuration option "datafusion.execution.time_zone"
pub const OPT_TIME_ZONE: &str = "datafusion.execution.time_zone";

/// Definition of a configuration option
pub struct ConfigDefinition {
/// key used to identifier this configuration option
Expand Down Expand Up @@ -102,6 +105,20 @@ impl ConfigDefinition {
ScalarValue::UInt64(Some(default_value)),
)
}

/// Create a configuration option definition with a string value
pub fn new_string(
key: impl Into<String>,
description: impl Into<String>,
default_value: String,
) -> Self {
Self::new(
key,
description,
DataType::Utf8,
ScalarValue::Utf8(Some(default_value)),
)
}
}

/// Contains definitions for all built-in configuration options
Expand Down Expand Up @@ -167,7 +184,14 @@ impl BuiltInConfigs {
messages if any optimization rules produce errors and then proceed to the next \
rule. When set to false, any rules that produce errors will cause the query to fail.",
true
)],
),
ConfigDefinition::new_string(
OPT_TIME_ZONE,
"The session time zone which some function require \
e.g. EXTRACT(HOUR from SOME_TIME) shift the underline datetime according to the time zone,
then extract the hour",
"UTC".into()
)]
}
}

Expand Down Expand Up @@ -279,6 +303,14 @@ impl ConfigOptions {
}
}

/// get a string configuration option
pub fn get_string(&self, key: &str) -> String {
match self.get(key) {
Some(ScalarValue::Utf8(Some(s))) => s,
_ => "".into(),
}
}

/// Access the underlying hashmap
pub fn options(&self) -> &HashMap<String, ScalarValue> {
&self.options
Expand Down
38 changes: 38 additions & 0 deletions datafusion/core/tests/sql/information_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,3 +703,41 @@ async fn show_all() {
.len();
assert_eq!(expected_length, results[0].num_rows());
}

#[tokio::test]
async fn show_time_zone_default_utc() {
// https://github.com/apache/arrow-datafusion/issues/3255
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
let sql = "SHOW TIME ZONE";
let results = plan_and_collect(&ctx, sql).await.unwrap();

let expected = vec![
"+--------------------------------+---------+",
"| name | setting |",
"+--------------------------------+---------+",
"| datafusion.execution.time_zone | UTC |",
"+--------------------------------+---------+",
];

assert_batches_eq!(expected, &results);
}

#[tokio::test]
async fn show_timezone_default_utc() {
// https://github.com/apache/arrow-datafusion/issues/3255
let ctx =
SessionContext::with_config(SessionConfig::new().with_information_schema(true));
let sql = "SHOW TIMEZONE";
let results = plan_and_collect(&ctx, sql).await.unwrap();

let expected = vec![
"+--------------------------------+---------+",
"| name | setting |",
"+--------------------------------+---------+",
"| datafusion.execution.time_zone | UTC |",
"+--------------------------------+---------+",
];

assert_batches_eq!(expected, &results);
}
7 changes: 6 additions & 1 deletion datafusion/sql/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2386,8 +2386,13 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
));
}

let query = if variable.to_lowercase() == "all" {
let variable_lower = variable.to_lowercase();

let query = if variable_lower == "all" {
String::from("SELECT name, setting FROM information_schema.df_settings")
} else if variable_lower == "timezone" || variable_lower == "time.zone" {
// we could introduce alias in OptionDefinition if this string matching thing grows
String::from("SELECT name, setting FROM information_schema.df_settings WHERE name = 'datafusion.execution.time_zone'")
Comment on lines +2393 to +2395
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we have more and more alias like this, we could consider add aliases into ConfigDefinition

} else {
format!(
"SELECT name, setting FROM information_schema.df_settings WHERE name = '{}'",
Expand Down