HuaHuaY commented on code in PR #47775:
URL: https://github.com/apache/arrow/pull/47775#discussion_r2782236557


##########
cpp/src/parquet/file_rewriter.cc:
##########
@@ -0,0 +1,455 @@
+// 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 "parquet/file_rewriter.h"
+
+#include <memory>
+#include <numeric>
+#include <sstream>
+#include <unordered_set>
+#include <utility>
+
+#include "parquet/bloom_filter.h"
+#include "parquet/bloom_filter_reader.h"
+#include "parquet/column_reader.h"
+#include "parquet/exception.h"
+#include "parquet/file_reader.h"
+#include "parquet/file_writer.h"
+#include "parquet/metadata.h"
+#include "parquet/page_index.h"
+#include "parquet/platform.h"
+#include "parquet/properties.h"
+
+namespace parquet {
+
+const std::shared_ptr<RewriterProperties>& default_rewriter_properties() {
+  static std::shared_ptr<RewriterProperties> default_rewriter_properties =
+      RewriterProperties::Builder().build();
+  return default_rewriter_properties;
+}
+
+class RowGroupRewriter {
+ public:
+  RowGroupRewriter(std::shared_ptr<ArrowInputFile> source,
+                   std::shared_ptr<ArrowOutputStream> sink,
+                   const RewriterProperties* props,
+                   std::shared_ptr<RowGroupReader> row_group_reader,
+                   std::shared_ptr<RowGroupPageIndexReader> page_index_reader,
+                   std::shared_ptr<RowGroupBloomFilterReader> 
bloom_filter_reader)
+      : source_(std::move(source)),
+        sink_(std::move(sink)),
+        props_(props),
+        row_group_reader_(std::move(row_group_reader)),
+        page_index_reader_(std::move(page_index_reader)),
+        bloom_filter_reader_(std::move(bloom_filter_reader)),
+        metadata_(row_group_reader_->metadata()) {}
+
+  void WriteData(bool fast_copy, RowGroupMetaDataBuilder* rg_metadata_builder,
+                 PageIndexBuilder* page_index_builder, int64_t& 
total_bytes_written) {
+    rg_metadata_builder->set_num_rows(metadata_->num_rows());
+    if (fast_copy) {
+      PARQUET_ASSIGN_OR_THROW(int64_t sink_offset, sink_->Tell());
+      int64_t shift = sink_offset - metadata_->file_offset();
+
+      auto stream = props_->reader_properties().GetStream(
+          source_, metadata_->file_offset(), 
metadata_->total_compressed_size());
+      CopyStream(stream, sink_, metadata_->total_compressed_size());
+      PARQUET_THROW_NOT_OK(stream->Close());
+
+      for (int i = 0; i < metadata_->num_columns(); ++i) {
+        auto cc_metadata = metadata_->ColumnChunk(i);
+        rg_metadata_builder->NextColumnChunk(std::move(cc_metadata), shift);
+
+        // TODO(HuaHuaY): copy column index and bloom filter instead of 
reading and
+        // writing it.
+        auto column_index = page_index_reader_->GetColumnIndex(i);
+        auto offset_index = page_index_reader_->GetOffsetIndex(i);
+        // TODO(HuaHuaY): support bloom filter writer
+        [[maybe_unused]] auto bloom_filter =
+            bloom_filter_reader_->GetColumnBloomFilter(i);
+
+        page_index_builder->SetColumnIndex(i, column_index);
+        page_index_builder->SetOffsetIndex(i, offset_index, shift);
+      }
+
+      total_bytes_written += metadata_->total_byte_size();
+    } else {

Review Comment:
   We need to add a `ColumnChunkRewriter` class and move some code in else 
branch into the new class.



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

Reply via email to