提交 73fcf1e1 编写于 作者: H Haojun Liao

[td-1151]

上级 2271ac92
...@@ -433,31 +433,36 @@ static FORCE_INLINE void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pField ...@@ -433,31 +433,36 @@ static FORCE_INLINE void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pField
int32_t bytes = pInfo->pSqlExpr->resBytes; int32_t bytes = pInfo->pSqlExpr->resBytes;
char* pData = pRes->data + pInfo->pSqlExpr->offset * pRes->numOfRows + bytes * pRes->row; char* pData = pRes->data + pInfo->pSqlExpr->offset * pRes->numOfRows + bytes * pRes->row;
if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) {
int32_t realLen = varDataLen(pData);
assert(realLen <= bytes - VARSTR_HEADER_SIZE);
if (isNull(pData, type)) { // user defined constant value output columns
pRes->tsrow[columnIndex] = NULL; if (pInfo->pSqlExpr->colInfo.flag == TSDB_COL_UDC) {
if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) {
pData = pInfo->pSqlExpr->param[1].pz;
pRes->length[columnIndex] = pInfo->pSqlExpr->param[1].nLen;
pRes->tsrow[columnIndex] = (pInfo->pSqlExpr->param[1].nType == TSDB_DATA_TYPE_NULL) ? NULL : pData;
} else { } else {
pRes->tsrow[columnIndex] = ((tstr*)pData)->data; assert(bytes == tDataTypeDesc[type].nSize);
}
if (realLen < pInfo->pSqlExpr->resBytes - VARSTR_HEADER_SIZE) { // todo refactor pRes->tsrow[columnIndex] = isNull(pData, type) ? NULL : &pInfo->pSqlExpr->param[1].i64Key;
*(pData + realLen + VARSTR_HEADER_SIZE) = 0; pRes->length[columnIndex] = bytes;
} }
pRes->length[columnIndex] = realLen;
} else { } else {
assert(bytes == tDataTypeDesc[type].nSize); if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) {
int32_t realLen = varDataLen(pData);
assert(realLen <= bytes - VARSTR_HEADER_SIZE);
pRes->tsrow[columnIndex] = (isNull(pData, type)) ? NULL : ((tstr *)pData)->data;
if (realLen < pInfo->pSqlExpr->resBytes - VARSTR_HEADER_SIZE) { // todo refactor
*(pData + realLen + VARSTR_HEADER_SIZE) = 0;
}
if (isNull(pData, type)) { pRes->length[columnIndex] = realLen;
pRes->tsrow[columnIndex] = NULL;
} else { } else {
pRes->tsrow[columnIndex] = pData; assert(bytes == tDataTypeDesc[type].nSize);
}
pRes->length[columnIndex] = bytes; pRes->tsrow[columnIndex] = isNull(pData, type) ? NULL : pData;
pRes->length[columnIndex] = bytes;
}
} }
} }
......
...@@ -2902,27 +2902,20 @@ static FORCE_INLINE void date_col_output_function_f(SQLFunctionCtx *pCtx, int32_ ...@@ -2902,27 +2902,20 @@ static FORCE_INLINE void date_col_output_function_f(SQLFunctionCtx *pCtx, int32_
} }
static void col_project_function(SQLFunctionCtx *pCtx) { static void col_project_function(SQLFunctionCtx *pCtx) {
if (pCtx->numOfParams == 2) { // the number of output rows should not affect the final number of rows, so set it to be 0 // the number of output rows should not affect the final number of rows, so set it to be 0
SET_VAL(pCtx, pCtx->size, 1); if (pCtx->numOfParams == 2) {
return;
}
char* output = pCtx->aOutputBuf; INC_INIT_VAL(pCtx, pCtx->size);
for(int32_t i = 0; i < pCtx->size; ++i) {
tVariantDump(&pCtx->param[1], output, pCtx->outputType, true);
output += pCtx->outputBytes;
}
char *pData = GET_INPUT_CHAR(pCtx);
if (pCtx->order == TSDB_ORDER_ASC) {
memcpy(pCtx->aOutputBuf, pData, (size_t) pCtx->size * pCtx->inputBytes);
} else { } else {
for(int32_t i = 0; i < pCtx->size; ++i) {
INC_INIT_VAL(pCtx, pCtx->size); memcpy(pCtx->aOutputBuf + (pCtx->size - 1 - i) * pCtx->inputBytes, pData + i * pCtx->inputBytes,
pCtx->inputBytes);
char *pData = GET_INPUT_CHAR(pCtx);
if (pCtx->order == TSDB_ORDER_ASC) {
memcpy(pCtx->aOutputBuf, pData, (size_t) pCtx->size * pCtx->inputBytes);
} else {
for(int32_t i = 0; i < pCtx->size; ++i) {
memcpy(pCtx->aOutputBuf + (pCtx->size - 1 - i) * pCtx->inputBytes, pData + i * pCtx->inputBytes,
pCtx->inputBytes);
}
} }
} }
...@@ -2931,20 +2924,18 @@ static void col_project_function(SQLFunctionCtx *pCtx) { ...@@ -2931,20 +2924,18 @@ static void col_project_function(SQLFunctionCtx *pCtx) {
static void col_project_function_f(SQLFunctionCtx *pCtx, int32_t index) { static void col_project_function_f(SQLFunctionCtx *pCtx, int32_t index) {
SResultInfo *pResInfo = GET_RES_INFO(pCtx); SResultInfo *pResInfo = GET_RES_INFO(pCtx);
if (pCtx->numOfParams == 2) { // the number of output rows should not affect the final number of rows, so set it to be 0
return;
}
// only one output // only one output
if (pCtx->param[0].i64Key == 1 && pResInfo->numOfRes >= 1) { if (pCtx->param[0].i64Key == 1 && pResInfo->numOfRes >= 1) {
return; return;
} }
if (pCtx->numOfParams == 2) { // the number of output rows should not affect the final number of rows, so set it to be 0 INC_INIT_VAL(pCtx, 1);
SET_VAL(pCtx, pCtx->size, 1); char *pData = GET_INPUT_CHAR_INDEX(pCtx, index);
tVariantDump(&pCtx->param[1], pCtx->aOutputBuf, pCtx->outputType, true); memcpy(pCtx->aOutputBuf, pData, pCtx->inputBytes);
} else {
INC_INIT_VAL(pCtx, 1);
char *pData = GET_INPUT_CHAR_INDEX(pCtx, index);
memcpy(pCtx->aOutputBuf, pData, pCtx->inputBytes);
}
pCtx->aOutputBuf += pCtx->inputBytes; pCtx->aOutputBuf += pCtx->inputBytes;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册