br1ghtyang / asterixdb

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

Listify type is not correctly referred by avg/sum/min/max aggregate functions #495

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The following query reveals this bug (failed when optimizing the logical plan):

drop dataverse test if exists;
create dataverse test;
use dataverse test;

create type TestType as open {
  id: int32,
  val: double
}

create dataset Test(TestType) primary key id;

insert into dataset Test ({"id": 0, "val": 4.32, "valplus": 2});
insert into dataset Test ({"id": 1, "val": 5.32});
insert into dataset Test ({"id": 2, "val": 6.32, "valplus": 38473827484738239});

let $l := for $t in dataset Test return $t.valplus
return { "count": count($l), "average": avg($l), "sum": sum($l), "min": 
min($l), "max": max($l) }  

Note that if the return contains only count, the above query will work. 

The following is the plan generated (before being optimized):

distribute result [%0->$$5] -- |UNPARTITIONED|
  project ([$$5]) -- |UNPARTITIONED|
    assign [$$5] <- [function-call: ASTERIX_PRIVATE:open-record-constructor, Args:[AString: {count}, function-call: ASTERIX_PUBLIC:count, Args:[%0->$$1], AString: {average}, function-call: ASTERIX_PUBLIC:avg, Args:[%0->$$1], AString: {sum}, function-call: ASTERIX_PUBLIC:sum, Args:[%0->$$1], AString: {min}, function-call: ASTERIX_PUBLIC:min, Args:[%0->$$1], AString: {max}, function-call: ASTERIX_PUBLIC:max, Args:[%0->$$1]]] -- |UNPARTITIONED|
      assign [$$1] <- [%0->$$4] -- |UNPARTITIONED|
        subplan {
                  aggregate [$$4] <- [function-call: ASTERIX_PRIVATE:listify, Args:[%0->$$3]] -- |UNPARTITIONED|
                    assign [$$3] <- [function-call: ASTERIX_PRIVATE:field-access-by-name, Args:[%0->$$0, AString: {valplus}]] -- |UNPARTITIONED|
                      unnest $$0 <- function-call: ASTERIX_PUBLIC:dataset, Args:[AString: {Test}] -- |UNPARTITIONED|
                        nested tuple source -- |UNPARTITIONED|
               } -- |UNPARTITIONED|
          empty-tuple-source -- |UNPARTITIONED|

@yingyi could you help me look at this issue, since it may relate to rewriting 
rules?

Original issue reported on code.google.com by jarod...@gmail.com on 3 Jun 2013 at 2:55

GoogleCodeExporter commented 8 years ago

Original comment by jarod...@gmail.com on 3 Jun 2013 at 5:48

GoogleCodeExporter commented 8 years ago

Original comment by jarod...@gmail.com on 3 Jun 2013 at 6:10

GoogleCodeExporter commented 8 years ago

Original comment by vinay...@gmail.com on 5 Jun 2013 at 7:04

GoogleCodeExporter commented 8 years ago

Original comment by jarod...@gmail.com on 5 Jun 2013 at 7:30

GoogleCodeExporter commented 8 years ago
The fix has been reviewed by Vinayak and Yingyi and pushed back to master.

Original comment by jarod...@gmail.com on 5 Jun 2013 at 9:55