fb-2030 - added test cases for Joins in sql3 (#2359)

* fb-2030 - added test cases for Joins in sql3

* test cases for joins

* Revert "test cases for joins"

This reverts commit 1501f7b202.
This commit is contained in:
HHans09 2023-03-31 11:52:19 -04:00 committed by GitHub
parent 8fca15e936
commit 52f9703585
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 85 additions and 0 deletions

View file

@ -190,6 +190,7 @@ var TableTests []TableTest = []TableTest{
// joins
joinTestsUsers,
joinTestsOrders,
joinTestsQuantity,
joinTests,
// bulk insert

View file

@ -43,6 +43,26 @@ var joinTestsOrders = TableTest{
),
SQLTests: nil,
}
var joinTestsQuantity = TableTest{
name: "jointestquantity",
Table: tbl(
"quantity",
srcHdrs(
srcHdr("_id", fldTypeID),
srcHdr("userid", fldTypeInt),
srcHdr("quantity", fldTypeInt),
),
srcRows(
srcRow(int64(0), int64(1), int64(1)),
srcRow(int64(1), int64(0), int64(2)),
srcRow(int64(2), int64(2), int64(2)),
srcRow(int64(3), int64(3), int64(1)),
srcRow(int64(4), int64(1), int64(3)),
srcRow(int64(5), int64(2), int64(5)),
),
),
SQLTests: nil,
}
var joinTests = TableTest{
name: "joinTests",
@ -116,6 +136,38 @@ var joinTests = TableTest{
),
Compare: CompareExactOrdered,
},
{
name: "nested-inner-join",
SQLs: sqls(
"select DISTINCT u._id from users u inner join orders o on o.userid = u._id join quantity q on o.userid = q.userid;",
),
ExpHdrs: hdrs(
hdr("_id", fldTypeID),
),
ExpRows: rows(
row(int64(0)),
row(int64(1)),
row(int64(2)),
row(int64(3)),
),
Compare: CompareExactOrdered,
},
{
name: "nested-inner-and-left-join",
SQLs: sqls(
"select DISTINCT u._id from users u inner join orders o on o.userid = u._id left join quantity q on o.userid = q.userid;",
),
ExpHdrs: hdrs(
hdr("_id", fldTypeID),
),
ExpRows: rows(
row(int64(0)),
row(int64(1)),
row(int64(2)),
row(int64(3)),
),
Compare: CompareExactOrdered,
},
{
name: "leftjoin",
SQLs: sqls(
@ -136,6 +188,24 @@ var joinTests = TableTest{
),
Compare: CompareExactOrdered,
},
{
name: "nested-left-join",
SQLs: sqls(
"select distinct u._id, o.userid from users u left join orders o on o.userid = u._id left join quantity q on o.userid = q.userid;",
),
ExpHdrs: hdrs(
hdr("_id", fldTypeID),
hdr("userid", fldTypeInt),
),
ExpRows: rows(
row(int64(0), int64(0)),
row(int64(1), int64(1)),
row(int64(2), int64(2)),
row(int64(3), int64(3)),
row(int64(4), nil),
),
Compare: CompareExactOrdered,
},
// test u.* and expect select list is expanded to all collumns in table alias u
{
name: "join-select-start",
@ -155,6 +225,13 @@ var joinTests = TableTest{
),
Compare: CompareExactOrdered,
},
{
name: "Unmatched-columns-in-join",
SQLs: sqls(
"select u._id, o.userid from users u join orders o on u.name = o.userid;",
),
ExpErr: "types 'string' and 'int' are not equatable",
},
{
name: "fulljoin",
SQLs: sqls(
@ -169,6 +246,13 @@ var joinTests = TableTest{
),
ExpErr: "RIGHT join types are not supported",
},
{
name: "nested-inner-join-with-right-join",
SQLs: sqls(
"select * from users u inner join orders o on o.userid = u._id right join quantity q on o.userid = q.userid;",
),
ExpErr: "RIGHT join types are not supported",
},
{
name: "commajoin",
SQLs: sqls(