Skip to content

Commit 21a24a4

Browse files
gaynor@illinois.edugaynor@illinois.edu
authored andcommitted
Found one (hopefully last!!) edge case and added a test.
1 parent 49c8b9d commit 21a24a4

3 files changed

Lines changed: 97 additions & 45 deletions

File tree

ncsa-qdl/src/main/java/edu/uiuc/ncsa/qdl/evaluate/ListEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ protected boolean doPickSubset(Polyad polyad, State state) {
606606
* @param polyad
607607
* @param state
608608
*/
609-
// list_starts_with(['a','qrs','pqr'],['a','p','s','t'])
609+
// starts_with(['a','qrs','pqr'],['a','p','s','t'])
610610
protected void doListStartsWith(Polyad polyad, State state) {
611611
if (polyad.isSizeQuery()) {
612612
polyad.setResult(new int[]{2});

ncsa-qdl/src/main/java/edu/uiuc/ncsa/qdl/expressions/StemExtractionNode.java

Lines changed: 77 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,34 @@ protected Object recurse(QDLStem in, IndexArgs sourceIndices) {
228228
int startIndex = 1;
229229
IndexArg root = indexArgs.get(startIndex);
230230
long autoIndex = 0L;
231+
boolean isList = indexArgs.size() == 2; // This does list processing only
232+
// Very simple case of list only -- this is just an optimization for a very common case, so we don't
233+
// start the recursion.
234+
if (isList) {
235+
for (Object key : root.createKeySet(in)) {
236+
Object value = in.get(key);
237+
if (Constant.isScalar(root.swri.getResult())) {
238+
if (value == null) {
239+
// edge case, they asked for a non-existent index
240+
// E.g. v.:=[;5]; v\42;
241+
return QDLNull.getInstance();
242+
}
243+
return value;
244+
}
245+
if (value == null) {
246+
continue;
247+
}
248+
if (root.strictOrder || (key instanceof String)) {
249+
out.putLongOrString(key, value);
250+
} else {
251+
out.put(autoIndex++, value);
252+
253+
}
254+
} // end for
255+
return out;
256+
}
257+
258+
231259
for (Object key : root.createKeySet(in)) {
232260
Object value = in.get(key);
233261
if (value == null) {
@@ -239,6 +267,7 @@ protected Object recurse(QDLStem in, IndexArgs sourceIndices) {
239267

240268
continue;
241269
}
270+
242271
if (value instanceof QDLStem) {
243272
IndexList indexList = new IndexList();
244273

@@ -256,20 +285,24 @@ protected Object recurse(QDLStem in, IndexArgs sourceIndices) {
256285
otherOut = recurse((QDLStem) value, out, indexList, sourceIndices, startIndex + 1, 0L);
257286
} else {
258287
if (indexArgs.size() - 1 == startIndex) {
288+
System.out.println("recurse: last args index size =" + (indexArgs.size() - 1));
259289
// set the value, but only if it is the end of an index list (so there
260290
// are no more indices to traverse.
261291
if (root.isWildcard()) {
292+
System.out.println(" set wildcard key=" + key + ", value=" + value);
262293
out.putLongOrString(key, value);
263294
} else {
264295
if (Constant.isScalar(root.swri.getResult())) {
296+
System.out.println(" return value=" + value);
265297
return value;
266298
} else {
267299
if (root.strictOrder || (key instanceof String)) {
300+
System.out.println(" put key=" + key + ", value=" + value);
268301
out.putLongOrString(key, value);
269302
} else {
303+
System.out.println(" autoindex put key=" + key + ", value=" + value);
270304
out.put(autoIndex++, value);
271305
}
272-
273306
}
274307

275308
}
@@ -286,18 +319,28 @@ protected Object recurse(QDLStem in, IndexArgs sourceIndices) {
286319
}
287320

288321
protected Object recurse(QDLStem in,
289-
QDLStem out,
290-
IndexList targetIndex,
291-
List<IndexArg> sourceIndices,
292-
int indexLocation,
293-
long strictIndex) {
322+
QDLStem out,
323+
IndexList targetIndex,
324+
List<IndexArg> sourceIndices,
325+
int indexLocation,
326+
long strictIndex) {
294327

295328
if (sourceIndices.size() <= indexLocation) {
296-
System.out.println("*** recurseNEW: targetIndex = " + targetIndex + ", strictIndex=" + strictIndex + ", loc=" + indexLocation + ", in=" + in + ", out=" + out);
329+
System.out.println("*** recurseNEW: " +
330+
"\n in=" + in +
331+
"\n out=" + out +
332+
"\n targetIndex = " + targetIndex +
333+
"\n sourceIndices = " + sourceIndices +
334+
"\n loc=" + indexLocation +
335+
"\n strictIndex=" + strictIndex
336+
);
297337
IndexArg lastIndex = sourceIndices.get(indexLocation - 1);
298338
if (Constant.isScalar(lastIndex.swri.getResult())) {
339+
System.out.println(" recurseNEW: adding all inStem");
299340
out.addAll(in);
300341
} else {
342+
System.out.println(" recurseNEW: strict add inStem");
343+
301344
out.putLongOrString(strictIndex, in);
302345
}
303346
return out;
@@ -339,34 +382,36 @@ protected Object recurse(QDLStem in,
339382
}
340383
out.set(indexList, value);
341384
}
342-
// System.out.println("recurse: setting value key =" + indexList + ", value = " + value);
385+
System.out.println(" recurseNEW: setting value key =" + indexList + ", value = " + value);
386+
}else{
387+
if (value instanceof QDLStem) {
388+
IndexList indexList = targetIndex.clone();
389+
if (indexLocation + 1 < sourceIndices.size()) {
390+
// System.out.println("recurseNEW: INDEX CHECK, targetIndex = " + targetIndex + ", strictIndex=" + strictIndex + ", loc=" + indexLocation + ", in=" + in + ", out=" + out);
391+
}
392+
393+
if ((indexArg.swri instanceof AllIndices) || !Constant.isScalar(indexArg.swri.getResult())) {
394+
if (indexArg.strictOrder && indexArg.isWildcard()) {
395+
indexList.add(key);
396+
} else {
397+
indexList.add(strictIndex++);
398+
}
399+
}
400+
if (sourceIndices.size() <= indexLocation) {
401+
IndexArg lastIndex = sourceIndices.get(indexLocation - 1);
402+
if (Constant.isScalar(lastIndex.swri.getResult())) {
403+
out.addAll(in);
404+
} else {
405+
out.putLongOrString(strictIndex++, in);
406+
}
407+
408+
} else {
409+
otherOut = recurse((QDLStem) value, out, indexList, sourceIndices, indexLocation + 1, 0L);
410+
}
411+
}
343412
}
344413

345-
if (value instanceof QDLStem) {
346-
IndexList indexList = targetIndex.clone();
347-
if (indexLocation + 1 < sourceIndices.size()) {
348-
// System.out.println("recurseNEW: INDEX CHECK, targetIndex = " + targetIndex + ", strictIndex=" + strictIndex + ", loc=" + indexLocation + ", in=" + in + ", out=" + out);
349-
}
350414

351-
if ((indexArg.swri instanceof AllIndices) || !Constant.isScalar(indexArg.swri.getResult())) {
352-
if (indexArg.strictOrder && indexArg.isWildcard()) {
353-
indexList.add(key);
354-
} else {
355-
indexList.add(strictIndex++);
356-
}
357-
}
358-
if (sourceIndices.size() <= indexLocation) {
359-
IndexArg lastIndex = sourceIndices.get(indexLocation - 1);
360-
if (Constant.isScalar(lastIndex.swri.getResult())) {
361-
out.addAll(in);
362-
} else {
363-
out.putLongOrString(strictIndex++, in);
364-
}
365-
366-
} else {
367-
otherOut = recurse((QDLStem) value, out, indexList, sourceIndices, indexLocation + 1, 0L);
368-
}
369-
}
370415
}
371416
if (!(otherOut instanceof QDLStem)) {
372417
return otherOut;

ncsa-qdl/src/test/java/edu/uiuc/ncsa/qdl/StemTest.java

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,18 +2558,25 @@ public void testExtractionStemKey() throws Throwable {
25582558
" zeta.'Communities:LVC:SegDB:SegDBWriter' := 'write:/DQSegDB';\n" +
25592559
" zeta.'gw-astronomy:KAGRA-LIGO:members' := ['read:/GraceDB', 'read:/frames'];\n" +
25602560
" g. := [{'name': 'Services:MailingLists:Testing:eligible_factor'},{'name': 'Communities:LSCVirgoLIGOGroupMembers'},{'name':'Communities:LVC:SegDB:SegDBWriter'}];");
2561-
2562-
addLine(script, "ok :=reduce(@&&, b\\>[star(),2] == [2,12,22,102]);");
2563-
addLine(script, "ok1 :=reduce(@&&, b\\>[2,star()] == [20,21,22,23,24,25,26]);"); // same as b.2, essentially
2564-
addLine(script, "ok2 :=reduce(@&&, reduce(@&&, b\\>[star(),star()] == b.));"); // same as b.
2565-
addLine(script, "ok3 :=reduce(@&&, reduce(@&&, b\\!>[star()] == b.));"); // same as b.
2566-
2567-
QDLInterpreter interpreter = new QDLInterpreter(null, state);
2568-
interpreter.execute(script.toString());
2569-
assert getBooleanValue("ok", state) : "b\\>[star(),2] failed";
2570-
assert getBooleanValue("ok1", state) : "b\\>[2,star()] failed";
2571-
assert getBooleanValue("ok2", state) : "b\\>[star(),star()] failed";
2572-
assert getBooleanValue("ok3", state) : "b\\!>[star()]* failed";
2561+
addLine(script, "i. := g\\*\\name;");
2562+
addLine(script, "w.0 := zeta.;"); // have one a level down too
2563+
addLine(script, "okz0 := 2== size(zeta\\i.);");
2564+
addLine(script, "okw0 := 2== size(w\\0\\i.);"); // have one a level down too
2565+
// GOT: {0:[read:/DQSegDB,read:/frames,read:/GraceDB], Communities:LVC:SegDB:SegDBWriter:write:/DQSegDB}
2566+
// WANT: {Communities:LSCVirgoLIGOGroupMembers:[read:/DQSegDB,read:/frames,read:/GraceDB], Communities:LVC:SegDB:SegDBWriter:write:/DQSegDB}
2567+
addLine(script, "okz1 := (zeta\\i.).'Communities:LVC:SegDB:SegDBWriter' == 'write:/DQSegDB';");
2568+
addLine(script, "okz2 := (zeta\\i.).'Communities:LSCVirgoLIGOGroupMembers'.0 == 'read:/DQSegDB';");
2569+
addLine(script, "okw1 := (w\\0\\i.).'Communities:LVC:SegDB:SegDBWriter' == 'write:/DQSegDB';");
2570+
addLine(script, "okw2 := (w\\0\\i.).'Communities:LSCVirgoLIGOGroupMembers'.0 == 'read:/DQSegDB';");
2571+
2572+
QDLInterpreter interpreter = new QDLInterpreter(null, state);
2573+
interpreter.execute(script.toString());
2574+
assert getBooleanValue("okz0", state) : "2== size(zeta\\i.) failed";
2575+
assert getBooleanValue("okz1", state) : "(zeta\\i.).'Communities:LVC:SegDB:SegDBWriter' == 'write:/DQSegDB' failed";
2576+
assert getBooleanValue("okz2", state) : "(zeta\\i.).'Communities:LSCVirgoLIGOGroupMembers'.0 == 'read:/DQSegDB' failed";
2577+
assert getBooleanValue("okw0", state) : "2== size(w\\0\\i.) failed";
2578+
assert getBooleanValue("okw1", state) : "(w\\0\\i.).'Communities:LVC:SegDB:SegDBWriter' == 'write:/DQSegDB' failed";
2579+
assert getBooleanValue("okw2", state) : "(w\\0\\i.).'Communities:LSCVirgoLIGOGroupMembers'.0 == 'read:/DQSegDB' failed";
25732580
}
25742581

25752582
}

0 commit comments

Comments
 (0)