修复decimal解析错误问题,统一以%.15g输出
This commit is contained in:
@@ -106,9 +106,9 @@ void decryptResult(int numberAttr, int numTuples, pAttrDescs pattDescs, pTuples
|
|||||||
|
|
||||||
void (*anyTypetoString)(const char *, char *const, void *) = NULL; // 把buffer转为相应类型的数据。
|
void (*anyTypetoString)(const char *, char *const, void *) = NULL; // 把buffer转为相应类型的数据。
|
||||||
switch (ctype) {
|
switch (ctype) {
|
||||||
// case TYPE_FLOAT:
|
case TYPE_FLOAT:
|
||||||
// anyTypetoString = &FloatTypetoString;
|
anyTypetoString = &DoubleTypetoString;
|
||||||
// break;
|
break;
|
||||||
|
|
||||||
case TYPE_STRING:
|
case TYPE_STRING:
|
||||||
|
|
||||||
@@ -168,10 +168,7 @@ void decryptResult(int numberAttr, int numTuples, pAttrDescs pattDescs, pTuples
|
|||||||
);
|
);
|
||||||
// 确保输出大小正确
|
// 确保输出大小正确
|
||||||
if (outSize >= sizeof(double)) {
|
if (outSize >= sizeof(double)) {
|
||||||
double d = *(double*)aesOut.get();
|
DoubleTypetoString((const char*)aesOut.get(), tuples[i][j].value, (void *) coltypename.get());
|
||||||
std::ostringstream ss;
|
|
||||||
ss << d;
|
|
||||||
strcpy(tuples[i][j].value, ss.str().c_str());
|
|
||||||
}
|
}
|
||||||
delete[] buff;
|
delete[] buff;
|
||||||
} else {
|
} else {
|
||||||
@@ -216,7 +213,7 @@ void decryptResult(int numberAttr, int numTuples, pAttrDescs pattDescs, pTuples
|
|||||||
// plainBuff = encryptValue(t, pbuff, buffSZ, &plainBuffSZ, false);
|
// plainBuff = encryptValue(t, pbuff, buffSZ, &plainBuffSZ, false);
|
||||||
if (anyTypetoString) {
|
if (anyTypetoString) {
|
||||||
//fixed by qxy for RND
|
//fixed by qxy for RND
|
||||||
if (type == CIPHER_RND) {
|
if (type == CIPHER_RND && ctype != TYPE_FLOAT) {
|
||||||
long l = *(long *)plainBuff;
|
long l = *(long *)plainBuff;
|
||||||
std::ostringstream ss;
|
std::ostringstream ss;
|
||||||
ss << l;
|
ss << l;
|
||||||
|
|||||||
@@ -57,6 +57,24 @@ bool IsInt8ColumnType(const char* type_name)
|
|||||||
return type.find("int8") != std::string::npos || type.find("bigint") != std::string::npos;
|
return type.find("int8") != std::string::npos || type.find("bigint") != std::string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsFloatColumnType(const char* type_name)
|
||||||
|
{
|
||||||
|
return type_name && unifyColumnType(type_name) == TYPE_FLOAT;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ShouldSetPeerFloat(const char* type_name, EncryptInfo* info)
|
||||||
|
{
|
||||||
|
if (!IsFloatColumnType(type_name))
|
||||||
|
return false;
|
||||||
|
if (!strcmp(type_name, "float"))
|
||||||
|
return true;
|
||||||
|
if (!info || !IsA((Node *) info->father, A_Expr))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
const char* op = getAExprOp((A_Expr *) info->father);
|
||||||
|
return op && !strcmp(op, "=");
|
||||||
|
}
|
||||||
|
|
||||||
bool TryParseInt64Literal(const char* literal, int64_t* value)
|
bool TryParseInt64Literal(const char* literal, int64_t* value)
|
||||||
{
|
{
|
||||||
if (!literal || !value)
|
if (!literal || !value)
|
||||||
@@ -224,15 +242,29 @@ static A_Const *encryptAConst(A_Const *aconst, T_Cipher encryptCipher, EncryptIn
|
|||||||
}
|
}
|
||||||
plainText = (uint8_t *) tmpInt;
|
plainText = (uint8_t *) tmpInt;
|
||||||
in_size = sizeof(int64_t);
|
in_size = sizeof(int64_t);
|
||||||
} else if (encryptCipher == CIPHER_RND) {
|
} else if (encryptCipher == CIPHER_RND || encryptCipher == CIPHER_RNDSM4CK) {
|
||||||
|
if (isFloat || info->isPeerColFloat || IsA(AConstValue, Float)) {
|
||||||
|
isFloat = true;
|
||||||
|
if (IsA(AConstValue, Integer)) {
|
||||||
|
tmpDouble = static_cast<double>(intVal(AConstValue));
|
||||||
|
} else {
|
||||||
|
tmpDouble = atof(strVal(AConstValue));
|
||||||
|
}
|
||||||
|
plainText = (uint8_t *) &tmpDouble;
|
||||||
|
in_size = sizeof(double);
|
||||||
|
} else {
|
||||||
*tmpInt = intVal(AConstValue);
|
*tmpInt = intVal(AConstValue);
|
||||||
// isFloat = true;
|
// isFloat = true;
|
||||||
// *tmpInt *= Float_Scale;
|
// *tmpInt *= Float_Scale;
|
||||||
|
plainText = (uint8_t *) tmpInt;
|
||||||
|
in_size = sizeof(int64_t);
|
||||||
|
}
|
||||||
|
if (info->isPeerColFloat) {
|
||||||
|
info->isPeerColFloat = false;
|
||||||
|
}
|
||||||
if (info->isPeerColInt8) {
|
if (info->isPeerColInt8) {
|
||||||
info->isPeerColInt8 = false;
|
info->isPeerColInt8 = false;
|
||||||
}
|
}
|
||||||
plainText = (uint8_t *) tmpInt;
|
|
||||||
in_size = sizeof(int64_t);
|
|
||||||
} else if (IsA(AConstValue, Float)) //
|
} else if (IsA(AConstValue, Float)) //
|
||||||
{
|
{
|
||||||
isFloat = true;
|
isFloat = true;
|
||||||
@@ -257,17 +289,28 @@ static A_Const *encryptAConst(A_Const *aconst, T_Cipher encryptCipher, EncryptIn
|
|||||||
plainText = (uint8_t *) &tmpDouble;
|
plainText = (uint8_t *) &tmpDouble;
|
||||||
in_size = sizeof(double);
|
in_size = sizeof(double);
|
||||||
} else if (IsA(AConstValue, Integer)) {
|
} else if (IsA(AConstValue, Integer)) {
|
||||||
|
if (isFloat || info->isPeerColFloat) {
|
||||||
|
isFloat = true;
|
||||||
|
tmpDouble = static_cast<double>(intVal(AConstValue));
|
||||||
|
plainText = (uint8_t *) &tmpDouble;
|
||||||
|
in_size = sizeof(double);
|
||||||
|
if (info->isPeerColFloat) {
|
||||||
|
info->isPeerColFloat = false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
*tmpInt = intVal(AConstValue);
|
*tmpInt = intVal(AConstValue);
|
||||||
// isFloat = true;
|
// isFloat = true;
|
||||||
isFloat = false;
|
isFloat = false;
|
||||||
// *tmpInt *= Float_Scale;
|
// *tmpInt *= Float_Scale;
|
||||||
|
plainText = (uint8_t *) tmpInt;
|
||||||
|
in_size = sizeof(int64_t);
|
||||||
|
}
|
||||||
if (info->isPeerColInt8) {
|
if (info->isPeerColInt8) {
|
||||||
info->isPeerColInt8 = false;
|
info->isPeerColInt8 = false;
|
||||||
}
|
}
|
||||||
plainText = (uint8_t *) tmpInt;
|
|
||||||
in_size = sizeof(int64_t);
|
|
||||||
} else {
|
} else {
|
||||||
*tmpInt = intVal(AConstValue);
|
*tmpInt = intVal(AConstValue);
|
||||||
|
tmpDouble = static_cast<double>(*tmpInt);
|
||||||
// if (info->isFloatorIntCol) { // 当前列是float或Int列
|
// if (info->isFloatorIntCol) { // 当前列是float或Int列
|
||||||
// isFloat = true;
|
// isFloat = true;
|
||||||
// *tmpInt *= Float_Scale;
|
// *tmpInt *= Float_Scale;
|
||||||
@@ -615,7 +658,7 @@ static ColumnRef *encryptColumnRef(ColumnRef *cref, T_Cipher encryptCipher, Encr
|
|||||||
char typebuf[128];
|
char typebuf[128];
|
||||||
if (IsA((Node *) info->father, A_Expr)) {
|
if (IsA((Node *) info->father, A_Expr)) {
|
||||||
getColumnType(name, typebuf);
|
getColumnType(name, typebuf);
|
||||||
if (!strcmp(typebuf, "float")) {
|
if (ShouldSetPeerFloat(typebuf, info)) {
|
||||||
info->isPeerColFloat = true;
|
info->isPeerColFloat = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1582,7 +1625,7 @@ static List *encryptValuesLists(List *valuesLists, List *cols, EncryptInfo *info
|
|||||||
// } else {
|
// } else {
|
||||||
// info->isFloatorIntCol = false;
|
// info->isFloatorIntCol = false;
|
||||||
// }
|
// }
|
||||||
if (string(colInfo->type).find("float") != string::npos)
|
if (IsFloatColumnType(colInfo->type))
|
||||||
{
|
{
|
||||||
info->isFloatCol = true;
|
info->isFloatCol = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -458,6 +458,15 @@ void FloatTypetoString(const char *buf, char *v,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DoubleTypetoString(const char *buf, char *v, void *others)
|
||||||
|
{
|
||||||
|
double d = 0.0;
|
||||||
|
memcpy(&d, buf, sizeof(double));
|
||||||
|
sprintf(v, "%.15g", d);
|
||||||
|
if (!strcmp(v, "-0"))
|
||||||
|
strcpy(v, "0");
|
||||||
|
}
|
||||||
|
|
||||||
void FloatTypetoString2(const char *buf, char *v,
|
void FloatTypetoString2(const char *buf, char *v,
|
||||||
void *others) // TODO: // buf 不一定是 double的内存排布,还有可能是long, 因为词法分析不区分 (long)1, (double)1
|
void *others) // TODO: // buf 不一定是 double的内存排布,还有可能是long, 因为词法分析不区分 (long)1, (double)1
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -153,6 +153,8 @@ void IntTypetoString(const char *buf, char *const v, void *others);
|
|||||||
|
|
||||||
void FloatTypetoString(const char *buf, char *const v, void *others);
|
void FloatTypetoString(const char *buf, char *const v, void *others);
|
||||||
|
|
||||||
|
void DoubleTypetoString(const char *buf, char *const v, void *others);
|
||||||
|
|
||||||
void FloatTypetoString2(const char *buf, char *const v, void *others);
|
void FloatTypetoString2(const char *buf, char *const v, void *others);
|
||||||
|
|
||||||
void FloatTypetoString3(const char *buf, char *const v, void *others);
|
void FloatTypetoString3(const char *buf, char *const v, void *others);
|
||||||
|
|||||||
Reference in New Issue
Block a user