Commit e3b89775 authored by Grégory Mantelet's avatar Grégory Mantelet
Browse files

[ADQL] Move validation of coord. sys. and STC-s expressions from DBChecker to

ADQLParser.
parent e4366686
Loading
Loading
Loading
Loading
+95 −37
Original line number Diff line number Diff line
@@ -77,14 +77,14 @@ import adql.search.SimpleSearchHandler;
 * 		query</li>
 * 	<li>Resolve all unknown functions as supported User Defined Functions
 * 		(UDFs)</li>
 * 	<li>Check whether all used coordinate systems are supported</li>
 * 	<li>Check that types of columns and UDFs match with their context</li>
 * </ol>
 *
 * <p><i><b>IMPORTANT note:</b>
 * 	Since v2.0, the check of supported geometrical functions is performed
 * 	directly in ADQLParser through the notion of Optional Features.
 * 	The declaration of supported geometrical functions must now be done
 * 	Since v2.0, the check of supported geometric functions, STC-s expressions
 * 	and coordinate systems are performed automatically in
 * 	{@link adql.parser.ADQLParser ADQLParser} through the notion of Optional
 * 	Features. The declaration of supported geometric functions must now be done
 * 	with {@link adql.parser.ADQLParser#getSupportedFeatures() ADQLParser.getSupportedFeatures()}
 * 	(see also {@link adql.parser.feature.FeatureSet FeatureSet}).
 * </i></p>
@@ -108,11 +108,11 @@ import adql.search.SimpleSearchHandler;
 * 	particularly useful for the translation of the ADQL query to SQL, because
 * 	the ADQL name of columns and tables can be replaced in SQL by their DB name,
 * 	if different. This mapping is done automatically by
 * 	{@link adql.translator.JDBCTranslator}.
 * 	{@link adql.translator.JDBCTranslator JDBCTranslator}.
 * </i></p>
 *
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (07/2019)
 * @version 2.0 (08/2019)
 */
public class DBChecker implements QueryChecker {

@@ -148,13 +148,19 @@ public class DBChecker implements QueryChecker {
	 * 	However, if not, all items of this list must be the only allowed coordinate systems.
	 * 	So, if the list is empty, none is allowed.
	 * </p>
	 * @since 1.3 */
	 * @since 1.3
	 * @deprecated Since v2.0, supported coordinate systems must be declared
	 *             in ADQLParser. */
	@Deprecated
	protected String[] allowedCoordSys = null;

	/** <p>A regular expression built using the list of allowed coordinate systems.
	 * With this regex, it is possible to known whether a coordinate system expression is allowed or not.</p>
	 * <p>If NULL, all coordinate systems are allowed.</p>
	 * @since 1.3 */
	 * @since 1.3
	 * @deprecated Since v2.0, supported coordinate systems must be declared
	 *             in ADQLParser. */
	@Deprecated
	protected String coordSysRegExp = null;

	/** <p>List of all allowed User Defined Functions (UDFs).</p>
@@ -341,7 +347,13 @@ public class DBChecker implements QueryChecker {
	 * @return	A sorted array containing all - except NULL and empty strings - items of the given collection.
	 *
	 * @since 1.3
	 *
	 * @deprecated	Since v2.0, this tool function is no longer used. It was
	 *            	useful only to collect allowed geometries and coordinate
	 *            	systems....but these are now checked by
	 *            	{@link adql.parser.ADQLParser ADQLParser}.
	 */
	@Deprecated
	protected final static String[] specialSort(final Collection<String> items) {
		// Nothing to do if the array is NULL:
		if (items == null)
@@ -392,16 +404,18 @@ public class DBChecker implements QueryChecker {
	/* CHECK METHODS */
	/* ************* */
	/**
	 * <p>Check all the columns, tables and UDFs references inside the given query.</p>
	 * Check all the columns, tables and UDFs references inside the given query.
	 *
	 * <p><i>
	 * 	<u>Note:</u> This query has already been parsed ; thus it is already syntactically correct.
	 * 	Only the consistency with the published tables, columns and all the defined UDFs must be checked.
	 * <p><i><b>Note:</b>
	 * 	This query has already been parsed ; thus it is already syntactically
	 * 	correct. Only the consistency with the published tables, columns and all
	 * 	the defined UDFs must be checked.
	 * </i></p>
	 *
	 * @param query		The query to check.
	 *
	 * @throws ParseException	An {@link UnresolvedIdentifiersException} if some tables or columns can not be resolved.
	 * @throws ParseException	An {@link UnresolvedIdentifiersException} if
	 *                       	some tables or columns can not be resolved.
	 *
	 * @see #check(ADQLQuery, Stack)
	 */
@@ -411,31 +425,37 @@ public class DBChecker implements QueryChecker {
	}

	/**
	 * <p>Process several (semantic) verifications in the given ADQL query.</p>
	 * Process several (semantic) verifications in the given ADQL query.
	 *
	 * <p>Main verifications done in this function:</p>
	 * <ol>
	 * 	<li>Existence of DB items (tables and columns)</li>
	 * 	<li>Semantic verification of sub-queries</li>
	 * 	<li>Support of every encountered User Defined Functions (UDFs - functions unknown by the syntactic parser)</li>
	 * 	<li>Support of every encountered geometries (functions, coordinate systems and STC-S expressions)</li>
	 * 	<li>Consistency of types still unknown (because the syntactic parser could not yet resolve them)</li>
	 * 	<li>Support of every encountered User Defined Functions (UDFs -
	 * 		functions unknown by the syntactic parser)</li>
	 * 	<li>Consistency of types still unknown (because the syntactic parser
	 * 		could not yet resolve them)</li>
	 * </ol>
	 *
	 * @param query			The query to check.
	 * @param fathersList	List of all columns available in the father queries and that should be accessed in sub-queries.
	 *                   	Each item of this stack is a list of columns available in each father-level query.
	 *                   	<i>Note: this parameter is NULL if this function is called with the root/father query as parameter.</i>
	 *
	 * @throws UnresolvedIdentifiersException	An {@link UnresolvedIdentifiersException} if one or several of the above listed tests have detected
	 *                                       	some semantic errors (i.e. unresolved table, columns, function).
	 * @param fathersList	List of all columns available in the father queries
	 *                   	and that should be accessed in sub-queries. Each
	 *                   	item of this stack is a list of columns available in
	 *                   	each father-level query. <i><b>Note:</b> this
	 *                   	parameter is NULL if this function is called with
	 *                   	the root/father query as parameter.</i>
	 *
	 * @throws UnresolvedIdentifiersException	An {@link UnresolvedIdentifiersException}
	 *                                       	if one or several of the above
	 *                                       	listed tests have detected some
	 *                                       	semantic errors (i.e. unresolved
	 *                                       	table, columns, function).
	 *
	 * @since 1.2
	 *
	 * @see #checkDBItems(ADQLQuery, Stack, UnresolvedIdentifiersException)
	 * @see #checkSubQueries(ADQLQuery, Stack, SearchColumnList, UnresolvedIdentifiersException)
	 * @see #checkUDFs(ADQLQuery, UnresolvedIdentifiersException)
	 * @see #checkGeometries(ADQLQuery, UnresolvedIdentifiersException)
	 * @see #checkTypes(ADQLQuery, UnresolvedIdentifiersException)
	 */
	protected void check(final ADQLQuery query, final Stack<SearchColumnList> fathersList) throws UnresolvedIdentifiersException {
@@ -448,13 +468,10 @@ public class DBChecker implements QueryChecker {
		if (allowedUdfs != null)
			checkUDFs(query, errors);

		// C. Check geometries:
		checkGeometries(query, errors);

		// D. Check types:
		// C. Check types:
		checkTypes(query, errors);

		// E. Check sub-queries:
		// D. Check sub-queries:
		checkSubQueries(query, fathersList, availableColumns, errors);

		// Throw all errors, if any:
@@ -1014,7 +1031,16 @@ public class DBChecker implements QueryChecker {
	 * @see #resolveSTCSExpressions(ADQLQuery, BinarySearch, UnresolvedIdentifiersException)
	 *
	 * @since 1.3
	 *
	 * @deprecated	Since 2.0, validation of the geometric functions is
	 *            	performed automatically by
	 *            	{@link adql.parser.ADQLParser ADQLParser}. Geometric
	 *            	functions are optional features and should be declared as
	 *            	such in the {@link adql.parser.ADQLParser ADQLParser} if
	 *            	they are supported (see
	 *            	{@link adql.parser.ADQLParser#getSupportedFeatures() ADQLParser.getSupportedFeatures()}).
	 */
	@Deprecated
	protected void checkGeometries(final ADQLQuery query, final UnresolvedIdentifiersException errors) {
		BinarySearch<String, String> binSearch = new BinarySearch<String, String>() {
			@Override
@@ -1041,10 +1067,13 @@ public class DBChecker implements QueryChecker {
	 * @see #checkGeometryFunction(String, ADQLFunction, BinarySearch, UnresolvedIdentifiersException)
	 *
	 * @since 1.3
	 * @deprecated	No more used since v2.0. Check of the geometric functions is
	 *            	now performed directly in ADQLParser. Geometric functions
	 *            	are optional features and should be declared as such in the
	 *            	ADQLParser if they are supported (see
	 *
	 * @deprecated	Since 2.0, validation of the geometric functions is
	 *            	performed automatically by
	 *            	{@link adql.parser.ADQLParser ADQLParser}. Geometric
	 *            	functions are optional features and should be declared as
	 *            	such in the {@link adql.parser.ADQLParser ADQLParser} if
	 *            	they are supported (see
	 *            	{@link adql.parser.ADQLParser#getSupportedFeatures() ADQLParser.getSupportedFeatures()}).
	 */
	@Deprecated
@@ -1076,10 +1105,13 @@ public class DBChecker implements QueryChecker {
	 * @param errors		List of errors to complete in this function each time a geometrical function is not supported.
	 *
	 * @since 1.3
	 * @deprecated	No more used since v2.0. Check of the geometric functions is
	 *            	now performed directly in ADQLParser. Geometric functions
	 *            	are optional features and should be declared as such in the
	 *            	ADQLParser if they are supported (see
	 *
	 * @deprecated	Since 2.0, validation of the geometric functions is
	 *            	performed automatically by
	 *            	{@link adql.parser.ADQLParser ADQLParser}. Geometric
	 *            	functions are optional features and should be declared as
	 *            	such in the {@link adql.parser.ADQLParser ADQLParser} if
	 *            	they are supported (see
	 *            	{@link adql.parser.ADQLParser#getSupportedFeatures() ADQLParser.getSupportedFeatures()}).
	 */
	@Deprecated
@@ -1106,7 +1138,11 @@ public class DBChecker implements QueryChecker {
	 * @see #checkCoordinateSystem(StringConstant, UnresolvedIdentifiersException)
	 *
	 * @since 1.3
	 *
	 * @deprecated	Since 2.0, the validation of coordinate systems is performed
	 *            	automatically by {@link adql.parser.ADQLParser ADQLParser}.
	 */
	@Deprecated
	protected void resolveCoordinateSystems(final ADQLQuery query, final UnresolvedIdentifiersException errors) {
		ISearchHandler sHandler = new SearchCoordSysHandler();
		sHandler.search(query);
@@ -1124,7 +1160,11 @@ public class DBChecker implements QueryChecker {
	 * @see #checkCoordinateSystem(adql.db.STCS.CoordSys, ADQLOperand, UnresolvedIdentifiersException)
	 *
	 * @since 1.3
	 *
	 * @deprecated	Since 2.0, the validation of coordinate systems is performed
	 *            	automatically by {@link adql.parser.ADQLParser ADQLParser}.
	 */
	@Deprecated
	protected void checkCoordinateSystem(final StringConstant adqlCoordSys, final UnresolvedIdentifiersException errors) {
		String coordSysStr = adqlCoordSys.getValue();
		try {
@@ -1142,7 +1182,11 @@ public class DBChecker implements QueryChecker {
	 * @param errors	List of errors to complete in this function each time a coordinate system is not supported.
	 *
	 * @since 1.3
	 *
	 * @deprecated	Since 2.0, the validation of coordinate systems is performed
	 *            	automatically by {@link adql.parser.ADQLParser ADQLParser}.
	 */
	@Deprecated
	protected void checkCoordinateSystem(final CoordSys coordSys, final ADQLOperand operand, final UnresolvedIdentifiersException errors) {
		if (coordSysRegExp != null && coordSys != null && !coordSys.toFullSTCS().matches(coordSysRegExp)) {
			StringBuffer buf = new StringBuffer();
@@ -1180,7 +1224,11 @@ public class DBChecker implements QueryChecker {
	 * @see #checkRegion(adql.db.STCS.Region, RegionFunction, BinarySearch, UnresolvedIdentifiersException)
	 *
	 * @since 1.3
	 *
	 * @deprecated	Since 2.0, the validation of STCs expressions is performed
	 *            	automatically by {@link adql.parser.ADQLParser ADQLParser}.
	 */
	@Deprecated
	protected void resolveSTCSExpressions(final ADQLQuery query, final BinarySearch<String, String> binSearch, final UnresolvedIdentifiersException errors) {
		// Search REGION functions:
		ISearchHandler sHandler = new SearchRegionHandler();
@@ -1224,7 +1272,11 @@ public class DBChecker implements QueryChecker {
	 * @see #checkRegion(adql.db.STCS.Region, RegionFunction, BinarySearch, UnresolvedIdentifiersException)
	 *
	 * @since 1.3
	 *
	 * @deprecated	Since 2.0, the validation of REGIONs is performed
	 *            	automatically by {@link adql.parser.ADQLParser ADQLParser}.
	 */
	@Deprecated
	protected void checkRegion(final Region r, final RegionFunction fct, final BinarySearch<String, String> binSearch, final UnresolvedIdentifiersException errors) {
		if (r == null)
			return;
@@ -1565,7 +1617,10 @@ public class DBChecker implements QueryChecker {
	 * @author Gr&eacute;gory Mantelet (ARI)
	 * @version 1.3 (10/2014)
	 * @since 1.3
	 * @deprecated	Since 2.0, the validation of REGIONs is performed
	 *            	automatically by {@link adql.parser.ADQLParser ADQLParser}.
	 */
	@Deprecated
	private static class SearchCoordSysHandler extends SimpleSearchHandler {
		@Override
		protected boolean match(ADQLObject obj) {
@@ -1588,7 +1643,10 @@ public class DBChecker implements QueryChecker {
	 * @author Gr&eacute;gory Mantelet (ARI)
	 * @version 1.3 (10/2014)
	 * @since 1.3
	 * @deprecated	Since 2.0, the validation of REGIONs is performed
	 *            	automatically by {@link adql.parser.ADQLParser ADQLParser}.
	 */
	@Deprecated
	private static class SearchRegionHandler extends SimpleSearchHandler {
		@Override
		protected boolean match(ADQLObject obj) {
+431 −55

File changed.

Preview size limit exceeded, changes collapsed.

+0 −179
Original line number Diff line number Diff line
@@ -31,10 +31,6 @@ import adql.query.operand.ADQLOperand;
import adql.query.operand.StringConstant;
import adql.query.operand.function.DefaultUDF;
import adql.query.operand.function.UserDefinedFunction;
import adql.query.operand.function.geometry.CircleFunction;
import adql.query.operand.function.geometry.ContainsFunction;
import adql.query.operand.function.geometry.PointFunction;
import adql.query.operand.function.geometry.RegionFunction;
import adql.search.SimpleSearchHandler;
import adql.translator.ADQLTranslator;
import adql.translator.PostgreSQLTranslator;
@@ -405,181 +401,6 @@ public class TestDBChecker {
		}
	}

	@Test
	public void testGeometry() {
		// DECLARE A SIMPLE PARSER where all geometries are allowed by default:
		ADQLParser parser = new ADQLParser();
		parser.setQueryChecker(new DBChecker(tables));

		// Test with several geometries while all are allowed:
		try {
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('', 12.3, 45.6), CIRCLE('', 1.2, 2.3, 5)) = 1;"));
		} catch(ParseException pe) {
			pe.printStackTrace();
			fail("This query contains several geometries, and all are theoretically allowed: this test should have succeeded!");
		}

		// Test with several geometries while only the allowed ones:
		try {
			parser = new ADQLParser();
			parser.getSupportedFeatures().unsupportAll(LanguageFeature.TYPE_ADQL_GEO);
			parser.getSupportedFeatures().support(ContainsFunction.FEATURE);
			parser.getSupportedFeatures().support(PointFunction.FEATURE);
			parser.getSupportedFeatures().support(CircleFunction.FEATURE);

			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('', 12.3, 45.6), CIRCLE('', 1.2, 2.3, 5)) = 1;"));
		} catch(ParseException pe) {
			pe.printStackTrace();
			fail("This query contains several geometries, and all are theoretically allowed: this test should have succeeded!");
		}
		try {
			parser.parseQuery("SELECT * FROM foo WHERE INTERSECTS(POINT('', 12.3, 45.6), CIRCLE('', 1.2, 2.3, 5)) = 1;");
			fail("This query contains a not-allowed geometry function (INTERSECTS): this test should have failed!");
		} catch(ParseException pe) {
			assertTrue(pe instanceof UnresolvedIdentifiersException);
			UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe;
			assertEquals(1, ex.getNbErrors());
			assertEquals("Unsupported ADQL feature: \"INTERSECTS\" (of type 'ivo://ivoa.net/std/TAPRegExt#features-adql-geo')!", ex.getErrors().next().getMessage());
		}

		// Test by adding REGION:
		try {
			parser = new ADQLParser();
			parser.getSupportedFeatures().unsupportAll(LanguageFeature.TYPE_ADQL_GEO);
			parser.getSupportedFeatures().support(ContainsFunction.FEATURE);
			parser.getSupportedFeatures().support(PointFunction.FEATURE);
			parser.getSupportedFeatures().support(CircleFunction.FEATURE);
			parser.getSupportedFeatures().support(RegionFunction.FEATURE);

			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(REGION('Position 12.3 45.6'), REGION('circle 1.2 2.3 5')) = 1;"));
		} catch(ParseException pe) {
			pe.printStackTrace();
			fail("This query contains several geometries, and all are theoretically allowed: this test should have succeeded!");
		}
		// TODO Deal with un/supported Regions inside STC-S!
		try {
			parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(REGION('Position 12.3 45.6'), REGION('BOX 1.2 2.3 5 9')) = 1;");
			fail("This query contains a not-allowed geometry function (BOX): this test should have failed!");
		} catch(ParseException pe) {
			assertTrue(pe instanceof UnresolvedIdentifiersException);
			UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe;
			assertEquals(1, ex.getNbErrors());
			assertEquals("The geometrical function \"BOX\" is not available in this implementation!", ex.getErrors().next().getMessage());
		}

		// Test with several geometries while none geometry is allowed:
		try {
			parser = new ADQLParser();
			parser.getSupportedFeatures().unsupportAll(LanguageFeature.TYPE_ADQL_GEO);

			parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('', 12.3, 45.6), CIRCLE('', 1.2, 2.3, 5)) = 1;");
			fail("This query contains geometries while they are all forbidden: this test should have failed!");
		} catch(ParseException pe) {
			assertTrue(pe instanceof UnresolvedIdentifiersException);
			UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe;
			assertEquals(3, ex.getNbErrors());
			Iterator<ParseException> itErrors = ex.getErrors();
			assertEquals("Unsupported ADQL feature: \"CONTAINS\" (of type 'ivo://ivoa.net/std/TAPRegExt#features-adql-geo')!", itErrors.next().getMessage());
			assertEquals("Unsupported ADQL feature: \"POINT\" (of type 'ivo://ivoa.net/std/TAPRegExt#features-adql-geo')!", itErrors.next().getMessage());
			assertEquals("Unsupported ADQL feature: \"CIRCLE\" (of type 'ivo://ivoa.net/std/TAPRegExt#features-adql-geo')!", itErrors.next().getMessage());
		}
	}

	@Test
	public void testCoordSys() {
		// DECLARE A SIMPLE PARSER where all coordinate systems are allowed by default:
		ADQLParser parser = new ADQLParser();
		parser.setQueryChecker(new DBChecker(tables));

		// Test with several coordinate systems while all are allowed:
		try {
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('', 12.3, 45.6), CIRCLE('', 1.2, 2.3, 5)) = 1;"));
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('icrs', 12.3, 45.6), CIRCLE('cartesian2', 1.2, 2.3, 5)) = 1;"));
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('lsr', 12.3, 45.6), CIRCLE('galactic heliocenter', 1.2, 2.3, 5)) = 1;"));
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('unknownframe', 12.3, 45.6), CIRCLE('galactic unknownrefpos spherical2', 1.2, 2.3, 5)) = 1;"));
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(REGION('position icrs lsr 12.3 45.6'), REGION('circle fk5 1.2 2.3 5')) = 1;"));
			assertNotNull(parser.parseQuery("SELECT Region('not(position 1 2)') FROM foo;"));
		} catch(ParseException pe) {
			pe.printStackTrace();
			fail("This query contains several valid coordinate systems, and all are theoretically allowed: this test should have succeeded!");
		}

		// Concatenation as coordinate systems not checked:
		try {
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('From ' || 'here', 12.3, 45.6), CIRCLE('', 1.2, 2.3, 5)) = 1;"));
		} catch(ParseException pe) {
			pe.printStackTrace();
			fail("This query contains a concatenation as coordinate systems (but only string constants are checked): this test should have succeeded!");
		}

		// Test with several coordinate systems while only some allowed:
		try {
			parser = new ADQLParser();
			parser.setQueryChecker(new DBChecker(tables, new ArrayList<FunctionDef>(0), null, Arrays.asList(new String[]{ "icrs * *", "fk4 geocenter *", "galactic * spherical2" })));
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('', 12.3, 45.6), CIRCLE('', 1.2, 2.3, 5)) = 1;"));
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('icrs', 12.3, 45.6), CIRCLE('cartesian3', 1.2, 2.3, 5)) = 1;"));
			assertNotNull(parser.parseQuery("SELECT POINT('fk4', 12.3, 45.6) FROM foo;"));
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('fk4 geocenter', 12.3, 45.6), CIRCLE('cartesian2', 1.2, 2.3, 5)) = 1;"));
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('galactic', 12.3, 45.6), CIRCLE('galactic spherical2', 1.2, 2.3, 5)) = 1;"));
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('galactic geocenter', 12.3, 45.6), CIRCLE('galactic lsr spherical2', 1.2, 2.3, 5)) = 1;"));
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(REGION('position galactic lsr 12.3 45.6'), REGION('circle icrs 1.2 2.3 5')) = 1;"));
			assertNotNull(parser.parseQuery("SELECT Region('not(position 1 2)') FROM foo;"));
		} catch(ParseException pe) {
			pe.printStackTrace();
			fail("This query contains several valid coordinate systems, and all are theoretically allowed: this test should have succeeded!");
		}
		try {
			parser.parseQuery("SELECT POINT('fk5 geocenter', 12.3, 45.6) FROM foo;");
			fail("This query contains a not-allowed coordinate system ('fk5' is not allowed): this test should have failed!");
		} catch(ParseException pe) {
			assertTrue(pe instanceof UnresolvedIdentifiersException);
			UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe;
			assertEquals(1, ex.getNbErrors());
			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 {
			parser.parseQuery("SELECT Region('not(position fk5 heliocenter 1 2)') FROM foo;");
			fail("This query contains a not-allowed coordinate system ('fk5' is not allowed): this test should have failed!");
		} catch(ParseException pe) {
			assertTrue(pe instanceof UnresolvedIdentifiersException);
			UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe;
			assertEquals(1, ex.getNbErrors());
			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:
		try {
			parser = new ADQLParser();
			parser.setQueryChecker(new DBChecker(tables, new ArrayList<FunctionDef>(0), null, new ArrayList<String>(0)));
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('', 12.3, 45.6), CIRCLE('', 1.2, 2.3, 5)) = 1;"));
			assertNotNull(parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(REGION('position 12.3 45.6'), REGION('circle 1.2 2.3 5')) = 1;"));
			assertNotNull(parser.parseQuery("SELECT Region('not(position 1 2)') FROM foo;"));
		} catch(ParseException pe) {
			pe.printStackTrace();
			fail("This query specifies none coordinate system: this test should have succeeded!");
		}
		try {
			parser.parseQuery("SELECT * FROM foo WHERE CONTAINS(POINT('ICRS SPHERICAL2', 12.3, 45.6), CIRCLE('icrs', 1.2, 2.3, 5)) = 1;");
			fail("This query specifies coordinate systems while they are all forbidden: this test should have failed!");
		} catch(ParseException pe) {
			assertTrue(pe instanceof UnresolvedIdentifiersException);
			UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe;
			assertEquals(2, ex.getNbErrors());
			Iterator<ParseException> itErrors = ex.getErrors();
			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. No coordinate system is allowed!", itErrors.next().getMessage());
		}
		try {
			parser.parseQuery("SELECT Region('not(position fk4 1 2)') FROM foo;");
			fail("This query specifies coordinate systems while they are all forbidden: this test should have failed!");
		} catch(ParseException pe) {
			assertTrue(pe instanceof UnresolvedIdentifiersException);
			UnresolvedIdentifiersException ex = (UnresolvedIdentifiersException)pe;
			assertEquals(1, ex.getNbErrors());
			assertEquals("Coordinate system \"FK4\" (= \"FK4 UNKNOWNREFPOS SPHERICAL2\") not allowed in this implementation. No coordinate system is allowed!", ex.getErrors().next().getMessage());
		}
	}

	@Test
	public void testTypesChecking() {
		// DECLARE A SIMPLE PARSER:
+213 −1

File changed.

Preview size limit exceeded, changes collapsed.