1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.expreval.expr.var;
22
23 import org.apache.expreval.client.InternalErrorException;
24 import org.apache.expreval.expr.MultipleExpressionContext;
25 import org.apache.expreval.expr.node.GenericValue;
26 import org.apache.expreval.expr.node.ObjectValue;
27 import org.apache.hadoop.hbase.client.Result;
28 import org.apache.hadoop.hbase.filter.Filter;
29 import org.apache.hadoop.hbase.hbql.client.HBqlException;
30 import org.apache.hadoop.hbase.hbql.impl.AggregateValue;
31 import org.apache.hadoop.hbase.hbql.impl.InvalidServerFilterException;
32 import org.apache.hadoop.hbase.hbql.mapping.ColumnAttrib;
33 import org.apache.hadoop.hbase.hbql.mapping.FieldType;
34
35 public abstract class GenericColumn<T extends GenericValue> implements GenericValue {
36
37 private final ColumnAttrib columnAttrib;
38 private MultipleExpressionContext expressionContext = null;
39
40 protected GenericColumn(final ColumnAttrib attrib) {
41 this.columnAttrib = attrib;
42 }
43
44 protected FieldType getFieldType() {
45 return this.getColumnAttrib().getFieldType();
46 }
47
48 public ColumnAttrib getColumnAttrib() {
49 return this.columnAttrib;
50 }
51
52 public String getVariableName() {
53 return this.getColumnAttrib().getFamilyQualifiedName();
54 }
55
56 public T getOptimizedValue() throws HBqlException {
57 return (T)this;
58 }
59
60 public boolean isAConstant() {
61 return false;
62 }
63
64 public boolean isDefaultKeyword() {
65 return false;
66 }
67
68 public boolean isAnAggregateValue() {
69 return false;
70 }
71
72 public void initAggregateValue(final AggregateValue aggregateValue) throws HBqlException {
73 throw new InternalErrorException("Not applicable");
74 }
75
76 public void applyResultToAggregateValue(final AggregateValue aggregateValue, final Result result) throws HBqlException {
77 throw new InternalErrorException("Not applicable");
78 }
79
80 public boolean hasAColumnReference() {
81 return true;
82 }
83
84 public boolean isAColumnReference() {
85 return true;
86 }
87
88 public void reset() {
89 if (this.getExpressionContext() != null)
90 this.getExpressionContext().reset();
91 }
92
93 public void setExpressionContext(final MultipleExpressionContext context) throws HBqlException {
94 this.expressionContext = context;
95 this.getExpressionContext().addColumnToUsedList(this);
96 }
97
98 protected MultipleExpressionContext getExpressionContext() {
99 return this.expressionContext;
100 }
101
102 public Class<? extends GenericValue> validateTypes(final GenericValue parentExpr,
103 final boolean allowCollections) throws HBqlException {
104
105 if (this.getColumnAttrib().isAnArray())
106 return ObjectValue.class;
107 else
108 return this.getFieldType().getExprType();
109 }
110
111 public String asString() {
112 return this.getVariableName();
113 }
114
115 public Filter getFilter() throws HBqlException {
116 throw new InvalidServerFilterException();
117 }
118 }