@stream_session
def list_dataset_replicas(scope, name, deep=False, session=None):
    '\n    :param scope: The scope of the dataset.\n    :param name: The name of the dataset.\n    :param deep: Lookup at the file level.\n    :param session: Database session to use.\n\n    :returns: A list of dictionaries containing the dataset replicas\n              with associated metrics and timestamps\n    '
    if (not deep):
        query = session.query(models.CollectionReplica.scope, models.CollectionReplica.name, models.RSE.rse, models.CollectionReplica.rse_id, models.CollectionReplica.bytes, models.CollectionReplica.length, models.CollectionReplica.available_bytes, models.CollectionReplica.available_replicas_cnt.label('available_length'), models.CollectionReplica.state, models.CollectionReplica.created_at, models.CollectionReplica.updated_at, models.CollectionReplica.accessed_at).filter_by(scope=scope, name=name, did_type=DIDType.DATASET).filter((models.CollectionReplica.rse_id == models.RSE.id)).filter((models.RSE.deleted == false()))
        for row in query:
            (yield row._asdict())
    else:
        content_query = session.query(func.sum(models.DataIdentifierAssociation.bytes).label('bytes'), func.count().label('length')).with_hint(models.DataIdentifierAssociation, 'INDEX_RS_ASC(CONTENTS CONTENTS_PK) NO_INDEX_FFS(CONTENTS CONTENTS_PK)', 'oracle').filter((models.DataIdentifierAssociation.scope == scope)).filter((models.DataIdentifierAssociation.name == name))
        (bytes, length) = (0, 0)
        for row in content_query:
            (bytes, length) = (row.bytes, row.length)
        sub_query_archives = session.query(models.DataIdentifierAssociation.scope.label('dataset_scope'), models.DataIdentifierAssociation.name.label('dataset_name'), models.DataIdentifierAssociation.bytes.label('file_bytes'), models.ConstituentAssociation.child_scope.label('file_scope'), models.ConstituentAssociation.child_name.label('file_name'), models.RSEFileAssociation.scope.label('replica_scope'), models.RSEFileAssociation.name.label('replica_name'), models.RSE.rse, models.RSE.id.label('rse_id'), models.RSEFileAssociation.created_at, models.RSEFileAssociation.accessed_at, models.RSEFileAssociation.updated_at).filter((models.DataIdentifierAssociation.scope == scope)).filter((models.DataIdentifierAssociation.name == name)).filter((models.ConstituentAssociation.child_scope == models.DataIdentifierAssociation.child_scope)).filter((models.ConstituentAssociation.child_name == models.DataIdentifierAssociation.child_name)).filter((models.ConstituentAssociation.scope == models.RSEFileAssociation.scope)).filter((models.ConstituentAssociation.name == models.RSEFileAssociation.name)).filter((models.RSEFileAssociation.rse_id == models.RSE.id)).filter((models.RSEFileAssociation.state == ReplicaState.AVAILABLE)).filter((models.RSE.deleted == false())).subquery()
        group_query_archives = session.query(sub_query_archives.c.dataset_scope, sub_query_archives.c.dataset_name, sub_query_archives.c.file_scope, sub_query_archives.c.file_name, sub_query_archives.c.rse_id, sub_query_archives.c.rse, func.sum(sub_query_archives.c.file_bytes).label('file_bytes'), func.min(sub_query_archives.c.created_at).label('created_at'), func.max(sub_query_archives.c.updated_at).label('updated_at'), func.max(sub_query_archives.c.accessed_at).label('accessed_at')).group_by(sub_query_archives.c.dataset_scope, sub_query_archives.c.dataset_name, sub_query_archives.c.file_scope, sub_query_archives.c.file_name, sub_query_archives.c.rse_id, sub_query_archives.c.rse).subquery()
        full_query_archives = session.query(group_query_archives.c.dataset_scope.label('scope'), group_query_archives.c.dataset_name.label('name'), group_query_archives.c.rse_id, group_query_archives.c.rse, func.sum(group_query_archives.c.file_bytes).label('available_bytes'), func.count().label('available_length'), func.min(group_query_archives.c.created_at).label('created_at'), func.max(group_query_archives.c.updated_at).label('updated_at'), func.max(group_query_archives.c.accessed_at).label('accessed_at')).group_by(group_query_archives.c.dataset_scope, group_query_archives.c.dataset_name, group_query_archives.c.rse_id, group_query_archives.c.rse)
        sub_query = session.query(models.DataIdentifierAssociation.scope, models.DataIdentifierAssociation.name, models.RSEFileAssociation.rse_id, func.sum(models.RSEFileAssociation.bytes).label('available_bytes'), func.count().label('available_length'), func.min(models.RSEFileAssociation.created_at).label('created_at'), func.max(models.RSEFileAssociation.updated_at).label('updated_at'), func.max(models.RSEFileAssociation.accessed_at).label('accessed_at')).with_hint(models.DataIdentifierAssociation, 'INDEX_RS_ASC(CONTENTS CONTENTS_PK) INDEX_RS_ASC(REPLICAS REPLICAS_PK) NO_INDEX_FFS(CONTENTS CONTENTS_PK)', 'oracle').filter((models.DataIdentifierAssociation.child_scope == models.RSEFileAssociation.scope)).filter((models.DataIdentifierAssociation.child_name == models.RSEFileAssociation.name)).filter((models.DataIdentifierAssociation.scope == scope)).filter((models.DataIdentifierAssociation.name == name)).filter((models.RSEFileAssociation.state == ReplicaState.AVAILABLE)).group_by(models.DataIdentifierAssociation.scope, models.DataIdentifierAssociation.name, models.RSEFileAssociation.rse_id).subquery()
        query = session.query(sub_query.c.scope, sub_query.c.name, sub_query.c.rse_id, models.RSE.rse, sub_query.c.available_bytes, sub_query.c.available_length, sub_query.c.created_at, sub_query.c.updated_at, sub_query.c.accessed_at).filter((models.RSE.id == sub_query.c.rse_id)).filter((models.RSE.deleted == false()))
        final_query = query.union_all(full_query_archives)
        for row in final_query.all():
            replica = row._asdict()
            (replica['length'], replica['bytes']) = (length, bytes)
            if (replica['length'] == row.available_length):
                replica['state'] = ReplicaState.AVAILABLE
            else:
                replica['state'] = ReplicaState.UNAVAILABLE
            (yield replica)
:param scope: The scope of the dataset.
:param name: The name of the dataset.
:param deep: Lookup at the file level.
:param session: Database session to use.

:returns: A list of dictionaries containing the dataset replicas
          with associated metrics and timestamps
@stream_session
def list_dataset_replicas(scope, name, deep=False, session=None):
    '\n    :param scope: The scope of the dataset.\n    :param name: The name of the dataset.\n    :param deep: Lookup at the file level.\n    :param session: Database session to use.\n\n    :returns: A list of dictionaries containing the dataset replicas\n              with associated metrics and timestamps\n    '
    if (not deep):
        query = session.query(models.CollectionReplica.scope, models.CollectionReplica.name, models.RSE.rse, models.CollectionReplica.rse_id, models.CollectionReplica.bytes, models.CollectionReplica.length, models.CollectionReplica.available_bytes, models.CollectionReplica.available_replicas_cnt.label('available_length'), models.CollectionReplica.state, models.CollectionReplica.created_at, models.CollectionReplica.updated_at, models.CollectionReplica.accessed_at).filter_by(scope=scope, name=name, did_type=DIDType.DATASET).filter((models.CollectionReplica.rse_id == models.RSE.id)).filter((models.RSE.deleted == false()))
        for row in query:
            (yield row._asdict())
    else:
        content_query = session.query(func.sum(models.DataIdentifierAssociation.bytes).label('bytes'), func.count().label('length')).with_hint(models.DataIdentifierAssociation, 'INDEX_RS_ASC(CONTENTS CONTENTS_PK) NO_INDEX_FFS(CONTENTS CONTENTS_PK)', 'oracle').filter((models.DataIdentifierAssociation.scope == scope)).filter((models.DataIdentifierAssociation.name == name))
        (bytes, length) = (0, 0)
        for row in content_query:
            (bytes, length) = (row.bytes, row.length)
        sub_query_archives = session.query(models.DataIdentifierAssociation.scope.label('dataset_scope'), models.DataIdentifierAssociation.name.label('dataset_name'), models.DataIdentifierAssociation.bytes.label('file_bytes'), models.ConstituentAssociation.child_scope.label('file_scope'), models.ConstituentAssociation.child_name.label('file_name'), models.RSEFileAssociation.scope.label('replica_scope'), models.RSEFileAssociation.name.label('replica_name'), models.RSE.rse, models.RSE.id.label('rse_id'), models.RSEFileAssociation.created_at, models.RSEFileAssociation.accessed_at, models.RSEFileAssociation.updated_at).filter((models.DataIdentifierAssociation.scope == scope)).filter((models.DataIdentifierAssociation.name == name)).filter((models.ConstituentAssociation.child_scope == models.DataIdentifierAssociation.child_scope)).filter((models.ConstituentAssociation.child_name == models.DataIdentifierAssociation.child_name)).filter((models.ConstituentAssociation.scope == models.RSEFileAssociation.scope)).filter((models.ConstituentAssociation.name == models.RSEFileAssociation.name)).filter((models.RSEFileAssociation.rse_id == models.RSE.id)).filter((models.RSEFileAssociation.state == ReplicaState.AVAILABLE)).filter((models.RSE.deleted == false())).subquery()
        group_query_archives = session.query(sub_query_archives.c.dataset_scope, sub_query_archives.c.dataset_name, sub_query_archives.c.file_scope, sub_query_archives.c.file_name, sub_query_archives.c.rse_id, sub_query_archives.c.rse, func.sum(sub_query_archives.c.file_bytes).label('file_bytes'), func.min(sub_query_archives.c.created_at).label('created_at'), func.max(sub_query_archives.c.updated_at).label('updated_at'), func.max(sub_query_archives.c.accessed_at).label('accessed_at')).group_by(sub_query_archives.c.dataset_scope, sub_query_archives.c.dataset_name, sub_query_archives.c.file_scope, sub_query_archives.c.file_name, sub_query_archives.c.rse_id, sub_query_archives.c.rse).subquery()
        full_query_archives = session.query(group_query_archives.c.dataset_scope.label('scope'), group_query_archives.c.dataset_name.label('name'), group_query_archives.c.rse_id, group_query_archives.c.rse, func.sum(group_query_archives.c.file_bytes).label('available_bytes'), func.count().label('available_length'), func.min(group_query_archives.c.created_at).label('created_at'), func.max(group_query_archives.c.updated_at).label('updated_at'), func.max(group_query_archives.c.accessed_at).label('accessed_at')).group_by(group_query_archives.c.dataset_scope, group_query_archives.c.dataset_name, group_query_archives.c.rse_id, group_query_archives.c.rse)
        sub_query = session.query(models.DataIdentifierAssociation.scope, models.DataIdentifierAssociation.name, models.RSEFileAssociation.rse_id, func.sum(models.RSEFileAssociation.bytes).label('available_bytes'), func.count().label('available_length'), func.min(models.RSEFileAssociation.created_at).label('created_at'), func.max(models.RSEFileAssociation.updated_at).label('updated_at'), func.max(models.RSEFileAssociation.accessed_at).label('accessed_at')).with_hint(models.DataIdentifierAssociation, 'INDEX_RS_ASC(CONTENTS CONTENTS_PK) INDEX_RS_ASC(REPLICAS REPLICAS_PK) NO_INDEX_FFS(CONTENTS CONTENTS_PK)', 'oracle').filter((models.DataIdentifierAssociation.child_scope == models.RSEFileAssociation.scope)).filter((models.DataIdentifierAssociation.child_name == models.RSEFileAssociation.name)).filter((models.DataIdentifierAssociation.scope == scope)).filter((models.DataIdentifierAssociation.name == name)).filter((models.RSEFileAssociation.state == ReplicaState.AVAILABLE)).group_by(models.DataIdentifierAssociation.scope, models.DataIdentifierAssociation.name, models.RSEFileAssociation.rse_id).subquery()
        query = session.query(sub_query.c.scope, sub_query.c.name, sub_query.c.rse_id, models.RSE.rse, sub_query.c.available_bytes, sub_query.c.available_length, sub_query.c.created_at, sub_query.c.updated_at, sub_query.c.accessed_at).filter((models.RSE.id == sub_query.c.rse_id)).filter((models.RSE.deleted == false()))
        final_query = query.union_all(full_query_archives)
        for row in final_query.all():
            replica = row._asdict()
            (replica['length'], replica['bytes']) = (length, bytes)
            if (replica['length'] == row.available_length):
                replica['state'] = ReplicaState.AVAILABLE
            else:
                replica['state'] = ReplicaState.UNAVAILABLE
            (yield replica)