diff --git a/src/queryparser/adql/adqltranslator.py b/src/queryparser/adql/adqltranslator.py index d243306..b4da4fe 100644 --- a/src/queryparser/adql/adqltranslator.py +++ b/src/queryparser/adql/adqltranslator.py @@ -205,7 +205,7 @@ def visitPoint(self, ctx): if derived_column is not None: ctx_text = f"spoint_to_array_deg({ctx_text})" if not (any([isinstance(child, ADQLParser.As_clauseContext) for child in derived_column.children])): - ctx_text = f"{ctx_text} AS point" + ctx_text = f"{ctx_text} AS adql_point" else: ctx_text = '' @@ -297,7 +297,7 @@ def visitPolygon(self, ctx): if derived_column is not None: ctx_text = f"spoly_to_array_deg({ctx_text})" if not (any([isinstance(child, ADQLParser.As_clauseContext) for child in derived_column.children])): - ctx_text = f"{ctx_text} AS polygon" + ctx_text = f"{ctx_text} AS adql_polygon" else: ctx_text = '' diff --git a/src/queryparser/postgresql/PostgreSQLLexer.g4 b/src/queryparser/postgresql/PostgreSQLLexer.g4 index 904c543..f307aa8 100644 --- a/src/queryparser/postgresql/PostgreSQLLexer.g4 +++ b/src/queryparser/postgresql/PostgreSQLLexer.g4 @@ -130,6 +130,8 @@ OUTER : O_ U_ T_ E_ R_ ; PARTITION_SYM : P_ A_ R_ T_ I_ T_ I_ O_ N_ ; PDIST : P_ D_ I_ S_ T_ ; PI : P_ I_ ; +POINT : P_ O_ I_ N_ T_ ; +POLYGON : P_ O_ L_ Y_ G_ O_ N_ ; POSITION_SYM : P_ O_ S_ I_ T_ I_ O_ N_ ; POW : P_ O_ W_ ; POWER : P_ O_ W_ E_ R_ ; diff --git a/src/queryparser/postgresql/PostgreSQLParser.g4 b/src/queryparser/postgresql/PostgreSQLParser.g4 index b3aadc5..e7ce066 100644 --- a/src/queryparser/postgresql/PostgreSQLParser.g4 +++ b/src/queryparser/postgresql/PostgreSQLParser.g4 @@ -242,8 +242,11 @@ pg_sphere_op: | SNOTCONTAINS2 | SLEFTNOTCONTAINS | SLEFTNOTCONTAINS2 | AND_SYM | SNOTOVERLAP ; + sbit_expr: - ( pg_sphere_object | spoint ) + ( polygon SLEFTCONTAINS2 point ) + | ( point SCONTAINS2 polygon ) + | ( pg_sphere_object | spoint ) | ( ( spoint | simple_expr ) pg_sphere_op pg_sphere_object) | ( pg_sphere_object EQ pg_sphere_object ) | ( pg_sphere_object pg_sphere_op pg_sphere_object ) @@ -255,6 +258,8 @@ sbit_expr: | ( ( spoint | scircle | sline | sellipse | spoly | spath | simple_expr ) ( ( PLUS | MINUS )? strans )+ ) ; +polygon: POLYGON string_literal ; +point: POINT LPAREN bit_expr COMMA bit_expr RPAREN ; spoint: SPOINT LPAREN bit_expr COMMA bit_expr RPAREN ; scircle: SCIRCLE LPAREN spoint COMMA bit_expr RPAREN ; sline: ( SLINE LPAREN spoint COMMA spoint RPAREN ) | ( SLINE LPAREN strans COMMA bit_expr RPAREN ); diff --git a/src/queryparser/testing/tests.yaml b/src/queryparser/testing/tests.yaml index fb093f6..1f60077 100644 --- a/src/queryparser/testing/tests.yaml +++ b/src/queryparser/testing/tests.yaml @@ -886,7 +886,7 @@ adql_postgresql_tests: - - SELECT POINT('icrs', 10, 10) FROM "db".tab - - SELECT spoint_to_array_deg(spoint(RADIANS(10.0), RADIANS(10.0))) AS point FROM "db".tab; + - SELECT spoint_to_array_deg(spoint(RADIANS(10.0), RADIANS(10.0))) AS adql_point FROM "db".tab; - - SELECT POINT(10, 10) AS "p" FROM "db".tab @@ -898,7 +898,7 @@ adql_postgresql_tests: - - SELECT POLYGON('ICRS', 10.0, -10.5, 20.0, 20.5, 30.0, 30.5) FROM db.tab; - - SELECT spoly_to_array_deg(spoly('{(10.0d,-10.5d),(20.0d,20.5d),(30.0d,30.5d)}')) AS polygon FROM db.tab; + - SELECT spoly_to_array_deg(spoly('{(10.0d,-10.5d),(20.0d,20.5d),(30.0d,30.5d)}')) AS adql_polygon FROM db.tab; - - SELECT CIRCLE(POINT(10.0, -10.5), 2.0) FROM db.tab;