mirror of
https://github.com/mariadb-corporation/mariadb-columnstore-engine.git
synced 2025-06-10 17:41:44 +03:00
Implement SPACE() and QUOTE() functions.
This commit is contained in:
parent
a9717ad49d
commit
feaa9cb659
@ -71,6 +71,7 @@ set(funcexp_LIB_SRCS
|
||||
func_pow.cpp
|
||||
func_period_add.cpp
|
||||
func_period_diff.cpp
|
||||
func_quote.cpp
|
||||
func_quarter.cpp
|
||||
func_rand.cpp
|
||||
func_regexp.cpp
|
||||
@ -85,6 +86,7 @@ set(funcexp_LIB_SRCS
|
||||
func_sec_to_time.cpp
|
||||
func_sha.cpp
|
||||
func_sign.cpp
|
||||
func_space.cpp
|
||||
func_str_to_date.cpp
|
||||
func_strcmp.cpp
|
||||
func_substr.cpp
|
||||
|
88
utils/funcexp/func_quote.cpp
Normal file
88
utils/funcexp/func_quote.cpp
Normal file
@ -0,0 +1,88 @@
|
||||
/* Copyright (C) 2019 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 <string>
|
||||
using namespace std;
|
||||
|
||||
#include "functor_str.h"
|
||||
using namespace execplan;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
namespace funcexp
|
||||
{
|
||||
|
||||
CalpontSystemCatalog::ColType Func_quote::operationType(FunctionParm& fp, CalpontSystemCatalog::ColType& resultType)
|
||||
{
|
||||
return resultType;
|
||||
}
|
||||
|
||||
std::string Func_quote::getStrVal(rowgroup::Row& row,
|
||||
FunctionParm& fp,
|
||||
bool& isNull,
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct)
|
||||
{
|
||||
string str;
|
||||
|
||||
stringValue(fp[0], row, isNull, str);
|
||||
|
||||
if (isNull)
|
||||
{
|
||||
isNull = false;
|
||||
return "NULL";
|
||||
}
|
||||
|
||||
if (str.empty())
|
||||
return "NULL";
|
||||
|
||||
string result;
|
||||
result.reserve((str.size() * 1.3) + 2);
|
||||
|
||||
result.push_back('\'');
|
||||
|
||||
for (uint64_t i = 0; i < str.size(); i++)
|
||||
{
|
||||
switch(str[i])
|
||||
{
|
||||
case 0:
|
||||
result.push_back('\\');
|
||||
result.push_back('0');
|
||||
break;
|
||||
case '\032':
|
||||
result.push_back('\\');
|
||||
result.push_back('Z');
|
||||
break;
|
||||
case '\'':
|
||||
case '\\':
|
||||
result.push_back('\\');
|
||||
result.push_back(str[i]);
|
||||
break;
|
||||
default:
|
||||
result.push_back(str[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
result.push_back('\'');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace funcexp
|
||||
// vim:ts=4 sw=4:
|
||||
|
66
utils/funcexp/func_space.cpp
Normal file
66
utils/funcexp/func_space.cpp
Normal file
@ -0,0 +1,66 @@
|
||||
/* Copyright (C) 2019 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 <string>
|
||||
using namespace std;
|
||||
|
||||
#include "functor_str.h"
|
||||
using namespace execplan;
|
||||
|
||||
#include "rowgroup.h"
|
||||
using namespace rowgroup;
|
||||
|
||||
namespace funcexp
|
||||
{
|
||||
|
||||
CalpontSystemCatalog::ColType Func_space::operationType(FunctionParm& fp, CalpontSystemCatalog::ColType& resultType)
|
||||
{
|
||||
return resultType;
|
||||
}
|
||||
|
||||
std::string Func_space::getStrVal(rowgroup::Row& row,
|
||||
FunctionParm& fp,
|
||||
bool& isNull,
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct)
|
||||
{
|
||||
|
||||
CalpontSystemCatalog::ColDataType ct = fp[0]->data()->resultType().colDataType;
|
||||
|
||||
// Int representation of temporal types can be a very large value,
|
||||
// so exit early if this is the case
|
||||
if (ct == CalpontSystemCatalog::DATE ||
|
||||
ct == CalpontSystemCatalog::DATETIME ||
|
||||
ct == CalpontSystemCatalog::TIMESTAMP ||
|
||||
ct == CalpontSystemCatalog::TIME)
|
||||
{
|
||||
isNull = true;
|
||||
return "";
|
||||
}
|
||||
|
||||
int64_t count = fp[0]->data()->getIntVal(row, isNull);
|
||||
|
||||
if (isNull || count < 1)
|
||||
return "";
|
||||
|
||||
string result(count, ' ');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace funcexp
|
||||
// vim:ts=4 sw=4:
|
||||
|
@ -175,6 +175,7 @@ FuncExp::FuncExp()
|
||||
fFuncMap["position"] = new Func_instr(); //dlh
|
||||
fFuncMap["pow"] = new Func_pow();
|
||||
fFuncMap["power"] = new Func_pow();
|
||||
fFuncMap["quote"] = new Func_quote();
|
||||
fFuncMap["quarter"] = new Func_quarter();
|
||||
fFuncMap["radians"] = new Func_radians(); //dlh
|
||||
fFuncMap["rand"] = new Func_rand();
|
||||
@ -192,6 +193,7 @@ FuncExp::FuncExp()
|
||||
fFuncMap["sha1"] = new Func_sha();
|
||||
fFuncMap["sign"] = new Func_sign();
|
||||
fFuncMap["sin"] = new Func_sin();
|
||||
fFuncMap["space"] = new Func_space();
|
||||
fFuncMap["sqrt"] = new Func_sqrt();
|
||||
fFuncMap["str_to_date"] = new Func_str_to_date();
|
||||
fFuncMap["strcmp"] = new Func_strcmp();
|
||||
|
@ -848,6 +848,40 @@ public:
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct);
|
||||
};
|
||||
|
||||
|
||||
/** @brief Func_space class
|
||||
*/
|
||||
class Func_space : public Func_Str
|
||||
{
|
||||
public:
|
||||
Func_space() : Func_Str("space") {}
|
||||
virtual ~Func_space() {}
|
||||
|
||||
execplan::CalpontSystemCatalog::ColType operationType(FunctionParm& fp, execplan::CalpontSystemCatalog::ColType& resultType);
|
||||
|
||||
std::string getStrVal(rowgroup::Row& row,
|
||||
FunctionParm& fp,
|
||||
bool& isNull,
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct);
|
||||
};
|
||||
|
||||
|
||||
/** @brief Func_quote class
|
||||
*/
|
||||
class Func_quote : public Func_Str
|
||||
{
|
||||
public:
|
||||
Func_quote() : Func_Str("quote") {}
|
||||
virtual ~Func_quote() {}
|
||||
|
||||
execplan::CalpontSystemCatalog::ColType operationType(FunctionParm& fp, execplan::CalpontSystemCatalog::ColType& resultType);
|
||||
|
||||
std::string getStrVal(rowgroup::Row& row,
|
||||
FunctionParm& fp,
|
||||
bool& isNull,
|
||||
execplan::CalpontSystemCatalog::ColType& op_ct);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user