From a976ac1d20f32f1cdc5ba71978be254a312b4c88 Mon Sep 17 00:00:00 2001 From: rip-nsk Date: Tue, 1 May 2018 10:32:04 -0700 Subject: [PATCH 1/2] Fix C09Adaper.cc (as Adaptor.cc) --- c++/src/{C09Adapter.cc => Adaptor.cc} | 18 +++++++++++------- c++/src/CMakeLists.txt | 1 + 2 files changed, 12 insertions(+), 7 deletions(-) rename c++/src/{C09Adapter.cc => Adaptor.cc} (80%) diff --git a/c++/src/C09Adapter.cc b/c++/src/Adaptor.cc similarity index 80% rename from c++/src/C09Adapter.cc rename to c++/src/Adaptor.cc index 8afc75208f..32bdec2f82 100644 --- a/c++/src/C09Adapter.cc +++ b/c++/src/Adaptor.cc @@ -16,13 +16,17 @@ * limitations under the License. */ -#include "orc/C09Adapter.hh" +#include "Adaptor.hh" #include -int64_t std::stoll(std::string str) { - int64_t val = 0; - stringstream ss ; - ss << str ; - ss >> val ; - return val; +#ifndef HAS_STOLL +namespace std { + int64_t std::stoll(std::string str) { + int64_t val = 0; + stringstream ss; + ss << str; + ss >> val; + return val; + } } +#endif diff --git a/c++/src/CMakeLists.txt b/c++/src/CMakeLists.txt index 8254574989..1ffec109f2 100644 --- a/c++/src/CMakeLists.txt +++ b/c++/src/CMakeLists.txt @@ -156,6 +156,7 @@ set(SOURCE_FILES io/InputStream.cc io/OutputStream.cc wrap/orc-proto-wrapper.cc + Adaptor.cc ByteRLE.cc ColumnPrinter.cc ColumnReader.cc From fefcd6a644e9237a5fc787d806a051b16e5a3790 Mon Sep 17 00:00:00 2001 From: rip-nsk Date: Tue, 1 May 2018 10:45:36 -0700 Subject: [PATCH 2/2] portable strptime() --- c++/src/Adaptor.cc | 11 +++++++++++ c++/src/Adaptor.hh.in | 5 +++++ c++/src/CMakeLists.txt | 9 +++++++++ c++/test/TestTimezone.cc | 5 ++--- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/c++/src/Adaptor.cc b/c++/src/Adaptor.cc index 32bdec2f82..9c0a74c598 100644 --- a/c++/src/Adaptor.cc +++ b/c++/src/Adaptor.cc @@ -18,6 +18,7 @@ #include "Adaptor.hh" #include +#include #ifndef HAS_STOLL namespace std { @@ -30,3 +31,13 @@ namespace std { } } #endif + +#ifndef HAS_STRPTIME +char* strptime(const char* s, const char* f, struct tm* tm) { + std::istringstream input(s); + input.imbue(std::locale(setlocale(LC_ALL, nullptr))); + input >> std::get_time(tm, f); + if (input.fail()) return nullptr; + return (char*)(s + input.tellg()); +} +#endif diff --git a/c++/src/Adaptor.hh.in b/c++/src/Adaptor.hh.in index 5d9ea15085..5fefa3f33d 100644 --- a/c++/src/Adaptor.hh.in +++ b/c++/src/Adaptor.hh.in @@ -21,6 +21,7 @@ #cmakedefine INT64_IS_LL #cmakedefine HAS_PREAD +#cmakedefine HAS_STRPTIME #cmakedefine HAS_STOLL #cmakedefine HAS_DIAGNOSTIC_PUSH #cmakedefine HAS_PRE_1970 @@ -40,6 +41,10 @@ } #endif +#ifndef HAS_STRPTIME + char* strptime(const char* buf, const char* format, struct tm* tm); +#endif + #ifndef HAS_PREAD ssize_t pread(int fd, void *buf, size_t count, off_t offset); #endif diff --git a/c++/src/CMakeLists.txt b/c++/src/CMakeLists.txt index 1ffec109f2..695a0ae38a 100644 --- a/c++/src/CMakeLists.txt +++ b/c++/src/CMakeLists.txt @@ -25,6 +25,15 @@ CHECK_CXX_SOURCE_COMPILES(" HAS_PREAD ) +CHECK_CXX_SOURCE_COMPILES(" + #include + int main(int,char*[]){ + struct tm time2020; + return !strptime(\"2020-02-02 12:34:56\", \"%Y-%m-%d %H:%M:%S\", &time2020); + }" + HAS_STRPTIME +) + CHECK_CXX_SOURCE_COMPILES(" #include int main(int,char* argv[]){ diff --git a/c++/test/TestTimezone.cc b/c++/test/TestTimezone.cc index 88415ccac3..f690786f86 100644 --- a/c++/test/TestTimezone.cc +++ b/c++/test/TestTimezone.cc @@ -21,7 +21,6 @@ #include "wrap/gtest-wrapper.h" #include -#include #include namespace orc { @@ -123,7 +122,7 @@ namespace orc { const std::string& getZoneFromRule(FutureRule *rule, const std::string& date) { tm timeStruct; - if (strptime(date.c_str(), "%F %H:%M:%S", &timeStruct) == nullptr) { + if (strptime(date.c_str(), "%Y-%m-%d %H:%M:%S", &timeStruct) == nullptr) { throw TimezoneError("bad time " + date); } return rule->getVariant(timegm(&timeStruct)).name; @@ -319,7 +318,7 @@ namespace orc { const std::string& getVariantFromZone(const Timezone& zone, const std::string& date) { tm timeStruct; - if (strptime(date.c_str(), "%F %H:%M:%S", &timeStruct) == nullptr) { + if (strptime(date.c_str(), "%Y-%m-%d %H:%M:%S", &timeStruct) == nullptr) { throw TimezoneError("bad time " + date); } return zone.getVariant(timegm(&timeStruct)).name;