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 2017/03/14 15:47:45 UTC
arrow git commit: ARROW-625: [C++] Add TimeUnit to
TimeType::ToString. Add timezone to TimestampType::ToString if present
Repository: arrow
Updated Branches:
refs/heads/master cef46152c -> a32ae5909
ARROW-625: [C++] Add TimeUnit to TimeType::ToString. Add timezone to TimestampType::ToString if present
Author: Wes McKinney <we...@twosigma.com>
Closes #377 from wesm/ARROW-625 and squashes the following commits:
d76a8d3 [Wes McKinney] Move PrintTimeUnit into operator<< for std::ostream
351f90e [Wes McKinney] Add TimeUnit to TimeType::ToString. Add timezone to TimestampType::ToString if it has one
Project: http://git-wip-us.apache.org/repos/asf/arrow/repo
Commit: http://git-wip-us.apache.org/repos/asf/arrow/commit/a32ae590
Tree: http://git-wip-us.apache.org/repos/asf/arrow/tree/a32ae590
Diff: http://git-wip-us.apache.org/repos/asf/arrow/diff/a32ae590
Branch: refs/heads/master
Commit: a32ae59094be82ad318a73d067f2db680d3ab295
Parents: cef4615
Author: Wes McKinney <we...@twosigma.com>
Authored: Tue Mar 14 11:47:39 2017 -0400
Committer: Wes McKinney <we...@twosigma.com>
Committed: Tue Mar 14 11:47:39 2017 -0400
----------------------------------------------------------------------
cpp/src/arrow/type-test.cc | 24 ++++++++++++++++++++++++
cpp/src/arrow/type.cc | 23 ++++++-----------------
cpp/src/arrow/type.h | 22 ++++++++++++++++++++--
3 files changed, 50 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/arrow/blob/a32ae590/cpp/src/arrow/type-test.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/type-test.cc b/cpp/src/arrow/type-test.cc
index fe6c62a..3adc4d8 100644
--- a/cpp/src/arrow/type-test.cc
+++ b/cpp/src/arrow/type-test.cc
@@ -132,6 +132,18 @@ TEST(TestTimeType, Equals) {
ASSERT_TRUE(t3.Equals(t4));
}
+TEST(TestTimeType, ToString) {
+ auto t1 = time(TimeUnit::MILLI);
+ auto t2 = time(TimeUnit::NANO);
+ auto t3 = time(TimeUnit::SECOND);
+ auto t4 = time(TimeUnit::MICRO);
+
+ ASSERT_EQ("time[ms]", t1->ToString());
+ ASSERT_EQ("time[ns]", t2->ToString());
+ ASSERT_EQ("time[s]", t3->ToString());
+ ASSERT_EQ("time[us]", t4->ToString());
+}
+
TEST(TestTimestampType, Equals) {
TimestampType t1;
TimestampType t2;
@@ -143,4 +155,16 @@ TEST(TestTimestampType, Equals) {
ASSERT_TRUE(t3.Equals(t4));
}
+TEST(TestTimestampType, ToString) {
+ auto t1 = timestamp(TimeUnit::MILLI);
+ auto t2 = timestamp("US/Eastern", TimeUnit::NANO);
+ auto t3 = timestamp(TimeUnit::SECOND);
+ auto t4 = timestamp(TimeUnit::MICRO);
+
+ ASSERT_EQ("timestamp[ms]", t1->ToString());
+ ASSERT_EQ("timestamp[ns, tz=US/Eastern]", t2->ToString());
+ ASSERT_EQ("timestamp[s]", t3->ToString());
+ ASSERT_EQ("timestamp[us]", t4->ToString());
+}
+
} // namespace arrow
http://git-wip-us.apache.org/repos/asf/arrow/blob/a32ae590/cpp/src/arrow/type.cc
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/type.cc b/cpp/src/arrow/type.cc
index 0cafdce..d41b363 100644
--- a/cpp/src/arrow/type.cc
+++ b/cpp/src/arrow/type.cc
@@ -108,27 +108,16 @@ std::string Date32Type::ToString() const {
return std::string("date32");
}
-static inline void print_time_unit(TimeUnit unit, std::ostream* stream) {
- switch (unit) {
- case TimeUnit::SECOND:
- (*stream) << "s";
- break;
- case TimeUnit::MILLI:
- (*stream) << "ms";
- break;
- case TimeUnit::MICRO:
- (*stream) << "us";
- break;
- case TimeUnit::NANO:
- (*stream) << "ns";
- break;
- }
+std::string TimeType::ToString() const {
+ std::stringstream ss;
+ ss << "time[" << this->unit << "]";
+ return ss.str();
}
std::string TimestampType::ToString() const {
std::stringstream ss;
- ss << "timestamp[";
- print_time_unit(this->unit, &ss);
+ ss << "timestamp[" << this->unit;
+ if (this->timezone.size() > 0) { ss << ", tz=" << this->timezone; }
ss << "]";
return ss.str();
}
http://git-wip-us.apache.org/repos/asf/arrow/blob/a32ae590/cpp/src/arrow/type.h
----------------------------------------------------------------------
diff --git a/cpp/src/arrow/type.h b/cpp/src/arrow/type.h
index 15b99c5..9f28875 100644
--- a/cpp/src/arrow/type.h
+++ b/cpp/src/arrow/type.h
@@ -20,6 +20,7 @@
#include <cstdint>
#include <memory>
+#include <ostream>
#include <string>
#include <vector>
@@ -460,6 +461,24 @@ struct ARROW_EXPORT Date32Type : public FixedWidthType {
enum class TimeUnit : char { SECOND = 0, MILLI = 1, MICRO = 2, NANO = 3 };
+static inline std::ostream& operator<<(std::ostream& os, TimeUnit unit) {
+ switch (unit) {
+ case TimeUnit::SECOND:
+ os << "s";
+ break;
+ case TimeUnit::MILLI:
+ os << "ms";
+ break;
+ case TimeUnit::MICRO:
+ os << "us";
+ break;
+ case TimeUnit::NANO:
+ os << "ns";
+ break;
+ }
+ return os;
+}
+
struct ARROW_EXPORT TimeType : public FixedWidthType {
static constexpr Type::type type_id = Type::TIME;
using Unit = TimeUnit;
@@ -474,8 +493,7 @@ struct ARROW_EXPORT TimeType : public FixedWidthType {
TimeType(const TimeType& other) : TimeType(other.unit) {}
Status Accept(TypeVisitor* visitor) const override;
- std::string ToString() const override { return name(); }
- static std::string name() { return "time"; }
+ std::string ToString() const override;
};
struct ARROW_EXPORT TimestampType : public FixedWidthType {