From a3bf05d3e1750187406b19f471570d93f9adde50 Mon Sep 17 00:00:00 2001 From: Xiao Meng Date: Sat, 31 May 2014 17:40:10 -0700 Subject: DRILL-898: C++ Client. Fix decimal data type. --- contrib/native/client/src/include/drill/drillc.hpp | 4 +-- .../client/src/include/drill/recordBatch.hpp | 30 +++++++++++++++++----- 2 files changed, 25 insertions(+), 9 deletions(-) (limited to 'contrib/native/client/src/include') 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 get(index); const std::string& str = boost::lexical_cast(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 void getValueAt(size_t index, char* buf, size_t nChars) const { VALUE_TYPE value = m_pBuffer->readAt(index * sizeof(VALUE_TYPE)); const std::string& str = boost::lexical_cast(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 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; -- cgit v1.2.3