aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXiao Meng <xiaom.cs@gmail.com>2014-05-31 17:40:10 -0700
committerJacques Nadeau <jacques@apache.org>2014-06-19 20:30:46 -0700
commita3bf05d3e1750187406b19f471570d93f9adde50 (patch)
tree6e08f990fe2ed2a3ed8597113616f2b361f5d5d7
parent632f5ca9cb8f096c1f70265ecd37d97aed17089e (diff)
DRILL-898: C++ Client. Fix decimal data type.
-rw-r--r--contrib/native/client/src/clientlib/decimalUtils.cpp2
-rw-r--r--contrib/native/client/src/clientlib/recordBatch.cpp12
-rw-r--r--contrib/native/client/src/include/drill/drillc.hpp4
-rw-r--r--contrib/native/client/src/include/drill/recordBatch.hpp30
4 files changed, 38 insertions, 10 deletions
diff --git a/contrib/native/client/src/clientlib/decimalUtils.cpp b/contrib/native/client/src/clientlib/decimalUtils.cpp
index 3885faa19..779ee72b7 100644
--- a/contrib/native/client/src/clientlib/decimalUtils.cpp
+++ b/contrib/native/client/src/clientlib/decimalUtils.cpp
@@ -88,7 +88,7 @@ DecimalValue getDecimalValueFromByteBuf(SlicedByteBuf& data, size_t startIndex,
val.m_unscaledValue = decimalDigits;
// set the sign
- if (data.getUint32((startIndex) & 0x80000000) != 0)
+ if ((data.getUint32(startIndex) & 0x80000000) != 0)
{
val.m_unscaledValue *= -1;
}
diff --git a/contrib/native/client/src/clientlib/recordBatch.cpp b/contrib/native/client/src/clientlib/recordBatch.cpp
index 81b9dbe29..17073bd62 100644
--- a/contrib/native/client/src/clientlib/recordBatch.cpp
+++ b/contrib/native/client/src/clientlib/recordBatch.cpp
@@ -238,6 +238,18 @@ ValueVectorBase* ValueVectorFactory::allocateValueVector(const Drill::FieldMetad
return new NullableValueVectorFixed<float>(b,f.getValueCount());
case common::FLOAT8:
return new NullableValueVectorFixed<double>(b,f.getValueCount());
+ case common::DECIMAL9:
+ return new NullableValueVectorDecimal9(b,f.getValueCount(), f.getScale());
+ case common::DECIMAL18:
+ return new NullableValueVectorDecimal18(b,f.getValueCount(), f.getScale());
+ case common::DECIMAL28DENSE:
+ return new NullableValueVectorDecimal28Dense(b,f.getValueCount(), f.getScale());
+ case common::DECIMAL38DENSE:
+ return new NullableValueVectorDecimal38Dense(b,f.getValueCount(), f.getScale());
+ case common::DECIMAL28SPARSE:
+ return new NullableValueVectorDecimal28Sparse(b,f.getValueCount(), f.getScale());
+ case common::DECIMAL38SPARSE:
+ return new NullableValueVectorDecimal38Sparse(b,f.getValueCount(), f.getScale());
case common::DATE:
return new NullableValueVectorTyped<DateHolder,
ValueVectorTyped<DateHolder, int64_t> >(b,f.getValueCount());
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;