-
Notifications
You must be signed in to change notification settings - Fork 446
Add missing PostgreSQL operators and fix >^ geometric operator #938
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,22 +66,26 @@ describe('PostgreSqlFormatter', () => { | |
| '##', | ||
| '<->', | ||
| '&&', | ||
| '&&&', | ||
| '&<', | ||
| '&>', | ||
| '<<|', | ||
| '&<|', | ||
| '|>>', | ||
| '|&>', | ||
| '<^', | ||
| '^>', | ||
| '>^', | ||
| '?#', | ||
| '?-', | ||
| '?|', | ||
| '?-|', | ||
| '?||', | ||
| '@>', | ||
| '<@', | ||
| '<@>', | ||
| '~=', | ||
| // PostGIS | ||
| '|=|', | ||
| // JSON | ||
| '?', | ||
| '@?', | ||
|
|
@@ -123,6 +127,10 @@ describe('PostgreSqlFormatter', () => { | |
| '<->>', | ||
| '<<<->', | ||
| '<->>>', | ||
| // Cube | ||
| '~>', | ||
| // Hstore | ||
| '#=', | ||
| // Custom operators: from pgvector extension | ||
| '<#>', | ||
| '<=>', | ||
|
|
@@ -250,4 +258,128 @@ describe('PostgreSqlFormatter', () => { | |
| dedent`COMMENT ON TABLE foo IS 'Hello my table';` | ||
| ); | ||
| }); | ||
|
|
||
| // Tests for PostgreSQL containment and full-text search operators | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these additional "operator tests in context" here are unnecessary. It's just noise, with no real value. |
||
| describe('containment and search operators', () => { | ||
| it('formats @> (contains) operator in WHERE clause', () => { | ||
| expect(format(`SELECT * FROM foo WHERE bar @> '{1,2}';`)).toBe(dedent` | ||
| SELECT | ||
| * | ||
| FROM | ||
| foo | ||
| WHERE | ||
| bar @> '{1,2}'; | ||
| `); | ||
| }); | ||
|
|
||
| it('formats <@ (contained by) operator in WHERE clause', () => { | ||
| expect(format(`SELECT * FROM foo WHERE bar <@ '{1,2,3}';`)).toBe(dedent` | ||
| SELECT | ||
| * | ||
| FROM | ||
| foo | ||
| WHERE | ||
| bar <@ '{1,2,3}'; | ||
| `); | ||
| }); | ||
|
|
||
| // https://www.postgresql.org/docs/current/earthdistance.html | ||
| it('formats <@> (distance) operator in ORDER BY clause', () => { | ||
| expect(format(`SELECT * FROM foo ORDER BY bar <@> point(1,2);`)).toBe(dedent` | ||
| SELECT | ||
| * | ||
| FROM | ||
| foo | ||
| ORDER BY | ||
| bar <@> point(1, 2); | ||
| `); | ||
| }); | ||
|
|
||
| it('formats @> operator with JSONB data', () => { | ||
| expect(format(`SELECT * FROM foo WHERE data @> '{"key": "value"}';`)).toBe(dedent` | ||
| SELECT | ||
| * | ||
| FROM | ||
| foo | ||
| WHERE | ||
| data @> '{"key": "value"}'; | ||
| `); | ||
| }); | ||
|
|
||
| it('formats <@ operator with JSONB data', () => { | ||
| expect(format(`SELECT * FROM foo WHERE data <@ '{"key": "value", "other": 1}';`)).toBe(dedent` | ||
| SELECT | ||
| * | ||
| FROM | ||
| foo | ||
| WHERE | ||
| data <@ '{"key": "value", "other": 1}'; | ||
| `); | ||
| }); | ||
| }); | ||
|
|
||
| // Tests for PostGIS operators | ||
| describe('PostGIS operators', () => { | ||
| // https://postgis.net/docs/geometry_overlaps_nd.html | ||
| it('formats &&& (3D bounding box overlap) operator', () => { | ||
| expect(format(`SELECT * FROM foo WHERE geom_a &&& geom_b;`)).toBe(dedent` | ||
| SELECT | ||
| * | ||
| FROM | ||
| foo | ||
| WHERE | ||
| geom_a &&& geom_b; | ||
| `); | ||
| }); | ||
|
|
||
| // https://postgis.net/docs/geometry_distance_cpa.html | ||
| it('formats |=| (closest point of approach distance) operator', () => { | ||
| expect(format(`SELECT * FROM foo ORDER BY traj_a |=| traj_b;`)).toBe(dedent` | ||
| SELECT | ||
| * | ||
| FROM | ||
| foo | ||
| ORDER BY | ||
| traj_a |=| traj_b; | ||
| `); | ||
| }); | ||
| }); | ||
|
|
||
| // https://www.postgresql.org/docs/current/functions-geometry.html | ||
| // Note: the formatter defines ^> but PostgreSQL docs say the operator is >^ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, it defined |
||
| describe('geometric operator correctness', () => { | ||
| it('formats >^ (is above) operator', () => { | ||
| expect(format(`SELECT * FROM foo WHERE point(1,2) >^ point(3,4);`)).toBe(dedent` | ||
| SELECT | ||
| * | ||
| FROM | ||
| foo | ||
| WHERE | ||
| point(1, 2) >^ point(3, 4); | ||
| `); | ||
| }); | ||
| }); | ||
|
|
||
| // Tests for extension operators (hstore, cube, ltree) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From where does the |
||
| describe('extension operators', () => { | ||
| // https://www.postgresql.org/docs/current/cube.html | ||
| it('formats ~> (cube coordinate extraction) operator', () => { | ||
| expect(format(`SELECT c ~> 1 FROM foo;`)).toBe(dedent` | ||
| SELECT | ||
| c ~> 1 | ||
| FROM | ||
| foo; | ||
| `); | ||
| }); | ||
|
|
||
| // https://www.postgresql.org/docs/current/hstore.html | ||
| it('formats #= (hstore replace fields) operator', () => { | ||
| expect(format(`SELECT row #= hstore_data FROM foo;`)).toBe(dedent` | ||
| SELECT | ||
| row #= hstore_data | ||
| FROM | ||
| foo; | ||
| `); | ||
| }); | ||
| }); | ||
| }); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the PR summary the
&&&operator and|=|are listed as PostGIS operators, but in the actual code only the latter is placed to PostGIS group. Some consistency would be nice.