Skip to content
Snippets Groups Projects
Commit 5cc544e4 authored by Grégory Mantelet's avatar Grégory Mantelet
Browse files

[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
...@@ -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>
{ {
......
...@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment