MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestParser_MultipleLateralJoins

Function TestParser_MultipleLateralJoins

pkg/sql/parser/lateral_join_test.go:119–167  ·  view source on GitHub ↗

TestParser_MultipleLateralJoins tests multiple LATERAL subqueries in one query

(t *testing.T)

Source from the content-addressed store, hash-verified

117
118// TestParser_MultipleLateralJoins tests multiple LATERAL subqueries in one query
119func TestParser_MultipleLateralJoins(t *testing.T) {
120 sql := `SELECT u.name, recent.order_date, top_product.product_name
121FROM users u
122LEFT JOIN LATERAL (SELECT order_date FROM orders WHERE user_id = u.id ORDER BY order_date DESC LIMIT 1) AS recent ON true
123LEFT JOIN LATERAL (SELECT p.product_name FROM orders o JOIN products p ON o.product_id = p.id WHERE o.user_id = u.id GROUP BY p.product_name LIMIT 1) AS top_product ON true`
124
125 // Get tokenizer from pool
126 tkz := tokenizer.GetTokenizer()
127 defer tokenizer.PutTokenizer(tkz)
128
129 // Tokenize SQL
130 tokens, err := tkz.Tokenize([]byte(sql))
131 if err != nil {
132 t.Fatalf("Failed to tokenize: %v", err)
133 }
134
135 // Convert tokens for parser
136
137 // Parse tokens
138 parser := GetParser()
139 defer PutParser(parser)
140
141 astObj, err := parser.ParseFromModelTokensWithPositions(tokens)
142 if err != nil {
143 t.Fatalf("Failed to parse: %v", err)
144 }
145 defer ast.ReleaseAST(astObj)
146
147 // Verify SELECT statement
148 selectStmt, ok := astObj.Statements[0].(*ast.SelectStatement)
149 if !ok {
150 t.Fatal("Expected SELECT statement")
151 }
152
153 // Verify we have 2 JOINs
154 if len(selectStmt.Joins) != 2 {
155 t.Fatalf("Expected 2 JOINs, got %d", len(selectStmt.Joins))
156 }
157
158 // Verify both are LATERAL
159 for i, join := range selectStmt.Joins {
160 if !join.Right.Lateral {
161 t.Errorf("JOIN %d: Expected LATERAL flag to be true", i)
162 }
163 if join.Right.Subquery == nil {
164 t.Errorf("JOIN %d: Expected subquery in LATERAL join", i)
165 }
166 }
167}

Callers

nothing calls this directly

Calls 9

GetTokenizerFunction · 0.92
PutTokenizerFunction · 0.92
ReleaseASTFunction · 0.92
GetParserFunction · 0.85
PutParserFunction · 0.85
TokenizeMethod · 0.80
FatalfMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected