Skip to content

Commit

Permalink
SQL variable format clean up (#11110)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuzhaoyuan authored Oct 24, 2024
1 parent b2ce990 commit 9a5f9e3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
LEFT JOIN sample_list sl on sll.list_id=sl.list_id
WHERE
<foreach item="list" collection="listGroup" separator="OR">
sl.stable_id LIKE '%_${list}'
sl.stable_id LIKE concat('%_', #{list})
</foreach>
</foreach>
)
Expand All @@ -49,7 +49,7 @@
</foreach>
AND
<foreach item="genomicProfileId" collection="ANDGroup" open="(" separator="OR" close=")">
gp.stable_id LIKE '%_${genomicProfileId}'
gp.stable_id LIKE concat('%_', #{genomicProfileId})
</foreach>
</where>
</foreach>
Expand All @@ -63,7 +63,7 @@
FROM sample_derived
WHERE sample_unique_id IN
<foreach item="sampleIdentifier" collection="studyViewFilterHelper.studyViewFilter.sampleIdentifiers" open="(" separator="," close=")">
'${sampleIdentifier.studyId}_${sampleIdentifier.sampleId}'
concat(#{sampleIdentifier.studyId}, '_', #{sampleIdentifier.sampleId})
</foreach>
</if>
<if test="studyViewFilterHelper.studyViewFilter.customDataFilters != null and !studyViewFilterHelper.studyViewFilter.customDataFilters.isEmpty() and studyViewFilterHelper.customDataSamples != null">
Expand All @@ -83,7 +83,7 @@
'',
<foreach item="sampleIdentifier" collection="studyViewFilterHelper.customDataSamples" separator=",">
<if test="!sampleIdentifier.getIsFilteredOut()">
'${sampleIdentifier.studyId}_${sampleIdentifier.sampleId}'
concat(#{sampleIdentifier.studyId}, '_', #{sampleIdentifier.sampleId})
</if>
</foreach>
)
Expand All @@ -94,7 +94,7 @@
OR
sample_unique_id NOT IN (
<foreach item="sampleIdentifier" collection="studyViewFilterHelper.customDataSamples" separator=",">
'${sampleIdentifier.studyId}_${sampleIdentifier.sampleId}'
concat(#{sampleIdentifier.studyId}, '_', #{sampleIdentifier.sampleId})
</foreach>
)
</if>
Expand Down Expand Up @@ -218,7 +218,7 @@
) ced_inner ON ced_inner.patient_unique_id = ced.patient_unique_id
<where>
<foreach item="sampleTreatmentFilter" collection="andedSampleTreatmentFilters.getFilters()" open="AND ((" separator=") OR (" close="))">
ced_inner.treatment = '${sampleTreatmentFilter.treatment}'
ced_inner.treatment = #{sampleTreatmentFilter.treatment}
<choose>
<when test="sampleTreatmentFilter.time.name() == 'Pre'">
AND ced.time_taken &lt;= ced_inner.treatment_time_taken
Expand All @@ -232,6 +232,7 @@
GROUP BY patient_unique_id, ced.sample_id, ced.time_taken, ced.cancer_study_identifier, ced_inner.treatment, ced_inner.treatment_time_taken
</foreach>
</sql>

<sql id="applyClinicalEventTypeFilter">
<foreach item="clinicalEventFilter" collection="studyViewFilterHelper.studyViewFilter.getClinicalEventFilters()" open="INTERSECT"
separator="INTERSECT">
Expand All @@ -241,8 +242,8 @@
SELECT patient_unique_id
FROM clinical_event_derived
<where>
<foreach item="dataFilterValue" collection="clinicalEventFilter.values" open="(" separator=") OR ("
close=")"> event_type = '${dataFilterValue.value}'
<foreach item="dataFilterValue" collection="clinicalEventFilter.values" open="(" separator=") OR (" close=")">
event_type = #{dataFilterValue.value}
</foreach>
</where>
)
Expand All @@ -262,7 +263,7 @@
separator=") OR ("
close=")"> lower(event_type) = 'treatment'
AND key = 'AGENT'
AND value = '${patientTreatmentFilter.treatment}'
AND value = #{patientTreatmentFilter.treatment}
</foreach>
</where>
)
Expand Down Expand Up @@ -361,7 +362,7 @@
<if test="userSelectsNumericalValue">
SELECT ${unique_id}
FROM ${table_name}
WHERE attribute_name = '${clinicalDataFilter.attributeId}' AND
WHERE attribute_name = #{clinicalDataFilter.attributeId} AND
type='${type}'
<foreach item="dataFilterValue" collection="clinicalDataFilter.values" open=" AND ((" separator=") OR (" close="))">
<trim prefix="" prefixOverrides="AND">
Expand All @@ -388,7 +389,7 @@
<include refid="castStringValueToFloat">
<property name="attribute_value" value="attribute_value"/>
</include>,
cast(${dataFilterValue.start} as float)
cast(#{dataFilterValue.start} as float)
)
) &lt; exp(-11)
</when>
Expand All @@ -397,13 +398,13 @@
AND
<include refid="castStringValueToFloat">
<property name="attribute_value" value="attribute_value"/>
</include> &gt; cast(${dataFilterValue.start} as float)
</include> &gt; cast(#{dataFilterValue.start} as float)
</if>
<if test="dataFilterValue.end != null">
AND
<include refid="castStringValueToFloat">
<property name="attribute_value" value="attribute_value"/>
</include> &lt;= cast(${dataFilterValue.end} as float)
</include> &lt;= cast(#{dataFilterValue.end} as float)
</if>
</otherwise>
</choose>
Expand All @@ -417,11 +418,10 @@
<sql id="selectAllClinicalDataByAttribute">
SELECT sample_unique_id, patient_unique_id, attribute_value
FROM clinical_data_derived
WHERE attribute_name = '${clinicalDataFilter.attributeId}' AND type='${type}'
WHERE attribute_name = #{clinicalDataFilter.attributeId} AND type='${type}'
AND cancer_study_identifier IN
<foreach item="studyId" collection="studyViewFilterHelper.studyViewFilter.studyIds" open="(" separator="," close=")">
#{studyId}

</foreach>
</sql>

Expand Down Expand Up @@ -454,7 +454,7 @@
<include refid="normalizeAttributeValue">
<property name="attribute_value" value="attribute_value"/>
</include>
) ILIKE '${dataFilterValue.value}'
) ILIKE #{dataFilterValue.value}
</otherwise>
</choose>
</foreach>
Expand Down Expand Up @@ -511,7 +511,7 @@
<include refid="castStringValueToFloat">
<property name="attribute_value" value="alteration_value"/>
</include>,
${dataFilterValue.start}
#{dataFilterValue.start}
)
) &lt; exp(-11)
</when>
Expand All @@ -520,13 +520,13 @@
AND
<include refid="castStringValueToFloat">
<property name="attribute_value" value="alteration_value"/>
</include> &gt; ${dataFilterValue.start}
</include> &gt; #{dataFilterValue.start}
</if>
<if test="dataFilterValue.end != null">
AND
<include refid="castStringValueToFloat">
<property name="attribute_value" value="alteration_value"/>
</include> &lt;= ${dataFilterValue.end}
</include> &lt;= #{dataFilterValue.end}
</if>
</otherwise>
</choose>
Expand Down Expand Up @@ -619,7 +619,7 @@
<include refid="castStringValueToFloat">
<property name="attribute_value" value="value"/>
</include>,
${dataFilterValue.start}
#{dataFilterValue.start}
)
) &lt; exp(-11)
</when>
Expand All @@ -628,13 +628,13 @@
AND
<include refid="castStringValueToFloat">
<property name="attribute_value" value="value"/>
</include> &gt; ${dataFilterValue.start}
</include> &gt; #{dataFilterValue.start}
</if>
<if test="dataFilterValue.end != null">
AND
<include refid="castStringValueToFloat">
<property name="attribute_value" value="value"/>
</include> &lt;= ${dataFilterValue.end}
</include> &lt;= #{dataFilterValue.end}
</if>
</otherwise>
</choose>
Expand Down Expand Up @@ -664,7 +664,7 @@
<include refid="normalizeAttributeValue">
<property name="attribute_value" value="value"/>
</include>
) ILIKE '${dataFilterValue.value}'
) ILIKE #{dataFilterValue.value}
</otherwise>
</choose>
</foreach>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<property name="filter_type" value="'SAMPLE_ID_ONLY'"/>
</include>
</where>
ORDER BY sample_stable_id ASC;
ORDER BY sample_stable_id ASC
</select>

<select id="getFilteredStudyIds" resultType="string">
Expand Down Expand Up @@ -48,7 +48,7 @@
<include refid="mutationAlterationFilter"/>
</if>
</where>
GROUP BY entrez_gene_id, hugo_gene_symbol;
GROUP BY entrez_gene_id, hugo_gene_symbol
</select>

<!-- /cna-genes/fetch (returns CopyNumberCountByGene) -->
Expand All @@ -70,7 +70,7 @@
<include refid="cnaAlterationFilter"/>
</if>
</where>
GROUP BY entrez_gene_id, hugo_gene_symbol, alteration, cytoband;
GROUP BY entrez_gene_id, hugo_gene_symbol, alteration, cytoband
</select>

<select id="getStructuralVariantGenes" resultType="org.cbioportal.model.AlterationCountByGene">
Expand All @@ -86,7 +86,7 @@
<property name="filter_type" value="'SAMPLE_ID_ONLY'"/>
</include>
</where>
GROUP BY entrez_gene_id, hugo_gene_symbol;
GROUP BY entrez_gene_id, hugo_gene_symbol
</select>

<select id="getSampleClinicalDataFromStudyViewFilter" resultType="org.cbioportal.model.ClinicalData">
Expand Down Expand Up @@ -173,7 +173,7 @@
</include>
</where>
AND label IS NOT NULL
GROUP BY s.cancer_study_identifier, sl.stable_id, sl.name;
GROUP BY s.cancer_study_identifier, sl.stable_id, sl.name
</select>


Expand Down Expand Up @@ -439,21 +439,21 @@
FROM sample_to_gene_panel_derived stgp
INNER JOIN gene_panel_to_gene_derived gptg on stgp.gene_panel_id = gptg.gene_panel_id
<where>
stgp.alteration_type = '${alterationType}'
stgp.alteration_type = #{alterationType}
AND stgp.gene_panel_id != 'WES'
AND
<include refid="applyStudyViewFilter">
<property name="filter_type" value="'SAMPLE_ID_ONLY'"/>
</include>
</where>
GROUP BY gptg.gene;
GROUP BY gptg.gene
</select>

<select id="getSampleProfileCountWithoutPanelData" resultType="int">
SELECT COUNT(*)
FROM sample_to_gene_panel_derived
<where>
alteration_type = '${alterationType}' AND gene_panel_id = 'WES'
alteration_type = #{alterationType} AND gene_panel_id = 'WES'
AND
<include refid="applyStudyViewFilter">
<property name="filter_type" value="'SAMPLE_ID_ONLY'"/>
Expand All @@ -468,7 +468,7 @@
COUNT(DISTINCT sample_unique_id)
FROM sample_to_gene_panel_derived stgp
<where>
stgp.alteration_type = '${alterationType}'
stgp.alteration_type = #{alterationType}
AND
<include refid="applyStudyViewFilter">
<property name="filter_type" value="'SAMPLE_ID_ONLY'"/>
Expand Down Expand Up @@ -496,15 +496,15 @@
select distinct gene_panel_id
from sample_to_gene_panel_derived
<where>
alteration_type = '${alterationType}'
alteration_type = #{alterationType}
AND
<include refid="applyStudyViewFilter">
<property name="filter_type" value="'SAMPLE_ID_ONLY'"/>
</include>
</where>
)
</where>
GROUP BY gene, gene_panel_id;
GROUP BY gene, gene_panel_id
</select>

<select id="getClinicalEventTypeCounts" resultType="org.cbioportal.model.ClinicalEventTypeCount">
Expand All @@ -517,7 +517,7 @@
<property name="filter_type" value="'PATIENT_ID_ONLY'"/>
</include>
</where>
GROUP BY event_type;
GROUP BY event_type
</select>

<select id="getPatientTreatmentCounts" resultType="int">
Expand Down Expand Up @@ -560,7 +560,7 @@
<property name="filter_type" value="'PATIENT_ID_ONLY'"/>
</include>
</where>
GROUP BY value;
GROUP BY value
</select>

<select id="getTotalSampleTreatmentCounts" resultType="int">
Expand Down Expand Up @@ -636,7 +636,7 @@
<where>
concat(ced.cancer_study_identifier, '_', ced.sample_id) IN ( <include refid="sampleUniqueIdsFromStudyViewFilter"/>)
</where>
GROUP BY treatments.treatment;
GROUP BY treatments.treatment
</select>

<select id="getGenomicDataBinCounts" resultType="org.cbioportal.model.ClinicalDataCount">
Expand Down

0 comments on commit 9a5f9e3

Please sign in to comment.