Package org.apache.hadoop.hive.ql.plan

Source Code of org.apache.hadoop.hive.ql.plan.ExprNodeFieldDesc

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.hadoop.hive.ql.plan;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.facebook.presto.hive.shaded.org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.hadoop.hive.ql.exec.Utilities;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;

/**
* ExprNodeFieldDesc.
*
*/
public class ExprNodeFieldDesc extends ExprNodeDesc implements Serializable {
  private static final long serialVersionUID = 1L;
  ExprNodeDesc desc;
  String fieldName;

  // Used to support a.b where a is a list of struct that contains a field
  // called b.
  // a.b will return an array that contains field b of all elements of array a.
  Boolean isList;

  public ExprNodeFieldDesc() {
  }

  public ExprNodeFieldDesc(TypeInfo typeInfo, ExprNodeDesc desc,
      String fieldName, Boolean isList) {
    super(typeInfo);
    this.desc = desc;
    this.fieldName = fieldName;
    this.isList = isList;
  }

  @Override
  public List<ExprNodeDesc> getChildren() {
    List<ExprNodeDesc> children = new ArrayList<ExprNodeDesc>(2);
    children.add(desc);
    return children;
  }

  public ExprNodeDesc getDesc() {
    return desc;
  }

  public void setDesc(ExprNodeDesc desc) {
    this.desc = desc;
  }

  public String getFieldName() {
    return fieldName;
  }

  public void setFieldName(String fieldName) {
    this.fieldName = fieldName;
  }

  public Boolean getIsList() {
    return isList;
  }

  public void setIsList(Boolean isList) {
    this.isList = isList;
  }

  @Override
  public String toString() {
    return desc.toString() + "." + fieldName;
  }

  @Override
  public String getExprString() {
    return desc.getExprString() + "." + fieldName;
  }

  @Override
  public List<String> getCols() {
    List<String> colList = new ArrayList<String>();
    if (desc != null) {
      colList = Utilities.mergeUniqElems(colList, desc.getCols());
    }
    return colList;
  }

  @Override
  public ExprNodeDesc clone() {
    return new ExprNodeFieldDesc(typeInfo, desc, fieldName, isList);
  }

  @Override
  public boolean isSame(Object o) {
    if (!(o instanceof ExprNodeFieldDesc)) {
      return false;
    }
    ExprNodeFieldDesc dest = (ExprNodeFieldDesc) o;
    if (!typeInfo.equals(dest.getTypeInfo())) {
      return false;
    }
    if (!fieldName.equals(dest.getFieldName())
        || !isList.equals(dest.getIsList()) || !desc.isSame(dest.getDesc())) {
      return false;
    }

    return true;
  }

  @Override
  public int hashCode() {
    int superHashCode = super.hashCode();
    HashCodeBuilder builder = new HashCodeBuilder();
    builder.appendSuper(superHashCode);
    builder.append(desc);
    builder.append(fieldName);
    builder.append(isList);
    return builder.toHashCode();
  }
}
TOP

Related Classes of org.apache.hadoop.hive.ql.plan.ExprNodeFieldDesc

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.