Reading fails when using DirectCodecFactory
Les mainteneurs répondent en général sous 4 jours
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 45/100
Piste de recherche
Commencez par le reproducer fourni et l'appel à DirectCodecFactory.createDirectCodecFactory, puis comparez son comportement avec celui de la fabrique de codecs Hadoop utilisée par ParquetReader. Utilisez le fichier test.parquet joint et vérifiez que la lecture se termine avec 51 000 enregistrements et préserve le contenu clé/valeur attendu.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Describe the bug, including details regarding any error messages, version, and platform.
Hello folks,
I'm currently working on removing the hadoop-common dependency from the runtime in one of my projects.
As part of this process, I need to replace the "Hadoop" codec factory, which relies on certain classes from hadoop-common, with a codec factory that exclusively uses classes from parquet-hadoop. One potential option is DirectCodecFactory, but it comes with a problem.
For demonstration purposes, I’m using a simple key-value Snappy-compressed parquet file containing 51,000 records. Here’s a sample of the data:
When attempting to read this file using DirectCodecFactory, I encounter two issues:
- The file fails to read completely. Near the end, it throws an error:
Can't read value in column [key] optional binary key (STRING) = 0 at value 49,534 out of 51,000, 9,534 out of 11,000 in currentPage. Repetition level: 0, definition level: 1. - At record number 40,001, the key and value columns get mixed up, with the key column unexpectedly containing a value.
Parquet version: 1.15.0
Hadoop version: 3.4.1
Observations:
- With the Hadoop codec factory the file can be read without any issues.
Here are tests demonstrating the issues:
package sandbox.parquet.reader;
import org.apache.hadoop.conf.Configuration;
import org.apache.parquet.bytes.DirectByteBufferAllocator;
import org.apache.parquet.column.ParquetProperties;
import org.apache.parquet.conf.ParquetConfiguration;
import org.apache.parquet.conf.PlainParquetConfiguration;
import org.apache.parquet.hadoop.CodecFactory;
import org.apache.parquet.hadoop.ParquetReader;
import org.apache.parquet.hadoop.api.InitContext;
import org.apache.parquet.hadoop.api.ReadSupport;
import org.apache.parquet.io.InputFile;
import org.apache.parquet.io.LocalInputFile;
import org.apache.parquet.io.api.Binary;
import org.apache.parquet.io.api.Converter;
import org.apache.parquet.io.api.GroupConverter;
import org.apache.parquet.io.api.PrimitiveConverter;
import org.apache.parquet.io.api.RecordMaterializer;
import org.apache.parquet.schema.GroupType;
import org.apache.parquet.schema.MessageType;
import org.apache.parquet.schema.Type;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
public class ParquetReaderTest {
@Test
void readParquetFileAndVerifyRecordCount_usingDirectCodeFactory() throws Exception {
Path filePath = Paths.get(ClassLoader.getSystemResource("test.parquet").toURI());
int recordCount = 0;
try(ParquetReader<String[]> parquetReader = createReaderWithDirectCodeFactory(filePath)) {
while (parquetReader.read() != null) {
recordCount++;
}
}
Assertions.assertEquals(51_000, recordCount);
}
@Test
void readParquetFileAndVerifyContent_usingDirectCodeFactory() throws Exception {
Path filePath = Paths.get(ClassLoader.getSystemResource("test.parquet").toURI());
int recordCount = 0;
try(ParquetReader<String[]> parquetReader = createReaderWithHadoopCodeFactory(filePath)) {
String[] record;
while ((record = parquetReader.read()) != null) {
Assertions.assertEquals("key_" + (recordCount + 1), record[0]);
Assertions.assertEquals("value_" + (recordCount + 1), record[1]);
recordCount++;
}
}
Assertions.assertEquals(51_000, recordCount);
}
@Test
void readParquetFileAndVerifyRecordCount_usingHadoopCodeFactory() throws Exception {
Path filePath = Paths.get(ClassLoader.getSystemResource("test.parquet").toURI());
int recordCount = 0;
try(ParquetReader<String[]> parquetReader = createReaderWithHadoopCodeFactory(filePath)) {
while (parquetReader.read() != null) {
recordCount++;
}
}
Assertions.assertEquals(51_000, recordCount);
}
@Test
void readParquetFileAndVerifyContent_usingHadoopCodeFactory() throws Exception {
Path filePath = Paths.get(ClassLoader.getSystemResource("test.parquet").toURI());
int recordCount = 0;
try(ParquetReader<String[]> parquetReader = createReaderWithDirectCodeFactory(filePath)) {
String[] record;
while ((record = parquetReader.read()) != null) {
Assertions.assertEquals("key_" + (recordCount + 1), record[0]);
Assertions.assertEquals("value_" + (recordCount + 1), record[1]);
recordCount++;
}
}
Assertions.assertEquals(51_000, recordCount);
}
private ParquetReader<String[]> createReaderWithDirectCodeFactory(Path file) throws Exception {
return new ParquetReaderBuilder(new LocalInputFile(file), new PlainParquetConfiguration())
.withCodecFactory(CodecFactory.createDirectCodecFactory(null,
DirectByteBufferAllocator.getInstance(),
ParquetProperties.DEFAULT_PAGE_SIZE))
.build();
}
private ParquetReader<String[]> createReaderWithHadoopCodeFactory(Path file) throws Exception {
// the Hadoop codec factory is created in ParquetReadOptions.Builder#build
return new ParquetReaderBuilder(new LocalInputFile(file), new PlainParquetConfiguration())
.build();
}
static class ParquetReaderBuilder extends ParquetReader.Builder<String[]> {
ParquetReaderBuilder(InputFile file, ParquetConfiguration conf) {
super(file, conf);
}
@Override
protected ReadSupport<String[]> getReadSupport() {
return new TestReadSupport();
}
}
static class TestReadSupport extends ReadSupport<String[]> {
@Override
public ReadContext init(InitContext context) {
return new ReadContext(context.getFileSchema());
}
@Override
public RecordMaterializer<String[]> prepareForRead(Configuration configuration,
Map<String, String> keyValueMetaData,
MessageType fileSchema,
ReadContext readContext) {
return new TestRecordMaterializer(fileSchema);
}
@Override
public RecordMaterializer<String[]> prepareForRead(ParquetConfiguration configuration,
Map<String, String> keyValueMetaData,
MessageType fileSchema,
ReadContext readContext) {
return new TestRecordMaterializer(fileSchema);
}
}
static class TestRecordMaterializer extends RecordMaterializer<String[]> {
private final TestRootGroupConverter root;
TestRecordMaterializer(MessageType schema) {
this.root = new TestRootGroupConverter(schema);
}
@Override
public String[] getCurrentRecord() {
return root.getCurrentRecord();
}
@Override
public GroupConverter getRootConverter() {
return root;
}
}
static class TestRootGroupConverter extends GroupConverter {
private String[] currentRecord;
private final Converter[] converters;
TestRootGroupConverter(GroupType schema) {
converters = new Converter[schema.getFieldCount()];
for (int i = 0; i < converters.length; i++) {
final Type type = schema.getType(i);
if (type.isPrimitive()) {
converters[i] = new TestPrimitiveConverter(this, i);
} else {
throw new RuntimeException("Nested records not supported!");
}
}
}
@Override
public Converter getConverter(int fieldIndex) {
return converters[fieldIndex];
}
@Override
public void start() {
currentRecord = new String[converters.length];
}
@Override
public void end() {
}
String[] getCurrentRecord() {
return currentRecord;
}
}
static class TestPrimitiveConverter extends PrimitiveConverter {
private final TestRootGroupConverter parent;
private final int index;
TestPrimitiveConverter(TestRootGroupConverter parent, int index) {
this.parent = parent;
this.index = index;
}
@Override
public void addBinary(Binary value) {
parent.getCurrentRecord()[index] = value.toStringUsingUTF8();
}
@Override
public void addBoolean(boolean value) {
throw new UnsupportedOperationException();
}
@Override
public void addDouble(double value) {
throw new UnsupportedOperationException();
}
@Override
public void addFloat(float value) {
throw new UnsupportedOperationException();
}
@Override
public void addInt(int value) {
throw new UnsupportedOperationException();
}
@Override
public void addLong(long value) {
throw new UnsupportedOperationException();
}
}
}
Attaching the parquet file and a demo application:
Component(s)
Core
- Langage dominant
- Java
- Étoiles
- 3.1k
- Forks
- 1.6k
- Merge moyen
- 5 j 23 h
- PR mergées (30 j)
- 32
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Aucun guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de apache/parquet-java
-
Row-group copying collides for distinct column paths with the same dot stringPeut-être pris @costas-db l’a pris il y a 17 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
apache/parquet-java#3829 ·
Les mainteneurs répondent en général sous 4 jours
-
Binary statistics truncation test ignores its configured truncation lengthPeut-être pris @dhruv-15-03 l’a pris il y a 19 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 88/100
apache/parquet-java#3820 ·
Les mainteneurs répondent en général sous 4 jours
-
Make PageReader AutoCloseableOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
apache/parquet-java#3767 ·
Les mainteneurs répondent en général sous 4 jours
-
Remove duplicate LICENSE and NOTICE files from benchmark JARsPeut-être pris @efegokdemir l’a pris il y a 22 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
apache/parquet-java#3695 · 1 commentaire ·
Les mainteneurs répondent en général sous 4 jours
-
null_count is omitted for large columns in parquet filesPeut-être pris @efegokdemir l’a pris il y a 20 jours. OuverteType: bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
apache/parquet-java#3574 · 1 commentaire ·
Les mainteneurs répondent en général sous 4 jours
Toutes les issues de apache/parquet-java
Issues similaires
-
approved bug
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
checkstyle/checkstyle#21981 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
Build: the CUDA backend fails without cuDNN instead of skipping the cuDNN shim (as the cuDF shim does)Peut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
beehive-lab/TornadoVM#1248 ·
Les mainteneurs répondent en général sous 1 jour
-
good first issue help wanted ready-for-human
Difficulté 2/5 Une demi-journée Accessibilité débutants 64/100
Les mainteneurs répondent en général sous 1 jour
-
bug jdbc-v2
Difficulté 2/5 1-3 heures Accessibilité débutants 70/100
ClickHouse/clickhouse-java#3214 ·
Les mainteneurs répondent en général sous 1 jour
-
Java and Kotlin (JVM): parse gradle/wrapper/gradle-wrapper.properties with exact line locationsOuvertearea: detector eco: java help wanted lane: free-agent roadmap size: S type: parser
Difficulté 2/5 1-3 heures Accessibilité débutants 62/100
arminazimi/evergreen#355 ·
Les mainteneurs répondent en général sous 1 jour