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

[ADQL] Remove bitwise operators and hexadecimal values....they are not yet

mature as defined in PR-ADQL-2.1 (see slides 26 of the talk
["Feedback on the implementation of ADQL-2.1"](https://wiki.ivoa.net/internal/IVOA/InterOpOct2019DAL/feedback_adql2_1.pdf)).
parent 8b0cc7c2
Loading
Loading
Loading
Loading
+1 −17
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import adql.query.from.OuterJoin;
import adql.query.from.OuterJoin.OuterType;
import adql.query.operand.ADQLColumn;
import adql.query.operand.ADQLOperand;
import adql.query.operand.BitNotOperand;
import adql.query.operand.Concatenation;
import adql.query.operand.NegativeOperand;
import adql.query.operand.NumericConstant;
@@ -93,7 +92,7 @@ import adql.query.operand.function.string.LowerFunction;
 * </p>
 *
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (08/2019)
 * @version 2.0 (11/2019)
 *
 * @see ADQLParser
 */
@@ -258,21 +257,6 @@ public class ADQLQueryFactory {
		return new NegativeOperand(opToNegativate);
	}

	/**
	 * Create the object representation of the bitwise operation NOT (i.e.
	 * binary complement) applied to the given operand.
	 *
	 * @param operandToBitNot	Operand whose binary complement must be
	 *                       	computed.
	 *
	 * @return	The corresponding object representation of this bitwise
	 *        	operation.
	 *
	 * @since 2.0 */
	public BitNotOperand createBitNotOperand(ADQLOperand operandToBitNot) throws Exception {
		return new BitNotOperand(operandToBitNot);
	}

	public Concatenation createConcatenation() throws Exception {
		return new Concatenation();
	}
+2 −4
Original line number Diff line number Diff line
@@ -31,8 +31,6 @@ import adql.db.FunctionDef;
import adql.query.ClauseOffset;
import adql.query.WithItem;
import adql.query.constraint.ComparisonOperator;
import adql.query.operand.BitNotOperand;
import adql.query.operand.OperationType;
import adql.query.operand.function.InUnitFunction;
import adql.query.operand.function.geometry.AreaFunction;
import adql.query.operand.function.geometry.BoxFunction;
@@ -151,7 +149,7 @@ import adql.query.operand.function.string.LowerFunction;
 * </ul>
 *
 * @author Gr&eacute;gory Mantelet (CDS)
 * @version 2.0 (08/2019)
 * @version 2.0 (11/2019)
 * @since 2.0
 */
public class FeatureSet implements Iterable<LanguageFeature> {
@@ -596,7 +594,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[]{ WithItem.FEATURE, 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 };
	static LanguageFeature[] availableFeatures = new LanguageFeature[]{ WithItem.FEATURE, InUnitFunction.FEATURE, 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.
+0 −1
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ 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    |
+10 −44
Original line number Diff line number Diff line
@@ -31,7 +31,7 @@
* ParseException is thrown.
*
* Author:  Gr&eacute;gory Mantelet (CDS)
* Version: 2.0 (09/2019)
* Version: 2.0 (11/2019)
*/

							/* ########### */
@@ -107,7 +107,7 @@ import adql.query.operand.function.geometry.GeometryFunction.GeometryValue;
 * @see ADQLParser
 *
 * @author Gr&eacute;gory Mantelet (CDS)
 * @version 2.0 (09/2019)
 * @version 2.0 (11/2019)
 * @since 2.0
 */
public class ADQLGrammar201 extends ADQLGrammarBase {
@@ -232,16 +232,6 @@ TOKEN : {
|	< DIVIDE: "/" >
}

/* **************** */
/* Binary operators */
/* **************** */
TOKEN : {
	< BIT_AND: "&" >
|	< BIT_OR: "|" >
|	< BIT_XOR: "^" >
|	< BIT_NOT: "~" >
}

/* ******************** */
/* Comparison operators */
/* ******************** */
@@ -414,7 +404,6 @@ TOKEN : {
	< SCIENTIFIC_NUMBER: (<UNSIGNED_FLOAT>|<UNSIGNED_INTEGER>) "E" (<PLUS>|<MINUS>)? <UNSIGNED_INTEGER> >
|	< UNSIGNED_FLOAT: (<UNSIGNED_INTEGER> <DOT> (<UNSIGNED_INTEGER>)?) | (<DOT> <UNSIGNED_INTEGER>) >
|	< UNSIGNED_INTEGER: (<DIGIT>)+ >
|	< UNSIGNED_HEXADECIMAL: ("0""x" (<DIGIT> | ["a"-"f","A"-"F"])+) >
|	< #DIGIT: ["0"-"9"] >
}

@@ -847,8 +836,7 @@ StringConstant String(): {Token t, start=null; String str=""; StringConstant cst
NumericConstant UnsignedNumeric(): {Token t; NumericConstant cst;} {
	(t=<SCIENTIFIC_NUMBER>
	| t=<UNSIGNED_FLOAT>
	| t=<UNSIGNED_INTEGER>
	| t=<UNSIGNED_HEXADECIMAL>)
	| t=<UNSIGNED_INTEGER>)
	{
		try{
		  	cst = queryFactory.createNumericConstant(t.image);
@@ -862,7 +850,6 @@ NumericConstant UnsignedNumeric(): {Token t; NumericConstant cst;} {

NumericConstant UnsignedFloat(): {Token t; NumericConstant cst;} {
	(t=<UNSIGNED_INTEGER>
	| t=<UNSIGNED_HEXADECIMAL>
	| t=<UNSIGNED_FLOAT>)
	{
		try{
@@ -928,7 +915,7 @@ ADQLOperand StringValueExpressionPrimary(): {StringConstant expr; ADQLColumn col

ADQLOperand ValueExpression(): {ADQLOperand valueExpr = null; Token left, right; } {
	try{
		(LOOKAHEAD((<PLUS>|<MINUS>|<BIT_NOT>) | (Factor() (<PLUS>|<MINUS>|<ASTERISK>|<DIVIDE>|<BIT_AND>|<BIT_OR>|<BIT_XOR>))) valueExpr=NumericExpression()
		(LOOKAHEAD((<PLUS>|<MINUS>) | (Factor() (<PLUS>|<MINUS>|<ASTERISK>|<DIVIDE>))) valueExpr=NumericExpression()
		| LOOKAHEAD(<COORDSYS> | <LOWER> | (StringFactor() <CONCAT>)) valueExpr=StringExpression()
		| LOOKAHEAD(<LEFT_PAR>) left=<LEFT_PAR> valueExpr=ValueExpression() right=<RIGHT_PAR> { valueExpr = queryFactory.createWrappedOperand(valueExpr); ((WrappedOperand)valueExpr).setPosition(new TextPosition(left, right)); }
		| LOOKAHEAD(<REGULAR_IDENTIFIER_CANDIDATE> <LEFT_PAR>) valueExpr=UserDefinedFunction()
@@ -955,25 +942,8 @@ ADQLOperand ValueExpression(): {ADQLOperand valueExpr = null; Token left, right;
	}
}

ADQLOperand NumericExpression(): { Token operator = null; ADQLOperand leftOp, rightOp = null; } {
	(leftOp=NumericTerm() ((operator=<BIT_AND> | operator=<BIT_OR> | operator=<BIT_XOR>) rightOp=NumericExpression())?)
	{
		if (operator == null)
			return leftOp;
		else{
			try{
				Operation operation = queryFactory.createOperation(leftOp, OperationType.getOperator(operator.image), rightOp);
				operation.setPosition(new TextPosition(leftOp.getPosition(), rightOp.getPosition()));
				return operation;
			}catch(Exception ex){
				throw generateParseException(ex);
			}
		}
	}
}

ADQLOperand NumericTerm(): {Token sign=null; ADQLOperand leftOp, rightOp=null;} {
	(leftOp=Term() ((sign=<PLUS> | sign=<MINUS>) rightOp=NumericTerm())?)
ADQLOperand NumericExpression(): {Token sign=null; ADQLOperand leftOp, rightOp=null;} {
	(leftOp=NumericTerm() ((sign=<PLUS> | sign=<MINUS>) rightOp=NumericExpression())?)
	{
	if (sign == null)
		return leftOp;
@@ -989,8 +959,8 @@ ADQLOperand NumericTerm(): {Token sign=null; ADQLOperand leftOp, rightOp=null;}
	}
}

ADQLOperand Term(): {Token sign=null; ADQLOperand leftOp, rightOp=null;} {
	(leftOp=Factor() ((sign=<ASTERISK> | sign=<DIVIDE>) rightOp=Term())?)
ADQLOperand NumericTerm(): {Token sign=null; ADQLOperand leftOp, rightOp=null;} {
	(leftOp=Factor() ((sign=<ASTERISK> | sign=<DIVIDE>) rightOp=NumericTerm())?)
	{
	if (sign == null)
		return leftOp;
@@ -1008,16 +978,12 @@ ADQLOperand Term(): {Token sign=null; ADQLOperand leftOp, rightOp=null;} {

ADQLOperand Factor(): {Token minusSign = null, bitNot = null; ADQLOperand op;} {
	(
		(<PLUS> | minusSign=<MINUS> | bitNot=<BIT_NOT>)?
		(<PLUS> | minusSign=<MINUS>)?
		(LOOKAHEAD(2) op=NumericFunction() | op=NumericValueExpressionPrimary())
	)
	{
		try {
			if (bitNot != null) {
				BitNotOperand bitNotOperand = queryFactory.createBitNotOperand(op);
				bitNotOperand.setPosition(new TextPosition(new TextPosition(bitNot), op.getPosition()));
				return bitNotOperand;
			} else if (minusSign != null) {
			if (minusSign != null) {
				NegativeOperand negativeOp = queryFactory.createNegativeOperand(op);
				negativeOp.setPosition(new TextPosition(new TextPosition(minusSign), op.getPosition()));
				return negativeOp;
+0 −187
Original line number Diff line number Diff line
package adql.query.operand;

/*
 * This file is part of ADQLLibrary.
 *
 * ADQLLibrary is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * ADQLLibrary is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with ADQLLibrary.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Copyright 2019 - UDS/Centre de Données astronomiques de Strasbourg (CDS)
 */

import java.util.NoSuchElementException;

import adql.parser.feature.LanguageFeature;
import adql.query.ADQLIterator;
import adql.query.ADQLObject;
import adql.query.TextPosition;

/**
 * Operand that represents the binary complement (bitwise NOT) of a given
 * numeric operand.
 *
 * @author Gr&eacute;gory Mantelet (CDS;ARI)
 * @version 2.0 (08/2019)
 * @since 2.0
 */
public final class BitNotOperand implements ADQLOperand {

	/** Description of this ADQL Feature. */
	public static final LanguageFeature FEATURE = new LanguageFeature(LanguageFeature.TYPE_ADQL_BITWISE, "BIT_NOT", true);

	/** The operand whose bits must be reversed. */
	private ADQLOperand operand;

	/** Position of this operand. */
	private TextPosition position = null;

	/**
	 * Builds an operand which computes the binary complement of the given
	 * operand.
	 *
	 * <p><i><b>Important:</b>
	 * 	The given operand must be numeric ({@link ADQLOperand#isNumeric()} must
	 * 	return <code>true</code>)!
	 * </b></p>
	 *
	 * @param operand	The operand whose binary complement must be computed.
	 *
	 * @throws NullPointerException				If the given operand is NULL.
	 * @throws UnsupportedOperationException	If the given operand is not
	 *                                          numeric (if {@link ADQLOperand#isNumeric()}
	 *                                          does not return
	 *                                          <code>true</code>).
	 */
	public BitNotOperand(ADQLOperand operand) throws NullPointerException, UnsupportedOperationException {
		if (operand == null)
			throw new NullPointerException("Impossible to apply a bitwise NOT on NULL!");

		if (operand.isNumeric())
			this.operand = operand;
		else
			throw new UnsupportedOperationException("Impossible to apply a bitwise NOT on a non-numeric operand (" + operand.toADQL() + ")!");
	}

	@Override
	public final LanguageFeature getFeatureDescription() {
		return FEATURE;
	}

	/**
	 * Gets the operand whose binary complement must be computed.
	 *
	 * @return	The operand to binary-complement.
	 */
	public final ADQLOperand getOperand() {
		return operand;
	}

	/** Always returns <code>true</code>.
	 * @see adql.query.operand.ADQLOperand#isNumeric()
	 */
	@Override
	public final boolean isNumeric() {
		return true;
	}

	/** Always returns <code>false</code>.
	 * @see adql.query.operand.ADQLOperand#isString()
	 */
	@Override
	public final boolean isString() {
		return false;
	}

	@Override
	public final TextPosition getPosition() {
		return this.position;
	}

	/**
	 * Sets the position at which this {@link BitNotOperand} has been found in
	 * the original ADQL query string.
	 *
	 * @param position	Position of this {@link BitNotOperand}.
	 * @since 1.4
	 */
	public final void setPosition(final TextPosition position) {
		this.position = position;
	}

	/** Always returns <code>false</code>.
	 * @see adql.query.operand.ADQLOperand#isGeometry()
	 */
	@Override
	public final boolean isGeometry() {
		return false;
	}

	@Override
	public ADQLObject getCopy() throws Exception {
		BitNotOperand copy = new BitNotOperand((ADQLOperand)operand.getCopy());
		return copy;
	}

	@Override
	public String getName() {
		return "BIT_NOT_" + operand.getName();
	}

	@Override
	public ADQLIterator adqlIterator() {
		return new ADQLIterator() {

			private boolean operandGot = (operand == null);

			@Override
			public ADQLObject next() {
				if (operandGot)
					throw new NoSuchElementException();
				operandGot = true;
				return operand;
			}

			@Override
			public boolean hasNext() {
				return !operandGot;
			}

			@Override
			public void replace(ADQLObject replacer) throws UnsupportedOperationException, IllegalStateException {
				if (!operandGot)
					throw new IllegalStateException("replace(ADQLObject) impossible: next() has not yet been called!");

				if (replacer == null)
					remove();
				else if (replacer instanceof ADQLOperand && ((ADQLOperand)replacer).isNumeric())
					operand = (ADQLOperand)replacer;
				else
					throw new UnsupportedOperationException("Impossible to replace the operand \"" + operand.toADQL() + "\" by \"" + replacer.toADQL() + "\" in the BitNotOperand \"" + toADQL() + "\" because the replacer is not an ADQLOperand or is not numeric!");
			}

			@Override
			public void remove() {
				if (!operandGot)
					throw new IllegalStateException("remove() impossible: next() has not yet been called!");
				else
					throw new UnsupportedOperationException("Impossible to remove the only operand (" + operand.toADQL() + ") of a BitNotOperand (" + toADQL() + "). However you can remove the whole BitNotOperand.");
			}
		};
	}

	@Override
	public String toADQL() {
		return "~" + operand.toADQL();
	}

}
Loading