You've already forked mariadb-columnstore-engine
mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-07-29 08:21:15 +03:00
MCOL-4412 Introduce TypeHandler::getEmptyValueForType to return const ptr for an empty value
WE changes for SQL DML and DDL operations Changes for bulk operations Changes for scanning operations Cleanup
This commit is contained in:
@ -25,6 +25,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "joblisttypes.h"
|
||||
#include "mcs_datatype.h"
|
||||
|
||||
#include "we_blockop.h"
|
||||
|
||||
@ -34,15 +35,13 @@
|
||||
|
||||
using namespace execplan;
|
||||
|
||||
#include "emptyvaluemanip.h"
|
||||
|
||||
namespace WriteEngine
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
BlockOp::BlockOp()
|
||||
BlockOp::BlockOp(): m_typeHandler(nullptr)
|
||||
{}
|
||||
|
||||
/**
|
||||
@ -84,11 +83,20 @@ bool BlockOp::calculateRowId(
|
||||
* RETURN:
|
||||
* emptyVal - the value of empty row
|
||||
***********************************************************/
|
||||
// TODO MCOL-641 Add support here
|
||||
void BlockOp::getEmptyRowValue(
|
||||
const CalpontSystemCatalog::ColDataType colDataType, const int width, uint8_t* emptyVal ) const
|
||||
const uint8_t* BlockOp::getEmptyRowValue(
|
||||
const CalpontSystemCatalog::ColDataType colDataType,
|
||||
const int width) const
|
||||
{
|
||||
utils::getEmptyRowValue(colDataType, width, emptyVal);
|
||||
auto attrs = datatypes::SystemCatalog::TypeAttributesStd(width, 0, -1);
|
||||
// Bulk operation runtime should have m_typeHandler nullptr calling this
|
||||
// Non-bulk operations runtime branch
|
||||
if (m_typeHandler)
|
||||
return m_typeHandler->getEmptyValueForType(attrs);
|
||||
|
||||
// Bulk operation branch
|
||||
auto* typeHandler = datatypes::TypeHandler::find(colDataType,
|
||||
attrs);
|
||||
return typeHandler->getEmptyValueForType(attrs);
|
||||
}
|
||||
|
||||
/***********************************************************
|
||||
@ -166,7 +174,10 @@ void BlockOp::resetBuf( unsigned char* buf, const int bufSize ) const
|
||||
***********************************************************/
|
||||
/* static */
|
||||
void BlockOp::setEmptyBuf(
|
||||
unsigned char* buf, const int bufSize, uint8_t* emptyVal, const int width )
|
||||
unsigned char* buf,
|
||||
const int bufSize,
|
||||
const uint8_t* emptyVal,
|
||||
const int width )
|
||||
{
|
||||
const int ARRAY_COUNT = 128;
|
||||
const int NBYTES_IN_ARRAY = width * ARRAY_COUNT;
|
||||
@ -214,7 +225,7 @@ void BlockOp::setEmptyBuf(
|
||||
* none
|
||||
***********************************************************/
|
||||
void BlockOp::writeBufValue(
|
||||
unsigned char* buf, void* val, const size_t width, const bool clear ) const
|
||||
unsigned char* buf, const void* val, const size_t width, const bool clear ) const
|
||||
{
|
||||
if ( clear )
|
||||
memset( buf, 0, width );
|
||||
@ -222,5 +233,16 @@ void BlockOp::writeBufValue(
|
||||
memcpy( buf, val, width );
|
||||
}
|
||||
|
||||
void BlockOp::findTypeHandler(const int colWidth,
|
||||
const execplan::CalpontSystemCatalog::ColDataType colDataType)
|
||||
|
||||
{
|
||||
auto attrs = datatypes::SystemCatalog::TypeAttributesStd(colWidth,
|
||||
0,
|
||||
-1);
|
||||
m_typeHandler = datatypes::TypeHandler::find(colDataType,
|
||||
attrs);
|
||||
}
|
||||
|
||||
} //end of namespace
|
||||
|
||||
|
@ -89,9 +89,9 @@ public:
|
||||
/**
|
||||
* @brief Get an empty row value
|
||||
*/
|
||||
EXPORT void getEmptyRowValue(const execplan::CalpontSystemCatalog::ColDataType colDataType,
|
||||
const int width,
|
||||
uint8_t* emptyVal ) const;
|
||||
EXPORT const uint8_t* getEmptyRowValue(const execplan::CalpontSystemCatalog::ColDataType colDataType,
|
||||
const int width) const;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Calculate row id
|
||||
@ -117,17 +117,23 @@ public:
|
||||
*/
|
||||
EXPORT void static setEmptyBuf( unsigned char* buf,
|
||||
const int bufSize,
|
||||
uint8_t* emptyVal, const int width );
|
||||
const uint8_t* emptyVal,
|
||||
const int width );
|
||||
|
||||
/**
|
||||
* @brief Set a value in a buffer
|
||||
*/
|
||||
EXPORT void writeBufValue( unsigned char* buf,
|
||||
void* val,
|
||||
const void* val,
|
||||
const size_t width,
|
||||
const bool clear = false ) const;
|
||||
EXPORT void findTypeHandler( const int colWidth,
|
||||
const execplan::CalpontSystemCatalog::ColDataType colDataType);
|
||||
private:
|
||||
const datatypes::TypeHandler* m_typeHandler;
|
||||
};
|
||||
|
||||
|
||||
} //end of namespace
|
||||
|
||||
#undef EXPORT
|
||||
|
@ -306,8 +306,7 @@ void BulkRollbackFile::reInitTruncColumnExtent(
|
||||
}
|
||||
|
||||
// Initialize the remainder of the extent after the HWM block
|
||||
uint8_t* emptyVal = (uint8_t*) alloca(colWidth);
|
||||
fDbFile.getEmptyRowValue( colType, colWidth, emptyVal );
|
||||
const uint8_t* emptyVal = fDbFile.getEmptyRowValue( colType, colWidth );
|
||||
|
||||
int rc = fDbFile.reInitPartialColumnExtent( pFile,
|
||||
startOffset,
|
||||
|
@ -374,8 +374,7 @@ void BulkRollbackFileCompressed::reInitTruncColumnExtent(
|
||||
|
||||
if (nBlocksToInit > 0)
|
||||
{
|
||||
uint8_t* emptyVal = (uint8_t*) alloca(colWidth);
|
||||
fDbFile.getEmptyRowValue( colType, colWidth, emptyVal );
|
||||
const uint8_t* emptyVal = fDbFile.getEmptyRowValue( colType, colWidth );
|
||||
rc = fDbFile.reInitPartialColumnExtent( pFile,
|
||||
(chunkPtrs[chunkIndex].first + restoredChunkLen),
|
||||
nBlocksToInit,
|
||||
|
@ -821,8 +821,8 @@ int ChunkManager::fetchChunkFromFile(IDBDataFile* pFile, int64_t id, ChunkData*&
|
||||
void ChunkManager::initializeColumnChunk(char* buf, CompFileData* fileData)
|
||||
{
|
||||
int size = UNCOMPRESSED_CHUNK_SIZE;
|
||||
uint8_t* emptyVal = (uint8_t*) alloca(fileData->fColWidth);
|
||||
fFileOp->getEmptyRowValue(fileData->fColDataType, fileData->fColWidth, emptyVal);
|
||||
const uint8_t* emptyVal = fFileOp->getEmptyRowValue(fileData->fColDataType,
|
||||
fileData->fColWidth);
|
||||
fFileOp->setEmptyBuf((unsigned char*)buf, size, emptyVal, fileData->fColWidth);
|
||||
}
|
||||
|
||||
@ -1343,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, uint8_t* emptyVal, int width)
|
||||
int ChunkManager::expandAbbrevColumnExtent(IDBDataFile* pFile, const uint8_t* emptyVal, int width)
|
||||
{
|
||||
map<IDBDataFile*, CompFileData*>::iterator i = fFilePtrMap.find(pFile);
|
||||
|
||||
|
@ -214,7 +214,7 @@ public:
|
||||
void cleanUp(const std::map<FID, FID>& columOids);
|
||||
|
||||
// @brief Expand an initial column, not dictionary, extent to a full extent.
|
||||
int expandAbbrevColumnExtent(IDBDataFile* pFile, uint8_t* emptyVal, int width);
|
||||
int expandAbbrevColumnExtent(IDBDataFile* pFile, const uint8_t* emptyVal, int width);
|
||||
|
||||
// @brief Update column extent
|
||||
int updateColumnExtent(IDBDataFile* pFile, int addBlockCount);
|
||||
|
@ -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,
|
||||
uint8_t* emptyVal, int width,
|
||||
const 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,
|
||||
uint8_t* emptyVal,
|
||||
const 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,
|
||||
uint8_t* emptyVal,
|
||||
const uint8_t* emptyVal,
|
||||
int width,
|
||||
HWM hwm,
|
||||
BRM::LBID_t startLbid,
|
||||
@ -875,7 +875,7 @@ int FileOp::extendFile(
|
||||
***********************************************************/
|
||||
int FileOp::addExtentExactFile(
|
||||
OID oid,
|
||||
uint8_t* emptyVal,
|
||||
const uint8_t* emptyVal,
|
||||
int width,
|
||||
int& allocSize,
|
||||
uint16_t dbRoot,
|
||||
@ -1045,7 +1045,7 @@ int FileOp::initColumnExtent(
|
||||
IDBDataFile* pFile,
|
||||
uint16_t dbRoot,
|
||||
int nBlocks,
|
||||
uint8_t* emptyVal,
|
||||
const uint8_t* emptyVal,
|
||||
int width,
|
||||
bool bNewFile,
|
||||
bool bExpandExtent,
|
||||
@ -1225,7 +1225,7 @@ int FileOp::initAbbrevCompColumnExtent(
|
||||
IDBDataFile* pFile,
|
||||
uint16_t dbRoot,
|
||||
int nBlocks,
|
||||
uint8_t* emptyVal,
|
||||
const 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,
|
||||
uint8_t* emptyVal,
|
||||
const uint8_t* emptyVal,
|
||||
int width,
|
||||
char* hdrs)
|
||||
{
|
||||
@ -1366,7 +1366,7 @@ int FileOp::writeInitialCompColumnChunk(
|
||||
***********************************************************/
|
||||
int FileOp::fillCompColumnExtentEmptyChunks(OID oid,
|
||||
int colWidth,
|
||||
uint8_t* emptyVal,
|
||||
const 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,
|
||||
uint8_t* emptyVal,
|
||||
const uint8_t* emptyVal,
|
||||
int colWidth,
|
||||
const CompChunkPtr& chunkInPtr,
|
||||
CompChunkPtr& chunkOutPtr )
|
||||
@ -2036,7 +2036,7 @@ int FileOp::reInitPartialColumnExtent(
|
||||
IDBDataFile* pFile,
|
||||
long long startOffset,
|
||||
int nBlocks,
|
||||
uint8_t* emptyVal,
|
||||
const 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
|
||||
uint8_t* emptyVal,// Empty value to be used in expanding the extent
|
||||
const 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
|
||||
|
@ -92,7 +92,7 @@ public:
|
||||
int& allocSize,
|
||||
uint16_t dbRoot, uint32_t partition,
|
||||
execplan::CalpontSystemCatalog::ColDataType colDataType,
|
||||
uint8_t* emptyVal, int width = 1 ) ;
|
||||
const uint8_t* emptyVal, int width = 1 ) ;
|
||||
|
||||
|
||||
/**
|
||||
@ -100,7 +100,7 @@ public:
|
||||
* Changed to public for UT.
|
||||
*/
|
||||
int createFile( const char* fileName, int fileSize,
|
||||
uint8_t* emptyVal, int width,
|
||||
const uint8_t* emptyVal, int width,
|
||||
uint16_t dbRoot );
|
||||
|
||||
/**
|
||||
@ -163,7 +163,7 @@ public:
|
||||
EXPORT virtual int expandAbbrevColumnExtent(
|
||||
IDBDataFile* pFile,
|
||||
uint16_t dbRoot,
|
||||
uint8_t* emptyVal,
|
||||
const 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, uint8_t* emptyVal,
|
||||
EXPORT int extendFile(OID oid, const 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, uint8_t* emptyVal,
|
||||
EXPORT int addExtentExactFile(OID oid, const uint8_t* emptyVal,
|
||||
int width,
|
||||
int& allocSize,
|
||||
uint16_t dbRoot,
|
||||
@ -253,7 +253,7 @@ public:
|
||||
*/
|
||||
EXPORT int fillCompColumnExtentEmptyChunks(OID oid,
|
||||
int colWidth,
|
||||
uint8_t* emptyVal,
|
||||
const 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,
|
||||
uint8_t* emptyVal,
|
||||
const uint8_t* emptyVal,
|
||||
int width );
|
||||
|
||||
/**
|
||||
@ -497,7 +497,7 @@ public:
|
||||
int initColumnExtent( IDBDataFile* pFile,
|
||||
uint16_t dbRoot,
|
||||
int nBlocks,
|
||||
uint8_t* emptyVal,
|
||||
const uint8_t* emptyVal,
|
||||
int width,
|
||||
bool bNewFile,
|
||||
bool bExpandExtent,
|
||||
@ -519,7 +519,7 @@ private:
|
||||
FileOp& operator=(const FileOp& rhs);
|
||||
|
||||
int expandAbbrevColumnChunk( IDBDataFile* pFile,
|
||||
uint8_t* emptyVal,
|
||||
const 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,
|
||||
uint8_t* emptyVal,
|
||||
const uint8_t* emptyVal,
|
||||
int width);
|
||||
|
||||
static void initDbRootExtentMutexes();
|
||||
@ -536,7 +536,7 @@ private:
|
||||
int writeInitialCompColumnChunk( IDBDataFile* pFile,
|
||||
int nBlocksAllocated,
|
||||
int nRows,
|
||||
uint8_t* emptyVal,
|
||||
const uint8_t* emptyVal,
|
||||
int width,
|
||||
char* hdrs);
|
||||
|
||||
|
@ -347,7 +347,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 */
|
||||
uint128_t emptyVal; /** @brief default empty value */
|
||||
const uint8_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 */
|
||||
@ -370,7 +370,7 @@ struct JobColumn /** @brief Job Column Structure */
|
||||
int128_t fDefaultWideDecimal; /** @brief Wide decimal column default */
|
||||
std::string fDefaultChr; /** @brief Char column default */
|
||||
JobColumn() : mapOid(0), dataType(execplan::CalpontSystemCatalog::INT), weType(WR_INT),
|
||||
typeName("integer"), emptyVal(0),
|
||||
typeName("integer"), emptyVal(nullptr),
|
||||
width(0), definedWidth(0), dctnryWidth(0),
|
||||
precision(0), scale(0), fNotNull(false),
|
||||
fFldColRelation(BULK_FLDCOL_COLUMN_FIELD), colType(' '),
|
||||
|
Reference in New Issue
Block a user