提交 b284e144 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Pass data type to constructor of aggregate data

上级 b86b2b26
......@@ -303,7 +303,7 @@ public class Aggregate extends AbstractAggregate {
v = updateCollecting(session, v, remembered);
}
}
data.add(session.getDatabase(), type.getValueType(), v);
data.add(session.getDatabase(), v);
}
@Override
......@@ -376,7 +376,7 @@ public class Aggregate extends AbstractAggregate {
@Override
protected Object createAggregateData() {
return AggregateData.create(aggregateType, distinct);
return AggregateData.create(aggregateType, distinct, type.getValueType());
}
@Override
......@@ -440,11 +440,11 @@ public class Aggregate extends AbstractAggregate {
if (c.getCount() == 0) {
return ValueNull.INSTANCE;
}
AggregateDataDefault d = new AggregateDataDefault(aggregateType);
AggregateDataDefault d = new AggregateDataDefault(aggregateType, type.getValueType());
Database db = session.getDatabase();
int dataType = type.getValueType();
for (Value v : c) {
d.add(db, dataType, v);
d.add(db, v);
}
return d.getValue(db, dataType);
}
......
......@@ -21,9 +21,10 @@ abstract class AggregateData {
*
* @param aggregateType the type of the aggregate operation
* @param distinct if the calculation should be distinct
* @param dataType the data type of the computed result
* @return the aggregate data object of the specified type
*/
static AggregateData create(AggregateType aggregateType, boolean distinct) {
static AggregateData create(AggregateType aggregateType, boolean distinct, int dataType) {
switch (aggregateType) {
case COUNT_ALL:
return new AggregateDataCount(true);
......@@ -42,7 +43,7 @@ abstract class AggregateData {
case BIT_AND:
case ANY:
case EVERY:
return new AggregateDataDefault(aggregateType);
return new AggregateDataDefault(aggregateType, dataType);
case SUM:
case AVG:
case STDDEV_POP:
......@@ -50,7 +51,7 @@ abstract class AggregateData {
case VAR_POP:
case VAR_SAMP:
if (!distinct) {
return new AggregateDataDefault(aggregateType);
return new AggregateDataDefault(aggregateType, dataType);
}
break;
case SELECTIVITY:
......@@ -71,10 +72,9 @@ abstract class AggregateData {
* Add a value to this aggregate.
*
* @param database the database
* @param dataType the datatype of the computed result
* @param v the value
*/
abstract void add(Database database, int dataType, Value v);
abstract void add(Database database, Value v);
/**
* Get the aggregate result.
......
......@@ -41,7 +41,7 @@ class AggregateDataCollecting extends AggregateData implements Iterable<Value> {
}
@Override
void add(Database database, int dataType, Value v) {
void add(Database database, Value v) {
if (v == ValueNull.INSTANCE) {
return;
}
......
......@@ -24,7 +24,7 @@ class AggregateDataCount extends AggregateData {
}
@Override
void add(Database database, int dataType, Value v) {
void add(Database database, Value v) {
if (all || v != ValueNull.INSTANCE) {
count++;
}
......
......@@ -21,19 +21,22 @@ import org.h2.value.ValueNull;
class AggregateDataDefault extends AggregateData {
private final AggregateType aggregateType;
private final int dataType;
private long count;
private Value value;
private double m2, mean;
/**
* @param aggregateType the type of the aggregate operation
* @param dataType the data type of the computed result
*/
AggregateDataDefault(AggregateType aggregateType) {
AggregateDataDefault(AggregateType aggregateType, int dataType) {
this.aggregateType = aggregateType;
this.dataType = dataType;
}
@Override
void add(Database database, int dataType, Value v) {
void add(Database database, Value v) {
if (v == ValueNull.INSTANCE) {
return;
}
......
......@@ -37,7 +37,7 @@ class AggregateDataDistinctWithCounts extends AggregateData {
}
@Override
void add(Database database, int dataType, Value v) {
void add(Database database, Value v) {
if (ignoreNulls && v == ValueNull.INSTANCE) {
return;
}
......
......@@ -57,7 +57,7 @@ class AggregateDataEnvelope extends AggregateData {
}
@Override
void add(Database database, int dataType, Value v) {
void add(Database database, Value v) {
if (v == ValueNull.INSTANCE) {
return;
}
......
......@@ -32,7 +32,7 @@ class AggregateDataSelectivity extends AggregateData {
}
@Override
void add(Database database, int dataType, Value v) {
void add(Database database, Value v) {
count++;
if (distinctHashes == null) {
distinctHashes = new IntIntHashMap();
......
......@@ -193,7 +193,7 @@ public class JavaAggregate extends AbstractAggregate {
arg = arg.convertTo(argTypes[i]);
argValues[i] = arg;
}
data.add(session.getDatabase(), dataType, args.length == 1 ? arg : ValueArray.get(argValues));
data.add(session.getDatabase(), args.length == 1 ? arg : ValueArray.get(argValues));
} else {
Aggregate agg = (Aggregate) aggregateData;
Object[] argValues = new Object[args.length];
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论