diff options
author | Xiao Meng <xiaom.cs@gmail.com> | 2014-05-31 17:40:10 -0700 |
---|---|---|
committer | Jacques Nadeau <jacques@apache.org> | 2014-06-19 20:30:46 -0700 |
commit | a3bf05d3e1750187406b19f471570d93f9adde50 (patch) | |
tree | 6e08f990fe2ed2a3ed8597113616f2b361f5d5d7 /contrib/native/client/src/include | |
parent | 632f5ca9cb8f096c1f70265ecd37d97aed17089e (diff) |
DRILL-898: C++ Client. Fix decimal data type.
Diffstat (limited to 'contrib/native/client/src/include')
-rw-r--r-- | contrib/native/client/src/include/drill/drillc.hpp | 4 | ||||
-rw-r--r-- | contrib/native/client/src/include/drill/recordBatch.hpp | 30 |
2 files changed, 25 insertions, 9 deletions
diff --git a/contrib/native/client/src/include/drill/drillc.hpp b/contrib/native/client/src/include/drill/drillc.hpp index 817b680d2..93a6b79d3 100644 --- a/contrib/native/client/src/include/drill/drillc.hpp +++ b/contrib/native/client/src/include/drill/drillc.hpp @@ -22,8 +22,8 @@ #include "drill/common.hpp" #include "drill/drillClient.hpp" #include "drill/recordBatch.hpp" -#include "Types.pb.h" -#include "User.pb.h" +#include "drill/protobuf/Types.pb.h" +#include "drill/protobuf/User.pb.h" #endif diff --git a/contrib/native/client/src/include/drill/recordBatch.hpp b/contrib/native/client/src/include/drill/recordBatch.hpp index 984588f84..979899786 100644 --- a/contrib/native/client/src/include/drill/recordBatch.hpp +++ b/contrib/native/client/src/include/drill/recordBatch.hpp @@ -303,9 +303,13 @@ 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); - size_t idxDecimalMark = str.length() - m_scale; - const std::string& decStr= str.substr(0, idxDecimalMark) + "." + str.substr(idxDecimalMark, m_scale); - strncpy(buf, decStr.c_str(), nChars); + if (m_scale == 0) { + strncpy(buf, str.c_str(), nChars); + } else { + size_t idxDecimalMark = str.length() - m_scale; + const std::string& decStr= str.substr(0, idxDecimalMark) + "." + str.substr(idxDecimalMark, m_scale); + strncpy(buf, decStr.c_str(), nChars); + } return; } @@ -336,9 +340,13 @@ 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); - size_t idxDecimalMark = str.length() - m_scale; - const std::string& decStr= str.substr(0, idxDecimalMark) + "." + str.substr(idxDecimalMark, m_scale); - strncpy(buf, decStr.c_str(), nChars); + if (m_scale == 0) { + strncpy(buf, str.c_str(), nChars); + } else { + size_t idxDecimalMark = str.length() - m_scale; + const std::string& decStr= str.substr(0, idxDecimalMark) + "." + str.substr(idxDecimalMark, m_scale); + strncpy(buf, decStr.c_str(), nChars); + } return; } @@ -559,6 +567,13 @@ template <class VALUEHOLDER_CLASS_TYPE, class VALUE_VECTOR_TYPE> this->m_pData= new SlicedByteBuf(*b, offsetEnd, b->getLength()-offsetEnd); this->m_pVector= new VALUE_VECTOR_TYPE(m_pData, rowCount); } + // Specialized for Decimal Types + NullableValueVectorTyped(SlicedByteBuf *b, size_t rowCount, int32_t scale):ValueVectorBase(b, rowCount){ + size_t offsetEnd = (size_t)ceil(rowCount/8.0); + this->m_pBitmap= new SlicedByteBuf(*b, 0, offsetEnd); + this->m_pData= new SlicedByteBuf(*b, offsetEnd, b->getLength()-offsetEnd); + this->m_pVector= new VALUE_VECTOR_TYPE(m_pData, rowCount, scale); + } ~NullableValueVectorTyped(){ delete this->m_pBitmap; @@ -732,11 +747,12 @@ class DECLSPEC_DRILL_CLIENT FieldMetadata{ m_precision=f.major_type().precision(); m_bufferLength=f.buffer_length(); } - const std::string& getName(){ return m_name;} + const std::string& getName() const{ return m_name;} common::MinorType getMinorType() const{ return m_minorType;} common::DataMode getDataMode() const{return m_dataMode;} uint32_t getValueCount() const{return m_valueCount;} uint32_t getScale() const{return m_scale;} + uint32_t getPrecision() const{return m_precision;} uint32_t getBufferLength() const{return m_bufferLength;} void copy(Drill::FieldMetadata& f){ m_name=f.m_name; |