Skip to content

Commit

Permalink
Support for Array Contains (&>) and ContainedBy (<&) operator added
Browse files Browse the repository at this point in the history
  • Loading branch information
MathewJoseph31 authored and manticore-projects committed Sep 12, 2023
1 parent 6955c43 commit 727c732
Show file tree
Hide file tree
Showing 8 changed files with 147 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
import net.sf.jsqlparser.expression.operators.relational.DoubleAnd;//Added by mathew on 21st Nov 2016
import net.sf.jsqlparser.expression.operators.relational.Contains;//Added by mathew on 21st Nov 2016
import net.sf.jsqlparser.expression.operators.relational.ContainedBy;//Added by mathew on 21st Nov 2016
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.expression.operators.relational.SimilarToExpression;
import net.sf.jsqlparser.schema.Column;
Expand Down Expand Up @@ -127,6 +129,10 @@ public interface ExpressionVisitor {
void visit(NotEqualsTo notEqualsTo);

void visit(DoubleAnd doubleAnd);//Added by mathew on 21st Nov 2016

void visit(Contains contains);//Added by mathew on 21st Nov 2016

void visit(ContainedBy containedBy);//Added by mathew on 21st Nov 2016

void visit(ParenthesedSelect selectBody);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,19 @@ public void visit(NotEqualsTo expr) {
public void visit(DoubleAnd expr) {
visitBinaryExpression(expr);
}

/*Added by mathew on 21st Nov 2016*/
@Override
public void visit(Contains expr) {
visitBinaryExpression(expr);
}

/*Added by mathew on 21st Nov 2016*/
@Override
public void visit(ContainedBy expr) {
visitBinaryExpression(expr);
}


@Override
public void visit(Column column) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2013 JSQLParser
* %%
* This program 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 2.1 of the
* License, or (at your option) any later version.
*
* This program 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 General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
/*Added by Mathew on 21st Nov 2016*/
package net.sf.jsqlparser.expression.operators.relational;

import net.sf.jsqlparser.expression.ExpressionVisitor;

public class ContainedBy extends ComparisonOperator {

public ContainedBy() {
super("<&");
}

public ContainedBy(String operator) {
super(operator);
}

@Override
public void accept(ExpressionVisitor expressionVisitor) {
expressionVisitor.visit(this);
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* #%L
* JSQLParser library
* %%
* Copyright (C) 2004 - 2013 JSQLParser
* %%
* This program 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 2.1 of the
* License, or (at your option) any later version.
*
* This program 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 General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
* #L%
*/
/*Added by Mathew on 21st Nov 2016*/
package net.sf.jsqlparser.expression.operators.relational;

import net.sf.jsqlparser.expression.ExpressionVisitor;

public class Contains extends ComparisonOperator {

public Contains() {
super("&>");
}

public Contains(String operator) {
super(operator);
}

@Override
public void accept(ExpressionVisitor expressionVisitor) {
expressionVisitor.visit(this);
}
}

16 changes: 16 additions & 0 deletions src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,22 @@ public void visit(NotEqualsTo notEqualsTo) {
public void visit(DoubleAnd doubleAnd) {
visitBinaryExpression(doubleAnd);
}

/* Added by Mathew on 21st Nov 2016
*
*/
@Override
public void visit(Contains contains) {
visitBinaryExpression(contains);
}

/* Added by Mathew on 21st Nov 2016
*
*/
@Override
public void visit(ContainedBy containedBy) {
visitBinaryExpression(containedBy);
}

@Override
public void visit(NullValue nullValue) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,20 @@ public void visit(DoubleAnd doubleAnd) {
visitOldOracleJoinBinaryExpression(doubleAnd, " " + doubleAnd.getStringExpression() + " ");

}

/*Added by Mathew on November 21st 2016*/
@Override
public void visit(Contains contains) {
visitOldOracleJoinBinaryExpression(contains, " " + contains.getStringExpression() + " ");

}

/*Added by Mathew on November 21st 2016*/
@Override
public void visit(ContainedBy containedBy) {
visitOldOracleJoinBinaryExpression(containedBy, " " + containedBy.getStringExpression() + " ");

}

@Override
public void visit(NullValue nullValue) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,8 @@ TOKEN : /* Operators */
| <OP_CONCAT: "|" (<WHITESPACE>)* "|">
| <OP_NOTEQUALSSTANDARD: "<" (<WHITESPACE>)* ">">
| <OP_DOUBLEAND: "&&"> /*added by mathew on 21st Nov 2016*/
| <OP_CONTAINS: "&>"> /*added by mathew on 21st Nov 2016*/
| <OP_CONTAINEDBY: "<&"> /*added by mathew on 21st Nov 2016*/
}

TOKEN : /* Date/Time with time zones */
Expand Down Expand Up @@ -3389,6 +3391,8 @@ Expression RegularCondition() #RegularCondition:
| token=<OP_NOTEQUALSSTANDARD> { result = new NotEqualsTo(token.image); }
| token=<OP_NOTEQUALSBANG> { result = new NotEqualsTo(token.image); }
| token=<OP_DOUBLEAND> { result = new DoubleAnd(token.image); }
| token=<OP_CONTAINS> { result = new DoubleAnd(token.image); }
| token=<OP_CONTAINEDBY> { result = new DoubleAnd(token.image); }
| "@@" { result = new Matches(); }
| "~" { result = new RegExpMatchOperator(RegExpMatchOperatorType.MATCH_CASESENSITIVE); }
| <K_REGEXP> [ <K_BINARY> { binary=true; } ] { result = new RegExpMySQLOperator(binary?RegExpMatchOperatorType.MATCH_CASESENSITIVE:RegExpMatchOperatorType.MATCH_CASEINSENSITIVE); }
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/net/sf/jsqlparser/test/select/SelectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1852,6 +1852,16 @@ public void testNotEqualsTo() throws JSQLParserException {
public void testDoubleAnd() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT * FROM foo WHERE a && b");
}

/*Added by Mathew on 21st Nov 2016*/
public void testContains() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT * FROM foo WHERE a &> b");
}

/*Added by Mathew on 21st Nov 2016*/
public void testContainedBy() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT * FROM foo WHERE a <& b");
}

public void testJsonExpression() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed("SELECT data->'images'->'thumbnail'->'url' AS thumb FROM instagram");
Expand Down

0 comments on commit 727c732

Please sign in to comment.