@@ -133,25 +133,7 @@ impl SqlToRelContext {
133133 }
134134}
135135
136- fn plan_key ( key : SQLExpr ) -> Result < ScalarValue > {
137- let scalar = match key {
138- SQLExpr :: Value ( Value :: Number ( s, _) ) => {
139- ScalarValue :: Int64 ( Some ( s. parse ( ) . unwrap ( ) ) )
140- }
141- SQLExpr :: Value ( Value :: SingleQuotedString ( s) ) => ScalarValue :: Utf8 ( Some ( s) ) ,
142- SQLExpr :: Identifier ( ident) => ScalarValue :: Utf8 ( Some ( ident. value ) ) ,
143- _ => {
144- return Err ( DataFusionError :: SQL ( ParserError ( format ! (
145- "Unsuported index key expression: {:?}" ,
146- key
147- ) ) ) )
148- }
149- } ;
150-
151- Ok ( scalar)
152- }
153-
154- fn plan_indexed ( expr : Expr , mut keys : Vec < SQLExpr > ) -> Result < Expr > {
136+ fn plan_indexed ( expr : Expr , mut keys : Vec < Expr > ) -> Result < Expr > {
155137 let key = keys. pop ( ) . ok_or_else ( || {
156138 DataFusionError :: SQL ( ParserError (
157139 "Internal error: Missing index key expression" . to_string ( ) ,
@@ -166,7 +148,7 @@ fn plan_indexed(expr: Expr, mut keys: Vec<SQLExpr>) -> Result<Expr> {
166148
167149 Ok ( Expr :: GetIndexedField {
168150 expr : Box :: new ( expr) ,
169- key : plan_key ( key) ? ,
151+ key : Box :: new ( key) ,
170152 } )
171153}
172154
@@ -1704,26 +1686,12 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
17041686 }
17051687 }
17061688
1707- SQLExpr :: MapAccess { ref column, keys } => {
1708- if let SQLExpr :: Identifier ( ref id) = column. as_ref ( ) {
1709- plan_indexed ( col ( & id. value ) , keys)
1710- } else {
1711- Err ( DataFusionError :: NotImplemented ( format ! (
1712- "map access requires an identifier, found column {} instead" ,
1713- column
1714- ) ) )
1715- }
1716- }
1717-
17181689 SQLExpr :: ArrayIndex { obj, indexs } => {
1719- if let SQLExpr :: Identifier ( ref id) = obj. as_ref ( ) {
1720- plan_indexed ( col ( & id. value ) , indexs)
1721- } else {
1722- Err ( DataFusionError :: NotImplemented ( format ! (
1723- "array index access requires an identifier, found column {} instead" ,
1724- obj
1725- ) ) )
1726- }
1690+ let expr = self . sql_expr_to_logical_expr ( * obj, schema) ?;
1691+
1692+ plan_indexed ( expr, indexs. into_iter ( )
1693+ . map ( |e| self . sql_expr_to_logical_expr ( e, schema) )
1694+ . collect :: < Result < Vec < _ > > > ( ) ?)
17271695 }
17281696
17291697 SQLExpr :: CompoundIdentifier ( ids) => {
@@ -1754,7 +1722,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
17541722 // Access to a field of a column which is a structure, example: SELECT my_struct.key
17551723 Ok ( Expr :: GetIndexedField {
17561724 expr : Box :: new ( Expr :: Column ( field. qualified_column ( ) ) ) ,
1757- key : ScalarValue :: Utf8 ( Some ( name) ) ,
1725+ key : Box :: new ( Expr :: Literal ( ScalarValue :: Utf8 ( Some ( name) ) ) ) ,
17581726 } )
17591727 } else {
17601728 // table.column identifier
@@ -2104,7 +2072,7 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
21042072 SQLExpr :: DotExpr { expr, field } => {
21052073 Ok ( Expr :: GetIndexedField {
21062074 expr : Box :: new ( self . sql_expr_to_logical_expr ( * expr, schema) ?) ,
2107- key : ScalarValue :: Utf8 ( Some ( field. value ) ) ,
2075+ key : Box :: new ( Expr :: Literal ( ScalarValue :: Utf8 ( Some ( field. value ) ) ) ) ,
21082076 } )
21092077 }
21102078
0 commit comments