Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vollt
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sonia Zorba
vollt
Commits
5cc544e4
Commit
5cc544e4
authored
Aug 20, 2019
by
Grégory Mantelet
Browse files
Options
Downloads
Patches
Plain Diff
[ADQL] Make the coordinate system argument optional in geometries constructor
(e.g. POINT, BOX, CIRCLE and POLYGON).
parent
0503672a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/adql/parser/grammar/adqlGrammar201.jj
+94
-14
94 additions, 14 deletions
src/adql/parser/grammar/adqlGrammar201.jj
test/adql/parser/TestADQLParser.java
+29
-0
29 additions, 0 deletions
test/adql/parser/TestADQLParser.java
with
123 additions
and
14 deletions
src/adql/parser/grammar/adqlGrammar201.jj
+
94
−
14
View file @
5cc544e4
...
@@ -1236,35 +1236,45 @@ ADQLOperand CoordinateSystem(): { ADQLOperand coordSys=null;}{
...
@@ -1236,35 +1236,45 @@ ADQLOperand CoordinateSystem(): { ADQLOperand coordSys=null;}{
{ return coordSys; }
{ return coordSys; }
}
}
GeometryFunction GeometryValueFunction(): {Token fct=null, end=null; ADQLOperand
coordSys; ADQLOperand
width, height; ADQLOperand[] coords, tmp; Vector<ADQLOperand> vCoords; ADQLOperand op=null; GeometryValue<GeometryFunction> gvf = null; GeometryFunction gf = null;} {
GeometryFunction GeometryValueFunction(): {Token fct=null, end=null; ADQLOperand width, height; ADQLOperand[] coords, tmp; Vector<ADQLOperand> vCoords; ADQLOperand op=null; GeometryValue<GeometryFunction> gvf = null; GeometryFunction gf = null;} {
try{
try{
// BOX (deprecated since ADQL-2.1)
(LOOKAHEAD(BoxWithCooSys()) gf=BoxWithCooSys()
// BOX:
// BOX:
(
(fct=<BOX> <LEFT_PAR>
coordSys=CoordinateSystem()
// coord_sys
|
(fct=<BOX> <LEFT_PAR> // coord_sys
<COMMA>
coords=Coordinates() // coordinates
coords=Coordinates() // coordinates
<COMMA> width=NumericExpression() <COMMA> height=NumericExpression() end=<RIGHT_PAR>)
<COMMA> width=NumericExpression() <COMMA> height=NumericExpression() end=<RIGHT_PAR>)
{gf = queryFactory.createBox(
coordSys
, coords[0], coords[1], width, height);}
{gf = queryFactory.createBox(
null
, coords[0], coords[1], width, height);}
// CENTROID:
// CENTROID:
| (fct=<CENTROID> <LEFT_PAR> gvf=GeometryExpression() end=<RIGHT_PAR>) {gf = queryFactory.createCentroid(gvf);}
| (fct=<CENTROID> <LEFT_PAR> gvf=GeometryExpression() end=<RIGHT_PAR>) {gf = queryFactory.createCentroid(gvf);}
// CIRCLE (deprecated since ADQL-2.1)
| LOOKAHEAD(CircleWithCooSys()) gf=CircleWithCooSys()
// CIRCLE:
// CIRCLE:
| (fct=<CIRCLE> <LEFT_PAR>
coordSys=CoordinateSystem() // coord_sys
| (fct=<CIRCLE> <LEFT_PAR>
<COMMA>
coords=Coordinates() // coordinates
coords=Coordinates() // coordinates
<COMMA> width=NumericExpression() end=<RIGHT_PAR>) // radius
<COMMA> width=NumericExpression() end=<RIGHT_PAR>) // radius
{gf = queryFactory.createCircle(
coordSys
, coords[0], coords[1], width);}
{gf = queryFactory.createCircle(
null
, coords[0], coords[1], width);}
// POINT:
// POINT:
| gf=Point()
| gf=Point()
// POLYGON (deprecated since ADQL-2.1)
| LOOKAHEAD(PolygonWithCooSys()) gf=PolygonWithCooSys()
// POLYGON:
// POLYGON:
| (fct=<POLYGON> <LEFT_PAR>
coordSys=CoordinateSystem() // coord_sys
| (fct=<POLYGON> <LEFT_PAR>
{ vCoords = new Vector<ADQLOperand>(); } // coordinates
{ vCoords = new Vector<ADQLOperand>(); } // coordinates
<COMMA>
tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
(<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);})*
(<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);})*
end=<RIGHT_PAR>)
end=<RIGHT_PAR>)
{ gf = queryFactory.createPolygon(
coordSys
, vCoords); }
{ gf = queryFactory.createPolygon(
null
, vCoords); }
/* // REGION (REMOVED SINCE 2.1):
/* // REGION (REMOVED SINCE 2.1):
| (fct=<REGION> <LEFT_PAR> op=StringExpression() end=<RIGHT_PAR>) {gf = queryFactory.createRegion(op);}*/
| (fct=<REGION> <LEFT_PAR> op=StringExpression() end=<RIGHT_PAR>) {gf = queryFactory.createRegion(op);}*/
...
@@ -1280,9 +1290,60 @@ GeometryFunction GeometryValueFunction(): {Token fct=null, end=null; ADQLOperand
...
@@ -1280,9 +1290,60 @@ GeometryFunction GeometryValueFunction(): {Token fct=null, end=null; ADQLOperand
}
}
}
}
PointFunction Point(): {Token start, end; ADQLOperand coordSys; ADQLOperand[] coords;} {
GeometryFunction BoxWithCooSys(): { Token fct=null, end=null; ADQLOperand coordSys; ADQLOperand width, height; ADQLOperand[] coords; } {
start=<POINT> <LEFT_PAR> coordSys=CoordinateSystem() // coord_sys
fct=<BOX> <LEFT_PAR> coordSys=CoordinateSystem() // coord_sys
<COMMA> coords=Coordinates() end=<RIGHT_PAR> // coordinates
<COMMA> coords=Coordinates() // coordinates
<COMMA> width=NumericExpression() <COMMA> height=NumericExpression() end=<RIGHT_PAR>
{
try {
GeometryFunction gf = queryFactory.createBox(coordSys, coords[0], coords[1], width, height);
gf.setPosition(new TextPosition(fct, end));
return gf;
}catch(Exception ex){
throw generateParseException(ex);
}
}
}
GeometryFunction CircleWithCooSys(): { Token fct=null, end=null; ADQLOperand coordSys; ADQLOperand width; ADQLOperand[] coords; } {
fct=<CIRCLE> <LEFT_PAR> coordSys=CoordinateSystem() <COMMA> // coord_sys
coords=Coordinates() // coordinates
<COMMA> width=NumericExpression() end=<RIGHT_PAR> // radius
{
try {
GeometryFunction gf = queryFactory.createCircle(coordSys, coords[0], coords[1], width);
gf.setPosition(new TextPosition(fct, end));
return gf;
}catch(Exception ex){
throw generateParseException(ex);
}
}
}
PointFunction Point(): {Token start, end; ADQLOperand[] coords; PointFunction pf;} {
// POINT (depecrated since ADQL-2.1)
(LOOKAHEAD(PointWithCooSys())
pf=PointWithCooSys()
{ return pf; }
// POINT (last version - >= ADQL-2.1)
|
start=<POINT> <LEFT_PAR> coords=Coordinates() end=<RIGHT_PAR> // coordinates
{
try{
pf = queryFactory.createPoint(null, coords[0], coords[1]);
pf.setPosition(new TextPosition(start, end));
return pf;
}catch(Exception ex){
throw generateParseException(ex);
}
}
)
}
PointFunction PointWithCooSys(): {Token start, end; ADQLOperand coordSys; ADQLOperand[] coords;} {
start=<POINT> <LEFT_PAR> coordSys=CoordinateSystem() <COMMA> // coord_sys
coords=Coordinates() end=<RIGHT_PAR> // coordinates
{
{
try{
try{
PointFunction pf = queryFactory.createPoint(coordSys, coords[0], coords[1]);
PointFunction pf = queryFactory.createPoint(coordSys, coords[0], coords[1]);
...
@@ -1294,6 +1355,25 @@ PointFunction Point(): {Token start, end; ADQLOperand coordSys; ADQLOperand[] co
...
@@ -1294,6 +1355,25 @@ PointFunction Point(): {Token start, end; ADQLOperand coordSys; ADQLOperand[] co
}
}
}
}
GeometryFunction PolygonWithCooSys(): { Token fct=null, end=null; ADQLOperand coordSys; ADQLOperand[] coords, tmp; Vector<ADQLOperand> vCoords; } {
fct=<POLYGON> <LEFT_PAR> coordSys=CoordinateSystem() // coord_sys
{ vCoords = new Vector<ADQLOperand>(); } // coordinates
<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);}
(<COMMA> tmp=Coordinates() {vCoords.add(tmp[0]); vCoords.add(tmp[1]);})*
end=<RIGHT_PAR>
{
try {
GeometryFunction gf = queryFactory.createPolygon(coordSys, vCoords);
gf.setPosition(new TextPosition(fct, end));
return gf;
}catch(Exception ex){
throw generateParseException(ex);
}
}
}
GeometryFunction ExtractCoordSys(): {Token start, end; GeometryValue<GeometryFunction> gvf;} {
GeometryFunction ExtractCoordSys(): {Token start, end; GeometryValue<GeometryFunction> gvf;} {
start=<COORDSYS> <LEFT_PAR> gvf=GeometryExpression() end=<RIGHT_PAR>
start=<COORDSYS> <LEFT_PAR> gvf=GeometryExpression() end=<RIGHT_PAR>
{
{
...
...
This diff is collapsed.
Click to expand it.
test/adql/parser/TestADQLParser.java
+
29
−
0
View file @
5cc544e4
...
@@ -550,6 +550,35 @@ public class TestADQLParser {
...
@@ -550,6 +550,35 @@ public class TestADQLParser {
}
}
}
}
@Test
public
void
testGeometryWithNoCooSys
()
{
/*
* NOTE:
* Since ADQL-2.1, the coordinate system argument becomes optional.
*/
ADQLParser
parser
=
new
ADQLParser
(
ADQLVersion
.
V2_1
);
// CASE: with no coordinate system => equivalent to coosys = ''
try
{
assertEquals
(
"POINT('', 1, 2)"
,
parser
.
parseSelect
(
"SELECT POINT(1, 2)"
).
get
(
0
).
toADQL
());
assertEquals
(
"CIRCLE('', 1, 2, 3)"
,
parser
.
parseSelect
(
"SELECT CIRCLE(1, 2, 3)"
).
get
(
0
).
toADQL
());
assertEquals
(
"BOX('', 1, 2, 3, 4)"
,
parser
.
parseSelect
(
"SELECT BOX(1, 2, 3, 4)"
).
get
(
0
).
toADQL
());
assertEquals
(
"POLYGON('', 1, 2, 3, 4, 5, 6)"
,
parser
.
parseSelect
(
"SELECT POLYGON(1, 2, 3, 4, 5, 6)"
).
get
(
0
).
toADQL
());
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
fail
(
"Unexpected error! All parsed geometries are correct."
);
}
// CASE: ambiguity with POLYGON and a wrong nb of arguments
try
{
assertEquals
(
"POLYGON(ra, dec, 3, 4, 5, 6, 7)"
,
parser
.
parseSelect
(
"SELECT POLYGON(ra, dec, 3, 4, 5, 6, 7)"
).
get
(
0
).
toADQL
());
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
fail
(
"Unexpected error! All parsed geometries are \"correct\"."
);
}
}
@Test
@Test
public
void
testCoordSys
()
{
public
void
testCoordSys
()
{
// DECLARE A SIMPLE PARSER where all coordinate systems are allowed by default:
// DECLARE A SIMPLE PARSER where all coordinate systems are allowed by default:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment