提交 77ab3a41 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Add some comments and reuse variable

上级 3d50985a
......@@ -76,21 +76,26 @@ public abstract class AbstractAggregate extends DataAnalysisOperation {
int rowIdColumn) {
WindowFrame frame = over.getWindowFrame();
if (frame == null || frame.isDefault()) {
// Aggregate all values before the current row (including)
Object aggregateData = createAggregateData();
for (Value[] row : ordered) {
// Collect values one by one
updateFromExpressions(session, aggregateData, row);
result.put(row[rowIdColumn].getInt(), getAggregatedValue(session, aggregateData));
}
} else if (frame.isFullPartition()) {
// Aggregate values from the whole partition
Object aggregateData = createAggregateData();
for (Value[] row : ordered) {
updateFromExpressions(session, aggregateData, row);
}
// All rows have the same value
Value value = getAggregatedValue(session, aggregateData);
for (Value[] row : ordered) {
result.put(row[rowIdColumn].getInt(), value);
}
} else {
// All other types of frames (slow)
int size = ordered.size();
for (int i = 0; i < size; i++) {
Object aggregateData = createAggregateData();
......
......@@ -244,6 +244,16 @@ public abstract class DataAnalysisOperation extends Expression {
: getWindowResult(session, groupData);
}
/**
* Returns result of this window function or window aggregate. This method
* is not used for plain aggregates.
*
* @param session
* the session
* @param groupData
* the group data
* @return result of this function
*/
private Value getWindowResult(Session session, SelectGroups groupData) {
PartitionData partition;
Object data;
......@@ -251,15 +261,17 @@ public abstract class DataAnalysisOperation extends Expression {
ValueArray key = over.getCurrentKey(session);
partition = groupData.getWindowExprData(this, key);
if (partition == null) {
// Window aggregates with FILTER clause may have no collected values
data = forOrderBy ? new ArrayList<>() : createAggregateData();
partition = new PartitionData(data);
groupData.setWindowExprData(this, key, partition);
} else {
data = partition.getData();
}
if (over.getOrderBy() != null || !isAggregate()) {
if (forOrderBy || !isAggregate()) {
return getOrderedResult(session, groupData, partition, data);
}
// Window aggregate without ORDER BY clause in window specification
Value result = partition.getResult();
if (result == null) {
result = getAggregatedValue(session, data);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论