Skip to content

Commit 7f068f6

Browse files
fix: revert to Semantic LOOKAHEAD for SubSelect in PrimaryExpression
- fixes #2242 Signed-off-by: Andreas Reichel <[email protected]>
1 parent f6e6eaf commit 7f068f6

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,8 @@ check {
637637

638638
jmh {
639639
includes = ['.*JSQLParserBenchmark.*']
640-
warmupIterations = 3
640+
warmupIterations = 2
641641
fork = 3
642-
iterations = 10
642+
iterations = 5
643643
timeOnIteration = '1s'
644644
}

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5457,9 +5457,9 @@ Expression PrimaryExpression() #PrimaryExpression:
54575457

54585458
| "{ts" token=<S_CHAR_LITERAL> "}" { retval = new TimestampValue(token.image); }
54595459

5460-
| LOOKAHEAD( 17 , { getAsBoolean(Feature.allowUnparenthesizedSubSelects) && !interrupted } ) retval=Select()
5460+
| LOOKAHEAD( Select() , { getAsBoolean(Feature.allowUnparenthesizedSubSelects) && !interrupted } ) retval=Select()
54615461

5462-
| LOOKAHEAD( 17 , { !getAsBoolean(Feature.allowUnparenthesizedSubSelects) && !interrupted } ) retval=ParenthesedSelect()
5462+
| LOOKAHEAD( ParenthesedSelect() , { !getAsBoolean(Feature.allowUnparenthesizedSubSelects) && !interrupted } ) retval=ParenthesedSelect()
54635463

54645464
|
54655465
(

src/test/java/net/sf/jsqlparser/benchmark/JSQLParserBenchmark.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class JSQLParserBenchmark {
3434
SqlParserRunner runner;
3535

3636
// @Param({ "latest", "5.2", "5.1", "5.0", "4.9", "4.8", "4.7", "4.6", "4.5" })
37-
@Param({"latest", "5.2", "5.1"})
37+
@Param({"latest", "5.3", "5.1"})
3838
public String version;
3939

4040
@Setup(Level.Trial)
@@ -83,7 +83,7 @@ public void parseSQLStatements(Blackhole blackhole) throws Exception {
8383
blackhole.consume(statements);
8484
}
8585

86-
@Benchmark
86+
// @Benchmark
8787
public void parseQuotedText(Blackhole blackhole) throws Exception {
8888
String sqlStr = "SELECT ('\\'', 'a');\n"
8989
+ "INSERT INTO recycle_record (a,f) VALUES ('\\'anything', 'abc');\n"

src/test/java/net/sf/jsqlparser/statement/select/SelectTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6214,4 +6214,15 @@ public void testSelectAllColumnsFromFunctionReturnWithMultipleParentheses()
62146214
plainSelect.getSelectItems().get(0).toString());
62156215
}
62166216

6217+
@Test
6218+
void testIssue2242SubSelectLookAhead() throws JSQLParserException {
6219+
String sqlStr = "INSERT INTO foo(col1, col2, col3, col4, col5, col6)\n"
6220+
+ " VALUES ( (SELECT blah FROM bar INNER JOIN bam ON bar.col1 = bam.col1 WHERE bar.id = ? AND et.id = ?), ?, ?, ?, ?, ?)\n"
6221+
+ " ON CONFLICT (id) DO UPDATE\n"
6222+
+ " SET col4 = ?, col5 = ?, col6 = ?";
6223+
Statement statement = CCJSqlParserUtil.parse(sqlStr);
6224+
System.out.println(statement.toString());
6225+
Insert insert = (Insert) statement;
6226+
Assertions.assertEquals("foo", insert.getTable().toString());
6227+
}
62176228
}

0 commit comments

Comments
 (0)