1
0
mirror of https://github.com/mariadb-corporation/mariadb-columnstore-engine.git synced 2025-07-30 19:23:07 +03:00

MCOL-2182 Change in MariaDB 10.3 allows for only 2 parameters to lpad and rpad

This commit is contained in:
David Hall
2019-03-08 15:14:42 -06:00
parent 26e61546bd
commit c3f8148fff
3 changed files with 48 additions and 10 deletions

View File

@ -20,7 +20,7 @@
* *
* *
****************************************************************************/ ****************************************************************************/
#include "errorids.h"
#include <string> #include <string>
using namespace std; using namespace std;
@ -39,6 +39,9 @@ using namespace joblist;
namespace funcexp namespace funcexp
{ {
const string Func_lpad::fPad = " ";
CalpontSystemCatalog::ColType Func_lpad::operationType(FunctionParm& fp, CalpontSystemCatalog::ColType& resultType) CalpontSystemCatalog::ColType Func_lpad::operationType(FunctionParm& fp, CalpontSystemCatalog::ColType& resultType)
{ {
// operation type is not used by this functor // operation type is not used by this functor
@ -114,17 +117,33 @@ std::string Func_lpad::getStrVal(rowgroup::Row& row,
} }
break; break;
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::VARCHAR:
{
const string& strval = fp[1]->data()->getStrVal(row, isNull);
len = strtol(strval.c_str(), NULL, 10);
break;
}
default: default:
{ {
len = fp[1]->data()->getIntVal(row, isNull); std::ostringstream oss;
oss << "lpad parameter 2 must be numeric, not " << execplan::colDataTypeToString(fp[1]->data()->resultType().colDataType);
throw logging::IDBExcept(oss.str(), logging::ERR_DATATYPE_NOT_SUPPORT);
} }
} }
if (len < 1) if (len < 1)
return ""; return "";
// MCOL-2182 As of MariaDB 10.3 the third parameter - pad characters - is optional
// The pad characters. // The pad characters.
const string& pad = fp[2]->data()->getStrVal(row, isNull); const string* pad = &fPad;
if (fp.size() > 2)
{
pad = &fp[2]->data()->getStrVal(row, isNull);
}
if (isNull) if (isNull)
return ""; return "";
@ -172,11 +191,11 @@ std::string Func_lpad::getStrVal(rowgroup::Row& row,
// This is the case where there's room to pad. // This is the case where there's room to pad.
// Convert the pad string to wide // Convert the pad string to wide
padwclen = pad.length(); // A guess to start. padwclen = pad->length(); // A guess to start.
size_t padbufsize = (padwclen + 1) * sizeof(wchar_t); size_t padbufsize = (padwclen + 1) * sizeof(wchar_t);
wchar_t* wcpad = (wchar_t*)alloca(padbufsize); wchar_t* wcpad = (wchar_t*)alloca(padbufsize);
// padwclen+1 is for giving count for the terminating null // padwclen+1 is for giving count for the terminating null
size_t padlen = utf8::idb_mbstowcs(wcpad, pad.c_str(), padwclen + 1); size_t padlen = utf8::idb_mbstowcs(wcpad, pad->c_str(), padwclen + 1);
// How many chars do we need? // How many chars do we need?
size_t padspace = len - strSize; size_t padspace = len - strSize;

View File

@ -20,7 +20,7 @@
* *
* *
****************************************************************************/ ****************************************************************************/
#include "errorids.h"
#include <string> #include <string>
using namespace std; using namespace std;
@ -39,6 +39,8 @@ using namespace joblist;
namespace funcexp namespace funcexp
{ {
const string Func_rpad::fPad = " ";
CalpontSystemCatalog::ColType Func_rpad::operationType(FunctionParm& fp, CalpontSystemCatalog::ColType& resultType) CalpontSystemCatalog::ColType Func_rpad::operationType(FunctionParm& fp, CalpontSystemCatalog::ColType& resultType)
{ {
// operation type is not used by this functor // operation type is not used by this functor
@ -114,9 +116,19 @@ std::string Func_rpad::getStrVal(rowgroup::Row& row,
} }
break; break;
case execplan::CalpontSystemCatalog::CHAR:
case execplan::CalpontSystemCatalog::VARCHAR:
{
const string& strval = fp[1]->data()->getStrVal(row, isNull);
len = strtol(strval.c_str(), NULL, 10);
break;
}
default: default:
{ {
len = fp[1]->data()->getIntVal(row, isNull); std::ostringstream oss;
oss << "lpad parameter 2 must be numeric, not " << execplan::colDataTypeToString(fp[1]->data()->resultType().colDataType);
throw logging::IDBExcept(oss.str(), logging::ERR_DATATYPE_NOT_SUPPORT);
} }
} }
@ -124,7 +136,12 @@ std::string Func_rpad::getStrVal(rowgroup::Row& row,
return ""; return "";
// The pad characters. // The pad characters.
const string& pad = fp[2]->data()->getStrVal(row, isNull); // MCOL-2182 As of MariaDB 10.3 the third parameter - pad characters - is optional
const string* pad = &fPad;
if (fp.size() > 2)
{
pad = &fp[2]->data()->getStrVal(row, isNull);
}
if (isNull) if (isNull)
return ""; return "";
@ -172,10 +189,10 @@ std::string Func_rpad::getStrVal(rowgroup::Row& row,
// This is the case where there's room to pad. // This is the case where there's room to pad.
// Convert the pad string to wide // Convert the pad string to wide
padwclen = pad.length(); // A guess to start. padwclen = pad->length(); // A guess to start.
int padbufsize = (padwclen + 1) * sizeof(wchar_t); int padbufsize = (padwclen + 1) * sizeof(wchar_t);
wchar_t* wcpad = (wchar_t*)alloca(padbufsize); wchar_t* wcpad = (wchar_t*)alloca(padbufsize);
size_t padlen = utf8::idb_mbstowcs(wcpad, pad.c_str(), padwclen + 1); size_t padlen = utf8::idb_mbstowcs(wcpad, pad->c_str(), padwclen + 1);
// How many chars do we need? // How many chars do we need?
unsigned int padspace = len - strSize; unsigned int padspace = len - strSize;

View File

@ -325,6 +325,7 @@ public:
*/ */
class Func_lpad : public Func_Str class Func_lpad : public Func_Str
{ {
static const string fPad;
public: public:
Func_lpad() : Func_Str("lpad") {} Func_lpad() : Func_Str("lpad") {}
virtual ~Func_lpad() {} virtual ~Func_lpad() {}
@ -342,6 +343,7 @@ public:
*/ */
class Func_rpad : public Func_Str class Func_rpad : public Func_Str
{ {
static const string fPad;
public: public:
Func_rpad() : Func_Str("rpad") {} Func_rpad() : Func_Str("rpad") {}
virtual ~Func_rpad() {} virtual ~Func_rpad() {}