|
21 | 21 | import java.util.ArrayList; |
22 | 22 | import java.util.List; |
23 | 23 | import net.sf.jsqlparser.JSQLParserException; |
| 24 | +import net.sf.jsqlparser.expression.operators.conditional.AndExpression; |
24 | 25 | import net.sf.jsqlparser.expression.operators.relational.InExpression; |
25 | 26 | import net.sf.jsqlparser.expression.operators.relational.ItemsList; |
26 | 27 | import net.sf.jsqlparser.parser.CCJSqlParserUtil; |
27 | 28 | import net.sf.jsqlparser.schema.Column; |
| 29 | +import net.sf.jsqlparser.schema.Table; |
28 | 30 | import net.sf.jsqlparser.statement.select.PlainSelect; |
29 | 31 | import net.sf.jsqlparser.statement.select.Select; |
30 | 32 | import net.sf.jsqlparser.statement.select.SelectVisitorAdapter; |
@@ -188,7 +190,31 @@ public void testSubSelectExpressionProblem() throws JSQLParserException { |
188 | 190 | fail(); |
189 | 191 | } |
190 | 192 | } |
191 | | - |
| 193 | + |
| 194 | + @Test |
| 195 | + public void testJoinWithoutFrom() throws JSQLParserException { |
| 196 | + Select select = (Select) CCJSqlParserUtil. |
| 197 | + parse("SELECT * JOIN dimension(arg1, arg2)"); |
| 198 | + PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); |
| 199 | + plainSelect.setFromItem(new Table("myDataSet")); |
| 200 | + assertEquals(plainSelect.getJoins().get(0).toString(), "JOIN dimension(arg1, arg2)"); |
| 201 | + assertEquals(plainSelect.toString(), "SELECT * FROM myDataSet JOIN dimension(arg1, arg2)"); |
| 202 | + } |
| 203 | + |
| 204 | + |
| 205 | + @Test |
| 206 | + public void testCustomFunction() throws JSQLParserException { |
| 207 | + Select select = (Select) CCJSqlParserUtil. |
| 208 | + parse("SELECT * FROM myData WHERE regexp_replace(arg1, arg2) AND y > 3"); |
| 209 | + PlainSelect plainSelect = (PlainSelect) select.getSelectBody(); |
| 210 | + AndExpression whereAnd = (AndExpression) plainSelect.getWhere(); |
| 211 | + Function whereFunction = (Function) whereAnd.getLeftExpression(); |
| 212 | + Select newExpression = (Select) CCJSqlParserUtil.parse("SELECT * WHERE x > 2"); |
| 213 | + PlainSelect newPlainSelect = (PlainSelect) newExpression.getSelectBody(); |
| 214 | + whereFunction.setCustomExpression(newPlainSelect.getWhere()); |
| 215 | + assertEquals(plainSelect.toString(), "SELECT * FROM myData WHERE x > 2 AND y > 3"); |
| 216 | + } |
| 217 | + |
192 | 218 | @Test |
193 | 219 | public void testCaseWithoutElse() throws JSQLParserException { |
194 | 220 | Expression expr = CCJSqlParserUtil.parseExpression("CASE WHEN 1 then 0 END"); |
|
0 commit comments