|
9 | 9 | */ |
10 | 10 | package net.sf.jsqlparser.expression; |
11 | 11 |
|
| 12 | +import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; |
| 13 | + |
12 | 14 | import net.sf.jsqlparser.JSQLParserException; |
| 15 | +import net.sf.jsqlparser.expression.operators.relational.ParenthesedExpressionList; |
13 | 16 | import net.sf.jsqlparser.statement.select.PlainSelect; |
14 | 17 | import net.sf.jsqlparser.test.TestUtils; |
15 | 18 | import org.junit.jupiter.api.Assertions; |
16 | 19 | import org.junit.jupiter.api.Test; |
17 | 20 |
|
18 | | -import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed; |
19 | | - |
20 | 21 | /** |
21 | 22 | * |
22 | 23 | * @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a> |
@@ -114,4 +115,29 @@ void testDateTimeCast() throws JSQLParserException { |
114 | 115 | + "as time_tstz;"; |
115 | 116 | assertSqlCanBeParsedAndDeparsed(sqlStr, true); |
116 | 117 | } |
| 118 | + |
| 119 | + @Test |
| 120 | + void testNestedCompositeTypeCastIssue2341() throws JSQLParserException { |
| 121 | + String sqlStr = "SELECT\n" |
| 122 | + + " (product_data::product_info_similarity).info.category AS category,\n" |
| 123 | + + " COUNT(*) AS num_products\n" |
| 124 | + + "FROM products\n" |
| 125 | + + "GROUP BY (product_data::product_info_similarity).info.category;"; |
| 126 | + PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true); |
| 127 | + |
| 128 | + RowGetExpression categoryAccess = |
| 129 | + Assertions.assertInstanceOf(RowGetExpression.class, |
| 130 | + select.getSelectItem(0).getExpression()); |
| 131 | + Assertions.assertEquals("category", categoryAccess.getColumnName()); |
| 132 | + |
| 133 | + RowGetExpression infoAccess = Assertions.assertInstanceOf(RowGetExpression.class, |
| 134 | + categoryAccess.getExpression()); |
| 135 | + Assertions.assertEquals("info", infoAccess.getColumnName()); |
| 136 | + |
| 137 | + ParenthesedExpressionList<?> parenthesedCast = |
| 138 | + Assertions.assertInstanceOf(ParenthesedExpressionList.class, |
| 139 | + infoAccess.getExpression()); |
| 140 | + Assertions.assertEquals(1, parenthesedCast.size()); |
| 141 | + Assertions.assertInstanceOf(CastExpression.class, parenthesedCast.get(0)); |
| 142 | + } |
117 | 143 | } |
0 commit comments