tmater commented on code in PR #4844:
URL: https://github.com/apache/calcite/pull/4844#discussion_r3079319816
##########
babel/src/test/java/org/apache/calcite/test/BabelParserTest.java:
##########
@@ -301,6 +306,101 @@ private void checkParseInfixCast(String sqlType) {
sql(sql).ok(expected);
}
+ @Test void testColonFieldAccessWithInfixCast() {
+ final SqlParserFixture f =
+ fixture().withConformance(new SqlAbstractConformance() {
+ @Override public boolean isColonFieldAccessAllowed() {
+ return true;
+ }
+ });
+
+ // Bracket after :: binds to the type, not as subscript on the cast result
+ sql("select v::varchar[1] from t")
+ .ok("SELECT `V` :: VARCHAR[1]\nFROM `T`");
+ f.sql("select v::varchar[1] from t")
+ .ok("SELECT `V` :: VARCHAR[1]\nFROM `T`");
+
+ // Explicit parentheses make no difference — bracket still binds to the
type
+ sql("select (v::varchar)[1] from t")
+ .ok("SELECT `V` :: VARCHAR[1]\nFROM `T`");
+ f.sql("select (v::varchar)[1] from t")
+ .ok("SELECT `V` :: VARCHAR[1]\nFROM `T`");
+
+ // Array type with bracket
+ sql("select v::integer array[1] from t")
+ .ok("SELECT `V` :: INTEGER ARRAY[1]\nFROM `T`");
+ f.sql("select v::integer array[1] from t")
+ .ok("SELECT `V` :: INTEGER ARRAY[1]\nFROM `T`");
+
+ // Parenthesized array type with bracket
+ sql("select (v::integer array)[1] from t")
+ .ok("SELECT `V` :: INTEGER ARRAY[1]\nFROM `T`");
+ f.sql("select (v::integer array)[1] from t")
+ .ok("SELECT `V` :: INTEGER ARRAY[1]\nFROM `T`");
+
+ // Multiple brackets bind to the type
+ sql("select v::varchar[1][2] from t")
+ .ok("SELECT `V` :: VARCHAR[1][2]\nFROM `T`");
Review Comment:
This is parser coverage rather than a meaningful type assertion. The test is
checking that after `::`, the parser still accepts postfix syntax on the RHS
and groups it there, rather than attaching the postfix to the cast result. I
agree the old example made that intent unclear, so I updated the test to make
the associativity point clearer.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]