From af84d12e32041b52934f13ab2e925347246c8139 Mon Sep 17 00:00:00 2001 From: Onur Sumer Date: Wed, 11 Dec 2024 14:42:34 -0500 Subject: [PATCH] make sure study ids exist before using them in filter SQL --- .../StudyViewFilterMapper.xml | 68 ++++++++++++------- .../mybatisclickhouse/StudyViewMapper.xml | 13 ++-- 2 files changed, 53 insertions(+), 28 deletions(-) diff --git a/src/main/resources/org/cbioportal/persistence/mybatisclickhouse/StudyViewFilterMapper.xml b/src/main/resources/org/cbioportal/persistence/mybatisclickhouse/StudyViewFilterMapper.xml index 30f3c7557b4..382ecd5a70d 100644 --- a/src/main/resources/org/cbioportal/persistence/mybatisclickhouse/StudyViewFilterMapper.xml +++ b/src/main/resources/org/cbioportal/persistence/mybatisclickhouse/StudyViewFilterMapper.xml @@ -42,18 +42,20 @@ JOIN genetic_profile gp ON sample_profile.genetic_profile_id = gp.genetic_profile_id JOIN cancer_study cs ON gp.cancer_study_id = cs.cancer_study_id JOIN sample_derived on sample_profile.sample_id = sample_derived.internal_id - - sample_derived.cancer_study_identifier IN - - #{studyId} - - AND - - - gp.stable_id=concat(#{studyId}, '_', #{genomicProfileId}) + + + sample_derived.cancer_study_identifier IN + + #{studyId} - - + AND + + + gp.stable_id=concat(#{studyId}, '_', #{genomicProfileId}) + + + + ) @@ -430,10 +432,12 @@ SELECT sample_unique_id, patient_unique_id, attribute_value FROM clinical_data_derived WHERE attribute_name = #{clinicalDataFilter.attributeId} AND type='${type}' - AND cancer_study_identifier IN - - #{studyId} - + + AND cancer_study_identifier IN + + #{studyId} + + @@ -511,10 +515,12 @@ FROM genetic_alteration_derived WHERE profile_type = #{genomicDataFilter.profileType} AND hugo_gene_symbol = #{genomicDataFilter.hugoGeneSymbol} + AND cancer_study_identifier IN #{studyId} + @@ -641,30 +647,40 @@ SELECT sample_unique_id FROM sample_derived WHERE cancer_study_identifier IN + #{studyId} + ), profiled_samples AS ( SELECT DISTINCT sgp.sample_unique_id FROM sample_to_gene_panel_derived sgp JOIN gene_panel_to_gene_derived gpg ON sgp.gene_panel_id = gpg.gene_panel_id - WHERE cancer_study_identifier IN + WHERE + + cancer_study_identifier IN #{studyId} - AND gpg.gene = #{mutationDataFilter.hugoGeneSymbol} - AND sgp.alteration_type = 'MUTATION_EXTENDED' + AND + + gpg.gene = #{mutationDataFilter.hugoGeneSymbol} + AND sgp.alteration_type = 'MUTATION_EXTENDED' ), mutated_samples AS ( SELECT DISTINCT sample_unique_id FROM genomic_event_derived - WHERE cancer_study_identifier IN + WHERE + + cancer_study_identifier IN #{studyId} - AND hugo_gene_symbol = #{mutationDataFilter.hugoGeneSymbol} - AND variant_type = 'mutation' + AND + + hugo_gene_symbol = #{mutationDataFilter.hugoGeneSymbol} + AND variant_type = 'mutation' ) SELECT DISTINCT sample_unique_id FROM @@ -706,20 +722,26 @@ FROM genetic_alteration_derived WHERE profile_type = #{genomicDataFilter.profileType} AND hugo_gene_symbol = #{genomicDataFilter.hugoGeneSymbol} + AND cancer_study_identifier IN #{studyId} + ) SELECT DISTINCT sd.sample_unique_id FROM sample_derived sd LEFT JOIN cna_query ON sd.sample_unique_id = cna_query.sampleUniqueId - WHERE cancer_study_identifier IN + WHERE + + cancer_study_identifier IN #{studyId} - + AND + + alteration_value IS null diff --git a/src/main/resources/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapper.xml b/src/main/resources/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapper.xml index e140fd00b6d..910d3ef9119 100644 --- a/src/main/resources/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapper.xml +++ b/src/main/resources/org/cbioportal/persistence/mybatisclickhouse/StudyViewMapper.xml @@ -346,11 +346,14 @@ ( SELECT count() > 0 FROM genetic_profile - WHERE patient_level = 1 - AND stable_id IN - - concat(#{studyId}, '_', #{profileType}) - + WHERE + patient_level = 1 + + AND stable_id IN + + concat(#{studyId}, '_', #{profileType}) + + ), (SELECT * FROM ()), (SELECT * FROM ())