Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions devHelper/scripts/commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ curl -iv -X PUT "${ESHOST}/${indexName}" \
"days_to_follow_up": { "type": "integer" },
"follow_up_label": { "type": "keyword", "fields": { "analyzed": {"type": "text", "analyzer": "ngram_analyzer", "search_analyzer": "search_analyzer", "term_vector": "with_positions_offsets"} } }
}
},
"treatments_array_under_subjects": {
"type": "nested",
"properties": {
"dose_amount": { "type": "integer" },
"test_article_name_array_under_treatments": { "type": "keyword", "fields": { "analyzed": {"type": "text", "analyzer": "ngram_analyzer", "search_analyzer": "search_analyzer", "term_vector": "with_positions_offsets"} } },
"submitter_id": { "type": "keyword", "fields": { "analyzed": {"type": "text", "analyzer": "ngram_analyzer", "search_analyzer": "search_analyzer", "term_vector": "with_positions_offsets"} } }
}
}
}
},
Expand Down
1 change: 1 addition & 0 deletions genData/genData.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ async function run() {
});
const { body: count } = await client.count({ index: esIndex });
console.log(count);
console.log(arrayFields);

if (configIndex) {
const data = [
Expand Down
20 changes: 13 additions & 7 deletions genData/types.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function fakerType(key, value, arrayFields) {
function fakerType(key, value, arrayFields, nestedFieldKeys = []) {
let fieldType;
const properties = {};
const required = [];
Expand All @@ -10,7 +10,7 @@ function fakerType(key, value, arrayFields) {
fieldType = {
type: 'array', items: { type: 'boolean', properties, required }, minItems: 0, maxItems: 10,
};
arrayFields.push(key);
arrayFields.push(`${nestedFieldKeys.join('.')}.${key}`);
} else {
fieldType = { type: 'boolean' };
}
Expand All @@ -26,7 +26,7 @@ function fakerType(key, value, arrayFields) {
minItems: 0,
maxItems: 10,
};
arrayFields.push(key);
arrayFields.push(`${nestedFieldKeys.join('.')}.${key}`);
} else {
fieldType = { type: 'string', faker: 'name.findName' };
}
Expand All @@ -37,7 +37,7 @@ function fakerType(key, value, arrayFields) {
fieldType = {
type: 'array', items: { type: 'number', properties, required }, minItems: 0, maxItems: 10,
};
arrayFields.push(key);
arrayFields.push(`${nestedFieldKeys.join('.')}.${key}`);
} else {
fieldType = { type: 'number' };
}
Expand All @@ -48,21 +48,27 @@ function fakerType(key, value, arrayFields) {
fieldType = {
type: 'array', items: { type: 'integer', properties, required }, minItems: 0, maxItems: 10,
};
arrayFields.push(key);
arrayFields.push(`${nestedFieldKeys.join('.')}.${key}`);
} else {
fieldType = { type: 'integer' };
}
break;
case 'nested':
nestedFieldKeys.push(key);
Object.entries(value.properties).forEach(([k, v]) => {
properties[k] = fakerType(k, v);
properties[k] = fakerType(k, v, arrayFields, [...nestedFieldKeys]);
required.push(k);
});
fieldType = {
type: 'array', items: { type: 'object', properties, required }, minItems: 0, maxItems: 10,
};
if (key.includes('array')) {
arrayFields.push(key);
// since we already pushed the current key into this array
if (nestedFieldKeys.length) {
arrayFields.push(nestedFieldKeys.join('.'));
} else {
arrayFields.push(key);
}
}
break;
default:
Expand Down
132 changes: 108 additions & 24 deletions genData/valueBank.json
Original file line number Diff line number Diff line change
@@ -1,72 +1,156 @@
{
"gender": ["male", "female", "unknown"],
"ethnicity": ["American Indian", "Pacific Islander", "Black", "Multi-racial", "White", "Haspanic" ],
"race": ["white", "black", "hispanic", "asian", "mixed", "not reported" ],
"vital_status": ["Alive", "Dead", "no data" ],
"file_type": ["mRNA Array", "Unaligned Reads", "Lipdomic MS", "Protionic MS", "1Gs Ribosomes", "Unknown" ],
"file_format": ["BEM", "BAM", "BED", "CSV", "FASTQ", "RAW", "TAR", "TSV", "TXT", "IDAT" ],
"auth_resource_path": ["/programs/jnkns/projects/jenkins", "/programs/DEV/projects/test", "/programs/external/projects/test"],
"sensitive": [ "true", "false" ],
"study": ["study_1", "study_2", "study_3"],
"file_id": ["file_id_1", "file_id_2", "file_id_3"],
"subject_id": ["subject_id_1", "subject_id_2", "subject_id_3"],
"project": ["jnkns-jenkins", "DEV-test", "external-test" ],
"gender": [
"male",
"female",
"unknown"
],
"ethnicity": [
"American Indian",
"Pacific Islander",
"Black",
"Multi-racial",
"White",
"Haspanic"
],
"race": [
"white",
"black",
"hispanic",
"asian",
"mixed",
"not reported"
],
"vital_status": [
"Alive",
"Dead",
"no data"
],
"file_type": [
"mRNA Array",
"Unaligned Reads",
"Lipdomic MS",
"Protionic MS",
"1Gs Ribosomes",
"Unknown"
],
"file_format": [
"BEM",
"BAM",
"BED",
"CSV",
"FASTQ",
"RAW",
"TAR",
"TSV",
"TXT",
"IDAT"
],
"auth_resource_path": [
"/programs/jnkns/projects/jenkins",
"/programs/DEV/projects/test",
"/programs/external/projects/test"
],
"sensitive": [
"true",
"false"
],
"study": [
"study_1",
"study_2",
"study_3"
],
"file_id": [
"file_id_1",
"file_id_2",
"file_id_3"
],
"subject_id": [
"subject_id_1",
"subject_id_2",
"subject_id_3"
],
"project": [
"jnkns-jenkins",
"DEV-test",
"external-test"
],
"visits": [
{
"days_to_visit": 1,
"visit_label": "vst_lbl_1",
"follow_ups": {
"days_to_follow_up": 1,
"follow_up_label": "flup_lbl_1"
}
},
"treatments_array_under_subjects": [
{
"submitter_id": "treatment_1",
"dose_amount": 1,
"test_article_name_array_under_treatments": ["article_1a", "article_1b"]
}
]
},
{
"days_to_visit": 2,
"visit_label": "vst_lbl_2",
"follow_ups": {
"days_to_follow_up": 2,
"follow_up_label": "flup_lbl_2"
}
},
"treatments_array_under_subjects": [
{
"submitter_id": "treatment_2",
"dose_amount": 2,
"test_article_name_array_under_treatments": ["article_2a", "article_2b"]
}
]
},
{
"days_to_visit": 3,
"visit_label": "vst_lbl_3",
"follow_ups": {
"days_to_follow_up": 3,
"follow_up_label": "flup_lbl_3"
}
},
"treatments_array_under_subjects": [
{
"submitter_id": "treatment_3",
"dose_amount": 3,
"test_article_name_array_under_treatments": ["article_3a", "article_3b"]
}
]
}
],
"some_nested_array_field": [
[
{
"some_integer_inside_nested": 1,
"some_string_inside_nested": "first"
"some_integer_inside_nested": 1,
"some_string_inside_nested": "first"
},
{
"some_integer_inside_nested": 2,
"some_string_inside_nested": "second"
}
}
],
[
{
"some_integer_inside_nested": 3,
"some_string_inside_nested": "third"
"some_integer_inside_nested": 3,
"some_string_inside_nested": "third"
},
{
"some_integer_inside_nested": 4,
"some_string_inside_nested": "forth"
}
}
],
[
{
"some_integer_inside_nested": 5,
"some_string_inside_nested": "fifth"
"some_integer_inside_nested": 5,
"some_string_inside_nested": "fifth"
},
{
"some_integer_inside_nested": 6,
"some_string_inside_nested": "sixth"
}
}
]
]
}
24 changes: 23 additions & 1 deletion src/server/__mocks__/mockDataFromES.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,28 @@ const mockESMapping = () => {
},
},
},
treatments_array_under_subjects: {
type: 'nested',
properties: {
dose_amount: { type: 'integer' },
test_article_name_array_under_treatments: {
type: 'keyword',
fields: {
analyzed: {
type: 'text', analyzer: 'ngram_analyzer', search_analyzer: 'search_analyzer', term_vector: 'with_positions_offsets',
},
},
},
submitter_id: {
type: 'keyword',
fields: {
analyzed: {
type: 'text', analyzer: 'ngram_analyzer', search_analyzer: 'search_analyzer', term_vector: 'with_positions_offsets',
},
},
},
},
},
},
},
gender: {
Expand Down Expand Up @@ -393,7 +415,7 @@ const mockArrayConfig = () => {
_id: 'gen3-dev-subject',
_score: 1.0,
_source: {
array: ['some_array_integer_field', 'some_array_string_field'],
array: ['some_array_integer_field', 'some_array_string_field', 'visits.treatments_array_under_subjects', 'visits.treatments_array_under_subjects.test_article_name_array_under_treatments'],
},
},
],
Expand Down
16 changes: 11 additions & 5 deletions src/server/__tests__/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,19 @@ describe('Schema', () => {
_matched:[MatchedItem]
}
type visits {
days_to_visit:Int,
visit_label:String,
follow_ups:follow_ups,
days_to_visit: Int,
visit_label: String,
follow_ups: follow_ups,
treatments_array_under_subjects: [treatments_array_under_subjects],
}
type follow_ups {
days_to_follow_up:Int,
follow_up_label:String,
days_to_follow_up: Int,
follow_up_label: String,
}
type treatments_array_under_subjects {
dose_amount: Int,
test_article_name_array_under_treatments: [String],
submitter_id: String,
}
type File {
gen3_resource_path: String,
Expand Down
2 changes: 1 addition & 1 deletion src/server/es/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ class ES {
let field = f;
if (f.endsWith(config.analyzedTextFieldSuffix)) {
// remove ".analyzed" suffix from field name
field = f.substr(0, f.length - config.analyzedTextFieldSuffix.length);
field = f.substring(0, f.length - config.analyzedTextFieldSuffix.length);
}
return {
field,
Expand Down
18 changes: 11 additions & 7 deletions src/server/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ const esgqlTypeMapping = {

const histogramTypePrefix = 'RegularAccess';

const getGQLType = (esInstance, esIndex, field, esFieldType) => {
const getGQLType = (esInstance, esIndex, field, esFieldType, nestedFieldKeys = []) => {
const gqlType = esgqlTypeMapping[esFieldType];
if (!gqlType) {
throw new Error(`Invalid type ${esFieldType} for field ${field} in index ${esIndex}`);
}
const isArrayField = esInstance.isArrayField(esIndex, field);
let fieldForArrayCheck = field;
if (nestedFieldKeys.length) {
fieldForArrayCheck = `${nestedFieldKeys.join('.')}.${field}`;
}
const isArrayField = esInstance.isArrayField(esIndex, fieldForArrayCheck);
if (isArrayField && esFieldType !== 'nested') {
return `[${gqlType}]`;
}
Expand Down Expand Up @@ -68,11 +72,11 @@ const getQuerySchemaForType = (esType) => {
): [${esTypeObjName}]`;
};

const getFieldGQLTypeMapForProperties = (esInstance, esIndex, properties) => {
const getFieldGQLTypeMapForProperties = (esInstance, esIndex, properties, nestedFieldKeys = []) => {
const result = Object.keys(properties).map((field) => {
const esFieldType = (properties[field].esType)
? properties[field].esType : properties[field].type;
const gqlType = getGQLType(esInstance, esIndex, field, esFieldType);
const gqlType = getGQLType(esInstance, esIndex, field, esFieldType, nestedFieldKeys);

return {
field, type: gqlType, esType: esFieldType, properties: properties[field].properties,
Expand Down Expand Up @@ -109,7 +113,7 @@ const getTypeSchemaForOneIndex = (esInstance, esIndex, esType) => {
const esFieldType = fieldESTypeMap[fieldKey].type;
if (esFieldType === 'nested' && !existingFields.has(fieldKey)) {
const { properties } = fieldESTypeMap[fieldKey];
queueTypes.push({ type: `${fieldKey}`, properties });
queueTypes.push({ type: `${fieldKey}`, properties, nestedFieldKeys: [fieldKey] });
existingFields.add(fieldKey);
}
});
Expand All @@ -123,10 +127,10 @@ const getTypeSchemaForOneIndex = (esInstance, esIndex, esType) => {

while (queueTypes.length > 0) {
const t = queueTypes.shift();
const gqlTypes = getFieldGQLTypeMapForProperties(esInstance, esIndex, t.properties);
const gqlTypes = getFieldGQLTypeMapForProperties(esInstance, esIndex, t.properties, t.nestedFieldKeys);
gqlTypes.forEach((entry) => {
if (entry.esType === 'nested' && !existingFields.has(entry.field)) {
queueTypes.push({ type: `${entry.field}`, properties: entry.properties });
queueTypes.push({ type: `${entry.field}`, properties: entry.properties, nestedFieldKeys: [...t.nestedFieldKeys, entry.field] });
existingFields.add(entry.field);
fieldToArgs[entry.field] = getArgsByField(entry.field, entry.properties);
}
Expand Down
Loading