Skip to content

Commit

Permalink
feat: old TSQL Joins *= and =*
Browse files Browse the repository at this point in the history
  • Loading branch information
manticore-projects committed Sep 14, 2023
2 parents e3afa5f + 786c8fc commit 0b50da4
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 10 deletions.
13 changes: 10 additions & 3 deletions src/main/java/net/sf/jsqlparser/expression/ExpressionVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import net.sf.jsqlparser.expression.operators.conditional.OrExpression;
import net.sf.jsqlparser.expression.operators.conditional.XorExpression;
import net.sf.jsqlparser.expression.operators.relational.Between;
import net.sf.jsqlparser.expression.operators.relational.ContainedBy;
import net.sf.jsqlparser.expression.operators.relational.Contains;
import net.sf.jsqlparser.expression.operators.relational.DoubleAnd;
import net.sf.jsqlparser.expression.operators.relational.EqualsTo;
import net.sf.jsqlparser.expression.operators.relational.ExistsExpression;
import net.sf.jsqlparser.expression.operators.relational.ExpressionList;
Expand All @@ -43,11 +46,10 @@
import net.sf.jsqlparser.expression.operators.relational.MinorThan;
import net.sf.jsqlparser.expression.operators.relational.MinorThanEquals;
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
import net.sf.jsqlparser.expression.operators.relational.DoubleAnd;
import net.sf.jsqlparser.expression.operators.relational.Contains;
import net.sf.jsqlparser.expression.operators.relational.ContainedBy;
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.expression.operators.relational.SimilarToExpression;
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.select.AllColumns;
import net.sf.jsqlparser.statement.select.AllTableColumns;
Expand Down Expand Up @@ -239,4 +241,9 @@ public interface ExpressionVisitor {
void visit(TrimFunction trimFunction);

void visit(RangeExpression rangeExpression);

void visit(TSQLLeftJoin tsqlLeftJoin);

void visit(TSQLRightJoin tsqlRightJoin);

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.expression.operators.relational.SimilarToExpression;
import net.sf.jsqlparser.expression.operators.relational.*;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.select.AllColumns;
import net.sf.jsqlparser.statement.select.AllTableColumns;
Expand Down Expand Up @@ -670,4 +671,15 @@ public void visit(RangeExpression rangeExpression) {
rangeExpression.getStartExpression().accept(this);
rangeExpression.getEndExpression().accept(this);
}

@Override
public void visit(TSQLLeftJoin tsqlLeftJoin) {
visitBinaryExpression(tsqlLeftJoin);
}

@Override
public void visit(TSQLRightJoin tsqlRightJoin) {
visitBinaryExpression(tsqlRightJoin);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* #%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%
*/
package net.sf.jsqlparser.expression.operators.relational;

import net.sf.jsqlparser.expression.ExpressionVisitor;

public class TSQLLeftJoin extends ComparisonOperator {

public TSQLLeftJoin() {
super("*=");
}

@Override
public void accept(ExpressionVisitor expressionVisitor) {
expressionVisitor.visit(this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* #%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%
*/
package net.sf.jsqlparser.expression.operators.relational;

import net.sf.jsqlparser.expression.ExpressionVisitor;

public class TSQLRightJoin extends ComparisonOperator {

public TSQLRightJoin() {
super("=*");
}

@Override
public void accept(ExpressionVisitor expressionVisitor) {
expressionVisitor.visit(this);
}
}
12 changes: 12 additions & 0 deletions src/main/java/net/sf/jsqlparser/util/TablesNamesFinder.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@
import net.sf.jsqlparser.expression.operators.relational.NotEqualsTo;
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.expression.operators.relational.SimilarToExpression;
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
import net.sf.jsqlparser.parser.CCJSqlParserUtil;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
Expand Down Expand Up @@ -1133,6 +1135,16 @@ public void visit(ShowTablesStatement showTables) {
"Finding tables from ShowTablesStatement is not supported");
}

@Override
public void visit(TSQLLeftJoin tsqlLeftJoin) {
visitBinaryExpression(tsqlLeftJoin);
}

@Override
public void visit(TSQLRightJoin tsqlRightJoin) {
visitBinaryExpression(tsqlRightJoin);
}

@Override
public void visit(VariableAssignment var) {
var.getVariable().accept(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.expression.operators.relational.SimilarToExpression;
import net.sf.jsqlparser.expression.operators.relational.SupportsOldOracleJoinSyntax;
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.schema.Table;
import net.sf.jsqlparser.statement.select.AllColumns;
Expand Down Expand Up @@ -1093,4 +1095,15 @@ public void visit(GeometryDistance geometryDistance) {
visitOldOracleJoinBinaryExpression(geometryDistance,
" " + geometryDistance.getStringExpression() + " ");
}

@Override
public void visit(TSQLLeftJoin tsqlLeftJoin) {
visitBinaryExpression(tsqlLeftJoin, " *= ");
}

@Override
public void visit(TSQLRightJoin tsqlRightJoin) {
visitBinaryExpression(tsqlRightJoin, " =* ");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@
import net.sf.jsqlparser.expression.operators.relational.RegExpMatchOperator;
import net.sf.jsqlparser.expression.operators.relational.SimilarToExpression;
import net.sf.jsqlparser.expression.operators.relational.SupportsOldOracleJoinSyntax;
import net.sf.jsqlparser.expression.operators.relational.TSQLLeftJoin;
import net.sf.jsqlparser.expression.operators.relational.TSQLRightJoin;
import net.sf.jsqlparser.parser.feature.Feature;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.select.AllColumns;
Expand Down Expand Up @@ -694,4 +696,16 @@ public void visit(RangeExpression rangeExpression) {
rangeExpression.getStartExpression().accept(this);
rangeExpression.getEndExpression().accept(this);
}

@Override
public void visit(TSQLLeftJoin tsqlLeftJoin) {
tsqlLeftJoin.getLeftExpression().accept(this);
tsqlLeftJoin.getRightExpression().accept(this);
}

@Override
public void visit(TSQLRightJoin tsqlRightJoin) {
tsqlRightJoin.getLeftExpression().accept(this);
tsqlRightJoin.getRightExpression().accept(this);
}
}
4 changes: 3 additions & 1 deletion src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -1752,7 +1752,7 @@ The following tokens are allowed as Names for Schema, Table, Column and Aliases
String RelObjectNameWithoutValue() :
{ Token tk = null; }
{
( tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER> | tk=<K_DATE_LITERAL> | tk=<K_DATETIMELITERAL> | tk=<K_STRING_FUNCTION_NAME> | tk=<K_ISOLATION> | tk=<K_TIME_KEY_EXPR>
( tk=<S_IDENTIFIER> | tk=<S_QUOTED_IDENTIFIER> | tk=<K_DATE_LITERAL> | tk=<K_DATETIMELITERAL> | tk=<K_STRING_FUNCTION_NAME> | tk=<K_ISOLATION> | tk=<K_TIME_KEY_EXPR>
| tk="ACTION" | tk="ACTIVE" | tk="ADD" | tk="ADVANCE" | tk="ADVISE" | tk="AGAINST" | tk="ALGORITHM" | tk="ALTER" | tk="ANALYZE" | tk="APPLY" | tk="ARCHIVE" | tk="ARRAY" | tk="ASC" | tk="AT" | tk="AUTHORIZATION" | tk="AUTO" | tk="BEGIN" | tk="BERNOULLI" | tk="BINARY" | tk="BIT" | tk="BLOCK" | tk="BROWSE" | tk="BUFFERS" | tk="BY" | tk="BYTE" | tk="BYTES" | tk="CACHE" | tk="CALL" | tk="CASCADE" | tk="CASE" | tk="CAST" | tk="CHANGE" | tk="CHANGES" | tk="CHAR" | tk="CHARACTER" | tk="CHECKPOINT" | tk="CLOSE" | tk="COLLATE" | tk="COLUMN" | tk="COLUMNS" | tk="COMMENT" | tk="COMMIT" | tk="CONFLICT" | tk="CONVERT" | tk="COSTS" | tk="CS" | tk="CYCLE" | tk="DATABASE" | tk="DDL" | tk="DECLARE" | tk="DEFAULT" | tk="DEFERRABLE" | tk="DELAYED" | tk="DELETE" | tk="DESC" | tk="DESCRIBE" | tk="DISABLE" | tk="DISCONNECT" | tk="DIV" | tk="DML" | tk="DO" | tk="DOMAIN" | tk="DROP" | tk="DUMP" | tk="DUPLICATE" | tk="ELEMENTS" | tk="EMIT" | tk="ENABLE" | tk="END" | tk="ESCAPE" | tk="EXCLUDE" | tk="EXEC" | tk="EXECUTE" | tk="EXPLAIN" | tk="EXPLICIT" | tk="EXTENDED" | tk="EXTRACT" | tk="FALSE" | tk="FILTER" | tk="FIRST" | tk="FLUSH" | tk="FN" | tk="FOLLOWING" | tk="FORMAT" | tk="FULLTEXT" | tk="FUNCTION" | tk="GLOBAL" | tk="GRANT" | tk="GUARD" | tk="HISTORY" | tk="HOPPING" | tk="INCLUDE" | tk="INCREMENT" | tk="INDEX" | tk="INSERT" | tk="INTERLEAVE" | tk="INTERPRET" | tk="ISNULL" | tk="JSON" | tk="KEEP" | tk="KEY" | tk="KEYS" | tk="LAST" | tk="LEADING" | tk="LINK" | tk="LOCAL" | tk="LOCKED" | tk="LOG" | tk="MATCH" | tk="MATCHED" | tk="MATERIALIZED" | tk="MAXVALUE" | tk="MEMBER" | tk="MERGE" | tk="MINVALUE" | tk="MODIFY" | tk="MOVEMENT" | tk="NEXT" | tk="NO" | tk="NOCACHE" | tk="NOKEEP" | tk="NOLOCK" | tk="NOMAXVALUE" | tk="NOMINVALUE" | tk="NOORDER" | tk="NOTHING" | tk="NOTNULL" | tk="NOVALIDATE" | tk="NOWAIT" | tk="NULLS" | tk="OF" | tk="OFF" | tk="OPEN" | tk="OVER" | tk="OVERLAPS" | tk="PARALLEL" | tk="PARENT" | tk="PARTITION" | tk="PATH" | tk="PERCENT" | tk="PLACING" | tk="PRECEDING" | tk="PRECISION" | tk="PRIMARY" | tk="PRIOR" | tk="PURGE" | tk="QUERY" | tk="QUICK" | tk="QUIESCE" | tk="RANGE" | tk="RAW" | tk="READ" | tk="RECYCLEBIN" | tk="REFERENCES" | tk="REFRESH" | tk="REGISTER" | tk="RENAME" | tk="REPEATABLE" | tk="REPLACE" | tk="RESET" | tk="RESTART" | tk="RESTRICT" | tk="RESTRICTED" | tk="RESUMABLE" | tk="RESUME" | tk="RLIKE" | tk="ROLLBACK" | tk="ROOT" | tk="ROW" | tk="ROWS" | tk="RR" | tk="RS" | tk="SAVEPOINT" | tk="SCHEMA" | tk="SEED" | tk="SEPARATOR" | tk="SEQUENCE" | tk="SESSION" | tk="SETS" | tk="SHOW" | tk="SHUTDOWN" | tk="SIBLINGS" | tk="SIGNED" | tk="SIMILAR" | tk="SIZE" | tk="SKIP" | tk="STORED" | tk="STRING" | tk="SUSPEND" | tk="SWITCH" | tk="SYNONYM" | tk="SYSTEM" | tk="TABLE" | tk="TABLESPACE" | tk="TEMP" | tk="TEMPORARY" | tk="THEN" | tk="TIMEOUT" | tk="TIMESTAMPTZ" | tk="TO" | tk="TRIGGER" | tk="TRUE" | tk="TRUNCATE" | tk="TUMBLING" | tk="TYPE" | tk="UNLOGGED" | tk="UNQIESCE" | tk="UNSIGNED" | tk="UPDATE" | tk="UPSERT" | tk="UR" | tk="USER" | tk="VALIDATE" | tk="VERBOSE" | tk="VIEW" | tk="WAIT" | tk="WITHIN" | tk="WITHOUT" | tk="WORK" | tk="XML" | tk="XMLAGG" | tk="XMLDATA" | tk="XMLSCHEMA" | tk="XMLTEXT" | tk="XSINIL" | tk="YAML" | tk="YES" | tk="ZONE" )
{ return tk.image; }
}
Expand Down Expand Up @@ -3406,6 +3406,8 @@ Expression RegularCondition() #RegularCondition:
| token=<OP_MINORTHANEQUALS> { result = new MinorThanEquals(token.image); }
| token=<OP_NOTEQUALSSTANDARD> { result = new NotEqualsTo(token.image); }
| token=<OP_NOTEQUALSBANG> { result = new NotEqualsTo(token.image); }
| "*=" { result = new TSQLLeftJoin(); }
| "=*" { result = new TSQLRightJoin(); }
| token=<OP_DOUBLEAND> { result = new DoubleAnd(); }
| token=<OP_CONTAINS> { result = new Contains(); }
| token=<OP_CONTAINEDBY> { result = new ContainedBy(); }
Expand Down
18 changes: 12 additions & 6 deletions src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2252,6 +2252,18 @@ public void testIsNotFalse() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(statement);
}

@Test
public void testTSQLJoin() throws JSQLParserException {
String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a *= tabelle2.b";
assertSqlCanBeParsedAndDeparsed(stmt);
}

@Test
public void testTSQLJoin2() throws JSQLParserException {
String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a =* tabelle2.b";
assertSqlCanBeParsedAndDeparsed(stmt);
}

@Test
public void testOracleJoin() throws JSQLParserException {
String stmt = "SELECT * FROM tabelle1, tabelle2 WHERE tabelle1.a = tabelle2.b(+)";
Expand Down Expand Up @@ -2418,12 +2430,6 @@ public void testExtractFrom4() throws JSQLParserException {
assertSqlCanBeParsedAndDeparsed(stmt);
}

// @Test
// public void testExtractFromIssue673() throws JSQLParserException {
// String stmt = "select EXTRACT(DAY FROM (SYSDATE - to_date('20180101', 'YYYYMMDD' ) ) DAY TO
// SECOND) from dual";
// assertSqlCanBeParsedAndDeparsed(stmt);
// }
@Test
public void testProblemFunction() throws JSQLParserException {
String stmt = "SELECT test() FROM testtable";
Expand Down

0 comments on commit 0b50da4

Please sign in to comment.