Skip to content

Commit

Permalink
Introspect comparison operators (#84)
Browse files Browse the repository at this point in the history
### What

Rather than dreaming up the comparison operators that can apply to each
type we ask the database.

### How

We introduce a new configuration field, `comparisonOperatorAliases`,
which defines what names to expose database infix comparison operators
under. This cannot be derived only from introspection. The default uses
the names of graphql-engine v2.

We filter how much of the introspection data ends up in the deployment
and schema to include only types, comparison operators, and aggregation
functions that are actually used in native queries or tables, in order
to keep the size small and the contents concise and relevant.

The operators are sourced from the catalog table `pg_operator`, because
this is supported by both Postgres and CockroachDB. We could relatively
easily extend our comparison operators to cover normal prefix
predicates, but that is future work.

Answering the question "which operators are defined for a given type" is
a somewhat nuanced affair, since we have to take into account operator
overloading and implicit casts.

There is even the insular case of an operator (`SIMILAR TO` in Postgres)
being defined as syntactic sugar over `LIKE`. Since `SIMILAR TO` is
somewhat obscure (IMO) and not really very distinguished from LIKE and
`REGEX`, I've opted not to try and have it appear automatically during
configuration/introspection. (And any user who categorically needs to
use it are free to define it themselves in the deployment)

---------

Co-authored-by: Samir Talwar <[email protected]>
  • Loading branch information
plcplc and SamirTalwar authored Oct 19, 2023
1 parent 4bfd5d6 commit 4cd5ee8
Show file tree
Hide file tree
Showing 30 changed files with 1,898 additions and 3,938 deletions.
12 changes: 0 additions & 12 deletions crates/connectors/ndc-citus/tests/query_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,18 +108,6 @@ mod predicates {
insta::assert_json_snapshot!(result);
}

#[tokio::test]
async fn select_where_name_similar() {
let result = run_query(create_router().await, "select_where_name_similar").await;
insta::assert_json_snapshot!(result);
}

#[tokio::test]
async fn select_where_name_nsimilar() {
let result = run_query(create_router().await, "select_where_name_nsimilar").await;
insta::assert_json_snapshot!(result);
}

#[tokio::test]
async fn select_where_name_regex() {
let result = run_query(create_router().await, "select_where_name_regex").await;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ FROM
FROM
"public"."Album" AS "%0_Album"
WHERE
("%0_Album"."Title" NOT ILIKE cast($1 as varchar))
("%0_Album"."Title" !~~* cast($1 as varchar))
ORDER BY
"%0_Album"."AlbumId" ASC
LIMIT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ FROM
FROM
"public"."Album" AS "%0_Album"
WHERE
("%0_Album"."Title" LIKE $1)
("%0_Album"."Title" ~~ $1)
ORDER BY
"%0_Album"."AlbumId" ASC
) AS "%2_rows"
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 4cd5ee8

Please sign in to comment.