def get_partition_by_name(cursor, name): column_names = [ "table_name", "datasource_id", "entitytype_id", "granularity", "data_start", "data_end"] columns = map(Column, column_names) query = schema.partition.select(columns, where_=Eq(Column("table_name"))) args = name, query.execute(cursor, args) if cursor.rowcount > 0: name, datasource_id, entitytype_id, granularity_str, data_start, \ data_end = cursor.fetchone() granularity = create_granularity(str(granularity_str)) datasource = get_datasource_by_id(cursor, datasource_id) entitytype = get_entitytype_by_id(cursor, entitytype_id) trendstore = TrendStore(datasource, entitytype, granularity) return Partition(name, trendstore, data_start, data_end) else: return None
def test_get_entitytype_by_id(conn): with closing(conn.cursor()) as cursor: new_entitytype = helpers_v4.create_entitytype(cursor, "test_get_entitytype_by_id", "short description of type") entitytype = helpers_v4.get_entitytype_by_id(cursor, new_entitytype.id) assert entitytype.id == new_entitytype.id assert entitytype.name == "test_get_entitytype_by_id"
def load_attributestore(cls, cursor, id, datasource_id, entitytype_id): datasource = get_datasource_by_id(cursor, datasource_id) entitytype = get_entitytype_by_id(cursor, entitytype_id) attributestore = AttributeStore(datasource, entitytype) attributestore.id = id attributestore.attributes = attributestore.load_attributes(cursor) return attributestore
def store_raw(self, datasource, rawdatapackage): with closing(self.conn.cursor()) as cursor: datapackage = rawdatapackage.refine(cursor) dn = rawdatapackage.rows[0][0] entity = get_entity(cursor, dn) entitytype = get_entitytype_by_id(cursor, entity.entitytype_id) self.store(datasource, entitytype, datapackage)
def view_source_from_row(cursor, row): id, name, datasource_id, entitytype_id, granularity = row view_source = ViewSource() view_source.id = id view_source.name = name view_source.datasource = get_datasource_by_id(cursor, datasource_id) view_source.entitytype = get_entitytype_by_id(cursor, entitytype_id) view_source.granularity = granularity return view_source
def view_from_row(cursor, row): id, description, datasource_id, entitytype_id, granularity, sql = row view = View() view.id = id view.sql = sql view.description = description view.datasource = get_datasource_by_id(cursor, datasource_id) view.entitytype = get_entitytype_by_id(cursor, entitytype_id) view.granularity = create_granularity(granularity) view.sources = get_sources_for_view(cursor, id) return view
def get(cls, cursor, id): """Load and return attributestore by its Id.""" query = ( "SELECT datasource_id, entitytype_id " "FROM attribute_directory.attributestore " "WHERE id = %s") args = id, cursor.execute(query, args) datasource_id, entitytype_id = cursor.fetchone() entitytype = get_entitytype_by_id(cursor, entitytype_id) datasource = get_datasource_by_id(cursor, datasource_id) attributestore = AttributeStore(datasource, entitytype) attributestore.id = id attributestore.attributes = attributestore.load_attributes(cursor) return attributestore
def execute(self, cursor, state): entity = get_entity(cursor, self.dn) entitytype = get_entitytype_by_id(cursor, entity.entitytype_id) datapackage = state["datapackage"] trendstore = TrendStore.get(cursor, self.datasource, entitytype, datapackage.granularity) if not trendstore: partition_size = 86400 trendstore = TrendStore(self.datasource, entitytype, datapackage.granularity, partition_size, "table").create(cursor) partition = trendstore.partition(datapackage.timestamp) logging.debug(partition.name) state["partition"] = partition
def get_by_id(cls, cursor, id): args = (id,) cls.get_by_id_query.execute(cursor, args) if cursor.rowcount == 1: trendstore_id, datasource_id, entitytype_id, granularity_str, \ partition_size, type, version = cursor.fetchone() datasource = get_datasource_by_id(cursor, datasource_id) entitytype = get_entitytype_by_id(cursor, entitytype_id) granularity = create_granularity(granularity_str) trendstore = TrendStore(datasource, entitytype, granularity, partition_size, type) trendstore.id = trendstore_id return trendstore