Skip to content

Unable to create logical plan for this query #462

@rajivr

Description

@rajivr

I noticed this issue during the discussion #79.

When I have the following PartiQL enviornment

{
'record': { 'fdb_rl_type': 'message_TestScalarFieldAccess', 'fdb_rl_value': { 'field': { 'fdb_rl_type': 'string', 'fdb_rl_value': 'Plants' }, 'repeat_me': { 'fdb_rl_type': 'repeated_string', 'fdb_rl_value': [{ 'fdb_rl_type': 'string', 'fdb_rl_value': 'Boxes' }, { 'fdb_rl_type': 'string', 'fdb_rl_value': 'Bowls' }] }, 'bytes_field': { 'fdb_rl_type': 'bytes', 'fdb_rl_value': NULL }, 'uuid_field': { 'fdb_rl_type': 'message_fdb_rl.field.v1.UUID', 'fdb_rl_value': NULL } } }
}

Using PartiQL CLI, following query works.

$ ./bin/partiql --typing-mode=PERMISSIVE --environment ../fdb_rl.env                           
Welcome to the PartiQL shell!
Typing mode: PERMISSIVE
Using version: 0.14.4-6634bc04
PartiQL> SELECT VALUE 
   | { 'repeat_me': ( 
   |   SELECT VALUE fdb_rl_value 
   |   FROM repeat_me.fdb_rl_value AS x AT i ORDER BY i ) 
   | } 
   | FROM record AS r, r.fdb_rl_value.repeat_me AS repeat_me
   | 
===' 
<<
  {
    'repeat_me': [
      'Boxes',
      'Bowls'
    ]
  }
>>
--- 
OK!
PartiQL> 

However, when I attempt to run the same query in Rust, it fails with the following error.

$ cargo test --lib -- --nocapture
   Compiling failing-test v0.1.0 (/home/rajiv/temp-partiql/repro/failing-test)
    Finished `test` profile [unoptimized + debuginfo] target(s) in 2.91s
     Running unittests src/lib.rs (target/debug/deps/failing_test-01f57f1dbe588fee)

running 1 test
thread 'tests::failing' panicked at src/lib.rs:78:64:
called `Result::unwrap()` on an `Err` value: AstTransformationError { errors: [IllegalState("env.len() is not even")] }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
test tests::failing ... FAILED

failures:

failures:
    tests::failing

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.04s

Below is the code for the failing test.

#[cfg(test)]
mod tests {
    use partiql_catalog::PartiqlCatalog;
    use partiql_eval::env::basic::MapBindings;
    use partiql_logical_planner::LogicalPlanner;
    use partiql_parser::Parser;
    use partiql_value::{list, tuple, Value};

    #[test]
    fn failing() {
        // Generated from
        //
        // ```proto
        // message TestScalarFieldAccess {
        //   optional string field = 1;
        //   repeated string repeat_me = 2;
        //   optional bytes bytes_field = 3;
        //   optional fdb_rl.field.v1.UUID uuid_field = 4;
        // }
        // ```
        //
        // ```rust
        // let test_scalar_field_access = TestScalarFieldAccess {
        //     field: Some("Plants".to_string()),
        //     repeat_me: vec!["Boxes".to_string(), "Bowls".to_string()],
        //     bytes_field: None,
        //     uuid_field: None,
        // };
        // ```
        let partiql_value = Value::from(tuple![
            ("fdb_rl_type", "message_TestScalarFieldAccess"),
            (
                "fdb_rl_value",
                tuple![
                    (
                        "field",
                        tuple![("fdb_rl_type", "string"), ("fdb_rl_value", "Plants"),]
                    ),
                    (
                        "repeat_me",
                        tuple![
                            ("fdb_rl_type", "repeated_string"),
                            (
                                "fdb_rl_value",
                                list![
                                    tuple![("fdb_rl_type", "string"), ("fdb_rl_value", "Boxes")],
                                    tuple![("fdb_rl_type", "string"), ("fdb_rl_value", "Bowls")],
                                ]
                            ),
                        ]
                    ),
                    (
                        "bytes_field",
                        tuple![("fdb_rl_type", "bytes"), ("fdb_rl_value", Value::Null),]
                    ),
                    (
                        "uuid_field",
                        tuple![
                            ("fdb_rl_type", "message_fdb_rl.field.v1.UUID"),
                            ("fdb_rl_value", Value::Null),
                        ]
                    ),
                ]
            ),
        ]);

        let mut bindings = MapBindings::default();
        bindings.insert("record", partiql_value);

        let catalog = PartiqlCatalog::default();

        let logical_planner = LogicalPlanner::new(&catalog);

        let parser = Parser::default();

	let parsed_ast = parser.parse("SELECT VALUE { 'repeat_me': ( SELECT VALUE fdb_rl_value FROM repeat_me.fdb_rl_value AS x AT i ORDER BY i ) } FROM record AS r, r.fdb_rl_value.repeat_me AS repeat_me").unwrap();

        let _logical_plan = logical_planner.lower(&parsed_ast).unwrap();
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions