def test_within_clause_error(self): with self.assertRaises(exceptions.CompileError) as context: compiler.compile_text( 'SELECT r1.s, COUNT(r1.s) WITHIN r2 AS ' 'num_s_in_r1 FROM record_table', self.tables_by_name) self.assertTrue( 'WITHIN clause syntax error' in str(context.exception))
def make_view(self, view_name, query): # TODO: Figure out the schema by compiling the query, and refactor the # code so that the compiler can use the schema instead of expecting # every TableId to have actual Columns. For now, we just validate that # the view works, and things will break later if the view is actually # used. compiler.compile_text(query, self.tables_by_name) return View(view_name, query)
def test_strange_arithmetic(self): try: compiler.compile_text( 'SELECT times + ints + floats + bools FROM ' 'rainbow_table', self.tables_by_name) except exceptions.CompileError: self.fail('Compiler exception on arithmetic across all numeric ' 'types.')
def assert_compiled_select(self, text, expected_ast): ast = compiler.compile_text(text, self.tables_by_name) self.assertEqual(expected_ast, ast)
def evaluate_query(self, query): select_ast = compiler.compile_text(query, self.tables_by_name) select_evaluator = evaluator.Evaluator(self.tables_by_name) return select_evaluator.evaluate_select(select_ast)
def test_mistyped_function_call(self): with self.assertRaises(exceptions.CompileError) as context: compiler.compile_text('SELECT SUM(strings) FROM rainbow_table', self.tables_by_name) self.assertTrue('Invalid types for function' in str(context.exception))
def test_mistyped_binary_operator(self): with self.assertRaises(exceptions.CompileError) as context: compiler.compile_text( 'SELECT ints CONTAINS strings FROM ' 'rainbow_table', self.tables_by_name) self.assertTrue('Invalid types for operator' in str(context.exception))