-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parser and Select statement Unit TestCases
- Loading branch information
Showing
4 changed files
with
60 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,65 @@ | ||
import unittest | ||
from src.query_parser.eva_parser import EvaFrameQLParser | ||
|
||
from src.query_parser.eva_statement import EvaStatementList, EvaStatement | ||
from src.query_parser.eva_statement import StatementType | ||
from src.query_parser.select_statement import SelectStatement | ||
from src.expression.abstract_expression import AbstractExpression, ExpressionType | ||
class ParserTest(unittest.TestCase): | ||
def __init__(self, *args, **kwargs): | ||
super().__init__(*args, **kwargs) | ||
|
||
def test_basic_visitor(self): | ||
def test_eva_parser(self): | ||
eva = EvaFrameQLParser() | ||
single_queries = [] | ||
single_queries.append("SELECT CLASS FROM TAIPAI;") | ||
single_queries.append("SELECT CLASS FROM TAIPAI WHERE CLASS = 'VAN';") | ||
single_queries.append("SELECT CLASS,REDNESS FROM TAIPAI WHERE CLASS = 'VAN' AND REDNESS > 20;") | ||
single_queries.append("SELECT CLASS FROM TAIPAI WHERE (CLASS = 'VAN' AND REDNESS < 300 ) OR REDNESS > 500;") | ||
single_queries.append("SELECT CLASS FROM TAIPAI WHERE (CLASS = 'VAN' AND REDNESS < 300 ) OR REDNESS > 500;") | ||
for query in single_queries: | ||
eva_statement_list = eva.build_eva_parse_tree(query) | ||
self.assertIsInstance(eva_statement_list, EvaStatementList) | ||
self.assertEqual(len(eva_statement_list), 1) | ||
self.assertIsInstance(eva_statement_list.get_statement(0), EvaStatement) | ||
|
||
multiple_queries = [] | ||
multiple_queries.append("SELECT CLASS FROM TAIPAI WHERE CLASS = 'VAN' AND REDNESS < 300 OR REDNESS > 500; \ | ||
SELECT REDNESS FROM TAIPAI WHERE (CLASS = 'VAN' AND REDNESS = 300)") | ||
|
||
for query in multiple_queries: | ||
eva_statement_list = eva.build_eva_parse_tree(query) | ||
self.assertIsInstance(eva_statement_list, EvaStatementList) | ||
self.assertEqual(len(eva_statement_list), 2) | ||
self.assertIsInstance(eva_statement_list.get_statement(0), EvaStatement) | ||
self.assertIsInstance(eva_statement_list.get_statement(1), EvaStatement) | ||
|
||
|
||
def test_select_parser(self): | ||
eva = EvaFrameQLParser() | ||
query = "SELECT CLASS , REDNESS FROM TAIPAI WHERE CLASS = 'VAN' AND REDNESS = 3 OR REDNESS > 300.23; GROUP BY CLASS HAVING REDNESS > 20 ORDER BY REDNESS;" | ||
eva.build_eva_parse_tree(query) | ||
select_query = "SELECT CLASS, REDNESS FROM TAIPAI WHERE (CLASS = 'VAN' AND REDNESS < 300 ) OR REDNESS > 500;" | ||
eva_statement_list = eva.build_eva_parse_tree(select_query) | ||
self.assertIsInstance(eva_statement_list, EvaStatementList) | ||
self.assertEqual(len(eva_statement_list), 1) | ||
self.assertEqual(eva_statement_list.get_statement(0).stmt_type, \ | ||
StatementType.SELECT) | ||
|
||
select_stmt = eva_statement_list.get_statement(0) | ||
|
||
#target List | ||
self.assertIsNotNone(select_stmt.target_list) | ||
self.assertEqual(len(select_stmt.target_list), 2) | ||
self.assertEqual(select_stmt.target_list[0].etype, ExpressionType.TUPLE_VALUE) | ||
self.assertEqual(select_stmt.target_list[1].etype, ExpressionType.TUPLE_VALUE) | ||
|
||
#from_table | ||
#Todo change this to table ref, discuss with data loader team before making any change | ||
self.assertIsNotNone(select_stmt.from_table) | ||
#self.assertEqual(select_stmt.from_table.etype, ExpressionType.TUPLE_VALUE) | ||
|
||
#where_clause | ||
self.assertIsNotNone(select_stmt.where_clause) | ||
#other tests should go in expression testing | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |