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

feat: add EXISTS/NOT_EXISTS query option for specific tags filter #697

Merged
merged 4 commits into from
Apr 7, 2023

Conversation

eneskaya
Copy link
Contributor

@eneskaya eneskaya commented Apr 4, 2023

This PR adds two new filters for specific tags, the does exist/EXISTS and does not exist/NOT_EXISTS filters. The EXISTS filter checks if a given tag key is present in a row, respectively NOT_EXISTS returns all rows that do not have that key present.

Screenshot 2023-04-04 at 16 36 42

@eneskaya
Copy link
Contributor Author

eneskaya commented Apr 4, 2023

@mlabouardy After a lot of experimenting with the queries for the NOT_EXISTS filter, I've decided to go with this solution, as it covers what we need. I've just one problem with it now, when applied the filter shows the correct results for all resources, that have tags except the one in the filter. But the CROSS JOIN json_each(tags) ... only shows rows, where the tags column is not empty.

Just to clarify, this:

SELECT
	resources.id,
	resources.resource_id,
	resources.tags
FROM
	resources
	CROSS JOIN json_each(tags)
WHERE
	TYPE = 'object'
	AND(NOT EXISTS (
			SELECT
				1 FROM json_each(resources.tags)
			WHERE (json_extract(value, '$.key') = 'Author')))
ORDER BY
	resources.id
LIMIT 50 OFFSET 0

shows all resources, that have tags but only if none of the keys is 'Author'.

And this:

SELECT
	resources.id,
	resources.resource_id,
	resources.tags
FROM
	resources
WHERE
	NOT EXISTS (
			SELECT
				1 FROM json_each(resources.tags)
			WHERE (json_extract(value, '$.key') = 'Author'))
ORDER BY
	resources.id
LIMIT 50 OFFSET 0

shows all resources, that don't have the Author tag, regardless wether the tags column is empty, [] or have other keys in them.

The CROSS JOIN ... statement is added later in the code. What do you think? One would expect the second behaviour, right? If so, should I remove the CROSS JOIN?

@eneskaya eneskaya added this to the v3.0.11 milestone Apr 4, 2023
@mlabouardy
Copy link
Collaborator

Yes its the expected behavior and CROSS JOIN could be removed in this case, could you check if this fix works when a user adds multiple filters as well

@eneskaya
Copy link
Contributor Author

eneskaya commented Apr 5, 2023

Yes its the expected behavior and CROSS JOIN could be removed in this case, could you check if this fix works when a user adds multiple filters as well

@mlabouardy I added a "SELECT DISTINCT" now to filter out the duplicates. But I am really hesitant to introduce yet another if statement in that query code 😅 I tried removing the CROSS JOIN altogether, but then other filters stop working. So I'd have to specifically remove in the case when the user filters for NOT_EXISTS.

@mlabouardy mlabouardy merged commit 3928c50 into develop Apr 7, 2023
@mlabouardy mlabouardy deleted the feature/tech-1031 branch April 7, 2023 08:20
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.

3 participants