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

fix: Add support for expressions on left hand side of std.in operator #4498

Merged
merged 4 commits into from
May 22, 2024

Conversation

kgutwin
Copy link
Collaborator

@kgutwin kgutwin commented May 21, 2024

Resolves #4497.

I'm hoping this is as simple as it needs to be to resolve this... if there's a more complex reason why std.in needs to not support expressions on the left-hand side, more discussion is appreciated!

Thanks for this package - it's making a big impact on our project, which we hope to release relatively soon!

@max-sixty max-sixty changed the title Add support for expressions on left hand side of std.in operator fix: Add support for expressions on left hand side of std.in operator May 21, 2024
@max-sixty
Copy link
Member

@kgutwin very nice fix!

Merging now — lmk if you want a release soon, was planning to do one in a few days, can push up if needed.

Great if you can add a changelog in another PR, no stress tho

@max-sixty
Copy link
Member

(+ if you can run cargo fmt then great, otherwise I can)

@@ -1155,6 +1155,8 @@ fn test_in_values_01() {
from employees
filter (title | in ["Sales Manager", "Sales Support Agent"])
filter (employee_id | in [1, 2, 5])
filter (f"{emp_group}.{role}" | in ["sales_ne.mgr", "sales_mw.mgr"])
filter (s"{metadata} ->> '$.location'" | in ["Northeast", "Midwest"])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
filter (s"{metadata} ->> '$.location'" | in ["Northeast", "Midwest"])
filter (s"{metadata} -> '$.location'" | in ["Northeast", "Midwest"])

?

Copy link
Member

@max-sixty max-sixty May 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good point.

I thought the tests had passed, but actually the cargo fmt test failed before these had a chance to run. So when we fix fmt, we'll get to test this properly.

It will need a run of task test-rust to update the snapshots (or cargo insta test --accept --features=default,test-dbs)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PrettyWood I think ->> is the right operator here, since in ["", ...] is comparing to a VARCHAR which is what ->> returns. Reference: https://duckdb.org/docs/extensions/json.html#json-extraction-functions

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need to delay merging, but FYI adding this to a query in this path https://github.com/PRQL/prql/blob/76c4f767c4312976dba0fbadfa6c27b84e31faa9/prqlc/prqlc/tests/integration/queries/cast.prql would test on duckdb & postgres DBs in CI

@@ -173,7 +178,10 @@ fn process_array_in(args: &[Expr], ctx: &mut Context) -> Result<sql_ast::Expr> {
.collect::<Result<Vec<sql_ast::Expr>>>()?,
negated: false,
}),
_ => panic!("args to `std.array_in` must be a column ref and an array"),
_ => Err(
Error::new_simple("args to `std.array_in` must be an expression and an array")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Error::new_simple("args to `std.array_in` must be an expression and an array")
Error::new_simple("args to `std.array_in` must be an expression and an array respectively")

@max-sixty max-sixty merged commit d1f0c1c into PRQL:main May 22, 2024
36 checks passed
@max-sixty
Copy link
Member

Thanks @kgutwin !

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

Successfully merging this pull request may close these issues.

std.in operator does not support expression on left-hand-side
3 participants