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.compare;
22
23 import org.apache.expreval.client.NullColumnValueException;
24 import org.apache.expreval.client.ResultMissingColumnException;
25 import org.apache.expreval.expr.Operator;
26 import org.apache.expreval.expr.TypeSupport;
27 import org.apache.expreval.expr.node.BooleanValue;
28 import org.apache.expreval.expr.node.ByteValue;
29 import org.apache.expreval.expr.node.DateValue;
30 import org.apache.expreval.expr.node.GenericValue;
31 import org.apache.expreval.expr.node.NumberValue;
32 import org.apache.expreval.expr.node.StringValue;
33 import org.apache.hadoop.hbase.filter.Filter;
34 import org.apache.hadoop.hbase.hbql.client.HBqlException;
35 import org.apache.hadoop.hbase.hbql.impl.HConnectionImpl;
36
37 public class DelegateCompare extends GenericCompare {
38
39 private GenericCompare typedExpr = null;
40
41 public DelegateCompare(final GenericValue arg0, final Operator operator, final GenericValue arg1) {
42 super(arg0, operator, arg1);
43 }
44
45 private GenericCompare getTypedExpr() {
46 return this.typedExpr;
47 }
48
49 public Class<? extends GenericValue> validateTypes(final GenericValue parentExpr,
50 final boolean allowCollections) throws HBqlException {
51
52 final Class<? extends GenericValue> type0 = this.getExprArg(0).validateTypes(this, false);
53 final Class<? extends GenericValue> type1 = this.getExprArg(1).validateTypes(this, false);
54
55 if (TypeSupport.isParentClass(StringValue.class, type0, type1))
56 this.typedExpr = new StringCompare(this.getExprArg(0), this.getOperator(), this.getExprArg(1));
57 else if (TypeSupport.isParentClass(NumberValue.class, type0, type1))
58 this.typedExpr = new NumberCompare(this.getExprArg(0), this.getOperator(), this.getExprArg(1));
59 else if (TypeSupport.isParentClass(DateValue.class, type0, type1))
60 this.typedExpr = new DateCompare(this.getExprArg(0), this.getOperator(), this.getExprArg(1));
61 else if (TypeSupport.isParentClass(BooleanValue.class, type0, type1))
62 this.typedExpr = new BooleanCompare(this.getExprArg(0), this.getOperator(), this.getExprArg(1));
63 else if (TypeSupport.isParentClass(ByteValue.class, type0, type1))
64 this.typedExpr = new ByteCompare(this.getExprArg(0), this.getOperator(), this.getExprArg(1));
65 else
66 this.throwInvalidTypeException(type0, type1);
67
68 return this.getTypedExpr().validateTypes(parentExpr, false);
69 }
70
71 public GenericValue getOptimizedValue() throws HBqlException {
72 this.optimizeAllArgs();
73 return !this.isAConstant() ? this : this.getTypedExpr().getOptimizedValue();
74 }
75
76 public Boolean getValue(final HConnectionImpl conn, final Object object) throws HBqlException,
77 ResultMissingColumnException,
78 NullColumnValueException {
79 return this.getTypedExpr().getValue(conn, object);
80 }
81
82 public Filter getFilter() throws HBqlException {
83 return this.getTypedExpr().getFilter();
84 }
85 }