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;
22
23 import org.apache.expreval.client.NullColumnValueException;
24 import org.apache.expreval.client.ResultMissingColumnException;
25 import org.apache.expreval.expr.literal.BooleanLiteral;
26 import org.apache.expreval.expr.node.BooleanValue;
27 import org.apache.expreval.expr.node.GenericValue;
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.HConnectionImpl;
31 import org.apache.hadoop.hbase.hbql.mapping.Mapping;
32 import org.apache.hadoop.hbase.hbql.mapping.MappingContext;
33
34 public class ExpressionTree extends MultipleExpressionContext {
35
36 private static FunctionTypeSignature exprSig = new FunctionTypeSignature(BooleanValue.class, BooleanValue.class);
37
38 private boolean useResultData = false;
39 private boolean allowColumns = true;
40
41 private Mapping embeddedMapping = null;
42
43 public ExpressionTree() {
44 }
45
46 private ExpressionTree(final GenericValue rootValue) {
47 super(exprSig, rootValue);
48 }
49
50 public static ExpressionTree newExpressionTree(final Mapping mapping, final GenericValue booleanValue) {
51 final ExpressionTree tree = new ExpressionTree(booleanValue == null ? new BooleanLiteral(true) : booleanValue);
52
53 tree.embeddedMapping = mapping;
54 return tree;
55 }
56
57
58 public void setEmbeddedMapping() throws HBqlException {
59 if (this.embeddedMapping != null)
60 this.setMappingContext(new MappingContext(this.embeddedMapping));
61 }
62
63 public Boolean evaluate(final HConnectionImpl conn, final Object object) throws HBqlException,
64 ResultMissingColumnException,
65 NullColumnValueException {
66 return (Boolean)this.evaluate(conn, 0, this.allowColumns(), false, object);
67 }
68
69 private GenericValue getGenericValue() {
70 return this.getGenericValue(0);
71 }
72
73 public Filter getFilter() throws HBqlException {
74 this.validateTypes(true, true);
75 this.optimize();
76 return this.getGenericValue().getFilter();
77 }
78
79 public String asString() {
80 return this.getGenericValue().asString();
81 }
82
83 public void setUseResultData(final boolean useResultData) {
84 this.useResultData = useResultData;
85 }
86
87 public boolean useResultData() {
88 return this.useResultData;
89 }
90
91 public boolean allowColumns() {
92 return this.allowColumns;
93 }
94
95 public void setAllowColumns(final boolean allowColumns) {
96 this.allowColumns = allowColumns;
97 }
98 }