Skip to content

Commit 3967c49

Browse files
authored
Remove string concatentation from within SQLFragment.append (#110)
1 parent 7221f87 commit 3967c49

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

GenotypeAssays/src/org/labkey/genotypeassays/GeneticsTableCustomizer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private void customizeSummaryByLineage(AbstractTableInfo ti)
144144
ti.addColumn(newCol);
145145

146146
String chr = ti.getSqlDialect().isPostgreSQL() ? "chr" : "char";
147-
SQLFragment sql3 = new SQLFragment("(select ").append(ti.getSqlDialect().getGroupConcat(new SQLFragment("hs.haplotype"), true, true, chr + "(10)")).append(" as expr FROM assayresult." + d.getStorageTableName() + " a JOIN sequenceanalysis.haplotype_sequences hs ON (a.marker = hs.haplotype AND hs.type = 'Lineage' AND hs.present = " + ti.getSqlDialect().getBooleanTRUE() + ") WHERE a.analysisId = " + ExprColumn.STR_TABLE_ALIAS + ".analysis_id AND a.result IS NULL AND hs.name = " + ExprColumn.STR_TABLE_ALIAS + ".lineages)");
147+
SQLFragment sql3 = new SQLFragment("(select ").append(ti.getSqlDialect().getGroupConcat(new SQLFragment("hs.haplotype"), true, true, chr + "(10)")).append(" as expr FROM assayresult.").append(d.getStorageTableName()).append(" a JOIN sequenceanalysis.haplotype_sequences hs ON (a.marker = hs.haplotype AND hs.type = 'Lineage' AND hs.present = ").append(ti.getSqlDialect().getBooleanTRUE()).append(") WHERE a.analysisId = ").append(ExprColumn.STR_TABLE_ALIAS).append(".analysis_id AND a.result IS NULL AND hs.name = ").append(ExprColumn.STR_TABLE_ALIAS).append(".lineages)");
148148
ExprColumn newCol3 = new ExprColumn(ti, "cachedHaplotypes", sql3, JdbcType.VARCHAR, ti.getColumn("analysis_id"), ti.getColumn("lineages"));
149149
newCol3.setLabel("Matching Cached Haplotypes");
150150
ti.addColumn(newCol3);

tcrdb/src/org/labkey/tcrdb/TCRdbTableCustomizer.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,49 +112,49 @@ private void addAssayFieldsToTable(AbstractTableInfo ti, String urlField, String
112112
SQLFragment selectSql = QueryService.get().getSelectSQL(data, Arrays.asList(data.getColumn("analysisId"), data.getColumn("CDR3"), data.getColumn("locus"), data.getColumn("fraction"), data.getColumn("count"), data.getColumn("cDNA")), filter, null, Table.ALL_ROWS, Table.NO_OFFSET, false);
113113
DetailsURL details = DetailsURL.fromString("/query/executeQuery.view?schemaName=assay." + ap.getName().replaceAll(" ", "") + "." + protocols.get(0).getName() + "&query.queryName=data&query." + urlField + "~eq=${" + urlSourceCol + "}", (ti.getUserSchema().getContainer().isWorkbook() ? ti.getUserSchema().getContainer().getParent() : ti.getUserSchema().getContainer()));
114114

115-
SQLFragment sql = new SQLFragment("(select count(*) as expr FROM (").append(selectSql).append(") a " + whereClause + ")");
115+
SQLFragment sql = new SQLFragment("(select count(*) as expr FROM (").append(selectSql).append(") a ").append(whereClause).append(")");
116116
ExprColumn newCol = new ExprColumn(ti, "numTcrResults" + colNameSuffix, sql, JdbcType.INTEGER, ti.getColumn("rowid"));
117117
newCol.setLabel("# TCR Results" + colLabelSuffix);
118118
newCol.setURL(details);
119119
ti.addColumn(newCol);
120120

121-
SQLFragment sql0 = new SQLFragment("(select count(*) as expr FROM (").append(selectSql).append(") a " + whereClause + " AND a.locus = 'TRB')");
121+
SQLFragment sql0 = new SQLFragment("(select count(*) as expr FROM (").append(selectSql).append(") a ").append(whereClause).append(" AND a.locus = 'TRB')");
122122
ExprColumn newCol0 = new ExprColumn(ti, "numTcrTrbResults" + colNameSuffix, sql0, JdbcType.INTEGER, ti.getColumn("rowid"));
123123
newCol0.setLabel("# TCR TRB Results" + colLabelSuffix);
124124
newCol0.setURL(details);
125125
ti.addColumn(newCol0);
126126

127-
SQLFragment sql2 = new SQLFragment("(select count(distinct CDR3) as expr FROM (").append(selectSql).append(") a " + whereClause + ")");
127+
SQLFragment sql2 = new SQLFragment("(select count(distinct CDR3) as expr FROM (").append(selectSql).append(") a ").append(whereClause).append(")");
128128
ExprColumn newCol2 = new ExprColumn(ti, "numCDR3s" + colNameSuffix, sql2, JdbcType.INTEGER, ti.getColumn("rowid"));
129129
newCol2.setLabel("# Distinct CDR3s" + colLabelSuffix);
130130
newCol2.setURL(details);
131131
ti.addColumn(newCol2);
132132

133-
SQLFragment sql3 = new SQLFragment("(select ").append(ti.getSqlDialect().getGroupConcat(new SQLFragment("locus"), true, true)).append(" FROM (").append(selectSql).append(") a " + whereClause + ")");
133+
SQLFragment sql3 = new SQLFragment("(select ").append(ti.getSqlDialect().getGroupConcat(new SQLFragment("locus"), true, true)).append(" FROM (").append(selectSql).append(") a ").append(whereClause).append(")");
134134
ExprColumn newCol3 = new ExprColumn(ti, "distinctLoci" + colNameSuffix, sql3, JdbcType.VARCHAR, ti.getColumn("rowid"));
135135
newCol3.setLabel("Distinct Loci" + colLabelSuffix);
136136
newCol3.setURL(details);
137137
ti.addColumn(newCol3);
138138

139-
SQLFragment sql4 = new SQLFragment("(select ").append(ti.getSqlDialect().getGroupConcat(new SQLFragment("CDR3"), true, true, getChr(ti) + "(10)")).append(" FROM (").append(selectSql).append(") a " + whereClause + " )");
139+
SQLFragment sql4 = new SQLFragment("(select ").append(ti.getSqlDialect().getGroupConcat(new SQLFragment("CDR3"), true, true, getChr(ti) + "(10)")).append(" FROM (").append(selectSql).append(") a ").append(whereClause).append(" )");
140140
ExprColumn newCol4 = new ExprColumn(ti, "distinctCDR3s" + colNameSuffix, sql4, JdbcType.VARCHAR, ti.getColumn("rowid"));
141141
newCol4.setLabel("Distinct CDR3s" + colLabelSuffix);
142142
newCol4.setURL(details);
143143
ti.addColumn(newCol4);
144144

145-
SQLFragment sqlTotal = new SQLFragment("(select sum(count) as expr FROM (").append(selectSql).append(") a " + whereClause + ")");
145+
SQLFragment sqlTotal = new SQLFragment("(select sum(count) as expr FROM (").append(selectSql).append(") a ").append(whereClause).append(")");
146146
ExprColumn newColTotal = new ExprColumn(ti, "numCells" + colNameSuffix, sqlTotal, JdbcType.INTEGER, ti.getColumn("rowid"));
147147
newColTotal.setLabel("# TCR Cells/Reads" + colLabelSuffix);
148148
newColTotal.setURL(details);
149149
ti.addColumn(newColTotal);
150150

151-
SQLFragment sqlTotal2 = new SQLFragment("(select sum(count) as expr FROM (").append(selectSql).append(") a " + whereClause + " AND a.locus = 'TRB')");
151+
SQLFragment sqlTotal2 = new SQLFragment("(select sum(count) as expr FROM (").append(selectSql).append(") a ").append(whereClause).append(" AND a.locus = 'TRB')");
152152
ExprColumn newColTotal2 = new ExprColumn(ti, "numCellsTrb" + colNameSuffix, sqlTotal2, JdbcType.INTEGER, ti.getColumn("rowid"));
153153
newColTotal2.setLabel("# TCR Cells/Reads - TRB " + colLabelSuffix);
154154
newColTotal2.setURL(details);
155155
ti.addColumn(newColTotal2);
156156

157-
SQLFragment sql6 = new SQLFragment("(select sum(a.count) as expr FROM (").append(selectSql).append(") a " + whereClause + " )");
157+
SQLFragment sql6 = new SQLFragment("(select sum(a.count) as expr FROM (").append(selectSql).append(") a ").append(whereClause).append(" )");
158158
ExprColumn newCol6 = new ExprColumn(ti, "totalCDR3Reads" + colNameSuffix, sql6, JdbcType.INTEGER, ti.getColumn("rowid"));
159159
newCol6.setLabel("Total CDR3 Reads" + colLabelSuffix);
160160
newCol6.setURL(details);
@@ -166,7 +166,7 @@ private void addAssayFieldsToTable(AbstractTableInfo ti, String urlField, String
166166
SQLFragment runSelectSql = QueryService.get().getSelectSQL(runs, Collections.singletonList(runs.getColumn("analysisId")), null, null, Table.ALL_ROWS, Table.NO_OFFSET, false);
167167
DetailsURL runDetails = DetailsURL.fromString("/query/executeQuery.view?schemaName=assay." + ap.getName().replaceAll(" ", "") + "." + protocols.get(0).getName() + "&query.queryName=runs&query." + urlField + "~eq=${" + urlSourceCol + "}", (ti.getUserSchema().getContainer().isWorkbook() ? ti.getUserSchema().getContainer().getParent() : ti.getUserSchema().getContainer()));
168168

169-
SQLFragment sql5 = new SQLFragment("(select count(*) as expr FROM (").append(runSelectSql).append(") a " + whereClause + ")");
169+
SQLFragment sql5 = new SQLFragment("(select count(*) as expr FROM (").append(runSelectSql).append(") a ").append(whereClause).append(")");
170170
ExprColumn newCol5 = new ExprColumn(ti, "numTcrRuns" + colNameSuffix, sql5, JdbcType.INTEGER, ti.getColumn("rowid"));
171171
newCol5.setLabel("# TCR Runs" + colLabelSuffix);
172172
newCol5.setURL(runDetails);
@@ -199,7 +199,7 @@ private void addAssayClonotypeColumn(AbstractTableInfo ti)
199199
SQLFragment selectSql = QueryService.get().getSelectSQL(ti, Arrays.asList(ti.getColumn("analysisId"), ti.getColumn("cloneId"), ti.getColumn("Run"), ti.getColumn("cDNA"), ti.getColumn("cdr3"), ti.getColumn("locus")), filter, null, Table.ALL_ROWS, Table.NO_OFFSET, false);
200200

201201
String whereClause = " WHERE (a.cloneId = " + ExprColumn.STR_TABLE_ALIAS + ".cloneId AND a.analysisId = " + ExprColumn.STR_TABLE_ALIAS + ".analysisId AND a.Run = " + ExprColumn.STR_TABLE_ALIAS + ".Run AND a.cDNA = " + ExprColumn.STR_TABLE_ALIAS + ".cDNA) ";
202-
SQLFragment sql = new SQLFragment("(select ").append(ti.getSqlDialect().getGroupConcat(new SQLFragment(ti.getSqlDialect().concatenate("a.locus", "':'","a.CDR3")), true, true, getChr(ti) + "(10)")).append(" FROM (").append(selectSql).append(") a " + whereClause + " )");
202+
SQLFragment sql = new SQLFragment("(select ").append(ti.getSqlDialect().getGroupConcat(new SQLFragment(ti.getSqlDialect().concatenate("a.locus", "':'", "a.CDR3")), true, true, getChr(ti) + "(10)")).append(" FROM (").append(selectSql).append(") a ").append(whereClause).append(" )");
203203
ExprColumn newCol = new ExprColumn(ti, "clonotypes", sql, JdbcType.VARCHAR, ti.getColumn("analysisId"), ti.getColumn("cloneId"));
204204
newCol.setLabel("Clonotype for Clone");
205205
newCol.setDescription("CDR3 clonotypes for this cloneId");
@@ -215,7 +215,7 @@ private void addClonotypeForLocusCol(AbstractTableInfo ti, SQLFragment selectSql
215215
DetailsURL detailsURL = details.clone();
216216
detailsURL.addParameter("data.locus~eq", locus);
217217

218-
SQLFragment sql = new SQLFragment("(select ").append(ti.getSqlDialect().getGroupConcat(new SQLFragment("CDR3"), true, true, getChr(ti) + "(10)")).append(" FROM (").append(selectSql).append(") a " + whereClause + " )");
218+
SQLFragment sql = new SQLFragment("(select ").append(ti.getSqlDialect().getGroupConcat(new SQLFragment("CDR3"), true, true, getChr(ti) + "(10)")).append(" FROM (").append(selectSql).append(") a ").append(whereClause).append(" )");
219219
ExprColumn newCol = new ExprColumn(ti, "clonotype" + locus + colNameSuffix, sql, JdbcType.VARCHAR, ti.getColumn("rowid"));
220220
newCol.setLabel("Clonotype: " + locus + colLabelSuffix);
221221
newCol.setDescription("Showing CDR3 clonotypes for " + locus + " with fraction >=0.05");

0 commit comments

Comments
 (0)