def test_table_ref(self): ''' Testing table info in TableRef Class: TableInfo ''' table_info = TableInfo('TAIPAI', 'Schema', 'Database') table_ref_obj = TableRef(table_info) select_stmt_new = SelectStatement() select_stmt_new.from_table = table_ref_obj self.assertEqual(select_stmt_new.from_table.table_info.table_name, 'TAIPAI') self.assertEqual(select_stmt_new.from_table.table_info.schema_name, 'Schema') self.assertEqual(select_stmt_new.from_table.table_info.database_name, 'Database')
def visitQuerySpecification(self, ctx: evaql_parser.QuerySpecificationContext): target_list = None from_clause = None where_clause = None # first child will be a SELECT terminal token for child in ctx.children[1:]: try: rule_idx = child.getRuleIndex() if rule_idx == evaql_parser.RULE_selectElements: target_list = self.visit(child) elif rule_idx == evaql_parser.RULE_fromClause: clause = self.visit(child) from_clause = clause.get('from', None) where_clause = clause.get('where', None) except BaseException: # stop parsing something bad happened return None # we don't support multiple table sources if from_clause is not None: from_clause = from_clause[0] select_stmt = SelectStatement(target_list, from_clause, where_clause) return select_stmt
def test_visit_select_should_not_call_visits_for_null_values(self): converter = StatementToPlanConvertor() converter.visit_table_ref = MagicMock() converter._visit_projection = MagicMock() converter._visit_select_predicate = MagicMock() statement = SelectStatement() converter.visit_select(statement) converter.visit_table_ref.assert_not_called() converter._visit_projection.assert_not_called() converter._visit_select_predicate.assert_not_called()
def test_select_statement_class(self): ''' Testing setting different clauses for Select Statement class Class: SelectStatement''' select_stmt_new = SelectStatement() parser = Parser() select_query_new = "SELECT CLASS, REDNESS FROM TAIPAI \ WHERE (CLASS = 'VAN' AND REDNESS < 400 ) OR REDNESS > 700;" eva_statement_list = parser.parse(select_query_new) select_stmt = eva_statement_list[0] select_stmt_new.where_clause = select_stmt.where_clause select_stmt_new.target_list = select_stmt.target_list select_stmt_new.from_table = select_stmt.from_table self.assertEqual(select_stmt_new.where_clause, select_stmt.where_clause) self.assertEqual(select_stmt_new.target_list, select_stmt.target_list) self.assertEqual(select_stmt_new.from_table, select_stmt.from_table) self.assertEqual(str(select_stmt_new), str(select_stmt))
def test_should_return_false_for_unequal_expression(self): table = TableRef(TableInfo('MyVideo')) load_stmt = LoadDataStatement(table, Path('data/video.mp4')) insert_stmt = InsertTableStatement(table) create_udf = CreateUDFStatement('udf', False, [ ColumnDefinition('frame', ParserColumnDataType.NDARRAY, [3, 256, 256]) ], [ColumnDefinition('labels', ParserColumnDataType.NDARRAY, [10])], Path('data/fastrcnn.py'), 'Classification') select_stmt = SelectStatement() self.assertNotEqual(load_stmt, insert_stmt) self.assertNotEqual(insert_stmt, load_stmt) self.assertNotEqual(create_udf, insert_stmt) self.assertNotEqual(select_stmt, create_udf)
def visitQuerySpecification( self, ctx: evaql_parser.QuerySpecificationContext): target_list = None from_clause = None where_clause = None orderby_clause = None limit_count = None # first child will be a SELECT terminal token for child in ctx.children[1:]: try: rule_idx = child.getRuleIndex() if rule_idx == evaql_parser.RULE_selectElements: target_list = self.visit(child) elif rule_idx == evaql_parser.RULE_fromClause: clause = self.visit(child) from_clause = clause.get('from', None) where_clause = clause.get('where', None) elif rule_idx == evaql_parser.RULE_orderByClause: orderby_clause = self.visit(ctx.orderByClause()) elif rule_idx == evaql_parser.RULE_limitClause: limit_count = self.visit(ctx.limitClause()) except BaseException as e: # stop parsing something bad happened LoggingManager().log('Error while parsing \ visitQuerySpecification', LoggingLevel.ERROR) raise e # we don't support multiple table sources if from_clause is not None: from_clause = from_clause[0] select_stmt = SelectStatement( target_list, from_clause, where_clause, orderby_clause_list=orderby_clause, limit_count=limit_count) return select_stmt