org.apache.hadoop.hive.serde2.columnar.ColumnarStructBase 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.serde2.columnar;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.hadoop.hive.serde2.SerDeStatsStruct;
import org.apache.hadoop.hive.serde2.StructObject;
import org.apache.hadoop.hive.serde2.lazy.ByteArrayRef;
import org.apache.hadoop.hive.serde2.lazy.LazyObjectBase;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.StructField;
import org.apache.hadoop.hive.serde2.objectinspector.StructObjectInspector;
public abstract class ColumnarStructBase implements StructObject, SerDeStatsStruct {
class FieldInfo {
LazyObjectBase field;
/*
* use an array instead of only one object in case in future hive does not do
* the byte copy.
*/
ByteArrayRef cachedByteArrayRef;
BytesRefWritable rawBytesField;
boolean inited;
boolean fieldSkipped;
ObjectInspector objectInspector;
public FieldInfo(LazyObjectBase lazyObject, boolean fieldSkipped, ObjectInspector oi) {
field = lazyObject;
cachedByteArrayRef = new ByteArrayRef();
objectInspector = oi;
if (fieldSkipped) {
this.fieldSkipped = true;
inited = true;
} else {
inited = false;
}
}
/*
* ============================ [PERF] ===================================
* This function is called for every row. Setting up the selected/projected
* columns at the first call, and don't do that for the following calls.
* Ideally this should be done in the constructor where we don't need to
* branch in the function for each row.
* =========================================================================
*/
public void init(BytesRefWritable col) {
if (col != null) {
rawBytesField = col;
inited = false;
fieldSkipped = false;
} else {
// select columns that actually do not exist in the file.
fieldSkipped = true;
}
}
/**
* Return the uncompressed size of this field
*/
public long getSerializedSize() {
if (rawBytesField == null) {
return 0;
}
return rawBytesField.getLength();
}
/**
* Get the field out of the row without checking parsed. This is called by
* both getField and getFieldsAsList.
*
* @return The value of the field
*/
protected Object uncheckedGetField() {
if (fieldSkipped) {
return null;
}
if (!inited) {
try {
cachedByteArrayRef.setData(rawBytesField.getData());
} catch (IOException e) {
throw new RuntimeException(e);
}
inited = true;
int byteLength = getLength(objectInspector, cachedByteArrayRef, rawBytesField.getStart(),
rawBytesField.getLength());
if (byteLength == -1) {
return null;
}
field.init(cachedByteArrayRef, rawBytesField.getStart(), byteLength);
return field.getObject();
} else {
if (getLength(objectInspector, cachedByteArrayRef, rawBytesField.getStart(),
rawBytesField.getLength()) == -1) {
return null;
}
return field.getObject();
}
}
}
protected int[] prjColIDs = null;
private FieldInfo[] fieldInfoList = null;
private ArrayList
© 2015 - 2024 Weber Informatics LLC | Privacy Policy