|
17 | 17 |
|
18 | 18 | use arrow_schema::DataType;
|
19 | 19 | use arrow_schema::TimeUnit;
|
20 |
| -use sqlparser::ast::{CastKind, Expr as SQLExpr, TrimWhereField, Value}; |
| 20 | +use sqlparser::ast::{CastKind, Expr as SQLExpr, JsonPathElem, TrimWhereField, Value}; |
21 | 21 | use sqlparser::parser::ParserError::ParserError;
|
22 | 22 |
|
23 | 23 | use datafusion_common::{
|
@@ -212,7 +212,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
|
212 | 212 | agg_func.order_by.clone(),
|
213 | 213 | agg_func.null_treatment,
|
214 | 214 | )), true)
|
215 |
| - }, |
| 215 | + } |
216 | 216 | _ => (expr, false),
|
217 | 217 | }
|
218 | 218 | }
|
@@ -916,7 +916,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
|
916 | 916 | distinct,
|
917 | 917 | order_by,
|
918 | 918 | null_treatment,
|
919 |
| - filter: None, // filter is passed in |
| 919 | + filter: _, // filter is passed in |
920 | 920 | }) => Ok(Expr::AggregateFunction(expr::AggregateFunction::new(
|
921 | 921 | fun,
|
922 | 922 | args,
|
@@ -944,65 +944,68 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
|
944 | 944 | schema: &DFSchema,
|
945 | 945 | planner_context: &mut PlannerContext,
|
946 | 946 | ) -> Result<GetFieldAccess> {
|
947 |
| - let field = match expr.clone() { |
| 947 | + match expr.clone() { |
948 | 948 | SQLExpr::Value(
|
949 | 949 | Value::SingleQuotedString(s) | Value::DoubleQuotedString(s),
|
950 |
| - ) => GetFieldAccess::NamedStructField { |
951 |
| - name: ScalarValue::from(s), |
952 |
| - }, |
| 950 | + ) => { |
| 951 | + return Ok(GetFieldAccess::NamedStructField { |
| 952 | + name: ScalarValue::from(s), |
| 953 | + }) |
| 954 | + } |
953 | 955 | SQLExpr::JsonAccess { value, path } => {
|
954 |
| - let (start, stop, stride) = if let SQLExpr::JsonAccess { |
955 |
| - left: l, |
956 |
| - operator: JsonOperator::Colon, |
957 |
| - right: r, |
958 |
| - } = *left |
959 |
| - { |
960 |
| - let start = Box::new(self.sql_expr_to_logical_expr( |
961 |
| - *l, |
962 |
| - schema, |
963 |
| - planner_context, |
964 |
| - )?); |
965 |
| - let stop = Box::new(self.sql_expr_to_logical_expr( |
966 |
| - *r, |
967 |
| - schema, |
968 |
| - planner_context, |
969 |
| - )?); |
970 |
| - let stride = Box::new(self.sql_expr_to_logical_expr( |
971 |
| - *right, |
972 |
| - schema, |
973 |
| - planner_context, |
974 |
| - )?); |
975 |
| - (start, stop, stride) |
976 |
| - } else { |
977 |
| - let start = Box::new(self.sql_expr_to_logical_expr( |
978 |
| - *left, |
| 956 | + let start = Box::new(self.sql_expr_to_logical_expr( |
| 957 | + *value, |
| 958 | + schema, |
| 959 | + planner_context, |
| 960 | + )?); |
| 961 | + |
| 962 | + fn json_path_elem_to_expr(expr: JsonPathElem) -> SQLExpr { |
| 963 | + match expr { |
| 964 | + JsonPathElem::Dot { key, .. } => SQLExpr::Value(Value::SingleQuotedString(key)), |
| 965 | + JsonPathElem::Bracket { key } => key, |
| 966 | + } |
| 967 | + } |
| 968 | + |
| 969 | + let mut path_iter = path.path.into_iter(); |
| 970 | + let stop = match path_iter.next() { |
| 971 | + None => { |
| 972 | + return Ok(GetFieldAccess::ListIndex { |
| 973 | + key: Box::new(self.sql_expr_to_logical_expr( |
| 974 | + expr, |
| 975 | + schema, |
| 976 | + planner_context, |
| 977 | + )?), |
| 978 | + }) |
| 979 | + } |
| 980 | + Some(expr) => Box::new(self.sql_expr_to_logical_expr( |
| 981 | + json_path_elem_to_expr(expr), |
979 | 982 | schema,
|
980 | 983 | planner_context,
|
981 |
| - )?); |
982 |
| - let stop = Box::new(self.sql_expr_to_logical_expr( |
983 |
| - *right, |
| 984 | + )?), |
| 985 | + }; |
| 986 | + let stride = match path_iter.next() { |
| 987 | + None => Box::new(Expr::Literal(ScalarValue::Int64(Some(1)))), |
| 988 | + Some(expr) => Box::new(self.sql_expr_to_logical_expr( |
| 989 | + json_path_elem_to_expr(expr), |
984 | 990 | schema,
|
985 | 991 | planner_context,
|
986 |
| - )?); |
987 |
| - let stride = Box::new(Expr::Literal(ScalarValue::Int64(Some(1)))); |
988 |
| - (start, stop, stride) |
| 992 | + )?), |
989 | 993 | };
|
990 |
| - GetFieldAccess::ListRange { |
| 994 | + |
| 995 | + Ok(GetFieldAccess::ListRange { |
991 | 996 | start,
|
992 | 997 | stop,
|
993 | 998 | stride,
|
994 |
| - } |
| 999 | + }) |
995 | 1000 | }
|
996 |
| - _ => GetFieldAccess::ListIndex { |
| 1001 | + _ => Ok(GetFieldAccess::ListIndex { |
997 | 1002 | key: Box::new(self.sql_expr_to_logical_expr(
|
998 | 1003 | expr,
|
999 | 1004 | schema,
|
1000 | 1005 | planner_context,
|
1001 | 1006 | )?),
|
1002 |
| - }, |
1003 |
| - }; |
1004 |
| - |
1005 |
| - Ok(field) |
| 1007 | + }), |
| 1008 | + } |
1006 | 1009 | }
|
1007 | 1010 |
|
1008 | 1011 | fn plan_indexed(
|
|
0 commit comments