thamht4190 commented on a change in pull request #8023:
URL: https://github.com/apache/arrow/pull/8023#discussion_r579596080



##########
File path: cpp/src/parquet/encryption/test_encryption_util.cc
##########
@@ -0,0 +1,481 @@
+// 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.
+
+// This module defines an abstract interface for iterating through pages in a
+// Parquet column chunk within a row group. It could be extended in the future
+// to iterate through all data pages in all chunks in a file.
+
+#include <arrow/io/file.h>
+
+#include "parquet/encryption/test_encryption_util.h"
+#include "parquet/file_reader.h"
+#include "parquet/file_writer.h"
+#include "parquet/properties.h"
+
+using FileClass = ::arrow::io::FileOutputStream;
+
+namespace parquet {
+namespace encryption {
+namespace test {
+
+FileEncryptor::FileEncryptor() { schema_ = SetupEncryptionSchema(); }
+
+std::shared_ptr<GroupNode> FileEncryptor::SetupEncryptionSchema() {
+  parquet::schema::NodeVector fields;
+  // Create a primitive node named 'boolean_field' with type:BOOLEAN,
+  // repetition:REQUIRED
+  fields.push_back(PrimitiveNode::Make(kBooleanFieldName, Repetition::REQUIRED,
+                                       Type::BOOLEAN, ConvertedType::NONE));
+
+  // Create a primitive node named 'int32_field' with type:INT32, 
repetition:REQUIRED,
+  // logical type:TIME_MILLIS
+  fields.push_back(PrimitiveNode::Make(kInt32FieldName, Repetition::REQUIRED, 
Type::INT32,
+                                       ConvertedType::TIME_MILLIS));
+
+  // Create a primitive node named 'int64_field' with type:INT64, 
repetition:REPEATED
+  fields.push_back(PrimitiveNode::Make(kInt64FieldName, Repetition::REPEATED, 
Type::INT64,
+                                       ConvertedType::NONE));
+
+  fields.push_back(PrimitiveNode::Make(kInt96FieldName, Repetition::REQUIRED, 
Type::INT96,
+                                       ConvertedType::NONE));
+
+  fields.push_back(PrimitiveNode::Make(kFloatFieldName, Repetition::REQUIRED, 
Type::FLOAT,
+                                       ConvertedType::NONE));
+
+  fields.push_back(PrimitiveNode::Make(kDoubleFieldName, Repetition::REQUIRED,
+                                       Type::DOUBLE, ConvertedType::NONE));
+
+  // Create a primitive node named 'ba_field' with type:BYTE_ARRAY, 
repetition:OPTIONAL
+  fields.push_back(PrimitiveNode::Make(kByteArrayFieldName, 
Repetition::OPTIONAL,
+                                       Type::BYTE_ARRAY, ConvertedType::NONE));
+
+  // Create a primitive node named 'flba_field' with type:FIXED_LEN_BYTE_ARRAY,
+  // repetition:REQUIRED, field_length = kFixedLength
+  fields.push_back(PrimitiveNode::Make(kFixedLenByteArrayFieldName, 
Repetition::REQUIRED,
+                                       Type::FIXED_LEN_BYTE_ARRAY, 
ConvertedType::NONE,
+                                       kFixedLength));
+
+  // Create a GroupNode named 'schema' using the primitive nodes defined above
+  // This GroupNode is the root node of the schema tree
+  return std::static_pointer_cast<GroupNode>(
+      GroupNode::Make("schema", Repetition::REQUIRED, fields));
+}
+
+void FileEncryptor::EncryptFile(
+    std::string file,
+    std::shared_ptr<parquet::FileEncryptionProperties> 
encryption_configurations) {
+  WriterProperties::Builder prop_builder;
+  prop_builder.compression(parquet::Compression::SNAPPY);
+  prop_builder.encryption(encryption_configurations);
+  std::shared_ptr<WriterProperties> writer_properties = prop_builder.build();
+
+  PARQUET_ASSIGN_OR_THROW(auto out_file, FileClass::Open(file));
+  // Create a ParquetFileWriter instance
+  std::shared_ptr<parquet::ParquetFileWriter> file_writer =
+      parquet::ParquetFileWriter::Open(out_file, schema_, writer_properties);
+
+  for (int r = 0; r < num_rgs; r++) {
+    bool buffered_mode = r % 2 == 0;
+    auto row_group_writer = buffered_mode ? 
file_writer->AppendBufferedRowGroup()
+                                          : file_writer->AppendRowGroup();
+
+    int column_index = 0;
+    // Captures i by reference; increments it by one
+    auto get_next_column = [&]() {
+      return buffered_mode ? row_group_writer->column(column_index++)
+                           : row_group_writer->NextColumn();
+    };
+
+    // Write the Bool column
+    parquet::BoolWriter* bool_writer =
+        static_cast<parquet::BoolWriter*>(get_next_column());
+    for (int i = 0; i < rows_per_rowgroup_; i++) {
+      bool value = ((i % 2) == 0) ? true : false;
+      bool_writer->WriteBatch(1, nullptr, nullptr, &value);

Review comment:
       I did it for other types, except `bool` and byte array.




----------------------------------------------------------------
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:
[email protected]


Reply via email to