Skip to content

Commit b283264

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 apache#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. Change-Id: I27160eb88f1b0c651323f30e4b709348112763e9
1 parent e21857a commit b283264

6 files changed

Lines changed: 72 additions & 22 deletions

File tree

cpp/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)

cpp/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

cpp/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_;

cpp/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+
}

cpp/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) \

cpp/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)