br1ghtyang / asterixdb

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

Bug in a query involving a group-by and a nested query #550

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

Run the following standalone query:

let $sample := 
{{ 
   {"r": 1, "uid": "1a2b", "t": datetime("2000-01-01T01:00:00"), "event": "e1"},
   {"r": 2, "uid": "1a2b", "t": datetime("2000-01-01T01:01:00"), "event": "e2"},
   {"r": 3, "uid": "3c4d", "t": datetime("2000-01-01T01:02:00"), "event": "e1"},
   {"r": 4, "uid": "3c4d", "t": datetime("2000-01-01T01:03:00"), "event": "e3"},
   {"r": 5, "uid": "1a2b", "t": datetime("2000-01-01T01:04:00"), "event": "e1"},
   {"r": 6, "uid": "1a2b", "t": datetime("2000-01-01T01:05:00"), "event": "e4"}
}}
for $s in $sample
group by $u := $s.uid with $s 
return {
   "u": $u,
   "recs": ( for $srec in $s return $srec )
 };

What is the expected output? What do you see instead?

I expect a query result that looks something like:

{ "u": "1a2b", "recs": [ { "r": 1, "uid": "1a2b", "t": 
datetime("2000-01-01T01:00:00.000Z"), "event": "e1" }, { "r": 2, "uid": "1a2b", 
"t": datetime("2000-01-01T01:01:00.000Z"), "event": "e2" }, { "r": 5, "uid": 
"1a2b", "t": datetime("2000-01-01T01:04:00.000Z"), "event": "e1" }, { "r": 6, 
"uid": "1a2b", "t": datetime("2000-01-01T01:05:00.000Z"), "event": "e4" } ] }
{ "u": "3c4d", "recs": [ { "r": 3, "uid": "3c4d", "t": 
datetime("2000-01-01T01:02:00.000Z"), "event": "e1" }, { "r": 4, "uid": "3c4d", 
"t": datetime("2000-01-01T01:03:00.000Z"), "event": "e3" } ] }

But instead I get an error:

PushAggregateIntoGroupbyRule: could not find UNNEST. [IllegalStateException]

Interestingly, the following "more complicated" query works!
let $sample := 
{{ 
   {"r": 1, "uid": "1a2b", "t": datetime("2000-01-01T01:00:00"), "event": "e1"},
   {"r": 2, "uid": "1a2b", "t": datetime("2000-01-01T01:01:00"), "event": "e2"},
   {"r": 3, "uid": "3c4d", "t": datetime("2000-01-01T01:02:00"), "event": "e1"},
   {"r": 4, "uid": "3c4d", "t": datetime("2000-01-01T01:03:00"), "event": "e3"},
   {"r": 5, "uid": "1a2b", "t": datetime("2000-01-01T01:04:00"), "event": "e1"},
   {"r": 6, "uid": "1a2b", "t": datetime("2000-01-01T01:05:00"), "event": "e4"}
}}
for $s in $sample
group by $u := $s.uid with $s 
return {
   "u": $u,
   "recs": ( for $srec in $s order by $srec.t return $srec )
 };

Original issue reported on code.google.com by dtab...@gmail.com on 4 Jul 2013 at 5:54

GoogleCodeExporter commented 8 years ago
(The only difference between the broken one and the working one is the addition 
of the order by.  I wanted the order by anyway - but was building up to it, and 
hit this and wanted to make sure we found/fixed it.)

Original comment by dtab...@gmail.com on 4 Jul 2013 at 5:56

GoogleCodeExporter commented 8 years ago

Original comment by buyingyi@gmail.com on 25 Oct 2014 at 7:45

GoogleCodeExporter commented 8 years ago

Original comment by buyingyi@gmail.com on 28 Oct 2014 at 2:08

GoogleCodeExporter commented 8 years ago

Original comment by buyingyi@gmail.com on 2 Nov 2014 at 9:44