@@ -22,8 +22,8 @@ use datafusion_expr::planner::{
2222use sqlparser:: ast:: {
2323 AccessExpr , BinaryOperator , CastFormat , CastKind , CeilFloorKind ,
2424 DataType as SQLDataType , DateTimeField , DictionaryField , Expr as SQLExpr ,
25- ExprWithAlias as SQLExprWithAlias , MapEntry , StructField , Subscript , TrimWhereField ,
26- TypedString , Value , ValueWithSpan ,
25+ ExprWithAlias as SQLExprWithAlias , JsonPath , MapEntry , StructField , Subscript ,
26+ TrimWhereField , TypedString , Value , ValueWithSpan ,
2727} ;
2828
2929use datafusion_common:: {
@@ -651,10 +651,36 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
651651 options : Box :: new ( WildcardOptions :: default ( ) ) ,
652652 } ) ,
653653 SQLExpr :: Tuple ( values) => self . parse_tuple ( schema, planner_context, values) ,
654+ SQLExpr :: JsonAccess { value, path } => {
655+ self . parse_json_access ( schema, planner_context, value, & path)
656+ }
654657 _ => not_impl_err ! ( "Unsupported ast node in sqltorel: {sql:?}" ) ,
655658 }
656659 }
657660
661+ fn parse_json_access (
662+ & self ,
663+ schema : & DFSchema ,
664+ planner_context : & mut PlannerContext ,
665+ value : Box < SQLExpr > ,
666+ path : & JsonPath ,
667+ ) -> Result < Expr > {
668+ let json_path = path. to_string ( ) ;
669+ let json_path = if let Some ( json_path) = json_path. strip_prefix ( ":" ) {
670+ // sqlparser's JsonPath display adds an extra `:` at the beginning.
671+ json_path. to_owned ( )
672+ } else {
673+ json_path
674+ } ;
675+ self . build_logical_expr (
676+ BinaryOperator :: Custom ( ":" . to_owned ( ) ) ,
677+ self . sql_to_expr ( * value, schema, planner_context) ?,
678+ // pass json path as a string literal, let the impl parse it when needed.
679+ Expr :: Literal ( ScalarValue :: Utf8 ( Some ( json_path) ) , None ) ,
680+ schema,
681+ )
682+ }
683+
658684 /// Parses a struct(..) expression and plans it creation
659685 fn parse_struct (
660686 & self ,
0 commit comments