Skip to content

Commit 1ce3cf8

Browse files
authored
Fix legacy core tests after changes to legacy mapper for clickhouse-only (#11784)
1 parent 2ed64fb commit 1ce3cf8

File tree

57 files changed

+2171
-362
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2171
-362
lines changed

src/main/java/org/cbioportal/legacy/persistence/mybatis/ClinicalEventMapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ List<ClinicalEvent> getSamplesOfPatientsPerEventType(
3434
List<String> studyIds, List<String> sampleIds);
3535

3636
List<ClinicalEvent> getPatientsDistinctClinicalEventInStudies(
37-
List<String> studyIds, List<String> patientIds);
37+
List<String> studyIds, List<String> patientIds, List<ClinicalEvent> clinicalEvents);
3838

3939
List<ClinicalEvent> getTimelineEvents(
4040
List<String> studyIds, List<String> patientIds, List<ClinicalEvent> clinicalEvents);

src/main/java/org/cbioportal/legacy/persistence/mybatis/ClinicalEventMyBatisRepository.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static java.util.stream.Collectors.groupingBy;
44

5+
import java.util.Collections;
56
import java.util.List;
67
import java.util.Map;
78
import java.util.Set;
@@ -86,7 +87,8 @@ public Map<String, Set<String>> getSamplesOfPatientsPerEventTypeInStudy(
8687
@Override
8788
public List<ClinicalEvent> getPatientsDistinctClinicalEventInStudies(
8889
List<String> studyIds, List<String> patientIds) {
89-
return clinicalEventMapper.getPatientsDistinctClinicalEventInStudies(studyIds, patientIds);
90+
return clinicalEventMapper.getPatientsDistinctClinicalEventInStudies(
91+
studyIds, patientIds, Collections.emptyList());
9092
}
9193

9294
@Override

src/main/java/org/cbioportal/legacy/persistence/mybatis/GenesetMyBatisRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public List<Geneset> getAllGenesets(String projection, Integer pageSize, Integer
2222
projection,
2323
pageSize,
2424
PaginationCalculator.offset(pageSize, pageNumber),
25-
"EXTERNAL_ID",
25+
"external_id",
2626
"ASC");
2727
}
2828

src/main/resources/org/cbioportal/legacy/persistence/mybatis/AlterationCountsMapper.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@
180180
SELECT
181181
gene1.entrez_gene_id AS gene1EntrezGeneId,
182182
<!-- TODO: check this-->
183-
gene1.hugo_gene_symbol AS gene1HugoGeneSymbol,
183+
ANY_VALUE(gene1.hugo_gene_symbol) AS gene1HugoGeneSymbol,
184184
gene2.entrez_gene_id AS gene2EntrezGeneId,
185-
gene2.hugo_gene_symbol AS gene2HugoGeneSymbol,
185+
ANY_VALUE(gene2.hugo_gene_symbol) AS gene2HugoGeneSymbol,
186186
COUNT(*) AS totalCount,
187187
COUNT(DISTINCT(patient.internal_id)) AS numberOfAlteredCases
188188
FROM

src/main/resources/org/cbioportal/legacy/persistence/mybatis/ClinicalDataMapper.xml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -264,14 +264,7 @@
264264
</if>
265265
<if test=" sortBy != null">
266266
<!-- Put 'NULL samples' last: -->
267-
<choose>
268-
<when test="_databaseId == 'mysql'">
269-
ORDER BY ISNULL(sort_by), sort_by ${direction}
270-
</when>
271-
<when test="_databaseId == 'h2'">
272-
ORDER BY sort_by ${direction} NULLS LAST
273-
</when>
274-
</choose>
267+
ORDER BY sort_by ${direction} NULLS LAST
275268
</if>
276269

277270
<if test="_parameter.containsKey('limit') and limit != null and limit != 0">
@@ -309,14 +302,7 @@
309302
ORDER BY patient.stable_id ${direction}
310303
</when>
311304
<when test="sortByAttribute">
312-
<choose>
313-
<when test="_databaseId == 'mysql'">
314-
ORDER BY ISNULL(sortData.sortAttrValue), sortData.sortAttrValue ${direction}
315-
</when>
316-
<when test="_databaseId == 'h2'">
317-
ORDER BY sortData.sortAttrValue ${direction} NULLS LAST
318-
</when>
319-
</choose>
305+
ORDER BY sortData.sortAttrValue ${direction} NULLS LAST
320306
</when>
321307
<otherwise></otherwise>
322308
</choose>
@@ -348,7 +334,7 @@
348334
<when test="sortIsPatientAttr">
349335
SELECT sample.internal_id sampleInternalId, sample.stable_id sampleId, patient.stable_id patientId, clinical_patient.attr_id sortAttrId,
350336
<choose>
351-
<when test="sortAttrIsNumber">CONVERT(clinical_patient.attr_value, DECIMAL) sortAttrValue
337+
<when test="sortAttrIsNumber">toFloat64OrNull(clinical_patient.attr_value) sortAttrValue
352338
</when>
353339
<otherwise>
354340
clinical_patient.attr_value sortAttrValue
@@ -363,7 +349,7 @@
363349
SELECT sample.internal_id sampleInternalId, sample.stable_id sampleId, patient.stable_id patientId, clinical_sample.attr_id sortAttrId,
364350
<choose>
365351
<when test="sortAttrIsNumber">
366-
CONVERT(clinical_sample.attr_value, DECIMAL) sortAttrValue
352+
toFloat64OrNull(clinical_sample.attr_value) sortAttrValue
367353
</when>
368354
<otherwise>
369355
clinical_sample.attr_value sortAttrValue

src/main/resources/org/cbioportal/legacy/persistence/mybatis/ClinicalEventMapper.xml

Lines changed: 109 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,16 +129,9 @@
129129

130130
<select id="getPatientsDistinctClinicalEventInStudies" resultType="org.cbioportal.legacy.model.ClinicalEvent">
131131
SELECT
132-
<choose>
133-
<when test="_databaseId == 'mysql'">
134-
ANY_VALUE(clinical_event.clinical_event_id) AS clinicalEventId,
135-
</when>
136-
<when test="_databaseId == 'h2'">
137-
clinical_event.clinical_event_id AS clinicalEventId,
138-
</when>
139-
</choose>
140-
clinical_event.event_type AS eventType,
141-
patient.stable_id AS patientId
132+
ANY_VALUE(clinical_event.clinical_event_id) AS clinicalEventId,
133+
clinical_event.event_type AS eventType,
134+
patient.stable_id AS patientId
142135
<include refid="from"/>
143136
<where>
144137
<if test="patientIds == null and studyIds != null">
@@ -179,4 +172,110 @@
179172
GROUP BY clinical_event.event_type, patient.stable_id
180173
</select>
181174

175+
<select id="getTimelineEvents" resultType="org.cbioportal.legacy.model.ClinicalEvent">
176+
SELECT
177+
ANY_VALUE(patient.stable_id) AS patientId,
178+
cancer_study.cancer_study_identifier AS studyId,
179+
MIN(clinical_event.start_date) AS startDate,
180+
GREATEST(MAX(clinical_event.start_date), COALESCE(MAX(clinical_event.stop_date),0)) AS stopDate
181+
FROM clinical_event
182+
INNER JOIN patient ON clinical_event.patient_id = patient.internal_id
183+
INNER JOIN clinical_event_data ON clinical_event.clinical_event_id = clinical_event_data.clinical_event_id
184+
INNER JOIN cancer_study ON patient.cancer_study_id = cancer_study.cancer_study_id
185+
<where>
186+
<if test="patientIds == null and studyIds != null">
187+
cancer_study.cancer_study_identifier IN
188+
<if test="studyIds.isEmpty()">(NULL)</if>
189+
<if test="!studyIds.isEmpty()"><foreach item="item" collection="studyIds" open="(" separator="," close=")">#{item}</foreach></if>
190+
</if>
191+
<if test="patientIds != null">
192+
<if test="@java.util.Arrays@stream(patientIds.toArray()).distinct().count() == 1">
193+
<bind name="patientArray" value="@org.cbioportal.legacy.persistence.mybatis.util.SqlUtils@listToArray(patientIds)" />
194+
cancer_study.cancer_study_identifier = #{studyIds[0]} AND
195+
patient.stable_id IN (
196+
#{patientArray, typeHandler=org.apache.ibatis.type.ArrayTypeHandler}
197+
)
198+
</if>
199+
<if test="@java.util.Arrays@stream(patientIds.toArray()).distinct().count() > 1">
200+
<bind name="patientUniqueKeys" value="@org.cbioportal.legacy.persistence.mybatis.util.SqlUtils@combineStudyAndPatientIds(studyIds, patientIds)" />
201+
CONCAT(cancer_study.cancer_study_identifier, ':', patient.stable_id) IN (
202+
#{patientUniqueKeys, typeHandler=org.apache.ibatis.type.ArrayTypeHandler}
203+
)
204+
</if>
205+
</if>
206+
<if test="!clinicalEvents.isEmpty()">
207+
AND
208+
<foreach item="element" collection="clinicalEvents" open="(" separator="OR " close=")">
209+
<if test="element.attributes == null || element.attributes.isEmpty()">
210+
clinical_event.event_type = #{element.eventType}
211+
</if>
212+
<if test="element.attributes != null and !element.attributes.isEmpty()">
213+
(CONCAT(clinical_event.event_type, '_', clinical_event_data.key, '_', clinical_event_data.value)) IN
214+
<foreach item="attribute" collection="element.attributes" open="(" separator="," close=")">
215+
CONCAT(#{element.eventType}, '_', #{attribute.key}, '_', #{attribute.value})
216+
</foreach>
217+
</if>
218+
</foreach>
219+
</if>
220+
</where>
221+
GROUP BY
222+
clinical_event.patient_id, cancer_study.cancer_study_identifier;
223+
</select>
224+
225+
<resultMap id="clinicalEventsResultMap" type="org.cbioportal.legacy.model.ClinicalEvent">
226+
<result property="eventType" column="eventType"/>
227+
<collection property="attributes" ofType="org.cbioportal.legacy.model.ClinicalEventData">
228+
<result property="key" column="key"/>
229+
<result property="value" column="value"/>
230+
</collection>
231+
</resultMap>
232+
233+
<select id="getClinicalEventsMeta" resultMap="clinicalEventsResultMap">
234+
SELECT
235+
LOWER(clinical_event.event_type) AS eventType,
236+
LOWER(clinical_event_data.key) AS "key",
237+
LOWER(clinical_event_data.value) AS value
238+
FROM clinical_event
239+
INNER JOIN patient ON clinical_event.patient_id = patient.internal_id
240+
INNER JOIN clinical_event_data ON clinical_event.clinical_event_id = clinical_event_data.clinical_event_id
241+
INNER JOIN cancer_study ON patient.cancer_study_id = cancer_study.cancer_study_id
242+
<where>
243+
<if test="patientIds == null and studyIds != null">
244+
cancer_study.cancer_study_identifier IN
245+
<if test="studyIds.isEmpty()">(NULL)</if>
246+
<if test="!studyIds.isEmpty()"><foreach item="item" collection="studyIds" open="(" separator="," close=")">#{item}</foreach></if>
247+
</if>
248+
<if test="patientIds != null">
249+
<if test="@java.util.Arrays@stream(patientIds.toArray()).distinct().count() == 1">
250+
<bind name="patientArray" value="@org.cbioportal.legacy.persistence.mybatis.util.SqlUtils@listToArray(patientIds)" />
251+
cancer_study.cancer_study_identifier = #{studyIds[0]} AND
252+
patient.stable_id IN (
253+
#{patientArray, typeHandler=org.apache.ibatis.type.ArrayTypeHandler}
254+
)
255+
</if>
256+
<if test="@java.util.Arrays@stream(patientIds.toArray()).distinct().count() > 1">
257+
<bind name="patientUniqueKeys" value="@org.cbioportal.legacy.persistence.mybatis.util.SqlUtils@combineStudyAndPatientIds(studyIds, patientIds)" />
258+
CONCAT(cancer_study.cancer_study_identifier, ':', patient.stable_id) IN (
259+
#{patientUniqueKeys, typeHandler=org.apache.ibatis.type.ArrayTypeHandler}
260+
)
261+
</if>
262+
</if>
263+
<if test="!clinicalEvents.isEmpty()">
264+
AND
265+
<foreach item="element" collection="clinicalEvents" open="(" separator="OR " close=")">
266+
<if test="element.attributes == null || element.attributes.isEmpty()">
267+
clinical_event.event_type = #{element.eventType}
268+
</if>
269+
<if test="element.attributes != null and !element.attributes.isEmpty()">
270+
(CONCAT(clinical_event.event_type, '_', clinical_event_data.key)) IN
271+
<foreach item="attribute" collection="element.attributes" open="(" separator="," close=")">
272+
CONCAT(#{element.eventType}, '_', #{attribute.key})
273+
</foreach>
274+
</if>
275+
</foreach>
276+
</if>
277+
</where>
278+
GROUP BY clinical_event.event_type , clinical_event_data.key, clinical_event_data.value;
279+
</select>
280+
182281
</mapper>

src/main/resources/org/cbioportal/legacy/persistence/mybatis/CopyNumberSegmentMapper.xml

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,16 @@
3535
</sql>
3636

3737
<select id="getSamplesWithCopyNumberSegments" resultType="Integer">
38-
SELECT sample.internal_id
38+
SELECT
39+
DISTINCT sample.internal_id
3940
FROM sample
4041
INNER JOIN patient ON sample.patient_id = patient.internal_id
4142
INNER JOIN cancer_study ON patient.cancer_study_id = cancer_study.cancer_study_id
43+
INNER JOIN copy_number_seg ON copy_number_seg.sample_id = sample.internal_id
4244
<include refid="where"/>
43-
AND EXISTS (
44-
SELECT * from copy_number_seg INNER JOIN sample ON sample.internal_id = copy_number_seg.sample_id
45-
<if test="chromosome != null and !chromosome.isEmpty()">
46-
<where>
47-
copy_number_seg.chr = #{chromosome}
48-
</where>
49-
</if>
50-
)
45+
<if test="chromosome != null and !chromosome.isEmpty()">
46+
AND copy_number_seg.chr = #{chromosome}
47+
</if>
5148
</select>
5249

5350

@@ -84,16 +81,14 @@
8481
SELECT
8582
<include refid="select"/>
8683
<include refid="from"/>
87-
WHERE cancer_study.cancer_study_identifier = #{studyId}
84+
INNER JOIN sample_list_list ON copy_number_seg.sample_id = sample_list_list.sample_id
85+
INNER JOIN sample_list ON sample_list_list.list_id = sample_list.list_id
86+
WHERE
87+
cancer_study.cancer_study_identifier = #{studyId}
88+
AND
89+
sample_list.stable_id = #{sampleListId}
8890
<if test="chromosome != null and !chromosome.isEmpty()">
8991
AND copy_number_seg.chr = #{chromosome}
9092
</if>
91-
AND copy_number_seg.sample_id IN
92-
(
93-
SELECT sample_list_list.sample_id FROM sample_list_list
94-
INNER JOIN sample_list ON sample_list_list.list_id = sample_list.list_id
95-
WHERE sample_list.stable_id = #{sampleListId}
96-
AND sample_list_list.sample_id = copy_number_seg.sample_id
97-
)
9893
</select>
9994
</mapper>

src/main/resources/org/cbioportal/legacy/persistence/mybatis/PatientMapper.xml

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@
33

44
<mapper namespace="org.cbioportal.legacy.persistence.mybatis.PatientMapper">
55

6+
<!-- TODO: we should eventually get rid of the ${prefix} and the quotes if possible -->
67
<sql id="select">
78
patient.internal_id AS "${prefix}internalId",
89
patient.stable_id AS "${prefix}stableId",
910
patient.cancer_study_id AS "${prefix}cancerStudyId",
1011
cancer_study.cancer_study_identifier AS "${prefix}cancerStudyIdentifier"
1112
<if test="projection == 'DETAILED'">
1213
,
13-
cancer_study.cancer_study_id AS "cancerStudy.cancerStudyId",
14-
cancer_study.cancer_study_identifier AS "cancerStudy.cancerStudyIdentifier",
15-
cancer_study.type_of_cancer_id AS "cancerStudy.typeOfCancerId",
16-
cancer_study.name AS "cancerStudy.name",
17-
cancer_study.description AS "cancerStudy.description",
18-
cancer_study.public AS "cancerStudy.publicStudy",
19-
cancer_study.pmid AS "cancerStudy.pmid",
20-
cancer_study.citation AS "cancerStudy.citation",
21-
cancer_study.groups AS "cancerStudy.groups",
22-
cancer_study.status AS "cancerStudy.status",
23-
cancer_study.import_date AS "cancerStudy.importDate",
24-
reference_genome.name AS "cancerStudy.referenceGenome"
14+
cancer_study.cancer_study_id AS "${prefix}cancerStudy.cancerStudyId",
15+
cancer_study.cancer_study_identifier AS "${prefix}cancerStudy.cancerStudyIdentifier",
16+
cancer_study.type_of_cancer_id AS "${prefix}cancerStudy.typeOfCancerId",
17+
cancer_study.name AS "${prefix}cancerStudy.name",
18+
cancer_study.description AS "${prefix}cancerStudy.description",
19+
cancer_study.public AS "${prefix}cancerStudy.publicStudy",
20+
cancer_study.pmid AS "${prefix}cancerStudy.pmid",
21+
cancer_study.citation AS "${prefix}cancerStudy.citation",
22+
cancer_study.groups AS "${prefix}cancerStudy.groups",
23+
cancer_study.status AS "${prefix}cancerStudy.status",
24+
cancer_study.import_date AS "${prefix}cancerStudy.importDate",
25+
reference_genome.name AS "${prefix}cancerStudy.referenceGenome"
2526
</if>
2627
</sql>
2728

src/main/resources/org/cbioportal/legacy/persistence/mybatis/ResourceDataMapper.xml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
<sql id="selectSampleResource">
77
sample.stable_id AS "${prefix}sampleId",
88
patient.stable_id AS "${prefix}patientId",
9-
resource_patient.resource_id AS "${prefix}resourceId",
9+
resource_sample.resource_id AS "${prefix}resourceId",
1010
cancer_study.cancer_study_identifier AS "${prefix}studyId"
1111
<if test="projection == 'SUMMARY' || projection == 'DETAILED'">
12-
, resource_patient.url AS "${prefix}url"
12+
, resource_sample.url AS "${prefix}url"
1313
</if>
1414
<if test="projection == 'DETAILED'">
1515
,
@@ -49,8 +49,8 @@
4949
</sql>
5050

5151
<sql id="fromSample">
52-
FROM resource_patient
53-
INNER JOIN sample ON resource_patient.internal_id = sample.internal_id
52+
FROM resource_sample
53+
INNER JOIN sample ON resource_sample.internal_id = sample.internal_id
5454
INNER JOIN patient ON sample.patient_id = patient.internal_id
5555
INNER JOIN cancer_study ON patient.cancer_study_id = cancer_study.cancer_study_id
5656
</sql>
@@ -76,7 +76,7 @@
7676
sample.stable_id = #{sampleId}
7777
</if>
7878
<if test="resourceId != null">
79-
AND resource_patient.resource_id = #{resourceId}
79+
AND resource_sample.resource_id = #{resourceId}
8080
</if>
8181
</where>
8282
</sql>
@@ -112,15 +112,15 @@
112112
</include>
113113
<include refid="fromSample"/>
114114
<if test="projection == 'DETAILED'">
115-
INNER JOIN resource_definition ON resource_patient.resource_id = resource_definition.resource_id
115+
INNER JOIN resource_definition ON resource_sample.resource_id = resource_definition.resource_id
116116
AND cancer_study.cancer_study_id = resource_definition.cancer_study_id
117117
</if>
118118
<include refid="whereSample"/>
119119
<if test="sortBy != null and projection != 'ID'">
120120
ORDER BY "${sortBy}" ${direction}
121121
</if>
122122
<if test="projection == 'ID'">
123-
ORDER BY resource_patient.resource_id ASC
123+
ORDER BY resource_sample.resource_id ASC
124124
</if>
125125
<if test="limit != null and limit != 0">
126126
LIMIT #{limit} OFFSET #{offset}

src/main/resources/org/cbioportal/legacy/persistence/mybatis/SampleListMapper.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
</if>
1717
<if test="projection == 'DETAILED'">
1818
,
19+
cancer_study.cancer_study_id AS "cancerStudy.cancerStudyId",
20+
cancer_study.cancer_study_identifier AS "cancerStudy.cancerStudyIdentifier",
1921
cancer_study.type_of_cancer_id AS "cancerStudy.typeOfCancerId",
2022
cancer_study.name AS "cancerStudy.name",
2123
cancer_study.description AS "cancerStudy.description",

0 commit comments

Comments
 (0)