Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions example/demo_example.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@

#include <iostream>

#include "iceberg/avro/avro_reader.h"
#include "iceberg/avro/avro_register.h"
#include "iceberg/file_reader.h"
#include "iceberg/parquet/parquet_register.h"

int main() {
iceberg::avro::AvroReader::Register();
iceberg::avro::RegisterAll();
iceberg::parquet::RegisterAll();
auto open_result = iceberg::ReaderFactoryRegistry::Open(
iceberg::FileFormatType::kAvro, {.path = "non-existing-file.avro"});
if (!open_result.has_value()) {
Expand Down
3 changes: 2 additions & 1 deletion src/iceberg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,12 @@ if(ICEBERG_BUILD_BUNDLE)
avro/avro_data_util.cc
avro/avro_reader.cc
avro/avro_writer.cc
avro/avro_schema_util.cc
avro/avro_register.cc
avro/avro_schema_util.cc
avro/avro_stream_internal.cc
parquet/parquet_data_util.cc
parquet/parquet_reader.cc
parquet/parquet_register.cc
parquet/parquet_schema_util.cc)

# Libraries to link with exported libiceberg_bundle.{so,a}.
Expand Down
3 changes: 2 additions & 1 deletion src/iceberg/avro/avro_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "iceberg/arrow/arrow_error_transform_internal.h"
#include "iceberg/arrow/arrow_fs_file_io_internal.h"
#include "iceberg/avro/avro_data_util_internal.h"
#include "iceberg/avro/avro_register.h"
#include "iceberg/avro/avro_schema_util_internal.h"
#include "iceberg/avro/avro_stream_internal.h"
#include "iceberg/name_mapping.h"
Expand Down Expand Up @@ -247,7 +248,7 @@ Status AvroReader::Open(const ReaderOptions& options) {

Status AvroReader::Close() { return impl_->Close(); }

void AvroReader::Register() {
void RegisterReader() {
static ReaderFactoryRegistry avro_reader_register(
FileFormatType::kAvro,
[]() -> Result<std::unique_ptr<Reader>> { return std::make_unique<AvroReader>(); });
Expand Down
3 changes: 0 additions & 3 deletions src/iceberg/avro/avro_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@ class ICEBERG_BUNDLE_EXPORT AvroReader : public Reader {

Result<ArrowSchema> Schema() final;

/// \brief Register this Avro reader implementation.
static void Register();

private:
class Impl;
std::unique_ptr<Impl> impl_;
Expand Down
17 changes: 10 additions & 7 deletions src/iceberg/avro/avro_register.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
namespace iceberg::avro {

void RegisterLogicalTypes() {
static std::once_flag flag{};
std::call_once(flag, []() {
// Register the map logical type with the avro custom logical type registry.
// See https://github.com/apache/avro/pull/3326 for details.
::avro::CustomLogicalTypeRegistry::instance().registerType(
"map", [](const std::string&) { return std::make_shared<MapLogicalType>(); });
});
// Register the map logical type with the avro custom logical type registry.
// See https://github.com/apache/avro/pull/3326 for details.
::avro::CustomLogicalTypeRegistry::instance().registerType(
"map", [](const std::string&) { return std::make_shared<MapLogicalType>(); });
}

void RegisterAll() {
RegisterLogicalTypes();
RegisterReader();
RegisterWriter();
}

} // namespace iceberg::avro
13 changes: 13 additions & 0 deletions src/iceberg/avro/avro_register.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,23 @@

#pragma once

/// \file iceberg/avro/avro_register.h
/// \brief Provide functions to register Avro implementations.

#include "iceberg/iceberg_bundle_export.h"

namespace iceberg::avro {

/// \brief Register all the logical types.
ICEBERG_BUNDLE_EXPORT void RegisterLogicalTypes();

/// \brief Register Avro reader implementation.
ICEBERG_BUNDLE_EXPORT void RegisterReader();

/// \brief Register Avro writer implementation.
ICEBERG_BUNDLE_EXPORT void RegisterWriter();

/// \brief Register all the logical types, Avro reader, and Avro writer.
ICEBERG_BUNDLE_EXPORT void RegisterAll();

} // namespace iceberg::avro
8 changes: 0 additions & 8 deletions src/iceberg/avro/avro_schema_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,7 @@ namespace iceberg::avro {

namespace {

constexpr std::string_view kIcebergFieldNameProp = "iceberg-field-name";
constexpr std::string_view kFieldIdProp = "field-id";
constexpr std::string_view kKeyIdProp = "key-id";
constexpr std::string_view kValueIdProp = "value-id";
constexpr std::string_view kElementIdProp = "element-id";
constexpr std::string_view kAdjustToUtcProp = "adjust-to-utc";

::avro::LogicalType GetMapLogicalType() {
RegisterLogicalTypes();
return ::avro::LogicalType(std::make_shared<MapLogicalType>());
}

Expand Down
3 changes: 2 additions & 1 deletion src/iceberg/avro/avro_writer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

#include "iceberg/arrow/arrow_error_transform_internal.h"
#include "iceberg/arrow/arrow_fs_file_io_internal.h"
#include "iceberg/avro/avro_register.h"
#include "iceberg/avro/avro_schema_util_internal.h"
#include "iceberg/avro/avro_stream_internal.h"
#include "iceberg/schema.h"
Expand Down Expand Up @@ -133,7 +134,7 @@ std::optional<int64_t> AvroWriter::length() {

std::vector<int64_t> AvroWriter::split_offsets() { return {}; }

void AvroWriter::Register() {
void RegisterWriter() {
static WriterFactoryRegistry avro_writer_register(
FileFormatType::kAvro,
[]() -> Result<std::unique_ptr<Writer>> { return std::make_unique<AvroWriter>(); });
Expand Down
3 changes: 0 additions & 3 deletions src/iceberg/avro/avro_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ class ICEBERG_BUNDLE_EXPORT AvroWriter : public Writer {

std::vector<int64_t> split_offsets() final;

/// \brief Register this Avro writer implementation.
static void Register();

private:
class Impl;
std::unique_ptr<Impl> impl_;
Expand Down
8 changes: 8 additions & 0 deletions src/iceberg/avro/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,12 @@ constexpr std::string_view kElement = "element";
constexpr std::string_view kKey = "key";
constexpr std::string_view kValue = "value";

// Avro custom attributes constants
constexpr std::string_view kIcebergFieldNameProp = "iceberg-field-name";
constexpr std::string_view kFieldIdProp = "field-id";
constexpr std::string_view kKeyIdProp = "key-id";
constexpr std::string_view kValueIdProp = "value-id";
constexpr std::string_view kElementIdProp = "element-id";
constexpr std::string_view kAdjustToUtcProp = "adjust-to-utc";

} // namespace iceberg::avro
3 changes: 2 additions & 1 deletion src/iceberg/parquet/parquet_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "iceberg/arrow/arrow_error_transform_internal.h"
#include "iceberg/arrow/arrow_fs_file_io_internal.h"
#include "iceberg/parquet/parquet_data_util_internal.h"
#include "iceberg/parquet/parquet_register.h"
#include "iceberg/parquet/parquet_schema_util_internal.h"
#include "iceberg/result.h"
#include "iceberg/schema_internal.h"
Expand Down Expand Up @@ -254,7 +255,7 @@ Status ParquetReader::Open(const ReaderOptions& options) {

Status ParquetReader::Close() { return impl_->Close(); }

void ParquetReader::Register() {
void RegisterReader() {
static ReaderFactoryRegistry parquet_reader_register(
FileFormatType::kParquet, []() -> Result<std::unique_ptr<Reader>> {
return std::make_unique<ParquetReader>();
Expand Down
2 changes: 0 additions & 2 deletions src/iceberg/parquet/parquet_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class ICEBERG_BUNDLE_EXPORT ParquetReader : public Reader {

Result<ArrowSchema> Schema() final;

static void Register();

private:
class Impl;
std::unique_ptr<Impl> impl_;
Expand Down
31 changes: 31 additions & 0 deletions src/iceberg/parquet/parquet_register.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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 "iceberg/parquet/parquet_register.h"

namespace iceberg::parquet {

void RegisterWriter() {}

void RegisterAll() {
RegisterReader();
RegisterWriter();
}

} // namespace iceberg::parquet
38 changes: 38 additions & 0 deletions src/iceberg/parquet/parquet_register.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.
*/

#pragma once

/// \file iceberg/parquet/parquet_register.h
/// \brief Provide functions to register Parquet implementations.

#include "iceberg/iceberg_bundle_export.h"

namespace iceberg::parquet {

/// \brief Register Parquet reader implementation.
ICEBERG_BUNDLE_EXPORT void RegisterReader();

/// \brief Register Parquet writer implementation.
ICEBERG_BUNDLE_EXPORT void RegisterWriter();

/// \brief Register Parquet reader and writer implementations.
ICEBERG_BUNDLE_EXPORT void RegisterAll();

} // namespace iceberg::parquet
5 changes: 3 additions & 2 deletions test/avro_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
#include <gtest/gtest.h>

#include "iceberg/arrow/arrow_fs_file_io_internal.h"
#include "iceberg/avro/avro_reader.h"
#include "iceberg/avro/avro_register.h"
#include "iceberg/file_reader.h"
#include "iceberg/schema.h"
#include "iceberg/type.h"
#include "matchers.h"
Expand All @@ -40,7 +41,7 @@ namespace iceberg::avro {

class AvroReaderTest : public TempFileTestBase {
protected:
static void SetUpTestSuite() { AvroReader::Register(); }
static void SetUpTestSuite() { RegisterAll(); }

void SetUp() override {
TempFileTestBase::SetUp();
Expand Down
4 changes: 2 additions & 2 deletions test/manifest_list_reader_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <gtest/gtest.h>

#include "iceberg/arrow/arrow_fs_file_io_internal.h"
#include "iceberg/avro/avro_reader.h"
#include "iceberg/avro/avro_register.h"
#include "iceberg/manifest_list.h"
#include "iceberg/manifest_reader.h"
#include "temp_file_test_base.h"
Expand All @@ -32,7 +32,7 @@ namespace iceberg {

class ManifestListReaderTestBase : public TempFileTestBase {
protected:
static void SetUpTestSuite() { avro::AvroReader::Register(); }
static void SetUpTestSuite() { avro::RegisterAll(); }

void SetUp() override {
TempFileTestBase::SetUp();
Expand Down
9 changes: 2 additions & 7 deletions test/manifest_reader_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <gtest/gtest.h>

#include "iceberg/arrow/arrow_fs_file_io_internal.h"
#include "iceberg/avro/avro_reader.h"
#include "iceberg/avro/avro_register.h"
#include "iceberg/manifest_entry.h"
#include "iceberg/schema.h"
Expand All @@ -36,14 +35,12 @@ namespace iceberg {

class ManifestReaderV1Test : public TempFileTestBase {
protected:
static void SetUpTestSuite() { avro::AvroReader::Register(); }
static void SetUpTestSuite() { avro::RegisterAll(); }

void SetUp() override {
TempFileTestBase::SetUp();
local_fs_ = std::make_shared<::arrow::fs::LocalFileSystem>();
file_io_ = std::make_shared<iceberg::arrow::ArrowFileSystemFileIO>(local_fs_);

avro::RegisterLogicalTypes();
}

std::vector<ManifestEntry> PrepareV1ManifestEntries() {
Expand Down Expand Up @@ -122,14 +119,12 @@ TEST_F(ManifestReaderV1Test, V1PartitionedBasicTest) {

class ManifestReaderV2Test : public TempFileTestBase {
protected:
static void SetUpTestSuite() { avro::AvroReader::Register(); }
static void SetUpTestSuite() { avro::RegisterAll(); }

void SetUp() override {
TempFileTestBase::SetUp();
local_fs_ = std::make_shared<::arrow::fs::LocalFileSystem>();
file_io_ = std::make_shared<iceberg::arrow::ArrowFileSystemFileIO>(local_fs_);

avro::RegisterLogicalTypes();
}

std::vector<ManifestEntry> PrepareV2NonPartitionedManifestEntries() {
Expand Down
3 changes: 2 additions & 1 deletion test/parquet_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "iceberg/arrow/arrow_fs_file_io_internal.h"
#include "iceberg/parquet/parquet_reader.h"
#include "iceberg/parquet/parquet_register.h"
#include "iceberg/schema.h"
#include "iceberg/type.h"
#include "iceberg/util/checked_cast.h"
Expand All @@ -39,7 +40,7 @@ namespace iceberg::parquet {

class ParquetReaderTest : public TempFileTestBase {
protected:
static void SetUpTestSuite() { ParquetReader::Register(); }
static void SetUpTestSuite() { parquet::RegisterAll(); }

void SetUp() override {
TempFileTestBase::SetUp();
Expand Down
Loading