The problem of SUM

72 views
Skip to first unread message

lhu

unread,
Mar 13, 2014, 4:53:46 AM3/13/14
to supersonic-...@googlegroups.com
hi,supersonic user group
I create a table t below:
i1 i2
1 1
And do the query:select sum(i2) from t where i1=0
Then i get a strange result,like -9958xxxx,a very big negative number.
What's the problem?
thx~

Piotr Tabor

unread,
Mar 13, 2014, 5:04:46 AM3/13/14
to lhu, supersonic-...@googlegroups.com
Could you please write a unit test that demonstrates the problem ?


--
You received this message because you are subscribed to the Google Groups "Supersonic Query Engine Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supersonic-query-...@googlegroups.com.
To post to this group, send email to supersonic-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

lhu

unread,
Mar 13, 2014, 5:59:41 AM3/13/14
to supersonic-...@googlegroups.com, lhu
void SumTest(Table& table) {
scoped_ptr<AggregationSpecification> specification(
new AggregationSpecification());
specification->AddAggregation(SUM, "i2", "i2");

const Expression* equal_i1 = Equal(ConstInt32(0),NamedAttribute("i1"));

scoped_ptr<Operation> filter1(Filter(equal_i1,
ProjectAllAttributes(),ScanView(table.view())));
scoped_ptr<Operation> aggregation(ScalarAggregate(specification.release(),filter1.release()));
scoped_ptr<Cursor> cursor(SucceedOrDie(aggregation->CreateCursor()));
ResultView result(cursor->Next(-1));
if(result.has_data() && !result.is_eos())
{
const int32* cnts = result.view().column(0).typed_data<INT32>();
cout << result.view().column(0).attribute().name() << ":" << *cnts << endl;
}
}


int main(int,char**)
{
TupleSchema schema;
schema.add_attribute(Attribute("i1",INT32,NOT_NULLABLE));
schema.add_attribute(Attribute("i2",INT32,NOT_NULLABLE));

Table table(schema,HeapBufferAllocator::Get());
TableRowWriter writer(&table);
writer.AddRow();
writer.Int32(1);
writer.Int32(1);
SumTest(table);

return 0;
}

在 2014年3月13日星期四UTC+8下午5时04分46秒,ptab写道:
Could you please write a unit test that demonstrates the problem ?
On Thu, Mar 13, 2014 at 9:53 AM, lhu <hulia...@gmail.com> wrote:
hi,supersonic user group
I create a table t below:
i1 i2
1 1
And do the query:select sum(i2) from t where i1=0
Then i get a strange result,like -9958xxxx,a very big negative number.
What's the problem?
thx~

--
You received this message because you are subscribed to the Google Groups "Supersonic Query Engine Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supersonic-query-engine+unsub...@googlegroups.com.

Piotr Tabor

unread,
Mar 13, 2014, 6:14:57 AM3/13/14
to lhu, supersonic-...@googlegroups.com
1.  You are calling cursor->Next(-1). -1 is not a 'supported' constant. You should give here a small positive number, e.g. 1024. -1 it converted to uint64, so its probably a large constant and It can lead to OOMs. 

2. Please do checks result.view().row_count() whether it's >=1 before trying to read: result.view().column(0).typed_data<INT32>()[0]


To unsubscribe from this group and stop receiving emails from it, send an email to supersonic-query-...@googlegroups.com.

lhu

unread,
Mar 13, 2014, 9:27:36 PM3/13/14
to supersonic-...@googlegroups.com, lhu

I tried your suggestions,but nothing changed.
在 2014年3月13日星期四UTC+8下午6时14分57秒,ptab写道:
To unsubscribe from this group and stop receiving emails from it, send an email to supersonic-query-engine+unsubscr...@googlegroups.com.
To post to this group, send email to supersonic-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

lhu

unread,
Mar 14, 2014, 4:51:56 AM3/14/14
to supersonic-...@googlegroups.com, lhu
I also tried :

void SumTest(Table& table) {
scoped_ptr<AggregationSpecification> specification(
new AggregationSpecification());
specification->AddAggregation(SUM, "i2", "i2");

scoped_ptr<Operation> aggregation(ScalarAggregate(specification.release(),ScanView(table.view())));
scoped_ptr<Cursor> cursor(SucceedOrDie(aggregation->CreateCursor()));
ResultView result(cursor->Next(1024));
if(result.has_data() && !result.is_eos())
{
if(result.view().row_count() < 1)
{
cout << "ERROR" << endl;
return;
}
const int32* cnts = result.view().column(0).typed_data<INT32>();
cout << result.view().column(0).attribute().name() << ":" << *cnts << endl;
}
}


int main(int,char**)
{
TupleSchema schema;
schema.add_attribute(Attribute("i1",INT32,NOT_NULLABLE));
schema.add_attribute(Attribute("i2",INT32,NOT_NULLABLE));

Table table(schema,HeapBufferAllocator::Get());
SumTest(table);

return 0;
}

The result is a random number.
How can i solve this problem?

Thanks

在 2014年3月13日星期四UTC+8下午6时14分57秒,ptab写道:
To unsubscribe from this group and stop receiving emails from it, send an email to supersonic-query-engine+unsubscr...@googlegroups.com.
To post to this group, send email to supersonic-...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Piotr Tabor

unread,
Mar 14, 2014, 6:34:23 AM3/14/14
to lhu, supersonic-...@googlegroups.com
Well, it seems that its a correct behavior. If the input list is empty, than the Scalar aggregate SUM(), MAX(), MIN(), AVG(), returns NULL for this column. 

The simplified testcase for your case is:

  TupleSchema schema;
  schema.add_attribute(Attribute("i1",INT32,NOT_NULLABLE));
  schema.add_attribute(Attribute("i2",INT32,NOT_NULLABLE));

  scoped_ptr<AggregationSpecification> specification(
    new AggregationSpecification());
  specification->AddAggregation(SUM, "i2", "i2");
  View view(schema);
  scoped_ptr<Operation> aggregation(
      ScalarAggregate(specification.release(), ScanView(view)));
  scoped_ptr<Cursor> cursor(SucceedOrDie(aggregation->CreateCursor()));
  ResultView result(cursor->Next(1024));
  CHECK(result.has_data());
  CHECK_EQ(1, result.view().row_count());
  EXPECT_TRUE(result.view().column(0).is_null()[0]);
  ResultView result2(cursor->Next(1024));
  CHECK(result2.is_eos());





To unsubscribe from this group and stop receiving emails from it, send an email to supersonic-query-...@googlegroups.com.

lhu

unread,
Mar 17, 2014, 3:44:39 AM3/17/14
to supersonic-...@googlegroups.com, lhu
It's ok!
Thanks

在 2014年3月14日星期五UTC+8下午6时34分23秒,ptab写道:
Reply all
Reply to author
Forward
0 new messages