Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to read mixed encoded parquet files #5176

Merged
merged 6 commits into from
Feb 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ public OffsetIndex getOffsetIndex() {

@Override
public ColumnPageReaderIterator getPageIterator() {
return new ColumnPageReaderIteratorImpl(columnChunk.meta_data.getData_page_offset(),
columnChunk.getMeta_data().getNum_values());
return new ColumnPageReaderIteratorImpl();
}

@Override
Expand Down Expand Up @@ -226,9 +225,9 @@ private final class ColumnPageReaderIteratorImpl implements ColumnPageReaderIter
private long nextHeaderOffset;
private long remainingValues;

ColumnPageReaderIteratorImpl(final long dataPageStartOffset, final long numValues) {
this.remainingValues = numValues;
this.nextHeaderOffset = dataPageStartOffset;
ColumnPageReaderIteratorImpl() {
this.remainingValues = columnChunk.meta_data.getNum_values();
this.nextHeaderOffset = columnChunk.meta_data.getData_page_offset();
}

@Override
Expand All @@ -252,9 +251,15 @@ public ColumnPageReader next(@NotNull final SeekableChannelContext channelContex
final long dataOffset = ch.position();
nextHeaderOffset = dataOffset + pageHeader.getCompressed_page_size();
final PageType pageType = pageHeader.type;
if (pageType == PageType.DICTIONARY_PAGE && headerOffset == columnChunk.meta_data.getData_page_offset()
&& columnChunk.meta_data.getDictionary_page_offset() == 0) {
// https://stackoverflow.com/questions/55225108/why-is-dictionary-page-offset-0-for-plain-dictionary-encoding
// Skip the dictionary page and jump to the data page
return next(holder.get());
rcaudy marked this conversation as resolved.
Show resolved Hide resolved
}
if (pageType != PageType.DATA_PAGE && pageType != PageType.DATA_PAGE_V2) {
throw new IllegalStateException("Expected data page, but got " + pageType + " in file " + ch +
" at offset " + headerOffset);
throw new IllegalStateException("Expected data page, but got " + pageType + " at offset " +
headerOffset + " for file " + getURI());
}
final int numValuesInPage = getNumValues(pageHeader);
remainingValues -= numValuesInPage;
Expand All @@ -263,7 +268,8 @@ public ColumnPageReader next(@NotNull final SeekableChannelContext channelContex
return new ColumnPageReaderImpl(channelsProvider, decompressor, pageDictionarySupplier,
nullMaterializerFactory, path, getURI(), fieldTypes, dataOffset, pageHeader, numValuesInPage);
} catch (IOException e) {
throw new UncheckedDeephavenException("Error reading page header", e);
throw new UncheckedDeephavenException("Error reading page header at offset " + headerOffset + " for " +
"file " + getURI(), e);
}
}
}
Expand Down Expand Up @@ -321,16 +327,16 @@ public ColumnPageReader getPageReader(final int pageNum, final SeekableChannelCo
final PageType pageType = pageHeader.type;
if (pageType != PageType.DATA_PAGE && pageType != PageType.DATA_PAGE_V2) {
throw new IllegalStateException("Expected data page, but got " + pageType + " for page number "
malhotrashivam marked this conversation as resolved.
Show resolved Hide resolved
+ pageNum + " for column " + getURI());
+ pageNum + " at offset " + headerOffset + " for file " + getURI());
}
final Function<SeekableChannelContext, Dictionary> pageDictionarySupplier =
getPageDictionarySupplier(pageHeader);
return new ColumnPageReaderImpl(channelsProvider, decompressor, pageDictionarySupplier,
nullMaterializerFactory, path, getURI(), fieldTypes, dataOffset, pageHeader,
getNumValues(pageHeader));
} catch (final IOException e) {
throw new UncheckedDeephavenException("Error reading page header for page number " + pageNum + " for " +
"column " + getURI(), e);
throw new UncheckedDeephavenException("Error reading page header for page number " + pageNum +
" at offset " + headerOffset + " for file " + getURI(), e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package io.deephaven.parquet.base;

import io.deephaven.base.Pair;
import io.deephaven.base.verify.Assert;
import io.deephaven.base.verify.Require;
import io.deephaven.parquet.compress.CompressorAdapter;
import io.deephaven.util.channel.SeekableChannelContext;
import io.deephaven.util.channel.SeekableChannelsProvider;
Expand Down Expand Up @@ -91,10 +91,8 @@ final class ColumnPageReaderImpl implements ColumnPageReader {
this.uri = uri;
this.fieldTypes = fieldTypes;
this.dataOffset = dataOffset;
malhotrashivam marked this conversation as resolved.
Show resolved Hide resolved
Assert.neqNull(pageHeader, "pageHeader");
this.pageHeader = pageHeader;
Assert.geqZero(numValues, "numValues");
this.numValues = numValues;
this.pageHeader = Require.neqNull(pageHeader, "pageHeader");
this.numValues = Require.geqZero(numValues, "numValues");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class ParquetTableWriter {
/**
* Helper struct used to pass information about where to write the grouping files for each grouping column
*/
public static class GroupingColumnWritingInfo {
static class GroupingColumnWritingInfo {
/**
* Parquet name of this grouping column
*/
Expand Down Expand Up @@ -96,7 +96,7 @@ public static class GroupingColumnWritingInfo {
* unsupported types)
* @throws IOException For file writing related errors
*/
public static void write(
static void write(
@NotNull final Table t,
@NotNull final TableDefinition definition,
@NotNull final ParquetInstructions writeInstructions,
Expand Down
Loading