Skip to content

Apache DataFusion SQL Query Engine

Return proper error message for ill formed variable reference (#3162)

Andrew Lambf677e5016b07
diff --git a/datafusion/core/src/execution/context.rs b/datafusion/core/src/execution/context.rs
index 96705bb0ca..64403715cf 100644
--- a/datafusion/core/src/execution/context.rs
+++ b/datafusion/core/src/execution/context.rs
@@ -1561,7 +1561,8 @@ impl ContextProvider for SessionState {
return None;
}
- let provider_type = if &variable_names[0][0..2] == "@@" {
+ let first_variable = &variable_names[0];
+ let provider_type = if first_variable.len() > 1 && &first_variable[0..2] == "@@" {
VarType::System
} else {
VarType::UserDefined
@@ -1857,6 +1858,21 @@ mod tests {
Ok(())
}
+ #[tokio::test]
+ async fn create_variable_err() -> Result<()> {
+ let ctx = SessionContext::new();
+
+ let err = plan_and_collect(&ctx, "SElECT @= X#=?!~ 5")
+ .await
+ .unwrap_err();
+
+ assert_eq!(
+ err.to_string(),
+ "Execution error: variable [\"@\"] has no type information"
+ );
+ Ok(())
+ }
+
#[tokio::test]
async fn register_deregister() -> Result<()> {
let tmp_dir = TempDir::new()?;