alamb commented on a change in pull request #1796:
URL: https://github.com/apache/arrow-datafusion/pull/1796#discussion_r802716290
##########
File path: datafusion/src/sql/planner.rs
##########
@@ -85,30 +86,40 @@ pub struct SqlToRel<'a, S: ContextProvider> {
schema_provider: &'a S,
}
-fn plan_key(key: Value) -> ScalarValue {
- match key {
- Value::Number(s, _) => ScalarValue::Int64(Some(s.parse().unwrap())),
- Value::SingleQuotedString(s) => ScalarValue::Utf8(Some(s)),
- _ => unreachable!(),
- }
+fn plan_key(key: SQLExpr) -> Result<ScalarValue> {
+ let scalar = match key {
+ SQLExpr::Value(Value::Number(s, _)) => {
+ ScalarValue::Int64(Some(s.parse().unwrap()))
+ }
+ SQLExpr::Value(Value::SingleQuotedString(s)) =>
ScalarValue::Utf8(Some(s)),
+ _ => {
+ return Err(DataFusionError::SQL(ParserError(format!(
+ "Unsuported index key expression: {}",
+ key
+ ))))
+ }
+ };
+
+ Ok(scalar)
}
-#[allow(clippy::branches_sharing_code)]
-fn plan_indexed(expr: Expr, mut keys: Vec<Value>) -> Expr {
- if keys.len() == 1 {
- let key = keys.pop().unwrap();
- Expr::GetIndexedField {
- expr: Box::new(expr),
- key: plan_key(key),
- }
+fn plan_indexed(expr: Expr, mut keys: Vec<SQLExpr>) -> Result<Expr> {
Review comment:
I had to change this code anyways to handle arbitrary expressions due to
https://github.com/sqlparser-rs/sqlparser-rs/pull/382 so I took the time to
remove the clippy warning too
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]