Skip to content

Commit

Permalink
apacheGH-40767: Minor enhance style for creating page writer
Browse files Browse the repository at this point in the history
  • Loading branch information
mapleFU committed Mar 24, 2024
1 parent 6aa6f85 commit f191257
Showing 1 changed file with 31 additions and 35 deletions.
66 changes: 31 additions & 35 deletions cpp/src/parquet/file_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -140,37 +140,35 @@ class RowGroupSerializer : public RowGroupWriter::Contents {

const int32_t column_ordinal = next_column_index_++;
const auto& path = col_meta->descr()->path();
const ColumnProperties& column_properties = properties_->column_properties(path);
auto meta_encryptor =
file_encryptor_ ? file_encryptor_->GetColumnMetaEncryptor(path->ToDotString())
: nullptr;
auto data_encryptor =
file_encryptor_ ? file_encryptor_->GetColumnDataEncryptor(path->ToDotString())
: nullptr;
auto ci_builder = page_index_builder_ && properties_->page_index_enabled(path) &&
properties_->statistics_enabled(path)
auto ci_builder = page_index_builder_ && column_properties.page_index_enabled() &&
column_properties.statistics_enabled()
? page_index_builder_->GetColumnIndexBuilder(column_ordinal)
: nullptr;
auto oi_builder = page_index_builder_ && properties_->page_index_enabled(path)
auto oi_builder = page_index_builder_ && column_properties.page_index_enabled()
? page_index_builder_->GetOffsetIndexBuilder(column_ordinal)
: nullptr;
auto codec_options = properties_->codec_options(path)
? properties_->codec_options(path).get()
: nullptr;
const CodecOptions* codec_options = column_properties.codec_options()
? column_properties.codec_options().get()
: nullptr;

std::unique_ptr<PageWriter> pager;
CodecOptions default_codec_options;
if (!codec_options) {
pager = PageWriter::Open(sink_, properties_->compression(path), col_meta,
row_group_ordinal_, static_cast<int16_t>(column_ordinal),
properties_->memory_pool(), false, meta_encryptor,
data_encryptor, properties_->page_checksum_enabled(),
ci_builder, oi_builder, CodecOptions());
} else {
pager = PageWriter::Open(sink_, properties_->compression(path), col_meta,
row_group_ordinal_, static_cast<int16_t>(column_ordinal),
properties_->memory_pool(), false, meta_encryptor,
data_encryptor, properties_->page_checksum_enabled(),
ci_builder, oi_builder, *codec_options);
codec_options = &default_codec_options;
}
DCHECK_NE(nullptr, codec_options);
std::unique_ptr<PageWriter> pager = PageWriter::Open(
sink_, properties_->compression(path), col_meta, row_group_ordinal_,
static_cast<int16_t>(column_ordinal), properties_->memory_pool(), false,
meta_encryptor, data_encryptor, properties_->page_checksum_enabled(), ci_builder,
oi_builder, *codec_options);

column_writers_[0] = ColumnWriter::Make(col_meta, std::move(pager), properties_);
return column_writers_[0].get();
}
Expand Down Expand Up @@ -292,36 +290,34 @@ class RowGroupSerializer : public RowGroupWriter::Contents {
auto col_meta = metadata_->NextColumnChunk();
const auto& path = col_meta->descr()->path();
const int32_t column_ordinal = next_column_index_++;
const ColumnProperties& column_properties = properties_->column_properties(path);
auto meta_encryptor =
file_encryptor_ ? file_encryptor_->GetColumnMetaEncryptor(path->ToDotString())
: nullptr;
auto data_encryptor =
file_encryptor_ ? file_encryptor_->GetColumnDataEncryptor(path->ToDotString())
: nullptr;
auto ci_builder = page_index_builder_ && properties_->page_index_enabled(path)
auto ci_builder = page_index_builder_ && column_properties.page_index_enabled()
? page_index_builder_->GetColumnIndexBuilder(column_ordinal)
: nullptr;
auto oi_builder = page_index_builder_ && properties_->page_index_enabled(path)
auto oi_builder = page_index_builder_ && column_properties.page_index_enabled()
? page_index_builder_->GetOffsetIndexBuilder(column_ordinal)
: nullptr;
auto codec_options = properties_->codec_options(path)
? (properties_->codec_options(path)).get()
: nullptr;

std::unique_ptr<PageWriter> pager;
const CodecOptions* codec_options = column_properties.codec_options()
? column_properties.codec_options().get()
: nullptr;
CodecOptions default_codec_options;
if (!codec_options) {
pager = PageWriter::Open(
sink_, properties_->compression(path), col_meta, row_group_ordinal_,
static_cast<int16_t>(column_ordinal), properties_->memory_pool(),
buffered_row_group_, meta_encryptor, data_encryptor,
properties_->page_checksum_enabled(), ci_builder, oi_builder, CodecOptions());
} else {
pager = PageWriter::Open(
sink_, properties_->compression(path), col_meta, row_group_ordinal_,
static_cast<int16_t>(column_ordinal), properties_->memory_pool(),
buffered_row_group_, meta_encryptor, data_encryptor,
properties_->page_checksum_enabled(), ci_builder, oi_builder, *codec_options);
codec_options = &default_codec_options;
}
DCHECK_NE(nullptr, codec_options);
std::unique_ptr<PageWriter> pager = PageWriter::Open(
sink_, properties_->compression(path), col_meta, row_group_ordinal_,
static_cast<int16_t>(column_ordinal), properties_->memory_pool(),
buffered_row_group_, meta_encryptor, data_encryptor,
properties_->page_checksum_enabled(), ci_builder, oi_builder, *codec_options);

column_writers_.push_back(
ColumnWriter::Make(col_meta, std::move(pager), properties_));
}
Expand Down

0 comments on commit f191257

Please sign in to comment.