提交 2bf25cb7 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Merge AggregateDataCount and AggregateDataCountAll

上级 53865d28
...@@ -25,10 +25,10 @@ abstract class AggregateData { ...@@ -25,10 +25,10 @@ abstract class AggregateData {
static AggregateData create(AggregateType aggregateType, boolean distinct) { static AggregateData create(AggregateType aggregateType, boolean distinct) {
switch (aggregateType) { switch (aggregateType) {
case COUNT_ALL: case COUNT_ALL:
return new AggregateDataCountAll(); return new AggregateDataCount(true);
case COUNT: case COUNT:
if (!distinct) { if (!distinct) {
return new AggregateDataCount(); return new AggregateDataCount(false);
} }
break; break;
case GROUP_CONCAT: case GROUP_CONCAT:
......
...@@ -11,14 +11,21 @@ import org.h2.value.ValueLong; ...@@ -11,14 +11,21 @@ import org.h2.value.ValueLong;
import org.h2.value.ValueNull; import org.h2.value.ValueNull;
/** /**
* Data stored while calculating an aggregate. * Data stored while calculating a COUNT aggregate.
*/ */
class AggregateDataCount extends AggregateData { class AggregateDataCount extends AggregateData {
private final boolean all;
private long count; private long count;
AggregateDataCount(boolean all) {
this.all = all;
}
@Override @Override
void add(Database database, int dataType, Value v) { void add(Database database, int dataType, Value v) {
if (v != ValueNull.INSTANCE) { if (all || v != ValueNull.INSTANCE) {
count++; count++;
} }
} }
......
/*
* Copyright 2004-2018 H2 Group. Multiple-Licensed under the MPL 2.0,
* and the EPL 1.0 (http://h2database.com/html/license.html).
* Initial Developer: H2 Group
*/
package org.h2.expression.aggregate;
import org.h2.engine.Database;
import org.h2.value.Value;
import org.h2.value.ValueLong;
/**
* Data stored while calculating a COUNT(*) aggregate.
*/
class AggregateDataCountAll extends AggregateData {
private long count;
@Override
void add(Database database, int dataType, Value v) {
count++;
}
@Override
Value getValue(Database database, int dataType) {
return ValueLong.get(count).convertTo(dataType);
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论