Skip to content

Commit 36d3416

Browse files
authored
Add psql native functions 'point' and 'polygon' (#24)
1 parent a6218e1 commit 36d3416

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

src/queryparser/adql/adqltranslator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def visitPoint(self, ctx):
205205
if derived_column is not None:
206206
ctx_text = f"spoint_to_array_deg({ctx_text})"
207207
if not (any([isinstance(child, ADQLParser.As_clauseContext) for child in derived_column.children])):
208-
ctx_text = f"{ctx_text} AS point"
208+
ctx_text = f"{ctx_text} AS adql_point"
209209
else:
210210
ctx_text = ''
211211

@@ -297,7 +297,7 @@ def visitPolygon(self, ctx):
297297
if derived_column is not None:
298298
ctx_text = f"spoly_to_array_deg({ctx_text})"
299299
if not (any([isinstance(child, ADQLParser.As_clauseContext) for child in derived_column.children])):
300-
ctx_text = f"{ctx_text} AS polygon"
300+
ctx_text = f"{ctx_text} AS adql_polygon"
301301
else:
302302
ctx_text = ''
303303

src/queryparser/postgresql/PostgreSQLLexer.g4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ OUTER : O_ U_ T_ E_ R_ ;
130130
PARTITION_SYM : P_ A_ R_ T_ I_ T_ I_ O_ N_ ;
131131
PDIST : P_ D_ I_ S_ T_ ;
132132
PI : P_ I_ ;
133+
POINT : P_ O_ I_ N_ T_ ;
134+
POLYGON : P_ O_ L_ Y_ G_ O_ N_ ;
133135
POSITION_SYM : P_ O_ S_ I_ T_ I_ O_ N_ ;
134136
POW : P_ O_ W_ ;
135137
POWER : P_ O_ W_ E_ R_ ;

src/queryparser/postgresql/PostgreSQLParser.g4

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,11 @@ pg_sphere_op:
242242
| SNOTCONTAINS2 | SLEFTNOTCONTAINS | SLEFTNOTCONTAINS2 | AND_SYM
243243
| SNOTOVERLAP ;
244244

245+
245246
sbit_expr:
246-
( pg_sphere_object | spoint )
247+
( polygon SLEFTCONTAINS2 point )
248+
| ( point SCONTAINS2 polygon )
249+
| ( pg_sphere_object | spoint )
247250
| ( ( spoint | simple_expr ) pg_sphere_op pg_sphere_object)
248251
| ( pg_sphere_object EQ pg_sphere_object )
249252
| ( pg_sphere_object pg_sphere_op pg_sphere_object )
@@ -255,6 +258,8 @@ sbit_expr:
255258
| ( ( spoint | scircle | sline | sellipse | spoly | spath | simple_expr ) ( ( PLUS | MINUS )? strans )+ ) ;
256259

257260

261+
polygon: POLYGON string_literal ;
262+
point: POINT LPAREN bit_expr COMMA bit_expr RPAREN ;
258263
spoint: SPOINT LPAREN bit_expr COMMA bit_expr RPAREN ;
259264
scircle: SCIRCLE LPAREN spoint COMMA bit_expr RPAREN ;
260265
sline: ( SLINE LPAREN spoint COMMA spoint RPAREN ) | ( SLINE LPAREN strans COMMA bit_expr RPAREN );

src/queryparser/testing/tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ adql_postgresql_tests:
911911

912912
-
913913
- SELECT POINT('icrs', 10, 10) FROM "db".tab
914-
- SELECT spoint_to_array_deg(spoint(RADIANS(10.0), RADIANS(10.0))) AS point FROM "db".tab;
914+
- SELECT spoint_to_array_deg(spoint(RADIANS(10.0), RADIANS(10.0))) AS adql_point FROM "db".tab;
915915

916916
-
917917
- SELECT POINT(10, 10) AS "p" FROM "db".tab
@@ -923,7 +923,7 @@ adql_postgresql_tests:
923923

924924
-
925925
- SELECT POLYGON('ICRS', 10.0, -10.5, 20.0, 20.5, 30.0, 30.5) FROM db.tab;
926-
- SELECT spoly_to_array_deg(spoly('{(10.0d,-10.5d),(20.0d,20.5d),(30.0d,30.5d)}')) AS polygon FROM db.tab;
926+
- SELECT spoly_to_array_deg(spoly('{(10.0d,-10.5d),(20.0d,20.5d),(30.0d,30.5d)}')) AS adql_polygon FROM db.tab;
927927

928928
-
929929
- SELECT CIRCLE(POINT(10.0, -10.5), 2.0) FROM db.tab;

0 commit comments

Comments
 (0)