MCPcopy Create free account
hub / github.com/apache/arrow / MakePopulator

Function MakePopulator

cpp/src/arrow/csv/writer.cc:441–494  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

439};
440
441Result<std::unique_ptr<ColumnPopulator>> MakePopulator(
442 const DataType& type, const std::string& end_chars, const char delimiter,
443 const std::shared_ptr<Buffer>& null_string, QuotingStyle quoting_style,
444 MemoryPool* pool) {
445 auto make_populator =
446 [&](const auto& type) -> Result<std::unique_ptr<ColumnPopulator>> {
447 using Type = std::decay_t<decltype(type)>;
448
449 if constexpr (is_primitive_ctype<Type>::value || is_decimal_type<Type>::value ||
450 is_null_type<Type>::value || is_temporal_type<Type>::value) {
451 switch (quoting_style) {
452 // These types are assumed not to produce any quotes, so we do not need to
453 // check and reject for potential quotes in the casted values in case the
454 // QuotingStyle is None.
455 case QuotingStyle::None:
456 [[fallthrough]];
457 case QuotingStyle::Needed:
458 return std::make_unique<UnquotedColumnPopulator>(
459 pool, end_chars, delimiter, null_string,
460 /*reject_values_with_quotes=*/false);
461 case QuotingStyle::AllValid:
462 return std::make_unique<QuotedColumnPopulator>(pool, end_chars, null_string);
463 }
464 }
465
466 if constexpr (is_base_binary_type<Type>::value ||
467 std::is_same<Type, FixedSizeBinaryType>::value) {
468 // Determine what ColumnPopulator to use based on desired CSV quoting style.
469 switch (quoting_style) {
470 case QuotingStyle::None:
471 // In unquoted output we must reject values with quotes. Since these types
472 // can produce quotes in their output rendering, we must check them and
473 // reject if quotes appear, hence reject_values_with_quotes is set to true.
474 return std::make_unique<UnquotedColumnPopulator>(
475 pool, end_chars, delimiter, null_string,
476 /*reject_values_with_quotes=*/true);
477 // Quoting is needed for strings/binary, or when all valid values need to be
478 // quoted.
479 case QuotingStyle::Needed:
480 [[fallthrough]];
481 case QuotingStyle::AllValid:
482 return std::make_unique<QuotedColumnPopulator>(pool, end_chars, null_string);
483 }
484 }
485
486 if constexpr (std::is_same<Type, DictionaryType>::value) {
487 return MakePopulator(*type.value_type(), end_chars, delimiter, null_string,
488 quoting_style, pool);
489 }
490
491 return Status::Invalid("Unsupported Type:", type.ToString());
492 };
493 return VisitType(type, make_populator);
494}
495
496Result<std::unique_ptr<ColumnPopulator>> MakePopulator(
497 const Field& field, const std::string& end_chars, char delimiter,

Callers 1

MakeMethod · 0.85

Calls 5

InvalidFunction · 0.50
VisitTypeFunction · 0.50
value_typeMethod · 0.45
ToStringMethod · 0.45
typeMethod · 0.45

Tested by

no test coverage detected