Skip to content

Step 11: Using advanced irods queries

Note that for all queries, you will only see results from files that you have access to!

Search data in iRods

You can use iquest to ask about anything to irods about anything. Metadata, users, files, collections etc. Below are some examples:

Querying all your data files

iquest "select COLL_NAME,DATA_NAME where DATA_OWNER_NAME = 'abcde001'"

Querying data with certain metadata fields.

iquest "select COLL_NAME,DATA_NAME,META_DATA_ATTR_VALUE where META_DATA_ATTR_NAME = 'archive_status'"

You can also do formatting of queries, and grouping of data by using counts or sums

iquest "We have %s files on resource %s with archive_status=archive_requested" "select count(DATA_NAME),DATA_RESC_HIER where META_DATA_ATTR_NAME = 'archive_status' and META_DATA_ATTR_VALUE = 'archive_requested'"
If you want to know more about possible fields to query you can use iquest attrs. Use it in combination with e.g. grep to filter for more specific usecases:

iquest attrs
iquest attrs | grep DATA
  1. Navigate to the search tab.
  2. Explore the search options.
  3. See examples:

    • An example with a search by metadata name
    • An example with a search by metadata name and value
    • An example with a search by file name

    Search by metadata 1 Search by metadata 2 Search by name

There is currently no command/query for metadata searches.

Querying all your data files:

from connect import connect_to_irods
from irods.models import Collection, DataObject, CollectionMeta

session = connect_to_irods()


def query_myfiles(username):
    query = session.query(DataObject).filter(DataObject.owner_name == username)
    for x in query:
        print(f' - {x[DataObject.path]}')
        print(f'    - {x[DataObject.name]}')


# Example
query_myfiles('abcde001')
...

And for querying data objects with specific metadata:

...
def querymeta(attr=None, val=None, unit=None):

    query = session.query(Collection, DataObject, DataObjectMeta)

    if attr is not None:
        query = query.filter(DataObjectMeta.name == attr)
    if val is not None:
        query = query.filter(DataObjectMeta.value == val)
    if unit is not None:
        query = query.filter(DataObjectMeta.units == unit)

    print(f'Data bjects matching metadata: ')
    if attr:
        print(f"| Attribute: '{attr}' |")
    if val:
        print(f"| Value: '{val}' |")
    if unit:
        print(f"| Units: '{unit}' |")
    print()

    for result in query:
        print(f' - {result[Collection.name]}')
        print(f'    - {result[DataObject.name]}')


# Example
querymeta(attr="archive_status")
Note: you can also do a similar query for collections with specific metadata with 'CollectionMeta'