Skip to content

Commit 162bac1

Browse files
committed
add libavrocpp_s
This closes #17 The avro_unittest is added for testing if libavrocpp works, once we supported Manifest, this should be removed. Signed-off-by: Junwang Zhao <[email protected]>
1 parent f17fd2f commit 162bac1

File tree

5 files changed

+115
-1
lines changed

5 files changed

+115
-1
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ jobs:
8080
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
8181
with:
8282
fetch-depth: 0
83+
- name: Install ZLIB
84+
shell: cmd
85+
run: |
86+
powershell -Command "(Invoke-WebRequest -Uri https://git.io/JnHTY -OutFile install_zlib.bat)"; ./install_zlib.bat; del install_zlib.bat
8387
- name: Build Iceberg
8488
shell: cmd
8589
run: |

cmake_modules/IcebergThirdpartyToolchain.cmake

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,44 @@ endfunction()
126126
if(ICEBERG_ARROW)
127127
resolve_arrow_dependency()
128128
endif()
129+
130+
# ----------------------------------------------------------------------
131+
# Apache Avro
132+
133+
function(resolve_avro_dependency)
134+
prepare_fetchcontent()
135+
136+
set(AVRO_USE_BOOST
137+
OFF
138+
CACHE BOOL "" FORCE)
139+
140+
set(AVRO_BUILD_EXECUTABLES
141+
OFF
142+
CACHE BOOL "" FORCE)
143+
144+
set(AVRO_BUILD_TESTS
145+
OFF
146+
CACHE BOOL "" FORCE)
147+
148+
fetchcontent_declare(Avro
149+
${FC_DECLARE_COMMON_OPTIONS}
150+
GIT_REPOSITORY https://github.com/apache/avro.git
151+
GIT_TAG 1144cb7322bab4cd1c8bf330a9c504a0d4252b56
152+
SOURCE_SUBDIR
153+
lang/c++
154+
FIND_PACKAGE_ARGS
155+
NAMES
156+
Avro
157+
CONFIG)
158+
159+
fetchcontent_makeavailable(Avro)
160+
161+
if(avro_SOURCE_DIR)
162+
if(NOT TARGET Avro::avro_static)
163+
add_library(Avro::avro_static INTERFACE IMPORTED)
164+
target_link_libraries(Avro::avro_static INTERFACE avrocpp_s)
165+
endif()
166+
endif()
167+
endfunction()
168+
169+
resolve_avro_dependency()

src/iceberg/CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,16 @@
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+
2023
add_iceberg_lib(iceberg
2124
SOURCES
2225
${ICEBERG_SOURCES}
2326
PRIVATE_INCLUDES
24-
${ICEBERG_INCLUDES})
27+
${ICEBERG_INCLUDES}
28+
STATIC_LINK_LIBS
29+
${ICEBERG_AVRO_STATIC_BUILD_LIBS})
2530

2631
iceberg_install_all_headers(iceberg)
2732

test/core/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,9 @@ target_sources(core_unittest PRIVATE core_unittest.cc)
2020
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)
23+
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)

test/core/avro_unittest.cc

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 <gtest/gtest.h>
21+
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+
";
39+
std::string expected =
40+
"{\n\
41+
\"type\": \"record\",\n\
42+
\"name\": \"testrecord\",\n\
43+
\"fields\": [\n\
44+
{\n\
45+
\"name\": \"testbytes\",\n\
46+
\"type\": \"bytes\",\n\
47+
\"default\": \"\"\n\
48+
}\n\
49+
]\n\
50+
}\n\
51+
";
52+
53+
avro::ValidSchema schema = avro::compileJsonSchemaFromString(input);
54+
std::ostringstream actual;
55+
schema.toJson(actual);
56+
57+
EXPECT_EQ(actual.str(), expected);
58+
}

0 commit comments

Comments
 (0)