Repository navigation
autogenerate indices using parallel loader #228
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
Changes from all commits
0323d2d
55b0d93
05471f4
d7c2b64
5ad4097
e650521
a885769
fa6927e
a3cd1fc
8652deb
c005c44
5a1be9f
73b88ce
b250b13
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,6 +16,59 @@ def __init__(self, db, dry_run=False): | |
| super().__init__(db, dry_run=dry_run) | ||
| self.type = "element" | ||
|
|
||
| def get_existing_indices(self): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry to join the party late here 🥲 This functionality is pretty much a re-implementation of what we have on our Utils.py file. We should try to re-use those.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will create an issue for re-factoring this later, it is not a big deal. |
||
| schema_result, _ = self.db.query([{"GetSchema": {}}]) | ||
| schema = schema_result[0]["GetSchema"] | ||
| existing_indices = {} | ||
| if schema: | ||
| for index_type in (("entity", "entities"), ("connection", "connections")): | ||
| foo = schema.get(index_type[1]) or {} | ||
| bar = foo.get("classes") or {} | ||
| for cls_name, cls_schema in bar.items(): | ||
| props = cls_schema.get("properties") or {} | ||
| for prop_name, prop_schema in props.items(): | ||
| if prop_schema[1]: # indicates property has an index | ||
| existing_indices.setdefault(index_type[0], {}).setdefault( | ||
| cls_name, set()).add(prop_name) | ||
| return existing_indices | ||
|
|
||
| def create_indices(self, indices): | ||
| if len(indices) == 0: | ||
| return | ||
|
|
||
| existing_indices = self.get_existing_indices() | ||
| new_indices = [] | ||
| for tp, classes in indices.items(): | ||
| ex_classes = existing_indices.get(tp, {}) | ||
| for cls, props in classes.items(): | ||
| ex_props = ex_classes.get(cls, set()) | ||
| for prop in props - ex_props: | ||
| new_indices.append({ | ||
| "index_type": tp, | ||
| "class": cls, | ||
| "property_key": prop | ||
| }) | ||
|
|
||
| if len(new_indices) == 0: | ||
| return | ||
|
|
||
| logger.info( | ||
| f"Creating {len(new_indices)} indices: {new_indices}.") | ||
|
|
||
| create_indices = [{"CreateIndex": idx} for idx in new_indices] | ||
|
|
||
| res, _ = self.db.query( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, we should just use this method on Utils.py. |
||
| create_indices) | ||
|
|
||
| if self.db.check_status(res) != 0: | ||
| logger.warning( | ||
| "Failed to create indices; ingestion will be slow.") | ||
| logger.warning(res) | ||
|
|
||
| def query_setup(self, generator): | ||
| if hasattr(generator, "get_indices"): | ||
| self.create_indices(generator.get_indices()) | ||
|
|
||
| def ingest(self, generator, batchsize=1, numthreads=4, stats=False): | ||
| logger.info( | ||
| f"Starting ingestion with batchsize={batchsize}, numthreads={numthreads}") | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check ensures that a CSV file is not read at the first pass when dask mode is used. It's a performance optimization, but it's impact can be observed when using a file with millions of rows. I can explain more offline.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, sorry, forgot to hit send 🤦
My interpretation was that this was only making use of the header, which should already be populated by
super().__init__()andvalidation().In any event, for this PT, I only need the header row. Is there a way to get that without having to read the whole file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. I think we can merge it and worry about the optimization part later.