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.nullcomp;
22
23 import org.apache.expreval.client.ResultMissingColumnException;
24 import org.apache.expreval.expr.TypeSupport;
25 import org.apache.expreval.expr.node.BooleanValue;
26 import org.apache.expreval.expr.node.ByteValue;
27 import org.apache.expreval.expr.node.DateValue;
28 import org.apache.expreval.expr.node.GenericValue;
29 import org.apache.expreval.expr.node.NumberValue;
30 import org.apache.expreval.expr.node.ObjectValue;
31 import org.apache.expreval.expr.node.StringValue;
32 import org.apache.hadoop.hbase.hbql.client.HBqlException;
33 import org.apache.hadoop.hbase.hbql.impl.HConnectionImpl;
34
35 public class DelegateNullCompare extends GenericNullCompare {
36
37 public DelegateNullCompare(final boolean not, final GenericValue expr) {
38 super(null, not, expr);
39 }
40
41 public Class<? extends GenericValue> validateTypes(final GenericValue parentExpr,
42 final boolean allowCollections) throws HBqlException {
43
44 final GenericValue genericValue = this.getExprArg(0);
45 final Class<? extends GenericValue> validatedValue = genericValue.validateTypes(this, false);
46 final Class<? extends GenericValue> type = this.getGenericValueClass(validatedValue);
47
48 final GenericNullCompare typedExpr;
49 if (TypeSupport.isParentClass(StringValue.class, type))
50 typedExpr = new StringNullCompare(this.isNot(), this.getExprArg(0));
51 else if (TypeSupport.isParentClass(NumberValue.class, type))
52 typedExpr = new NumberNullCompare(this.isNot(), this.getExprArg(0));
53 else if (TypeSupport.isParentClass(DateValue.class, type))
54 typedExpr = new DateNullCompare(this.isNot(), this.getExprArg(0));
55 else if (TypeSupport.isParentClass(BooleanValue.class, type))
56 typedExpr = new BooleanNullCompare(this.isNot(), this.getExprArg(0));
57 else if (TypeSupport.isParentClass(ByteValue.class, type))
58 typedExpr = new ByteNullCompare(this.isNot(), this.getExprArg(0));
59 else if (TypeSupport.isParentClass(ObjectValue.class, type))
60 typedExpr = new ObjectNullCompare(this.isNot(), this.getExprArg(0));
61 else {
62 typedExpr = null;
63 this.throwInvalidTypeException(type);
64 }
65
66 this.setTypedExpr(typedExpr);
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 return this.getTypedExpr().getValue(conn, object);
79 }
80 }