def test_time_range(self): time_range_tests = [ [(None, None), "NULL", "NULL"], [(0, 1000000000), "'1970-01-01 00:00:00'", "'2001-09-09 01:46:40'"], [ ("2000-01-01", "2010-01-01"), "'2000-01-01 00:00:00'", "'2010-01-01 00:00:00'", ], [ (datetime.date(2000, 1, 1), datetime.datetime(2010, 1, 1, 0, 0, 0)), "'2000-01-01 00:00:00'", "'2010-01-01 00:00:00'", ], ] for time_range, start, end in time_range_tests: read_td_table("test_table", self.engine, time_range=time_range) self.assert_query( """ SELECT * FROM test_table WHERE td_time_range(time, {0}, {1}) LIMIT 10000 """.format( start, end ) )
def test_with_columns(self): read_td_table('test_table', self.engine, columns=['c1', 'c2']) self.assert_query(''' SELECT c1, c2 FROM test_table LIMIT 10000 ''')
def test_default(self): read_td_table('test_table', self.engine) self.assert_query(''' SELECT * FROM test_table LIMIT 10000 ''')
def test_with_sample(self): read_td_table('test_table', self.engine, sample=0.1) self.assert_query(''' SELECT * FROM test_table TABLESAMPLE BERNOULLI (10.0) LIMIT 10000 ''')
def test_without_limit(self): read_td_table("test_table", self.engine, limit=None) self.assert_query( """ SELECT * FROM test_table """ )
def test_default(self): read_td_table("test_table", self.engine) self.assert_query( """ SELECT * FROM test_table LIMIT 10000 """ )
def test_with_columns(self): read_td_table("test_table", self.engine, columns=["c1", "c2"]) self.assert_query( """ SELECT c1, c2 FROM test_table LIMIT 10000 """ )
def test_time_range(self): time_range_tests = [ [(None, None), "NULL", "NULL"], [(0, 1000000000), "'1970-01-01 00:00:00'", "'2001-09-09 01:46:40'"], [('2000-01-01', '2010-01-01'), "'2000-01-01 00:00:00'", "'2010-01-01 00:00:00'"], [(datetime.date(2000, 1, 1), datetime.datetime(2010, 1, 1, 0, 0, 0)), "'2000-01-01 00:00:00'", "'2010-01-01 00:00:00'"], ] for time_range, start, end in time_range_tests: read_td_table('test_table', self.engine, time_range=time_range) self.assert_query(''' SELECT * FROM test_table WHERE td_time_range(time, {0}, {1}) LIMIT 10000 '''.format(start, end))
else: qLimit = None #============output format =================== try: outputFormat = input('would you like to specify output format?yes/no? ') except: print("something went wrong") if outputFormat == 'yes': outFormat = user_input_script.outputformat() else: outFormat = 'tabular' #============issue query in treasure data based on user inputs =================== engine = con.query_engine(database=dbName, type=qEngine) df = td.read_td_table(tabName, engine, limit=qLimit, time_range=(mintStamp, maxtStamp), columns=colList) df #======================Download or display results================================ if outFormat == 'csv': df.to_csv('result.csv') else: print(tabulate(df, headers=df.columns, tablefmt="grid")) #####################################################
def getdefaultcolumnlist(tabName, dbName, qEngine): engine = con.query_engine(database=dbName, type=qEngine) df = td.read_td_table(tabName, engine) #it throw an error bcz of engine!!!! colList = list(df.columns.values) return colList
def test_without_limit(self): read_td_table('test_table', self.engine, limit=None) self.assert_query(''' SELECT * FROM test_table ''')
def test_invalid_time_range(self): with self.assertRaises(ValueError): read_td_table("test_table", self.engine, time_range=(1.0, 2.0))
def test_invalid_time_range(self): read_td_table('test_table', self.engine, time_range=(1.0, 2.0))
def fetch_table(self, table): return td.read_td_table(table, self.engine)
def test_invalid_sample_small(self): read_td_table('test_table', self.engine, sample=-1)
def test_invalid_sample_large(self): read_td_table('test_table', self.engine, sample=1.1)