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 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.io.parquet.write;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.common.type.HiveDecimal;
import org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe;
import org.apache.hadoop.hive.ql.io.parquet.timestamp.NanoTimeUtils;
import org.apache.hadoop.hive.serde2.io.DateWritable;
import org.apache.hadoop.hive.serde2.io.ParquetHiveRecord;
import org.apache.hadoop.hive.serde2.objectinspector.*;
import org.apache.hadoop.hive.serde2.objectinspector.primitive.*;
import org.apache.hadoop.hive.serde2.typeinfo.DecimalTypeInfo;
import parquet.io.api.Binary;
import parquet.io.api.RecordConsumer;
import parquet.schema.GroupType;
import parquet.schema.OriginalType;
import parquet.schema.Type;
import java.sql.Date;
import java.sql.Timestamp;
import java.util.List;
import java.util.Map;
/**
*
* DataWritableWriter is a writer that reads a ParquetWritable object and send the data to the Parquet
* API with the expected schema. This class is only used through DataWritableWriteSupport class.
*/
public class DataWritableWriter {
private static final Log LOG = LogFactory.getLog(DataWritableWriter.class);
private final RecordConsumer recordConsumer;
private final GroupType schema;
public DataWritableWriter(final RecordConsumer recordConsumer, final GroupType schema) {
this.recordConsumer = recordConsumer;
this.schema = schema;
}
/**
* It writes all record values to the Parquet RecordConsumer.
* @param record Contains the record that are going to be written.
*/
public void write(final ParquetHiveRecord record) {
if (record != null) {
recordConsumer.startMessage();
try {
writeGroupFields(record.getObject(), record.getObjectInspector(), schema);
} catch (RuntimeException e) {
String errorMessage = "Parquet record is malformed: " + e.getMessage();
LOG.error(errorMessage, e);
throw new RuntimeException(errorMessage, e);
}
recordConsumer.endMessage();
}
}
/**
* It writes all the fields contained inside a group to the RecordConsumer.
* @param value The list of values contained in the group.
* @param inspector The object inspector used to get the correct value type.
* @param type Type that contains information about the group schema.
*/
private void writeGroupFields(final Object value, final StructObjectInspector inspector, final GroupType type) {
if (value != null) {
List fields = inspector.getAllStructFieldRefs();
List