From f677e5016b07e2b76143e43358cec0f45243cb12 Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Tue, 16 Aug 2022 01:20:33 -0400 Subject: [PATCH] Return proper error message for ill formed variable reference (#3162) --- datafusion/core/src/execution/context.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/datafusion/core/src/execution/context.rs b/datafusion/core/src/execution/context.rs index 96705bb0cab5..64403715cf10 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()?;