[
https://issues.apache.org/jira/browse/PARQUET-2366?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17776977#comment-17776977
]
ASF GitHub Bot commented on PARQUET-2366:
-----------------------------------------
wgtmac commented on code in PR #1174:
URL: https://github.com/apache/parquet-mr/pull/1174#discussion_r1364799606
##########
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/rewrite/IndexCacher.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.parquet.hadoop.rewrite;
+
+import org.apache.parquet.column.values.bloomfilter.BloomFilter;
+import org.apache.parquet.hadoop.ParquetFileReader;
+import org.apache.parquet.hadoop.metadata.BlockMetaData;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.hadoop.metadata.ColumnPath;
+import org.apache.parquet.internal.column.columnindex.ColumnIndex;
+import org.apache.parquet.internal.column.columnindex.OffsetIndex;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A cacher for caching file indexes(ColumnIndex, OffsetIndex, BloomFilter)
+ */
+class IndexCacher {
+ private final ParquetFileReader fileReader;
+ private final Set<ColumnPath> columnPathSet;
+ private final boolean prefetchBlockAllIndexes;
+
+ // Only used when cacheBlockIndexInOnce is true
+ private Map<ColumnPath, ColumnIndex> columnIndexCache;
+ private Map<ColumnPath, OffsetIndex> offsetIndexCache;
+ private Map<ColumnPath, BloomFilter> bloomIndexCache;
+
+ IndexCacher(
+ ParquetFileReader fileReader,
+ Set<ColumnPath> columnPathSet,
+ boolean prefetchBlockAllIndexes) {
+ this.fileReader = fileReader;
+ this.columnPathSet = columnPathSet;
+ this.prefetchBlockAllIndexes = prefetchBlockAllIndexes;
+ if (prefetchBlockAllIndexes) {
+ this.columnIndexCache = new HashMap<>();
+ this.offsetIndexCache = new HashMap<>();
+ this.bloomIndexCache = new HashMap<>();
+ } else {
+ this.columnIndexCache = null;
+ this.offsetIndexCache = null;
+ this.bloomIndexCache = null;
+ }
+ }
+
+ void setCurrentBlockMetadata(BlockMetaData blockMetaData) throws IOException
{
+ if (prefetchBlockAllIndexes) {
+ free();
+ this.columnIndexCache = readAllColumnIndexes(blockMetaData);
+ this.offsetIndexCache = readAllOffsetIndexes(blockMetaData);
+ this.bloomIndexCache = readAllBloomFilters(blockMetaData);
+ }
+ }
+
+ ColumnIndex getColumnIndex(ColumnChunkMetaData chunk) throws IOException {
Review Comment:
nit: add some comment for these APIs.
##########
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/rewrite/RewriteOptions.java:
##########
@@ -213,6 +221,19 @@ public Builder addInputFile(Path path) {
return this;
}
+ /**
+ * Whether enable prefetch block indexes into cache.
+ * <p>
+ * This could reduce the random seek while rewriting, disabled by default.
+ *
+ * @param prefetchBlockAllIndexes enable or not
+ * @return self
+ */
+ public Builder prefetchBlockAllIndex(boolean prefetchBlockAllIndexes) {
Review Comment:
An enum class would be more extensible in the future. Please see my above
comments.
##########
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/rewrite/IndexCacher.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.parquet.hadoop.rewrite;
+
+import org.apache.parquet.column.values.bloomfilter.BloomFilter;
+import org.apache.parquet.hadoop.ParquetFileReader;
+import org.apache.parquet.hadoop.metadata.BlockMetaData;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.hadoop.metadata.ColumnPath;
+import org.apache.parquet.internal.column.columnindex.ColumnIndex;
+import org.apache.parquet.internal.column.columnindex.OffsetIndex;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A cacher for caching file indexes(ColumnIndex, OffsetIndex, BloomFilter)
+ */
+class IndexCacher {
Review Comment:
Thanks for adding this! Do you think we can move it out of the rewrite
module so that the general parquet reader can leverage it in the future?
##########
parquet-hadoop/src/main/java/org/apache/parquet/hadoop/rewrite/IndexCacher.java:
##########
@@ -0,0 +1,147 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.parquet.hadoop.rewrite;
+
+import org.apache.parquet.column.values.bloomfilter.BloomFilter;
+import org.apache.parquet.hadoop.ParquetFileReader;
+import org.apache.parquet.hadoop.metadata.BlockMetaData;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.hadoop.metadata.ColumnPath;
+import org.apache.parquet.internal.column.columnindex.ColumnIndex;
+import org.apache.parquet.internal.column.columnindex.OffsetIndex;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * A cacher for caching file indexes(ColumnIndex, OffsetIndex, BloomFilter)
+ */
+class IndexCacher {
Review Comment:
BTW, what about switching it into an interface? We can possibly provide this
as a default concrete implementation. A new enum class (e.g.
IndexCacheStrategy) for selecting implementations would be beneficial to
extensibility.
> Optimize random seek during rewriting
> -------------------------------------
>
> Key: PARQUET-2366
> URL: https://issues.apache.org/jira/browse/PARQUET-2366
> Project: Parquet
> Issue Type: Improvement
> Reporter: Xianyang Liu
> Priority: Major
>
> The `ColunIndex`, `OffsetIndex`, and `BloomFilter` are stored at the end of
> the file. We need to randomly seek 4 times when rewriting a column chunk. We
> found this could impact the rewrite performance heavily for files with a
> number of columns(~1000). In this PR, we read the `ColumnIndex`,
> `OffsetIndex`, and `BloomFilter` into a cache to avoid the random seek. We
> got about 60 times performance improvement in production environments for the
> files with about one thousand columns.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)