Skip to content

Commit 5992b02

Browse files
gaynor@illinois.edugaynor@illinois.edu
authored andcommitted
Lots of documentation upgrades. Found an edge case in writing and example and fixed it with refgression tests.
1 parent 1b8e911 commit 5992b02

10 files changed

Lines changed: 70 additions & 54 deletions

File tree

.idea/workspace.xml

Lines changed: 20 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
-395 Bytes
Binary file not shown.
73 Bytes
Binary file not shown.
70 Bytes
Binary file not shown.
11 Bytes
Binary file not shown.
2.08 KB
Binary file not shown.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ protected Object get(State state) {
8585
throw new IllegalStateException("error: left argument must evaluate to be a stem ");
8686
}
8787
StemVariable stemVariable = (StemVariable) r0;
88-
IndexList r = stemVariable.get(indexList);
88+
IndexList r = stemVariable.get(indexList,true);
8989
Object result = r.get(0);
9090
setResult(result);
9191
setResultType(Constant.getType(result));
@@ -113,7 +113,7 @@ protected void oldWhittle(IndexList indexList){
113113

114114
for (int i = indexList.size() - 1; 0 <= i; i--) {
115115
if (indexList.get(i) instanceof StemVariable) {
116-
r = ((StemVariable) indexList.get(i)).get(indexList.tail(i + 1));
116+
r = ((StemVariable) indexList.get(i)).get(indexList.tail(i + 1), false);
117117
indexList.truncate(i);
118118
indexList.addAll(i, r);
119119
}
@@ -134,7 +134,7 @@ protected void newWhittle(IndexList indexList){
134134
if(i == indexList.size() - 1 ){
135135
continue;
136136
}
137-
r = ((StemVariable) indexList.get(i)).get(indexList.tail(i + 1));
137+
r = ((StemVariable) indexList.get(i)).get(indexList.tail(i + 1), false);
138138
indexList.truncate(i);
139139
indexList.addAll(i, r);
140140
}else{

ncsa-qdl/src/main/java/edu/uiuc/ncsa/qdl/variables/StemVariable.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,9 +1423,9 @@ public Object get(StemPath<StemPathEntry> stemPath) {
14231423
This is used to overlay the stem in the calling function
14241424
so arguments don't get lost
14251425
*/
1426-
public IndexList get(IndexList indexList) {
1426+
public IndexList get(IndexList indexList, boolean strictMatching) {
14271427
if (experimental) {
1428-
return newGet(indexList);
1428+
return newGet(indexList, strictMatching);
14291429
}
14301430
return oldGet(indexList);
14311431
}
@@ -1484,6 +1484,9 @@ public IndexList oldGet(IndexList indexList) {
14841484
}
14851485

14861486
public IndexList newGet(IndexList indexList) {
1487+
return newGet(indexList, true);
1488+
}
1489+
public IndexList newGet(IndexList indexList, boolean strictMatching) {
14871490
if (indexList.get(indexList.size() - 1) instanceof StemVariable) {
14881491
StemVariable ndx = (StemVariable) indexList.get(indexList.size() - 1);
14891492
if (!ndx.isList()) {
@@ -1527,6 +1530,9 @@ public IndexList newGet(IndexList indexList) {
15271530
if (obj instanceof StemVariable) {
15281531
currentStem = (StemVariable) obj;
15291532
} else {
1533+
if(strictMatching && i != indexList.size()-1){
1534+
throw new IndexError("error: scalars do not have indices.");
1535+
}
15301536
rc.add(obj); // 0th entry is returned value
15311537
gotOne = true;
15321538
}

ncsa-qdl/src/main/resources/func_help.xml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,9 +1127,16 @@ So options = 0 means append, have a trailing delimiter
11271127
options = 1 means prepend, " " leading "
11281128
options = 2 means append, omit trailing delimiter
11291129
options = 3 means prepend, omit first delimiter
1130-
E.g. detokenize(indices(4), ' ') yields the string
1131-
'0 1 2 3 '
1132-
(Note the trailing blank added at the end.)
1130+
E.g.
1131+
detokenize([;4],'|')
1132+
0|1|2|3|
1133+
1134+
Note the trailing | added at the end.
1135+
E.g.
1136+
detokenize([;4]], '|',2)
1137+
'0 1 2 3'
1138+
1139+
omits the trailing |.
11331140
See also: truncate, constants (which contains the option values for reference)
11341141
11351142
]]>
@@ -1680,19 +1687,12 @@ E.g. 1: getting a result set
16801687
price:8.99,
16811688
isbn:0-553-21311-3,...
16821689
1683-
Note well that results are returned as stem lists of v paths.
1684-
1685-
A v path is a string of the form
1686-
1687-
(` | · ) vpath0 (` | · ) vpath1 (` | · )
1688-
1689-
whose paths are v-encoded. You may use either a backtick ` or a
1690-
raised dot · (unicode \u00b7).
1690+
Note well that results are returned as stem lists of paths.
16911691
16921692
E.g. 2: Getting the indices
16931693
ndx. := query(test., '$..book[?(@.isbn)]', true); // Just get the indices
16941694
ndx.
1695-
['`store`book`2','`store`book`3']
1695+
[[store,book,2],[store,book,3]]
16961696
16971697
E.g. 3: Using the indices
16981698
my_json.ndx.0
@@ -1704,7 +1704,6 @@ E.g. 3: Using the indices
17041704
Hint: Easy way to import the JSON is to cut and paste it to a file at /my/path/my_json.json
17051705
and issue
17061706
my_json. := from_json(file_read('/my/path/my_json.json'));
1707-
17081707
]]>
17091708
</body>
17101709
</entry>

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package edu.uiuc.ncsa.qdl;
22

33
import edu.uiuc.ncsa.qdl.evaluate.StemEvaluator;
4+
import edu.uiuc.ncsa.qdl.exceptions.IndexError;
45
import edu.uiuc.ncsa.qdl.expressions.ConstantNode;
56
import edu.uiuc.ncsa.qdl.expressions.Polyad;
67
import edu.uiuc.ncsa.qdl.expressions.VariableNode;
@@ -1509,4 +1510,30 @@ public void testDyadicStemSubtraction() throws Throwable {
15091510
assert getBooleanValue("ok", state);
15101511
}
15111512

1513+
public void testExtraIndices() throws Throwable {
1514+
State state = testUtils.getNewState();
1515+
StringBuffer script = new StringBuffer();
1516+
addLine(script, "b. := [;5].2.4;");
1517+
QDLInterpreter interpreter = new QDLInterpreter(null, state);
1518+
try {
1519+
interpreter.execute(script.toString());
1520+
assert false : "was able to access a non-existant index in a stem";
1521+
}catch(IndexError ie){
1522+
assert true;
1523+
}
1524+
}
1525+
1526+
public void testExtraIndices2() throws Throwable {
1527+
State state = testUtils.getNewState();
1528+
StringBuffer script = new StringBuffer();
1529+
addLine(script, "b. := [;5].i(2).i(4);");
1530+
QDLInterpreter interpreter = new QDLInterpreter(null, state);
1531+
try {
1532+
interpreter.execute(script.toString());
1533+
assert false : "was able to access a non-existant index in a stem";
1534+
}catch(IndexError ie){
1535+
assert true;
1536+
}
1537+
}
1538+
15121539
}

0 commit comments

Comments
 (0)