Skip to content

Commit ff671c0

Browse files
committed
chore: consolidate avro and parquet register api
1 parent 515b019 commit ff671c0

File tree

12 files changed

+125
-30
lines changed

12 files changed

+125
-30
lines changed

example/demo_example.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,13 @@
1919

2020
#include <iostream>
2121

22-
#include "iceberg/avro/avro_reader.h"
22+
#include "iceberg/avro/avro_register.h"
2323
#include "iceberg/file_reader.h"
24+
#include "iceberg/parquet/parquet_register.h"
2425

2526
int main() {
26-
iceberg::avro::AvroReader::Register();
27+
iceberg::avro::RegisterAll();
28+
iceberg::parquet::RegisterAll();
2729
auto open_result = iceberg::ReaderFactoryRegistry::Open(
2830
iceberg::FileFormatType::kAvro, {.path = "non-existing-file.avro"});
2931
if (!open_result.has_value()) {

src/iceberg/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,12 @@ if(ICEBERG_BUILD_BUNDLE)
109109
avro/avro_data_util.cc
110110
avro/avro_reader.cc
111111
avro/avro_writer.cc
112-
avro/avro_schema_util.cc
113112
avro/avro_register.cc
113+
avro/avro_schema_util.cc
114114
avro/avro_stream_internal.cc
115115
parquet/parquet_data_util.cc
116116
parquet/parquet_reader.cc
117+
parquet/parquet_register.cc
117118
parquet/parquet_schema_util.cc)
118119

119120
# Libraries to link with exported libiceberg_bundle.{so,a}.

src/iceberg/avro/avro_register.cc

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,27 @@
1919

2020
#include "iceberg/avro/avro_register.h"
2121

22+
#include "iceberg/avro/avro_reader.h"
2223
#include "iceberg/avro/avro_schema_util_internal.h"
24+
#include "iceberg/avro/avro_writer.h"
2325

2426
namespace iceberg::avro {
2527

2628
void RegisterLogicalTypes() {
27-
static std::once_flag flag{};
28-
std::call_once(flag, []() {
29-
// Register the map logical type with the avro custom logical type registry.
30-
// See https://github.com/apache/avro/pull/3326 for details.
31-
::avro::CustomLogicalTypeRegistry::instance().registerType(
32-
"map", [](const std::string&) { return std::make_shared<MapLogicalType>(); });
33-
});
29+
// Register the map logical type with the avro custom logical type registry.
30+
// See https://github.com/apache/avro/pull/3326 for details.
31+
::avro::CustomLogicalTypeRegistry::instance().registerType(
32+
"map", [](const std::string&) { return std::make_shared<MapLogicalType>(); });
33+
}
34+
35+
void RegisterReader() { AvroReader::Register(); }
36+
37+
void RegisterWriter() { AvroWriter::Register(); }
38+
39+
void RegisterAll() {
40+
RegisterLogicalTypes();
41+
RegisterReader();
42+
RegisterWriter();
3443
}
3544

3645
} // namespace iceberg::avro

src/iceberg/avro/avro_register.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,23 @@
1919

2020
#pragma once
2121

22+
/// \file iceberg/avro/avro_register.h
23+
/// \brief Provide functions to register Avro implementations.
24+
2225
#include "iceberg/iceberg_bundle_export.h"
2326

2427
namespace iceberg::avro {
2528

29+
/// \brief Register all the logical types.
2630
ICEBERG_BUNDLE_EXPORT void RegisterLogicalTypes();
2731

32+
/// \brief Register Avro reader implementation.
33+
ICEBERG_BUNDLE_EXPORT void RegisterReader();
34+
35+
/// \brief Register Avro writer implementation.
36+
ICEBERG_BUNDLE_EXPORT void RegisterWriter();
37+
38+
/// \brief Register all the logical types, Avro reader, and Avro writer.
39+
ICEBERG_BUNDLE_EXPORT void RegisterAll();
40+
2841
} // namespace iceberg::avro

src/iceberg/avro/avro_schema_util.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,7 @@ namespace iceberg::avro {
4545

4646
namespace {
4747

48-
constexpr std::string_view kIcebergFieldNameProp = "iceberg-field-name";
49-
constexpr std::string_view kFieldIdProp = "field-id";
50-
constexpr std::string_view kKeyIdProp = "key-id";
51-
constexpr std::string_view kValueIdProp = "value-id";
52-
constexpr std::string_view kElementIdProp = "element-id";
53-
constexpr std::string_view kAdjustToUtcProp = "adjust-to-utc";
54-
5548
::avro::LogicalType GetMapLogicalType() {
56-
RegisterLogicalTypes();
5749
return ::avro::LogicalType(std::make_shared<MapLogicalType>());
5850
}
5951

src/iceberg/avro/constants.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,12 @@ constexpr std::string_view kElement = "element";
3131
constexpr std::string_view kKey = "key";
3232
constexpr std::string_view kValue = "value";
3333

34+
// Avro custom attributes constants
35+
constexpr std::string_view kIcebergFieldNameProp = "iceberg-field-name";
36+
constexpr std::string_view kFieldIdProp = "field-id";
37+
constexpr std::string_view kKeyIdProp = "key-id";
38+
constexpr std::string_view kValueIdProp = "value-id";
39+
constexpr std::string_view kElementIdProp = "element-id";
40+
constexpr std::string_view kAdjustToUtcProp = "adjust-to-utc";
41+
3442
} // namespace iceberg::avro
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include "iceberg/parquet/parquet_register.h"
21+
22+
#include "iceberg/parquet/parquet_reader.h"
23+
24+
namespace iceberg::parquet {
25+
26+
void RegisterReader() { ParquetReader::Register(); }
27+
28+
void RegisterWriter() {}
29+
30+
void RegisterAll() {
31+
RegisterReader();
32+
RegisterWriter();
33+
}
34+
35+
} // namespace iceberg::parquet
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#pragma once
21+
22+
/// \file iceberg/parquet/parquet_register.h
23+
/// \brief Provide functions to register Parquet implementations.
24+
25+
#include "iceberg/iceberg_bundle_export.h"
26+
27+
namespace iceberg::parquet {
28+
29+
/// \brief Register Parquet reader implementation.
30+
ICEBERG_BUNDLE_EXPORT void RegisterReader();
31+
32+
/// \brief Register Parquet writer implementation.
33+
ICEBERG_BUNDLE_EXPORT void RegisterWriter();
34+
35+
/// \brief Register Parquet reader and writer implementations.
36+
ICEBERG_BUNDLE_EXPORT void RegisterAll();
37+
38+
} // namespace iceberg::parquet

test/avro_test.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030
#include <gtest/gtest.h>
3131

3232
#include "iceberg/arrow/arrow_fs_file_io_internal.h"
33-
#include "iceberg/avro/avro_reader.h"
33+
#include "iceberg/avro/avro_register.h"
34+
#include "iceberg/file_reader.h"
3435
#include "iceberg/schema.h"
3536
#include "iceberg/type.h"
3637
#include "matchers.h"
@@ -40,7 +41,7 @@ namespace iceberg::avro {
4041

4142
class AvroReaderTest : public TempFileTestBase {
4243
protected:
43-
static void SetUpTestSuite() { AvroReader::Register(); }
44+
static void SetUpTestSuite() { RegisterAll(); }
4445

4546
void SetUp() override {
4647
TempFileTestBase::SetUp();

test/manifest_list_reader_test.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include <gtest/gtest.h>
2323

2424
#include "iceberg/arrow/arrow_fs_file_io_internal.h"
25-
#include "iceberg/avro/avro_reader.h"
25+
#include "iceberg/avro/avro_register.h"
2626
#include "iceberg/manifest_list.h"
2727
#include "iceberg/manifest_reader.h"
2828
#include "temp_file_test_base.h"
@@ -32,7 +32,7 @@ namespace iceberg {
3232

3333
class ManifestListReaderTestBase : public TempFileTestBase {
3434
protected:
35-
static void SetUpTestSuite() { avro::AvroReader::Register(); }
35+
static void SetUpTestSuite() { avro::RegisterAll(); }
3636

3737
void SetUp() override {
3838
TempFileTestBase::SetUp();

0 commit comments

Comments
 (0)