iffyio commented on code in PR #1534:
URL: 
https://github.com/apache/datafusion-sqlparser-rs/pull/1534#discussion_r1850713552


##########
tests/sqlparser_redshift.rs:
##########
@@ -196,3 +199,118 @@ fn test_create_view_with_no_schema_binding() {
     redshift_and_generic()
         .verified_stmt("CREATE VIEW myevent AS SELECT eventname FROM event 
WITH NO SCHEMA BINDING");
 }
+
+#[test]
+fn test_redshift_json_path() {
+    let sql = "SELECT cust.c_orders[0].o_orderkey FROM 
customer_orders_lineitem";
+    let select = redshift().verified_only_select(sql);
+
+    assert_eq!(
+        &Expr::JsonAccess {
+            value: Box::new(Expr::CompoundIdentifier(vec![
+                Ident::new("cust"),
+                Ident::new("c_orders")
+            ])),
+            path: JsonPath {
+                path: vec![
+                    JsonPathElem::Bracket {
+                        key: Expr::Value(Value::Number("0".parse().unwrap(), 
false))
+                    },
+                    JsonPathElem::Dot {
+                        key: "o_orderkey".to_string(),
+                        quoted: false
+                    }
+                ]
+            }
+        },
+        expr_from_projection(only(&select.projection))
+    );
+
+    let sql = "SELECT cust.c_orders[0]['id'] FROM customer_orders_lineitem";
+    let select = redshift().verified_only_select(sql);
+    assert_eq!(
+        &Expr::JsonAccess {
+            value: Box::new(Expr::CompoundIdentifier(vec![
+                Ident::new("cust"),
+                Ident::new("c_orders")
+            ])),
+            path: JsonPath {
+                path: vec![
+                    JsonPathElem::Bracket {
+                        key: Expr::Value(Value::Number("0".parse().unwrap(), 
false))
+                    },
+                    JsonPathElem::Bracket {
+                        key: 
Expr::Value(Value::SingleQuotedString("id".to_owned()))
+                    }
+                ]
+            }
+        },
+        expr_from_projection(only(&select.projection))
+    );
+}
+
+#[test]
+fn test_parse_json_path_from() {
+    let select = redshift().verified_only_select("SELECT * FROM src[0].a AS 
a");

Review Comment:
   Could we add a test for something containing a qualified name e.g. 
`a.b.c[0].d` (it wasn't clear from the code how that's represented or rejected 
if its not valid partiql)?



##########
tests/sqlparser_redshift.rs:
##########
@@ -196,3 +199,118 @@ fn test_create_view_with_no_schema_binding() {
     redshift_and_generic()
         .verified_stmt("CREATE VIEW myevent AS SELECT eventname FROM event 
WITH NO SCHEMA BINDING");
 }
+
+#[test]
+fn test_redshift_json_path() {
+    let sql = "SELECT cust.c_orders[0].o_orderkey FROM 
customer_orders_lineitem";
+    let select = redshift().verified_only_select(sql);

Review Comment:
   Could we use `let dialect = all_dialects_where(|d| d.supports_partiql())` 
for the tests? thinking so any dialect that gets this feature can potentially 
reuse the same tests



##########
src/ast/query.rs:
##########
@@ -974,6 +974,8 @@ pub enum TableFactor {
         with_ordinality: bool,
         /// [Partition 
selection](https://dev.mysql.com/doc/refman/8.0/en/partitioning-selection.html),
 supported by MySQL.
         partitions: Vec<Ident>,
+        /// Optional PartiQL JsonPath: <https://partiql.org/dql/from.html>
+        partiql: Option<JsonPath>,

Review Comment:
   Maybe we can call this `json_path` to be generic (in the doc we mention 
partiql as one example)?
   



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to