22
22
*/
23
23
public class NestedBracketsPerformanceTest {
24
24
25
- private static final int ITERATIONS_20 = 20 ;
26
-
27
25
@ Test
28
26
public void testIssue766 () throws JSQLParserException {
29
27
assertSqlCanBeParsedAndDeparsed ("SELECT concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat(concat('1','2'),'3'),'4'),'5'),'6'),'7'),'8'),'9'),'10'),'11'),'12'),'13'),'14'),'15'),'16'),'17'),'18'),'19'),'20'),'21'),col1 FROM tbl t1" , true );
@@ -50,6 +48,18 @@ public void testIssue856() throws JSQLParserException {
50
48
String sql = "SELECT " + buildRecursiveBracketExpression ("if(month(today()) = 3, sum(\" Table5\" .\" Month 002\" ), $1)" , "0" , 5 ) + " FROM mytbl" ;
51
49
assertSqlCanBeParsedAndDeparsed (sql );
52
50
}
51
+
52
+ @ Test
53
+ public void testRecursiveBracketExpressionIssue1019 () {
54
+ assertEquals ("IF(1=1, 1, 2)" , buildRecursiveBracketExpression ("IF(1=1, $1, 2)" , "1" , 0 ));
55
+ assertEquals ("IF(1=1, IF(1=1, 1, 2), 2)" , buildRecursiveBracketExpression ("IF(1=1, $1, 2)" , "1" , 1 ));
56
+ assertEquals ("IF(1=1, IF(1=1, IF(1=1, 1, 2), 2), 2)" , buildRecursiveBracketExpression ("IF(1=1, $1, 2)" , "1" , 2 ));
57
+ }
58
+
59
+ @ Test
60
+ public void testRecursiveBracketExpressionIssue1019_2 () throws JSQLParserException {
61
+ doIncreaseOfParseTimeTesting ("IF(1=1, $1, 2)" , "1" , 10 );
62
+ }
53
63
54
64
/**
55
65
* Try to avoid or border exceptionally big parsing time increments by adding more bracket constructs.
@@ -58,10 +68,14 @@ public void testIssue856() throws JSQLParserException {
58
68
*/
59
69
@ Test
60
70
public void testIncreaseOfParseTime () throws JSQLParserException {
71
+ doIncreaseOfParseTimeTesting ("concat($1,'B')" , "'A'" , 20 );
72
+ }
73
+
74
+ private void doIncreaseOfParseTimeTesting (String template , String finalExpression , int maxDepth ) throws JSQLParserException {
61
75
long oldDurationTime = 1000 ;
62
76
int countProblematic = 0 ;
63
- for (int i = 0 ; i < ITERATIONS_20 ; i ++) {
64
- String sql = "SELECT " + buildRecursiveBracketExpression ("concat($1,'B')" , "'A'" , i ) + " FROM mytbl" ;
77
+ for (int i = 0 ; i < maxDepth ; i ++) {
78
+ String sql = "SELECT " + buildRecursiveBracketExpression (template , finalExpression , i ) + " FROM mytbl" ;
65
79
long startTime = System .currentTimeMillis ();
66
80
assertSqlCanBeParsedAndDeparsed (sql , true );
67
81
long durationTime = System .currentTimeMillis () - startTime ;
@@ -86,7 +100,7 @@ public void testRecursiveBracketExpression() {
86
100
assertEquals ("concat(concat('A','B'),'B')" , buildRecursiveBracketExpression ("concat($1,'B')" , "'A'" , 1 ));
87
101
assertEquals ("concat(concat(concat('A','B'),'B'),'B')" , buildRecursiveBracketExpression ("concat($1,'B')" , "'A'" , 2 ));
88
102
}
89
-
103
+
90
104
private String buildRecursiveBracketExpression (String template , String finalExpression , int depth ) {
91
105
if (depth == 0 ) {
92
106
return template .replace ("$1" , finalExpression );
0 commit comments