diff --git a/dbcon/mysql/ha_mcs_impl.cpp b/dbcon/mysql/ha_mcs_impl.cpp index 135c5edd9..0529523cc 100644 --- a/dbcon/mysql/ha_mcs_impl.cpp +++ b/dbcon/mysql/ha_mcs_impl.cpp @@ -1608,7 +1608,9 @@ uint32_t doUpdateDelete(THD* thd, gp_walk_info& gwi, const std::vector& c } // Exit early if there is nothing to update - if (colAssignmentListPtr->empty()) + if (colAssignmentListPtr->empty() && + (((thd->lex)->sql_command == SQLCOM_UPDATE) || + ((thd->lex)->sql_command == SQLCOM_UPDATE_MULTI))) { ci->affectedRows = 0; return 0; diff --git a/primitives/linux-port/column.cpp b/primitives/linux-port/column.cpp index b8acd52d9..1161f2cda 100644 --- a/primitives/linux-port/column.cpp +++ b/primitives/linux-port/column.cpp @@ -1537,11 +1537,6 @@ inline void p_Col_ridArray(NewColRequestHeader* in, #endif } - -// WIP MCOL-641 -using uint128_t = unsigned __int128; -using int128_t = __int128; - // for BINARY template inline void p_Col_bin_ridArray(NewColRequestHeader* in, diff --git a/primitives/primproc/columncommand.cpp b/primitives/primproc/columncommand.cpp index 8a50fd3e0..3dbd2fa61 100644 --- a/primitives/primproc/columncommand.cpp +++ b/primitives/primproc/columncommand.cpp @@ -48,6 +48,8 @@ using namespace rowgroup; #include "messageids.h" using namespace logging; +#include "emptyvaluemanip.h" + #ifdef _MSC_VER #define llabs labs #endif @@ -193,28 +195,34 @@ void ColumnCommand::loadData() { if (bPtr && colType.colWidth == 1) { - ByteStream::byte b = getEmptyRowValue(colType.colDataType, colType.colWidth); + ByteStream::byte b; + utils::getEmptyRowValue(colType.colDataType, colType.colWidth, (uint8_t*)&b); bPtr[idx] = b; } //@Bug 1812. Added two bytes column handling else if (dPtr && colType.colWidth == 2) { - ByteStream::doublebyte d = getEmptyRowValue(colType.colDataType, colType.colWidth); + ByteStream::doublebyte d; + utils::getEmptyRowValue(colType.colDataType, colType.colWidth, (uint8_t*)&d); dPtr[idx] = d; } else if (qPtr && colType.colWidth == 4) { - ByteStream::quadbyte q = getEmptyRowValue(colType.colDataType, colType.colWidth); + ByteStream::quadbyte q; + utils::getEmptyRowValue(colType.colDataType, colType.colWidth, (uint8_t*)&q); qPtr[idx] = q; } else if (oPtr && colType.colWidth == 8) { - ByteStream::octbyte o = getEmptyRowValue(colType.colDataType, colType.colWidth); + ByteStream::octbyte o; + utils::getEmptyRowValue(colType.colDataType, colType.colWidth, (uint8_t*)&o); oPtr[idx] = o; } else if (colType.colWidth == 16) { - getEmptyRowValue(colType.colDataType, colType.colWidth, &hPtr[idx]); + ByteStream::hexbyte h; + utils::getEmptyRowValue(colType.colDataType, colType.colWidth, (uint8_t*)&h); + hPtr[idx] = h; } } @@ -959,114 +967,6 @@ void ColumnCommand::enableFilters() prep(primMsg->OutputType, makeAbsRids); } - -/*********************************************************** -* DESCRIPTION: -* Get the value that represents empty row -* PARAMETERS: -* dataType - data type -* width - data width in byte -* RETURN: -* emptyVal - the value of empty row -***********************************************************/ -const uint64_t ColumnCommand::getEmptyRowValue( const CSCDataType dataType, const int width ) const -{ - uint64_t emptyVal = 0; - int offset; - - offset = ( dataType == execplan::CalpontSystemCatalog::VARCHAR ) ? -1 : 0; - - switch ( dataType ) - { - case execplan::CalpontSystemCatalog::TINYINT : - emptyVal = joblist::TINYINTEMPTYROW; - break; - - case execplan::CalpontSystemCatalog::SMALLINT: - emptyVal = joblist::SMALLINTEMPTYROW; - break; - - case execplan::CalpontSystemCatalog::MEDINT : - case execplan::CalpontSystemCatalog::INT : - emptyVal = joblist::INTEMPTYROW; - break; - - case execplan::CalpontSystemCatalog::BIGINT : - emptyVal = joblist::BIGINTEMPTYROW; - break; - - case execplan::CalpontSystemCatalog::UTINYINT : - emptyVal = joblist::UTINYINTEMPTYROW; - break; - - case execplan::CalpontSystemCatalog::USMALLINT: - emptyVal = joblist::USMALLINTEMPTYROW; - break; - - case execplan::CalpontSystemCatalog::UMEDINT : - case execplan::CalpontSystemCatalog::UINT : - emptyVal = joblist::UINTEMPTYROW; - break; - - case execplan::CalpontSystemCatalog::UBIGINT : - emptyVal = joblist::UBIGINTEMPTYROW; - break; - - case execplan::CalpontSystemCatalog::FLOAT : - case execplan::CalpontSystemCatalog::UFLOAT : - emptyVal = joblist::FLOATEMPTYROW; - break; - - case execplan::CalpontSystemCatalog::DOUBLE : - case execplan::CalpontSystemCatalog::UDOUBLE : - emptyVal = joblist::DOUBLEEMPTYROW; - break; - - case execplan::CalpontSystemCatalog::DECIMAL : - case execplan::CalpontSystemCatalog::UDECIMAL : - if ( width <= 1 ) - emptyVal = joblist::TINYINTEMPTYROW; - else if (width <= 2) - emptyVal = joblist::SMALLINTEMPTYROW; - else if ( width <= 4 ) - emptyVal = joblist::INTEMPTYROW; - else - emptyVal = joblist::BIGINTEMPTYROW; - - break; - - case execplan::CalpontSystemCatalog::CHAR : - case execplan::CalpontSystemCatalog::VARCHAR : - case execplan::CalpontSystemCatalog::DATE : - case execplan::CalpontSystemCatalog::DATETIME : - case execplan::CalpontSystemCatalog::TIMESTAMP : - case execplan::CalpontSystemCatalog::TIME : - case execplan::CalpontSystemCatalog::VARBINARY : - case execplan::CalpontSystemCatalog::BLOB : - case execplan::CalpontSystemCatalog::TEXT : - default: - emptyVal = joblist::CHAR1EMPTYROW; - - if ( width == (2 + offset) ) - emptyVal = joblist::CHAR2EMPTYROW; - else if ( width >= (3 + offset) && width <= ( 4 + offset ) ) - emptyVal = joblist::CHAR4EMPTYROW; - else if ( width >= (5 + offset) ) - emptyVal = joblist::CHAR8EMPTYROW; - - break; - } - - return emptyVal; -} - -void ColumnCommand::getEmptyRowValue(const CSCDataType dataType, - const int width, messageqcpp::ByteStream::hexbyte* space) const -{ - int128_t *val = reinterpret_cast(space); - utils::setWideDecimalEMptyValue(*val); -} - void ColumnCommand::getLBIDList(uint32_t loopCount, vector* lbids) { int64_t firstLBID = lbid, lastLBID = firstLBID + (loopCount * colType.colWidth) - 1, i; diff --git a/primitives/primproc/columncommand.h b/primitives/primproc/columncommand.h index 52544021f..c1db001b0 100644 --- a/primitives/primproc/columncommand.h +++ b/primitives/primproc/columncommand.h @@ -84,9 +84,6 @@ public: makeAbsRids = m; } bool willPrefetch(); - const uint64_t getEmptyRowValue( const CSCDataType dataType, const int width ) const; - void getEmptyRowValue(const CSCDataType dataType, - const int width, messageqcpp::ByteStream::hexbyte* space) const; const int64_t getLastLbid(); void getLBIDList(uint32_t loopCount, std::vector* lbids); diff --git a/primitives/primproc/passthrucommand.cpp b/primitives/primproc/passthrucommand.cpp index 7e362b1a6..6c7a0336f 100644 --- a/primitives/primproc/passthrucommand.cpp +++ b/primitives/primproc/passthrucommand.cpp @@ -167,7 +167,7 @@ void PassThruCommand::projectIntoRowGroup(RowGroup& rg, uint32_t col) << *(((int64_t*) bpp->values[i]) +1) << endl; // values[i] is 8 bytes so it contains the pointer to bpp->outputMsg set by ColumnCommand::process_OT_BOTH() - r.setBinaryField_offset((uint8_t*)bpp->values[i], 16, offset); + r.setBinaryField_offset((uint128_t*)bpp->values[i], 16, offset); r.nextRow(rowSize); } diff --git a/utils/common/CMakeLists.txt b/utils/common/CMakeLists.txt index c6a0fde01..e3dd4607e 100644 --- a/utils/common/CMakeLists.txt +++ b/utils/common/CMakeLists.txt @@ -10,7 +10,8 @@ set(common_LIB_SRCS MonitorProcMem.cpp nullvaluemanip.cpp threadnaming.cpp - utils_utf8.cpp) + utils_utf8.cpp + emptyvaluemanip.cpp) add_library(common SHARED ${common_LIB_SRCS}) diff --git a/utils/common/emptyvaluemanip.cpp b/utils/common/emptyvaluemanip.cpp new file mode 100644 index 000000000..fc97d2f14 --- /dev/null +++ b/utils/common/emptyvaluemanip.cpp @@ -0,0 +1,115 @@ +/* Copyright (C) 2020 MariaDB Corporation + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; version 2 of + the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. */ + +#include "widedecimalutils.h" +#include "emptyvaluemanip.h" + +namespace utils +{ + +void getEmptyRowValue(const execplan::CalpontSystemCatalog::ColDataType colDataType, + const int width, uint8_t* emptyVal) +{ + switch (colDataType) + { + case execplan::CalpontSystemCatalog::TINYINT: + *(uint8_t*)emptyVal = joblist::TINYINTEMPTYROW; + break; + + case execplan::CalpontSystemCatalog::SMALLINT: + *(uint16_t*)emptyVal = joblist::SMALLINTEMPTYROW; + break; + + case execplan::CalpontSystemCatalog::MEDINT: + case execplan::CalpontSystemCatalog::INT: + *(uint32_t*)emptyVal = joblist::INTEMPTYROW; + break; + + case execplan::CalpontSystemCatalog::BIGINT: + *(uint64_t*)emptyVal = joblist::BIGINTEMPTYROW; + break; + + case execplan::CalpontSystemCatalog::UTINYINT: + *(uint8_t*)emptyVal = joblist::UTINYINTEMPTYROW; + break; + + case execplan::CalpontSystemCatalog::USMALLINT: + *(uint16_t*)emptyVal = joblist::USMALLINTEMPTYROW; + break; + + case execplan::CalpontSystemCatalog::UMEDINT: + case execplan::CalpontSystemCatalog::UINT: + *(uint32_t*)emptyVal = joblist::UINTEMPTYROW; + break; + + case execplan::CalpontSystemCatalog::UBIGINT: + *(uint64_t*)emptyVal = joblist::UBIGINTEMPTYROW; + break; + + case execplan::CalpontSystemCatalog::FLOAT: + case execplan::CalpontSystemCatalog::UFLOAT: + *(uint32_t*)emptyVal = joblist::FLOATEMPTYROW; + break; + + case execplan::CalpontSystemCatalog::DOUBLE: + case execplan::CalpontSystemCatalog::UDOUBLE: + *(uint64_t*)emptyVal = joblist::DOUBLEEMPTYROW; + break; + + case execplan::CalpontSystemCatalog::DECIMAL: + case execplan::CalpontSystemCatalog::UDECIMAL: + if (width <= 1) + *(uint8_t*)emptyVal = joblist::TINYINTEMPTYROW; + else if (width <= 2) + *(uint16_t*)emptyVal = joblist::SMALLINTEMPTYROW; + else if (width <= 4) + *(uint32_t*)emptyVal = joblist::INTEMPTYROW; + else if (width <= 8) + *(uint64_t*)emptyVal = joblist::BIGINTEMPTYROW; + else + setWideDecimalEmptyValue(*(reinterpret_cast(emptyVal))); + break; + + //case CalpontSystemCatalog::BINARY: + // emptyVal = joblist::BINARYEMPTYROW; + // break; + + case execplan::CalpontSystemCatalog::CHAR: + case execplan::CalpontSystemCatalog::VARCHAR: + case execplan::CalpontSystemCatalog::DATE: + case execplan::CalpontSystemCatalog::DATETIME: + case execplan::CalpontSystemCatalog::TIMESTAMP: + case execplan::CalpontSystemCatalog::TIME: + case execplan::CalpontSystemCatalog::VARBINARY: + case execplan::CalpontSystemCatalog::BLOB: + case execplan::CalpontSystemCatalog::TEXT: + default: + *(uint8_t*)emptyVal = joblist::CHAR1EMPTYROW; + int offset = (colDataType == execplan::CalpontSystemCatalog::VARCHAR) ? -1 : 0; + + if (width == (2 + offset)) + *(uint16_t*)emptyVal = joblist::CHAR2EMPTYROW; + else if (width >= (3 + offset) && width <= (4 + offset)) + *(uint32_t*)emptyVal = joblist::CHAR4EMPTYROW; + else if (width >= (5 + offset)) + *(uint64_t*)emptyVal = joblist::CHAR8EMPTYROW; + + break; + } +} + +} // namespace utils diff --git a/utils/common/emptyvaluemanip.h b/utils/common/emptyvaluemanip.h new file mode 100644 index 000000000..2cf6222de --- /dev/null +++ b/utils/common/emptyvaluemanip.h @@ -0,0 +1,31 @@ +/* Copyright (C) 2020 MariaDB Corporation + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; version 2 of + the License. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + MA 02110-1301, USA. */ + +#ifndef EMPTY_VALUE_MANIP_H +#define EMPTY_VALUE_MANIP_H + +#include "calpontsystemcatalog.h" + +namespace utils +{ + +void getEmptyRowValue(const execplan::CalpontSystemCatalog::ColDataType colDataType, + const int width, uint8_t* emptyVal); + +} // namespace utils + +#endif // EMPTY_VALUE_MANIP_H diff --git a/utils/common/widedecimalutils.h b/utils/common/widedecimalutils.h index 67302f2bd..7ae3d0ebd 100644 --- a/utils/common/widedecimalutils.h +++ b/utils/common/widedecimalutils.h @@ -18,6 +18,8 @@ #ifndef WIDE_DECIMAL_UTILS_H #define WIDE_DECIMAL_UTILS_H +#include + using int128_t = __int128; using uint128_t = unsigned __int128; @@ -48,7 +50,7 @@ namespace utils ptr[1] = BINARYNULLVALUEHIGH; } - inline void setWideDecimalEMptyValue(int128_t& val) + inline void setWideDecimalEmptyValue(int128_t& val) { uint64_t* ptr = reinterpret_cast(&val); ptr[0] = BINARYEMPTYVALUELOW; @@ -62,7 +64,7 @@ namespace utils ptr[1] = BINARYNULLVALUEHIGH; } - inline void setWideDecimalEMptyValue(int128_t* val) + inline void setWideDecimalEmptyValue(int128_t* val) { uint64_t* ptr = reinterpret_cast(val); ptr[0] = BINARYEMPTYVALUELOW; diff --git a/utils/dataconvert/dataconvert.cpp b/utils/dataconvert/dataconvert.cpp index 42f4295fa..dac9e521e 100644 --- a/utils/dataconvert/dataconvert.cpp +++ b/utils/dataconvert/dataconvert.cpp @@ -1920,6 +1920,12 @@ DataConvert::convertColumnData(const CalpontSystemCatalog::ColType& colType, long long eightbyte = joblist::BIGINTNULL; value = eightbyte; } + else if (colType.colWidth == 16) + { + int128_t val; + utils::setWideDecimalNullValue(val); + value = val; + } else { WriteEngine::Token nullToken; diff --git a/writeengine/bulk/we_bulkload.cpp b/writeengine/bulk/we_bulkload.cpp index e51b51237..0b4c4abb5 100644 --- a/writeengine/bulk/we_bulkload.cpp +++ b/writeengine/bulk/we_bulkload.cpp @@ -563,9 +563,10 @@ int BulkLoad::preProcess( Job& job, int tableNo, job.jobTableList[tableNo].colList[i].weType = curColStruct.colType; // set width to correct column width job.jobTableList[tableNo].colList[i].width = curColStruct.colWidth; - job.jobTableList[tableNo].colList[i].emptyVal = getEmptyRowValue( - job.jobTableList[tableNo].colList[i].dataType, - job.jobTableList[tableNo].colList[i].width ); + getEmptyRowValue( + job.jobTableList[tableNo].colList[i].dataType, + job.jobTableList[tableNo].colList[i].width, + (uint8_t*)&job.jobTableList[tableNo].colList[i].emptyVal); // check HWM for column file rc = BRMWrapper::getInstance()->getDbRootHWMInfo( curJobCol.mapOid, diff --git a/writeengine/bulk/we_colbuf.cpp b/writeengine/bulk/we_colbuf.cpp index 7be21a6ec..caa4f8535 100644 --- a/writeengine/bulk/we_colbuf.cpp +++ b/writeengine/bulk/we_colbuf.cpp @@ -115,12 +115,13 @@ int ColumnBuffer::writeToFile(int startOffset, int writeSize, bool fillUpWEmptie { BlockOp blockOp; newBuf = new unsigned char[BYTE_PER_BLOCK]; - uint64_t EmptyValue = blockOp.getEmptyRowValue(fColInfo->column.dataType, - fColInfo->column.width); + uint8_t* emptyVal = (uint8_t*) alloca(fColInfo->column.width); + blockOp.getEmptyRowValue(fColInfo->column.dataType, + fColInfo->column.width, emptyVal); ::memcpy(static_cast(newBuf), static_cast(fBuffer + startOffset), writeSize); blockOp.setEmptyBuf(newBuf + writeSize, BYTE_PER_BLOCK - writeSize, - EmptyValue, fColInfo->column.width); + emptyVal, fColInfo->column.width); } #ifdef PROFILE Stats::startParseEvent(WE_STATS_WRITE_COL); diff --git a/writeengine/bulk/we_colbufcompressed.cpp b/writeengine/bulk/we_colbufcompressed.cpp index 43534dc75..0e359e885 100644 --- a/writeengine/bulk/we_colbufcompressed.cpp +++ b/writeengine/bulk/we_colbufcompressed.cpp @@ -132,7 +132,7 @@ int ColumnBufferCompressed::resetToBeCompressedColBuf( BlockOp::setEmptyBuf( fToBeCompressedBuffer, IDBCompressInterface::UNCOMPRESSED_INBUF_LEN, - fColInfo->column.emptyVal, + (uint8_t*)&fColInfo->column.emptyVal, fColInfo->column.width ); if (fLog->isDebug( DEBUG_2 )) @@ -317,7 +317,7 @@ int ColumnBufferCompressed::writeToFile(int startOffset, int writeSize, // Start over again loading a new to-be-compressed buffer BlockOp::setEmptyBuf( fToBeCompressedBuffer, IDBCompressInterface::UNCOMPRESSED_INBUF_LEN, - fColInfo->column.emptyVal, + (uint8_t*)&fColInfo->column.emptyVal, fColInfo->column.width ); fToBeCompressedCapacity = @@ -628,7 +628,7 @@ int ColumnBufferCompressed::initToBeCompressedBuffer(long long& startFileOffset) new unsigned char[IDBCompressInterface::UNCOMPRESSED_INBUF_LEN]; BlockOp::setEmptyBuf( fToBeCompressedBuffer, IDBCompressInterface::UNCOMPRESSED_INBUF_LEN, - fColInfo->column.emptyVal, + (uint8_t*)&fColInfo->column.emptyVal, fColInfo->column.width ); bNewBuffer = true; } @@ -743,7 +743,7 @@ int ColumnBufferCompressed::initToBeCompressedBuffer(long long& startFileOffset) { BlockOp::setEmptyBuf( fToBeCompressedBuffer, IDBCompressInterface::UNCOMPRESSED_INBUF_LEN, - fColInfo->column.emptyVal, + (uint8_t*)&fColInfo->column.emptyVal, fColInfo->column.width ); } diff --git a/writeengine/bulk/we_columninfo.cpp b/writeengine/bulk/we_columninfo.cpp index 5a9e4afa0..f0e40fb9d 100644 --- a/writeengine/bulk/we_columninfo.cpp +++ b/writeengine/bulk/we_columninfo.cpp @@ -895,7 +895,7 @@ int ColumnInfo::extendColumnOldExtent( } rc = colOp->expandAbbrevColumnExtent( pFile, dbRootNext, - column.emptyVal, column.width); + (uint8_t*)&column.emptyVal, column.width); if (rc != NO_ERROR) { diff --git a/writeengine/bulk/we_columninfocompressed.cpp b/writeengine/bulk/we_columninfocompressed.cpp index 25af8bc22..4fdd7f7be 100644 --- a/writeengine/bulk/we_columninfocompressed.cpp +++ b/writeengine/bulk/we_columninfocompressed.cpp @@ -540,7 +540,7 @@ int ColumnInfoCompressed::extendColumnOldExtent( int rc = colOp->fillCompColumnExtentEmptyChunks( curCol.dataFile.fid, curCol.colWidth, - column.emptyVal, + (uint8_t*)&column.emptyVal, curCol.dataFile.fDbRoot, curCol.dataFile.fPartition, curCol.dataFile.fSegment, diff --git a/writeengine/server/we_dmlcommandproc.cpp b/writeengine/server/we_dmlcommandproc.cpp index 83e75588d..ff274d677 100644 --- a/writeengine/server/we_dmlcommandproc.cpp +++ b/writeengine/server/we_dmlcommandproc.cpp @@ -370,8 +370,6 @@ uint8_t WE_DMLCommandProc::processSingleInsert(messageqcpp::ByteStream& bs, std: try { - // WIP - // make convertColumnData a template datavalue = DataConvert::convertColumnData(colType, indata, pushWarning, insertPkg.get_TimeZone(), isNULL, false, false); } catch (exception&) @@ -388,7 +386,7 @@ uint8_t WE_DMLCommandProc::processSingleInsert(messageqcpp::ByteStream& bs, std: return rc; } - if ( pushWarning) + if (pushWarning) { if (!isWarningSet) isWarningSet = true; @@ -546,7 +544,7 @@ uint8_t WE_DMLCommandProc::processSingleInsert(messageqcpp::ByteStream& bs, std: WErrorCodes ec; err = ec.errorString(error); } - else if ( error == ERR_BRM_VB_OVERFLOW ) + else if (error == ERR_BRM_VB_OVERFLOW) { rc = dmlpackageprocessor::DMLPackageProcessor::VB_OVERFLOW_ERROR; err = IDBErrorInfo::instance()->errorMsg(ERR_VERSIONBUFFER_OVERFLOW); @@ -561,9 +559,9 @@ uint8_t WE_DMLCommandProc::processSingleInsert(messageqcpp::ByteStream& bs, std: } std::map oids; - std::vector oidsToFlush; + std::vector oidsToFlush; - for ( unsigned i = 0; i < colStructs.size(); i++) + for (unsigned i = 0; i < colStructs.size(); i++) { oids[colStructs[i].dataOid] = colStructs[i].dataOid; oidsToFlush.push_back(colStructs[i].dataOid); diff --git a/writeengine/shared/we_blockop.cpp b/writeengine/shared/we_blockop.cpp index 01a8cd6f1..9cb1700eb 100644 --- a/writeengine/shared/we_blockop.cpp +++ b/writeengine/shared/we_blockop.cpp @@ -34,6 +34,8 @@ using namespace execplan; +#include "emptyvaluemanip.h" + namespace WriteEngine { @@ -83,110 +85,10 @@ bool BlockOp::calculateRowId( * emptyVal - the value of empty row ***********************************************************/ // TODO MCOL-641 Add support here -uint64_t BlockOp::getEmptyRowValue( - const CalpontSystemCatalog::ColDataType colDataType, const int width ) const +void BlockOp::getEmptyRowValue( + const CalpontSystemCatalog::ColDataType colDataType, const int width, uint8_t* emptyVal ) const { - uint64_t emptyVal = 0; - int offset = 0; - - switch ( colDataType ) - { - case CalpontSystemCatalog::TINYINT : - emptyVal = joblist::TINYINTEMPTYROW; - break; - - case CalpontSystemCatalog::SMALLINT: - emptyVal = joblist::SMALLINTEMPTYROW; - break; - - case CalpontSystemCatalog::MEDINT : - case CalpontSystemCatalog::INT : - emptyVal = joblist::INTEMPTYROW; - break; - - case CalpontSystemCatalog::BIGINT : - emptyVal = joblist::BIGINTEMPTYROW; - break; - - case CalpontSystemCatalog::FLOAT : - case CalpontSystemCatalog::UFLOAT : - emptyVal = joblist::FLOATEMPTYROW; - break; - - case CalpontSystemCatalog::DOUBLE : - case CalpontSystemCatalog::UDOUBLE : - emptyVal = joblist::DOUBLEEMPTYROW; - break; - - case CalpontSystemCatalog::DECIMAL : - case CalpontSystemCatalog::UDECIMAL : - - /* if( width <= 4 ) - emptyVal = joblist::SMALLINTEMPTYROW; - else - if( width <= 9 ) - emptyVal = 0x80000001; - else - if( width <= 18 ) - emptyVal = 0x8000000000000001LL; - else - emptyVal = 0xFFFFFFFFFFFFFFFFLL; - */ - // @bug 194 use the correct logic in handling empty value for decimal - if (width <= 1) - emptyVal = joblist::TINYINTEMPTYROW; - else if ( width <= 2 ) - emptyVal = joblist::SMALLINTEMPTYROW; - else if ( width <= 4 ) - emptyVal = joblist::INTEMPTYROW; - else if ( width <= 8 ) - emptyVal = joblist::BIGINTEMPTYROW; - else - emptyVal = joblist::BINARYEMPTYROW; - - break; - - case CalpontSystemCatalog::UTINYINT : - emptyVal = joblist::UTINYINTEMPTYROW; - break; - - case CalpontSystemCatalog::USMALLINT: - emptyVal = joblist::USMALLINTEMPTYROW; - break; - - case CalpontSystemCatalog::UMEDINT : - case CalpontSystemCatalog::UINT : - emptyVal = joblist::UINTEMPTYROW; - break; - - case CalpontSystemCatalog::UBIGINT : - emptyVal = joblist::UBIGINTEMPTYROW; - break; - - case CalpontSystemCatalog::BINARY : - emptyVal = joblist::BINARYEMPTYROW; - break; - - case CalpontSystemCatalog::CHAR : - case CalpontSystemCatalog::VARCHAR : - case CalpontSystemCatalog::DATE : - case CalpontSystemCatalog::DATETIME : - case CalpontSystemCatalog::TIMESTAMP : - default: - offset = ( colDataType == CalpontSystemCatalog::VARCHAR ) ? -1 : 0; - emptyVal = joblist::CHAR1EMPTYROW; - - if ( width == (2 + offset) ) - emptyVal = joblist::CHAR2EMPTYROW; - else if ( width >= (3 + offset) && width <= ( 4 + offset ) ) - emptyVal = joblist::CHAR4EMPTYROW; - else if ( width >= (5 + offset) ) - emptyVal = joblist::CHAR8EMPTYROW; - - break; - } - - return emptyVal; + utils::getEmptyRowValue(colDataType, width, emptyVal); } /*********************************************************** @@ -264,7 +166,7 @@ void BlockOp::resetBuf( unsigned char* buf, const int bufSize ) const ***********************************************************/ /* static */ void BlockOp::setEmptyBuf( - unsigned char* buf, const int bufSize, uint64_t emptyVal, const int width ) + unsigned char* buf, const int bufSize, uint8_t* emptyVal, const int width ) { const int ARRAY_COUNT = 128; const int NBYTES_IN_ARRAY = width * ARRAY_COUNT; @@ -275,10 +177,9 @@ void BlockOp::setEmptyBuf( // instead of individual values. This reduces the number of calls to // memcpy(). - int w = width > 8 ? 8: width; - for(uint8_t* pos = emptyValArray, * end = pos + NBYTES_IN_ARRAY; pos < end; pos += w) //FIXME for no loop + for(uint8_t* pos = emptyValArray, * end = pos + NBYTES_IN_ARRAY; pos < end; pos += width) //FIXME for no loop { - memcpy(pos, &emptyVal, w); + memcpy(pos, emptyVal, width); } int countFull128 = (bufSize / width) / ARRAY_COUNT; diff --git a/writeengine/shared/we_blockop.h b/writeengine/shared/we_blockop.h index eb88c5e38..10df5a8bb 100644 --- a/writeengine/shared/we_blockop.h +++ b/writeengine/shared/we_blockop.h @@ -89,8 +89,9 @@ public: /** * @brief Get an empty row value */ - EXPORT uint64_t getEmptyRowValue(const execplan::CalpontSystemCatalog::ColDataType colDataType, - const int width ) const; + EXPORT void getEmptyRowValue(const execplan::CalpontSystemCatalog::ColDataType colDataType, + const int width, + uint8_t* emptyVal ) const; /** * @brief Calculate row id @@ -116,7 +117,7 @@ public: */ EXPORT void static setEmptyBuf( unsigned char* buf, const int bufSize, - uint64_t emptyVal, const int width ); + uint8_t* emptyVal, const int width ); /** * @brief Set a value in a buffer diff --git a/writeengine/shared/we_bulkrollbackfile.cpp b/writeengine/shared/we_bulkrollbackfile.cpp index fbf4dfba7..ac4cdb4ee 100644 --- a/writeengine/shared/we_bulkrollbackfile.cpp +++ b/writeengine/shared/we_bulkrollbackfile.cpp @@ -306,7 +306,8 @@ void BulkRollbackFile::reInitTruncColumnExtent( } // Initialize the remainder of the extent after the HWM block - uint64_t emptyVal = fDbFile.getEmptyRowValue( colType, colWidth ); + uint8_t* emptyVal = (uint8_t*) alloca(colWidth); + fDbFile.getEmptyRowValue( colType, colWidth, emptyVal ); int rc = fDbFile.reInitPartialColumnExtent( pFile, startOffset, diff --git a/writeengine/shared/we_bulkrollbackfilecompressed.cpp b/writeengine/shared/we_bulkrollbackfilecompressed.cpp index 08954411d..4954930af 100644 --- a/writeengine/shared/we_bulkrollbackfilecompressed.cpp +++ b/writeengine/shared/we_bulkrollbackfilecompressed.cpp @@ -374,7 +374,8 @@ void BulkRollbackFileCompressed::reInitTruncColumnExtent( if (nBlocksToInit > 0) { - uint64_t emptyVal = fDbFile.getEmptyRowValue( colType, colWidth ); + uint8_t* emptyVal = (uint8_t*) alloca(colWidth); + fDbFile.getEmptyRowValue( colType, colWidth, emptyVal ); rc = fDbFile.reInitPartialColumnExtent( pFile, (chunkPtrs[chunkIndex].first + restoredChunkLen), nBlocksToInit, diff --git a/writeengine/shared/we_chunkmanager.cpp b/writeengine/shared/we_chunkmanager.cpp index 75a8feff8..a435ce1d4 100644 --- a/writeengine/shared/we_chunkmanager.cpp +++ b/writeengine/shared/we_chunkmanager.cpp @@ -821,7 +821,8 @@ int ChunkManager::fetchChunkFromFile(IDBDataFile* pFile, int64_t id, ChunkData*& void ChunkManager::initializeColumnChunk(char* buf, CompFileData* fileData) { int size = UNCOMPRESSED_CHUNK_SIZE; - uint64_t emptyVal = fFileOp->getEmptyRowValue(fileData->fColDataType, fileData->fColWidth); + uint8_t* emptyVal = (uint8_t*) alloca(fileData->fColWidth); + fFileOp->getEmptyRowValue(fileData->fColDataType, fileData->fColWidth, emptyVal); fFileOp->setEmptyBuf((unsigned char*)buf, size, emptyVal, fileData->fColWidth); } @@ -1342,7 +1343,7 @@ inline int ChunkManager::writeHeader_(CompFileData* fileData, int ptrSecSize) // For the specified segment file (pFile), read in an abbreviated/compressed // chunk extent, uncompress, and expand to a full chunk for a full extent. //------------------------------------------------------------------------------ -int ChunkManager::expandAbbrevColumnExtent(IDBDataFile* pFile, uint64_t emptyVal, int width) +int ChunkManager::expandAbbrevColumnExtent(IDBDataFile* pFile, uint8_t* emptyVal, int width) { map::iterator i = fFilePtrMap.find(pFile); diff --git a/writeengine/shared/we_chunkmanager.h b/writeengine/shared/we_chunkmanager.h index edf9b232f..6122537e3 100644 --- a/writeengine/shared/we_chunkmanager.h +++ b/writeengine/shared/we_chunkmanager.h @@ -214,7 +214,7 @@ public: void cleanUp(const std::map& columOids); // @brief Expand an initial column, not dictionary, extent to a full extent. - int expandAbbrevColumnExtent(IDBDataFile* pFile, uint64_t emptyVal, int width); + int expandAbbrevColumnExtent(IDBDataFile* pFile, uint8_t* emptyVal, int width); // @brief Update column extent int updateColumnExtent(IDBDataFile* pFile, int addBlockCount); diff --git a/writeengine/shared/we_convertor.cpp b/writeengine/shared/we_convertor.cpp index 9c5c63454..77fa8128d 100644 --- a/writeengine/shared/we_convertor.cpp +++ b/writeengine/shared/we_convertor.cpp @@ -639,8 +639,6 @@ void Convertor::convertColType(ColStruct* curStruct) break; default: - // WIP replace with BINARY - //*internalType = WriteEngine::WR_INT128; *internalType = WriteEngine::WR_BINARY; break; } @@ -710,14 +708,8 @@ void Convertor::convertColType(ColStruct* curStruct) // check whether width is in sync with the requirement *width = getCorrectRowWidth(dataType, *width); - - // This is the patch for the decimal thing, override -// if (dataType == CalpontSystemCatalog::DECIMAL) -// { -// *internalType = *width <= 4 ? -// WriteEngine::WR_INT : WriteEngine::WR_LONGLONG; -// } } + /******************************************************************************* * DESCRIPTION: diff --git a/writeengine/shared/we_fileop.cpp b/writeengine/shared/we_fileop.cpp index fe2eb2710..23e285e47 100644 --- a/writeengine/shared/we_fileop.cpp +++ b/writeengine/shared/we_fileop.cpp @@ -161,7 +161,7 @@ int FileOp::createDir( const char* dirName, mode_t mode ) const * ERR_FILE_CREATE if can not create the file ***********************************************************/ int FileOp::createFile( const char* fileName, int numOfBlock, - uint64_t emptyVal, int width, + uint8_t* emptyVal, int width, uint16_t dbRoot ) { IDBDataFile* pFile = @@ -228,7 +228,7 @@ int FileOp::createFile(FID fid, uint16_t dbRoot, uint32_t partition, execplan::CalpontSystemCatalog::ColDataType colDataType, - uint64_t emptyVal, + uint8_t* emptyVal, int width) { //std::cout << "Creating file oid: " << fid << @@ -569,7 +569,7 @@ bool FileOp::existsOIDDir( FID fid ) const ***********************************************************/ int FileOp::extendFile( OID oid, - uint64_t emptyVal, + uint8_t* emptyVal, int width, HWM hwm, BRM::LBID_t startLbid, @@ -875,7 +875,7 @@ int FileOp::extendFile( ***********************************************************/ int FileOp::addExtentExactFile( OID oid, - uint64_t emptyVal, + uint8_t* emptyVal, int width, int& allocSize, uint16_t dbRoot, @@ -1045,7 +1045,7 @@ int FileOp::initColumnExtent( IDBDataFile* pFile, uint16_t dbRoot, int nBlocks, - uint64_t emptyVal, + uint8_t* emptyVal, int width, bool bNewFile, bool bExpandExtent, @@ -1225,7 +1225,7 @@ int FileOp::initAbbrevCompColumnExtent( IDBDataFile* pFile, uint16_t dbRoot, int nBlocks, - uint64_t emptyVal, + uint8_t* emptyVal, int width) { // Reserve disk space for optimized abbreviated extent @@ -1285,7 +1285,7 @@ int FileOp::writeInitialCompColumnChunk( IDBDataFile* pFile, int nBlocksAllocated, int nRows, - uint64_t emptyVal, + uint8_t* emptyVal, int width, char* hdrs) { @@ -1366,7 +1366,7 @@ int FileOp::writeInitialCompColumnChunk( ***********************************************************/ int FileOp::fillCompColumnExtentEmptyChunks(OID oid, int colWidth, - uint64_t emptyVal, + uint8_t* emptyVal, uint16_t dbRoot, uint32_t partition, uint16_t segment, @@ -1671,7 +1671,7 @@ int FileOp::fillCompColumnExtentEmptyChunks(OID oid, ***********************************************************/ int FileOp::expandAbbrevColumnChunk( IDBDataFile* pFile, - uint64_t emptyVal, + uint8_t* emptyVal, int colWidth, const CompChunkPtr& chunkInPtr, CompChunkPtr& chunkOutPtr ) @@ -2036,7 +2036,7 @@ int FileOp::reInitPartialColumnExtent( IDBDataFile* pFile, long long startOffset, int nBlocks, - uint64_t emptyVal, + uint8_t* emptyVal, int width ) { int rc = setFileOffset( pFile, startOffset, SEEK_SET ); @@ -2845,7 +2845,7 @@ bool FileOp::isDiskSpaceAvail(const std::string& fileName, int nBlocks) const int FileOp::expandAbbrevColumnExtent( IDBDataFile* pFile, // FILE ptr to file where abbrev extent is to be expanded uint16_t dbRoot, // The DBRoot of the file with the abbreviated extent - uint64_t emptyVal,// Empty value to be used in expanding the extent + uint8_t* emptyVal,// Empty value to be used in expanding the extent int width ) // Width of the column (in bytes) { // Based on extent size, see how many blocks to add to fill the extent diff --git a/writeengine/shared/we_fileop.h b/writeengine/shared/we_fileop.h index 0b7d094e4..0615eaef8 100644 --- a/writeengine/shared/we_fileop.h +++ b/writeengine/shared/we_fileop.h @@ -92,7 +92,7 @@ public: int& allocSize, uint16_t dbRoot, uint32_t partition, execplan::CalpontSystemCatalog::ColDataType colDataType, - uint64_t emptyVal = 0, int width = 1 ) ; + uint8_t* emptyVal, int width = 1 ) ; /** @@ -100,7 +100,7 @@ public: * Changed to public for UT. */ int createFile( const char* fileName, int fileSize, - uint64_t emptyVal, int width, + uint8_t* emptyVal, int width, uint16_t dbRoot ); /** @@ -163,7 +163,7 @@ public: EXPORT virtual int expandAbbrevColumnExtent( IDBDataFile* pFile, uint16_t dbRoot, - uint64_t emptyVal, + uint8_t* emptyVal, int width ); /** @@ -198,7 +198,7 @@ public: * @param hdrs (in/out) Contents of headers, if file is compressed. * @return returns NO_ERROR if success. */ - EXPORT int extendFile(OID oid, uint64_t emptyVal, + EXPORT int extendFile(OID oid, uint8_t* emptyVal, int width, HWM hwm, BRM::LBID_t startLbid, @@ -226,7 +226,7 @@ public: * @param newFile (out) Indicates if a new file was created for the extent * @param hdrs (in/out) Contents of headers, if file is compressed. */ - EXPORT int addExtentExactFile(OID oid, uint64_t emptyVal, + EXPORT int addExtentExactFile(OID oid, uint8_t* emptyVal, int width, int& allocSize, uint16_t dbRoot, @@ -253,7 +253,7 @@ public: */ EXPORT int fillCompColumnExtentEmptyChunks(OID oid, int colWidth, - uint64_t emptyVal, + uint8_t* emptyVal, uint16_t dbRoot, uint32_t partition, uint16_t segment, @@ -433,7 +433,7 @@ public: EXPORT int reInitPartialColumnExtent( IDBDataFile* pFile, long long startOffset, int nBlocks, - uint64_t emptyVal, + uint8_t* emptyVal, int width ); /** @@ -497,7 +497,7 @@ public: int initColumnExtent( IDBDataFile* pFile, uint16_t dbRoot, int nBlocks, - uint64_t emptyVal, + uint8_t* emptyVal, int width, bool bNewFile, bool bExpandExtent, @@ -519,7 +519,7 @@ private: FileOp& operator=(const FileOp& rhs); int expandAbbrevColumnChunk( IDBDataFile* pFile, - uint64_t emptyVal, + uint8_t* emptyVal, int colWidth, const compress::CompChunkPtr& chunkInPtr, compress::CompChunkPtr& chunkOutPt); @@ -527,7 +527,7 @@ private: int initAbbrevCompColumnExtent( IDBDataFile* pFile, uint16_t dbRoot, int nBlocks, - uint64_t emptyVal, + uint8_t* emptyVal, int width); static void initDbRootExtentMutexes(); @@ -536,7 +536,7 @@ private: int writeInitialCompColumnChunk( IDBDataFile* pFile, int nBlocksAllocated, int nRows, - uint64_t emptyVal, + uint8_t* emptyVal, int width, char* hdrs); diff --git a/writeengine/shared/we_type.h b/writeengine/shared/we_type.h index c2b20a1af..ba77b9409 100644 --- a/writeengine/shared/we_type.h +++ b/writeengine/shared/we_type.h @@ -57,6 +57,7 @@ typedef uint32_t FID; /** @brief File ID */ typedef uint64_t RID; /** @brief Row ID */ typedef uint32_t TxnID; /** @brief Transaction ID (New)*/ typedef uint32_t HWM; /** @brief high water mark */ +typedef unsigned __int128 uint128_t; /************************************************************************ * Type enumerations @@ -347,7 +348,7 @@ struct JobColumn /** @brief Job Column Structure */ execplan::CalpontSystemCatalog::ColDataType dataType; /** @brief column data type */ ColType weType; /** @brief write engine data type */ std::string typeName; /** @brief data type name */ - uint64_t emptyVal; /** @brief default empty value */ + uint128_t emptyVal; /** @brief default empty value */ int width; /** @brief column width; for a dictionary column, this is "eventually" the token width */ int definedWidth; /** @brief column width as defined in the table, used for non-dictionary strings */ int dctnryWidth; /** @brief dictionary width */ diff --git a/writeengine/wrapper/we_colop.cpp b/writeengine/wrapper/we_colop.cpp index de6119752..a997f0999 100644 --- a/writeengine/wrapper/we_colop.cpp +++ b/writeengine/wrapper/we_colop.cpp @@ -45,6 +45,7 @@ using namespace execplan; using namespace idbdatafile; +#include "emptyvaluemanip.h" namespace WriteEngine { @@ -54,6 +55,9 @@ struct RefcolInfo unsigned numExtents; }; +using int128_t = __int128; +using uint128_t = unsigned __int128; + /** * Constructor */ @@ -126,10 +130,8 @@ int ColumnOp::allocRowId(const TxnID& txnid, bool useStartingExtent, Column newCol; unsigned char buf[BYTE_PER_BLOCK]; unsigned char* curVal; - int64_t emptyVal = getEmptyRowValue(column.colDataType, column.colWidth); // Seems is ok have it here and just once - // TODO MCOL-641 consolidate the emptyvalue logic - //__int128 bigEmptyVal; - //dataconvert::DataConvert::uint128Max(bigEmptyVal); + uint8_t* emptyVal = (uint8_t*) alloca(column.colWidth); + getEmptyRowValue(column.colDataType, column.colWidth, emptyVal); if (useStartingExtent) { @@ -190,10 +192,12 @@ int ColumnOp::allocRowId(const TxnID& txnid, bool useStartingExtent, { if (rc == ERR_FILE_EOF) { - uint64_t emptyVal = getEmptyRowValue(column.colDataType, column.colWidth); + uint8_t* emptyVal = (uint8_t*) alloca(column.colWidth); + getEmptyRowValue(column.colDataType, column.colWidth, emptyVal); setEmptyBuf(buf, BYTE_PER_BLOCK, emptyVal, column.colWidth); RETURN_ON_ERROR(saveBlock(column.dataFile.pFile, buf, hwm)); - } else + } + else { return rc; } @@ -287,7 +291,8 @@ int ColumnOp::allocRowId(const TxnID& txnid, bool useStartingExtent, if (newColStructList[i].fCompressionType > 0) { - uint64_t emptyVal = getEmptyRowValue(newColStructList[i].colDataType, newColStructList[i].colWidth); + uint8_t* emptyVal = (uint8_t*) alloca(newColStructList[i].colWidth); + getEmptyRowValue(newColStructList[i].colDataType, newColStructList[i].colWidth, emptyVal); string errorInfo; rc = fileOp.fillCompColumnExtentEmptyChunks(newColStructList[i].dataOid, newColStructList[i].colWidth, emptyVal, dbRoot, partition, segment, newHwm, segFile, errorInfo); @@ -313,7 +318,8 @@ int ColumnOp::allocRowId(const TxnID& txnid, bool useStartingExtent, return rc; } - uint64_t emptyVal = getEmptyRowValue(newColStructList[i].colDataType, newColStructList[i].colWidth); + uint8_t* emptyVal = (uint8_t*) alloca(newColStructList[i].colWidth); + getEmptyRowValue(newColStructList[i].colDataType, newColStructList[i].colWidth, emptyVal); rc = fileOp.expandAbbrevColumnExtent( pFile, dbRoot, emptyVal, newColStructList[i].colWidth); //set hwm for this extent. fileOp.closeFile(pFile); @@ -385,7 +391,7 @@ int ColumnOp::allocRowId(const TxnID& txnid, bool useStartingExtent, return rc; //create corresponding dictionary files - if (newFile ) + if (newFile) { boost::scoped_ptr we (new WriteEngineWrapper()); we->setTransId(txnid); @@ -406,7 +412,7 @@ int ColumnOp::allocRowId(const TxnID& txnid, bool useStartingExtent, } } - we->flushDataFiles(rc, txnid, columnOids ); + we->flushDataFiles(rc, txnid, columnOids); } } @@ -490,10 +496,12 @@ int ColumnOp::allocRowId(const TxnID& txnid, bool useStartingExtent, { if (rc == ERR_FILE_EOF) { - uint64_t emptyVal = getEmptyRowValue(newCol.colDataType, newCol.colWidth); + uint8_t* emptyVal = (uint8_t*) alloca(newCol.colWidth); + getEmptyRowValue(newCol.colDataType, newCol.colWidth, emptyVal); setEmptyBuf(buf, BYTE_PER_BLOCK, emptyVal, newCol.colWidth); RETURN_ON_ERROR(saveBlock(newCol.dataFile.pFile, buf, newHwm)); - } else + } + else { return rc; } @@ -531,10 +539,12 @@ int ColumnOp::allocRowId(const TxnID& txnid, bool useStartingExtent, { if (rc == ERR_FILE_EOF) { - uint64_t emptyVal = getEmptyRowValue(newCol.colDataType, newCol.colWidth); + uint8_t* emptyVal = (uint8_t*) alloca(newCol.colWidth); + getEmptyRowValue(newCol.colDataType, newCol.colWidth, emptyVal); setEmptyBuf(buf, BYTE_PER_BLOCK, emptyVal, newCol.colWidth); RETURN_ON_ERROR(saveBlock(newCol.dataFile.pFile, buf, newHwm)); - } else + } + else { return rc; } @@ -641,10 +651,10 @@ int ColumnOp::createColumn(Column& column, uint32_t partition) { int rc, newWidth, allocSize; - uint64_t emptyVal = 0; int compressionType = column.compressionType; setColParam(column, colNo, colWidth, colDataType, colType); - emptyVal = getEmptyRowValue(colDataType, colWidth); + uint8_t* emptyVal = (uint8_t*) alloca(colWidth); + getEmptyRowValue(colDataType, colWidth, emptyVal); newWidth = getCorrectRowWidth(colDataType, colWidth); column.dataFile.fid = dataFid; column.dataFile.fDbRoot = dbRoot; @@ -677,8 +687,6 @@ int ColumnOp::fillColumn(const TxnID& txnid, Column& column, Column& refCol, voi HWM colHwm = 0; RID maxRowId = 0; int size = sizeof(Token); - uint64_t emptyVal; - uint64_t refEmptyVal; long long startColFbo = 0; long long startRefColFbo = 0; @@ -713,8 +721,10 @@ int ColumnOp::fillColumn(const TxnID& txnid, Column& column, Column& refCol, voi config.initConfigCache(); std::vector rootList; config.getRootIdList( rootList ); - emptyVal = getEmptyRowValue(column.colDataType, column.colWidth); - refEmptyVal = getEmptyRowValue(refCol.colDataType, refCol.colWidth); + uint8_t* emptyVal = (uint8_t*) alloca(column.colWidth); + uint8_t* refEmptyVal = (uint8_t*) alloca(refCol.colWidth); + getEmptyRowValue(column.colDataType, column.colWidth, emptyVal); + getEmptyRowValue(refCol.colDataType, refCol.colWidth, refEmptyVal); //find the dbroots which have rows for refrence column unsigned int i = 0, k = 0; @@ -938,7 +948,7 @@ int ColumnOp::fillColumn(const TxnID& txnid, Column& column, Column& refCol, voi while (refBufOffset > 0) { - if (memcmp(&refColBuf[refBufOffset], &refEmptyVal, refCol.colWidth) != 0) + if (memcmp(&refColBuf[refBufOffset], refEmptyVal, refCol.colWidth) != 0) { maxRowId = maxRowId + (refBufOffset / refCol.colWidth); break; @@ -999,7 +1009,7 @@ int ColumnOp::fillColumn(const TxnID& txnid, Column& column, Column& refCol, voi while ((tmpBufOffset + refCol.colWidth) <= BYTE_PER_BLOCK) { - if (memcmp(refColBuf + tmpBufOffset, &refEmptyVal, refCol.colWidth) != 0) //Find the number of nextVal needed. + if (memcmp(refColBuf + tmpBufOffset, refEmptyVal, refCol.colWidth) != 0) //Find the number of nextVal needed. { nexValNeeded++; //memcpy(colBuf + colBufOffset, defaultVal, column.colWidth); @@ -1028,7 +1038,7 @@ int ColumnOp::fillColumn(const TxnID& txnid, Column& column, Column& refCol, voi while (((refBufOffset + refCol.colWidth) <= BYTE_PER_BLOCK) && ((colBufOffset + column.colWidth) <= BYTE_PER_BLOCK)) { - if (memcmp(refColBuf + refBufOffset, &refEmptyVal, refCol.colWidth) != 0) //Find the number of nextVal needed. + if (memcmp(refColBuf + refBufOffset, refEmptyVal, refCol.colWidth) != 0) //Find the number of nextVal needed. { memcpy(defaultVal, &nextVal, 8); nextVal++; @@ -1085,7 +1095,7 @@ int ColumnOp::fillColumn(const TxnID& txnid, Column& column, Column& refCol, voi while (((refBufOffset + refCol.colWidth) <= BYTE_PER_BLOCK) && ((colBufOffset + column.colWidth) <= BYTE_PER_BLOCK)) { - if (memcmp(refColBuf + refBufOffset, &refEmptyVal, refCol.colWidth) != 0) + if (memcmp(refColBuf + refBufOffset, refEmptyVal, refCol.colWidth) != 0) { /*if (autoincrement) { @@ -1097,8 +1107,7 @@ int ColumnOp::fillColumn(const TxnID& txnid, Column& column, Column& refCol, voi } else if (column.compressionType != 0) //@Bug 3866, fill the empty row value for compressed chunk { - for(int b = 0, w = column.colWidth; b < column.colWidth; b += 8, w = 8) //FIXME for no loop! - memcpy(colBuf + colBufOffset + b, &emptyVal, w); + memcpy(colBuf + colBufOffset, emptyVal, column.colWidth); dirty = true; } @@ -1327,9 +1336,8 @@ int ColumnOp::extendColumn( bool& newFile, char* hdrs) { - uint64_t emptyVal = 0; - - emptyVal = getEmptyRowValue(column.colDataType, column.colWidth); + uint8_t* emptyVal = (uint8_t*) alloca(column.colWidth); + getEmptyRowValue(column.colDataType, column.colWidth, emptyVal); int rc = extendFile(column.dataFile.fid, emptyVal, column.colWidth, @@ -1370,9 +1378,8 @@ int ColumnOp::addExtent( int& allocSize, char* hdrs) { - uint64_t emptyVal = 0; - - emptyVal = getEmptyRowValue(column.colDataType, column.colWidth); + uint8_t* emptyVal = (uint8_t*) alloca(column.colWidth); + getEmptyRowValue(column.colDataType, column.colWidth, emptyVal); int rc = addExtentExactFile(column.dataFile.fid, emptyVal, column.colWidth, @@ -1400,7 +1407,8 @@ int ColumnOp::addExtent( ***********************************************************/ int ColumnOp::expandAbbrevExtent(const Column& column) { - uint64_t emptyVal = getEmptyRowValue(column.colDataType, column.colWidth); + uint8_t* emptyVal = (uint8_t*) alloca(column.colWidth); + getEmptyRowValue(column.colDataType, column.colWidth, emptyVal); int rc = expandAbbrevColumnExtent(column.dataFile.pFile, column.dataFile.fDbRoot, emptyVal, @@ -1456,33 +1464,30 @@ void ColumnOp::initColumn(Column& column) const * RETURN: * true if success, false otherwise ***********************************************************/ - -// It is called at just 4 places on allocRowId() but all the time inside extend scanning loops -// WIP Template this method -// TODO MCOL-641 Add support here. -inline bool ColumnOp::isEmptyRow(uint64_t* curVal, uint64_t emptyVal, const int colWidth) +inline bool ColumnOp::isEmptyRow(uint64_t* curVal, uint8_t* emptyVal, const int colWidth) { + // colWidth is either 1, 2, 4, 8, or 16 (Convertor::getCorrectRowWidth) switch(colWidth){ case 1: - return *(uint8_t*)curVal == emptyVal; + return *(uint8_t*)curVal == *(uint8_t*)emptyVal; case 2: - return *(uint16_t*)curVal == emptyVal; + return *(uint16_t*)curVal == *(uint16_t*)emptyVal; case 4: - return *(uint32_t*)curVal == emptyVal; + return *(uint32_t*)curVal == *(uint32_t*)emptyVal; case 8: - return *curVal == emptyVal; + return *(uint64_t*)curVal == *(uint64_t*)emptyVal; case 16: - return ((curVal[0] == emptyVal) && (curVal[1] == emptyVal)); + return *(uint128_t*)curVal == *(uint128_t*)emptyVal; - case 32: - return ((curVal[0] == emptyVal) && (curVal[1] == emptyVal) - && (curVal[2] == emptyVal) && (curVal[3] == emptyVal)); + //case 32: + // return ((curVal[0] == emptyVal) && (curVal[1] == emptyVal) + // && (curVal[2] == emptyVal) && (curVal[3] == emptyVal)); } - // WIP + return false; } @@ -1610,11 +1615,6 @@ void ColumnOp::setColParam(Column& column, column.compressionType = compressionType; } -// WIP -using int128_t = __int128; -using uint128_t = unsigned __int128; - - /*********************************************************** * DESCRIPTION: * Write row(s) @@ -1637,7 +1637,7 @@ int ColumnOp::writeRow(Column& curCol, uint64_t totalRow, const RID* rowIdArray, bool bExit = false, bDataDirty = false; void* pVal = 0; char charTmpBuf[8]; - uint64_t emptyVal; + uint8_t* emptyVal = (uint8_t*) alloca(curCol.colWidth); int rc = NO_ERROR; uint16_t rowsInBlock = BYTE_PER_BLOCK / curCol.colWidth; @@ -1734,9 +1734,7 @@ int ColumnOp::writeRow(Column& curCol, uint64_t totalRow, const RID* rowIdArray, break; case WriteEngine::WR_BINARY: - // WIP CSCCol type - pVal = &((uint128_t*) valArray)[i]; - //pVal = (uint8_t*) valArray + i * curCol.colWidth; + if (!bDelete) pVal = &((int128_t*) valArray)[i]; break; default : @@ -1744,11 +1742,10 @@ int ColumnOp::writeRow(Column& curCol, uint64_t totalRow, const RID* rowIdArray, break; } - // TODO MCOL-641 do we need support here? if (bDelete) { - emptyVal = getEmptyRowValue(curCol.colDataType, curCol.colWidth); - pVal = &emptyVal; + utils::getEmptyRowValue(curCol.colDataType, curCol.colWidth, emptyVal); + pVal = emptyVal; } // This is the write stuff @@ -1793,16 +1790,9 @@ int ColumnOp::writeRows(Column& curCol, uint64_t totalRow, const RIDList& ridLis void* pVal = 0; //void* pOldVal; char charTmpBuf[8]; - uint64_t emptyVal; + uint8_t* emptyVal; int rc = NO_ERROR; - int w = 0, incr = 8; - - if (curCol.colType == WriteEngine::WR_BINARY) - w = incr = curCol.colWidth; - else - w = curCol.colWidth > 8 ? 8 : curCol.colWidth; - while (!bExit) { curRowId = ridList[i]; @@ -1903,26 +1893,12 @@ int ColumnOp::writeRows(Column& curCol, uint64_t totalRow, const RIDList& ridLis } else { - if (curCol.colType != WriteEngine::WR_BINARY) - { - emptyVal = getEmptyRowValue(curCol.colDataType, curCol.colWidth); - pVal = &emptyVal; - } - else - { - // fix this - uint128_t bigEmptyVal; - emptyVal = getEmptyRowValue(curCol.colDataType, curCol.colWidth); - *(reinterpret_cast(&bigEmptyVal)) = emptyVal; - *(reinterpret_cast(&bigEmptyVal) + 1) = emptyVal; - //dataconvert::DataConvert::uint128Max(bigEmptyVal); - pVal = &bigEmptyVal; - } + emptyVal = (uint8_t*) alloca(curCol.colWidth); + getEmptyRowValue(curCol.colDataType, curCol.colWidth, emptyVal); + pVal = emptyVal; } - // This is the write stuff - for (int b = 0; b < curCol.colWidth; b += incr) //FIXME for no loop - writeBufValue(dataBuf + dataBio + b, pVal, w); + writeBufValue(dataBuf + dataBio, pVal, curCol.colWidth); i++; diff --git a/writeengine/wrapper/we_colop.h b/writeengine/wrapper/we_colop.h index ad485a8e7..1b2d5dcc7 100644 --- a/writeengine/wrapper/we_colop.h +++ b/writeengine/wrapper/we_colop.h @@ -220,7 +220,7 @@ public: /** * @brief Check whether it is an empty row */ - EXPORT virtual bool isEmptyRow(uint64_t* curVal, uint64_t emptyVal, const int colWidth); + EXPORT virtual bool isEmptyRow(uint64_t* curVal, uint8_t* emptyVal, const int colWidth); /** * @brief Check whether it is a valid column diff --git a/writeengine/wrapper/we_colopcompress.cpp b/writeengine/wrapper/we_colopcompress.cpp index cb4fb05dd..4b06c429d 100644 --- a/writeengine/wrapper/we_colopcompress.cpp +++ b/writeengine/wrapper/we_colopcompress.cpp @@ -191,7 +191,7 @@ int ColumnOpCompress1::flushFile(int rc, std::map& columnOids) int ColumnOpCompress1::expandAbbrevColumnExtent( - IDBDataFile* pFile, uint16_t dbRoot, uint64_t emptyVal, int width) + IDBDataFile* pFile, uint16_t dbRoot, uint8_t* emptyVal, int width) { // update the uncompressed initial chunk to full chunk int rc = m_chunkManager->expandAbbrevColumnExtent(pFile, emptyVal, width); diff --git a/writeengine/wrapper/we_colopcompress.h b/writeengine/wrapper/we_colopcompress.h index 0203af320..5b6635dac 100644 --- a/writeengine/wrapper/we_colopcompress.h +++ b/writeengine/wrapper/we_colopcompress.h @@ -111,7 +111,7 @@ public: /** * @brief virtual method in FileOp */ - int expandAbbrevColumnExtent(IDBDataFile* pFile, uint16_t dbRoot, uint64_t emptyVal, int width); + int expandAbbrevColumnExtent(IDBDataFile* pFile, uint16_t dbRoot, uint8_t* emptyVal, int width); /** * @brief virtual method in ColumnOp diff --git a/writeengine/wrapper/writeengine.cpp b/writeengine/wrapper/writeengine.cpp index 7ce12b5a3..559dbe616 100644 --- a/writeengine/wrapper/writeengine.cpp +++ b/writeengine/wrapper/writeengine.cpp @@ -168,7 +168,6 @@ int WriteEngineWrapper::checkValid(const TxnID& txnid, const ColStructList& colS structListSize = colStructList.size() ; valListSize = colValueList.size(); -// if (colStructList.size() != colValueList.size()) if (structListSize != valListSize) return ERR_STRUCT_VALUE_NOT_MATCH; @@ -400,16 +399,16 @@ void WriteEngineWrapper::convertValue(const execplan::CalpontSystemCatalog::ColT } break; - // WIP MCOL-641 case WriteEngine::WR_BINARY: { size = cscColType.colWidth; - if (cscColType.colDataType == CalpontSystemCatalog::DECIMAL) + if (cscColType.colDataType == CalpontSystemCatalog::DECIMAL || + cscColType.colDataType == CalpontSystemCatalog::UDECIMAL) { int128_t val = boost::any_cast(data); memcpy(value, &val, size); } - else + else // for CalpontSystemCatalog::BINARY { char val = boost::any_cast(data); memcpy(value, &val, size); @@ -521,19 +520,19 @@ void WriteEngineWrapper::convertValue(const CalpontSystemCatalog::ColType& cscCo ((Token*)valArray)[pos] = boost::any_cast(data); break; + // WIP MCOL-641 case WriteEngine::WR_BINARY: - if (cscColType.colDataType != CalpontSystemCatalog::DECIMAL) - { - curStr = boost::any_cast(data); - // String length or column width? - memcpy((char*)valArray + pos * curStr.length(), curStr.c_str(), curStr.length()); - } - else + size_t size = cscColType.colWidth; + if (cscColType.colDataType == CalpontSystemCatalog::DECIMAL || + cscColType.colDataType == CalpontSystemCatalog::UDECIMAL) { int128_t val = boost::any_cast(data); - size_t size = cscColType.colWidth; - // WIP Why do we use memcpy here? - memcpy((uint8_t*)valArray+pos*size, &val, size); + memcpy((uint8_t*)valArray + pos * size, &val, size); + } + else // for CalpontSystemCatalog::BINARY + { + char val = boost::any_cast(data); + memcpy((uint8_t*)valArray + pos * size, &val, size); } break; @@ -602,17 +601,19 @@ void WriteEngineWrapper::convertValue(const CalpontSystemCatalog::ColType& cscCo case WriteEngine::WR_TOKEN: data = ((Token*)valArray)[pos]; break; - // WIP + // WIP MCOL-641 case WriteEngine::WR_BINARY : - if (cscColType.colDataType == CalpontSystemCatalog::DECIMAL) + if (cscColType.colDataType == CalpontSystemCatalog::DECIMAL || + cscColType.colDataType == CalpontSystemCatalog::UDECIMAL) { data = ((int128_t*)valArray)[pos]; } - else + else // for CalpontSystemCatalog::BINARY { // WIP do we need tmp here? - char *tmp = (char*) alloca (sizeof(char) * cscColType.colWidth); - memcpy(tmp, (char*)valArray + pos * cscColType.colWidth, cscColType.colWidth); + size_t size = cscColType.colWidth; + char *tmp = (char*) alloca (sizeof(char) * size); + memcpy(tmp, (uint8_t*)valArray + pos * size, size); curStr = tmp; data = curStr; } @@ -778,7 +779,6 @@ int WriteEngineWrapper::deleteRow(const TxnID& txnid, const vector DctnryValueList dctnryValueList; ColStructList colStructList; CSCTypesList cscColTypeList; - uint64_t emptyVal; int rc; string tmpStr(""); vector dctnryExtentsStruct; @@ -790,6 +790,8 @@ int WriteEngineWrapper::deleteRow(const TxnID& txnid, const vector setTransId(txnid); unsigned numExtents = colExtentsStruct.size(); + uint128_t emptyVal; + for (unsigned extent = 0; extent < numExtents; extent++) { colStructList = colExtentsStruct[extent]; @@ -802,23 +804,21 @@ int WriteEngineWrapper::deleteRow(const TxnID& txnid, const vector cscColType = cscColTypeList[i]; Convertor::convertColType(&curColStruct); - if (curColStruct.colType == WriteEngine::WR_BINARY) + /*if (curColStruct.colType == WriteEngine::WR_BINARY) { uint128_t bigEmptyVal; emptyVal = m_colOp[op(curColStruct.fCompressionType)]-> getEmptyRowValue(curColStruct.colDataType, curColStruct.colWidth); *(reinterpret_cast(&bigEmptyVal)) = emptyVal; *(reinterpret_cast(&bigEmptyVal) + 1) = emptyVal; - //dataconvert::DataConvert::uint128Max(bigEmptyVal); curTuple.data = bigEmptyVal; } else - { - emptyVal = m_colOp[op(curColStruct.fCompressionType)]-> - getEmptyRowValue(curColStruct.colDataType, curColStruct.colWidth); - + {*/ + m_colOp[op(curColStruct.fCompressionType)]-> + getEmptyRowValue(curColStruct.colDataType, curColStruct.colWidth, (uint8_t*)&emptyVal); curTuple.data = emptyVal; - } + //} curTupleList.push_back(curTuple); colValueList.push_back(curTupleList); @@ -850,6 +850,75 @@ int WriteEngineWrapper::deleteRow(const TxnID& txnid, const vector return rc; } +inline void allocateValArray(void*& valArray, ColTupleList::size_type totalRow, + ColType colType, int colWidth) +{ + valArray = calloc(totalRow, colWidth); + // TODO MCOL-641 is commenting out the switch statement below correct? +#if 0 + switch (colType) + { + case WriteEngine::WR_INT: + case WriteEngine::WR_MEDINT: + valArray = (int*) calloc(sizeof(int), totalRow); + break; + + case WriteEngine::WR_UINT: + case WriteEngine::WR_UMEDINT: + valArray = (uint32_t*) calloc(sizeof(uint32_t), totalRow); + break; + + case WriteEngine::WR_VARBINARY : // treat same as char for now + case WriteEngine::WR_CHAR: + case WriteEngine::WR_BLOB: + case WriteEngine::WR_TEXT: + valArray = (char*) calloc(sizeof(char), totalRow * MAX_COLUMN_BOUNDARY); + break; + + case WriteEngine::WR_FLOAT: + valArray = (float*) calloc(sizeof(float), totalRow); + break; + + case WriteEngine::WR_DOUBLE: + valArray = (double*) calloc(sizeof(double), totalRow); + break; + + case WriteEngine::WR_BYTE: + valArray = (char*) calloc(sizeof(char), totalRow); + break; + + case WriteEngine::WR_UBYTE: + valArray = (uint8_t*) calloc(sizeof(uint8_t), totalRow); + break; + + case WriteEngine::WR_SHORT: + valArray = (short*) calloc(sizeof(short), totalRow); + break; + + case WriteEngine::WR_USHORT: + valArray = (uint16_t*) calloc(sizeof(uint16_t), totalRow); + break; + + case WriteEngine::WR_LONGLONG: + valArray = (long long*) calloc(sizeof(long long), totalRow); + break; + + case WriteEngine::WR_ULONGLONG: + valArray = (uint64_t*) calloc(sizeof(uint64_t), totalRow); + break; + + case WriteEngine::WR_TOKEN: + valArray = (Token*) calloc(sizeof(Token), totalRow); + break; + + case WriteEngine::WR_BINARY: + valArray = calloc(totalRow, colWidth); + break; + + } +#endif +} + int WriteEngineWrapper::deleteBadRows(const TxnID& txnid, ColStructList& colStructs, RIDList& ridList, DctnryStructList& dctnryStructList) { @@ -889,69 +958,7 @@ int WriteEngineWrapper::deleteBadRows(const TxnID& txnid, ColStructList& colStru throw std::runtime_error(oss.str()); } - switch (colStructs[i].colType) - { - case WriteEngine::WR_INT: - case WriteEngine::WR_MEDINT: - valArray = (int*) calloc(sizeof(int), 1); - break; - - case WriteEngine::WR_UINT: - case WriteEngine::WR_UMEDINT: - valArray = (uint32_t*) calloc(sizeof(uint32_t), 1); - break; - - case WriteEngine::WR_VARBINARY : // treat same as char for now - case WriteEngine::WR_CHAR: - case WriteEngine::WR_BLOB: - case WriteEngine::WR_TEXT: - valArray = (char*) calloc(sizeof(char), 1 * MAX_COLUMN_BOUNDARY); - break; - - case WriteEngine::WR_FLOAT: - valArray = (float*) calloc(sizeof(float), 1); - break; - - case WriteEngine::WR_DOUBLE: - valArray = (double*) calloc(sizeof(double), 1); - break; - - case WriteEngine::WR_BYTE: - valArray = (char*) calloc(sizeof(char), 1); - break; - - case WriteEngine::WR_UBYTE: - valArray = (uint8_t*) calloc(sizeof(uint8_t), 1); - break; - - case WriteEngine::WR_SHORT: - valArray = (short*) calloc(sizeof(short), 1); - break; - - case WriteEngine::WR_USHORT: - valArray = (uint16_t*) calloc(sizeof(uint16_t), 1); - break; - - case WriteEngine::WR_LONGLONG: - valArray = (long long*) calloc(sizeof(long long), 1); - break; - - case WriteEngine::WR_ULONGLONG: - valArray = (uint64_t*) calloc(sizeof(uint64_t), 1); - break; - - case WriteEngine::WR_TOKEN: - valArray = (Token*) calloc(sizeof(Token), 1); - break; - - case WriteEngine::WR_BINARY: - //case WriteEngine::WR_INT128: - // WIP use column width here - // remove all C-casts from above - valArray = calloc(1, 16); - break; - - } + allocateValArray(valArray, 1, colStructs[i].colType, colStructs[i].colWidth); rc = colOp->writeRows(curCol, ridList.size(), ridList, valArray, 0, true); @@ -3270,8 +3277,6 @@ int WriteEngineWrapper::insertColumnRec_Single(const TxnID& txnid, printInputValue(colStructList, colValueList, ridList); } - // end - //Convert data type and column width to write engine specific for (i = 0; i < colStructList.size(); i++) Convertor::convertColType(&colStructList[i]); @@ -3299,7 +3304,7 @@ int WriteEngineWrapper::insertColumnRec_Single(const TxnID& txnid, //-------------------------------------------------------------------------- // allocate row id(s) //-------------------------------------------------------------------------- - curColStruct = colStructList[colId]; + curColStruct = colStructList[colId]; colOp = m_colOp[op(curColStruct.fCompressionType)]; colOp->initColumn(curCol); @@ -3336,7 +3341,7 @@ int WriteEngineWrapper::insertColumnRec_Single(const TxnID& txnid, oldHwm = hwm; //Save this info for rollback //need to pass real dbRoot, partition, and segment to setColParam - colOp->setColParam(curCol, colId, curColStruct.colWidth, curColStruct.colDataType, + colOp->setColParam(curCol, colId, curColStruct.colWidth, curColStruct.colDataType, curColStruct.colType, curColStruct.dataOid, curColStruct.fCompressionType, dbRoot, partitionNum, segmentNum); @@ -3455,12 +3460,12 @@ int WriteEngineWrapper::insertColumnRec_Single(const TxnID& txnid, // if totalRow == rowsLeft, then not adding rows to 1st extent, so skip it. //-------------------------------------------------------------------------- // DMC-SHARED_NOTHING_NOTE: Is it safe to assume only part0 seg0 is abbreviated? - if ((colStructList[colId].fColPartition == 0) && - (colStructList[colId].fColSegment == 0) && - ((totalRow - rowsLeft) > 0) && - (rowIdArray[totalRow - rowsLeft - 1] >= (RID)INITIAL_EXTENT_ROWS_TO_DISK)) + if ((colStructList[colId].fColPartition == 0) && + (colStructList[colId].fColSegment == 0) && + ((totalRow - rowsLeft) > 0) && + (rowIdArray[totalRow - rowsLeft - 1] >= (RID)INITIAL_EXTENT_ROWS_TO_DISK)) { - for (unsigned k=0; kcalculateRowId(lastRid, BYTE_PER_BLOCK / colWidth, colWidth, curFbo, curBio); - //cout << "insertcolumnrec oid:rid:fbo:hwm = " << - //colStructList[i].dataOid << ":" << lastRid << ":" << - //curFbo << ":" << hwm << endl; if (succFlag) { if ((HWM)curFbo > oldHwm) @@ -3811,7 +3812,6 @@ int WriteEngineWrapper::insertColumnRec_Single(const TxnID& txnid, } } - //cout << "lbids size = " << lbids.size()<< endl; if (lbids.size() > 0) rc = BRMWrapper::getInstance()->markExtentsInvalid(lbids, colDataTypes); @@ -4516,68 +4516,7 @@ int WriteEngineWrapper::writeColumnRecords(const TxnID& txnid, break; } - switch (curColStruct.colType) - { - case WriteEngine::WR_INT: - case WriteEngine::WR_MEDINT: - valArray = (int*) calloc(sizeof(int), totalRow); - break; - - case WriteEngine::WR_UINT: - case WriteEngine::WR_UMEDINT: - valArray = (uint32_t*) calloc(sizeof(uint32_t), totalRow); - break; - - case WriteEngine::WR_VARBINARY : // treat same as char for now - case WriteEngine::WR_CHAR: - case WriteEngine::WR_BLOB: - case WriteEngine::WR_TEXT: - valArray = (char*) calloc(sizeof(char), totalRow * MAX_COLUMN_BOUNDARY); - break; - - case WriteEngine::WR_FLOAT: - valArray = (float*) calloc(sizeof(float), totalRow); - break; - - case WriteEngine::WR_DOUBLE: - valArray = (double*) calloc(sizeof(double), totalRow); - break; - - case WriteEngine::WR_BYTE: - valArray = (char*) calloc(sizeof(char), totalRow); - break; - - case WriteEngine::WR_UBYTE: - valArray = (uint8_t*) calloc(sizeof(uint8_t), totalRow); - break; - - case WriteEngine::WR_SHORT: - valArray = (short*) calloc(sizeof(short), totalRow); - break; - - case WriteEngine::WR_USHORT: - valArray = (uint16_t*) calloc(sizeof(uint16_t), totalRow); - break; - - case WriteEngine::WR_LONGLONG: - valArray = (long long*) calloc(sizeof(long long), totalRow); - break; - - case WriteEngine::WR_ULONGLONG: - valArray = (uint64_t*) calloc(sizeof(uint64_t), totalRow); - break; - - case WriteEngine::WR_TOKEN: - valArray = (Token*) calloc(sizeof(Token), totalRow); - break; - - // WIP MCOL-641 - case WriteEngine::WR_BINARY: - // Use column width and remove all C-casts from above - valArray = calloc(totalRow, curColType.colWidth); - break; - - } + allocateValArray(valArray, totalRow, curColStruct.colType, curColStruct.colWidth); // convert values to valArray bExcp = false; @@ -4679,16 +4618,11 @@ int WriteEngineWrapper::writeColumnRec(const TxnID& txnid, StopWatch timer; #endif + totalRow1 = colValueList[0].size(); + totalRow2 = 0; + if (newColValueList.size() > 0) - { - totalRow1 = colValueList[0].size(); totalRow2 = newColValueList[0].size(); - } - else - { - totalRow1 = colValueList[0].size(); - totalRow2 = 0; - } TableMetaData* aTbaleMetaData = TableMetaData::makeTableMetaData(tableOid); @@ -4763,74 +4697,10 @@ int WriteEngineWrapper::writeColumnRec(const TxnID& txnid, // WIP We can allocate based on column size and not colType // have to init the size here - valArray = calloc(totalRow1, colStructList[i].colWidth); -#if 0 - switch (colStructList[i].colType) - { - // WIP we don't need type cast here only size - case WriteEngine::WR_INT: - case WriteEngine::WR_MEDINT: - valArray = (int*) calloc(sizeof(int), totalRow1); - break; - - case WriteEngine::WR_UINT: - case WriteEngine::WR_UMEDINT: - valArray = (uint32_t*) calloc(sizeof(uint32_t), totalRow1); - break; - - case WriteEngine::WR_VARBINARY : // treat same as char for now - case WriteEngine::WR_CHAR: - case WriteEngine::WR_BLOB: - case WriteEngine::WR_TEXT: - valArray = (char*) calloc(sizeof(char), totalRow1 * MAX_COLUMN_BOUNDARY); - break; - - case WriteEngine::WR_FLOAT: - valArray = (float*) calloc(sizeof(float), totalRow1); - break; - - case WriteEngine::WR_DOUBLE: - valArray = (double*) calloc(sizeof(double), totalRow1); - break; - - case WriteEngine::WR_BYTE: - valArray = (char*) calloc(sizeof(char), totalRow1); - break; - - case WriteEngine::WR_UBYTE: - valArray = (uint8_t*) calloc(sizeof(uint8_t), totalRow1); - break; - - case WriteEngine::WR_SHORT: - valArray = (short*) calloc(sizeof(short), totalRow1); - break; - - case WriteEngine::WR_USHORT: - valArray = (uint16_t*) calloc(sizeof(uint16_t), totalRow1); - break; - - case WriteEngine::WR_LONGLONG: - valArray = (long long*) calloc(sizeof(long long), totalRow1); - break; - - case WriteEngine::WR_ULONGLONG: - valArray = (uint64_t*) calloc(sizeof(uint64_t), totalRow1); - break; - - case WriteEngine::WR_TOKEN: - valArray = (Token*) calloc(sizeof(Token), totalRow1); - break; - - // WIP - case WriteEngine::WR_BINARY: - valArray = calloc(totalRow1, colStructList[i].colWidth); - break; - } -#endif + allocateValArray(valArray, totalRow1, colStructList[i].colType, colStructList[i].colWidth); // convert values to valArray - // WIP - // Is this m_opType ever set to DELETE? + // WIP Is m_opType ever set to DELETE? if (m_opType != DELETE) { bExcp = false; @@ -4857,7 +4727,7 @@ int WriteEngineWrapper::writeColumnRec(const TxnID& txnid, } #ifdef PROFILE - iimer.start("writeRow "); + timer.start("writeRow "); #endif rc = colOp->writeRow(curCol, totalRow1, firstPart, valArray); #ifdef PROFILE @@ -4950,71 +4820,7 @@ int WriteEngineWrapper::writeColumnRec(const TxnID& txnid, } } - // have to init the size here - // TODO MCOL-641 is commenting out the switch statement below correct? - valArray = calloc(totalRow2, newColStructList[i].colWidth); - /*switch (newColStructList[i].colType) - { - case WriteEngine::WR_INT: - case WriteEngine::WR_MEDINT: - valArray = (int*) calloc(sizeof(int), totalRow2); - break; - - case WriteEngine::WR_UINT: - case WriteEngine::WR_UMEDINT: - valArray = (uint32_t*) calloc(sizeof(uint32_t), totalRow2); - break; - - case WriteEngine::WR_VARBINARY : // treat same as char for now - case WriteEngine::WR_CHAR: - case WriteEngine::WR_BLOB: - case WriteEngine::WR_TEXT: - valArray = (char*) calloc(sizeof(char), totalRow2 * MAX_COLUMN_BOUNDARY); - break; - - case WriteEngine::WR_FLOAT: - valArray = (float*) calloc(sizeof(float), totalRow2); - break; - - case WriteEngine::WR_DOUBLE: - valArray = (double*) calloc(sizeof(double), totalRow2); - break; - - case WriteEngine::WR_BYTE: - valArray = (char*) calloc(sizeof(char), totalRow2); - break; - - case WriteEngine::WR_UBYTE: - valArray = (uint8_t*) calloc(sizeof(uint8_t), totalRow2); - break; - - case WriteEngine::WR_SHORT: - valArray = (short*) calloc(sizeof(short), totalRow2); - break; - - case WriteEngine::WR_USHORT: - valArray = (uint16_t*) calloc(sizeof(uint16_t), totalRow2); - break; - - case WriteEngine::WR_LONGLONG: - valArray = (long long*) calloc(sizeof(long long), totalRow2); - break; - - case WriteEngine::WR_ULONGLONG: - valArray = (uint64_t*) calloc(sizeof(uint64_t), totalRow2); - break; - - case WriteEngine::WR_TOKEN: - valArray = (Token*) calloc(sizeof(Token), totalRow2); - break; - - case WriteEngine::WR_BINARY: - //case WriteEngine::WR_INT128: - // WIP - valArray = calloc(totalRow2, 16); - break; - - }*/ + allocateValArray(valArray, totalRow2, newColStructList[i].colType, newColStructList[i].colWidth); // convert values to valArray if (m_opType != DELETE) @@ -5131,71 +4937,7 @@ int WriteEngineWrapper::writeColumnRec(const TxnID& txnid, } } - // have to init the size here - // shared pointers or memory in a stack - // TODO MCOL-641 is commenting out the switch statement below correct? - valArray = calloc(totalRow1, colStructList[i].colWidth); - // WIP - /*switch (colStructList[i].colType) - { - case WriteEngine::WR_INT: - case WriteEngine::WR_MEDINT: - valArray = (int*) calloc(sizeof(int), totalRow1); - break; - - case WriteEngine::WR_UINT: - case WriteEngine::WR_UMEDINT: - valArray = (uint32_t*) calloc(sizeof(uint32_t), totalRow1); - break; - - case WriteEngine::WR_VARBINARY : // treat same as char for now - case WriteEngine::WR_CHAR: - case WriteEngine::WR_BLOB: - case WriteEngine::WR_TEXT: - valArray = (char*) calloc(sizeof(char), totalRow1 * MAX_COLUMN_BOUNDARY); - break; - - case WriteEngine::WR_FLOAT: - valArray = (float*) calloc(sizeof(float), totalRow1); - break; - - case WriteEngine::WR_DOUBLE: - valArray = (double*) calloc(sizeof(double), totalRow1); - break; - - case WriteEngine::WR_BYTE: - valArray = (char*) calloc(sizeof(char), totalRow1); - break; - - case WriteEngine::WR_UBYTE: - valArray = (uint8_t*) calloc(sizeof(uint8_t), totalRow1); - break; - - case WriteEngine::WR_SHORT: - valArray = (short*) calloc(sizeof(short), totalRow1); - break; - - case WriteEngine::WR_USHORT: - valArray = (uint16_t*) calloc(sizeof(uint16_t), totalRow1); - break; - - case WriteEngine::WR_LONGLONG: - valArray = (long long*) calloc(sizeof(long long), totalRow1); - break; - - case WriteEngine::WR_ULONGLONG: - valArray = (uint64_t*) calloc(sizeof(uint64_t), totalRow1); - break; - - case WriteEngine::WR_TOKEN: - valArray = (Token*) calloc(sizeof(Token), totalRow1); - break; - - case WriteEngine::WR_BINARY: - //case WriteEngine::WR_INT128: - valArray = calloc(colStructList[i].colWidth, totalRow1); - break; - }*/ + allocateValArray(valArray, totalRow1, colStructList[i].colType, colStructList[i].colWidth); // convert values to valArray if (m_opType != DELETE) @@ -5415,9 +5157,8 @@ int WriteEngineWrapper::writeColumnRecBinary(const TxnID& txnid, ((uint16_t*)valArray)[j] = tmp16; break; - case WriteEngine::WR_BINARY: // WIP - //case WriteEngine::WR_INT128: + case WriteEngine::WR_BINARY: ((uint64_t*)valArray)[j] = curValue; //FIXME maybe break; @@ -5565,9 +5306,8 @@ int WriteEngineWrapper::writeColumnRecBinary(const TxnID& txnid, ((uint16_t*)valArray)[j] = tmp16; break; - case WriteEngine::WR_BINARY: // WIP - //case WriteEngine::WR_INT128: + case WriteEngine::WR_BINARY: ((uint64_t*)valArray)[j] = curValue; // FIXME maybe break; } @@ -5786,64 +5526,7 @@ int WriteEngineWrapper::writeColumnRec(const TxnID& txnid, break; } - switch (curColStruct.colType) - { - case WriteEngine::WR_INT: - case WriteEngine::WR_MEDINT: - valArray = (int*) calloc(sizeof(int), 1); - break; - - case WriteEngine::WR_UINT: - case WriteEngine::WR_UMEDINT: - valArray = (uint32_t*) calloc(sizeof(uint32_t), 1); - break; - - case WriteEngine::WR_VARBINARY : // treat same as char for now - case WriteEngine::WR_CHAR: - case WriteEngine::WR_BLOB: - case WriteEngine::WR_TEXT: - valArray = (char*) calloc(sizeof(char), 1 * MAX_COLUMN_BOUNDARY); - break; - - case WriteEngine::WR_FLOAT: - valArray = (float*) calloc(sizeof(float), 1); - break; - - case WriteEngine::WR_DOUBLE: - valArray = (double*) calloc(sizeof(double), 1); - break; - - case WriteEngine::WR_BYTE: - valArray = (char*) calloc(sizeof(char), 1); - break; - - case WriteEngine::WR_UBYTE: - valArray = (uint8_t*) calloc(sizeof(uint8_t), 1); - break; - - case WriteEngine::WR_SHORT: - valArray = (short*) calloc(sizeof(short), 1); - break; - - case WriteEngine::WR_USHORT: - valArray = (uint16_t*) calloc(sizeof(uint16_t), 1); - break; - - case WriteEngine::WR_LONGLONG: - valArray = (long long*) calloc(sizeof(long long), 1); - break; - - case WriteEngine::WR_ULONGLONG: - valArray = (uint64_t*) calloc(sizeof(uint64_t), 1); - break; - - case WriteEngine::WR_TOKEN: - valArray = (Token*) calloc(sizeof(Token), 1); - break; - case WriteEngine::WR_BINARY: - valArray = calloc(1, curColStruct.colWidth); - break; - } + allocateValArray(valArray, 1, curColStruct.colType, curColStruct.colWidth); // convert values to valArray if (m_opType != DELETE)