Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dagster and referential integrity notebook generate alldocs collection in different ways #696

Open
Tracked by #318
eecavanna opened this issue Sep 20, 2024 · 2 comments · May be fixed by #786
Open
Tracked by #318

Dagster and referential integrity notebook generate alldocs collection in different ways #696

eecavanna opened this issue Sep 20, 2024 · 2 comments · May be fixed by #786
Assignees

Comments

@eecavanna
Copy link
Collaborator

eecavanna commented Sep 20, 2024

There is some code in the ref integrity notebook that looks similar to your first commit, but batches the write operations to mongo. It is fairly performant (~30 sec with functional annotation) and uses LinkML's native schemaview to get all class ancestors for each doc.

for coll_name in collection_names:
    pbar.set_description(f"processing {coll_name}...")
    requests = []
    for doc in mdb[coll_name].find():
        doc_type = doc_cls(doc, coll_name=coll_name)
        slots_to_include = ["id"] + document_reference_ranged_slots[doc_type]
        new_doc = pick(slots_to_include, doc)
        new_doc["type"] = schema_view.class_ancestors(doc_type)
        requests.append(InsertOne(new_doc))
        if len(requests) == 1000: # ensure bulk-write batches aren't too huge
            result = mdb.alldocs.bulk_write(requests, ordered=False)
            pbar.update(result.inserted_count)
            requests.clear()
    if len(requests) > 0:
        result = mdb.alldocs.bulk_write(requests, ordered=False)
        pbar.update(result.inserted_count)
pbar.close()

Could you use this logic instead? It is fairly similar to your first commit

Originally posted by @PeopleMakeCulture in #694 (comment)

@eecavanna
Copy link
Collaborator Author

As discussed on Slack, I'm thinking of there being a helper function (a.k.a. a "util" function) that generates the alldocs collection (I called this function "compile_alldocs_collection" in the diagram below). The Dagster op and the bulk referential integrity validation notebook would then each "import" that helper function insteading of having their own local implementation (which could fall "out of sync" with the other's over time).

image

@ssarrafan
Copy link

@eecavanna @PeopleMakeCulture appears to still be in progress. I'll move to the next sprint. FYI @dwinston

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: On stage
Development

Successfully merging a pull request may close this issue.

3 participants