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