Skip to content

Commit 7f5b61e

Browse files
committed
small modifications, reduces some semantic lookaheads
1 parent eccd66f commit 7f5b61e

File tree

3 files changed

+109
-5
lines changed

3 files changed

+109
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,15 +2023,15 @@ Expression PrimaryExpression():
20232023

20242024
| LOOKAHEAD([sign="+" | sign="-"] JsonExpression()) [sign="+" | sign="-"] retval=JsonExpression()
20252025

2026-
| LOOKAHEAD(["+" | "-"] Function()) [sign="+" | sign="-"] retval=Function()
2026+
| LOOKAHEAD(["+" | "-"] Function()) [sign="+" | sign="-"] retval=Function()
20272027

2028-
| LOOKAHEAD(["+" | "-"] <S_DOUBLE>) [sign="+" | sign="-"] token=<S_DOUBLE> { retval = new DoubleValue(token.image); }
2028+
| LOOKAHEAD(2) [sign="+" | sign="-"] token=<S_DOUBLE> { retval = new DoubleValue(token.image); }
20292029

2030-
| LOOKAHEAD(["+" | "-"] <S_LONG>) [sign="+" | sign="-"] token=<S_LONG> { retval = new LongValue(token.image); }
2030+
| LOOKAHEAD(2) [sign="+" | sign="-"] token=<S_LONG> { retval = new LongValue(token.image); }
20312031

2032-
| LOOKAHEAD(["+" | "-"] <S_HEX>) [sign="+" | sign="-"] token=<S_HEX> { retval = new HexValue(token.image); }
2032+
| LOOKAHEAD(2) [sign="+" | sign="-"] token=<S_HEX> { retval = new HexValue(token.image); }
20332033

2034-
| LOOKAHEAD(["+" | "-"] CastExpression()) [sign="+" | sign="-"] retval=CastExpression()
2034+
| LOOKAHEAD(2) [sign="+" | sign="-"] retval=CastExpression()
20352035

20362036
| LOOKAHEAD(["+" | "-"] Column()) [sign="+" | sign="-"] retval=Column()
20372037

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,4 +2119,13 @@ public void testBooleanValue() throws JSQLParserException {
21192119
public void testBooleanValue2() throws JSQLParserException {
21202120
assertSqlCanBeParsedAndDeparsed("SELECT col FROM t WHERE 3 < 5 AND a");
21212121
}
2122+
2123+
public void testSpeedTestIssue235() throws JSQLParserException {
2124+
assertSqlCanBeParsedAndDeparsed("SELECT * FROM tbl WHERE (ROUND((((((period_diff(date_format(tbl.CD, '%Y%m'), date_format(SUBTIME(CURRENT_TIMESTAMP(), 25200), '%Y%m')) + month(SUBTIME(CURRENT_TIMESTAMP(), 25200))) - MONTH('2012-02-01')) - 1) / 3) - ROUND((((month(SUBTIME(CURRENT_TIMESTAMP(),25200)) - MONTH('2012-02-01')) - 1) / 3)))) = -3)", true);
2125+
}
2126+
2127+
public void testSpeedTestIssue235_2() throws IOException, JSQLParserException {
2128+
String stmt = IOUtils.toString(SelectTest.class.getResourceAsStream("large-sql-issue-235.txt"));
2129+
assertSqlCanBeParsedAndDeparsed(stmt, true);
2130+
}
21222131
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
SELECT
2+
'CR' AS `^CR`,
3+
(1 - (SUM((CASE
4+
WHEN (`tbl`.`AS` = 'Cancelled') THEN (CASE
5+
WHEN (ROUND((((((period_diff(date_format(`tbl`.`CD`,
6+
'%Y%m'),
7+
date_format(SUBTIME(CURRENT_TIMESTAMP(),
8+
25200),
9+
'%Y%m')) + month(SUBTIME(CURRENT_TIMESTAMP(),
10+
25200))) - MONTH('2012-02-01')) - 1) / 3) - ROUND((((month(SUBTIME(CURRENT_TIMESTAMP(),
11+
25200)) - MONTH('2012-02-01')) - 1) / 3)))) = -3) THEN 1
12+
ELSE 0
13+
END)
14+
ELSE 0
15+
END)) / SUM((CASE
16+
WHEN (`tbl`.`AS` = 'Active') THEN (CASE
17+
WHEN (ROUND((((((period_diff(date_format(`tbl`.`OCD`,
18+
'%Y%m'),
19+
date_format(SUBTIME(CURRENT_TIMESTAMP(),
20+
25200),
21+
'%Y%m')) + month(SUBTIME(CURRENT_TIMESTAMP(),
22+
25200))) - MONTH('2012-02-01')) - 1) / 3) - ROUND((((month(SUBTIME(CURRENT_TIMESTAMP(),
23+
25200)) - MONTH('2012-02-01')) - 1) / 3)))) <= -3) THEN 1
24+
ELSE 0
25+
END)
26+
ELSE 0
27+
END)))) AS `^P3Q TRR`,
28+
(1 - (SUM((CASE
29+
WHEN (`tbl`.`AS` = 'Cancelled') THEN (CASE
30+
WHEN (ROUND((((((period_diff(date_format(`tbl`.`CD`,
31+
'%Y%m'),
32+
date_format(SUBTIME(CURRENT_TIMESTAMP(),
33+
25200),
34+
'%Y%m')) + month(SUBTIME(CURRENT_TIMESTAMP(),
35+
25200))) - MONTH('2012-02-01')) - 1) / 3) - ROUND((((month(SUBTIME(CURRENT_TIMESTAMP(),
36+
25200)) - MONTH('2012-02-01')) - 1) / 3)))) = -2) THEN 1
37+
ELSE 0
38+
END)
39+
ELSE 0
40+
END)) / SUM((CASE
41+
WHEN (`tbl`.`AS` = 'Active') THEN (CASE
42+
WHEN (ROUND((((((period_diff(date_format(`tbl`.`OCD`,
43+
'%Y%m'),
44+
date_format(SUBTIME(CURRENT_TIMESTAMP(),
45+
25200),
46+
'%Y%m')) + month(SUBTIME(CURRENT_TIMESTAMP(),
47+
25200))) - MONTH('2012-02-01')) - 1) / 3) - ROUND((((month(SUBTIME(CURRENT_TIMESTAMP(),
48+
25200)) - MONTH('2012-02-01')) - 1) / 3)))) <= -2) THEN 1
49+
ELSE 0
50+
END)
51+
ELSE 0
52+
END)))) AS `^P2Q TRR`,
53+
(1 - (SUM((CASE
54+
WHEN (`tbl`.`AS` = 'Cancelled') THEN (CASE
55+
WHEN (ROUND((((((period_diff(date_format(`tbl`.`CD`,
56+
'%Y%m'),
57+
date_format(SUBTIME(CURRENT_TIMESTAMP(),
58+
25200),
59+
'%Y%m')) + month(SUBTIME(CURRENT_TIMESTAMP(),
60+
25200))) - MONTH('2012-02-01')) - 1) / 3) - ROUND((((month(SUBTIME(CURRENT_TIMESTAMP(),
61+
25200)) - MONTH('2012-02-01')) - 1) / 3)))) = -1) THEN 1
62+
ELSE 0
63+
END)
64+
ELSE 0
65+
END)) / SUM((CASE
66+
WHEN (`tbl`.`AS` = 'Active') THEN (CASE
67+
WHEN (ROUND((((((period_diff(date_format(`tbl`.`OCD`,
68+
'%Y%m'),
69+
date_format(SUBTIME(CURRENT_TIMESTAMP(),
70+
25200),
71+
'%Y%m')) + month(SUBTIME(CURRENT_TIMESTAMP(),
72+
25200))) - MONTH('2012-02-01')) - 1) / 3) - ROUND((((month(SUBTIME(CURRENT_TIMESTAMP(),
73+
25200)) - MONTH('2012-02-01')) - 1) / 3)))) <= -1) THEN 1
74+
ELSE 0
75+
END)
76+
ELSE 0
77+
END)))) AS `^PQ TRR`,
78+
(1 - (SUM((CASE
79+
WHEN ((ROUND((((((period_diff(date_format(`tbl`.`CD`,
80+
'%Y%m'),
81+
date_format(SUBTIME(CURRENT_TIMESTAMP(),
82+
25200),
83+
'%Y%m')) + month(SUBTIME(CURRENT_TIMESTAMP(),
84+
25200))) - MONTH('2012-02-01')) - 1) / 3) - ROUND((((month(SUBTIME(CURRENT_TIMESTAMP(),
85+
25200)) - MONTH('2012-02-01')) - 1) / 3)))) = 0)
86+
AND (`tbl`.`AS` = 'Cancelled')) THEN 1
87+
ELSE 0
88+
END)) / SUM((CASE
89+
WHEN (`tbl`.`AS` = 'Active') THEN 1
90+
ELSE 0
91+
END)))) AS `^CQ TRR`
92+
FROM
93+
`tbl`
94+
GROUP BY
95+
'CR' LIMIT 25000

0 commit comments

Comments
 (0)