PageRenderTime 27ms CodeModel.GetById 14ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/tags/release-0.0.0-rc0/hive/external/ql/src/java/org/apache/hadoop/hive/ql/plan/ExprNodeFieldDesc.java

#
Java | 125 lines | 81 code | 20 blank | 24 comment | 7 complexity | ae3f3d0455cfd8201bbe97cfe348d704 MD5 | raw file
  1/**
  2 * Licensed to the Apache Software Foundation (ASF) under one
  3 * or more contributor license agreements.  See the NOTICE file
  4 * distributed with this work for additional information
  5 * regarding copyright ownership.  The ASF licenses this file
  6 * to you under the Apache License, Version 2.0 (the
  7 * "License"); you may not use this file except in compliance
  8 * with the License.  You may obtain a copy of the License at
  9 *
 10 *     http://www.apache.org/licenses/LICENSE-2.0
 11 *
 12 * Unless required by applicable law or agreed to in writing, software
 13 * distributed under the License is distributed on an "AS IS" BASIS,
 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15 * See the License for the specific language governing permissions and
 16 * limitations under the License.
 17 */
 18
 19package org.apache.hadoop.hive.ql.plan;
 20
 21import java.io.Serializable;
 22import java.util.ArrayList;
 23import java.util.List;
 24
 25import org.apache.hadoop.hive.ql.exec.Utilities;
 26import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
 27
 28/**
 29 * ExprNodeFieldDesc.
 30 *
 31 */
 32public class ExprNodeFieldDesc extends ExprNodeDesc implements Serializable {
 33  private static final long serialVersionUID = 1L;
 34  ExprNodeDesc desc;
 35  String fieldName;
 36
 37  // Used to support a.b where a is a list of struct that contains a field
 38  // called b.
 39  // a.b will return an array that contains field b of all elements of array a.
 40  Boolean isList;
 41
 42  public ExprNodeFieldDesc() {
 43  }
 44
 45  public ExprNodeFieldDesc(TypeInfo typeInfo, ExprNodeDesc desc,
 46      String fieldName, Boolean isList) {
 47    super(typeInfo);
 48    this.desc = desc;
 49    this.fieldName = fieldName;
 50    this.isList = isList;
 51  }
 52
 53  @Override
 54  public List<ExprNodeDesc> getChildren() {
 55    List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>(2);
 56    children.add(desc);
 57    return children;
 58  }
 59
 60  public ExprNodeDesc getDesc() {
 61    return desc;
 62  }
 63
 64  public void setDesc(ExprNodeDesc desc) {
 65    this.desc = desc;
 66  }
 67
 68  public String getFieldName() {
 69    return fieldName;
 70  }
 71
 72  public void setFieldName(String fieldName) {
 73    this.fieldName = fieldName;
 74  }
 75
 76  public Boolean getIsList() {
 77    return isList;
 78  }
 79
 80  public void setIsList(Boolean isList) {
 81    this.isList = isList;
 82  }
 83
 84  @Override
 85  public String toString() {
 86    return desc.toString() + "." + fieldName;
 87  }
 88
 89  @Explain(displayName = "expr")
 90  @Override
 91  public String getExprString() {
 92    return desc.getExprString() + "." + fieldName;
 93  }
 94
 95  @Override
 96  public List<String> getCols() {
 97    List<String> colList = new ArrayList<String>();
 98    if (desc != null) {
 99      colList = Utilities.mergeUniqElems(colList, desc.getCols());
100    }
101    return colList;
102  }
103
104  @Override
105  public ExprNodeDesc clone() {
106    return new ExprNodeFieldDesc(typeInfo, desc, fieldName, isList);
107  }
108
109  @Override
110  public boolean isSame(Object o) {
111    if (!(o instanceof ExprNodeFieldDesc)) {
112      return false;
113    }
114    ExprNodeFieldDesc dest = (ExprNodeFieldDesc) o;
115    if (!typeInfo.equals(dest.getTypeInfo())) {
116      return false;
117    }
118    if (!fieldName.equals(dest.getFieldName())
119        || !isList.equals(dest.getIsList()) || !desc.isSame(dest.getDesc())) {
120      return false;
121    }
122
123    return true;
124  }
125}