DRILL-1226: C++ Client Decimal ignores leading zeros for decimal 9 and 18
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/687b9b0b Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/687b9b0b Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/687b9b0b Branch: refs/heads/master Commit: 687b9b0b6e8d30fcf2a1e4fc8f34ddc6728b1f69 Parents: 90cd194 Author: norrislee <norrisle...@hotmail.com> Authored: Wed Jul 30 13:31:20 2014 -0700 Committer: Jacques Nadeau <jacq...@apache.org> Committed: Mon Aug 11 21:33:43 2014 -0700 ---------------------------------------------------------------------- .../native/client/src/include/drill/recordBatch.hpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-drill/blob/687b9b0b/contrib/native/client/src/include/drill/recordBatch.hpp ---------------------------------------------------------------------- diff --git a/contrib/native/client/src/include/drill/recordBatch.hpp b/contrib/native/client/src/include/drill/recordBatch.hpp index d4735a9..e9298bf 100644 --- a/contrib/native/client/src/include/drill/recordBatch.hpp +++ b/contrib/native/client/src/include/drill/recordBatch.hpp @@ -350,7 +350,18 @@ template<typename VALUE_TYPE> void getValueAt(size_t index, char* buf, size_t nChars) const { VALUE_TYPE value = m_pBuffer->readAt<VALUE_TYPE>(index * sizeof(VALUE_TYPE)); - const std::string& str = boost::lexical_cast<std::string>(value); + std::string str = boost::lexical_cast<std::string>(value); + if (str[0] == '-') { + str = str.substr(1); + while (str.length() < m_scale) { + str = "0" + str; + } + str = "-" + str; + } else { + while (str.length() < m_scale) { + str = "0" + str; + } + } if (m_scale == 0) { strncpy(buf, str.c_str(), nChars); } else {