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

Support for jsonb array comparision for $in $nin operator #59

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jernkuan
Copy link

Current we are not able to check whether the jsonb array includes a value within a list. Likewise for checking array does not include any value in target list.

@@ -203,11 +203,31 @@
{"name": {"$in": ["adam", "bob"]}},
[1, 2],
),
(
{"tags": {"$in": ["c", "d"]}},
Copy link
Collaborator

Choose a reason for hiding this comment

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

@jernkuan would you mind checking if this works against

"location": [1.0, 2.0],

field as well?

Copy link
Collaborator

@eyurtsev eyurtsev left a comment

Choose a reason for hiding this comment

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

  1. The change introduces a bug when working with numeric fields.
  2. If we wanted to support array comparison, we need to define clear semantics for Any vs. All. I suspect more users will expect the functionality to be All rather than Any. We can introduce a separate operator for that purpose.

@@ -701,9 +701,15 @@ def _handle_field_filter(
queried_field = self.EmbeddingStore.cmetadata[field].astext

if operator in {"$in"}:
return queried_field.in_([str(val) for val in filter_value])
return func.jsonb_exists_any(
Copy link
Collaborator

Choose a reason for hiding this comment

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

This change will result in a bug when working with integer fields which is a more common use case.

Adding a unit-test in a separate PR and will rebase.

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.

2 participants