org.apache.hadoop.hive.ql.exec.vector.VectorHashKeyWrapperBatch Maven / Gradle / Ivy
/*
* 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 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.ql.exec.vector.ColumnVector.Type;
import org.apache.hadoop.hive.serde2.typeinfo.TypeInfo;
/**
* 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;
/**
* Shared hashcontext for all keys in this batch
*/
private final VectorHashKeyWrapper.HashContext hashCtx = new VectorHashKeyWrapper.HashContext();
/**
* 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 {
if (keyCount == 0) {
// all keywrappers must be EmptyVectorHashKeyWrapper
return;
}
for(int i=0;i