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
9f845f0b
Commit
9f845f0b
authored
5 years ago
by
Grégory Mantelet
Browse files
Options
Downloads
Patches
Plain Diff
[ADQL] Support DISTANCE also with 4 parameters (i.e. lon1, lat1, lon2, lat2).
parent
046ac691
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
+62
-26
62 additions, 26 deletions
src/adql/parser/grammar/adqlGrammar201.jj
test/adql/parser/TestADQLParser.java
+32
-0
32 additions, 0 deletions
test/adql/parser/TestADQLParser.java
with
94 additions
and
26 deletions
src/adql/parser/grammar/adqlGrammar201.jj
+
62
−
26
View file @
9f845f0b
...
@@ -1181,7 +1181,7 @@ ADQLOperand[] Coordinates(): {ADQLOperand[] ops = new ADQLOperand[2];} {
...
@@ -1181,7 +1181,7 @@ ADQLOperand[] Coordinates(): {ADQLOperand[] ops = new ADQLOperand[2];} {
{return ops;}
{return ops;}
}
}
GeometryFunction GeometryFunction(): {Token fct=null, end; GeometryValue<GeometryFunction> gvf1, gvf2; GeometryValue<PointFunction> gvp1, gvp2; GeometryFunction gf = null; PointFunction p1=null, p2=null; ADQLColumn col1 = null, col2 = null;} {
GeometryFunction GeometryFunction(): {Token fct=null, end
=null
; GeometryValue<GeometryFunction> gvf1, gvf2; GeometryValue<PointFunction> gvp1, gvp2; GeometryFunction gf = null; PointFunction p1=null, p2=null; ADQLColumn col1 = null, col2 = null;} {
try{
try{
// predicate_geometry_function
// predicate_geometry_function
(
(
...
@@ -1196,8 +1196,47 @@ GeometryFunction GeometryFunction(): {Token fct=null, end; GeometryValue<Geometr
...
@@ -1196,8 +1196,47 @@ GeometryFunction GeometryFunction(): {Token fct=null, end; GeometryValue<Geometr
| (fct=<AREA> <LEFT_PAR> gvf1=GeometryExpression() end=<RIGHT_PAR>) {gf = queryFactory.createArea(gvf1);}
| (fct=<AREA> <LEFT_PAR> gvf1=GeometryExpression() end=<RIGHT_PAR>) {gf = queryFactory.createArea(gvf1);}
| (fct=<COORD1> <LEFT_PAR> (p1=Point() {gf = queryFactory.createCoord1(p1);} | col1=Column() {col1.setExpectedType('G'); gf = queryFactory.createCoord1(col1);}) end=<RIGHT_PAR>)
| (fct=<COORD1> <LEFT_PAR> (p1=Point() {gf = queryFactory.createCoord1(p1);} | col1=Column() {col1.setExpectedType('G'); gf = queryFactory.createCoord1(col1);}) end=<RIGHT_PAR>)
| (fct=<COORD2> <LEFT_PAR> (p1=Point() {gf = queryFactory.createCoord2(p1);} | col1=Column() {col1.setExpectedType('G'); gf = queryFactory.createCoord2(col1);}) end=<RIGHT_PAR>)
| (fct=<COORD2> <LEFT_PAR> (p1=Point() {gf = queryFactory.createCoord2(p1);} | col1=Column() {col1.setExpectedType('G'); gf = queryFactory.createCoord2(col1);}) end=<RIGHT_PAR>)
| (fct=<DISTANCE>
| (gf=DistanceFunction())
<LEFT_PAR>
)
}catch(Exception ex){
throw generateParseException(ex);
}
{
if (fct != null)
gf.setPosition(new TextPosition(fct, end));
return gf;
}
}
DistanceFunction DistanceFunction(): { Token fct=null, end=null; DistanceFunction gf; ADQLOperand lon, lat; GeometryValue<PointFunction> gvp1, gvp2; } {
try {
// DISTANCE(POINT,POINT)
(LOOKAHEAD(DistanceFunction2())
gf=DistanceFunction2()
|
// DISTANCE(lon1, lat1, lon2, lat2)
fct=<DISTANCE> <LEFT_PAR>
lon=NumericExpression() <COMMA> lat=NumericExpression()
{ gvp1 = new GeometryValue<PointFunction>(queryFactory.createPoint(null, lon, lat)); }
<COMMA>
lon=NumericExpression() <COMMA> lat=NumericExpression()
{ gvp2 = new GeometryValue<PointFunction>(queryFactory.createPoint(null, lon, lat)); }
end=<RIGHT_PAR>
{
gf = queryFactory.createDistance(gvp1, gvp2);
gf.setPosition(new TextPosition(fct, end));
}
)
{ return gf; }
}catch(Exception ex){
throw generateParseException(ex);
}
}
DistanceFunction DistanceFunction2(): { Token fct=null, end=null; DistanceFunction gf; GeometryValue<PointFunction> gvp1, gvp2; PointFunction p1=null, p2=null; ADQLColumn col1=null, col2=null; } {
try {
fct=<DISTANCE> <LEFT_PAR>
(p1=Point()|col1=Column())
(p1=Point()|col1=Column())
{
{
if (p1 != null)
if (p1 != null)
...
@@ -1218,16 +1257,13 @@ GeometryFunction GeometryFunction(): {Token fct=null, end; GeometryValue<Geometr
...
@@ -1218,16 +1257,13 @@ GeometryFunction GeometryFunction(): {Token fct=null, end; GeometryValue<Geometr
}
}
}
}
end=<RIGHT_PAR>
end=<RIGHT_PAR>
{gf = queryFactory.createDistance(gvp1, gvp2);}
)
)
}catch(Exception ex){
throw generateParseException(ex);
}
{
{
gf = queryFactory.createDistance(gvp1, gvp2);
gf.setPosition(new TextPosition(fct, end));
gf.setPosition(new TextPosition(fct, end));
return gf;
}
{ return gf; }
}catch(Exception ex){
throw generateParseException(ex);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
test/adql/parser/TestADQLParser.java
+
32
−
0
View file @
9f845f0b
...
@@ -735,4 +735,36 @@ public class TestADQLParser {
...
@@ -735,4 +735,36 @@ public class TestADQLParser {
}
}
}
}
@Test
public
void
testDistance
()
{
// CASE: In ADQL-2.0, DISTANCE(POINT, POINT) is allowed:
ADQLParser
parser
=
new
ADQLParser
(
ADQLVersion
.
V2_0
);
try
{
assertEquals
(
"DISTANCE(POINT('', ra, dec), POINT('', ra2, dec2))"
,
parser
.
parseSelect
(
"SELECT DISTANCE(POINT('', ra, dec), POINT('', ra2, dec2))"
).
get
(
0
).
toADQL
());
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
fail
(
"Unexpected error! All ADQL expressions were composed of correct tokens. (see console for more details)"
);
}
// CASE: ...BUT not DISTANCE(lon1, lat1, lon2, lat2)
try
{
parser
.
parseSelect
(
"SELECT DISTANCE(ra, dec, ra2, dec2)"
);
fail
(
"In ADQL-2.0, DISTANCE(lon1, lat1, lon2, lat2) should not be allowed!"
);
}
catch
(
Exception
ex
)
{
assertEquals
(
ParseException
.
class
,
ex
.
getClass
());
assertEquals
(
" Encountered \",\". Was expecting one of: \")\" \".\" \".\" \")\" "
,
ex
.
getMessage
());
}
/* CASE: In ADQL-2.1 (and more), DISTANCE(POINT, POINT) and
* DISTANCE(lon1, lat1, lon2, lat2) are both allowed: */
parser
=
new
ADQLParser
(
ADQLVersion
.
V2_1
);
try
{
assertEquals
(
"DISTANCE(POINT('', ra, dec), POINT('', ra2, dec2))"
,
parser
.
parseSelect
(
"SELECT DISTANCE(POINT('', ra, dec), POINT('', ra2, dec2))"
).
get
(
0
).
toADQL
());
assertEquals
(
"DISTANCE(POINT('', ra, dec), POINT('', ra2, dec2))"
,
parser
.
parseSelect
(
"SELECT DISTANCE(ra, dec, ra2, dec2)"
).
get
(
0
).
toADQL
());
}
catch
(
Exception
ex
)
{
ex
.
printStackTrace
();
fail
(
"Unexpected error! All ADQL expressions were composed of correct tokens. (see console for more details)"
);
}
}
}
}
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
register
or
sign in
to comment