Skip to content

Commit

Permalink
make previous Codec create api deprecate
Browse files Browse the repository at this point in the history
  • Loading branch information
yyang52 committed Jun 6, 2023
1 parent 50ef1ee commit a8748d8
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 1 deletion.
76 changes: 76 additions & 0 deletions cpp/src/arrow/util/compression.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,82 @@ Result<std::unique_ptr<Codec>> Codec::Create(
return std::move(codec);
}

// Deprecated and use CodecOptions to create Codec instead
Result<std::unique_ptr<Codec>> Codec::Create(Compression::type codec_type,
int compression_level) {
if (!IsAvailable(codec_type)) {
if (codec_type == Compression::LZO) {
return Status::NotImplemented("LZO codec not implemented");
}

auto name = GetCodecAsString(codec_type);
if (name == "unknown") {
return Status::Invalid("Unrecognized codec");
}

return Status::NotImplemented("Support for codec '", GetCodecAsString(codec_type),
"' not built");
}

if (compression_level != kUseDefaultCompressionLevel &&
!SupportsCompressionLevel(codec_type)) {
return Status::Invalid("Codec '", GetCodecAsString(codec_type),
"' doesn't support setting a compression level.");
}

std::unique_ptr<Codec> codec;
switch (codec_type) {
case Compression::UNCOMPRESSED:
return nullptr;
case Compression::SNAPPY:
#ifdef ARROW_WITH_SNAPPY
codec = internal::MakeSnappyCodec();
#endif
break;
case Compression::GZIP:
#ifdef ARROW_WITH_ZLIB
codec = internal::MakeGZipCodec(compression_level);
#endif
break;
case Compression::BROTLI:
#ifdef ARROW_WITH_BROTLI
codec = internal::MakeBrotliCodec(compression_level);
#endif
break;
case Compression::LZ4:
#ifdef ARROW_WITH_LZ4
codec = internal::MakeLz4RawCodec(compression_level);
#endif
break;
case Compression::LZ4_FRAME:
#ifdef ARROW_WITH_LZ4
codec = internal::MakeLz4FrameCodec(compression_level);
#endif
break;
case Compression::LZ4_HADOOP:
#ifdef ARROW_WITH_LZ4
codec = internal::MakeLz4HadoopRawCodec();
#endif
break;
case Compression::ZSTD:
#ifdef ARROW_WITH_ZSTD
codec = internal::MakeZSTDCodec(compression_level);
#endif
break;
case Compression::BZ2:
#ifdef ARROW_WITH_BZ2
codec = internal::MakeBZ2Codec(compression_level);
#endif
break;
default:
break;
}

DCHECK_NE(codec, nullptr);
RETURN_NOT_OK(codec->Init());
return std::move(codec);
}

bool Codec::IsAvailable(Compression::type codec_type) {
switch (codec_type) {
case Compression::UNCOMPRESSED:
Expand Down
5 changes: 5 additions & 0 deletions cpp/src/arrow/util/compression.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ class ARROW_EXPORT Codec {
const std::shared_ptr<CodecOptions>& codec_options =
std::make_shared<CodecOptions>(kUseDefaultCompressionLevel));

/// \brief Create a codec for the given compression algorithm
/// \deprecated and left for backwards compatibility.
static Result<std::unique_ptr<Codec>> Create(Compression::type codec,
int compression_level);

/// \brief Return true if support for indicated codec has been enabled
static bool IsAvailable(Compression::type codec);

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/util/compression_zlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,10 @@ class GZipCodec : public Codec {
// Indeed, this is slightly hacky, but the alternative is having separate
// Compressor and Decompressor classes. If this ever becomes an issue, we can
// perform the refactoring then
int window_bits_;
bool compressor_initialized_;
bool decompressor_initialized_;
int compression_level_;
int window_bits_;
};

} // namespace
Expand Down
20 changes: 20 additions & 0 deletions cpp/src/parquet/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ std::unique_ptr<Codec> GetCodec(Compression::type codec,
return result;
}

// Deprecated and use CodecOptions to create Codec instead
std::unique_ptr<Codec> GetCodec(Compression::type codec, int compression_level) {
std::unique_ptr<Codec> result;
if (codec == Compression::LZO) {
throw ParquetException(
"While LZO compression is supported by the Parquet format in "
"general, it is currently not supported by the C++ implementation.");
}

if (!IsCodecSupported(codec)) {
std::stringstream ss;
ss << "Codec type " << Codec::GetCodecAsString(codec)
<< " not supported in Parquet format";
throw ParquetException(ss.str());
}

PARQUET_ASSIGN_OR_THROW(result, Codec::Create(codec, compression_level));
return result;
}

std::string FormatStatValue(Type::type parquet_type, ::std::string_view val) {
std::stringstream result;

Expand Down
4 changes: 4 additions & 0 deletions cpp/src/parquet/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@ PARQUET_EXPORT
std::unique_ptr<Codec> GetCodec(Compression::type codec,
const std::shared_ptr<CodecOptions>& codec_options);

/// \deprecated and left for backwards compatibility.
PARQUET_EXPORT
std::unique_ptr<Codec> GetCodec(Compression::type codec, int compression_level);

struct ParquetCipher {
enum type { AES_GCM_V1 = 0, AES_GCM_CTR_V1 = 1 };
};
Expand Down

0 comments on commit a8748d8

Please sign in to comment.