Skip to content

Commit 32daed6

Browse files
committed
add iceberg_avro
Signed-off-by: Junwang Zhao <[email protected]>
1 parent b195b86 commit 32daed6

File tree

9 files changed

+227
-34
lines changed

9 files changed

+227
-34
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ option(ICEBERG_BUILD_STATIC "Build static library" ON)
3737
option(ICEBERG_BUILD_SHARED "Build shared library" OFF)
3838
option(ICEBERG_BUILD_TESTS "Build tests" ON)
3939
option(ICEBERG_ARROW "Build Arrow" ON)
40+
option(ICEBERG_AVRO "Build Avro" ON)
4041

4142
include(GNUInstallDirs)
4243
include(FetchContent)

cmake_modules/IcebergThirdpartyToolchain.cmake

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,32 @@ function(resolve_avro_dependency)
162162
if(NOT TARGET Avro::avro_static)
163163
add_library(Avro::avro_static INTERFACE IMPORTED)
164164
target_link_libraries(Avro::avro_static INTERFACE avrocpp_s)
165+
set_target_properties(avrocpp_s PROPERTIES OUTPUT_NAME "iceberg_vendored_avro")
166+
endif()
167+
168+
if(NOT TARGET Avro::avro_shared)
169+
add_library(Avro::avro_shared INTERFACE IMPORTED)
170+
target_link_libraries(Avro::avro_shared INTERFACE avrocpp)
171+
set_target_properties(avrocpp PROPERTIES OUTPUT_NAME "iceberg_vendored_avro")
172+
endif()
173+
174+
if(ICEBERG_BUILD_STATIC)
175+
install(TARGETS avrocpp_s
176+
EXPORT iceberg_targets
177+
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
178+
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
179+
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
180+
endif()
181+
if(ICEBERG_BUILD_SHARED)
182+
install(TARGETS avrocpp
183+
EXPORT iceberg_targets
184+
RUNTIME DESTINATION "${ICEBERG_INSTALL_BINDIR}"
185+
ARCHIVE DESTINATION "${ICEBERG_INSTALL_LIBDIR}"
186+
LIBRARY DESTINATION "${ICEBERG_INSTALL_LIBDIR}")
165187
endif()
166188
endif()
167189
endfunction()
168190

169-
resolve_avro_dependency()
191+
if(ICEBERG_AVRO)
192+
resolve_avro_dependency()
193+
endif()

src/iceberg/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,19 @@
1717

1818
set(ICEBERG_SOURCES demo_table.cc)
1919

20-
set(ICEBERG_AVRO_STATIC_BUILD_LIBS)
21-
list(APPEND ICEBERG_AVRO_STATIC_BUILD_LIBS Avro::avro_static)
22-
2320
add_iceberg_lib(iceberg
2421
SOURCES
2522
${ICEBERG_SOURCES}
2623
PRIVATE_INCLUDES
27-
${ICEBERG_INCLUDES}
28-
STATIC_LINK_LIBS
29-
${ICEBERG_AVRO_STATIC_BUILD_LIBS})
24+
${ICEBERG_INCLUDES})
3025

3126
iceberg_install_all_headers(iceberg)
3227

3328
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_export.h
3429
DESTINATION ${ICEBERG_INSTALL_INCLUDEDIR}/iceberg)
3530

3631
add_subdirectory(arrow)
32+
add_subdirectory(avro)
3733
add_subdirectory(puffin)
3834

3935
iceberg_install_cmake_package(Iceberg iceberg_targets)

src/iceberg/avro.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
#include <string>
23+
24+
#include "iceberg/iceberg_export.h"
25+
26+
namespace iceberg {
27+
28+
class ICEBERG_EXPORT Avro {
29+
public:
30+
virtual ~Avro() = default;
31+
virtual std::string print() const = 0;
32+
};
33+
34+
} // namespace iceberg

src/iceberg/avro/CMakeLists.txt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
if(NOT ICEBERG_AVRO)
19+
return()
20+
endif()
21+
22+
set(ICEBERG_AVRO_SOURCES demo_avro.cc)
23+
set(ICEBERG_AVRO_INCLUDES "${ICEBERG_INCLUDES}")
24+
25+
# Libraries to link with exported libiceberg_avro.{so,a}.
26+
set(ICEBERG_AVRO_STATIC_BUILD_INTERFACE_LIBS)
27+
set(ICEBERG_AVRO_SHARED_BUILD_INTERFACE_LIBS)
28+
set(ICEBERG_AVRO_STATIC_INSTALL_INTERFACE_LIBS)
29+
set(ICEBERG_AVRO_SHARED_INSTALL_INTERFACE_LIBS)
30+
31+
list(APPEND ICEBERG_AVRO_STATIC_BUILD_INTERFACE_LIBS
32+
"$<IF:$<TARGET_EXISTS:iceberg_static>,iceberg_static,iceberg_shared>"
33+
Avro::avro_static)
34+
list(APPEND ICEBERG_AVRO_SHARED_BUILD_INTERFACE_LIBS
35+
"$<IF:$<TARGET_EXISTS:iceberg_shared>,iceberg_shared,iceberg_static>"
36+
Avro::avro_shared)
37+
list(APPEND ICEBERG_AVRO_STATIC_INSTALL_INTERFACE_LIBS Iceberg::avro_static)
38+
list(APPEND ICEBERG_AVRO_SHARED_INSTALL_INTERFACE_LIBS Iceberg::avro_shared)
39+
40+
list(APPEND
41+
ICEBERG_AVRO_STATIC_INSTALL_INTERFACE_LIBS
42+
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_static>,Iceberg::iceberg_static,Iceberg::iceberg_shared>"
43+
)
44+
list(APPEND
45+
ICEBERG_AVRO_SHARED_INSTALL_INTERFACE_LIBS
46+
"$<IF:$<TARGET_EXISTS:Iceberg::iceberg_shared>,Iceberg::iceberg_shared,Iceberg::iceberg_static>"
47+
)
48+
49+
add_iceberg_lib(iceberg_avro
50+
SOURCES
51+
${ICEBERG_AVRO_SOURCES}
52+
PRIVATE_INCLUDES
53+
${ICEBERG_AVRO_INCLUDES}
54+
SHARED_LINK_LIBS
55+
${ICEBERG_AVRO_SHARED_BUILD_INTERFACE_LIBS}
56+
STATIC_LINK_LIBS
57+
${ICEBERG_AVRO_STATIC_BUILD_INTERFACE_LIBS}
58+
STATIC_INSTALL_INTERFACE_LIBS
59+
${ICEBERG_AVRO_STATIC_INSTALL_INTERFACE_LIBS}
60+
SHARED_INSTALL_INTERFACE_LIBS
61+
${ICEBERG_AVRO_SHARED_INSTALL_INTERFACE_LIBS})
62+
63+
iceberg_install_all_headers(iceberg/avro)
64+
65+
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/iceberg_avro_export.h
66+
DESTINATION ${ICEBERG_INSTALL_INCLUDEDIR}/iceberg/avro)

src/iceberg/avro/demo_avro.cc

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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/avro/demo_avro.h"
21+
22+
#include <sstream>
23+
24+
#include "avro/Compiler.hh"
25+
#include "avro/ValidSchema.hh"
26+
#include "iceberg/demo_table.h"
27+
28+
namespace iceberg {
29+
30+
std::string DemoAvro::print() const {
31+
std::string input =
32+
"{\n\
33+
\"type\": \"record\",\n\
34+
\"name\": \"testrecord\",\n\
35+
\"fields\": [\n\
36+
{\n\
37+
\"name\": \"testbytes\",\n\
38+
\"type\": \"bytes\",\n\
39+
\"default\": \"\"\n\
40+
}\n\
41+
]\n\
42+
}\n\
43+
";
44+
45+
avro::ValidSchema schema = avro::compileJsonSchemaFromString(input);
46+
std::ostringstream actual;
47+
schema.toJson(actual);
48+
49+
return actual.str();
50+
}
51+
52+
} // namespace iceberg

src/iceberg/avro/demo_avro.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
#include <string>
23+
24+
#include "iceberg/avro.h"
25+
#include "iceberg/avro/iceberg_avro_export.h"
26+
27+
namespace iceberg {
28+
29+
class ICEBERG_AVRO_EXPORT DemoAvro : public Avro {
30+
public:
31+
DemoAvro() = default;
32+
~DemoAvro() override = default;
33+
std::string print() const override;
34+
};
35+
36+
} // namespace iceberg

test/core/CMakeLists.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@ target_link_libraries(core_unittest PRIVATE iceberg_static GTest::gtest_main)
2121
target_include_directories(core_unittest PRIVATE "${ICEBERG_INCLUDES}")
2222
add_test(NAME core_unittest COMMAND core_unittest)
2323

24-
add_executable(avro_unittest)
25-
target_sources(avro_unittest PRIVATE avro_unittest.cc)
26-
target_link_libraries(avro_unittest PRIVATE Avro::avro_static GTest::gtest_main)
27-
target_include_directories(avro_unittest PRIVATE "${ICEBERG_INCLUDES}")
28-
add_test(NAME avro_unittest COMMAND avro_unittest)
24+
if(ICEBERG_AVRO)
25+
add_executable(avro_unittest)
26+
target_sources(avro_unittest PRIVATE avro_unittest.cc)
27+
target_link_libraries(avro_unittest PRIVATE iceberg_avro_static GTest::gtest_main)
28+
target_include_directories(avro_unittest PRIVATE "${ICEBERG_INCLUDES}")
29+
add_test(NAME avro_unittest COMMAND avro_unittest)
30+
endif()

test/core/avro_unittest.cc

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,24 +18,9 @@
1818
*/
1919

2020
#include <gtest/gtest.h>
21+
#include <iceberg/avro/demo_avro.h>
2122

22-
#include "avro/Compiler.hh"
23-
#include "avro/ValidSchema.hh"
24-
25-
TEST(TableTest, TestTableCons) {
26-
std::string input =
27-
"{\n\
28-
\"type\": \"record\",\n\
29-
\"name\": \"testrecord\",\n\
30-
\"fields\": [\n\
31-
{\n\
32-
\"name\": \"testbytes\",\n\
33-
\"type\": \"bytes\",\n\
34-
\"default\": \"\"\n\
35-
}\n\
36-
]\n\
37-
}\n\
38-
";
23+
TEST(AVROTest, TestDemoAvro) {
3924
std::string expected =
4025
"{\n\
4126
\"type\": \"record\",\n\
@@ -50,9 +35,6 @@ TEST(TableTest, TestTableCons) {
5035
}\n\
5136
";
5237

53-
avro::ValidSchema schema = avro::compileJsonSchemaFromString(input);
54-
std::ostringstream actual;
55-
schema.toJson(actual);
56-
57-
EXPECT_EQ(actual.str(), expected);
38+
auto avro = iceberg::DemoAvro();
39+
EXPECT_EQ(avro.print(), expected);
5840
}

0 commit comments

Comments
 (0)