Merge pull request #3446 from taosdata/feature/TD-1370
[TD-1370]<enhance>: support function count(1)
This commit is contained in:
commit
e19dc2b7cb
|
@ -1597,13 +1597,14 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
|
||||||
SColumnIndex index = COLUMN_INDEX_INITIALIZER;
|
SColumnIndex index = COLUMN_INDEX_INITIALIZER;
|
||||||
|
|
||||||
if (pItem->pNode->pParam != NULL) {
|
if (pItem->pNode->pParam != NULL) {
|
||||||
SStrToken* pToken = &pItem->pNode->pParam->a[0].pNode->colInfo;
|
tSQLExprItem* pParamElem = &pItem->pNode->pParam->a[0];
|
||||||
if (pToken->z == NULL || pToken->n == 0) {
|
SStrToken* pToken = &pParamElem->pNode->colInfo;
|
||||||
|
short sqlOptr = pParamElem->pNode->nSQLOptr;
|
||||||
|
if ((pToken->z == NULL || pToken->n == 0)
|
||||||
|
&& (TK_INTEGER != sqlOptr)) /*select count(1) from table*/ {
|
||||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||||
}
|
}
|
||||||
|
if (sqlOptr == TK_ALL) {
|
||||||
tSQLExprItem* pParamElem = &pItem->pNode->pParam->a[0];
|
|
||||||
if (pParamElem->pNode->nSQLOptr == TK_ALL) {
|
|
||||||
// select table.*
|
// select table.*
|
||||||
// check if the table name is valid or not
|
// check if the table name is valid or not
|
||||||
SStrToken tmpToken = pParamElem->pNode->colInfo;
|
SStrToken tmpToken = pParamElem->pNode->colInfo;
|
||||||
|
@ -1615,6 +1616,21 @@ int32_t addExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32_t col
|
||||||
index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX};
|
index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX};
|
||||||
int32_t size = tDataTypeDesc[TSDB_DATA_TYPE_BIGINT].nSize;
|
int32_t size = tDataTypeDesc[TSDB_DATA_TYPE_BIGINT].nSize;
|
||||||
pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size, false);
|
pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size, false);
|
||||||
|
} else if (sqlOptr == TK_INTEGER) { // select count(1) from table1
|
||||||
|
char buf[8] = {0};
|
||||||
|
int64_t val = -1;
|
||||||
|
tVariant* pVariant = &pParamElem->pNode->val;
|
||||||
|
if (pVariant->nType == TSDB_DATA_TYPE_BIGINT) {
|
||||||
|
tVariantDump(pVariant, buf, TSDB_DATA_TYPE_BIGINT, true);
|
||||||
|
val = GET_INT64_VAL(buf);
|
||||||
|
}
|
||||||
|
if (val == 1) {
|
||||||
|
index = (SColumnIndex){0, PRIMARYKEY_TIMESTAMP_COL_INDEX};
|
||||||
|
int32_t size = tDataTypeDesc[TSDB_DATA_TYPE_BIGINT].nSize;
|
||||||
|
pExpr = tscSqlExprAppend(pQueryInfo, functionID, &index, TSDB_DATA_TYPE_BIGINT, size, size, false);
|
||||||
|
} else {
|
||||||
|
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// count the number of meters created according to the super table
|
// count the number of meters created according to the super table
|
||||||
if (getColumnIndexByName(pCmd, pToken, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
|
if (getColumnIndexByName(pCmd, pToken, pQueryInfo, &index) != TSDB_CODE_SUCCESS) {
|
||||||
|
|
|
@ -52,6 +52,12 @@ if $data00 != $rowNum then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
sql select count(1) from $tb
|
||||||
|
print ===> select count(1) from $tb => $data00
|
||||||
|
if $data00 != $rowNum then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
sql select count(tbcol) from $tb
|
sql select count(tbcol) from $tb
|
||||||
print ===> $data00
|
print ===> $data00
|
||||||
if $data00 != $rowNum then
|
if $data00 != $rowNum then
|
||||||
|
@ -102,13 +108,20 @@ if $data00 != $totalNum then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
print =============== step8
|
||||||
|
sql select count(1) from $mt
|
||||||
|
print ===> $data00
|
||||||
|
if $data00 != $totalNum then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
sql select count(tbcol) from $mt
|
sql select count(tbcol) from $mt
|
||||||
print ===> $data00
|
print ===> $data00
|
||||||
if $data00 != $totalNum then
|
if $data00 != $totalNum then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
print =============== step8
|
print =============== step10
|
||||||
sql select count(tbcol) as c from $mt where ts < now + 4m
|
sql select count(tbcol) as c from $mt where ts < now + 4m
|
||||||
print ===> $data00
|
print ===> $data00
|
||||||
if $data00 != 50 then
|
if $data00 != 50 then
|
||||||
|
|
Loading…
Reference in New Issue