2525import org .labkey .test .categories .Daily ;
2626import org .labkey .test .categories .Data ;
2727import org .labkey .test .components .ChartTypeDialog ;
28+ import org .labkey .test .pages .query .SourceQueryPage ;
2829import org .labkey .test .pages .study .DatasetDesignerPage ;
2930import org .labkey .test .params .FieldDefinition ;
3031import org .labkey .test .util .DataRegionTable ;
@@ -214,10 +215,10 @@ public void testBadPivotQuery()
214215 importPage .setText (bulkData );
215216 importPage .submit ();
216217
217- // configure the query
218+ // configure the query without F1 as pivot field
218219 String queryName = "Q1" ;
219220 String queryText = """
220- SELECT ParticipantId, SequenceNum, MAX([F1]) AS I1Max, [F1] FROM study.[D2]
221+ SELECT ParticipantId, SequenceNum, MAX([F1]) AS I1Max FROM study.[D2]
221222 GROUP BY ParticipantId, SequenceNum, [F1]
222223 PIVOT I1Max BY [F1]
223224 """ .replace ("[F1]" , EscapeUtil .getSqlQuotedValue (textFieldName ))
@@ -230,6 +231,22 @@ SELECT ParticipantId, SequenceNum, MAX([F1]) AS I1Max, [F1] FROM study.[D2]
230231 sourceQueryPage .setSource (queryText );
231232 sourceQueryPage .clickSaveAndFinish ();
232233
234+ // expect query error
235+ waitForText ("Query 'Q1' has errors" , "Error on line 3: Can not find pivot column:" );
236+
237+ // update the query to include the pivot column and verify it works
238+ String updatedQueryText = """
239+ SELECT ParticipantId, SequenceNum, MAX([F1]) AS I1Max, [F1] FROM study.[D2]
240+ GROUP BY ParticipantId, SequenceNum, [F1]
241+ PIVOT I1Max BY [F1]
242+ """ .replace ("[F1]" , EscapeUtil .getSqlQuotedValue (textFieldName ))
243+ .replace ("[D2]" , EscapeUtil .getSqlQuotedValue (datasetName ));
244+
245+ clickAndWait (Locator .linkWithText ("Edit Query" ));
246+ var editQueryPage = new SourceQueryPage (getDriver ());
247+ editQueryPage .setSource (updatedQueryText );
248+ editQueryPage .clickSaveAndFinish ();
249+
233250 // ensure query results contain F1 contents
234251 assertTextPresent ("this" , "that" , "the other" , "and more" , "but wait" , "still more" );
235252 }
0 commit comments