From bc644c36405c6a1205252b02d3e73d4be43b0867 Mon Sep 17 00:00:00 2001 From: ysandler Date: Tue, 13 May 2025 18:08:32 -0500 Subject: [PATCH] test: added test for parsing multiple joins and different join type --- q/parse.go | 6 ------ q/parse_test.go | 24 +++++++++++++++++++++++- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/q/parse.go b/q/parse.go index c02fdad..ea54a93 100644 --- a/q/parse.go +++ b/q/parse.go @@ -433,8 +433,6 @@ func parseJoins(p *parser) error { return t.Type == sqllexer.KEYWORD && strings.ToUpper(t.Value) == "ON" }) - fmt.Printf("Found ON at '%d'\n", foundOnTokenIndex) - if foundOnTokenIndex < 0 { selectQuery.Joins = append(selectQuery.Joins, workingJoin) continue @@ -447,8 +445,6 @@ func parseJoins(p *parser) error { break } - fmt.Printf("Currently at '%d', reading '%s'\n", i, t.Value) - if t.Type == sqllexer.IDENT { if workingOn.Key == "" { workingOn.Key = t.Value @@ -467,8 +463,6 @@ func parseJoins(p *parser) error { if workingOn.Key != "" && workingOn.Operator != "" && workingOn.Value != "" { workingJoin.Ons = append(workingJoin.Ons, workingOn) - fmt.Println("Adding ON to workingJoin") - fmt.Println(workingOn) workingOn = Conditional{} } } diff --git a/q/parse_test.go b/q/parse_test.go index 7b4f1b9..94ef266 100644 --- a/q/parse_test.go +++ b/q/parse_test.go @@ -151,7 +151,7 @@ func TestParseSelectStatement_StateMachine(t *testing.T) { }, }, { - input: "SELECT ProductID, ProductName, CategoryName FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID; ", + input: "SELECT ProductID, ProductName, CategoryName FROM Products INNER JOIN Categories ON Products.CategoryID = Categories.CategoryID AND Products.SupplierID = Categories.SupplierID LEFT JOIN Stores ON Products.StoreID = Stores.ID ;", expected: &Select{ Type: SELECT, Table: Table{Name: "Products"}, @@ -175,6 +175,28 @@ func TestParseSelectStatement_StateMachine(t *testing.T) { Operator: "=", Value: "Categories.CategoryID", }, + { + Key: "Products.SupplierID", + Operator: "=", + Value: "Categories.SupplierID", + Extension: "AND", + }, + }, + }, + { + Type: LEFT, + MainTable: Table{ + Name: "Products", + }, + JoiningTable: Table{ + Name: "Stores", + }, + Ons: []Conditional{ + { + Key: "Products.StoreID", + Operator: "=", + Value: "Stores.ID", + }, }, }, },