class NormalSet(DataSet): def load(self, cursor): entitytype = name_to_entitytype(cursor, "materialize_dummytype001") self.datasource = name_to_datasource(cursor, "materialize_src_normal001") view_datasource = name_to_datasource(cursor, "vmaterialize_normal001") granularity = create_granularity('900') self.timestamp = self.datasource.tzinfo.localize( datetime.datetime(2013, 8, 26, 22, 0, 0)) trend_names = ["cntr"] rows_small = [ (1234, (55,)), (1235, (56,))] self.small_datapackage = DataPackage(granularity, self.timestamp, trend_names, rows_small) rows_large = [ (1234, (55243444334,)), (1235, (56242343242,))] self.large_datapackage = DataPackage(granularity, self.timestamp, trend_names, rows_large) self.trendstore = TrendStore(self.datasource, entitytype, granularity, 86400, 'table') self.trendstore.create(cursor) partition = self.trendstore.partition(self.timestamp) partition.create(cursor) self.trendstore.check_columns_exist(trend_names, ["smallint"])(cursor) modified = self.datasource.tzinfo.localize(datetime.datetime.now()) store_copy_from(cursor, partition.table(), self.small_datapackage, modified) mark_modified(cursor, partition.table(), self.timestamp, modified) view_trendstore = TrendStore(view_datasource, entitytype, granularity, 0, 'view').create(cursor) sql = ( "SELECT " "entity_id, " "timestamp, " 'cntr FROM {}').format(self.trendstore.base_table().render()) self.view = View(view_trendstore, sql).define(cursor).create(cursor) def update_type(self, cursor): self.trendstore.clear_timestamp(self.timestamp)(cursor) names = ["cntr"] types = ["bigint"] self.trendstore.check_column_types(names, types)(cursor) partition = self.trendstore.partition(self.timestamp) modified = self.datasource.tzinfo.localize(datetime.datetime.now()) store_copy_from(cursor, partition.table(), self.large_datapackage, modified)
def test_check_column_types(self): granularity = create_granularity("900") partition_size = 3600 trendstore = TrendStore(self.datasource, self.entitytype, granularity, partition_size, "table") with closing(self.conn.cursor()) as cursor: trendstore.create(cursor) column_names = ["counter1", "counter2"] initial_data_types = ["smallint", "smallint"] data_types = ["integer", "text"] check_columns_exist = trendstore.check_columns_exist(column_names, initial_data_types) check_columns_exist(cursor) check_column_types = trendstore.check_column_types(column_names, data_types) check_column_types(cursor)