Skip to content

Commit 2ead1b6

Browse files
committed
make query more efficient
1 parent 77d39c7 commit 2ead1b6

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

SequenceAnalysis/resources/queries/pipeline/Job/Sequence Jobs Without Data.qview.xml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
<column name="totalReadsets"/>
99
<column name="totalAnalyses"/>
1010
<column name="totalOutputs"/>
11-
<column name="hasSequenceData"/>
11+
<column name="sequenceJobWithoutData"/>
1212
</columns>
1313
<filters>
14-
<filter column="hasSequenceData" operator="eq" value="false"/>
15-
<filter column="Provider" operator="in" value="sequenceOutputHandler;Sequence Pipeline;sequenceReadsetHandler"/>
16-
<filter column="Status" operator="eq" value="COMPLETE"/>
14+
<filter column="sequenceJobWithoutData" operator="eq" value="true"/>
1715
</filters>
1816
<sorts>
1917
<sort column="Created" descending="true"/>

SequenceAnalysis/resources/queries/pipeline/Job/Sequence Jobs.qview.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<column name="totalReadsets"/>
99
<column name="totalAnalyses"/>
1010
<column name="totalOutputs"/>
11-
<column name="hasSequenceData"/>
11+
<column name="sequenceJobWithoutData"/>
1212
</columns>
1313
<filters>
1414
<!--<filter column="Provider" operator="neqornull" value="ETL"/>-->

SequenceAnalysis/src/org/labkey/sequenceanalysis/query/JobsTableCustomizer.java

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.labkey.api.data.TableCustomizer;
77
import org.labkey.api.data.TableInfo;
88
import org.labkey.api.ldk.LDKService;
9+
import org.labkey.api.pipeline.PipelineJob;
910
import org.labkey.api.query.ExprColumn;
1011

1112
/**
@@ -58,22 +59,27 @@ public void customize(TableInfo ti)
5859
((AbstractTableInfo)ti).addColumn(newCol);
5960
}
6061

61-
String hasSequenceData = "hasSequenceData";
62-
if (ti.getColumn(hasSequenceData) == null)
62+
String sequenceJobWithoutData = "sequenceJobWithoutData";
63+
if (ti.getColumn(sequenceJobWithoutData) == null)
6364
{
64-
SQLFragment sql = new SQLFragment("(SELECT CASE " +
65-
"WHEN sum(CASE WHEN (rs.RowId IS NULL AND rd.RowId IS NULL AND sa.RowId IS NULL AND o.RowId IS NULL) THEN 0 ELSE 1 END) = 0 THEN " + ti.getSqlDialect().getBooleanFALSE() + "\n" +
66-
"WHEN sum(CASE WHEN (rs.RowId IS NULL AND rd.RowId IS NULL AND sa.RowId IS NULL AND o.RowId IS NULL) THEN 0 ELSE 1 END) IS NULL THEN " + ti.getSqlDialect().getBooleanFALSE() + "\n" +
67-
"ELSE " + ti.getSqlDialect().getBooleanTRUE() + " END as expr\n" +
68-
"FROM exp.experimentrun r\n" +
69-
"LEFT JOIN sequenceanalysis.sequence_readsets rs ON (r.RowId = rs.runid)\n" +
70-
"LEFT JOIN sequenceanalysis.readdata rd on (r.RowId = rd.runid)\n" +
71-
"LEFT JOIN sequenceanalysis.sequence_analyses sa ON (r.RowId = sa.runid)\n" +
72-
"LEFT JOIN sequenceanalysis.outputfiles o ON (r.RowId = o.runid)\n" +
73-
"WHERE (r.jobid = " + ExprColumn.STR_TABLE_ALIAS + ".RowId OR r.jobid = (SELECT p.RowId FROM pipeline.statusfiles p WHERE " + ExprColumn.STR_TABLE_ALIAS + ".jobparent = p.job))\n" +
74-
")");
75-
ExprColumn newCol = new ExprColumn(ti, hasSequenceData, sql, JdbcType.BOOLEAN, ti.getColumn("RowId"));
76-
newCol.setLabel("Has Sequence Data?");
65+
//Jobs from all exp runs connected to sequence data
66+
String runSubquery = "(SELECT DISTINCT r.jobid FROM exp.experimentrun r\n" +
67+
"WHERE\n" +
68+
"r.jobid IS NOT NULL AND (\n" +
69+
"EXISTS (SELECT rs.rowid FROM sequenceanalysis.sequence_readsets rs WHERE (r.RowId = rs.runid)) OR\n" +
70+
"EXISTS (SELECT rd.rowid FROM sequenceanalysis.readdata rd WHERE (r.RowId = rd.runid)) OR\n" +
71+
"EXISTS (SELECT sa.rowid FROM sequenceanalysis.sequence_analyses sa WHERE (r.RowId = sa.runid)) OR\n" +
72+
"EXISTS (SELECT o.runid FROM sequenceanalysis.outputfiles o WHERE (r.RowId = o.runid))\n" +
73+
"))";
74+
75+
SQLFragment sql = new SQLFragment("(CASE " +
76+
"WHEN " + ExprColumn.STR_TABLE_ALIAS + ".status IS NULL OR " + ExprColumn.STR_TABLE_ALIAS + ".status != '"+ PipelineJob.TaskStatus.complete.name().toUpperCase() + "' THEN " + ti.getSqlDialect().getBooleanFALSE() + "\n" +
77+
"WHEN " + ExprColumn.STR_TABLE_ALIAS + ".provider IS NULL OR " + ExprColumn.STR_TABLE_ALIAS + ".provider NOT IN ('sequenceOutputHandler', 'Sequence Pipeline', 'sequenceReadsetHandler') THEN " + ti.getSqlDialect().getBooleanFALSE() + "\n" +
78+
"WHEN " + ExprColumn.STR_TABLE_ALIAS + ".RowId IN " + runSubquery + " THEN " + ti.getSqlDialect().getBooleanFALSE() + "\n" +
79+
"WHEN " + ExprColumn.STR_TABLE_ALIAS + ".jobparent IS NOT NULL AND (SELECT p.RowId FROM pipeline.statusfiles p WHERE " + ExprColumn.STR_TABLE_ALIAS + ".jobparent = p.job) IN " + runSubquery + " THEN " + ti.getSqlDialect().getBooleanFALSE() + "\n" +
80+
"ELSE " + ti.getSqlDialect().getBooleanTRUE() + " END)");
81+
ExprColumn newCol = new ExprColumn(ti, sequenceJobWithoutData, sql, JdbcType.BOOLEAN, ti.getColumn("RowId"));
82+
newCol.setLabel("Sequence Job Without Data?");
7783
((AbstractTableInfo)ti).addColumn(newCol);
7884
}
7985

0 commit comments

Comments
 (0)