1 | /* |
2 | * Copyright 2004-2014 H2 Group. Multiple-Licensed under the MPL 2.0, |
3 | * and the EPL 1.0 (http://h2database.com/html/license.html). |
4 | * Initial Developer: H2 Group |
5 | */ |
6 | package org.h2.expression; |
7 | |
8 | import org.h2.engine.Database; |
9 | import org.h2.value.Value; |
10 | |
11 | /** |
12 | * Abstract class for the computation of an aggregate. |
13 | */ |
14 | abstract class AggregateData { |
15 | |
16 | /** |
17 | * Create an AggregateData object of the correct sub-type. |
18 | * |
19 | * @param aggregateType the type of the aggregate operation |
20 | * @return the aggregate data object of the specified type |
21 | */ |
22 | static AggregateData create(int aggregateType) { |
23 | if (aggregateType == Aggregate.SELECTIVITY) { |
24 | return new AggregateDataSelectivity(); |
25 | } else if (aggregateType == Aggregate.GROUP_CONCAT) { |
26 | return new AggregateDataGroupConcat(); |
27 | } else if (aggregateType == Aggregate.COUNT_ALL) { |
28 | return new AggregateDataCountAll(); |
29 | } else if (aggregateType == Aggregate.COUNT) { |
30 | return new AggregateDataCount(); |
31 | } else if (aggregateType == Aggregate.HISTOGRAM) { |
32 | return new AggregateDataHistogram(); |
33 | } else { |
34 | return new AggregateDataDefault(aggregateType); |
35 | } |
36 | } |
37 | |
38 | /** |
39 | * Add a value to this aggregate. |
40 | * |
41 | * @param database the database |
42 | * @param dataType the datatype of the computed result |
43 | * @param distinct if the calculation should be distinct |
44 | * @param v the value |
45 | */ |
46 | abstract void add(Database database, int dataType, boolean distinct, Value v); |
47 | |
48 | /** |
49 | * Get the aggregate result. |
50 | * |
51 | * @param database the database |
52 | * @param dataType the datatype of the computed result |
53 | * @param distinct if distinct is used |
54 | * @return the value |
55 | */ |
56 | abstract Value getValue(Database database, int dataType, boolean distinct); |
57 | } |