Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* 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.avro;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.avro.Schema;
import org.apache.avro.file.DataFileStream;
import org.apache.avro.generic.GenericDatumReader;
import org.apache.avro.generic.GenericRecord;
import org.apache.avro.io.DatumReader;
import com.facebook.presto.hive.$internal.org.apache.commons.lang.ClassUtils;
import com.facebook.presto.hive.$internal.org.apache.commons.logging.Log;
import com.facebook.presto.hive.$internal.org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.serde2.SerDeException;
import org.apache.hadoop.hive.serde2.lazy.ByteArrayRef;
import org.apache.hadoop.hive.serde2.lazy.LazyArray;
import org.apache.hadoop.hive.serde2.lazy.LazyFactory;
import org.apache.hadoop.hive.serde2.lazy.LazyMap;
import org.apache.hadoop.hive.serde2.lazy.LazyObject;
import org.apache.hadoop.hive.serde2.lazy.LazyStruct;
import org.apache.hadoop.hive.serde2.lazy.LazyUnion;
import org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyListObjectInspector;
import org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyMapObjectInspector;
import org.apache.hadoop.hive.serde2.lazy.objectinspector.LazySimpleStructObjectInspector;
import org.apache.hadoop.hive.serde2.lazy.objectinspector.LazyUnionObjectInspector;
import org.apache.hadoop.hive.serde2.lazy.objectinspector.primitive.LazyObjectInspectorParameters;
import org.apache.hadoop.hive.serde2.objectinspector.ListObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.MapObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.ObjectInspector;
import org.apache.hadoop.hive.serde2.objectinspector.StandardUnionObjectInspector.StandardUnion;
import org.apache.hadoop.hive.serde2.objectinspector.StructField;
import org.apache.hadoop.io.Text;
/**
* Lazy objectinspector for avro serialization
* */
public class AvroLazyObjectInspector extends LazySimpleStructObjectInspector {
/**
* Reader {@link Schema} for the avro data
* */
private Schema readerSchema;
/**
* {@link AvroSchemaRetriever} to retrieve avro schema
* */
private AvroSchemaRetriever schemaRetriever;
/**
* LOGGER
* */
public static final Log LOG = LogFactory.getLog(AvroLazyObjectInspector.class);
/**
* Constructor
*
* @param structFieldNames fields within the given protobuf object
* @param structFieldObjectInspectors object inspectors for the fields
* @param structFieldComments comments for the given fields
* @param separator separator between different fields
* @param nullSequence sequence to represent null value
* @param lastColumnTakesRest whether the last column of the struct should take the rest of the
* row if there are extra fields.
* @param escaped whether the data is escaped or not
* @param escapeChar if escaped is true, the escape character
* */
@Deprecated
public AvroLazyObjectInspector(List structFieldNames,
List structFieldObjectInspectors, List structFieldComments,
byte separator, Text nullSequence, boolean lastColumnTakesRest, boolean escaped,
byte escapeChar) {
super(structFieldNames, structFieldObjectInspectors, structFieldComments, separator,
nullSequence, lastColumnTakesRest, escaped, escapeChar);
}
public AvroLazyObjectInspector(List structFieldNames,
List structFieldObjectInspectors, List structFieldComments,
byte separator, LazyObjectInspectorParameters lazyParams) {
super(structFieldNames, structFieldObjectInspectors, structFieldComments, separator, lazyParams);
}
/**
* Set the reader schema for the {@link AvroLazyObjectInspector} to the given schema
* */
public void setReaderSchema(Schema readerSchema) {
this.readerSchema = readerSchema;
}
/**
* Set the {@link AvroSchemaRetriever} for the {@link AvroLazyObjectInspector} to the given class
*
* @param scheamRetrieverClass the schema retriever class to be set
* */
public void setSchemaRetriever(AvroSchemaRetriever schemaRetriever) {
this.schemaRetriever = schemaRetriever;
}
@SuppressWarnings("unchecked")
@Override
public Object getStructFieldData(Object data, StructField f) {
if (data == null) {
return null;
}
int fieldID = f.getFieldID();
if (LOG.isDebugEnabled()) {
LOG.debug("Getting struct field data for field: [" + f.getFieldName() + "] on data ["
+ data.getClass() + "]");
}
if (data instanceof LazyStruct) {
LazyStruct row = (LazyStruct) data;
// get the field out of struct
Object rowField = row.getField(fieldID);
if (rowField instanceof LazyStruct) {
if (LOG.isDebugEnabled()) {
LOG.debug("Deserializing struct [" + rowField.getClass() + "]");
}
return deserializeStruct(rowField, f.getFieldName());
} else if (rowField instanceof LazyMap) {
// We have found a map. Systematically deserialize the values of the map and return back the
// map
LazyMap lazyMap = (LazyMap) rowField;
for (Entry