DRILL-1144 Fix cases where leading zeros are ignored in decimals
Project: http://git-wip-us.apache.org/repos/asf/incubator-drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-drill/commit/6d48ff8c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-drill/tree/6d48ff8c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-drill/diff/6d48ff8c
Branch: refs/heads/master
Commit: 6d48ff8c22bf91a4acfcd55bfe7fb220b38387c4
Parents: d595363
Author: norrislee <norrislee18@hotmail.com>
Authored: Tue Jul 15 13:03:01 2014 -0700
Committer: Aditya Kishore <aditya@maprtech.com>
Committed: Thu Jul 24 16:16:03 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/6d48ff8c/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 80c7142..8d7942a 100644
--- a/contrib/native/client/src/include/drill/recordBatch.hpp
+++ b/contrib/native/client/src/include/drill/recordBatch.hpp
@@ -302,7 +302,18 @@ template <int DECIMAL_DIGITS, int WIDTH_IN_BYTES, bool IS_SPARSE,
int MAX_PRECIS
void getValueAt(size_t index, char* buf, size_t nChars) const {
const DecimalValue& val = this->get(index);
- const std::string& str = boost::lexical_cast<std::string>(val.m_unscaledValue);
+ std::string& str = boost::lexical_cast<std::string>(val.m_unscaledValue);
+ 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 {
|