def apply_auto_limit(self, query_text, should_apply_auto_limit): if should_apply_auto_limit: from redash.query_runner.databricks import split_sql_statements, combine_sql_statements queries = split_sql_statements(query_text) # we only check for last one in the list because it is the one that we show result last_query = queries[-1] if query_is_select_no_limit(last_query): queries[-1] = add_limit_to_query(last_query) return combine_sql_statements(queries) else: return query_text
def test_check_query_limit_no_limit(self): query = "SELECT *" self.assertEqual(True, query_is_select_no_limit(query))
def test_check_query_with_offset(self): query = "SELECT * LIMIT 5 OFFSET 3" self.assertEqual(False, query_is_select_no_limit(query))
def test_check_query_limit_invalid_2(self): query = "TABLE A FROM TABLE B" self.assertEqual(False, query_is_select_no_limit(query))
def test_check_query_limit_invalid_1(self): query = "OFFSET 5" self.assertEqual(False, query_is_select_no_limit(query))
def test_check_query_limit_non_select(self): query = "Create Table (PersonID INT)" self.assertEqual(False, query_is_select_no_limit(query))