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

Enable unhex function and make minor implementation changes.

This commit is contained in:
Gagan Goel
2019-11-26 04:02:44 +00:00
parent 57724e5515
commit a5bfd484f4
2 changed files with 29 additions and 24 deletions

View File

@ -36,18 +36,25 @@ using namespace execplan;
namespace namespace
{ {
int64_t hex_to_int(char c) inline int hex_to_int(char c, bool& isNull)
{ {
if (c <= '9' && c >= '0') if (c <= '9' && c >= '0')
return c - '0'; return c - '0';
c = toupper(c); c |= 32;
if (c <= 'F' && c >= 'A') if (c <= 'f' && c >= 'a')
return c - 'A' + 10; return c - 'a' + 10;
isNull = true;
return -1; return -1;
} }
inline string cleanup(char *to)
{
delete[] to;
return "";
}
} }
namespace funcexp namespace funcexp
@ -65,48 +72,46 @@ string Func_unhex::getStrVal(rowgroup::Row& row,
CalpontSystemCatalog::ColType& op_ct) CalpontSystemCatalog::ColType& op_ct)
{ {
const string& from = parm[0]->data()->getStrVal(row, isNull); const string& from = parm[0]->data()->getStrVal(row, isNull);
char* to = new char[2 + from.length() / 2];
if (!to) if (isNull)
{
isNull = true;
return ""; return "";
}
char* to = new char[2 + from.size() / 2];
uint64_t from_pos = 0, to_pos = 0; uint64_t from_pos = 0, to_pos = 0;
int64_t hex_char = 0; int hex_char = 0;
if (strlen(from.c_str()) % 2) if (from.size() % 2)
{ {
hex_char = hex_to_int(from[from_pos++]); hex_char = hex_to_int(from[from_pos++], isNull);
to[to_pos++] = hex_char;
if (hex_char == -1) if (hex_char == -1)
goto nullHandling; return cleanup(to);
to[to_pos++] = hex_char;
} }
for (; from_pos < strlen(from.c_str()); from_pos += 2) for (; from_pos < from.size(); from_pos += 2)
{ {
hex_char = hex_to_int(from[from_pos]) << 4; hex_char = hex_to_int(from[from_pos], isNull) << 4;
if (hex_char == -1) if (hex_char == -1)
goto nullHandling; return cleanup(to);
to[to_pos] = hex_char; to[to_pos] = hex_char;
hex_char = hex_to_int(from[from_pos + 1]); hex_char = hex_to_int(from[from_pos + 1], isNull);
if (hex_char == -1) if (hex_char == -1)
goto nullHandling; return cleanup(to);
to[to_pos++] |= hex_char; to[to_pos++] |= hex_char;
} }
to[to_pos] = 0; to[to_pos] = 0;
return string(to); string tmp = string(to);
delete[] to;
nullHandling: return tmp;
isNull = true;
return "";
} }

View File

@ -209,7 +209,7 @@ FuncExp::FuncExp()
fFuncMap["trim"] = new Func_trim(); //dlh fFuncMap["trim"] = new Func_trim(); //dlh
fFuncMap["truncate"] = new Func_truncate(); //dlh fFuncMap["truncate"] = new Func_truncate(); //dlh
fFuncMap["ucase"] = new Func_ucase(); //dlh fFuncMap["ucase"] = new Func_ucase(); //dlh
//fFuncMap["unhex"] = new Func_unhex(); fFuncMap["unhex"] = new Func_unhex();
fFuncMap["unix_timestamp"] = new Func_unix_timestamp(); fFuncMap["unix_timestamp"] = new Func_unix_timestamp();
fFuncMap["upper"] = new Func_ucase(); //dlh fFuncMap["upper"] = new Func_ucase(); //dlh
fFuncMap["week"] = new Func_week(); //dlh fFuncMap["week"] = new Func_week(); //dlh