shamim8888 / asterixdb

Automatically exported from code.google.com/p/asterixdb
0 stars 0 forks source link

For statements don't always scan over #903

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
This query doesn't do what would be expected. It should return the individual 
records of items, but it just returns the ordered list itself, as if the 
outermost for statement wasn't even there. 

for $z in (
      for $y in (
          for $x in 
[{ 
"kind":"project",
"issues": { 
   "kind":"nestedthing",
   "items": [
        {"foo":1, "bar" :2},
        {"foo":3, "bar":4}
    ]
  }
}]
 return $x) 
      return $y.issues.items) 
return $z

Yields:
[
[ { "foo": 1, "bar": 2 }, { "foo": 3, "bar": 4 } ]
]

Where it should yield:
[
{ "foo": 1, "bar": 2 }, { "foo": 3, "bar": 4 }
]

Original issue reported on code.google.com by ima...@uci.edu on 23 Jun 2015 at 7:23

GoogleCodeExporter commented 8 years ago
The result is expected.

for $y in (
          for $x in 
[{ 
"kind":"project",
"issues": { 
   "kind":"nestedthing",
   "items": [
        {"foo":1, "bar" :2},
        {"foo":3, "bar":4}
    ]
  }
}]
 return $x) 
      return $y.issues.items

This query's return type is  List<List>.  So $z will bind to a List for each 
input.

To get the result you want, you can use this query:
for $y in (
          for $x in 
            [{ 
                "kind":"project",
                "issues": { 
                        "kind":"nestedthing",
                        "items": [
                                    {"foo":1, "bar" :2},
                                    {"foo":3, "bar":4}
                                 ]
                           }
            }]
          return $x) 
for $z in $y.issues.items
return $z

Original comment by buyingyi@gmail.com on 26 Jun 2015 at 6:09

GoogleCodeExporter commented 8 years ago
Yes, you are right :) I was misinterpreting the $y to be a list, when it's 
really a list of lists- the FLOWR always "listifies".  

Original comment by ima...@uci.edu on 26 Jun 2015 at 7:31