Skip to content

Commit

Permalink
add libavrocpp_s
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
zhjwpku committed Jan 18, 2025
1 parent f17fd2f commit 162bac1
Show file tree
Hide file tree
Showing 5 changed files with 115 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ jobs:
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
- name: Install ZLIB
shell: cmd
run: |
powershell -Command "(Invoke-WebRequest -Uri https://git.io/JnHTY -OutFile install_zlib.bat)"; ./install_zlib.bat; del install_zlib.bat
- name: Build Iceberg
shell: cmd
run: |
Expand Down
41 changes: 41 additions & 0 deletions cmake_modules/IcebergThirdpartyToolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,44 @@ endfunction()
if(ICEBERG_ARROW)
resolve_arrow_dependency()
endif()

# ----------------------------------------------------------------------
# Apache Avro

function(resolve_avro_dependency)
prepare_fetchcontent()

set(AVRO_USE_BOOST
OFF
CACHE BOOL "" FORCE)

set(AVRO_BUILD_EXECUTABLES
OFF
CACHE BOOL "" FORCE)

set(AVRO_BUILD_TESTS
OFF
CACHE BOOL "" FORCE)

fetchcontent_declare(Avro
${FC_DECLARE_COMMON_OPTIONS}
GIT_REPOSITORY https://github.com/apache/avro.git
GIT_TAG 1144cb7322bab4cd1c8bf330a9c504a0d4252b56
SOURCE_SUBDIR
lang/c++
FIND_PACKAGE_ARGS
NAMES
Avro
CONFIG)

fetchcontent_makeavailable(Avro)

if(avro_SOURCE_DIR)
if(NOT TARGET Avro::avro_static)
add_library(Avro::avro_static INTERFACE IMPORTED)
target_link_libraries(Avro::avro_static INTERFACE avrocpp_s)
endif()
endif()
endfunction()

resolve_avro_dependency()
7 changes: 6 additions & 1 deletion src/iceberg/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,16 @@

set(ICEBERG_SOURCES demo_table.cc)

set(ICEBERG_AVRO_STATIC_BUILD_LIBS)
list(APPEND ICEBERG_AVRO_STATIC_BUILD_LIBS Avro::avro_static)

add_iceberg_lib(iceberg
SOURCES
${ICEBERG_SOURCES}
PRIVATE_INCLUDES
${ICEBERG_INCLUDES})
${ICEBERG_INCLUDES}
STATIC_LINK_LIBS
${ICEBERG_AVRO_STATIC_BUILD_LIBS})

iceberg_install_all_headers(iceberg)

Expand Down
6 changes: 6 additions & 0 deletions test/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@ target_sources(core_unittest PRIVATE core_unittest.cc)
target_link_libraries(core_unittest PRIVATE iceberg_static GTest::gtest_main)
target_include_directories(core_unittest PRIVATE "${ICEBERG_INCLUDES}")
add_test(NAME core_unittest COMMAND core_unittest)

add_executable(avro_unittest)
target_sources(avro_unittest PRIVATE avro_unittest.cc)
target_link_libraries(avro_unittest PRIVATE Avro::avro_static GTest::gtest_main)
target_include_directories(avro_unittest PRIVATE "${ICEBERG_INCLUDES}")
add_test(NAME avro_unittest COMMAND avro_unittest)
58 changes: 58 additions & 0 deletions test/core/avro_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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 <gtest/gtest.h>

#include "avro/Compiler.hh"
#include "avro/ValidSchema.hh"

TEST(TableTest, TestTableCons) {
std::string input =
"{\n\
\"type\": \"record\",\n\
\"name\": \"testrecord\",\n\
\"fields\": [\n\
{\n\
\"name\": \"testbytes\",\n\
\"type\": \"bytes\",\n\
\"default\": \"\"\n\
}\n\
]\n\
}\n\
";
std::string expected =
"{\n\
\"type\": \"record\",\n\
\"name\": \"testrecord\",\n\
\"fields\": [\n\
{\n\
\"name\": \"testbytes\",\n\
\"type\": \"bytes\",\n\
\"default\": \"\"\n\
}\n\
]\n\
}\n\
";

avro::ValidSchema schema = avro::compileJsonSchemaFromString(input);
std::ostringstream actual;
schema.toJson(actual);

EXPECT_EQ(actual.str(), expected);
}

0 comments on commit 162bac1

Please sign in to comment.