Search in sources :

Example 6 with ParquetEncodingException

use of org.apache.parquet.io.ParquetEncodingException in project parquet-mr by apache.

the class TupleWriteSupport method writeValue.

private void writeValue(Type type, FieldSchema pigType, Tuple t, int i) {
    try {
        if (type.isPrimitive()) {
            switch(type.asPrimitiveType().getPrimitiveTypeName()) {
                // TODO: use PrimitiveTuple accessors
                case BINARY:
                    byte[] bytes;
                    if (pigType.type == DataType.BYTEARRAY) {
                        bytes = ((DataByteArray) t.get(i)).get();
                    } else if (pigType.type == DataType.CHARARRAY) {
                        bytes = ((String) t.get(i)).getBytes("UTF-8");
                    } else {
                        throw new UnsupportedOperationException("can not convert from " + DataType.findTypeName(pigType.type) + " to BINARY ");
                    }
                    recordConsumer.addBinary(Binary.fromReusedByteArray(bytes));
                    break;
                case BOOLEAN:
                    recordConsumer.addBoolean((Boolean) t.get(i));
                    break;
                case INT32:
                    recordConsumer.addInteger(((Number) t.get(i)).intValue());
                    break;
                case INT64:
                    recordConsumer.addLong(((Number) t.get(i)).longValue());
                    break;
                case DOUBLE:
                    recordConsumer.addDouble(((Number) t.get(i)).doubleValue());
                    break;
                case FLOAT:
                    recordConsumer.addFloat(((Number) t.get(i)).floatValue());
                    break;
                default:
                    throw new UnsupportedOperationException(type.asPrimitiveType().getPrimitiveTypeName().name());
            }
        } else {
            assert pigType.type == DataType.TUPLE;
            recordConsumer.startGroup();
            writeTuple(type.asGroupType(), pigType.schema, (Tuple) t.get(i));
            recordConsumer.endGroup();
        }
    } catch (Exception e) {
        throw new ParquetEncodingException("can not write value at " + i + " in tuple " + t + " from type '" + pigType + "' to type '" + type + "'", e);
    }
}
Also used : ParquetEncodingException(org.apache.parquet.io.ParquetEncodingException) FrontendException(org.apache.pig.impl.logicalLayer.FrontendException) ExecException(org.apache.pig.backend.executionengine.ExecException) ParserException(org.apache.pig.parser.ParserException) ParquetEncodingException(org.apache.parquet.io.ParquetEncodingException)

Example 7 with ParquetEncodingException

use of org.apache.parquet.io.ParquetEncodingException in project parquet-mr by apache.

the class DeltaLengthByteArrayValuesWriter method writeBytes.

@Override
public void writeBytes(Binary v) {
    try {
        lengthWriter.writeInteger(v.length());
        v.writeTo(out);
    } catch (IOException e) {
        throw new ParquetEncodingException("could not write bytes", e);
    }
}
Also used : ParquetEncodingException(org.apache.parquet.io.ParquetEncodingException) IOException(java.io.IOException)

Example 8 with ParquetEncodingException

use of org.apache.parquet.io.ParquetEncodingException in project parquet-mr by apache.

the class ColumnWriterV1 method writePage.

private void writePage() {
    if (DEBUG)
        LOG.debug("write page");
    try {
        pageWriter.writePage(concat(repetitionLevelColumn.getBytes(), definitionLevelColumn.getBytes(), dataColumn.getBytes()), valueCount, statistics, repetitionLevelColumn.getEncoding(), definitionLevelColumn.getEncoding(), dataColumn.getEncoding());
    } catch (IOException e) {
        throw new ParquetEncodingException("could not write page for " + path, e);
    }
    repetitionLevelColumn.reset();
    definitionLevelColumn.reset();
    dataColumn.reset();
    valueCount = 0;
    resetStatistics();
}
Also used : ParquetEncodingException(org.apache.parquet.io.ParquetEncodingException) IOException(java.io.IOException)

Example 9 with ParquetEncodingException

use of org.apache.parquet.io.ParquetEncodingException in project parquet-mr by apache.

the class ColumnWriterV2 method writePage.

/**
 * writes the current data to a new page in the page store
 * @param rowCount how many rows have been written so far
 */
public void writePage(long rowCount) {
    int pageRowCount = Ints.checkedCast(rowCount - rowsWrittenSoFar);
    this.rowsWrittenSoFar = rowCount;
    if (DEBUG)
        LOG.debug("write page");
    try {
        // TODO: rework this API. Those must be called *in that order*
        BytesInput bytes = dataColumn.getBytes();
        Encoding encoding = dataColumn.getEncoding();
        pageWriter.writePageV2(pageRowCount, Ints.checkedCast(statistics.getNumNulls()), valueCount, path.getMaxRepetitionLevel() == 0 ? BytesInput.empty() : repetitionLevelColumn.toBytes(), path.getMaxDefinitionLevel() == 0 ? BytesInput.empty() : definitionLevelColumn.toBytes(), encoding, bytes, statistics);
    } catch (IOException e) {
        throw new ParquetEncodingException("could not write page for " + path, e);
    }
    repetitionLevelColumn.reset();
    definitionLevelColumn.reset();
    dataColumn.reset();
    valueCount = 0;
    resetStatistics();
}
Also used : BytesInput(org.apache.parquet.bytes.BytesInput) ParquetEncodingException(org.apache.parquet.io.ParquetEncodingException) Encoding(org.apache.parquet.column.Encoding) IOException(java.io.IOException)

Aggregations

ParquetEncodingException (org.apache.parquet.io.ParquetEncodingException)9 IOException (java.io.IOException)5 BytesInput (org.apache.parquet.bytes.BytesInput)2 ArrayList (java.util.ArrayList)1 BigDecimalWritable (org.apache.hadoop.hive.ql.io.parquet.writable.BigDecimalWritable)1 BinaryWritable (org.apache.hadoop.hive.ql.io.parquet.writable.BinaryWritable)1 ByteWritable (org.apache.hadoop.hive.serde2.io.ByteWritable)1 DoubleWritable (org.apache.hadoop.hive.serde2.io.DoubleWritable)1 ShortWritable (org.apache.hadoop.hive.serde2.io.ShortWritable)1 ArrayWritable (org.apache.hadoop.io.ArrayWritable)1 BooleanWritable (org.apache.hadoop.io.BooleanWritable)1 FloatWritable (org.apache.hadoop.io.FloatWritable)1 IntWritable (org.apache.hadoop.io.IntWritable)1 LongWritable (org.apache.hadoop.io.LongWritable)1 Writable (org.apache.hadoop.io.Writable)1 Encoding (org.apache.parquet.column.Encoding)1 DataPageV1 (org.apache.parquet.column.page.DataPageV1)1 IntIterator (org.apache.parquet.column.values.dictionary.IntList.IntIterator)1 RunLengthBitPackingHybridEncoder (org.apache.parquet.column.values.rle.RunLengthBitPackingHybridEncoder)1 BlockMetaData (org.apache.parquet.hadoop.metadata.BlockMetaData)1