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

org.apache.hadoop.hive.ql.exec.vector.VectorHashKeyWrapperBatch 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.vector;

import java.util.Arrays;

import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpression;
import org.apache.hadoop.hive.ql.exec.vector.expressions.VectorExpressionWriter;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.util.JavaDataModel;
import org.apache.hadoop.hive.serde2.lazybinary.LazyBinarySerDe;

/**
 * Class for handling vectorized hash map key wrappers. It evaluates the key columns in a
 * row batch in a vectorized fashion.
 * This class stores additional information about keys needed to evaluate and output the key values.
 *
 */
public class VectorHashKeyWrapperBatch extends VectorColumnSetInfo {

  public VectorHashKeyWrapperBatch(int keyCount) {
    super(keyCount);
  }

  /**
   * Number of object references in 'this' (for size computation)
   */
  private static final int MODEL_REFERENCES_COUNT = 7;

  /**
   * The key expressions that require evaluation and output the primitive values for each key.
   */
  private VectorExpression[] keyExpressions;

  /**
   * Pre-allocated batch size vector of keys wrappers.
   * N.B. these keys are **mutable** and should never be used in a HashMap.
   * Always clone the key wrapper to obtain an immutable keywrapper suitable
   * to use a key in a HashMap.
   */
  private VectorHashKeyWrapper[] vectorHashKeyWrappers;

  /**
   * The fixed size of the key wrappers.
   */
  private int keysFixedSize;

   /**
   * Returns the compiled fixed size for the key wrappers.
   * @return
   */
  public int getKeysFixedSize() {
    return keysFixedSize;
  }

  /**
   * Accessor for the batch-sized array of key wrappers.
   */
  public VectorHashKeyWrapper[] getVectorHashKeyWrappers() {
    return vectorHashKeyWrappers;
  }

  /**
   * Processes a batch:
   * 
    *
  • Evaluates each key vector expression.
  • *
  • Copies out each key's primitive values into the key wrappers
  • *
  • computes the hashcode of the key wrappers
  • *
* @param batch * @throws HiveException */ public void evaluateBatch(VectorizedRowBatch batch) throws HiveException { for(int i = 0; i < keyExpressions.length; ++i) { keyExpressions[i].evaluate(batch); } for(int i = 0; i< longIndices.length; ++i) { int keyIndex = longIndices[i]; int columnIndex = keyExpressions[keyIndex].getOutputColumn(); LongColumnVector columnVector = (LongColumnVector) batch.cols[columnIndex]; if (columnVector.noNulls && !columnVector.isRepeating && !batch.selectedInUse) { assignLongNoNullsNoRepeatingNoSelection(i, batch.size, columnVector); } else if (columnVector.noNulls && !columnVector.isRepeating && batch.selectedInUse) { assignLongNoNullsNoRepeatingSelection(i, batch.size, columnVector, batch.selected); } else if (columnVector.noNulls && columnVector.isRepeating) { assignLongNoNullsRepeating(i, batch.size, columnVector); } else if (!columnVector.noNulls && !columnVector.isRepeating && !batch.selectedInUse) { assignLongNullsNoRepeatingNoSelection(i, batch.size, columnVector); } else if (!columnVector.noNulls && columnVector.isRepeating) { assignLongNullsRepeating(i, batch.size, columnVector); } else if (!columnVector.noNulls && !columnVector.isRepeating && batch.selectedInUse) { assignLongNullsNoRepeatingSelection (i, batch.size, columnVector, batch.selected); } else { throw new HiveException (String.format( "Unimplemented Long null/repeat/selected combination %b/%b/%b", columnVector.noNulls, columnVector.isRepeating, batch.selectedInUse)); } } for(int i=0;i= 0) { return kw.getIsLongNull(klh.longIndex) ? null : keyOutputWriter.writeValue(kw.getLongValue(klh.longIndex)); } else if (klh.doubleIndex >= 0) { return kw.getIsDoubleNull(klh.doubleIndex) ? null : keyOutputWriter.writeValue(kw.getDoubleValue(klh.doubleIndex)); } else if (klh.stringIndex >= 0) { return kw.getIsBytesNull(klh.stringIndex) ? null : keyOutputWriter.writeValue( kw.getBytes(klh.stringIndex), kw.getByteStart(klh.stringIndex), kw.getByteLength(klh.stringIndex)); } else if (klh.decimalIndex >= 0) { return kw.getIsDecimalNull(klh.decimalIndex)? null : keyOutputWriter.writeValue( kw.getDecimal(klh.decimalIndex).getHiveDecimal()); } else { throw new HiveException(String.format( "Internal inconsistent KeyLookupHelper at index [%d]:%d %d %d %d", i, klh.longIndex, klh.doubleIndex, klh.stringIndex, klh.decimalIndex)); } } public int getVariableSize(int batchSize) { int variableSize = 0; if ( 0 < stringIndices.length) { for (int k=0; k




© 2015 - 2024 Weber Informatics LLC | Privacy Policy