test: added test for parsing multiple joins and different join type

This commit is contained in:
Yehoshua Sandler 2025-05-13 18:08:32 -05:00
parent 2f7d996485
commit bc644c3640
2 changed files with 23 additions and 7 deletions

View File

@ -433,8 +433,6 @@ func parseJoins(p *parser) error {
return t.Type == sqllexer.KEYWORD && strings.ToUpper(t.Value) == "ON" return t.Type == sqllexer.KEYWORD && strings.ToUpper(t.Value) == "ON"
}) })
fmt.Printf("Found ON at '%d'\n", foundOnTokenIndex)
if foundOnTokenIndex < 0 { if foundOnTokenIndex < 0 {
selectQuery.Joins = append(selectQuery.Joins, workingJoin) selectQuery.Joins = append(selectQuery.Joins, workingJoin)
continue continue
@ -447,8 +445,6 @@ func parseJoins(p *parser) error {
break break
} }
fmt.Printf("Currently at '%d', reading '%s'\n", i, t.Value)
if t.Type == sqllexer.IDENT { if t.Type == sqllexer.IDENT {
if workingOn.Key == "" { if workingOn.Key == "" {
workingOn.Key = t.Value workingOn.Key = t.Value
@ -467,8 +463,6 @@ func parseJoins(p *parser) error {
if workingOn.Key != "" && workingOn.Operator != "" && workingOn.Value != "" { if workingOn.Key != "" && workingOn.Operator != "" && workingOn.Value != "" {
workingJoin.Ons = append(workingJoin.Ons, workingOn) workingJoin.Ons = append(workingJoin.Ons, workingOn)
fmt.Println("Adding ON to workingJoin")
fmt.Println(workingOn)
workingOn = Conditional{} workingOn = Conditional{}
} }
} }

View File

@ -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{ expected: &Select{
Type: SELECT, Type: SELECT,
Table: Table{Name: "Products"}, Table: Table{Name: "Products"},
@ -175,6 +175,28 @@ func TestParseSelectStatement_StateMachine(t *testing.T) {
Operator: "=", Operator: "=",
Value: "Categories.CategoryID", 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",
},
}, },
}, },
}, },