Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions src/jsonata.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ var jsonata = (function() {
// expr is an array of steps
// if the first step is a variable reference ($...), including root reference ($$),
// then the path is absolute rather than relative
if (expr.steps[0].type === 'variable') {
inputSequence = createSequence(input); // dummy singleton sequence for first (absolute) step
} else if (Array.isArray(input)) {
if (Array.isArray(input) && expr.steps[0].type !== 'variable') {
inputSequence = input;
} else {
// if input is not an array, make it so
Expand Down Expand Up @@ -334,7 +332,7 @@ var jsonata = (function() {
result.tupleStream = true;
var stepEnv = environment;
if(tupleBindings === undefined) {
tupleBindings = [{'@': input}];
tupleBindings = input.map(item => { return {'@': item} });
}

for(var ee = 0; ee < tupleBindings.length; ee++) {
Expand Down
8 changes: 7 additions & 1 deletion src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ const parser = (() => {
}
// throw error if there are any predicates defined at this point
// at this point the only type of stages can be predicates
if(typeof step.stages !== 'undefined') {
if(typeof step.stages !== 'undefined' || typeof step.predicate !== 'undefined') {
throw {
code: "S0215",
stack: (new Error()).stack,
Expand All @@ -1038,6 +1038,12 @@ const parser = (() => {
step = result;
if (result.type === 'path') {
step = result.steps[result.steps.length - 1];
} else {
result = {type: 'path', steps: [result]};
if (typeof step.predicate !== 'undefined') {
step.stages = step.predicate;
delete step.predicate;
}
}
if (typeof step.stages === 'undefined') {
step.index = expr.rhs.value;
Expand Down
42 changes: 33 additions & 9 deletions test/test-suite/groups/joins/index.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"expr": "$.$#$pos[$pos<3]",
"expr": "$#$pos[$pos<3]",
"data": [3,1,4,1,5,9],
"bindings": {},
"result": [
Expand All @@ -10,7 +10,25 @@
]
},
{
"expr": "$.$#$pos[$pos<3]^($)",
"expr": "$#$pos[$pos<3] = $[[0..2]]",
"data": [3,1,4,1,5,9],
"bindings": {},
"result": true
},
{
"expr": "$.$#$pos[$pos<3]",
"data": [3,1,4,1,5,9],
"bindings": {},
"result": [3,1,4,1,5,9]
},
{
"expr": "$.$#$pos[$pos<3] = $.$[[0..2]]",
"data": [3,1,4,1,5,9],
"bindings": {},
"result": true
},
{
"expr": "$#$pos[$pos<3]^($)",
"data": [3,1,4,1,5,9],
"bindings": {},
"result": [
Expand All @@ -20,7 +38,7 @@
]
},
{
"expr": "$.$#$pos[$pos<3]^(>$)",
"expr": "$#$pos[$pos<3]^(>$)",
"data": [3,1,4,1,5,9],
"bindings": {},
"result": [
Expand All @@ -30,7 +48,7 @@
]
},
{
"expr": "$.$^($)#$pos[$pos<3] ",
"expr": "$^($)#$pos[$pos<3] ",
"data": [3,1,4,1,5,9],
"bindings": {},
"result": [
Expand All @@ -40,35 +58,41 @@
]
},
{
"expr": "$.$#$pos[$pos<3][1]",
"expr": "$#$pos[$pos<3][1]",
"data": [3,1,4,1,5,9],
"bindings": {},
"result": 1
},
{
"expr": "$.$#$pos[$pos<3][1][]",
"expr": "$#$pos[$pos<3][1][]",
"data": [3,1,4,1,5,9],
"bindings": {},
"result": [1]
},
{
"expr": "$.$#$pos[$pos<3]^($)[-1]",
"expr": "$#$pos[$pos<3]^($)[-1]",
"data": [3,1,4,1,5,9],
"bindings": {},
"result": 4
},
{
"expr": "$.$#$pos[][$pos<3]^($)[-1]",
"expr": "$#$pos[][$pos<3]^($)[-1]",
"data": [3,1,4,1,5,9],
"bindings": {},
"result": [4]
},
{
"expr": "$.$#$pos[$pos<3]^($)[-1][]",
"expr": "$#$pos[$pos<3]^($)[-1][]",
"data": [3,1,4,1,5,9],
"bindings": {},
"result": [4]
},
{
"expr": "$[[1..4]]#$pos[$pos>=2]",
"data": [3,1,4,1,5,9],
"bindings": {},
"result": [1,5]
},
{
"expr": "Account.Order#$o.Product[ProductID=858383].{ 'Product': `Product Name`, 'Order Index': $o }",
"dataset": "dataset5",
Expand Down