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.statement;
22
23 import org.apache.expreval.expr.node.GenericValue;
24 import org.apache.hadoop.hbase.hbql.client.ExecutionResults;
25 import org.apache.hadoop.hbase.hbql.client.HBqlException;
26 import org.apache.hadoop.hbase.hbql.impl.HConnectionImpl;
27 import org.apache.hadoop.hbase.hbql.statement.select.SimpleExpressionContext;
28
29 public class EvalStatement extends GenericStatement implements ConnectionStatement {
30
31 private final GenericValue genericValue;
32
33 public EvalStatement(final GenericValue genericValue) {
34 super(null);
35 this.genericValue = genericValue;
36 }
37
38 private GenericValue getGenericValue() {
39 return this.genericValue;
40 }
41
42 public ExecutionResults execute(HConnectionImpl connection) throws HBqlException {
43
44 final ExecutionResults retval = new ExecutionResults("Parsed successfully");
45
46 if (this.getGenericValue() != null) {
47 final SimpleExpressionContext expr = new SimpleExpressionContext(this.getGenericValue());
48 expr.validate();
49 final Object val = expr.getValue(connection);
50 retval.out.println(this.getGenericValue().asString() + " = " + val);
51 }
52
53 return retval;
54 }
55
56 public static String usage() {
57 return "EVAL expression";
58 }
59 }