You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@parquet.apache.org by GitBox <gi...@apache.org> on 2021/02/10 17:01:09 UTC

[GitHub] [parquet-mr] gszadovszky opened a new pull request #868: PARQUET-1977: Invalid data_page_offset

gszadovszky opened a new pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868


   Make sure you have checked _all_ steps below.
   
   ### Jira
   
   - [ ] My PR addresses the following [Parquet Jira](https://issues.apache.org/jira/browse/PARQUET/) issues and references them in the PR title. For example, "PARQUET-1234: My Parquet PR"
     - https://issues.apache.org/jira/browse/PARQUET-XXX
     - In case you are adding a dependency, check if the license complies with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   
   ### Tests
   
   - [ ] My PR adds the following unit tests __OR__ does not need testing for this extremely good reason:
   
   ### Commits
   
   - [ ] My commits all reference Jira issues in their subject lines. In addition, my commits follow the guidelines from "[How to write a good git commit message](http://chris.beams.io/posts/git-commit/)":
     1. Subject is separated from body by a blank line
     1. Subject is limited to 50 characters (not including Jira issue reference)
     1. Subject does not end with a period
     1. Subject uses the imperative mood ("add", not "adding")
     1. Body wraps at 72 characters
     1. Body explains "what" and "why", not "how"
   
   ### Documentation
   
   - [ ] In case of new functionality, my PR adds documentation that describes how to use it.
     - All the public functions and the classes in the PR contain Javadoc that explain what it does
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] shangxinli commented on pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
shangxinli commented on pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#issuecomment-779408903


   Great findings! I will review it sometime this week. 
   
   BTW, I see you keep finding issues like this. Are you doing some testing? 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] shangxinli commented on a change in pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
shangxinli commented on a change in pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#discussion_r581415235



##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/Offsets.java
##########
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.parquet.format.PageHeader;
+import org.apache.parquet.format.Util;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.io.SeekableInputStream;
+
+/**
+ * Class to help gather/calculate the proper values of the dictionary/first data page offset values in a column chunk.
+ */
+class Offsets {
+
+  /**
+   * Returns the offset values for the column chunk to be written.
+   *
+   * @param input         the source input stream of the column chunk
+   * @param chunk         the column chunk metadata read from the source file
+   * @param newChunkStart the position of the column chunk to be written
+   * @return the offset values
+   * @throws IOException if any I/O error occurs during the reading of the input stream
+   */
+  public static Offsets getOffsets(SeekableInputStream input, ColumnChunkMetaData chunk, long newChunkStart)
+      throws IOException {
+    long firstDataPageOffset;
+    long dictionaryPageOffset;
+    if (chunk.hasDictionaryPage()) {
+      long dictionaryPageSize = chunk.getFirstDataPageOffset() - chunk.getDictionaryPageOffset();
+      if (dictionaryPageSize <= 0) {
+        // The offset values might be invalid so we have to read the size of the dictionary page
+        dictionaryPageSize = readDictionaryPageSize(input, newChunkStart);
+      }
+      firstDataPageOffset = newChunkStart + dictionaryPageSize;
+      dictionaryPageOffset = newChunkStart;
+    } else {
+      firstDataPageOffset = newChunkStart;
+      dictionaryPageOffset = 0;
+    }
+    return new Offsets(firstDataPageOffset, dictionaryPageOffset);
+  }
+
+  private static long readDictionaryPageSize(SeekableInputStream in, long pos) throws IOException {
+    long origPos = -1;
+    try {
+      origPos = in.getPos();
+      // TODO: Do we need to handle encryption here?

Review comment:
       +1




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] shangxinli commented on a change in pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
shangxinli commented on a change in pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#discussion_r581417576



##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/Offsets.java
##########
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.parquet.format.PageHeader;
+import org.apache.parquet.format.Util;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.io.SeekableInputStream;
+
+/**
+ * Class to help gather/calculate the proper values of the dictionary/first data page offset values in a column chunk.
+ */
+class Offsets {
+
+  /**
+   * Returns the offset values for the column chunk to be written.
+   *
+   * @param input         the source input stream of the column chunk
+   * @param chunk         the column chunk metadata read from the source file
+   * @param newChunkStart the position of the column chunk to be written
+   * @return the offset values
+   * @throws IOException if any I/O error occurs during the reading of the input stream
+   */
+  public static Offsets getOffsets(SeekableInputStream input, ColumnChunkMetaData chunk, long newChunkStart)
+      throws IOException {
+    long firstDataPageOffset;
+    long dictionaryPageOffset;
+    if (chunk.hasDictionaryPage()) {
+      long dictionaryPageSize = chunk.getFirstDataPageOffset() - chunk.getDictionaryPageOffset();
+      if (dictionaryPageSize <= 0) {
+        // The offset values might be invalid so we have to read the size of the dictionary page
+        dictionaryPageSize = readDictionaryPageSize(input, newChunkStart);
+      }
+      firstDataPageOffset = newChunkStart + dictionaryPageSize;
+      dictionaryPageOffset = newChunkStart;
+    } else {
+      firstDataPageOffset = newChunkStart;
+      dictionaryPageOffset = 0;
+    }
+    return new Offsets(firstDataPageOffset, dictionaryPageOffset);
+  }
+
+  private static long readDictionaryPageSize(SeekableInputStream in, long pos) throws IOException {
+    long origPos = -1;
+    try {
+      origPos = in.getPos();
+      // TODO: Do we need to handle encryption here?
+      PageHeader header = Util.readPageHeader(in);
+      long headerSize = in.getPos() - origPos;
+      return headerSize + header.getCompressed_page_size();
+    } finally {
+      if (origPos != -1) {
+        in.seek(origPos);

Review comment:
       Got it

##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetFileWriter.java
##########
@@ -493,6 +492,9 @@ public void writeDictionaryPage(DictionaryPage dictionaryPage,
     dictionaryPage.getBytes().writeAllTo(out); // for encrypted column, dictionary page bytes are already encrypted
     encodingStatsBuilder.addDictEncoding(dictionaryPage.getEncoding());
     currentEncodings.add(dictionaryPage.getEncoding());
+
+    // First data page comes just after the dictionary page
+    currentChunkFirstDataPage = out.getPos();

Review comment:
       Sounds good!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] gszadovszky commented on a change in pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
gszadovszky commented on a change in pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#discussion_r580848361



##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/Offsets.java
##########
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.parquet.format.PageHeader;
+import org.apache.parquet.format.Util;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.io.SeekableInputStream;
+
+/**
+ * Class to help gather/calculate the proper values of the dictionary/first data page offset values in a column chunk.
+ */
+class Offsets {
+
+  /**
+   * Returns the offset values for the column chunk to be written.
+   *
+   * @param input         the source input stream of the column chunk
+   * @param chunk         the column chunk metadata read from the source file
+   * @param newChunkStart the position of the column chunk to be written
+   * @return the offset values
+   * @throws IOException if any I/O error occurs during the reading of the input stream
+   */
+  public static Offsets getOffsets(SeekableInputStream input, ColumnChunkMetaData chunk, long newChunkStart)
+      throws IOException {
+    long firstDataPageOffset;
+    long dictionaryPageOffset;
+    if (chunk.hasDictionaryPage()) {
+      long dictionaryPageSize = chunk.getFirstDataPageOffset() - chunk.getDictionaryPageOffset();
+      if (dictionaryPageSize <= 0) {
+        // The offset values might be invalid so we have to read the size of the dictionary page

Review comment:
       We are just fixing that the offset of the first data page is not valid in case there is a dictionary page. In case of throwing an exception we would block reading parquet files written by parquet-mr before.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] ggershinsky commented on a change in pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
ggershinsky commented on a change in pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#discussion_r580860001



##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/Offsets.java
##########
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.parquet.format.PageHeader;
+import org.apache.parquet.format.Util;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.io.SeekableInputStream;
+
+/**
+ * Class to help gather/calculate the proper values of the dictionary/first data page offset values in a column chunk.
+ */
+class Offsets {
+
+  /**
+   * Returns the offset values for the column chunk to be written.
+   *
+   * @param input         the source input stream of the column chunk
+   * @param chunk         the column chunk metadata read from the source file
+   * @param newChunkStart the position of the column chunk to be written
+   * @return the offset values
+   * @throws IOException if any I/O error occurs during the reading of the input stream
+   */
+  public static Offsets getOffsets(SeekableInputStream input, ColumnChunkMetaData chunk, long newChunkStart)
+      throws IOException {
+    long firstDataPageOffset;
+    long dictionaryPageOffset;
+    if (chunk.hasDictionaryPage()) {
+      long dictionaryPageSize = chunk.getFirstDataPageOffset() - chunk.getDictionaryPageOffset();
+      if (dictionaryPageSize <= 0) {
+        // The offset values might be invalid so we have to read the size of the dictionary page
+        dictionaryPageSize = readDictionaryPageSize(input, newChunkStart);
+      }
+      firstDataPageOffset = newChunkStart + dictionaryPageSize;
+      dictionaryPageOffset = newChunkStart;
+    } else {
+      firstDataPageOffset = newChunkStart;
+      dictionaryPageOffset = 0;
+    }
+    return new Offsets(firstDataPageOffset, dictionaryPageOffset);
+  }
+
+  private static long readDictionaryPageSize(SeekableInputStream in, long pos) throws IOException {
+    long origPos = -1;
+    try {
+      origPos = in.getPos();
+      // TODO: Do we need to handle encryption here?

Review comment:
       Setting up decryption in the writer could be a major headache. Would it be possible to store the dictionary page size in the `ColumnChunkMetaData chunk` object?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] gszadovszky commented on pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
gszadovszky commented on pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#issuecomment-779685215


   > Great findings! I will review it sometime this week.
   > 
   > BTW, I see you keep finding issues like this. Are you doing some testing?
   
   The Impala team started working on bloom filters. They are the ones coming to me with these issues :)
   (It is really fortunate that they started working on this before our release.)


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] gszadovszky commented on a change in pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
gszadovszky commented on a change in pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#discussion_r580868682



##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/Offsets.java
##########
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.parquet.format.PageHeader;
+import org.apache.parquet.format.Util;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.io.SeekableInputStream;
+
+/**
+ * Class to help gather/calculate the proper values of the dictionary/first data page offset values in a column chunk.
+ */
+class Offsets {
+
+  /**
+   * Returns the offset values for the column chunk to be written.
+   *
+   * @param input         the source input stream of the column chunk
+   * @param chunk         the column chunk metadata read from the source file
+   * @param newChunkStart the position of the column chunk to be written
+   * @return the offset values
+   * @throws IOException if any I/O error occurs during the reading of the input stream
+   */
+  public static Offsets getOffsets(SeekableInputStream input, ColumnChunkMetaData chunk, long newChunkStart)
+      throws IOException {
+    long firstDataPageOffset;
+    long dictionaryPageOffset;
+    if (chunk.hasDictionaryPage()) {
+      long dictionaryPageSize = chunk.getFirstDataPageOffset() - chunk.getDictionaryPageOffset();
+      if (dictionaryPageSize <= 0) {
+        // The offset values might be invalid so we have to read the size of the dictionary page
+        dictionaryPageSize = readDictionaryPageSize(input, newChunkStart);
+      }
+      firstDataPageOffset = newChunkStart + dictionaryPageSize;
+      dictionaryPageOffset = newChunkStart;
+    } else {
+      firstDataPageOffset = newChunkStart;
+      dictionaryPageOffset = 0;
+    }
+    return new Offsets(firstDataPageOffset, dictionaryPageOffset);
+  }
+
+  private static long readDictionaryPageSize(SeekableInputStream in, long pos) throws IOException {
+    long origPos = -1;
+    try {
+      origPos = in.getPos();
+      // TODO: Do we need to handle encryption here?

Review comment:
       We do not have such field in the thrift file currently and even if we add it it would not solve the issue of the already existing files. So, I guess you've thought about adding an additional field to the parquet-mr side object only to be set manually. To set it we need to read the dictionary which do not do in the tools we currently use this functionality (mask/prune columns). But the whole think is not a problem currently because we do not support encryption/decryption in the tools anyway.
   
   I am not sure if we want to support encryption in the tools later or it is even feasible but for now it is correct as is. I'll remove the TODO line and try to document the situation in the class header.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] gszadovszky commented on a change in pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
gszadovszky commented on a change in pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#discussion_r580860455



##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/metadata/ColumnChunkMetaData.java
##########
@@ -566,7 +567,7 @@ public Statistics getStatistics() {
   private final ParquetMetadataConverter parquetMetadataConverter;
   private final byte[] encryptedMetadata;
   private final byte[] columnKeyMetadata;
-  private final InternalFileDecryptor fileDecryptor; 

Review comment:
       I'll undo them




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] gszadovszky commented on a change in pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
gszadovszky commented on a change in pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#discussion_r581768521



##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/Offsets.java
##########
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.parquet.format.PageHeader;
+import org.apache.parquet.format.Util;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.io.SeekableInputStream;
+
+/**
+ * Class to help gather/calculate the proper values of the dictionary/first data page offset values in a column chunk.
+ */
+class Offsets {
+
+  /**
+   * Returns the offset values for the column chunk to be written.
+   *
+   * @param input         the source input stream of the column chunk
+   * @param chunk         the column chunk metadata read from the source file
+   * @param newChunkStart the position of the column chunk to be written
+   * @return the offset values
+   * @throws IOException if any I/O error occurs during the reading of the input stream
+   */
+  public static Offsets getOffsets(SeekableInputStream input, ColumnChunkMetaData chunk, long newChunkStart)
+      throws IOException {
+    long firstDataPageOffset;
+    long dictionaryPageOffset;
+    if (chunk.hasDictionaryPage()) {
+      long dictionaryPageSize = chunk.getFirstDataPageOffset() - chunk.getDictionaryPageOffset();
+      if (dictionaryPageSize <= 0) {
+        // The offset values might be invalid so we have to read the size of the dictionary page

Review comment:
       You are right, I didn't think it through. I'll update the code and add some explanation.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] gszadovszky commented on pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
gszadovszky commented on pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#issuecomment-783252490


   > Great findings! I will review it sometime this week.
   
   @shangxinli, a friendly reminder that the release is blocked on this PR.
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] gszadovszky commented on a change in pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
gszadovszky commented on a change in pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#discussion_r580854648



##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/Offsets.java
##########
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.parquet.format.PageHeader;
+import org.apache.parquet.format.Util;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.io.SeekableInputStream;
+
+/**
+ * Class to help gather/calculate the proper values of the dictionary/first data page offset values in a column chunk.
+ */
+class Offsets {
+
+  /**
+   * Returns the offset values for the column chunk to be written.
+   *
+   * @param input         the source input stream of the column chunk
+   * @param chunk         the column chunk metadata read from the source file
+   * @param newChunkStart the position of the column chunk to be written
+   * @return the offset values
+   * @throws IOException if any I/O error occurs during the reading of the input stream
+   */
+  public static Offsets getOffsets(SeekableInputStream input, ColumnChunkMetaData chunk, long newChunkStart)
+      throws IOException {
+    long firstDataPageOffset;
+    long dictionaryPageOffset;
+    if (chunk.hasDictionaryPage()) {
+      long dictionaryPageSize = chunk.getFirstDataPageOffset() - chunk.getDictionaryPageOffset();
+      if (dictionaryPageSize <= 0) {
+        // The offset values might be invalid so we have to read the size of the dictionary page
+        dictionaryPageSize = readDictionaryPageSize(input, newChunkStart);
+      }
+      firstDataPageOffset = newChunkStart + dictionaryPageSize;
+      dictionaryPageOffset = newChunkStart;
+    } else {
+      firstDataPageOffset = newChunkStart;
+      dictionaryPageOffset = 0;
+    }
+    return new Offsets(firstDataPageOffset, dictionaryPageOffset);
+  }
+
+  private static long readDictionaryPageSize(SeekableInputStream in, long pos) throws IOException {
+    long origPos = -1;
+    try {
+      origPos = in.getPos();
+      // TODO: Do we need to handle encryption here?
+      PageHeader header = Util.readPageHeader(in);
+      long headerSize = in.getPos() - origPos;
+      return headerSize + header.getCompressed_page_size();
+    } finally {
+      if (origPos != -1) {
+        in.seek(origPos);

Review comment:
       We read the dictionary page header so we alter the actual file position. Because it may not be trivial to the caller that this utility might read the file I wanted to set back the original position.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] gszadovszky commented on a change in pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
gszadovszky commented on a change in pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#discussion_r580860051



##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetFileWriter.java
##########
@@ -493,6 +492,9 @@ public void writeDictionaryPage(DictionaryPage dictionaryPage,
     dictionaryPage.getBytes().writeAllTo(out); // for encrypted column, dictionary page bytes are already encrypted
     encodingStatsBuilder.addDictEncoding(dictionaryPage.getEncoding());
     currentEncodings.add(dictionaryPage.getEncoding());
+
+    // First data page comes just after the dictionary page
+    currentChunkFirstDataPage = out.getPos();

Review comment:
       I'll move setting this value to data page writes.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] gszadovszky merged pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
gszadovszky merged pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] gszadovszky commented on pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
gszadovszky commented on pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#issuecomment-785769998


   Thanks @ggershinsky, @shangxinli for reviewing.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] shangxinli commented on a change in pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
shangxinli commented on a change in pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#discussion_r581414720



##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/Offsets.java
##########
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.parquet.format.PageHeader;
+import org.apache.parquet.format.Util;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.io.SeekableInputStream;
+
+/**
+ * Class to help gather/calculate the proper values of the dictionary/first data page offset values in a column chunk.
+ */
+class Offsets {
+
+  /**
+   * Returns the offset values for the column chunk to be written.
+   *
+   * @param input         the source input stream of the column chunk
+   * @param chunk         the column chunk metadata read from the source file
+   * @param newChunkStart the position of the column chunk to be written
+   * @return the offset values
+   * @throws IOException if any I/O error occurs during the reading of the input stream
+   */
+  public static Offsets getOffsets(SeekableInputStream input, ColumnChunkMetaData chunk, long newChunkStart)
+      throws IOException {
+    long firstDataPageOffset;
+    long dictionaryPageOffset;
+    if (chunk.hasDictionaryPage()) {
+      long dictionaryPageSize = chunk.getFirstDataPageOffset() - chunk.getDictionaryPageOffset();
+      if (dictionaryPageSize <= 0) {
+        // The offset values might be invalid so we have to read the size of the dictionary page

Review comment:
       If that is the case, should we also check chunk.getFirstDataPageOffset() is invalid? My concern is "chunk.getFirstDataPageOffset() - chunk.getDictionaryPageOffset()" could result in a number greater than 0 even in invalid case. Is it possible? 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] ggershinsky commented on a change in pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
ggershinsky commented on a change in pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#discussion_r580889480



##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/Offsets.java
##########
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.parquet.format.PageHeader;
+import org.apache.parquet.format.Util;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.io.SeekableInputStream;
+
+/**
+ * Class to help gather/calculate the proper values of the dictionary/first data page offset values in a column chunk.
+ */
+class Offsets {
+
+  /**
+   * Returns the offset values for the column chunk to be written.
+   *
+   * @param input         the source input stream of the column chunk
+   * @param chunk         the column chunk metadata read from the source file
+   * @param newChunkStart the position of the column chunk to be written
+   * @return the offset values
+   * @throws IOException if any I/O error occurs during the reading of the input stream
+   */
+  public static Offsets getOffsets(SeekableInputStream input, ColumnChunkMetaData chunk, long newChunkStart)
+      throws IOException {
+    long firstDataPageOffset;
+    long dictionaryPageOffset;
+    if (chunk.hasDictionaryPage()) {
+      long dictionaryPageSize = chunk.getFirstDataPageOffset() - chunk.getDictionaryPageOffset();
+      if (dictionaryPageSize <= 0) {
+        // The offset values might be invalid so we have to read the size of the dictionary page
+        dictionaryPageSize = readDictionaryPageSize(input, newChunkStart);
+      }
+      firstDataPageOffset = newChunkStart + dictionaryPageSize;
+      dictionaryPageOffset = newChunkStart;
+    } else {
+      firstDataPageOffset = newChunkStart;
+      dictionaryPageOffset = 0;
+    }
+    return new Offsets(firstDataPageOffset, dictionaryPageOffset);
+  }
+
+  private static long readDictionaryPageSize(SeekableInputStream in, long pos) throws IOException {
+    long origPos = -1;
+    try {
+      origPos = in.getPos();
+      // TODO: Do we need to handle encryption here?

Review comment:
       Sounds good. Applying the tools to encrypted files will require a new design (including management of file identities, that are ingrained in the encryption process for anti-tampering; pruning a column obviously produces a new file, that must have a different identity).




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] shangxinli commented on pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
shangxinli commented on pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#issuecomment-785219004


   LGTM


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] gszadovszky commented on a change in pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
gszadovszky commented on a change in pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#discussion_r580853377



##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/Offsets.java
##########
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.parquet.format.PageHeader;
+import org.apache.parquet.format.Util;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.io.SeekableInputStream;
+
+/**
+ * Class to help gather/calculate the proper values of the dictionary/first data page offset values in a column chunk.
+ */
+class Offsets {
+
+  /**
+   * Returns the offset values for the column chunk to be written.
+   *
+   * @param input         the source input stream of the column chunk
+   * @param chunk         the column chunk metadata read from the source file
+   * @param newChunkStart the position of the column chunk to be written
+   * @return the offset values
+   * @throws IOException if any I/O error occurs during the reading of the input stream
+   */
+  public static Offsets getOffsets(SeekableInputStream input, ColumnChunkMetaData chunk, long newChunkStart)
+      throws IOException {
+    long firstDataPageOffset;
+    long dictionaryPageOffset;
+    if (chunk.hasDictionaryPage()) {
+      long dictionaryPageSize = chunk.getFirstDataPageOffset() - chunk.getDictionaryPageOffset();
+      if (dictionaryPageSize <= 0) {
+        // The offset values might be invalid so we have to read the size of the dictionary page
+        dictionaryPageSize = readDictionaryPageSize(input, newChunkStart);
+      }
+      firstDataPageOffset = newChunkStart + dictionaryPageSize;
+      dictionaryPageOffset = newChunkStart;
+    } else {
+      firstDataPageOffset = newChunkStart;
+      dictionaryPageOffset = 0;
+    }
+    return new Offsets(firstDataPageOffset, dictionaryPageOffset);
+  }
+
+  private static long readDictionaryPageSize(SeekableInputStream in, long pos) throws IOException {
+    long origPos = -1;
+    try {
+      origPos = in.getPos();
+      // TODO: Do we need to handle encryption here?

Review comment:
       This class is used by the `append*` methods of `ParquetFileWriter` which are used by the tools for prune/mask columns. Tools do not support encryption currently so I cannot get the required encryption objects to support decrypting of the dictionary page.
   Maybe this todo is a bit misleading but I was not sure about the future encryption support in the tools.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [parquet-mr] shangxinli commented on a change in pull request #868: PARQUET-1977: Invalid data_page_offset

Posted by GitBox <gi...@apache.org>.
shangxinli commented on a change in pull request #868:
URL: https://github.com/apache/parquet-mr/pull/868#discussion_r580424903



##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/Offsets.java
##########
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.parquet.format.PageHeader;
+import org.apache.parquet.format.Util;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.io.SeekableInputStream;
+
+/**
+ * Class to help gather/calculate the proper values of the dictionary/first data page offset values in a column chunk.
+ */
+class Offsets {
+
+  /**
+   * Returns the offset values for the column chunk to be written.
+   *
+   * @param input         the source input stream of the column chunk
+   * @param chunk         the column chunk metadata read from the source file
+   * @param newChunkStart the position of the column chunk to be written
+   * @return the offset values
+   * @throws IOException if any I/O error occurs during the reading of the input stream
+   */
+  public static Offsets getOffsets(SeekableInputStream input, ColumnChunkMetaData chunk, long newChunkStart)
+      throws IOException {
+    long firstDataPageOffset;
+    long dictionaryPageOffset;
+    if (chunk.hasDictionaryPage()) {
+      long dictionaryPageSize = chunk.getFirstDataPageOffset() - chunk.getDictionaryPageOffset();
+      if (dictionaryPageSize <= 0) {
+        // The offset values might be invalid so we have to read the size of the dictionary page

Review comment:
       if the offset is invalid, should we through exception here?

##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/Offsets.java
##########
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.parquet.format.PageHeader;
+import org.apache.parquet.format.Util;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.io.SeekableInputStream;
+
+/**
+ * Class to help gather/calculate the proper values of the dictionary/first data page offset values in a column chunk.
+ */
+class Offsets {
+
+  /**
+   * Returns the offset values for the column chunk to be written.
+   *
+   * @param input         the source input stream of the column chunk
+   * @param chunk         the column chunk metadata read from the source file
+   * @param newChunkStart the position of the column chunk to be written
+   * @return the offset values
+   * @throws IOException if any I/O error occurs during the reading of the input stream
+   */
+  public static Offsets getOffsets(SeekableInputStream input, ColumnChunkMetaData chunk, long newChunkStart)
+      throws IOException {
+    long firstDataPageOffset;
+    long dictionaryPageOffset;
+    if (chunk.hasDictionaryPage()) {
+      long dictionaryPageSize = chunk.getFirstDataPageOffset() - chunk.getDictionaryPageOffset();
+      if (dictionaryPageSize <= 0) {
+        // The offset values might be invalid so we have to read the size of the dictionary page
+        dictionaryPageSize = readDictionaryPageSize(input, newChunkStart);
+      }
+      firstDataPageOffset = newChunkStart + dictionaryPageSize;
+      dictionaryPageOffset = newChunkStart;
+    } else {
+      firstDataPageOffset = newChunkStart;
+      dictionaryPageOffset = 0;
+    }
+    return new Offsets(firstDataPageOffset, dictionaryPageOffset);
+  }
+
+  private static long readDictionaryPageSize(SeekableInputStream in, long pos) throws IOException {
+    long origPos = -1;
+    try {
+      origPos = in.getPos();
+      // TODO: Do we need to handle encryption here?
+      PageHeader header = Util.readPageHeader(in);
+      long headerSize = in.getPos() - origPos;
+      return headerSize + header.getCompressed_page_size();
+    } finally {
+      if (origPos != -1) {
+        in.seek(origPos);

Review comment:
       Why we need seek here? 

##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/ParquetFileWriter.java
##########
@@ -493,6 +492,9 @@ public void writeDictionaryPage(DictionaryPage dictionaryPage,
     dictionaryPage.getBytes().writeAllTo(out); // for encrypted column, dictionary page bytes are already encrypted
     encodingStatsBuilder.addDictEncoding(dictionaryPage.getEncoding());
     currentEncodings.add(dictionaryPage.getEncoding());
+
+    // First data page comes just after the dictionary page
+    currentChunkFirstDataPage = out.getPos();

Review comment:
       The assumption is data page is immediately written after the dictionary page always. This could be true today but later on, if that assumption is changed, it would be hard to find this line of code that need to be changed. 

##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/Offsets.java
##########
@@ -0,0 +1,84 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+import org.apache.parquet.format.PageHeader;
+import org.apache.parquet.format.Util;
+import org.apache.parquet.hadoop.metadata.ColumnChunkMetaData;
+import org.apache.parquet.io.SeekableInputStream;
+
+/**
+ * Class to help gather/calculate the proper values of the dictionary/first data page offset values in a column chunk.
+ */
+class Offsets {
+
+  /**
+   * Returns the offset values for the column chunk to be written.
+   *
+   * @param input         the source input stream of the column chunk
+   * @param chunk         the column chunk metadata read from the source file
+   * @param newChunkStart the position of the column chunk to be written
+   * @return the offset values
+   * @throws IOException if any I/O error occurs during the reading of the input stream
+   */
+  public static Offsets getOffsets(SeekableInputStream input, ColumnChunkMetaData chunk, long newChunkStart)
+      throws IOException {
+    long firstDataPageOffset;
+    long dictionaryPageOffset;
+    if (chunk.hasDictionaryPage()) {
+      long dictionaryPageSize = chunk.getFirstDataPageOffset() - chunk.getDictionaryPageOffset();
+      if (dictionaryPageSize <= 0) {
+        // The offset values might be invalid so we have to read the size of the dictionary page
+        dictionaryPageSize = readDictionaryPageSize(input, newChunkStart);
+      }
+      firstDataPageOffset = newChunkStart + dictionaryPageSize;
+      dictionaryPageOffset = newChunkStart;
+    } else {
+      firstDataPageOffset = newChunkStart;
+      dictionaryPageOffset = 0;
+    }
+    return new Offsets(firstDataPageOffset, dictionaryPageOffset);
+  }
+
+  private static long readDictionaryPageSize(SeekableInputStream in, long pos) throws IOException {
+    long origPos = -1;
+    try {
+      origPos = in.getPos();
+      // TODO: Do we need to handle encryption here?

Review comment:
       If it is encrypted, I guess we need decrypt it https://github.com/apache/parquet-mr/blob/master/parquet-format-structures/src/main/java/org/apache/parquet/format/Util.java#L130

##########
File path: parquet-hadoop/src/main/java/org/apache/parquet/hadoop/metadata/ColumnChunkMetaData.java
##########
@@ -566,7 +567,7 @@ public Statistics getStatistics() {
   private final ParquetMetadataConverter parquetMetadataConverter;
   private final byte[] encryptedMetadata;
   private final byte[] columnKeyMetadata;
-  private final InternalFileDecryptor fileDecryptor; 

Review comment:
       This could be changed by IDE, but it is unnecessary.  




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org