You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2016/08/16 05:09:09 UTC
arrow git commit: ARROW-251: Expose APIs for getting code and message
of the status
Repository: arrow
Updated Branches:
refs/heads/master 689cd270e -> 268e108c2
ARROW-251: Expose APIs for getting code and message of the status
Author: Jihoon Son <ji...@apache.org>
Closes #114 from jihoonson/ARROW-251 and squashes the following commits:
d1186bf [Jihoon Son] Fix compilation failure
4275c70 [Jihoon Son] Add tests for status
1162084 [Jihoon Son] Merge branch 'master' of https://github.com/apache/arrow into ARROW-251
a76b888 [Jihoon Son] Make code() public and add message()
Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/268e108c
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/268e108c
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/268e108c
Branch: refs/heads/master
Commit: 268e108c2d9101eccf2624fccf1fddf6f7f97b8b
Parents: 689cd27
Author: Jihoon Son <ji...@apache.org>
Authored: Mon Aug 15 22:08:56 2016 -0700
Committer: Wes McKinney <we...@apache.org>
Committed: Mon Aug 15 22:08:56 2016 -0700
----------------------------------------------------------------------
cpp/src/arrow/util/CMakeLists.txt | 1 +
cpp/src/arrow/util/status-test.cc | 38 ++++++++++++++++++++++++++++++++++
cpp/src/arrow/util/status.h | 16 ++++++++++----
3 files changed, 51 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/arrow/blob/268e108c/cpp/src/arrow/util/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/util/CMakeLists.txt b/cpp/src/arrow/util/CMakeLists.txt
index 4e941fb..13c0d75 100644
--- a/cpp/src/arrow/util/CMakeLists.txt
+++ b/cpp/src/arrow/util/CMakeLists.txt
@@ -70,3 +70,4 @@ endif()
ADD_ARROW_TEST(bit-util-test)
ADD_ARROW_TEST(buffer-test)
ADD_ARROW_TEST(memory-pool-test)
+ADD_ARROW_TEST(status-test)
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/arrow/blob/268e108c/cpp/src/arrow/util/status-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/util/status-test.cc b/cpp/src/arrow/util/status-test.cc
new file mode 100644
index 0000000..45e0ff3
--- /dev/null
+++ b/cpp/src/arrow/util/status-test.cc
@@ -0,0 +1,38 @@
+// 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 "arrow/util/status.h"
+#include "arrow/test-util.h"
+
+namespace arrow {
+
+TEST(StatusTest, TestCodeAndMessage) {
+ Status ok = Status::OK();
+ ASSERT_EQ(StatusCode::OK, ok.code());
+ Status file_error = Status::IOError("file error");
+ ASSERT_EQ(StatusCode::IOError, file_error.code());
+ ASSERT_EQ("file error", file_error.message());
+}
+
+TEST(StatusTest, TestToString) {
+ Status file_error = Status::IOError("file error");
+ ASSERT_EQ("IOError: file error", file_error.ToString());
+}
+
+} // namespace arrow
http://git-wip-us.apache.org/repos/asf/arrow/blob/268e108c/cpp/src/arrow/util/status.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/util/status.h b/cpp/src/arrow/util/status.h
index 6ba2035..d558531 100644
--- a/cpp/src/arrow/util/status.h
+++ b/cpp/src/arrow/util/status.h
@@ -138,6 +138,18 @@ class ARROW_EXPORT Status {
// Get the POSIX code associated with this Status, or -1 if there is none.
int16_t posix_code() const;
+ StatusCode code() const {
+ return ((state_ == NULL) ? StatusCode::OK : static_cast<StatusCode>(state_[4]));
+ }
+
+ std::string message() const {
+ uint32_t length;
+ memcpy(&length, state_, sizeof(length));
+ std::string msg;
+ msg.append((state_ + 7), length);
+ return msg;
+ }
+
private:
// OK status has a NULL state_. Otherwise, state_ is a new[] array
// of the following form:
@@ -147,10 +159,6 @@ class ARROW_EXPORT Status {
// state_[7..] == message
const char* state_;
- StatusCode code() const {
- return ((state_ == NULL) ? StatusCode::OK : static_cast<StatusCode>(state_[4]));
- }
-
Status(StatusCode code, const std::string& msg, int16_t posix_code);
static const char* CopyState(const char* s);
};