diff --git a/src/adql/parser/ADQLQueryFactory.java b/src/adql/parser/ADQLQueryFactory.java index 4305fdee0f9c178e52b9644962b0e9f838b48730..42c55029fe8083b1815e5d7a9dfed2cec2fdeb73 100644 --- a/src/adql/parser/ADQLQueryFactory.java +++ b/src/adql/parser/ADQLQueryFactory.java @@ -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é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(); } diff --git a/src/adql/parser/feature/FeatureSet.java b/src/adql/parser/feature/FeatureSet.java index da3073f0393036e003ee849a954a827b732453b5..75d7002e9977d2499c14f61e13d1165205a72279 100644 --- a/src/adql/parser/feature/FeatureSet.java +++ b/src/adql/parser/feature/FeatureSet.java @@ -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é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. diff --git a/src/adql/parser/feature/default_features.md b/src/adql/parser/feature/default_features.md index 80f7b4a6434df30dc7e0f94fd4aa961b00cf4dbc..e3a7eca3427accd9612010d51f1a5169bbb2ac29 100644 --- a/src/adql/parser/feature/default_features.md +++ b/src/adql/parser/feature/default_features.md @@ -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 | diff --git a/src/adql/parser/grammar/adqlGrammar201.jj b/src/adql/parser/grammar/adqlGrammar201.jj index ffceab0ffe6ad8cc35080dd7b12243db7c23cf95..65c07fe376c7b1510998ee5d1785f62765813c22 100644 --- a/src/adql/parser/grammar/adqlGrammar201.jj +++ b/src/adql/parser/grammar/adqlGrammar201.jj @@ -31,7 +31,7 @@ * ParseException is thrown. * * Author: Gré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é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; diff --git a/src/adql/query/operand/BitNotOperand.java b/src/adql/query/operand/BitNotOperand.java deleted file mode 100644 index cf9c78da65a793ad39bc80f7e2f2df70833dcc79..0000000000000000000000000000000000000000 --- a/src/adql/query/operand/BitNotOperand.java +++ /dev/null @@ -1,187 +0,0 @@ -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é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(); - } - -} diff --git a/src/adql/query/operand/OperationType.java b/src/adql/query/operand/OperationType.java index 1543a69aceb1692c3727b55fd2dc5a961bb10e5f..935060fdff793571a9bc60b48a9652cc85c065f6 100644 --- a/src/adql/query/operand/OperationType.java +++ b/src/adql/query/operand/OperationType.java @@ -26,7 +26,7 @@ import adql.query.operand.function.SQLFunction; * Type of possible simple numeric operations. * * @author Grégory Mantelet (CDS) - * @version 2.0 (08/2019) + * @version 2.0 (11/2019) * * @see Operation */ @@ -34,13 +34,7 @@ public enum OperationType { SUM, SUB, MULT, - DIV, - /** @since 2.0 */ - BIT_AND, - /** @since 2.0 */ - BIT_OR, - /** @since 2.0 */ - BIT_XOR; + DIV; /** Description of the ADQL Feature based on this type. * @since 2.0 */ @@ -48,10 +42,7 @@ public enum OperationType { /** @since 2.0 */ private OperationType() { - if (this.name().startsWith("BIT_")) - FEATURE = new LanguageFeature(LanguageFeature.TYPE_ADQL_BITWISE, this.name(), true); - else - FEATURE = new LanguageFeature(null, this.name(), false); + FEATURE = new LanguageFeature(null, this.name(), false); } /** @@ -73,7 +64,7 @@ public enum OperationType { } public static String[] getOperators() { - return new String[]{ SUM.toString(), SUB.toString(), MULT.toString(), DIV.toString(), BIT_AND.toString(), BIT_OR.toString(), BIT_XOR.toString() }; + return new String[]{ SUM.toString(), SUB.toString(), MULT.toString(), DIV.toString() }; } public static OperationType getOperator(String str) throws UnsupportedOperationException { @@ -85,12 +76,6 @@ public enum OperationType { return MULT; else if (str.equalsIgnoreCase("/")) return DIV; - else if (str.equalsIgnoreCase("&")) - return BIT_AND; - else if (str.equalsIgnoreCase("|")) - return BIT_OR; - else if (str.equalsIgnoreCase("^")) - return BIT_XOR; else throw new UnsupportedOperationException("Numeric operation unknown: \"" + str + "\" !"); } @@ -110,12 +95,6 @@ public enum OperationType { return "*"; case DIV: return "/"; - case BIT_AND: - return "&"; - case BIT_OR: - return "|"; - case BIT_XOR: - return "^"; default: return "???"; } diff --git a/src/adql/translator/ADQLTranslator.java b/src/adql/translator/ADQLTranslator.java index d915931f69d59f50ebe0e3b5a3a5f3aa17b873f1..3814698cc566fada71f67d2f6f13d3141370c01d 100644 --- a/src/adql/translator/ADQLTranslator.java +++ b/src/adql/translator/ADQLTranslator.java @@ -1,7 +1,5 @@ package adql.translator; -import adql.parser.feature.FeatureSet; - /* * This file is part of ADQLLibrary. * @@ -22,6 +20,7 @@ import adql.parser.feature.FeatureSet; * Astronomisches Rechen Institut (ARI) */ +import adql.parser.feature.FeatureSet; import adql.query.ADQLList; import adql.query.ADQLObject; import adql.query.ADQLOrder; @@ -45,7 +44,6 @@ import adql.query.from.ADQLTable; import adql.query.from.FromContent; 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; @@ -77,7 +75,7 @@ import adql.query.operand.function.string.LowerFunction; * Translates ADQL objects into any language (i.e. SQL). * * @author Grégory Mantelet (CDS) - * @version 2.0 (08/2019) + * @version 2.0 (11/2019) * * @see PostgreSQLTranslator */ @@ -140,9 +138,6 @@ public interface ADQLTranslator { public String translate(NegativeOperand negOp) throws TranslationException; - /** @since 2.0 */ - public String translate(BitNotOperand bitNotOp) throws TranslationException; - public String translate(NumericConstant numConst) throws TranslationException; public String translate(StringConstant strConst) throws TranslationException; diff --git a/src/adql/translator/JDBCTranslator.java b/src/adql/translator/JDBCTranslator.java index f2da12c19cde507a298df47c0bea2496e5bf0b80..5c1dbf3c473b589dcd3ff90f9dce68790c2d71ff 100644 --- a/src/adql/translator/JDBCTranslator.java +++ b/src/adql/translator/JDBCTranslator.java @@ -56,7 +56,6 @@ import adql.query.from.ADQLTable; import adql.query.from.FromContent; 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; @@ -169,7 +168,7 @@ import adql.query.operand.function.string.LowerFunction; * </p> * * @author Grégory Mantelet (ARI;CDS) - * @version 2.0 (08/2019) + * @version 2.0 (11/2019) * @since 1.4 * * @see PostgreSQLTranslator @@ -707,8 +706,6 @@ public abstract class JDBCTranslator implements ADQLTranslator { return translate((Concatenation)op); else if (op instanceof NegativeOperand) return translate((NegativeOperand)op); - else if (op instanceof BitNotOperand) - return translate((BitNotOperand)op); else if (op instanceof NumericConstant) return translate((NumericConstant)op); else if (op instanceof StringConstant) @@ -757,11 +754,6 @@ public abstract class JDBCTranslator implements ADQLTranslator { return "-" + translate(negOp.getOperand()); } - @Override - public String translate(BitNotOperand bitNotOp) throws TranslationException { - return "(~" + translate(bitNotOp.getOperand()) + ")"; - } - @Override public String translate(NumericConstant numConst) throws TranslationException { if (numConst.isHexadecimal()) { diff --git a/src/adql/translator/MySQLTranslator.java b/src/adql/translator/MySQLTranslator.java index ba81c6ad37fe393b79c6aba8e931d359c73f0a67..01304f9572b37ddff33471551c49a912d81334b1 100644 --- a/src/adql/translator/MySQLTranslator.java +++ b/src/adql/translator/MySQLTranslator.java @@ -31,7 +31,6 @@ import adql.query.constraint.Comparison; import adql.query.constraint.ComparisonOperator; import adql.query.operand.ADQLOperand; import adql.query.operand.Concatenation; -import adql.query.operand.Operation; import adql.query.operand.function.InUnitFunction; import adql.query.operand.function.MathFunction; import adql.query.operand.function.geometry.AreaFunction; @@ -65,7 +64,7 @@ import adql.query.operand.function.geometry.RegionFunction; * </i></p> * * @author Grégory Mantelet (ARI;CDS) - * @version 2.0 (08/2019) + * @version 2.0 (11/2019) * @since 1.4 */ public class MySQLTranslator extends JDBCTranslator { @@ -194,18 +193,6 @@ public class MySQLTranslator extends JDBCTranslator { /* * * */ /* ********************************************************************** */ - @Override - public String translate(Operation op) throws TranslationException { - switch(op.getOperation()) { - case BIT_AND: - case BIT_OR: - case BIT_XOR: - return "CAST(" + translate(op.getLeftOperand()) + op.getOperation().toADQL() + translate(op.getRightOperand()) + " AS SIGNED)"; - default: - return super.translate(op); - } - } - @Override public String translate(MathFunction fct) throws TranslationException { switch(fct.getType()) { diff --git a/src/adql/translator/PostgreSQLTranslator.java b/src/adql/translator/PostgreSQLTranslator.java index fc34b036f4a92e5629977fa7d8abf043fad20dec..fb19a63aea05f98779229aa62840b910f838a3cc 100644 --- a/src/adql/translator/PostgreSQLTranslator.java +++ b/src/adql/translator/PostgreSQLTranslator.java @@ -27,8 +27,6 @@ import adql.parser.feature.FeatureSet; import adql.parser.feature.LanguageFeature; import adql.parser.grammar.ParseException; import adql.query.IdentifierField; -import adql.query.operand.Operation; -import adql.query.operand.OperationType; import adql.query.operand.StringConstant; import adql.query.operand.function.ADQLFunction; import adql.query.operand.function.InUnitFunction; @@ -76,7 +74,7 @@ import adql.query.operand.function.geometry.RegionFunction; * </i></p> * * @author Grégory Mantelet (CDS;ARI) - * @version 2.0 (08/2019) + * @version 2.0 (11/2019) * * @see PgSphereTranslator */ @@ -184,14 +182,6 @@ public class PostgreSQLTranslator extends JDBCTranslator { return super.translate(strConst); } - @Override - public String translate(Operation op) throws TranslationException { - if (op.getOperation() == OperationType.BIT_XOR) - return "(" + translate(op.getLeftOperand()) + " # " + translate(op.getRightOperand()) + ")"; - else - return super.translate(op); - } - @Override public String translate(MathFunction fct) throws TranslationException { switch(fct.getType()) { diff --git a/test/adql/parser/TestADQLParser.java b/test/adql/parser/TestADQLParser.java index c7c2002feca498e4f504069c64fd7b64ce0a856c..68ead6866e1f5f787b4fa806f802b3ecbd80bbe3 100644 --- a/test/adql/parser/TestADQLParser.java +++ b/test/adql/parser/TestADQLParser.java @@ -29,10 +29,6 @@ import adql.query.ADQLQuery; import adql.query.WithItem; import adql.query.from.ADQLJoin; import adql.query.from.ADQLTable; -import adql.query.operand.ADQLOperand; -import adql.query.operand.BitNotOperand; -import adql.query.operand.Operation; -import adql.query.operand.OperationType; import adql.query.operand.StringConstant; import adql.query.operand.function.geometry.CircleFunction; import adql.query.operand.function.geometry.ContainsFunction; @@ -191,113 +187,6 @@ public class TestADQLParser { } } - @Test - public void testOperatorsPrecedence() { - - ADQLParser parser = new ADQLParser(ADQLVersion.V2_1); - - // CASE: Check the generated tree (i.e. precedence of operators): - try { - ADQLQuery query = parser.parseQuery("SELECT ~3-1|2*5^6/1+2 FROM foo"); - assertEquals("SELECT ~3-1|2*5^6/1+2\nFROM foo", query.toADQL()); - // top operand = OR( ~3-1 , 2*5^6/1+2 ) - ADQLOperand topOp = query.getSelect().get(0).getOperand(); - assertEquals(Operation.class, topOp.getClass()); - assertEquals(OperationType.BIT_OR, ((Operation)topOp).getOperation()); - assertEquals("~3-1", ((Operation)topOp).getLeftOperand().toADQL()); - assertEquals("2*5^6/1+2", ((Operation)topOp).getRightOperand().toADQL()); - // left operand = SUB( ~3 , 1 ) - ADQLOperand op = ((Operation)topOp).getLeftOperand(); - assertEquals(Operation.class, op.getClass()); - assertEquals(OperationType.SUB, ((Operation)op).getOperation()); - assertEquals("~3", ((Operation)op).getLeftOperand().toADQL()); - assertEquals("1", ((Operation)op).getRightOperand().toADQL()); - // left operand = BIT_NOT( 3 ) - op = ((Operation)op).getLeftOperand(); - assertEquals(BitNotOperand.class, op.getClass()); - assertEquals("3", ((BitNotOperand)op).getOperand().toADQL()); - // right operand = BIT_XOR( 2*5 , 6/1+2 ) - topOp = ((Operation)topOp).getRightOperand(); - assertEquals(Operation.class, topOp.getClass()); - assertEquals(OperationType.BIT_XOR, ((Operation)topOp).getOperation()); - assertEquals("2*5", ((Operation)topOp).getLeftOperand().toADQL()); - assertEquals("6/1+2", ((Operation)topOp).getRightOperand().toADQL()); - // left operand = MULT( 2 , 5 ) - op = ((Operation)topOp).getLeftOperand(); - assertEquals(Operation.class, op.getClass()); - assertEquals(OperationType.MULT, ((Operation)op).getOperation()); - assertEquals("2", ((Operation)op).getLeftOperand().toADQL()); - assertEquals("5", ((Operation)op).getRightOperand().toADQL()); - // right operand = SUM( 6/1 , 2 ) - op = ((Operation)topOp).getRightOperand(); - assertEquals(Operation.class, op.getClass()); - assertEquals(OperationType.SUM, ((Operation)op).getOperation()); - assertEquals("6/1", ((Operation)op).getLeftOperand().toADQL()); - assertEquals("2", ((Operation)op).getRightOperand().toADQL()); - // left operand = DIV( 6 , 1 ) - op = ((Operation)op).getLeftOperand(); - assertEquals(Operation.class, op.getClass()); - assertEquals(OperationType.DIV, ((Operation)op).getOperation()); - assertEquals("6", ((Operation)op).getLeftOperand().toADQL()); - assertEquals("1", ((Operation)op).getRightOperand().toADQL()); - - } catch(Exception ex) { - ex.printStackTrace(); - fail("Unexpected error with valid operations! (see console for more details)"); - } - } - - @Test - public void testBitwiseOperation() { - - // CASE: No bitwise operation in ADQL-2.0 - ADQLParser parser = new ADQLParser(ADQLVersion.V2_0); - try { - parser.parseQuery("SELECT 3|2 FROM foo"); - fail("Bitwise operations should not be allowed with ADQL-2.0!"); - } catch(Exception ex) { - assertEquals(ParseException.class, ex.getClass()); - assertEquals(" Encountered \"|\". Was expecting one of: \",\" \"FROM\" \"AS\" \"\\\"\" <REGULAR_IDENTIFIER_CANDIDATE> " + System.getProperty("line.separator", "\n") + "(HINT: \"|\" bitwise operations are not supported in ADQL-2.0. You should migrate your ADQL parser to support at least ADQL-2.1.)", ex.getMessage()); - } - - // CASE: Bitwise operations allowed in ADQL-2.1 - parser = new ADQLParser(ADQLVersion.V2_1); - try { - assertEquals("SELECT 3|2\nFROM foo", parser.parseQuery("SELECT 3|2 FROM foo").toADQL()); - assertEquals("SELECT 0xF&5\nFROM foo", parser.parseQuery("SELECT 0xF &5 FROM foo").toADQL()); - assertEquals("SELECT 67^45\nFROM foo", parser.parseQuery("SELECT 67 ^ 45 FROM foo").toADQL()); - assertEquals("SELECT ~0x3 , ~0x4 , ~3\nFROM foo", parser.parseQuery("SELECT ~ 0x3, ~0x4, ~ 3 FROM foo").toADQL()); - } catch(Exception ex) { - ex.printStackTrace(); - fail("Unexpected error with valid bitwise operations! (see console for more details)"); - } - } - - @Test - public void testHexadecimal() { - - // CASE: No hexadecimal in ADQL-2.0 - ADQLParser parser = new ADQLParser(ADQLVersion.V2_0); - try { - parser.parseQuery("SELECT 0xF FROM foo"); - fail("Hexadecimal values should not be allowed with ADQL-2.0!"); - } catch(Exception ex) { - assertEquals(ParseException.class, ex.getClass()); - assertEquals("Invalid ADQL regular identifier: \"0xF\"!" + System.getProperty("line.separator", "\n") + "(HINT: hexadecimal values are not supported in ADQL-2.0. You should upgrade your ADQL parser to support at least ADQL-2.1.)", ex.getMessage()); - } - - // CASE: Hexadecimal allowed in ADQL-2.1 - parser = new ADQLParser(ADQLVersion.V2_1); - try { - assertEquals("SELECT 0xF\nFROM foo", parser.parseQuery("SELECT 0xF FROM foo").toADQL()); - assertEquals("SELECT 0xF*2\nFROM foo", parser.parseQuery("SELECT 0xF*2 FROM foo").toADQL()); - assertEquals("SELECT -0xF\nFROM foo", parser.parseQuery("SELECT -0xF FROM foo").toADQL()); - } catch(Exception ex) { - ex.printStackTrace(); - fail("Unexpected error with valid hexadecimal values! (see console for more details)"); - } - } - @Test public void testOffset() { diff --git a/test/adql/translator/TestJDBCTranslator.java b/test/adql/translator/TestJDBCTranslator.java index 2f8a5a010d92917b9bc5cfc8e0e5595d8aea12fa..83524a2ccee3916970d701927c214a4cf0b2070e 100644 --- a/test/adql/translator/TestJDBCTranslator.java +++ b/test/adql/translator/TestJDBCTranslator.java @@ -30,7 +30,6 @@ import adql.query.WithItem; import adql.query.operand.ADQLColumn; import adql.query.operand.ADQLOperand; import adql.query.operand.NumericConstant; -import adql.query.operand.Operation; import adql.query.operand.StringConstant; import adql.query.operand.function.DefaultUDF; import adql.query.operand.function.InUnitFunction; @@ -124,23 +123,6 @@ public class TestJDBCTranslator { return cnt; } - @Test - public void testTranslateComplexNumericOperation() { - JDBCTranslator tr = new AJDBCTranslator(); - ADQLParser parser = new ADQLParser(ADQLVersion.V2_1); - - // CASE: Check the applied operators precedence while translating: - try { - ADQLQuery query = parser.parseQuery("SELECT ~3-1|2*5^6/1+2 FROM foo"); - assertEquals("SELECT ~3-1|2*5^6/1+2\nFROM foo", query.toADQL()); - assertEquals(Operation.class, query.getSelect().get(0).getOperand().getClass()); - assertEquals("(((~3)-1)|((2*5)^((6/1)+2)))", tr.translate(query.getSelect().get(0).getOperand())); - } catch(Exception ex) { - ex.printStackTrace(); - fail("Unexpected error with valid operations! (see console for more details)"); - } - } - @Test public void testTranslateOffset() { JDBCTranslator tr = new AJDBCTranslator(); @@ -169,26 +151,6 @@ public class TestJDBCTranslator { } } - @Test - public void testTranslateHexadecimal() { - JDBCTranslator tr = new AJDBCTranslator(); - ADQLParser parser = new ADQLParser(ADQLVersion.V2_1); - - try { - - assertEquals("SELECT 15 AS \"0xF\"\nFROM foo", tr.translate(parser.parseQuery("Select 0xF From foo"))); - assertEquals("SELECT (15*2) AS \"MULT\"\nFROM foo", tr.translate(parser.parseQuery("Select 0xF*2 From foo"))); - assertEquals("SELECT -15 AS \"NEG_0xF\"\nFROM foo", tr.translate(parser.parseQuery("Select -0xF From foo"))); - - } catch(ParseException pe) { - pe.printStackTrace(System.err); - fail("Unexpected failed query parsing! (see console for more details)"); - } catch(Exception e) { - e.printStackTrace(System.err); - fail("There should have been no problem to translate a query with hexadecimal values into SQL."); - } - } - @Test public void testTranslateStringConstant() { JDBCTranslator tr = new AJDBCTranslator();