-
Notifications
You must be signed in to change notification settings - Fork 345
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(embedded/sql): add support for LEFT JOIN
Signed-off-by: Stefano Scafiti <[email protected]>
- Loading branch information
Showing
3 changed files
with
53 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5986,7 +5986,7 @@ func TestNestedJoins(t *testing.T) { | |
require.NoError(t, err) | ||
} | ||
|
||
func TestLeftRightJoins(t *testing.T) { | ||
func TestLeftJoins(t *testing.T) { | ||
e := setupCommonTest(t) | ||
|
||
_, _, err := e.Exec( | ||
|
@@ -6055,10 +6055,28 @@ func TestLeftRightJoins(t *testing.T) { | |
) | ||
require.NoError(t, err) | ||
|
||
rows, err := e.queryAll( | ||
context.Background(), | ||
nil, | ||
`SELECT | ||
assertQueryShouldProduceResults( | ||
t, | ||
e, | ||
`SELECT c.customer_id, c.customer_name, c.email, o.order_id, o.order_date | ||
FROM customers c LEFT JOIN orders o ON c.customer_id = o.customer_id | ||
ORDER BY c.customer_id, o.order_date;`, | ||
` | ||
SELECT * | ||
FROM ( | ||
VALUES | ||
(1, 'Alice Johnson', '[email protected]', 101, '2024-11-01'::TIMESTAMP), | ||
(1, 'Alice Johnson', '[email protected]', 103, '2024-11-03'::TIMESTAMP), | ||
(2, 'Bob Smith', '[email protected]', 102, '2024-11-02'::TIMESTAMP), | ||
(3, 'Charlie Brown', '[email protected]', NULL, NULL) | ||
)`, | ||
) | ||
|
||
assertQueryShouldProduceResults( | ||
t, | ||
e, | ||
` | ||
SELECT | ||
c.customer_name, | ||
c.email, | ||
o.order_id, | ||
|
@@ -6073,10 +6091,16 @@ func TestLeftRightJoins(t *testing.T) { | |
LEFT JOIN orders o ON oi.order_id = o.order_id | ||
LEFT JOIN customers c ON o.customer_id = c.customer_id | ||
ORDER BY o.order_date, c.customer_name;`, | ||
nil, | ||
` | ||
SELECT * | ||
FROM ( | ||
VALUES | ||
('Alice Johnson', '[email protected]', 101, '2024-11-01'::TIMESTAMP, 'Laptop', 2, 1200.00, 2400.00), | ||
('Alice Johnson', '[email protected]', 101, '2024-11-01'::TIMESTAMP, 'Smartphone', 1, 800.00, 800.00), | ||
('Bob Smith', '[email protected]', 102, '2024-11-02'::TIMESTAMP, 'Tablet', 3, 400.00, 1200.00), | ||
('Alice Johnson', '[email protected]', 103, '2024-11-03'::TIMESTAMP, 'Smartphone', 2, 800.00, 1600.00) | ||
)`, | ||
) | ||
require.NoError(t, err) | ||
require.Len(t, rows, 4) | ||
} | ||
|
||
func TestReOpening(t *testing.T) { | ||
|
@@ -9527,3 +9551,24 @@ func TestFunctions(t *testing.T) { | |
require.Equal(t, "OBJECT", rows[0].ValuesByPosition[0].RawValue().(string)) | ||
}) | ||
} | ||
|
||
func assertQueryShouldProduceResults(t *testing.T, e *Engine, query, resultQuery string) { | ||
queryReader, err := e.Query(context.Background(), nil, query, nil) | ||
require.NoError(t, err) | ||
defer queryReader.Close() | ||
|
||
resultReader, err := e.Query(context.Background(), nil, resultQuery, nil) | ||
require.NoError(t, err) | ||
defer resultReader.Close() | ||
|
||
for { | ||
row, err := queryReader.Read(context.Background()) | ||
row1, err1 := resultReader.Read(context.Background()) | ||
require.Equal(t, err, err1) | ||
|
||
if errors.Is(err, ErrNoMoreRows) { | ||
break | ||
} | ||
require.Equal(t, row1.ValuesByPosition, row.ValuesByPosition) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters