View Javadoc

1   /*
2    * Copyright (c) 2011.  The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
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 }