Skip to content
This repository was archived by the owner on May 10, 2024. It is now read-only.

Commit 616305c

Browse files
committed
PARQUET-662: Compile ParquetException implementation and explicitly export
This was causing downstream failure in ARROW-237. Now thirdparty libraries can safely throw `ParquetException` and be properly recognized on both ends. Author: Wes McKinney <wesm@apache.org> Closes #139 from wesm/PARQUET-662 and squashes the following commits: c1458d2 [Wes McKinney] Move ParquetException impl to object code, explicitly export. Add LINKAGE option to ADD_PARQUET_TEST, test throwing ParquetException via shared lib. Build shared library in gcc build.
1 parent 29c6bff commit 616305c

8 files changed

Lines changed: 106 additions & 29 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ matrix:
2626
before_script:
2727
- source $TRAVIS_BUILD_DIR/ci/before_script_travis.sh
2828
- cmake -DCMAKE_CXX_FLAGS="-Werror" -DPARQUET_TEST_MEMCHECK=ON -DPARQUET_BUILD_BENCHMARKS=ON
29-
-DPARQUET_GENERATE_COVERAGE=1 $TRAVIS_BUILD_DIR -DPARQUET_BUILD_SHARED=OFF -DPARQUET_BUILD_STATIC=ON
29+
-DPARQUET_GENERATE_COVERAGE=1 $TRAVIS_BUILD_DIR
3030
- export PARQUET_TEST_DATA=$TRAVIS_BUILD_DIR/data
3131
- compiler: clang
3232
os: linux

CMakeLists.txt

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,32 @@ endfunction()
171171
#
172172
# Arguments after the test name will be passed to set_tests_properties().
173173
function(ADD_PARQUET_TEST REL_TEST_NAME)
174-
if(NOT PARQUET_BUILD_TESTS OR NOT PARQUET_BUILD_STATIC)
174+
set(options)
175+
set(one_value_args LINKAGE)
176+
set(multi_value_args)
177+
cmake_parse_arguments(ARG "${options}" "${one_value_args}" "${multi_value_args}" ${ARGN})
178+
179+
if(NOT PARQUET_BUILD_TESTS)
175180
return()
176181
endif()
182+
183+
# TODO(wesm): not very rigorous error checking
184+
if (ARG_LINKAGE AND "${ARG_LINKAGE}" STREQUAL "shared")
185+
if(NOT PARQUET_BUILD_SHARED)
186+
# Skip this test if we are not building the shared library
187+
return()
188+
else()
189+
set(TEST_LINK_LIBS ${PARQUET_TEST_SHARED_LINK_LIBS})
190+
endif()
191+
else()
192+
if(NOT PARQUET_BUILD_STATIC)
193+
# Skip this test if we are not building the static library
194+
return()
195+
else()
196+
set(TEST_LINK_LIBS ${PARQUET_TEST_LINK_LIBS})
197+
endif()
198+
endif()
199+
177200
get_filename_component(TEST_NAME ${REL_TEST_NAME} NAME_WE)
178201

179202
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${REL_TEST_NAME}.cc)
@@ -192,7 +215,7 @@ function(ADD_PARQUET_TEST REL_TEST_NAME)
192215
-DGTEST_USE_OWN_TR1_TUPLE=0)
193216
endif()
194217

195-
target_link_libraries(${TEST_NAME} ${PARQUET_TEST_LINK_LIBS})
218+
target_link_libraries(${TEST_NAME} ${TEST_LINK_LIBS})
196219
else()
197220
# No executable, just invoke the test (probably a script) directly.
198221
set(TEST_PATH ${CMAKE_CURRENT_SOURCE_DIR}/${REL_TEST_NAME})
@@ -417,10 +440,13 @@ endif()
417440
# Test linking
418441

419442
set(PARQUET_MIN_TEST_LIBS
420-
parquet_test_main
443+
parquet_test_main)
444+
445+
set(PARQUET_TEST_LINK_LIBS ${PARQUET_MIN_TEST_LIBS}
421446
parquet_static)
422447

423-
set(PARQUET_TEST_LINK_LIBS ${PARQUET_MIN_TEST_LIBS})
448+
set(PARQUET_TEST_SHARED_LINK_LIBS ${PARQUET_MIN_TEST_LIBS}
449+
parquet_shared)
424450

425451
#############################################################
426452
# Benchmark linking
@@ -460,6 +486,7 @@ endif()
460486
# Library config
461487

462488
set(LIBPARQUET_SRCS
489+
src/parquet/exception.cc
463490
src/parquet/types.cc
464491

465492
src/parquet/column/levels.cc
@@ -533,8 +560,8 @@ if (PARQUET_BUILD_STATIC)
533560
LIBRARY_OUTPUT_DIRECTORY "${BUILD_OUTPUT_ROOT_DIRECTORY}"
534561
OUTPUT_NAME "parquet")
535562
target_link_libraries(parquet_static
536-
LINK_PUBLIC ${LIBPARQUET_LINK_LIBS}
537-
LINK_PRIVATE ${LIBPARQUET_PRIVATE_LINK_LIBS})
563+
LINK_PUBLIC ${LIBPARQUET_LINK_LIBS}
564+
LINK_PRIVATE ${LIBPARQUET_PRIVATE_LINK_LIBS})
538565
endif()
539566

540567
add_subdirectory(src/parquet)

src/parquet/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ install(FILES
2121
types.h
2222
DESTINATION include/parquet)
2323

24-
ADD_PARQUET_TEST(public-api-test)
24+
ADD_PARQUET_TEST(public-api-test
25+
LINKAGE shared)
26+
2527
ADD_PARQUET_TEST(types-test)
2628
ADD_PARQUET_TEST(reader-test)

src/parquet/exception.cc

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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+
#include "parquet/exception.h"
19+
20+
#include <exception>
21+
#include <sstream>
22+
#include <string>
23+
24+
namespace parquet {
25+
26+
void ParquetException::EofException() {
27+
throw ParquetException("Unexpected end of stream.");
28+
}
29+
30+
void ParquetException::NYI(const std::string& msg) {
31+
std::stringstream ss;
32+
ss << "Not yet implemented: " << msg << ".";
33+
throw ParquetException(ss.str());
34+
}
35+
36+
ParquetException::ParquetException(const char* msg) : msg_(msg) {}
37+
38+
ParquetException::ParquetException(const std::string& msg) : msg_(msg) {}
39+
40+
ParquetException::ParquetException(const char* msg, std::exception& e) : msg_(msg) {}
41+
42+
ParquetException::~ParquetException() throw() {}
43+
44+
const char* ParquetException::what() const throw() {
45+
return msg_.c_str();
46+
}
47+
48+
} // namespace parquet

src/parquet/exception.h

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,23 @@
1919
#define PARQUET_EXCEPTION_H
2020

2121
#include <exception>
22-
#include <sstream>
2322
#include <string>
2423

2524
#include "parquet/util/visibility.h"
2625

2726
namespace parquet {
2827

29-
class ParquetException : public std::exception {
28+
class PARQUET_EXPORT ParquetException : public std::exception {
3029
public:
31-
static void EofException() { throw ParquetException("Unexpected end of stream."); }
32-
static void NYI(const std::string& msg) {
33-
std::stringstream ss;
34-
ss << "Not yet implemented: " << msg << ".";
35-
throw ParquetException(ss.str());
36-
}
37-
38-
explicit ParquetException(const char* msg) : msg_(msg) {}
39-
explicit ParquetException(const std::string& msg) : msg_(msg) {}
40-
explicit ParquetException(const char* msg, exception& e) : msg_(msg) {}
41-
42-
virtual ~ParquetException() throw() {}
43-
virtual const char* what() const throw() { return msg_.c_str(); }
30+
static void EofException();
31+
static void NYI(const std::string& msg);
32+
33+
explicit ParquetException(const char* msg);
34+
explicit ParquetException(const std::string& msg);
35+
explicit ParquetException(const char* msg, exception& e);
36+
37+
virtual ~ParquetException() throw();
38+
virtual const char* what() const throw();
4439

4540
private:
4641
std::string msg_;

src/parquet/public-api-test.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include "parquet/api/schema.h"
2323
#include "parquet/api/writer.h"
2424

25-
namespace parquet {
26-
2725
TEST(TestPublicAPI, DoesNotIncludeThrift) {
2826
#ifdef _THRIFT_THRIFT_H_
2927
FAIL() << "Thrift headers should not be in the public API";
@@ -36,4 +34,10 @@ TEST(TestPublicAPI, DoesNotExportDCHECK) {
3634
#endif
3735
}
3836

39-
} // namespace parquet
37+
void ThrowsParquetException() {
38+
throw parquet::ParquetException("This function throws");
39+
}
40+
41+
TEST(TestPublicAPI, CanThrowParquetException) {
42+
ASSERT_THROW(ThrowsParquetException(), parquet::ParquetException);
43+
}

src/parquet/util/logging.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ namespace parquet {
4444
#ifdef NDEBUG
4545
#define PARQUET_DFATAL PARQUET_WARNING
4646

47-
#define DCHECK(condition) \
48-
PARQUET_IGNORE_EXPR(condition)\
49-
while (false) \
47+
#define DCHECK(condition) \
48+
PARQUET_IGNORE_EXPR(condition) \
49+
while (false) \
5050
parquet::internal::NullLog()
5151
#define DCHECK_EQ(val1, val2) \
5252
PARQUET_IGNORE_EXPR(val1) \

src/parquet/util/output.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <cstring>
2121
#include <memory>
22+
#include <sstream>
2223

2324
#include "parquet/exception.h"
2425
#include "parquet/util/buffer.h"

0 commit comments

Comments
 (0)