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

Feature/federated search #888

Open
wants to merge 32 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
bd4508e
Network aggregation search - Initial Config (#876)
ciaranschutte Jun 7, 2024
4877cfc
Feat/#873 retrieve remote schemas (#877)
ciaranschutte Jun 26, 2024
0b195d0
Pr feedback - doc updates (#879)
ciaranschutte Jun 26, 2024
5d7a3e6
Feat/#874 merge schemas (#878)
ciaranschutte Jul 5, 2024
cc0848b
Add core functionality for remote connection resolvers (#880)
ciaranschutte Jul 15, 2024
2be0edc
Feat/agg resolver (#881)
ciaranschutte Aug 13, 2024
dd54fd5
Feat/resolve stats (#883)
ciaranschutte Aug 14, 2024
b0b9a74
Feat/resolver responses (#884)
ciaranschutte Aug 16, 2024
e8517ec
Fix network agg resolution (#885)
ciaranschutte Sep 12, 2024
820f22d
Response data & batching requests (#887)
ciaranschutte Sep 19, 2024
2f82cbb
Fed Search request timeouts (#889)
ciaranschutte Sep 19, 2024
4c4dc68
Reorg connection (#891)
ciaranschutte Sep 22, 2024
7926ea4
Accumulator pipeline (#893)
ciaranschutte Sep 27, 2024
0a5db00
Feat/fed total hits (#895)
ciaranschutte Oct 1, 2024
1de98ed
feat/agg acc tests (#897)
ciaranschutte Oct 2, 2024
e31855a
Feat/fed numeric agg resolution (#898)
ciaranschutte Oct 3, 2024
8f4fa08
use Math methods (#900)
ciaranschutte Oct 7, 2024
242c1d1
Individual node config query fields (#899)
ciaranschutte Oct 7, 2024
1afb680
Feat/aggregate not available (#903)
ciaranschutte Oct 12, 2024
87355bb
Feat/filters (#904)
ciaranschutte Oct 21, 2024
a86e70c
Minor comment updates (#905)
ciaranschutte Oct 21, 2024
d5e604f
Fed search cleanup typings (#906)
ciaranschutte Oct 25, 2024
a16623c
Fix broken build (#907)
ciaranschutte Oct 29, 2024
e4d8439
add agg mode env config (#908)
ciaranschutte Nov 21, 2024
52553ac
Feature/threshold calc (#909)
ciaranschutte Dec 10, 2024
9edd1bd
multiple node with data thresholding (#912)
ciaranschutte Dec 16, 2024
52ed91e
remove unused import
Mar 14, 2025
5ffe5e9
Feat/fed search cleanup (#920)
ciaranschutte Mar 15, 2025
7ae3daa
Feat/fed search networked cleanup (#921)
ciaranschutte Mar 20, 2025
4dfa47d
Update modules/server/src/app.js
ciaranschutte Mar 21, 2025
9a9d4fd
remove tsjest diagnostic setting
Mar 21, 2025
f2a33dd
make horrible ajax.ts console logging somewhat useful
ciaranschutte Mar 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix network agg resolution (#885)
* add Bucket gql object type

* text change, move func outside of nested func

* fix resolved aggregations overriding

* Update modules/server/src/network/aggregations/index.ts

Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>

---------

Co-authored-by: Ciaran Schutte <ciaranschutte@oicr.on.ca>
Co-authored-by: Anders Richardsson <2107110+justincorrigible@users.noreply.github.com>
3 people committed Mar 14, 2025
commit e8517ec1d03b6fbd62a6e109ba3437350f9bcb7b
37 changes: 31 additions & 6 deletions modules/server/src/network/aggregations/index.ts
Original file line number Diff line number Diff line change
@@ -44,21 +44,46 @@ export const resolveToNetworkAggregation = (
* Takes an array of the same aggregation type and computes the singular type
* eg. NumericAggregation => NetworkNumericAggregation
*
* Note for operations on Buckets - the size of the array can be large (e.g. total bucket count), complicating lookups, etc.
*
* @param aggregations
* @returns
*/
export const resolveAggregation = (aggregations: Aggregations[]): NetworkAggregation => {
const emptyAggregation: NetworkAggregation = { bucket_count: 0, buckets: [] };

const resolvedAggregation = aggregations.reduce((resolvedAggregation, agg) => {
const computedBucketCount = resolvedAggregation.bucket_count + agg.bucket_count;
const computedBuckets = agg.buckets.map(({ key, doc_count }) => {
// potentially expensive "find" if array of buckets is very large
const bucket = resolvedAggregation.buckets.find((bucket) => bucket.key === key);
return { key, doc_count: (bucket?.doc_count || 0) + doc_count };
const bucketCountAccumulator = resolvedAggregation.bucket_count + agg.bucket_count;

/*
* Unable to use lookup key eg. buckets[key]
* "buckets": [
* {
* "doc_count": 140,
* "key": "Dog"
* },
*/
const computedBuckets = resolvedAggregation.buckets;

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);
}
});
return { bucket_count: computedBucketCount, buckets: computedBuckets };
return { bucket_count: bucketCountAccumulator, buckets: computedBuckets };
}, emptyAggregation);

return resolvedAggregation;
};

2 changes: 1 addition & 1 deletion modules/server/src/network/index.ts
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ const fetchRemoteSchema = async (
/**
* TODO: expand on error handling for instance of Axios error for example
*/
console.error(`failed to retrieve schema from url: ${config.graphqlUrl}`);
console.error(`Failed to retrieve schema from url: ${config.graphqlUrl}`);
return;
}
};
30 changes: 17 additions & 13 deletions modules/server/src/network/typeDefs/aggregations.ts
Original file line number Diff line number Diff line change
@@ -2,11 +2,26 @@ import { GraphQLObjectType, GraphQLSchema } from 'graphql';
import { SupportedNetworkFieldType } from '../types';
import { singleToNetworkAggregationMap } from './networkAggregations';

/**
* 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 };
}, {});
};

/**
* Returns available aggregations by filtering duplicates, and mapping from
* singular remote aggregation type to network aggregation types
*
* eg. NumericAggregation to NetworkNumericAggregation
* eg. NumericAggregations to NetworkNumericAggregations
*
* There is no distinction on which types come from which remote connections
* This is the resolvers responsibility
@@ -17,18 +32,7 @@ import { singleToNetworkAggregationMap } from './networkAggregations';
export const createNetworkAggregationTypeDefs = (
networkFieldTypes: SupportedNetworkFieldType[],
) => {
/**
* Converts field/types to GQLObjectType definition shape
*
* @example
* { name: "donor_age", type: "NumericAggregations" } => { donor_age: { type: "NetworkNumericAggregations" } }
*/
const allFields = networkFieldTypes.reduce((allFields, currentField) => {
const field = {
[currentField.name]: { type: singleToNetworkAggregationMap.get(currentField.type) },
};
return { ...allFields, ...field };
}, {});
const allFields = convertToGQLObjectType(networkFieldTypes);

const typeDefs = new GraphQLObjectType({
name: 'Aggregations',
17 changes: 16 additions & 1 deletion modules/server/src/network/typeDefs/networkAggregations.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
import { GraphQLInt, GraphQLObjectType, GraphQLString } from 'graphql';
import { GraphQLInt, GraphQLList, GraphQLObjectType, GraphQLString } from 'graphql';
import { SupportedAggregation, SUPPORTED_AGGREGATIONS } from '../common';

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),
},
},
});