Skip to content

Commit baac99a

Browse files
committed
fix: support ClickHouse tuple positional access
1 parent 25f3040 commit baac99a

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9559,6 +9559,7 @@ Function InternalFunction(boolean escaped):
95599559
Expression expr = null;
95609560
Expression attributeExpression = null;
95619561
Column attributeColumn = null;
9562+
Token attributeToken = null;
95629563
Limit limit;
95639564
List<Function.KeywordArgument> keywordArgs = null;
95649565
}
@@ -9624,14 +9625,24 @@ Function InternalFunction(boolean escaped):
96249625
]
96259626

96269627

9627-
[ LOOKAHEAD(2) "." (
9628-
// tricky lookahead since we do need to support the following constructs
9629-
// schema.f1().f2() - Function with Function Column
9630-
// schema.f1().f2.f3 - Function with Attribute Column
9631-
LOOKAHEAD( 6 ) attributeExpression=Function() { retval.setAttribute(attributeExpression); }
9628+
[
9629+
LOOKAHEAD(2)
9630+
(
9631+
LOOKAHEAD({ getToken(1).kind == S_DOUBLE
9632+
&& getToken(1).image.matches("\\.[0-9]+") })
9633+
attributeToken=<S_DOUBLE> {
9634+
retval.setAttribute(new LongValue(attributeToken.image.substring(1)));
9635+
}
96329636
|
9633-
attributeColumn=Column() { retval.setAttribute(attributeColumn); }
9634-
)
9637+
"." (
9638+
// tricky lookahead since we do need to support the following constructs
9639+
// schema.f1().f2() - Function with Function Column
9640+
// schema.f1().f2.f3 - Function with Attribute Column
9641+
LOOKAHEAD( 6 ) attributeExpression=Function() { retval.setAttribute(attributeExpression); }
9642+
|
9643+
attributeColumn=Column() { retval.setAttribute(attributeColumn); }
9644+
)
9645+
)
96359646
]
96369647

96379648
[ LOOKAHEAD(2) (

src/test/java/net/sf/jsqlparser/statement/select/ClickHouseTest.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,12 @@ public void testFunctionWithAttributesIssue1742() throws JSQLParserException {
7878
assertSqlCanBeParsedAndDeparsed(sql, true);
7979
}
8080

81+
@Test
82+
public void testTuplePositionalAccessIssue2442() throws JSQLParserException {
83+
String sql = "SELECT tuple(1, 2, 3).2 FROM tuple_demo";
84+
assertSqlCanBeParsedAndDeparsed(sql, true);
85+
}
86+
8187
@Test
8288
public void testGlobalIn() throws JSQLParserException {
8389
String sql =

0 commit comments

Comments
 (0)