|
213 | 213 |
|
214 | 214 | <sql id="getClinicalDataCountsQuery"> |
215 | 215 | ( |
216 | | - WITH clinical_data_query AS ( |
| 216 | + WITH ( |
| 217 | + SELECT |
| 218 | + groupArray(sample_unique_id) |
| 219 | + FROM ( |
| 220 | + <include refid="org.cbioportal.infrastructure.repository.clickhouse.studyview.ClickhouseStudyViewFilterMapper.sampleUniqueIdsFromStudyViewFilter"/> |
| 221 | + ) |
| 222 | + ) AS filteredSamplesArray, ( |
| 223 | + SELECT |
| 224 | + groupArray(patient_unique_id) |
| 225 | + FROM |
| 226 | + sample_derived |
| 227 | + WHERE |
| 228 | + has(filteredSamplesArray, sample_unique_id) |
| 229 | + ) AS filteredPatientsArray, |
| 230 | + length(arrayDistinct(filteredSamplesArray)) AS filteredSampleCount, |
| 231 | + length(arrayDistinct(filteredPatientsArray)) AS filteredPatientCount, |
| 232 | + clinical_data_query AS ( |
217 | 233 | SELECT |
218 | 234 | attribute_name AS attributeId, |
219 | 235 | attribute_value AS value, |
|
238 | 254 | AND |
239 | 255 | <choose> |
240 | 256 | <when test="'${type}' == 'sample'"> |
241 | | - <include refid="org.cbioportal.infrastructure.repository.clickhouse.studyview.ClickhouseStudyViewFilterMapper.applyStudyViewFilterUsingSampleId"/> |
| 257 | + has(filteredSamplesArray, sample_unique_id) |
242 | 258 | </when> |
243 | 259 | <otherwise> |
244 | | - <include refid="org.cbioportal.infrastructure.repository.clickhouse.studyview.ClickhouseStudyViewFilterMapper.applyStudyViewFilterUsingPatientId"/> |
| 260 | + has(filteredPatientsArray, patient_unique_id) |
245 | 261 | </otherwise> |
246 | 262 | </choose> |
247 | 263 | AND attribute_name IN |
|
256 | 272 | UNION ALL |
257 | 273 | SELECT attributeId, |
258 | 274 | 'NA' AS value, |
259 | | - (( |
| 275 | + ( |
260 | 276 | <choose> |
261 | 277 | <when test="'${type}' == 'sample' or '${isConflicting}' == 'true'"> |
262 | 278 | <!-- Use sample count for: |
263 | 279 | 1. Pure sample attributes (type='sample') |
264 | 280 | 2. Conflicting attributes (already mapped to sample-level via JOIN) --> |
265 | | - <include refid="org.cbioportal.infrastructure.repository.clickhouse.sample.ClickhouseSampleMapper.getFilteredSampleCount"/> |
| 281 | + filteredSampleCount |
266 | 282 | </when> |
267 | 283 | <otherwise> |
268 | | - <include refid="org.cbioportal.infrastructure.repository.clickhouse.patient.ClickhousePatientMapper.getFilteredPatientCount"/> |
| 284 | + filteredPatientCount |
269 | 285 | </otherwise> |
270 | 286 | </choose> |
271 | | - ) - clinical_data_sum.sum) AS count |
| 287 | + - clinical_data_sum.sum) AS count |
272 | 288 | FROM clinical_data_sum |
273 | 289 | <where> |
274 | 290 | count > 0 |
|
0 commit comments