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

[ADQL] An ADQLTranslator now provides a list of all features it supports,

& Rename UnitConversionFunction into InUnitFunction.
parent f265eb17
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ import adql.query.operand.function.MathFunction;
import adql.query.operand.function.MathFunctionType;
import adql.query.operand.function.SQLFunction;
import adql.query.operand.function.SQLFunctionType;
import adql.query.operand.function.UnitConversionFunction;
import adql.query.operand.function.InUnitFunction;
import adql.query.operand.function.UserDefinedFunction;
import adql.query.operand.function.geometry.AreaFunction;
import adql.query.operand.function.geometry.BoxFunction;
@@ -319,8 +319,8 @@ public class ADQLQueryFactory {
	}

	/** @since 2.0 */
	public UnitConversionFunction createUnitConversionFunction(final ADQLOperand value, final ADQLOperand targetUnit) throws Exception {
		return new UnitConversionFunction(value, targetUnit);
	public InUnitFunction createInUnitFunction(final ADQLOperand value, final ADQLOperand targetUnit) throws Exception {
		return new InUnitFunction(value, targetUnit);
	}

	/**
+2 −2
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ import adql.query.ClauseOffset;
import adql.query.constraint.ComparisonOperator;
import adql.query.operand.BitNotOperand;
import adql.query.operand.OperationType;
import adql.query.operand.function.UnitConversionFunction;
import adql.query.operand.function.InUnitFunction;
import adql.query.operand.function.geometry.AreaFunction;
import adql.query.operand.function.geometry.BoxFunction;
import adql.query.operand.function.geometry.CentroidFunction;
@@ -597,7 +597,7 @@ public class FeatureSet implements Iterable<LanguageFeature> {
	 * <p><i><b>Important note:</b>
	 * 	All of them must be optional and must have a type.
	 * </i></p> */
	static LanguageFeature[] availableFeatures = new LanguageFeature[]{ UnitConversionFunction.FEATURE, BitNotOperand.FEATURE, OperationType.BIT_AND.getFeatureDescription(), OperationType.BIT_OR.getFeatureDescription(), OperationType.BIT_XOR.getFeatureDescription(), ClauseOffset.FEATURE, ComparisonOperator.ILIKE.getFeatureDescription(), LowerFunction.FEATURE, AreaFunction.FEATURE, BoxFunction.FEATURE, CentroidFunction.FEATURE, CircleFunction.FEATURE, ContainsFunction.FEATURE, ExtractCoord.FEATURE_COORD1, ExtractCoord.FEATURE_COORD2, ExtractCoordSys.FEATURE, DistanceFunction.FEATURE, IntersectsFunction.FEATURE, PointFunction.FEATURE, PolygonFunction.FEATURE, RegionFunction.FEATURE };
	static LanguageFeature[] availableFeatures = new LanguageFeature[]{ InUnitFunction.FEATURE, BitNotOperand.FEATURE, OperationType.BIT_AND.getFeatureDescription(), OperationType.BIT_OR.getFeatureDescription(), OperationType.BIT_XOR.getFeatureDescription(), ClauseOffset.FEATURE, ComparisonOperator.ILIKE.getFeatureDescription(), LowerFunction.FEATURE, AreaFunction.FEATURE, BoxFunction.FEATURE, CentroidFunction.FEATURE, CircleFunction.FEATURE, ContainsFunction.FEATURE, ExtractCoord.FEATURE_COORD1, ExtractCoord.FEATURE_COORD2, ExtractCoordSys.FEATURE, DistanceFunction.FEATURE, IntersectsFunction.FEATURE, PointFunction.FEATURE, PolygonFunction.FEATURE, RegionFunction.FEATURE };

	/**
	 * List all available language features.
+36 −0
Original line number Diff line number Diff line

## Default features set in ADQLParser

At its initialization, ADQLParser sets a list of supported optional language
features. By default, this list is as permissive as possible: everything
compatible with the implemented ADQL version is supported, and any UDF (even if
not declared) is allowed.

Of course, this list can be customized after creation of the parser.
_See the javadoc of ADQLParser for more technical details._ 

## Supported features provided by an ADQLTranslator

Databases are not supported guaranteed to support all optional features
introduced by ADQL.

For this reason, an appropriate list of supported optional features is provided 
in each implementation of ADQLTranslator: use the function
ADQLTranslator.getSupportedFeatures() to discover these features.

Here is a sum-up of supported features for each implemented translator:

|       Feature        | MySQL | MS-SQL Server | PostgreSQL | PgSphere |
| bitwise operations   |   X   |       X       |      X     |     X    |
| LOWER                |   X   |       X       |      X     |     X    |
| geometries           |       |               |            |     X    |
| ILIKE                |       |               |      X     |     X    |
| IN_UNIT              |       |               |            |          |


**Note about `ILIKE`:** In MySQL and MS-SQLServer, the case sensitiveness of
string comparison is determined by the collation of the compared strings.
ADQL-Lib could translate the ADQL's `o1 ILIKE o2` into
`LOWER(o1) LIKE LOWER(o2)` but in such case, the use of index on the column o1
would fail. That's why nothing is done by default in ADQL-Lib. Whether or not
search in a column must be case sensitive or not is completely DB dependant.
+3 −3
Original line number Diff line number Diff line
@@ -1504,16 +1504,16 @@ ADQLFunction NumericFunction(): {ADQLFunction fct;} {
	(fct=MathFunction()
	| fct=TrigFunction()
	| fct=GeometryFunction()
	| fct=UnitConversionFunction()
	| fct=InUnitFunction()
	| fct=UserDefinedFunction() { ((UserDefinedFunction)fct).setExpectedType('N'); })
	{return fct;}
}

UnitConversionFunction UnitConversionFunction() : { Token start, end; ADQLOperand value, destUnit; } {
InUnitFunction InUnitFunction() : { Token start, end; ADQLOperand value, destUnit; } {
	start=<IN_UNIT> <LEFT_PAR> value=NumericExpression() <COMMA> destUnit=StringExpression() end=<RIGHT_PAR>
	{
		try {
			UnitConversionFunction fct = queryFactory.createUnitConversionFunction(value, destUnit);
			InUnitFunction fct = queryFactory.createInUnitFunction(value, destUnit);
			fct.setPosition(new TextPosition(start, end));
			return fct;
		}catch(Exception ex) {
+3 −3
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ import adql.query.operand.ADQLOperand;
 * @version 2.0 (08/2019)
 * @since 2.0
 */
public class UnitConversionFunction extends ADQLFunction {
public class InUnitFunction extends ADQLFunction {

	/** Description of this ADQL Feature. */
	public static final LanguageFeature FEATURE = new LanguageFeature(LanguageFeature.TYPE_ADQL_UNIT, "IN_UNIT", true, "Convert the given value (1st argument) into the given VO-Unit (2nd argument).");
@@ -61,7 +61,7 @@ public class UnitConversionFunction extends ADQLFunction {
	 * @throws IllegalArgumentException	If the 1st operand is not a numeric,
	 *                                 	or if the 2nd is not a string.
	 */
	public UnitConversionFunction(final ADQLOperand value, final ADQLOperand targetUnit) throws NullPointerException, IllegalArgumentException {
	public InUnitFunction(final ADQLOperand value, final ADQLOperand targetUnit) throws NullPointerException, IllegalArgumentException {
		setValue(value);
		setTargetUnit(targetUnit);
	}
@@ -147,7 +147,7 @@ public class UnitConversionFunction extends ADQLFunction {

	@Override
	public ADQLObject getCopy() throws Exception {
		return new UnitConversionFunction((ADQLOperand)value.getCopy(), (ADQLOperand)targetUnit.getCopy());
		return new InUnitFunction((ADQLOperand)value.getCopy(), (ADQLOperand)targetUnit.getCopy());
	}

	@Override
Loading