All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.hadoop.hive.ql.exec.SelectOperator Maven / Gradle / Ivy

The newest version!
/**
 * 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.exec;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.Future;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hive.conf.HiveConf;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.plan.ExprNodeColumnDesc;
import org.apache.hadoop.hive.ql.plan.ExprNodeDesc;
import org.apache.hadoop.hive.ql.plan.SelectDesc;
import org.apache.hadoop.hive.ql.plan.api.OperatorType;

/**
 * Select operator implementation.
 */
public class SelectOperator extends Operator implements Serializable {

  private static final long serialVersionUID = 1L;
  protected transient ExprNodeEvaluator[] eval;

  transient Object[] output;

  private transient boolean isSelectStarNoCompute = false;

  @Override
  protected Collection> initializeOp(Configuration hconf) throws HiveException {
    Collection> result = super.initializeOp(hconf);
    // Just forward the row as is
    if (conf.isSelStarNoCompute()) {
      isSelectStarNoCompute = true;
      return result;
    }
    List colList = conf.getColList();
    eval = new ExprNodeEvaluator[colList.size()];
    for (int i = 0; i < colList.size(); i++) {
      assert (colList.get(i) != null);
      eval[i] = ExprNodeEvaluatorFactory.get(colList.get(i));
    }
    if (HiveConf.getBoolVar(hconf, HiveConf.ConfVars.HIVEEXPREVALUATIONCACHE)) {
      eval = ExprNodeEvaluatorFactory.toCachedEvals(eval);
    }
    output = new Object[eval.length];
    if (isLogInfoEnabled) {
      LOG.info("SELECT " + inputObjInspectors[0].getTypeName());
    }
    outputObjInspector = initEvaluatorsAndReturnStruct(eval, conf.getOutputColumnNames(),
        inputObjInspectors[0]);
    return result;
  }

  @Override
  public void process(Object row, int tag) throws HiveException {
    if (isSelectStarNoCompute) {
      forward(row, inputObjInspectors[tag]);
      return;
    }
    int i = 0;
    try {
      for (; i < eval.length; ++i) {
        output[i] = eval[i].evaluate(row);
      }
    } catch (HiveException e) {
      throw e;
    } catch (RuntimeException e) {
      throw new HiveException("Error evaluating " + conf.getColList().get(i).getExprString(), e);
    }
    forward(output, outputObjInspector);
  }

  /**
   * @return the name of the operator
   */
  @Override
  public String getName() {
    return getOperatorName();
  }

  static public String getOperatorName() {
    return "SEL";
  }

  @Override
  public OperatorType getType() {
    return OperatorType.SELECT;
  }

  @Override
  public boolean supportSkewJoinOptimization() {
    return true;
  }

  @Override
  public boolean columnNamesRowResolvedCanBeObtained() {
    return true;
  }

  @Override
  public boolean supportAutomaticSortMergeJoin() {
    return true;
  }

  @Override
  public boolean supportUnionRemoveOptimization() {
    return true;
  }

  @Override
  public boolean acceptLimitPushdown() {
    return true;
  }

  /**
   * Checks whether this select operator does something to the
   * input tuples.
   *
   * @return if it is an identity select operator or not
   */
  public boolean isIdentitySelect() {
    // Safety check
    if(this.getNumParent() != 1) {
      return false;
    }

    if(conf.isSelStarNoCompute()) {
      return true;
    }

    // Check whether the have the same schema
    RowSchema orig = this.getSchema();
    RowSchema dest = this.getParentOperators().get(0).getSchema();
    if(orig.getSignature() == null && dest.getSignature() == null) {
      return true;
    }
    if((orig.getSignature() == null && dest.getSignature() != null) ||
        (orig.getSignature() != null && dest.getSignature() == null) ) {
      return false;
    }

    if(orig.getSignature().size() != dest.getSignature().size() ||
            orig.getSignature().size() != conf.getColList().size()) {
      return false;
    }

    for(int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy