MCPcopy Create free account
hub / github.com/apache/datafusion / set_statement_to_plan

Method set_statement_to_plan

datafusion/sql/src/statement.rs:2116–2169  ·  view source on GitHub ↗
(&self, statement: Set)

Source from the content-addressed store, hash-verified

2114 }
2115
2116 fn set_statement_to_plan(&self, statement: Set) -> Result<LogicalPlan> {
2117 match statement {
2118 Set::SingleAssignment {
2119 scope,
2120 hivevar,
2121 variable,
2122 values,
2123 } => {
2124 if scope.is_some() {
2125 return not_impl_err!("SET with scope modifiers is not supported");
2126 }
2127
2128 if hivevar {
2129 return not_impl_err!("SET HIVEVAR is not supported");
2130 }
2131
2132 let variable = object_name_to_string(&variable);
2133 let mut variable_lower = variable.to_lowercase();
2134
2135 // Map PostgreSQL "timezone" and MySQL "time.zone" aliases to DataFusion's canonical name
2136 if variable_lower == "timezone" || variable_lower == "time.zone" {
2137 variable_lower = "datafusion.execution.time_zone".to_string();
2138 }
2139
2140 if values.len() != 1 {
2141 return plan_err!("SET only supports single value assignment");
2142 }
2143
2144 let value_string = match &values[0] {
2145 SQLExpr::Identifier(i) => ident_to_string(i),
2146 SQLExpr::Value(v) => match crate::utils::value_to_string(&v.value) {
2147 None => {
2148 return plan_err!("Unsupported value {:?}", v.value);
2149 }
2150 Some(s) => s,
2151 },
2152 SQLExpr::UnaryOp { op, expr } => match op {
2153 UnaryOperator::Plus => format!("+{expr}"),
2154 UnaryOperator::Minus => format!("-{expr}"),
2155 _ => return plan_err!("Unsupported unary op {:?}", op),
2156 },
2157 _ => return plan_err!("Unsupported expr {:?}", values[0]),
2158 };
2159
2160 Ok(LogicalPlan::Statement(PlanStatement::SetVariable(
2161 SetVariable {
2162 variable: variable_lower,
2163 value: value_string,
2164 },
2165 )))
2166 }
2167 other => not_impl_err!("SET variant not implemented yet: {other:?}"),
2168 }
2169 }
2170
2171 fn reset_statement_to_plan(&self, statement: ResetStatement) -> Result<LogicalPlan> {
2172 match statement {

Calls 7

object_name_to_stringFunction · 0.85
ident_to_stringFunction · 0.85
value_to_stringFunction · 0.85
SetVariableClass · 0.85
StatementEnum · 0.70
to_stringMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected