forked from taoyds/spider
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request taoyds#3 from ElementAI/dima-improve-parsing
support "distinct(bla)" and "FROM foo, bar"
- Loading branch information
Showing
4 changed files
with
109 additions
and
28 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
Binary file not shown.
Binary file not shown.
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,38 @@ | ||
from process_sql import get_schema, Schema, get_sql | ||
|
||
|
||
def test_schema(): | ||
return Schema(get_schema('test/db.sqlite')) | ||
|
||
|
||
def test_parse_col(): | ||
ground_truth = (False, [(3, (0, (0, '__papers.id__', True), None))]) | ||
assert get_sql(test_schema(), | ||
'SELECT COUNT(DISTINCT(papers.id)) FROM papers')['select'] == ground_truth | ||
assert get_sql(test_schema(), | ||
'SELECT COUNT(DISTINCT papers.id) FROM papers')['select'] == ground_truth | ||
|
||
ground_truth = (True, [(0, (0, (0, '__papers.id__', False), None))]) | ||
assert get_sql(test_schema(), | ||
'SELECT DISTINCT(papers.id) FROM papers')['select'] == ground_truth | ||
assert get_sql(test_schema(), | ||
'SELECT DISTINCT papers.id FROM papers')['select'] == ground_truth | ||
|
||
|
||
def test_joins(): | ||
ground_truth = {'conds': [], | ||
'table_units': [('table_unit', '__papers__'), ('table_unit', '__coauthored__')]} | ||
assert get_sql(test_schema(), | ||
'SELECT * FROM papers JOIN coauthored')['from'] == ground_truth | ||
assert get_sql(test_schema(), | ||
'SELECT * FROM papers INNER JOIN coauthored')['from'] == ground_truth | ||
assert get_sql(test_schema(), | ||
'SELECT * FROM papers, coauthored')['from'] == ground_truth | ||
|
||
|
||
def test_different_not_equal_operators(): | ||
ground_truth = [(False, 7, (0, (0, '__papers.title__', False), None), '"bar"', None)] | ||
assert get_sql(test_schema(), | ||
'SELECT * FROM papers WHERE papers.title <> "bar"')['where'] == ground_truth | ||
assert get_sql(test_schema(), | ||
'SELECT * FROM papers WHERE papers.title != "bar"')['where'] == ground_truth |