Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to create logical plan for this query #462

Open
rajivr opened this issue May 23, 2024 · 2 comments
Open

Unable to create logical plan for this query #462

rajivr opened this issue May 23, 2024 · 2 comments
Assignees

Comments

@rajivr
Copy link
Contributor

rajivr commented May 23, 2024

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();
    }
}
@rajivr
Copy link
Contributor Author

rajivr commented Jun 3, 2024

Hi @alancai98 I hope you had a good weekend. I was wondering if anyone from PartiQL Rust Team had a chance to look at this issue?

@alancai98
Copy link
Member

Hi @rajivr sorry for the delay. I'm currently pulled away for some other tasks. I'll forward the issue to the rest of the PartiQL team.

@jpschorr jpschorr self-assigned this Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants