-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(Views): views for a single dataframe (#1594)
* feature(Views): views for a single dataframe * fix: regression on sql dataframe, added tests * fix(VirtualDataframe): postpone head loading for dependency needs
- Loading branch information
1 parent
be3e158
commit 2455592
Showing
12 changed files
with
148 additions
and
57 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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import pytest | ||
|
||
from pandasai.query_builders.sql_parser import SQLParser | ||
|
||
|
||
class TestSqlParser: | ||
@staticmethod | ||
@pytest.mark.parametrize( | ||
"query, table_mapping, expected", | ||
[ | ||
( | ||
"SELECT * FROM customers", | ||
{"customers": "clients"}, | ||
"""SELECT | ||
* | ||
FROM "clients" AS customers""", | ||
), | ||
( | ||
"SELECT * FROM orders", | ||
{"orders": "(SELECT * FROM sales)"}, | ||
"""SELECT | ||
* | ||
FROM ( | ||
( | ||
SELECT | ||
* | ||
FROM "sales" | ||
) | ||
) AS orders""", | ||
), | ||
( | ||
"SELECT * FROM customers c", | ||
{"customers": "clients"}, | ||
"""SELECT | ||
* | ||
FROM "clients" AS c""", | ||
), | ||
( | ||
"SELECT c.id, o.amount FROM customers c JOIN orders o ON c.id = o.customer_id", | ||
{"customers": "clients", "orders": "(SELECT * FROM sales)"}, | ||
'''SELECT | ||
"c"."id", | ||
"o"."amount" | ||
FROM "clients" AS c | ||
JOIN ( | ||
( | ||
SELECT | ||
* | ||
FROM "sales" | ||
) | ||
) AS o | ||
ON "c"."id" = "o"."customer_id"''', | ||
), | ||
], | ||
) | ||
def test_replace_table_names(query, table_mapping, expected): | ||
result = SQLParser.replace_table_and_column_names(query, table_mapping) | ||
assert result.strip() == expected.strip() |
Oops, something went wrong.