1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-08-10 01:22:48 +03:00
Files
mariadb-columnstore-engine/utils/funcexp/func_crc32.cpp
Marko Mäkelä 7158253b88 MDEV-27519 CRC32() upon Columnstore table returns a wrong value
Func_crc32::getIntVal(): Support the 2-ary CRC32() variant (MDEV-27208).
Also, do not assume that the string contains no NUL bytes.
2022-01-18 08:42:21 +00:00

75 lines
2.0 KiB
C++

/* Copyright (C) 2014 InfiniDB, Inc.
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. */
/****************************************************************************
* $Id: func_crc32.cpp 3923 2013-06-19 21:43:06Z bwilkinson $
*
*
****************************************************************************/
#include <unistd.h>
#include <cstdlib>
#include <string>
#include <sstream>
using namespace std;
#include "functor_int.h"
#include "functioncolumn.h"
#include "rowgroup.h"
using namespace execplan;
#ifndef _MSC_VER
#include "zlib.h"
#endif
namespace funcexp
{
CalpontSystemCatalog::ColType Func_crc32::operationType( FunctionParm& fp, CalpontSystemCatalog::ColType& resultType )
{
return resultType;
}
int64_t Func_crc32::getIntVal(rowgroup::Row& row,
FunctionParm& parm,
bool& isNull,
CalpontSystemCatalog::ColType& ct)
{
unsigned crc;
switch (parm.size) {
default:
isNull = true;
return 0;
case 1:
crc = 0;
break;
case 2:
crc = static_cast<unsigned>(parm[0]->data()->getIntVal(row, isNull));
if (isNull)
return 0;
}
const string& b = parm[parm.size - 1]->data()->getStrVal(row, isNull);
if (isNull)
return 0;
return crc32(crc, reinterpret_cast<unsigned char*>(b.data()), b.size());
}
} // namespace funcexp
// vim:ts=4 sw=4: