(&self, variable: &[Ident])
| 2058 | } |
| 2059 | |
| 2060 | fn show_variable_to_plan(&self, variable: &[Ident]) -> Result<LogicalPlan> { |
| 2061 | if !self.has_table("information_schema", "df_settings") { |
| 2062 | return plan_err!( |
| 2063 | "SHOW [VARIABLE] is not supported unless information_schema is enabled" |
| 2064 | ); |
| 2065 | } |
| 2066 | |
| 2067 | let verbose = variable |
| 2068 | .last() |
| 2069 | .map(|s| ident_to_string(s) == "verbose") |
| 2070 | .unwrap_or(false); |
| 2071 | let mut variable_vec = variable.to_vec(); |
| 2072 | let mut columns: String = "name, value".to_owned(); |
| 2073 | |
| 2074 | if verbose { |
| 2075 | columns = format!("{columns}, description"); |
| 2076 | variable_vec = variable_vec.split_at(variable_vec.len() - 1).0.to_vec(); |
| 2077 | } |
| 2078 | |
| 2079 | let variable = object_name_to_string(&ObjectName::from(variable_vec)); |
| 2080 | let base_query = format!("SELECT {columns} FROM information_schema.df_settings"); |
| 2081 | let query = if variable == "all" { |
| 2082 | // Add an ORDER BY so the output comes out in a consistent order |
| 2083 | format!("{base_query} ORDER BY name") |
| 2084 | } else if variable == "timezone" || variable == "time.zone" { |
| 2085 | // we could introduce alias in OptionDefinition if this string matching thing grows |
| 2086 | format!("{base_query} WHERE name = 'datafusion.execution.time_zone'") |
| 2087 | } else { |
| 2088 | // These values are what are used to make the information_schema table, so we just |
| 2089 | // check here, before actually planning or executing the query, if it would produce no |
| 2090 | // results, and error preemptively if it would (for a better UX) |
| 2091 | let is_valid_variable = self |
| 2092 | .context_provider |
| 2093 | .options() |
| 2094 | .entries() |
| 2095 | .iter() |
| 2096 | .any(|opt| opt.key == variable); |
| 2097 | |
| 2098 | // Check if it's a runtime variable |
| 2099 | let is_runtime_variable = variable.starts_with("datafusion.runtime."); |
| 2100 | |
| 2101 | if !is_valid_variable && !is_runtime_variable { |
| 2102 | return plan_err!( |
| 2103 | "'{variable}' is not a variable which can be viewed with 'SHOW'" |
| 2104 | ); |
| 2105 | } |
| 2106 | |
| 2107 | format!("{base_query} WHERE name = '{variable}'") |
| 2108 | }; |
| 2109 | |
| 2110 | let mut rewrite = DFParser::parse_sql(&query)?; |
| 2111 | assert_eq!(rewrite.len(), 1); |
| 2112 | |
| 2113 | self.statement_to_plan(rewrite.pop_front().unwrap()) |
| 2114 | } |
| 2115 | |
| 2116 | fn set_statement_to_plan(&self, statement: Set) -> Result<LogicalPlan> { |
| 2117 | match statement { |
no test coverage detected