baibaichen commented on code in PR #4634:
URL: https://github.com/apache/incubator-gluten/pull/4634#discussion_r1528341292


##########
cpp-ch/local-engine/Storages/Parquet/VectorizedParquetRecordReader.cpp:
##########
@@ -0,0 +1,523 @@
+/*
+ * 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.
+ */
+#include "VectorizedParquetRecordReader.h"
+
+#if USE_PARQUET
+#include <numeric>
+#include <optional>
+#include <Processors/Chunk.h>
+#include <Processors/Formats/Impl/ArrowBufferedStreams.h>
+#include <Processors/Formats/Impl/ArrowFieldIndexUtil.h>
+#include <Storages/Parquet/ArrowUtils.h>
+#include <arrow/io/memory.h>
+#include <arrow/util/int_util_overflow.h>
+#include <boost/iterator/counting_iterator.hpp>
+#include <parquet/column_reader.h>
+#include <parquet/file_reader.h>
+#include <parquet/page_index.h>
+
+namespace
+{
+bool extend(arrow::io::ReadRange & read_range, const int64_t offset, const 
int64_t length)
+{
+    if (read_range.offset + read_range.length == offset)
+    {
+        read_range.length += length;
+        return true;
+    }
+    return false;
+}
+void emplaceReadRange(local_engine::ReadRanges & read_ranges, const int64_t 
offset, const int64_t length)
+{
+    if (read_ranges.empty() || !extend(read_ranges.back(), offset, length))
+        read_ranges.emplace_back(arrow::io::ReadRange{offset, length});
+}
+
+/// Compute the section of the file that should be read for the given
+/// row group and column chunk.
+::arrow::io::ReadRange ComputeColumnChunkRange(
+    const parquet::FileMetaData & file_metadata, const 
parquet::ColumnChunkMetaData & column_metadata, const int64_t source_size)
+{
+    // For PARQUET-816
+    static constexpr int64_t kMaxDictHeaderSize = 100;
+
+    int64_t col_start = column_metadata.data_page_offset();
+    if (column_metadata.has_dictionary_page() && 
column_metadata.dictionary_page_offset() > 0
+        && col_start > column_metadata.dictionary_page_offset())
+        col_start = column_metadata.dictionary_page_offset();
+
+    int64_t col_length = column_metadata.total_compressed_size();
+    int64_t col_end;
+    if (col_start < 0 || col_length < 0)
+        throw parquet::ParquetException("Invalid column metadata (corrupt 
file?)");

Review Comment:
   https://github.com/apache/incubator-gluten/issues/4998 for tracing this 
iussue



##########
cpp-ch/local-engine/Storages/Parquet/VectorizedParquetRecordReader.cpp:
##########
@@ -0,0 +1,523 @@
+/*
+ * 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.
+ */
+#include "VectorizedParquetRecordReader.h"
+
+#if USE_PARQUET
+#include <numeric>
+#include <optional>
+#include <Processors/Chunk.h>
+#include <Processors/Formats/Impl/ArrowBufferedStreams.h>
+#include <Processors/Formats/Impl/ArrowFieldIndexUtil.h>
+#include <Storages/Parquet/ArrowUtils.h>
+#include <arrow/io/memory.h>
+#include <arrow/util/int_util_overflow.h>
+#include <boost/iterator/counting_iterator.hpp>
+#include <parquet/column_reader.h>
+#include <parquet/file_reader.h>
+#include <parquet/page_index.h>
+
+namespace
+{
+bool extend(arrow::io::ReadRange & read_range, const int64_t offset, const 
int64_t length)
+{
+    if (read_range.offset + read_range.length == offset)
+    {
+        read_range.length += length;
+        return true;
+    }
+    return false;
+}
+void emplaceReadRange(local_engine::ReadRanges & read_ranges, const int64_t 
offset, const int64_t length)
+{
+    if (read_ranges.empty() || !extend(read_ranges.back(), offset, length))
+        read_ranges.emplace_back(arrow::io::ReadRange{offset, length});
+}
+
+/// Compute the section of the file that should be read for the given
+/// row group and column chunk.
+::arrow::io::ReadRange ComputeColumnChunkRange(
+    const parquet::FileMetaData & file_metadata, const 
parquet::ColumnChunkMetaData & column_metadata, const int64_t source_size)
+{
+    // For PARQUET-816
+    static constexpr int64_t kMaxDictHeaderSize = 100;
+
+    int64_t col_start = column_metadata.data_page_offset();
+    if (column_metadata.has_dictionary_page() && 
column_metadata.dictionary_page_offset() > 0
+        && col_start > column_metadata.dictionary_page_offset())
+        col_start = column_metadata.dictionary_page_offset();
+
+    int64_t col_length = column_metadata.total_compressed_size();
+    int64_t col_end;
+    if (col_start < 0 || col_length < 0)
+        throw parquet::ParquetException("Invalid column metadata (corrupt 
file?)");

Review Comment:
   add https://github.com/apache/incubator-gluten/issues/4998 for tracing this 
iussue



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to