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

Investigate free form queries against the metadata column #27

Open
machristie opened this issue Mar 21, 2023 · 0 comments
Open

Investigate free form queries against the metadata column #27

machristie opened this issue Mar 21, 2023 · 0 comments

Comments

@machristie
Copy link
Contributor

The Calcite integration only support queries against pre-registered metadata schema fields, like so

SELECT
    *
FROM
    my_schema
WHERE
    (
        field1 < 5
        OR field3 = 'bar'
    )
    AND field1 > 0
    AND external_id = 'fff';

But it would be nice if one could query against unregistered metadata schema fields that are known to exist within the metadata JSONB column, something like:

SELECT
    *
FROM
    my_schema
WHERE
    metadata.some_other_field > 0;

There are two challenges. One is how to relax Calcite's validation to allow referencing fields that aren't known ahead of time. Second is how to support a syntax for referencing a JSON field that Calcite will parse.

One option might be to have the client queries use JSON functions that Calcite supports: https://calcite.apache.org/docs/reference.html#json-functions

For example:

SELECT
    *
FROM
    my_schema
WHERE
    JSON_EXISTS(metadata, '$.some_other_field > 0');

But, PostgreSQL doesn't yet natively support these functions (see https://www.depesz.com/2022/04/01/waiting-for-postgresql-15-sql-json-query-functions/) so they would need to be rewritten.

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

1 participant