diff --git a/dbcon/dmlpackage/dmlpkg.cpp b/dbcon/dmlpackage/dmlpkg.cpp index c23f90d6e..5219d9a09 100644 --- a/dbcon/dmlpackage/dmlpkg.cpp +++ b/dbcon/dmlpackage/dmlpkg.cpp @@ -1211,7 +1211,7 @@ string BetweenPredicate::getPredicateString() const between_predicate += fRH1ScalarExpression; between_predicate += " "; between_predicate += fOperator2; - between_predicate + " "; + between_predicate += " "; between_predicate += fRH2ScalarExpression; return between_predicate; diff --git a/dbcon/joblist/rowestimator.cpp b/dbcon/joblist/rowestimator.cpp index 9879aa932..873a1ad49 100644 --- a/dbcon/joblist/rowestimator.cpp +++ b/dbcon/joblist/rowestimator.cpp @@ -159,16 +159,16 @@ uint32_t RowEstimator::estimateDistinctValues(const execplan::CalpontSystemCatal // Return limit/2 for integers where limit is number of possible values. case CalpontSystemCatalog::TINYINT: - return (2 ^ 8) / 2; + return (1 << 8) / 2; case CalpontSystemCatalog::UTINYINT: - return (2 ^ 8); + return (1 << 8); case CalpontSystemCatalog::SMALLINT: - return (2 ^ 16) / 2; + return (1 << 16) / 2; case CalpontSystemCatalog::USMALLINT: - return (2 ^ 16); + return (1 << 16); // Next group all have range greater than 8M (# of rows in an extent), use 8M/2 as the estimate. case CalpontSystemCatalog::MEDINT: diff --git a/dbcon/mysql/ha_mcs_datatype.h b/dbcon/mysql/ha_mcs_datatype.h index e4b80d9bf..ecd51367d 100644 --- a/dbcon/mysql/ha_mcs_datatype.h +++ b/dbcon/mysql/ha_mcs_datatype.h @@ -202,11 +202,11 @@ class WriteBatchFieldMariaDB: public WriteBatchField public: - Field *m_field; - const CalpontSystemCatalog::ColType &m_type; + Field * m_field; + const CalpontSystemCatalog::ColType & m_type; uint32_t m_mbmaxlen; WriteBatchFieldMariaDB(Field *field, - const CalpontSystemCatalog::ColType type, + const CalpontSystemCatalog::ColType & type, uint32_t mbmaxlen) :m_field(field), m_type(type), m_mbmaxlen(mbmaxlen) { } @@ -423,7 +423,7 @@ public: return 8; } - size_t ColWriteBatchUInt64(const uchar *buf, bool nullVal, ColBatchWriter &ci) override + size_t ColWriteBatchUInt64(const uchar *buf, bool nullVal, ColBatchWriter &ci) override { if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) fprintf(ci.filePtr(), "%c", ci.delimiter()); @@ -433,7 +433,7 @@ public: } - size_t ColWriteBatchSInt32(const uchar *buf, bool nullVal, ColBatchWriter &ci) override + size_t ColWriteBatchSInt32(const uchar *buf, bool nullVal, ColBatchWriter &ci) override { if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) fprintf(ci.filePtr(), "%c", ci.delimiter()); @@ -442,7 +442,7 @@ public: return 4; } - size_t ColWriteBatchUInt32(const uchar *buf, bool nullVal, ColBatchWriter &ci) override + size_t ColWriteBatchUInt32(const uchar *buf, bool nullVal, ColBatchWriter &ci) override { if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) fprintf(ci.filePtr(), "%c", ci.delimiter()); @@ -451,7 +451,7 @@ public: return 4; } - size_t ColWriteBatchSInt16(const uchar *buf, bool nullVal, ColBatchWriter &ci) override + size_t ColWriteBatchSInt16(const uchar *buf, bool nullVal, ColBatchWriter &ci) override { if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) fprintf(ci.filePtr(), "%c", ci.delimiter()); @@ -460,7 +460,7 @@ public: return 2; } - size_t ColWriteBatchUInt16(const uchar *buf, bool nullVal, ColBatchWriter &ci) override + size_t ColWriteBatchUInt16(const uchar *buf, bool nullVal, ColBatchWriter &ci) override { if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) fprintf(ci.filePtr(), "%c", ci.delimiter()); @@ -469,7 +469,7 @@ public: return 2; } - size_t ColWriteBatchSInt8(const uchar *buf, bool nullVal, ColBatchWriter &ci) override + size_t ColWriteBatchSInt8(const uchar *buf, bool nullVal, ColBatchWriter &ci) override { if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) fprintf(ci.filePtr(), "%c", ci.delimiter()); @@ -478,7 +478,7 @@ public: return 1; } - size_t ColWriteBatchUInt8(const uchar *buf, bool nullVal, ColBatchWriter &ci) override + size_t ColWriteBatchUInt8(const uchar *buf, bool nullVal, ColBatchWriter &ci) override { if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) fprintf(ci.filePtr(), "%c", ci.delimiter()); @@ -488,7 +488,7 @@ public: } - size_t ColWriteBatchXFloat(const uchar *buf, bool nullVal, ColBatchWriter &ci) override + size_t ColWriteBatchXFloat(const uchar *buf, bool nullVal, ColBatchWriter &ci) override { if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) fprintf(ci.filePtr(), "%c", ci.delimiter()); @@ -513,7 +513,7 @@ public: } - size_t ColWriteBatchXDouble(const uchar *buf, bool nullVal, ColBatchWriter &ci) override + size_t ColWriteBatchXDouble(const uchar *buf, bool nullVal, ColBatchWriter &ci) override { if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) fprintf(ci.filePtr(), "%c", ci.delimiter()); @@ -527,7 +527,7 @@ public: } - size_t ColWriteBatchSLongDouble(const uchar *buf, bool nullVal, ColBatchWriter &ci) override + size_t ColWriteBatchSLongDouble(const uchar *buf, bool nullVal, ColBatchWriter &ci) override { if (nullVal && (m_type.constraintType != CalpontSystemCatalog::NOTNULL_CONSTRAINT)) fprintf(ci.filePtr(), "%c", ci.delimiter()); @@ -537,7 +537,7 @@ public: } - size_t ColWriteBatchXDecimal(const uchar *buf, bool nullVal, ColBatchWriter &ci) override + size_t ColWriteBatchXDecimal(const uchar *buf, bool nullVal, ColBatchWriter &ci) override { uint bytesBefore = numDecimalBytes(m_type.precision - m_type.scale); uint totalBytes = bytesBefore + numDecimalBytes(m_type.scale); @@ -838,13 +838,13 @@ public: } - size_t ColWriteBatchVarbinary(const uchar *buf0, bool nullVal, ColBatchWriter &ci) override + size_t ColWriteBatchVarbinary(const uchar *buf0, bool nullVal, ColBatchWriter &ci) override { return ColWriteBatchString(buf0, nullVal, ci, &ColWriteBatchBlobString); } - size_t ColWriteBatchBlob(const uchar *buf0, bool nullVal, ColBatchWriter &ci) override + size_t ColWriteBatchBlob(const uchar *buf0, bool nullVal, ColBatchWriter &ci) override { return (UNLIKELY(m_type.colDataType == CalpontSystemCatalog::BLOB)) ? ColWriteBatchString(buf0, nullVal, ci, &ColWriteBatchBlobString) : diff --git a/utils/funcexp/functor.cpp b/utils/funcexp/functor.cpp index 7fb55b47e..2696eaf1c 100644 --- a/utils/funcexp/functor.cpp +++ b/utils/funcexp/functor.cpp @@ -61,7 +61,7 @@ void Func::init() double* dp = reinterpret_cast(&dni); fDoubleNullVal = *dp; - fDoubleNullVal = joblist::LONGDOUBLENULL; + fLongDoubleNullVal = joblist::LONGDOUBLENULL; } diff --git a/utils/regr/modamysql.cpp b/utils/regr/modamysql.cpp index 0d22fa343..770b72b7a 100644 --- a/utils/regr/modamysql.cpp +++ b/utils/regr/modamysql.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include #include #include "idb_mysql.h" @@ -31,10 +31,11 @@ struct moda_data { long double fSum; uint64_t fCount; - enum Item_result fReturnType; - std::tr1::unordered_map mapINT; - std::tr1::unordered_map mapREAL; - std::tr1::unordered_map mapDECIMAL; + enum Item_result fReturnType; + std::unordered_map mapINT; + std::unordered_map mapREAL; + std::unordered_map mapDECIMAL; + std::string result; void clear() { fSum = 0.0; @@ -44,9 +45,39 @@ struct moda_data mapDECIMAL.clear(); } }; - } +template +char * moda(CONTAINER & container, struct moda_data* data) +{ + TYPE avg = (TYPE)data->fCount ? data->fSum / data->fCount : 0; + TYPE val = 0.0; + uint32_t maxCnt = 0.0; + + for (auto iter = container.begin(); iter != container.end(); ++iter) + { + if (iter->second > maxCnt) + { + val = iter->first; + maxCnt = iter->second; + } + else if (iter->second == maxCnt) + { + // Tie breaker: choose the closest to avg. If still tie, choose smallest + if ((abs(val-avg) > abs(iter->first-avg)) + || ((abs(val-avg) == abs(iter->first-avg)) && (abs(val) > abs(iter->first)))) + { + val = iter->first; + } + } + } + + data->result = std::to_string(val); + + return const_cast(data->result.c_str()); +} + + extern "C" { @@ -83,7 +114,7 @@ void moda_deinit(UDF_INIT* initid) struct moda_data* data = (struct moda_data*)initid->ptr; data->clear(); delete data; -} +} #ifdef _MSC_VER __declspec(dllexport) @@ -98,7 +129,7 @@ void moda_clear(UDF_INIT* initid, char* is_null __attribute__((unused)), #ifdef _MSC_VER __declspec(dllexport) #endif -void moda_add(UDF_INIT* initid, +void moda_add(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* message __attribute__((unused))) @@ -188,101 +219,22 @@ void moda_remove(UDF_INIT* initid, UDF_ARGS* args, #ifdef _MSC_VER __declspec(dllexport) #endif -char* moda(UDF_INIT* initid, UDF_ARGS* args __attribute__((unused)), - char* is_null, char* error __attribute__((unused))) +char* moda(UDF_INIT* initid, UDF_ARGS* args, char* is_null, char* error __attribute__((unused))) { struct moda_data* data = (struct moda_data*)initid->ptr; - uint32_t maxCnt = 0.0; - switch (args->arg_type[0]) { case INT_RESULT: - { - typename std::tr1::unordered_map::iterator iter; - int64_t avg = (int64_t)data->fCount ? data->fSum / data->fCount : 0; - int64_t val = 0.0; - for (iter = data->mapINT.begin(); iter != data->mapINT.end(); ++iter) - { - if (iter->second > maxCnt) - { - val = iter->first; - maxCnt = iter->second; - } - else if (iter->second == maxCnt) - { - // Tie breaker: choose the closest to avg. If still tie, choose smallest - if ((abs(val-avg) > abs(iter->first-avg)) - || ((abs(val-avg) == abs(iter->first-avg)) && (abs(val) > abs(iter->first)))) - { - val = iter->first; - } - } - } - std::ostringstream oss; - oss << val; - return const_cast(oss.str().c_str()); - break; - } + return moda(data->mapINT, data); case REAL_RESULT: - { - typename std::tr1::unordered_map::iterator iter; - double avg = data->fCount ? data->fSum / data->fCount : 0; - double val = 0.0; - for (iter = data->mapREAL.begin(); iter != data->mapREAL.end(); ++iter) - { - if (iter->second > maxCnt) - { - val = iter->first; - maxCnt = iter->second; - } - else if (iter->second == maxCnt) - { - // Tie breaker: choose the closest to avg. If still tie, choose smallest - if ((abs(val-avg) > abs(iter->first-avg)) - || ((abs(val-avg) == abs(iter->first-avg)) && (abs(val) > abs(iter->first)))) - { - val = iter->first; - } - } - } - std::ostringstream oss; - oss << val; - return const_cast(oss.str().c_str()); - break; - } + return moda(data->mapREAL, data); case DECIMAL_RESULT: case STRING_RESULT: - { - typename std::tr1::unordered_map::iterator iter; - long double avg = data->fCount ? data->fSum / data->fCount : 0; - long double val = 0.0; - for (iter = data->mapDECIMAL.begin(); iter != data->mapDECIMAL.end(); ++iter) - { - if (iter->second > maxCnt) - { - val = iter->first; - maxCnt = iter->second; - } - else if (iter->second == maxCnt) - { - long double thisVal = iter->first; - // Tie breaker: choose the closest to avg. If still tie, choose smallest - if ((abs(val-avg) > abs(thisVal-avg)) - || ((abs(val-avg) == abs(thisVal-avg)) && (abs(val) > abs(thisVal)))) - { - val = thisVal; - } - } - } - std::ostringstream oss; - oss << val; - return const_cast(oss.str().c_str()); - break; - } + return moda(data->mapDECIMAL, data); default: - break; + return NULL; } + return NULL; } - } // Extern "C" diff --git a/utils/windowfunction/wf_udaf.h b/utils/windowfunction/wf_udaf.h index e87b39759..ef6345e0c 100644 --- a/utils/windowfunction/wf_udaf.h +++ b/utils/windowfunction/wf_udaf.h @@ -74,7 +74,7 @@ public: { return bInterrupted; } - bool getInterruptedPtr() + bool * getInterruptedPtr() { return &bInterrupted; } @@ -98,7 +98,7 @@ protected: bool bHasDropValue; // Set to false when we discover the UDAnF doesn't implement dropValue. // To hold distinct values and their counts typedef std::tr1::unordered_map DistinctMap; - DistinctMap fDistinctMap; + DistinctMap fDistinctMap; static_any::any fValOut; // The return value diff --git a/versioning/BRM/sessionmanagerserver.cpp b/versioning/BRM/sessionmanagerserver.cpp index 7d5f3b8be..55645615f 100644 --- a/versioning/BRM/sessionmanagerserver.cpp +++ b/versioning/BRM/sessionmanagerserver.cpp @@ -100,7 +100,7 @@ SessionManagerServer::SessionManagerServer() : unique32(0), unique64(0) catch (const std::exception& e) { cout << e.what() << endl; - stmp.empty(); + stmp.clear(); } if (stmp != "") diff --git a/writeengine/redistribute/we_redistributecontrolthread.cpp b/writeengine/redistribute/we_redistributecontrolthread.cpp index 93d4721bf..8b92c430f 100644 --- a/writeengine/redistribute/we_redistributecontrolthread.cpp +++ b/writeengine/redistribute/we_redistributecontrolthread.cpp @@ -460,7 +460,7 @@ int RedistributeControlThread::makeRedistributePlan() { if (targetDbroot == targetDbroots.end()) { - targetDbroot == targetDbroots.begin(); + targetDbroot = targetDbroots.begin(); } if (dbPartVec[*targetDbroot].size() < partCount) diff --git a/writeengine/splitter/we_splclient.h b/writeengine/splitter/we_splclient.h index 63c54c337..0a33aadec 100644 --- a/writeengine/splitter/we_splclient.h +++ b/writeengine/splitter/we_splclient.h @@ -213,7 +213,7 @@ public: void setBytesTx(uint32_t BytesTx) { boost::mutex::scoped_lock aLock(fTxMutex); - BytesTx = BytesTx; + fBytesTx = BytesTx; aLock.unlock(); } void updateBytesTx(uint32_t fBytes)