Skip to content
Snippets Groups Projects
Commit 163ec172 authored by gmantele's avatar gmantele
Browse files

[ADQL] Specify position while building UnresolvedFunctionException and UnresolvedJoinException.

parent 8b1c7efd
No related branches found
No related tags found
No related merge requests found
...@@ -97,7 +97,7 @@ import adql.search.SimpleSearchHandler; ...@@ -97,7 +97,7 @@ import adql.search.SimpleSearchHandler;
* </i></p> * </i></p>
* *
* @author Gr&eacute;gory Mantelet (CDS;ARI) * @author Gr&eacute;gory Mantelet (CDS;ARI)
* @version 1.3 (05/2015) * @version 1.4 (06/2015)
*/ */
public class DBChecker implements QueryChecker { public class DBChecker implements QueryChecker {
...@@ -819,7 +819,7 @@ public class DBChecker implements QueryChecker { ...@@ -819,7 +819,7 @@ public class DBChecker implements QueryChecker {
if (match < 0){ if (match < 0){
// ...if the type of all parameters is resolved, add an error (no match is possible): // ...if the type of all parameters is resolved, add an error (no match is possible):
if (isAllParamTypesResolved(udf)) if (isAllParamTypesResolved(udf))
errors.addException(new UnresolvedFunctionException(udf)); // TODO Add the ADQLOperand position! errors.addException(new UnresolvedFunctionException(udf));
// ...otherwise, try to resolved it later (when other UDFs will be mostly resolved): // ...otherwise, try to resolved it later (when other UDFs will be mostly resolved):
else else
toResolveLater.add(udf); toResolveLater.add(udf);
...@@ -836,7 +836,7 @@ public class DBChecker implements QueryChecker { ...@@ -836,7 +836,7 @@ public class DBChecker implements QueryChecker {
match = binSearch.search(udf, allowedUdfs); match = binSearch.search(udf, allowedUdfs);
// if no match, add an error: // if no match, add an error:
if (match < 0) if (match < 0)
errors.addException(new UnresolvedFunctionException(udf)); // TODO Add the ADQLOperand position! errors.addException(new UnresolvedFunctionException(udf));
// otherwise, metadata may be attached (particularly if the function is built automatically by the syntactic parser): // otherwise, metadata may be attached (particularly if the function is built automatically by the syntactic parser):
else if (udf instanceof DefaultUDF) else if (udf instanceof DefaultUDF)
((DefaultUDF)udf).setDefinition(allowedUdfs[match]); ((DefaultUDF)udf).setDefinition(allowedUdfs[match]);
...@@ -1003,7 +1003,7 @@ public class DBChecker implements QueryChecker { ...@@ -1003,7 +1003,7 @@ public class DBChecker implements QueryChecker {
try{ try{
checkCoordinateSystem(STCS.parseCoordSys(coordSysStr), adqlCoordSys, errors); checkCoordinateSystem(STCS.parseCoordSys(coordSysStr), adqlCoordSys, errors);
}catch(ParseException pe){ }catch(ParseException pe){
errors.addException(new ParseException(pe.getMessage())); // TODO Missing object position! errors.addException(new ParseException(pe.getMessage(), adqlCoordSys.getPosition()));
} }
} }
...@@ -1017,8 +1017,21 @@ public class DBChecker implements QueryChecker { ...@@ -1017,8 +1017,21 @@ public class DBChecker implements QueryChecker {
* @since 1.3 * @since 1.3
*/ */
protected void checkCoordinateSystem(final CoordSys coordSys, final ADQLOperand operand, final UnresolvedIdentifiersException errors){ protected void checkCoordinateSystem(final CoordSys coordSys, final ADQLOperand operand, final UnresolvedIdentifiersException errors){
if (coordSysRegExp != null && coordSys != null && !coordSys.toFullSTCS().matches(coordSysRegExp)) if (coordSysRegExp != null && coordSys != null && !coordSys.toFullSTCS().matches(coordSysRegExp)){
errors.addException(new ParseException("Coordinate system \"" + ((operand instanceof StringConstant) ? ((StringConstant)operand).getValue() : coordSys.toString()) + "\" (= \"" + coordSys.toFullSTCS() + "\") not allowed in this implementation.")); // TODO Missing object position! + List of accepted coordinate systems StringBuffer buf = new StringBuffer();
if (allowedCoordSys != null){
for(String cs : allowedCoordSys){
if (buf.length() > 0)
buf.append(", ");
buf.append(cs);
}
}
if (buf.length() == 0)
buf.append("No coordinate system is allowed!");
else
buf.insert(0, "Allowed coordinate systems are: ");
errors.addException(new ParseException("Coordinate system \"" + ((operand instanceof StringConstant) ? ((StringConstant)operand).getValue() : coordSys.toString()) + "\" (= \"" + coordSys.toFullSTCS() + "\") not allowed in this implementation. " + buf.toString(), operand.getPosition()));
}
} }
/** /**
...@@ -1060,7 +1073,7 @@ public class DBChecker implements QueryChecker { ...@@ -1060,7 +1073,7 @@ public class DBChecker implements QueryChecker {
// check whether the regions (this one + the possible inner ones) and the coordinate systems are allowed: // check whether the regions (this one + the possible inner ones) and the coordinate systems are allowed:
checkRegion(region, (RegionFunction)result, binSearch, errors); checkRegion(region, (RegionFunction)result, binSearch, errors);
}catch(ParseException pe){ }catch(ParseException pe){
errors.addException(new ParseException(pe.getMessage())); // TODO Missing object position! errors.addException(new ParseException(pe.getMessage(), result.getPosition()));
} }
} }
} }
...@@ -1155,17 +1168,17 @@ public class DBChecker implements QueryChecker { ...@@ -1155,17 +1168,17 @@ public class DBChecker implements QueryChecker {
case 'G': case 'G':
case 'g': case 'g':
if (!unknown.isGeometry()) if (!unknown.isGeometry())
errors.addException(new ParseException("Type mismatch! A geometry was expected instead of \"" + unknown.toADQL() + "\".")); // TODO Add the ADQLOperand position! errors.addException(new ParseException("Type mismatch! A geometry was expected instead of \"" + unknown.toADQL() + "\".", result.getPosition()));
break; break;
case 'N': case 'N':
case 'n': case 'n':
if (!unknown.isNumeric()) if (!unknown.isNumeric())
errors.addException(new ParseException("Type mismatch! A numeric value was expected instead of \"" + unknown.toADQL() + "\".")); // TODO Add the ADQLOperand position! errors.addException(new ParseException("Type mismatch! A numeric value was expected instead of \"" + unknown.toADQL() + "\".", result.getPosition()));
break; break;
case 'S': case 'S':
case 's': case 's':
if (!unknown.isString()) if (!unknown.isString())
errors.addException(new ParseException("Type mismatch! A string value was expected instead of \"" + unknown.toADQL() + "\".")); // TODO Add the ADQLOperand position! errors.addException(new ParseException("Type mismatch! A string value was expected instead of \"" + unknown.toADQL() + "\".", result.getPosition()));
break; break;
} }
} }
......
...@@ -1395,7 +1395,7 @@ public final class STCS { ...@@ -1395,7 +1395,7 @@ public final class STCS {
if (nextToken().matches(numericRegExp)) if (nextToken().matches(numericRegExp))
return Double.parseDouble(token); return Double.parseDouble(token);
else else
throw new ParseException("a numeric was expected!", new TextPosition(1, pos - token.length(), 1, pos)); // TODO Check the begin and end! throw new ParseException("a numeric was expected!", new TextPosition(1, pos - token.length(), 1, pos));
} }
/** /**
...@@ -1415,7 +1415,7 @@ public final class STCS { ...@@ -1415,7 +1415,7 @@ public final class STCS {
if (pe instanceof EOEException) if (pe instanceof EOEException)
throw pe; throw pe;
else else
throw new ParseException("a coordinates pair (2 numerics separated by one or more spaces) was expected!", new TextPosition(1, startPos, 1, pos)); // TODO Check the begin and end! throw new ParseException("a coordinates pair (2 numerics separated by one or more spaces) was expected!", new TextPosition(1, startPos, 1, pos));
} }
} }
......
...@@ -20,13 +20,14 @@ package adql.db.exception; ...@@ -20,13 +20,14 @@ package adql.db.exception;
*/ */
import adql.parser.ParseException; import adql.parser.ParseException;
import adql.query.TextPosition;
import adql.query.operand.function.ADQLFunction; import adql.query.operand.function.ADQLFunction;
/** /**
* Exception thrown when a function can not be resolved by the library. * Exception thrown when a function can not be resolved by the library.
* *
* @author Gr&eacute;gory Mantelet (ARI) * @author Gr&eacute;gory Mantelet (ARI)
* @version 1.3 (05/2015) * @version 1.4 (06/2015)
* @since 1.3 * @since 1.3
*/ */
public class UnresolvedFunctionException extends ParseException { public class UnresolvedFunctionException extends ParseException {
...@@ -41,7 +42,19 @@ public class UnresolvedFunctionException extends ParseException { ...@@ -41,7 +42,19 @@ public class UnresolvedFunctionException extends ParseException {
* @param message Description of the error. * @param message Description of the error.
*/ */
public UnresolvedFunctionException(final String message){ public UnresolvedFunctionException(final String message){
super(message); this(message, (TextPosition)null);
}
/**
* Build the exception with just a message.
*
* @param message Description of the error.
* @param pos Position of the unresolved function inside the ADQL query.
*
* @since 1.4
*/
public UnresolvedFunctionException(final String message, final TextPosition pos){
super(message, pos);
functionInError = null; functionInError = null;
} }
...@@ -52,7 +65,7 @@ public class UnresolvedFunctionException extends ParseException { ...@@ -52,7 +65,7 @@ public class UnresolvedFunctionException extends ParseException {
* @param fct The unresolved function. * @param fct The unresolved function.
*/ */
public UnresolvedFunctionException(final ADQLFunction fct){ public UnresolvedFunctionException(final ADQLFunction fct){
super("Unresolved function: \"" + fct.toADQL() + "\"! No UDF has been defined or found with the signature: " + getFctSignature(fct) + "."); // TODO Add the position of the function in the ADQL query! super("Unresolved function: \"" + fct.toADQL() + "\"! No UDF has been defined or found with the signature: " + getFctSignature(fct) + ".", fct.getPosition());
functionInError = fct; functionInError = fct;
} }
...@@ -64,7 +77,7 @@ public class UnresolvedFunctionException extends ParseException { ...@@ -64,7 +77,7 @@ public class UnresolvedFunctionException extends ParseException {
* @param fct The unresolved function. * @param fct The unresolved function.
*/ */
public UnresolvedFunctionException(final String message, final ADQLFunction fct){ public UnresolvedFunctionException(final String message, final ADQLFunction fct){
super(message); // TODO Add the position of the function in the ADQL query! super(message, (fct == null) ? null : fct.getPosition());
functionInError = fct; functionInError = fct;
} }
......
...@@ -26,8 +26,8 @@ import adql.query.TextPosition; ...@@ -26,8 +26,8 @@ import adql.query.TextPosition;
* This exception is thrown when a table between 2 tables can not be resolved, * This exception is thrown when a table between 2 tables can not be resolved,
* and particularly because of the join condition (i.e. column names not found, ...). * and particularly because of the join condition (i.e. column names not found, ...).
* *
* @author Gr&eacute;gory Mantelet (ARI) - gmantele@ari.uni-heidelberg.de * @author Gr&eacute;gory Mantelet (ARI)
* @version 1.3 (05/2015) * @version 1.4 (06/2015)
* @since 1.2 * @since 1.2
*/ */
public class UnresolvedJoinException extends ParseException { public class UnresolvedJoinException extends ParseException {
...@@ -53,4 +53,15 @@ public class UnresolvedJoinException extends ParseException { ...@@ -53,4 +53,15 @@ public class UnresolvedJoinException extends ParseException {
super(message, errorPosition); super(message, errorPosition);
} }
/**
* Set the position of the invalid JOIN.
*
* @param pos Position of the concerned JOIN inside the ADQL query.
*
* @since 1.4
*/
public void setPosition(final TextPosition pos){
this.position = pos;
}
} }
...@@ -364,6 +364,7 @@ public abstract class ADQLJoin implements ADQLObject, FromContent { ...@@ -364,6 +364,7 @@ public abstract class ADQLJoin implements ADQLObject, FromContent {
@Override @Override
public SearchColumnList getDBColumns() throws UnresolvedJoinException{ public SearchColumnList getDBColumns() throws UnresolvedJoinException{
try{
SearchColumnList list = new SearchColumnList(); SearchColumnList list = new SearchColumnList();
SearchColumnList leftList = leftTable.getDBColumns(); SearchColumnList leftList = leftTable.getDBColumns();
SearchColumnList rightList = rightTable.getDBColumns(); SearchColumnList rightList = rightTable.getDBColumns();
...@@ -422,6 +423,10 @@ public abstract class ADQLJoin implements ADQLObject, FromContent { ...@@ -422,6 +423,10 @@ public abstract class ADQLJoin implements ADQLObject, FromContent {
list.addAll(mapDuplicated.values()); list.addAll(mapDuplicated.values());
return list; return list;
}catch(UnresolvedJoinException uje){
uje.setPosition(position);
throw uje;
}
} }
public final static void addAllExcept(final SearchColumnList itemsToAdd, final SearchColumnList target, final Map<String,DBCommonColumn> exception){ public final static void addAllExcept(final SearchColumnList itemsToAdd, final SearchColumnList target, final Map<String,DBCommonColumn> exception){
......
...@@ -315,7 +315,7 @@ public class TestDBChecker { ...@@ -315,7 +315,7 @@ public class TestDBChecker {
assertTrue(pe instanceof UnresolvedIdentifiersException); assertTrue(pe instanceof UnresolvedIdentifiersException);
UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe; UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe;
assertEquals(1, ex.getNbErrors()); assertEquals(1, ex.getNbErrors());
assertEquals("Coordinate system \"fk5 geocenter\" (= \"FK5 GEOCENTER SPHERICAL2\") not allowed in this implementation.", ex.getErrors().next().getMessage()); assertEquals("Coordinate system \"fk5 geocenter\" (= \"FK5 GEOCENTER SPHERICAL2\") not allowed in this implementation. Allowed coordinate systems are: fk4 geocenter *, galactic * spherical2, icrs * *", ex.getErrors().next().getMessage());
} }
try{ try{
parser.parseQuery("SELECT Region('not(position fk5 heliocenter 1 2)') FROM foo;"); parser.parseQuery("SELECT Region('not(position fk5 heliocenter 1 2)') FROM foo;");
...@@ -324,7 +324,7 @@ public class TestDBChecker { ...@@ -324,7 +324,7 @@ public class TestDBChecker {
assertTrue(pe instanceof UnresolvedIdentifiersException); assertTrue(pe instanceof UnresolvedIdentifiersException);
UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe; UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe;
assertEquals(1, ex.getNbErrors()); assertEquals(1, ex.getNbErrors());
assertEquals("Coordinate system \"FK5 HELIOCENTER\" (= \"FK5 HELIOCENTER SPHERICAL2\") not allowed in this implementation.", ex.getErrors().next().getMessage()); assertEquals("Coordinate system \"FK5 HELIOCENTER\" (= \"FK5 HELIOCENTER SPHERICAL2\") not allowed in this implementation. Allowed coordinate systems are: fk4 geocenter *, galactic * spherical2, icrs * *", ex.getErrors().next().getMessage());
} }
// Test with a coordinate system while none is allowed: // Test with a coordinate system while none is allowed:
...@@ -345,8 +345,8 @@ public class TestDBChecker { ...@@ -345,8 +345,8 @@ public class TestDBChecker {
UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe; UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe;
assertEquals(2, ex.getNbErrors()); assertEquals(2, ex.getNbErrors());
Iterator<ParseException> itErrors = ex.getErrors(); Iterator<ParseException> itErrors = ex.getErrors();
assertEquals("Coordinate system \"ICRS SPHERICAL2\" (= \"ICRS UNKNOWNREFPOS SPHERICAL2\") not allowed in this implementation.", itErrors.next().getMessage()); assertEquals("Coordinate system \"ICRS SPHERICAL2\" (= \"ICRS UNKNOWNREFPOS SPHERICAL2\") not allowed in this implementation. No coordinate system is allowed!", itErrors.next().getMessage());
assertEquals("Coordinate system \"icrs\" (= \"ICRS UNKNOWNREFPOS SPHERICAL2\") not allowed in this implementation.", itErrors.next().getMessage()); assertEquals("Coordinate system \"icrs\" (= \"ICRS UNKNOWNREFPOS SPHERICAL2\") not allowed in this implementation. No coordinate system is allowed!", itErrors.next().getMessage());
} }
try{ try{
parser.parseQuery("SELECT Region('not(position fk4 1 2)') FROM foo;"); parser.parseQuery("SELECT Region('not(position fk4 1 2)') FROM foo;");
...@@ -355,7 +355,7 @@ public class TestDBChecker { ...@@ -355,7 +355,7 @@ public class TestDBChecker {
assertTrue(pe instanceof UnresolvedIdentifiersException); assertTrue(pe instanceof UnresolvedIdentifiersException);
UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe; UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe;
assertEquals(1, ex.getNbErrors()); assertEquals(1, ex.getNbErrors());
assertEquals("Coordinate system \"FK4\" (= \"FK4 UNKNOWNREFPOS SPHERICAL2\") not allowed in this implementation.", ex.getErrors().next().getMessage()); assertEquals("Coordinate system \"FK4\" (= \"FK4 UNKNOWNREFPOS SPHERICAL2\") not allowed in this implementation. No coordinate system is allowed!", ex.getErrors().next().getMessage());
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment