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);
}
}
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);
}
}
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();
}
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();
}
Aggregations