提交 d48ba502 编写于 作者: H Haojun Liao

[td-225] fix bug found by regression test.

上级 f17bf6d7
......@@ -496,47 +496,6 @@ int32_t tscSQLSyntaxErrMsg(char* msg, const char* additionalInfo, const char* s
int32_t tscToSQLCmd(SSqlObj *pSql, struct SSqlInfo *pInfo);
static FORCE_INLINE void tscGetResultColumnChr(SSqlRes* pRes, SFieldInfo* pFieldInfo, int32_t columnIndex, int32_t offset) {
SInternalField* pInfo = (SInternalField*) TARRAY_GET_ELEM(pFieldInfo->internalField, columnIndex);
int32_t type = pInfo->field.type;
int32_t bytes = pInfo->field.bytes;
char* pData = pRes->data + (int32_t)(offset * pRes->numOfRows + bytes * pRes->row);
UNUSED(pData);
// user defined constant value output columns
if (pInfo->pExpr != NULL && TSDB_COL_IS_UD_COL(pInfo->pExpr->base.colInfo.flag)) {
if (type == TSDB_DATA_TYPE_NCHAR || type == TSDB_DATA_TYPE_BINARY) {
pData = pInfo->pExpr->base.param[1].pz;
pRes->length[columnIndex] = pInfo->pExpr->base.param[1].nLen;
pRes->tsrow[columnIndex] = (pInfo->pExpr->base.param[1].nType == TSDB_DATA_TYPE_NULL) ? NULL : (unsigned char*)pData;
} else {
assert(bytes == tDataTypes[type].bytes);
pRes->tsrow[columnIndex] = isNull(pData, type) ? NULL : (unsigned char*)&pInfo->pExpr->base.param[1].i64;
pRes->length[columnIndex] = bytes;
}
} else {
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 : (unsigned char*)((tstr *)pData)->data;
if (realLen < pInfo->pExpr->base.resBytes - VARSTR_HEADER_SIZE) { // todo refactor
*(pData + realLen + VARSTR_HEADER_SIZE) = 0;
}
pRes->length[columnIndex] = realLen;
} else {
assert(bytes == tDataTypes[type].bytes);
pRes->tsrow[columnIndex] = isNull(pData, type) ? NULL : (unsigned char*)pData;
pRes->length[columnIndex] = bytes;
}
}
}
extern int32_t sentinel;
extern SHashObj *tscVgroupMap;
extern SHashObj *tscTableMetaInfo;
......
......@@ -6801,12 +6801,16 @@ int32_t tscGetExprFilters(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pSelect
tSqlExprItem* pItem = taosArrayGet(pSelectNodeList, i);
if (tSqlExprCompare(pItem->pNode, pSqlExpr) == 0) { // exists, not added it,
int32_t functionId = isValidFunction(pSqlExpr->operand.z, pSqlExpr->operand.n);
tSqlExprItem* pParamElem = taosArrayGet(pSqlExpr->pParam, 0);
SStrToken* pToken = &pParamElem->pNode->colInfo;
SColumnIndex index = COLUMN_INDEX_INITIALIZER;
getColumnIndexByName(pCmd, pToken, pQueryInfo, &index);
int32_t functionId = pSqlExpr->functionId;
if (pSqlExpr->pParam == NULL) {
index.columnIndex = 0;
index.tableIndex = 0;
} else {
tSqlExprItem* pParamElem = taosArrayGet(pSqlExpr->pParam, 0);
SStrToken* pToken = &pParamElem->pNode->colInfo;
getColumnIndexByName(pCmd, pToken, pQueryInfo, &index);
}
size_t numOfNodeInSel = tscSqlExprNumOfExprs(pQueryInfo);
for(int32_t k = 0; k < numOfNodeInSel; ++k) {
......@@ -6843,6 +6847,10 @@ int32_t tscGetExprFilters(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pSelect
size_t n = tscSqlExprNumOfExprs(pQueryInfo);
*pExpr = tscSqlExprGet(pQueryInfo, (int32_t)n - 1);
SInternalField* pField = taosArrayGet(pQueryInfo->fieldsInfo.internalField, n - 1);
pField->visible = false;
return TSDB_CODE_SUCCESS;
}
......@@ -6920,7 +6928,6 @@ static int32_t handleExprInHavingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, S
}
return TSDB_CODE_SUCCESS;
// return genExprFilter(pInfo->pFieldFilters);
}
int32_t getHavingExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pSelectNodeList, tSqlExpr* pExpr, int32_t parentOptr) {
......
......@@ -3403,20 +3403,26 @@ TAOS_ROW doSetResultRowData(SSqlObj *pSql) {
SQueryInfo *pQueryInfo = tscGetQueryInfo(pCmd, pCmd->clauseIndex);
size_t size = tscNumOfFields(pQueryInfo);
int32_t j = 0;
for (int i = 0; i < size; ++i) {
SInternalField* pInfo = (SInternalField*)TARRAY_GET_ELEM(pQueryInfo->fieldsInfo.internalField, i);
if (!pInfo->visible) {
continue;
}
int32_t type = pInfo->field.type;
int32_t bytes = pInfo->field.bytes;
if (type != TSDB_DATA_TYPE_BINARY && type != TSDB_DATA_TYPE_NCHAR) {
pRes->tsrow[i] = isNull(pRes->urow[i], type) ? NULL : pRes->urow[i];
pRes->tsrow[j] = isNull(pRes->urow[i], type) ? NULL : pRes->urow[i];
} else {
pRes->tsrow[i] = isNull(pRes->urow[i], type) ? NULL : varDataVal(pRes->urow[i]);
pRes->length[i] = varDataLen(pRes->urow[i]);
pRes->tsrow[j] = isNull(pRes->urow[i], type) ? NULL : varDataVal(pRes->urow[i]);
pRes->length[j] = varDataLen(pRes->urow[i]);
}
((char**) pRes->urow)[i] += bytes;
j += 1;
}
pRes->row++; // index increase one-step
......
......@@ -358,7 +358,7 @@ int32_t tSqlExprCompare(tSqlExpr *left, tSqlExpr *right) {
for (int32_t i = 0; i < size; i++) {
tSqlExprItem* pLeftElem = taosArrayGet(left->pParam, i);
tSqlExpr* pSubLeft = pLeftElem->pNode;
tSqlExprItem* pRightElem = taosArrayGet(left->pParam, i);
tSqlExprItem* pRightElem = taosArrayGet(right->pParam, i);
tSqlExpr* pSubRight = pRightElem->pNode;
if (tSqlExprCompare(pSubLeft, pSubRight)) {
......
......@@ -141,9 +141,7 @@ if $data30 != 4 then
endi
sql_error select top(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select top(f1,2) from st2 group by f1 having count(f2) > 0;
sql_error select top(f1,2) from st2 group by f1 having avg(f1) > 0;
sql select avg(f1),count(f1) from st2 group by f1 having avg(f1) > 2;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册