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

Fix network agg resolution #885

Merged
merged 4 commits into from
Sep 12, 2024

Conversation

ciaranschutte
Copy link
Contributor

@ciaranschutte ciaranschutte commented Sep 12, 2024

Fixes bucket resolution

example:
Server1 buckets: [Cat, Dog]
Server2 buckets: [Cat, Bird]
Output: [Cat, Dog, Bird]

Comment on lines +4 to +25
const bucket = new GraphQLObjectType({
name: 'bucket',
fields: {
doc_count: {
type: GraphQLInt,
},
key: {
type: GraphQLString,
},
},
});

// TODO: Placeholder to expand type
const networkAggregations = new GraphQLObjectType({
name: 'NetworkAggregations',
fields: {
bucket_count: {
type: GraphQLInt,
},
buckets: {
type: new GraphQLList(bucket),
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extend GQL typings for GQL query response

Comment on lines +5 to +19
/**
* Converts field/types to GQLObjectType definition shape
*
* @example
* { name: "donor_age", type: "NumericAggregations" } => { donor_age: { type: "NetworkNumericAggregations" } }
*/
const convertToGQLObjectType = (networkFieldTypes) => {
return networkFieldTypes.reduce((allFields, currentField) => {
const field = {
[currentField.name]: { type: singleToNetworkAggregationMap.get(currentField.type) },
};
return { ...allFields, ...field };
}, {});
};

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isolate function

Comment on lines +68 to +82
agg.buckets.forEach((bucket) => {
const { key, doc_count } = bucket;
const existingBucketIndex = computedBuckets.findIndex((bucket) => bucket.key === key);
if (existingBucketIndex !== -1) {
const existingBucket = computedBuckets[existingBucketIndex];
if (existingBucket) {
// update existing bucket
computedBuckets[existingBucketIndex] = {
...existingBucket,
doc_count: existingBucket.doc_count + doc_count,
};
}
} else {
computedBuckets.push(bucket);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Size of buckets can be large
Using forEach to either update "found bucket" or add to resolved buckets

Avoids using functional operations on the entire "resolved buckets" and then having a large array of Buckets and needing to flatten and filter on same Bucket key

No way around searching buckets for existing bucket unfortunately as the data structure is an array and a key lookup is not an option.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the lookup has always been a pain point... perhaps we should make a ticket for future improvement to make the buckets a dictionary available internally in the Arranger server for this and other lookups, even if it's ultimately turned in the UI as an array for display purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ciaranschutte
Copy link
Contributor Author

CI failing is known issue

};
}
} else {
computedBuckets.push(bucket);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol I don't think I'll ever be happy/comfortable with mutational logic.

Copy link
Member

@justincorrigible justincorrigible left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

(looks great, though "mutation" 😆)

@ciaranschutte ciaranschutte merged commit f86d685 into feature/federated_search Sep 12, 2024
0 of 2 checks passed
@ciaranschutte ciaranschutte deleted the fix_network_agg_resolution branch September 12, 2024 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants