support decimal max func, cast func
This commit is contained in:
parent
7c31f060af
commit
83f7efd649
|
@ -80,6 +80,9 @@ typedef struct SBlockOrderInfo {
|
||||||
#define IS_JSON_NULL(type, data) \
|
#define IS_JSON_NULL(type, data) \
|
||||||
((type) == TSDB_DATA_TYPE_JSON && (*(data) == TSDB_DATA_TYPE_NULL || tTagIsJsonNull(data)))
|
((type) == TSDB_DATA_TYPE_JSON && (*(data) == TSDB_DATA_TYPE_NULL || tTagIsJsonNull(data)))
|
||||||
|
|
||||||
|
#define GET_COL_DATA_TYPE(col) \
|
||||||
|
{ .type = (col).type, .precision = (col).precision, .bytes = (col).bytes, .scale = (col).scale }
|
||||||
|
|
||||||
static FORCE_INLINE bool colDataIsNull_s(const SColumnInfoData* pColumnInfoData, uint32_t row) {
|
static FORCE_INLINE bool colDataIsNull_s(const SColumnInfoData* pColumnInfoData, uint32_t row) {
|
||||||
if (!pColumnInfoData->hasNull) {
|
if (!pColumnInfoData->hasNull) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -405,9 +405,13 @@ void *getDataMin(int32_t type, void *value);
|
||||||
void *getDataMax(int32_t type, void *value);
|
void *getDataMax(int32_t type, void *value);
|
||||||
|
|
||||||
#define STypeMod int32_t
|
#define STypeMod int32_t
|
||||||
|
STypeMod typeGetTypeMod(uint8_t type, uint8_t prec, uint8_t scale, int32_t bytes);
|
||||||
|
void extractTypeFromTypeMod(uint8_t type, STypeMod typeMod, uint8_t *prec, uint8_t scale, int32_t *bytes);
|
||||||
uint8_t decimalTypeFromPrecision(uint8_t precision);
|
uint8_t decimalTypeFromPrecision(uint8_t precision);
|
||||||
STypeMod decimalCalcTypeMod(uint8_t prec, uint8_t scale);
|
STypeMod decimalCalcTypeMod(uint8_t prec, uint8_t scale);
|
||||||
void decimalFromTypeMod(STypeMod typeMod, uint8_t *precision, uint8_t *scale);
|
void decimalFromTypeMod(STypeMod typeMod, uint8_t *precision, uint8_t *scale);
|
||||||
|
// pType->type should has been set
|
||||||
|
void fillTypeFromTypeMod(SDataType *pType, STypeMod mod);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -247,3 +247,15 @@ void decimalFromTypeMod(STypeMod typeMod, uint8_t* precision, uint8_t* scale) {
|
||||||
*scale = (uint8_t)(typeMod & 0xFF);
|
*scale = (uint8_t)(typeMod & 0xFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STypeMod typeGetTypeMod(uint8_t type, uint8_t prec, uint8_t scale, int32_t bytes) {
|
||||||
|
if (IS_DECIMAL_TYPE(type)) {
|
||||||
|
return decimalCalcTypeMod(prec, scale);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void fillTypeFromTypeMod(SDataType* pType, STypeMod mod) {
|
||||||
|
if (IS_DECIMAL_TYPE(pType->type)) {
|
||||||
|
decimalFromTypeMod(mod, &pType->precision, &pType->scale);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -112,6 +112,10 @@ static int32_t doSetUserSpecifiedValue(SColumnInfoData* pDst, SVariant* pVar, in
|
||||||
pDst->info.type == TSDB_DATA_TYPE_VARBINARY) {
|
pDst->info.type == TSDB_DATA_TYPE_VARBINARY) {
|
||||||
code = colDataSetVal(pDst, rowIndex, pVar->pz, isNull);
|
code = colDataSetVal(pDst, rowIndex, pVar->pz, isNull);
|
||||||
QUERY_CHECK_CODE(code, lino, _end);
|
QUERY_CHECK_CODE(code, lino, _end);
|
||||||
|
} else if (pDst->info.type == TSDB_DATA_TYPE_DECIMAL64) {
|
||||||
|
code = colDataSetVal(pDst, rowIndex, (char*)&pVar->i, isNull);
|
||||||
|
} else if (pDst->info.type == TSDB_DATA_TYPE_DECIMAL) {
|
||||||
|
code = colDataSetVal(pDst, rowIndex, (char*)pVar->pz, isNull);
|
||||||
} else { // others data
|
} else { // others data
|
||||||
colDataSetNULL(pDst, rowIndex);
|
colDataSetNULL(pDst, rowIndex);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ target_link_libraries(
|
||||||
PRIVATE qcom
|
PRIVATE qcom
|
||||||
PRIVATE scalar
|
PRIVATE scalar
|
||||||
PRIVATE geometry
|
PRIVATE geometry
|
||||||
|
PRIVATE decimal
|
||||||
PRIVATE transport
|
PRIVATE transport
|
||||||
PUBLIC uv_a
|
PUBLIC uv_a
|
||||||
)
|
)
|
||||||
|
|
|
@ -90,6 +90,7 @@ extern "C" {
|
||||||
#define FUNC_PARAM_SUPPORT_INTEGER_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(21)
|
#define FUNC_PARAM_SUPPORT_INTEGER_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(21)
|
||||||
#define FUNC_PARAM_SUPPORT_NULL_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(22)
|
#define FUNC_PARAM_SUPPORT_NULL_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(22)
|
||||||
#define FUNC_PARAM_SUPPORT_UNIX_TS_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(23)
|
#define FUNC_PARAM_SUPPORT_UNIX_TS_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(23)
|
||||||
|
#define FUNC_PARAM_SUPPORT_DECIMAL_TYPE FUNC_MGT_FUNC_PARAM_SUPPORT_TYPE(24)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -410,6 +410,11 @@ static bool paramSupportGeometry(uint64_t typeFlag) {
|
||||||
FUNC_MGT_TEST_MASK(typeFlag, FUNC_PARAM_SUPPORT_VAR_TYPE);
|
FUNC_MGT_TEST_MASK(typeFlag, FUNC_PARAM_SUPPORT_VAR_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool paramSupportDecimal(uint64_t typeFlag) {
|
||||||
|
return FUNC_MGT_TEST_MASK(typeFlag, FUNC_PARAM_SUPPORT_DECIMAL_TYPE) ||
|
||||||
|
FUNC_MGT_TEST_MASK(typeFlag, FUNC_PARAM_SUPPORT_ALL_TYPE);
|
||||||
|
}
|
||||||
|
|
||||||
static bool paramSupportValueNode(uint64_t typeFlag) {
|
static bool paramSupportValueNode(uint64_t typeFlag) {
|
||||||
return FUNC_MGT_TEST_MASK(typeFlag, FUNC_PARAM_SUPPORT_VALUE_NODE) ||
|
return FUNC_MGT_TEST_MASK(typeFlag, FUNC_PARAM_SUPPORT_VALUE_NODE) ||
|
||||||
FUNC_MGT_TEST_MASK(typeFlag, FUNC_PARAM_SUPPORT_EXPR_NODE);
|
FUNC_MGT_TEST_MASK(typeFlag, FUNC_PARAM_SUPPORT_EXPR_NODE);
|
||||||
|
@ -502,6 +507,9 @@ static bool paramSupportDataType(SDataType* pDataType, uint64_t typeFlag) {
|
||||||
return paramSupportVarBinary(typeFlag);
|
return paramSupportVarBinary(typeFlag);
|
||||||
case TSDB_DATA_TYPE_GEOMETRY:
|
case TSDB_DATA_TYPE_GEOMETRY:
|
||||||
return paramSupportGeometry(typeFlag);
|
return paramSupportGeometry(typeFlag);
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL64:
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL:
|
||||||
|
return paramSupportDecimal(typeFlag);
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -965,7 +973,8 @@ static int32_t translateMinMax(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
||||||
SDataType* dataType = getSDataTypeFromNode(nodesListGetNode(pFunc->pParameterList, 0));
|
SDataType* dataType = getSDataTypeFromNode(nodesListGetNode(pFunc->pParameterList, 0));
|
||||||
uint8_t paraType = IS_NULL_TYPE(dataType->type) ? TSDB_DATA_TYPE_BIGINT : dataType->type;
|
uint8_t paraType = IS_NULL_TYPE(dataType->type) ? TSDB_DATA_TYPE_BIGINT : dataType->type;
|
||||||
int32_t bytes = IS_STR_DATA_TYPE(paraType) ? dataType->bytes : tDataTypes[paraType].bytes;
|
int32_t bytes = IS_STR_DATA_TYPE(paraType) ? dataType->bytes : tDataTypes[paraType].bytes;
|
||||||
pFunc->node.resType = (SDataType){.bytes = bytes, .type = paraType};
|
uint8_t prec = IS_DECIMAL_TYPE(paraType) ? dataType->precision : pFunc->node.resType.precision;
|
||||||
|
pFunc->node.resType = (SDataType){.bytes = bytes, .type = paraType, .precision = prec, .scale = dataType->scale};
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1876,7 +1885,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
.inputParaInfo[0][0] = {.isLastParam = true,
|
.inputParaInfo[0][0] = {.isLastParam = true,
|
||||||
.startParam = 1,
|
.startParam = 1,
|
||||||
.endParam = 1,
|
.endParam = 1,
|
||||||
.validDataType = FUNC_PARAM_SUPPORT_NUMERIC_TYPE | FUNC_PARAM_SUPPORT_STRING_TYPE | FUNC_PARAM_SUPPORT_NULL_TYPE,
|
.validDataType = FUNC_PARAM_SUPPORT_NUMERIC_TYPE | FUNC_PARAM_SUPPORT_STRING_TYPE | FUNC_PARAM_SUPPORT_NULL_TYPE | FUNC_PARAM_SUPPORT_DECIMAL_TYPE,
|
||||||
.validNodeType = FUNC_PARAM_SUPPORT_EXPR_NODE,
|
.validNodeType = FUNC_PARAM_SUPPORT_EXPR_NODE,
|
||||||
.paramAttribute = FUNC_PARAM_NO_SPECIFIC_ATTRIBUTE,
|
.paramAttribute = FUNC_PARAM_NO_SPECIFIC_ATTRIBUTE,
|
||||||
.valueRangeFlag = FUNC_PARAM_NO_SPECIFIC_VALUE,},
|
.valueRangeFlag = FUNC_PARAM_NO_SPECIFIC_VALUE,},
|
||||||
|
@ -1903,7 +1912,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||||
.inputParaInfo[0][0] = {.isLastParam = true,
|
.inputParaInfo[0][0] = {.isLastParam = true,
|
||||||
.startParam = 1,
|
.startParam = 1,
|
||||||
.endParam = 1,
|
.endParam = 1,
|
||||||
.validDataType = FUNC_PARAM_SUPPORT_NUMERIC_TYPE | FUNC_PARAM_SUPPORT_STRING_TYPE | FUNC_PARAM_SUPPORT_NULL_TYPE,
|
.validDataType = FUNC_PARAM_SUPPORT_NUMERIC_TYPE | FUNC_PARAM_SUPPORT_STRING_TYPE | FUNC_PARAM_SUPPORT_NULL_TYPE |FUNC_PARAM_SUPPORT_DECIMAL_TYPE,
|
||||||
.validNodeType = FUNC_PARAM_SUPPORT_EXPR_NODE,
|
.validNodeType = FUNC_PARAM_SUPPORT_EXPR_NODE,
|
||||||
.paramAttribute = FUNC_PARAM_NO_SPECIFIC_ATTRIBUTE,
|
.paramAttribute = FUNC_PARAM_NO_SPECIFIC_ATTRIBUTE,
|
||||||
.valueRangeFlag = FUNC_PARAM_NO_SPECIFIC_VALUE,},
|
.valueRangeFlag = FUNC_PARAM_NO_SPECIFIC_VALUE,},
|
||||||
|
|
|
@ -902,6 +902,12 @@ int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL64:
|
||||||
|
code = colDataSetVal(pCol, currentRow, (const char*)&pRes->v, false);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL:
|
||||||
|
code = colDataSetVal(pCol, currentRow, pRes->str, false);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
colDataSetNULL(pCol, currentRow);
|
colDataSetNULL(pCol, currentRow);
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#include "tdatablock.h"
|
#include "tdatablock.h"
|
||||||
#include "tfunctionInt.h"
|
#include "tfunctionInt.h"
|
||||||
#include "tglobal.h"
|
#include "tglobal.h"
|
||||||
|
#include "decimal.h"
|
||||||
|
|
||||||
#define __COMPARE_ACQUIRED_MAX(i, end, bm, _data, ctx, val, pos) \
|
#define __COMPARE_ACQUIRED_MAX(i, end, bm, _data, ctx, val, pos) \
|
||||||
int32_t code = TSDB_CODE_SUCCESS; \
|
int32_t code = TSDB_CODE_SUCCESS; \
|
||||||
|
@ -458,6 +459,40 @@ static int32_t doExtractVal(SColumnInfoData* pCol, int32_t i, int32_t end, SqlFu
|
||||||
__COMPARE_ACQUIRED_MAX(i, end, pCol->nullbitmap, pData, pCtx, *(double*)&(pBuf->v), &pBuf->tuplePos)
|
__COMPARE_ACQUIRED_MAX(i, end, pCol->nullbitmap, pData, pCtx, *(double*)&(pBuf->v), &pBuf->tuplePos)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL64: {
|
||||||
|
const Decimal64* pData = (const Decimal64*)pCol->pData;
|
||||||
|
const SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL64);
|
||||||
|
int32_t code = 0;
|
||||||
|
for (; i < end; ++i) {
|
||||||
|
if (colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (pOps->lt(&pBuf->v, &pData[i], WORD_NUM(Decimal64))) {
|
||||||
|
pBuf->v = DECIMAL64_GET_VALUE(&pData[i]);
|
||||||
|
if (pCtx->subsidiaries.num > 0) {
|
||||||
|
code = updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||||
|
if (TSDB_CODE_SUCCESS != code) return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL: {
|
||||||
|
int32_t code = 0;
|
||||||
|
const SDecimalOps* pOps = getDecimalOps(TSDB_DATA_TYPE_DECIMAL);
|
||||||
|
const Decimal128* pData = (const Decimal128*)pCol->pData;
|
||||||
|
for (; i < end; ++i) {
|
||||||
|
if (colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (pOps->lt(pBuf->str, &pData[i], WORD_NUM(Decimal128))) {
|
||||||
|
memcpy(pBuf->str, pData + i, pCol->info.bytes);
|
||||||
|
if (pCtx->subsidiaries.num > 0) {
|
||||||
|
code = updateTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||||
|
if (TSDB_CODE_SUCCESS != code) return code;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
case TSDB_DATA_TYPE_VARCHAR:
|
case TSDB_DATA_TYPE_VARCHAR:
|
||||||
case TSDB_DATA_TYPE_VARBINARY: {
|
case TSDB_DATA_TYPE_VARBINARY: {
|
||||||
|
@ -612,8 +647,8 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc, int32_t* nElems)
|
||||||
int32_t threshold[] = {
|
int32_t threshold[] = {
|
||||||
//NULL, BOOL, TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, VARCHAR, TIMESTAMP, NCHAR,
|
//NULL, BOOL, TINYINT, SMALLINT, INT, BIGINT, FLOAT, DOUBLE, VARCHAR, TIMESTAMP, NCHAR,
|
||||||
INT32_MAX, INT32_MAX, 32, 16, 8, 4, 8, 4, INT32_MAX, INT32_MAX, INT32_MAX,
|
INT32_MAX, INT32_MAX, 32, 16, 8, 4, 8, 4, INT32_MAX, INT32_MAX, INT32_MAX,
|
||||||
// UTINYINT,USMALLINT, UINT, UBIGINT, JSON, VARBINARY, DECIMAL, BLOB, MEDIUMBLOB, BINARY
|
// UTINYINT,USMALLINT, UINT, UBIGINT, JSON, VARBINARY, DECIMAL, BLOB, MEDIUMBLOB, BINARY, Decimal64
|
||||||
32, 16, 8, 4, INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX,
|
32, 16, 8, 4, INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX, INT32_MAX,
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
|
@ -656,6 +691,14 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc, int32_t* nElems)
|
||||||
(void)memcpy(pBuf->str, colDataGetData(pCol, i), varDataTLen(colDataGetData(pCol, i)));
|
(void)memcpy(pBuf->str, colDataGetData(pCol, i), varDataTLen(colDataGetData(pCol, i)));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL64:
|
||||||
|
*(int64_t*)&pBuf->v = *(int64_t*)p;
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL:
|
||||||
|
pBuf->str = taosMemoryMalloc(pCol->info.bytes);
|
||||||
|
if (!pBuf->str) return terrno;
|
||||||
|
(void)memcpy(pBuf->str, p, pCol->info.bytes);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
(void)memcpy(&pBuf->v, p, pCol->info.bytes);
|
(void)memcpy(&pBuf->v, p, pCol->info.bytes);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -197,7 +197,14 @@ static int32_t valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) {
|
||||||
memcpy(pDst->datum.p, pSrc->datum.p, len);
|
memcpy(pDst->datum.p, pSrc->datum.p, len);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL64:
|
||||||
|
COPY_SCALAR_FIELD(datum.d);
|
||||||
|
break;
|
||||||
case TSDB_DATA_TYPE_DECIMAL:
|
case TSDB_DATA_TYPE_DECIMAL:
|
||||||
|
pDst->datum.p = taosMemCalloc(1, pSrc->node.resType.bytes);
|
||||||
|
if (!pDst->datum.p) return terrno;
|
||||||
|
memcpy(pDst->datum.p, pSrc->datum.p, pSrc->node.resType.bytes);
|
||||||
|
break;
|
||||||
case TSDB_DATA_TYPE_BLOB:
|
case TSDB_DATA_TYPE_BLOB:
|
||||||
case TSDB_DATA_TYPE_MEDIUMBLOB:
|
case TSDB_DATA_TYPE_MEDIUMBLOB:
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -877,6 +877,11 @@ static int32_t datumToMsg(const void* pObj, STlvEncoder* pEncoder) {
|
||||||
code = tlvEncodeBinary(pEncoder, VALUE_CODE_DATUM, pNode->datum.p, getJsonValueLen(pNode->datum.p));
|
code = tlvEncodeBinary(pEncoder, VALUE_CODE_DATUM, pNode->datum.p, getJsonValueLen(pNode->datum.p));
|
||||||
break;
|
break;
|
||||||
case TSDB_DATA_TYPE_DECIMAL:
|
case TSDB_DATA_TYPE_DECIMAL:
|
||||||
|
code = tlvEncodeBinary(pEncoder, VALUE_CODE_DATUM, pNode->datum.p, pNode->node.resType.bytes);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL64:
|
||||||
|
code = tlvEncodeI64(pEncoder, VALUE_CODE_DATUM, pNode->datum.i);
|
||||||
|
break;
|
||||||
case TSDB_DATA_TYPE_BLOB:
|
case TSDB_DATA_TYPE_BLOB:
|
||||||
// todo
|
// todo
|
||||||
default:
|
default:
|
||||||
|
@ -995,6 +1000,17 @@ static int32_t msgToDatum(STlv* pTlv, void* pObj) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case TSDB_DATA_TYPE_DECIMAL:
|
case TSDB_DATA_TYPE_DECIMAL:
|
||||||
|
pNode->datum.p = taosMemoryCalloc(1, pNode->node.resType.bytes);
|
||||||
|
if (!pNode->datum.p) {
|
||||||
|
code = terrno;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
code = tlvDecodeBinary(pTlv, pNode->datum.p);
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL64:
|
||||||
|
code = tlvDecodeI64(pTlv, &pNode->datum.i);
|
||||||
|
*(int64_t*)&pNode->typeData = pNode->datum.i;
|
||||||
|
break;
|
||||||
case TSDB_DATA_TYPE_BLOB:
|
case TSDB_DATA_TYPE_BLOB:
|
||||||
// todo
|
// todo
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -2377,13 +2377,19 @@ int32_t nodesSetValueNodeValue(SValueNode* pNode, void* value) {
|
||||||
case TSDB_DATA_TYPE_NCHAR:
|
case TSDB_DATA_TYPE_NCHAR:
|
||||||
case TSDB_DATA_TYPE_VARCHAR:
|
case TSDB_DATA_TYPE_VARCHAR:
|
||||||
case TSDB_DATA_TYPE_VARBINARY:
|
case TSDB_DATA_TYPE_VARBINARY:
|
||||||
case TSDB_DATA_TYPE_DECIMAL:
|
|
||||||
case TSDB_DATA_TYPE_JSON:
|
case TSDB_DATA_TYPE_JSON:
|
||||||
case TSDB_DATA_TYPE_BLOB:
|
case TSDB_DATA_TYPE_BLOB:
|
||||||
case TSDB_DATA_TYPE_MEDIUMBLOB:
|
case TSDB_DATA_TYPE_MEDIUMBLOB:
|
||||||
case TSDB_DATA_TYPE_GEOMETRY:
|
case TSDB_DATA_TYPE_GEOMETRY:
|
||||||
pNode->datum.p = (char*)value;
|
pNode->datum.p = (char*)value;
|
||||||
break;
|
break;
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL64:
|
||||||
|
pNode->datum.i = *(int64_t*)value;
|
||||||
|
pNode->typeData = *(int64_t*)value;
|
||||||
|
break;
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL:
|
||||||
|
pNode->datum.p = (char*)value;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
return TSDB_CODE_APP_ERROR;
|
return TSDB_CODE_APP_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -3026,7 +3032,17 @@ int32_t nodesValueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
|
||||||
code = terrno;
|
code = terrno;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL64:
|
||||||
|
pVal->d = pNode->datum.d;
|
||||||
|
break;
|
||||||
case TSDB_DATA_TYPE_DECIMAL:
|
case TSDB_DATA_TYPE_DECIMAL:
|
||||||
|
pVal->pz = taosMemoryCalloc(1, pVal->nLen);
|
||||||
|
if (!pVal->pz) {
|
||||||
|
code = terrno;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
memcpy(pVal->pz, pNode->datum.p, pVal->nLen);
|
||||||
|
break;
|
||||||
case TSDB_DATA_TYPE_BLOB:
|
case TSDB_DATA_TYPE_BLOB:
|
||||||
// todo
|
// todo
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -1383,11 +1383,7 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p
|
||||||
pCol->isPk = (pCol->tableHasPk) && (pColSchema->flags & COL_IS_KEY);
|
pCol->isPk = (pCol->tableHasPk) && (pColSchema->flags & COL_IS_KEY);
|
||||||
pCol->numOfPKs = pTable->pMeta->tableInfo.numOfPKs;
|
pCol->numOfPKs = pTable->pMeta->tableInfo.numOfPKs;
|
||||||
|
|
||||||
if (pExtSchema) {
|
if (pExtSchema) fillTypeFromTypeMod(&pCol->node.resType, pExtSchema->typeMod);
|
||||||
if (IS_DECIMAL_TYPE(pCol->node.resType.type)) {
|
|
||||||
decimalFromTypeMod(pExtSchema->typeMod, &pCol->node.resType.precision, &pCol->node.resType.scale);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SColumnNode** pColRef) {
|
static int32_t setColumnInfoByExpr(STempTableNode* pTable, SExprNode* pExpr, SColumnNode** pColRef) {
|
||||||
|
@ -1484,8 +1480,10 @@ static int32_t createColumnsByTable(STranslateContext* pCxt, const STableNode* p
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
return generateSyntaxErrMsg(&pCxt->msgBuf, code);
|
return generateSyntaxErrMsg(&pCxt->msgBuf, code);
|
||||||
}
|
}
|
||||||
SSchemaExt* pSchemaExt = i > pMeta->tableInfo.numOfColumns ? NULL : pMeta->schemaExt + i;
|
SSchemaExt* pSchemaExt =
|
||||||
setColumnInfoBySchema((SRealTableNode*)pTable, pMeta->schema + i, (i - pMeta->tableInfo.numOfColumns), pCol, pSchemaExt);
|
pMeta->schemaExt ? (i > pMeta->tableInfo.numOfColumns ? NULL : (pMeta->schemaExt + i)) : NULL;
|
||||||
|
setColumnInfoBySchema((SRealTableNode*)pTable, pMeta->schema + i, (i - pMeta->tableInfo.numOfColumns), pCol,
|
||||||
|
pSchemaExt);
|
||||||
setColumnPrimTs(pCxt, pCol, pTable);
|
setColumnPrimTs(pCxt, pCol, pTable);
|
||||||
code = nodesListStrictAppend(pList, (SNode*)pCol);
|
code = nodesListStrictAppend(pList, (SNode*)pCol);
|
||||||
}
|
}
|
||||||
|
@ -1563,7 +1561,7 @@ static int32_t findAndSetColumn(STranslateContext* pCxt, SColumnNode** pColRef,
|
||||||
if (0 == strcmp(pCol->colName, pMeta->schema[i].name) &&
|
if (0 == strcmp(pCol->colName, pMeta->schema[i].name) &&
|
||||||
!invisibleColumn(pCxt->pParseCxt->enableSysInfo, pMeta->tableType, pMeta->schema[i].flags)) {
|
!invisibleColumn(pCxt->pParseCxt->enableSysInfo, pMeta->tableType, pMeta->schema[i].flags)) {
|
||||||
|
|
||||||
SSchemaExt* pSchemaExt = i > pMeta->tableInfo.numOfColumns ? NULL : pMeta->schemaExt + i;
|
SSchemaExt* pSchemaExt = pMeta->schemaExt ? (i > pMeta->tableInfo.numOfColumns ? NULL : (pMeta->schemaExt + i)) : NULL;
|
||||||
setColumnInfoBySchema((SRealTableNode*)pTable, pMeta->schema + i, (i - pMeta->tableInfo.numOfColumns), pCol, pSchemaExt);
|
setColumnInfoBySchema((SRealTableNode*)pTable, pMeta->schema + i, (i - pMeta->tableInfo.numOfColumns), pCol, pSchemaExt);
|
||||||
setColumnPrimTs(pCxt, pCol, pTable);
|
setColumnPrimTs(pCxt, pCol, pTable);
|
||||||
*pFound = true;
|
*pFound = true;
|
||||||
|
@ -3381,6 +3379,7 @@ static int32_t createCastFunc(STranslateContext* pCxt, SNode* pExpr, SDataType d
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
code = getFuncInfo(pCxt, pFunc);
|
code = getFuncInfo(pCxt, pFunc);
|
||||||
|
pFunc->node.resType = dt;
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
nodesClearList(pFunc->pParameterList);
|
nodesClearList(pFunc->pParameterList);
|
||||||
pFunc->pParameterList = NULL;
|
pFunc->pParameterList = NULL;
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
#include "tjson.h"
|
#include "tjson.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
#include "filter.h"
|
#include "filter.h"
|
||||||
|
#include "decimal.h"
|
||||||
|
|
||||||
typedef float (*_float_fn)(float);
|
typedef float (*_float_fn)(float);
|
||||||
typedef float (*_float_fn_2)(float, float);
|
typedef float (*_float_fn_2)(float, float);
|
||||||
|
@ -2155,6 +2156,25 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL64:
|
||||||
|
case TSDB_DATA_TYPE_DECIMAL: {
|
||||||
|
SDataType iT = GET_COL_DATA_TYPE(pInput[0].columnData->info), oT = GET_COL_DATA_TYPE(pOutput->columnData->info);
|
||||||
|
if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||||
|
int32_t len = taosUcs4ToMbs((TdUcs4 *)(varDataVal(input)), varDataLen(input), convBuf, pInput->charsetCxt);
|
||||||
|
if (len < 0) {
|
||||||
|
code = TSDB_CODE_SCALAR_CONVERT_ERROR;
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
convBuf[len] = 0;
|
||||||
|
code = convertToDecimal(convBuf, &iT, output, &oT);
|
||||||
|
} else {
|
||||||
|
code = convertToDecimal(input, &iT, output, &oT);
|
||||||
|
}
|
||||||
|
if (code != TSDB_CODE_SUCCESS) {
|
||||||
|
terrno = code;
|
||||||
|
goto _end;
|
||||||
|
}
|
||||||
|
} break;
|
||||||
default: {
|
default: {
|
||||||
code = TSDB_CODE_FAILED;
|
code = TSDB_CODE_FAILED;
|
||||||
goto _end;
|
goto _end;
|
||||||
|
|
|
@ -39,8 +39,6 @@
|
||||||
IS_JSON_NULL(pRight->columnData->info.type, colDataGetVarData(pRight->columnData, i))
|
IS_JSON_NULL(pRight->columnData->info.type, colDataGetVarData(pRight->columnData, i))
|
||||||
|
|
||||||
#define IS_HELPER_NULL(col, i) colDataIsNull_s(col, i) || IS_JSON_NULL(col->info.type, colDataGetVarData(col, i))
|
#define IS_HELPER_NULL(col, i) colDataIsNull_s(col, i) || IS_JSON_NULL(col->info.type, colDataGetVarData(col, i))
|
||||||
#define GET_COL_DATA_TYPE(col) \
|
|
||||||
{ .type = (col).type, .precision = (col).precision, .bytes = (col).bytes, .scale = (col).scale }
|
|
||||||
|
|
||||||
bool noConvertBeforeCompare(int32_t leftType, int32_t rightType, int32_t optr) {
|
bool noConvertBeforeCompare(int32_t leftType, int32_t rightType, int32_t optr) {
|
||||||
return !IS_DECIMAL_TYPE(leftType) && !IS_DECIMAL_TYPE(rightType) && IS_NUMERIC_TYPE(leftType) &&
|
return !IS_DECIMAL_TYPE(leftType) && !IS_DECIMAL_TYPE(rightType) && IS_NUMERIC_TYPE(leftType) &&
|
||||||
|
|
Loading…
Reference in New Issue