Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,15 @@ private AppendableRowsAndColumns computeCumulativeAggregates(AggregatorFactory[]
rowIdProvider.incrementAndGet();
}

// Corner case when the numRows=upperOffset
// In such a case the priming of results is not needed
if (rowIdProvider.get() == numRows) {
for (int i = 0; i < aggs.length; i++) {
results[i][resultStorageIndex] = aggs[i].get();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should now be
results[i][resultStorageIndex] = aggFactories[i].finalizeComputation(aggs[i].get())
since this PR

Similarly in reverse cummulative aggregate as well

}
++resultStorageIndex;
}

// Prime the results
if (rowIdProvider.get() < numRows) {
for (int i = 0; i < aggs.length; i++) {
Expand Down Expand Up @@ -541,6 +550,15 @@ private AppendableRowsAndColumns computeReverseCumulativeAggregates(AggregatorFa
rowIdProvider.decrementAndGet();
}

// Corner case when the numRows=loweOffset
// In such a case the priming of results is not needed
if (rowIdProvider.get() < 0) {
for (int i = 0; i < aggs.length; i++) {
results[i][resultStorageIndex] = aggs[i].get();
}
--resultStorageIndex;
}

// Prime the results
if (rowIdProvider.get() >= 0) {
for (int i = 0; i < aggs.length; i++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ public void testUnboundedWindowedAggregation()
.validate(results);
}



@Test
public void testCumulativeAggregation()
{
Expand Down Expand Up @@ -460,6 +462,73 @@ public void testReverseCumulativeAggregation()
.validate(results);
}

@Test
public void testCumulativeAggregationUnbounded()
{
Map<String, Column> map = new LinkedHashMap<>();
map.put("intCol", new IntArrayColumn(new int[]{0}));
map.put("doubleCol", new DoubleArrayColumn(new double[]{0}));
map.put("objectCol", new ObjectArrayColumn(
new String[]{"a"},
ColumnType.STRING
)
);

RowsAndColumns rac = make(MapOfColumnsRowsAndColumns.fromMap(map));

FramedOnHeapAggregatable agger = FramedOnHeapAggregatable.fromRAC(rac);

final RowsAndColumns results = agger.aggregateAll(
new WindowFrame(WindowFrame.PeerType.ROWS, true, 1, false, 1, null),
new AggregatorFactory[]{
new LongMaxAggregatorFactory("cummMax", "intCol"),
new DoubleSumAggregatorFactory("cummSum", "doubleCol")
}
);

new RowsAndColumnsHelper()
.expectColumn("intCol", new int[]{0})
.expectColumn("doubleCol", new double[]{0})
.expectColumn("objectCol", new String[]{"a"}, ColumnType.STRING)
.expectColumn("cummMax", new long[]{0})
.expectColumn("cummSum", new double[]{0})
.allColumnsRegistered()
.validate(results);
}

@Test
public void testReverseCumulativeAggregationUnbound()
{
Map<String, Column> map = new LinkedHashMap<>();
map.put("intCol", new IntArrayColumn(new int[]{0}));
map.put("doubleCol", new DoubleArrayColumn(new double[]{0}));
map.put("objectCol", new ObjectArrayColumn(
new String[]{"a"},
ColumnType.STRING
)
);

RowsAndColumns rac = make(MapOfColumnsRowsAndColumns.fromMap(map));

FramedOnHeapAggregatable agger = FramedOnHeapAggregatable.fromRAC(rac);

final RowsAndColumns results = agger.aggregateAll(
new WindowFrame(WindowFrame.PeerType.ROWS, false, 1, true, 0, null),
new AggregatorFactory[]{
new LongMaxAggregatorFactory("cummMax", "intCol"),
new DoubleSumAggregatorFactory("cummSum", "doubleCol")
}
);

new RowsAndColumnsHelper()
.expectColumn("intCol", new int[]{0})
.expectColumn("doubleCol", new double[]{0})
.expectColumn("objectCol", new String[]{"a"}, ColumnType.STRING)
.expectColumn("cummMax", new long[]{0})
.expectColumn("cummSum", new double[]{0})
.allColumnsRegistered()
.validate(results);
}


@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type: "operatorValidation"

sql: |
select countryName, cityName,
count(cityName) over w cnt
from wikipedia
where countryName in ('Austria', 'Republic of Korea') and (cityName in ('Horsching', 'Vienna', 'Seoul', 'Jeonju'))
group by countryName, cityName
window w as (partition by cityName order by countryName asc rows between unbounded preceding and 1 following)


expectedResults:
- ["Austria","Horsching",1]
- ["Republic of Korea","Jeonju",1]
- ["Republic of Korea","Seoul",1]
- ["Austria","Vienna",1]
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type: "operatorValidation"

sql: |
select countryName, cityName,
count(cityName) over w cnt
from wikipedia
where countryName in ('Austria', 'Republic of Korea') and (cityName in ('Horsching', 'Vienna', 'Seoul', 'Jeonju'))
group by countryName, cityName
window w as (partition by cityName order by countryName asc rows between 1 preceding and unbounded following)


expectedResults:
- ["Austria","Horsching",1]
- ["Republic of Korea","Jeonju",1]
- ["Republic of Korea","Seoul",1]
- ["Austria","Vienna",1]