def test_query_simple_1(self): table_name = 'testing' c_1 = Column(str, 'column_1') c_2 = Column(str, 'column_2') q = Query([c_1, c_2], table_name) expected_response = 'SELECT column_1, column_2 FROM ' + \ self.table_date_range response = q.assemble() self.assertEquals(expected_response, response)
def test_query_order_3(self): table_name = 'testing' c_1 = Column(str, 'column_1') c_2 = Column(str, 'column_2') q = Query([c_1, c_2], table_name) q = q.order_by(c_1, desc=True) expected_response = 'SELECT column_1, column_2 FROM ' + \ self.table_date_range + ' ORDER BY column_1 DESC' response = q.assemble() self.assertEquals(expected_response, response)
def basic_test_2(self): c_1 = Column(str, 'c1') c_2 = Column(int, 'c2') q = Query([c_1, c_2], 'test') q.filter(or_(c_1 == 10, c_2 == 10)) expected_query = 'SELECT c1, c2 FROM ' +\ '' + DATABASE_NAME + '.test WHERE _PARTITIONTIME BETWEEN ' +\ 'TIMESTAMP(\'2010-01-01\') AND ' +\ 'TIMESTAMP(\'2030-01-01\')' self.assertEquals(q.assemble(), expected_query)
def test_query_filter_2(self): table_name = 'testing' c_1 = Column(str, 'column_1') c_2 = Column(str, 'column_2') q = Query([c_1, c_2], table_name) # Wrong comparision q = q.filter(c_1 == 10) expected_response = 'SELECT column_1, column_2 FROM ' + \ self.table_date_range response = q.assemble() self.assertEquals(expected_response, response)
def test_query_filter_1(self): table_name = 'testing' c_1 = Column(str, 'column_1') c_2 = Column(str, 'column_2') q = Query([c_1, c_2], table_name) q = q.filter(c_1 == 'test') expected_response = 'SELECT column_1, column_2 FROM ' + \ self.table_date_range + ' AND ' + \ 'column_1 = \'test\'' response = q.assemble() self.assertEquals(expected_response, response)
def test_query_limit_2(self): table_name = 'testing' c_1 = Column(str, 'column_1') c_2 = Column(str, 'column_2') q = Query([c_1, c_2], table_name) q = q.limit(100) q = q.limit(101) expected_response = 'SELECT column_1, column_2 FROM ' + \ self.table_date_range + ' LIMIT 101' response = q.assemble() self.assertEquals(expected_response, response)
def test_query_filter_by_date(self): begin_date = '2015-12-01' end_date = '2016-01-01' table_date_range = '' + DATABASE_NAME + '.testing WHERE _PARTITIONTIME BETWEEN ' +\ 'TIMESTAMP(\'' + begin_date + '\') AND TIMESTAMP' +\ '(\'' + end_date + '\')' table_name = 'testing' c_1 = Column(str, 'column_1') c_2 = Column(str, 'column_2') q = Query([c_1, c_2], table_name).filter_by_date(begin_date, end_date) expected_response = 'SELECT column_1, column_2 FROM ' + \ table_date_range response = q.assemble() self.assertEquals(expected_response, response)