Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt
Original file line number Diff line number Diff line change
Expand Up @@ -6890,8 +6890,8 @@ Expression PrimaryExpression() #PrimaryExpression:
}


// RowGet Expression
[ LOOKAHEAD(2) "." tmp=RelObjectNameExt() { retval = new RowGetExpression(retval, tmp); }]
// RowGet Expressions
( LOOKAHEAD(2) "." tmp=RelObjectNameExt() { retval = new RowGetExpression(retval, tmp); } )*
)
)

Expand Down
30 changes: 28 additions & 2 deletions src/test/java/net/sf/jsqlparser/expression/CastExpressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@
*/
package net.sf.jsqlparser.expression;

import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed;

import net.sf.jsqlparser.JSQLParserException;
import net.sf.jsqlparser.expression.operators.relational.ParenthesedExpressionList;
import net.sf.jsqlparser.statement.select.PlainSelect;
import net.sf.jsqlparser.test.TestUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static net.sf.jsqlparser.test.TestUtils.assertSqlCanBeParsedAndDeparsed;

/**
*
* @author <a href="mailto:andreas@manticore-projects.com">Andreas Reichel</a>
Expand Down Expand Up @@ -114,4 +115,29 @@ void testDateTimeCast() throws JSQLParserException {
+ "as time_tstz;";
assertSqlCanBeParsedAndDeparsed(sqlStr, true);
}

@Test
void testNestedCompositeTypeCastIssue2341() throws JSQLParserException {
String sqlStr = "SELECT\n"
+ " (product_data::product_info_similarity).info.category AS category,\n"
+ " COUNT(*) AS num_products\n"
+ "FROM products\n"
+ "GROUP BY (product_data::product_info_similarity).info.category;";
PlainSelect select = (PlainSelect) TestUtils.assertSqlCanBeParsedAndDeparsed(sqlStr, true);

RowGetExpression categoryAccess =
Assertions.assertInstanceOf(RowGetExpression.class,
select.getSelectItem(0).getExpression());
Assertions.assertEquals("category", categoryAccess.getColumnName());

RowGetExpression infoAccess = Assertions.assertInstanceOf(RowGetExpression.class,
categoryAccess.getExpression());
Assertions.assertEquals("info", infoAccess.getColumnName());

ParenthesedExpressionList<?> parenthesedCast =
Assertions.assertInstanceOf(ParenthesedExpressionList.class,
infoAccess.getExpression());
Assertions.assertEquals(1, parenthesedCast.size());
Assertions.assertInstanceOf(CastExpression.class, parenthesedCast.get(0));
}
}