@@ -3,6 +3,8 @@ package parser
33import (
44 "errors"
55 "fmt"
6+
7+ "slices"
68)
79
810func (p * Parser ) tryParseWithClause (pos Pos ) (* WithClause , error ) {
@@ -196,11 +198,11 @@ func (p *Parser) parseJoinOp(_ Pos) []string {
196198 case p .matchKeyword (KeywordInner ):
197199 modifiers = append (modifiers , p .last ().String )
198200 _ = p .lexer .consumeToken ()
199- if p .matchKeyword (KeywordAll ) || p .matchKeyword (KeywordAny ) || p .matchKeyword (KeywordAsof ) {
201+ if p .matchKeyword (KeywordAll ) || p .matchKeyword (KeywordAny ) || p .matchKeyword (KeywordAsof ) || p . matchKeyword ( KeywordArray ) {
200202 modifiers = append (modifiers , p .last ().String )
201203 _ = p .lexer .consumeToken ()
202204 }
203- case p .matchKeyword (KeywordLeft ), p . matchKeyword ( KeywordRight ) :
205+ case p .matchKeyword (KeywordLeft ):
204206 modifiers = append (modifiers , p .last ().String )
205207 _ = p .lexer .consumeToken ()
206208 if p .matchKeyword (KeywordOuter ) {
@@ -213,6 +215,19 @@ func (p *Parser) parseJoinOp(_ Pos) []string {
213215 modifiers = append (modifiers , p .last ().String )
214216 _ = p .lexer .consumeToken ()
215217 }
218+ case p .matchKeyword (KeywordRight ):
219+ modifiers = append (modifiers , p .last ().String )
220+ _ = p .lexer .consumeToken ()
221+ if p .matchKeyword (KeywordOuter ) {
222+ modifiers = append (modifiers , p .last ().String )
223+ _ = p .lexer .consumeToken ()
224+ }
225+ if p .matchKeyword (KeywordSemi ) || p .matchKeyword (KeywordAnti ) ||
226+ p .matchKeyword (KeywordAny ) || p .matchKeyword (KeywordAll ) ||
227+ p .matchKeyword (KeywordAsof ) {
228+ modifiers = append (modifiers , p .last ().String )
229+ _ = p .lexer .consumeToken ()
230+ }
216231 case p .matchKeyword (KeywordFull ):
217232 modifiers = append (modifiers , p .last ().String )
218233 _ = p .lexer .consumeToken ()
@@ -224,6 +239,9 @@ func (p *Parser) parseJoinOp(_ Pos) []string {
224239 modifiers = append (modifiers , p .last ().String )
225240 _ = p .lexer .consumeToken ()
226241 }
242+ case p .matchKeyword (KeywordArray ):
243+ modifiers = append (modifiers , p .last ().String )
244+ _ = p .lexer .consumeToken ()
227245 }
228246 return modifiers
229247}
@@ -281,6 +299,30 @@ func (p *Parser) parseJoinRightExpr(pos Pos) (expr Expr, err error) {
281299 }
282300
283301 modifiers = append (modifiers , KeywordJoin )
302+
303+ // Check if this is an ARRAY JOIN
304+ if slices .Contains (modifiers , KeywordArray ) {
305+ // For ARRAY JOIN, parse column expression list instead of table expression
306+ expr , err = p .parseColumnExprList (p .Pos ())
307+ if err != nil {
308+ return nil , err
309+ }
310+
311+ // ARRAY JOIN doesn't have constraints (ON/USING)
312+ // try parse next join
313+ rightExpr , err = p .parseJoinRightExpr (p .Pos ())
314+ if err != nil {
315+ return nil , err
316+ }
317+ return & JoinExpr {
318+ JoinPos : pos ,
319+ Left : expr ,
320+ Right : rightExpr ,
321+ Modifiers : modifiers ,
322+ Constraints : nil ,
323+ }, nil
324+ }
325+
284326 expr , err = p .parseJoinTableExpr (p .Pos ())
285327 if err != nil {
286328 return nil , err
@@ -852,41 +894,6 @@ func (p *Parser) parseWindowClause(pos Pos) (*WindowClause, error) {
852894 }, nil
853895}
854896
855- func (p * Parser ) tryParseArrayJoinClause (pos Pos ) (* ArrayJoinClause , error ) {
856- if ! p .matchKeyword (KeywordLeft ) && ! p .matchKeyword (KeywordInner ) && ! p .matchKeyword (KeywordArray ) {
857- return nil , nil
858- }
859- return p .parseArrayJoinClause (pos )
860- }
861-
862- func (p * Parser ) parseArrayJoinClause (_ Pos ) (* ArrayJoinClause , error ) {
863- var typ string
864- switch {
865- case p .matchKeyword (KeywordLeft ), p .matchKeyword (KeywordInner ):
866- typ = p .last ().String
867- _ = p .lexer .consumeToken ()
868- }
869- arrayPos := p .Pos ()
870- if err := p .expectKeyword (KeywordArray ); err != nil {
871- return nil , err
872- }
873-
874- if err := p .expectKeyword (KeywordJoin ); err != nil {
875- return nil , err
876- }
877-
878- expr , err := p .parseColumnExprList (p .Pos ())
879- if err != nil {
880- return nil , err
881- }
882-
883- return & ArrayJoinClause {
884- ArrayPos : arrayPos ,
885- Type : typ ,
886- Expr : expr ,
887- }, nil
888- }
889-
890897func (p * Parser ) tryParseHavingClause (pos Pos ) (* HavingClause , error ) {
891898 if ! p .matchKeyword (KeywordHaving ) {
892899 return nil , nil
@@ -1009,18 +1016,6 @@ func (p *Parser) parseSelectStmt(pos Pos) (*SelectQuery, error) { // nolint: fun
10091016 if from != nil {
10101017 statementEnd = from .End ()
10111018 }
1012- var arrayJoins []* ArrayJoinClause
1013- for {
1014- arrayJoin , err := p .tryParseArrayJoinClause (p .Pos ())
1015- if err != nil {
1016- return nil , err
1017- }
1018- if arrayJoin == nil {
1019- break
1020- }
1021- arrayJoins = append (arrayJoins , arrayJoin )
1022- statementEnd = arrayJoin .End ()
1023- }
10241019 prewhere , err := p .tryParsePrewhereClause (p .Pos ())
10251020 if err != nil {
10261021 return nil , err
@@ -1129,7 +1124,6 @@ func (p *Parser) parseSelectStmt(pos Pos) (*SelectQuery, error) { // nolint: fun
11291124 DistinctOn : distinctOn ,
11301125 SelectItems : selectItems ,
11311126 From : from ,
1132- ArrayJoin : arrayJoins ,
11331127 Window : window ,
11341128 Prewhere : prewhere ,
11351129 Where : where ,
0 commit comments