1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.hadoop.hbase.hbql.impl;
22
23 import org.apache.expreval.client.NullColumnValueException;
24 import org.apache.expreval.client.ResultMissingColumnException;
25 import org.apache.hadoop.hbase.client.Result;
26 import org.apache.hadoop.hbase.hbql.client.HBqlException;
27 import org.apache.hadoop.hbase.hbql.mapping.MappingContext;
28 import org.apache.hadoop.hbase.hbql.statement.SelectStatement;
29 import org.apache.hadoop.hbase.hbql.statement.select.SelectElement;
30
31 import java.util.List;
32
33 public class AggregateRecord extends HRecordImpl {
34
35 final List<SelectElement> selectElementList;
36
37 private AggregateRecord(final MappingContext mappingContext,
38 final List<SelectElement> selectElementList) throws HBqlException {
39 super(mappingContext);
40
41 this.selectElementList = selectElementList;
42
43
44 this.getTableMapping().getKeyAttrib().setCurrentValue(this, 0, "");
45
46 for (final SelectElement selectElement : this.getSelectElementList()) {
47 final AggregateValue val = selectElement.newAggregateValue();
48 val.initAggregateValue();
49 this.addElement(val);
50 }
51 }
52
53 public static AggregateRecord newAggregateRecord(final SelectStatement selectStmt) throws HBqlException {
54 return (selectStmt.isAnAggregateQuery())
55 ? new AggregateRecord(selectStmt.getMappingContext(), selectStmt.getSelectElementList())
56 : null;
57 }
58
59 private List<SelectElement> getSelectElementList() {
60 return this.selectElementList;
61 }
62
63 public void applyValues(final Result result) throws HBqlException {
64
65 for (final ColumnValue val : this.getColumnValuesMap().values()) {
66 if (val instanceof AggregateValue) {
67 final AggregateValue aggregateValue = (AggregateValue)val;
68 try {
69 aggregateValue.applyValues(result);
70 }
71 catch (ResultMissingColumnException e) {
72
73 }
74 catch (NullColumnValueException e) {
75
76 }
77 }
78 }
79 }
80 }