[td-4723]<fix>: fix bug in derivative function.
This commit is contained in:
parent
0cbe5463e6
commit
3e65aedae2
|
@ -1800,7 +1800,6 @@ int32_t validateSelectNodeList(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SArray* pS
|
||||||
assert(pSelNodeList != NULL && pCmd != NULL);
|
assert(pSelNodeList != NULL && pCmd != NULL);
|
||||||
|
|
||||||
const char* msg1 = "too many items in selection clause";
|
const char* msg1 = "too many items in selection clause";
|
||||||
|
|
||||||
const char* msg2 = "functions or others can not be mixed up";
|
const char* msg2 = "functions or others can not be mixed up";
|
||||||
const char* msg3 = "not support query expression";
|
const char* msg3 = "not support query expression";
|
||||||
const char* msg4 = "only support distinct one tag";
|
const char* msg4 = "only support distinct one tag";
|
||||||
|
@ -2726,6 +2725,8 @@ void getColumnName(tSqlExprItem* pItem, char* resultFieldName, char* rawName, in
|
||||||
strncpy(rawName, pItem->pNode->token.z, len);
|
strncpy(rawName, pItem->pNode->token.z, len);
|
||||||
|
|
||||||
if (pItem->aliasName != NULL) {
|
if (pItem->aliasName != NULL) {
|
||||||
|
int32_t aliasNameLen = (int32_t) strlen(pItem->aliasName);
|
||||||
|
len = (aliasNameLen < nameLength)? aliasNameLen:nameLength;
|
||||||
strncpy(resultFieldName, pItem->aliasName, len);
|
strncpy(resultFieldName, pItem->aliasName, len);
|
||||||
} else {
|
} else {
|
||||||
strncpy(resultFieldName, rawName, len);
|
strncpy(resultFieldName, rawName, len);
|
||||||
|
@ -7752,6 +7753,7 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
|
||||||
const char* msg4 = "interval query not supported, since the result of sub query not include valid timestamp column";
|
const char* msg4 = "interval query not supported, since the result of sub query not include valid timestamp column";
|
||||||
const char* msg5 = "only tag query not compatible with normal column filter";
|
const char* msg5 = "only tag query not compatible with normal column filter";
|
||||||
const char* msg6 = "not support stddev/percentile in outer query yet";
|
const char* msg6 = "not support stddev/percentile in outer query yet";
|
||||||
|
const char* msg7 = "drivative requires timestamp column exists in subquery";
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
||||||
|
@ -7801,13 +7803,23 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo derivate funtion requires ts column exists in subquery
|
||||||
|
STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta;
|
||||||
|
SSchema* pSchema = tscGetTableColumnSchema(pTableMeta, 0);
|
||||||
|
|
||||||
|
if (tscNumOfExprs(pQueryInfo) > 1) {
|
||||||
|
SExprInfo* pExpr = tscExprGet(pQueryInfo, 1);
|
||||||
|
if (pExpr->base.functionId == TSDB_FUNC_DERIVATIVE && pSchema->type != TSDB_DATA_TYPE_TIMESTAMP) {
|
||||||
|
return invalidOperationMsg(tscGetErrorMsgPayload(pCmd), msg7);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// validate the query filter condition info
|
// validate the query filter condition info
|
||||||
if (pSqlNode->pWhere != NULL) {
|
if (pSqlNode->pWhere != NULL) {
|
||||||
if (validateWhereNode(pQueryInfo, &pSqlNode->pWhere, pSql) != TSDB_CODE_SUCCESS) {
|
if (validateWhereNode(pQueryInfo, &pSqlNode->pWhere, pSql) != TSDB_CODE_SUCCESS) {
|
||||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta;
|
|
||||||
if (pTableMeta->tableInfo.precision == TSDB_TIME_PRECISION_MILLI) {
|
if (pTableMeta->tableInfo.precision == TSDB_TIME_PRECISION_MILLI) {
|
||||||
pQueryInfo->window.skey = pQueryInfo->window.skey / 1000;
|
pQueryInfo->window.skey = pQueryInfo->window.skey / 1000;
|
||||||
pQueryInfo->window.ekey = pQueryInfo->window.ekey / 1000;
|
pQueryInfo->window.ekey = pQueryInfo->window.ekey / 1000;
|
||||||
|
@ -7832,7 +7844,6 @@ int32_t validateSqlNode(SSqlObj* pSql, SSqlNode* pSqlNode, SQueryInfo* pQueryInf
|
||||||
}
|
}
|
||||||
|
|
||||||
// set order by info
|
// set order by info
|
||||||
STableMeta* pTableMeta = tscGetMetaInfo(pQueryInfo, 0)->pTableMeta;
|
|
||||||
if (validateOrderbyNode(pCmd, pQueryInfo, pSqlNode, tscGetTableSchema(pTableMeta)) != TSDB_CODE_SUCCESS) {
|
if (validateOrderbyNode(pCmd, pQueryInfo, pSqlNode, tscGetTableSchema(pTableMeta)) != TSDB_CODE_SUCCESS) {
|
||||||
return TSDB_CODE_TSC_INVALID_OPERATION;
|
return TSDB_CODE_TSC_INVALID_OPERATION;
|
||||||
}
|
}
|
||||||
|
|
|
@ -290,8 +290,9 @@ static int taos_options_imp(TSDB_OPTION option, const char *pStr) {
|
||||||
char* defaultLocale = setlocale(LC_CTYPE, "");
|
char* defaultLocale = setlocale(LC_CTYPE, "");
|
||||||
|
|
||||||
// The locale of the current OS does not be set correctly, so the default locale cannot be acquired.
|
// The locale of the current OS does not be set correctly, so the default locale cannot be acquired.
|
||||||
|
// The launch of current system will abort soon.
|
||||||
if (defaultLocale == NULL) {
|
if (defaultLocale == NULL) {
|
||||||
uError("failed to get default locale, please set the correct locale in current OS");
|
tscError("failed to get default locale, please set the correct locale in current OS");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3662,7 +3662,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
|
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
|
||||||
*pOutput = (int32_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null
|
*pOutput = (int32_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null
|
||||||
*pTimestamp = tsList[i];
|
*pTimestamp = (tsList != NULL)? tsList[i]:0;
|
||||||
pOutput += 1;
|
pOutput += 1;
|
||||||
pTimestamp += 1;
|
pTimestamp += 1;
|
||||||
}
|
}
|
||||||
|
@ -3684,7 +3684,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
|
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
|
||||||
*pOutput = pData[i] - pCtx->param[1].i64; // direct previous may be null
|
*pOutput = pData[i] - pCtx->param[1].i64; // direct previous may be null
|
||||||
*pTimestamp = tsList[i];
|
*pTimestamp = (tsList != NULL)? tsList[i]:0;
|
||||||
pOutput += 1;
|
pOutput += 1;
|
||||||
pTimestamp += 1;
|
pTimestamp += 1;
|
||||||
}
|
}
|
||||||
|
@ -3706,7 +3706,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
|
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
|
||||||
*pOutput = pData[i] - pCtx->param[1].dKey; // direct previous may be null
|
*pOutput = pData[i] - pCtx->param[1].dKey; // direct previous may be null
|
||||||
*pTimestamp = tsList[i];
|
*pTimestamp = (tsList != NULL)? tsList[i]:0;
|
||||||
pOutput += 1;
|
pOutput += 1;
|
||||||
pTimestamp += 1;
|
pTimestamp += 1;
|
||||||
}
|
}
|
||||||
|
@ -3728,7 +3728,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
|
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
|
||||||
*pOutput = (float)(pData[i] - pCtx->param[1].dKey); // direct previous may be null
|
*pOutput = (float)(pData[i] - pCtx->param[1].dKey); // direct previous may be null
|
||||||
*pTimestamp = tsList[i];
|
*pTimestamp = (tsList != NULL)? tsList[i]:0;
|
||||||
pOutput += 1;
|
pOutput += 1;
|
||||||
pTimestamp += 1;
|
pTimestamp += 1;
|
||||||
}
|
}
|
||||||
|
@ -3750,7 +3750,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
|
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
|
||||||
*pOutput = (int16_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null
|
*pOutput = (int16_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null
|
||||||
*pTimestamp = tsList[i];
|
*pTimestamp = (tsList != NULL)? tsList[i]:0;
|
||||||
pOutput += 1;
|
pOutput += 1;
|
||||||
pTimestamp += 1;
|
pTimestamp += 1;
|
||||||
}
|
}
|
||||||
|
@ -3773,7 +3773,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
|
||||||
|
|
||||||
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
|
if (pCtx->param[1].nType != INITIAL_VALUE_NOT_ASSIGNED) { // initial value is not set yet
|
||||||
*pOutput = (int8_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null
|
*pOutput = (int8_t)(pData[i] - pCtx->param[1].i64); // direct previous may be null
|
||||||
*pTimestamp = tsList[i];
|
*pTimestamp = (tsList != NULL)? tsList[i]:0;
|
||||||
pOutput += 1;
|
pOutput += 1;
|
||||||
pTimestamp += 1;
|
pTimestamp += 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1080,6 +1080,8 @@ sql insert into t1 values('2020-1-1 1:1:10', 20000);
|
||||||
|
|
||||||
sql_error select derivative(k, 1s, 0) from m1;
|
sql_error select derivative(k, 1s, 0) from m1;
|
||||||
sql_error select derivative(k, 1s, 0) from m1 group by a;
|
sql_error select derivative(k, 1s, 0) from m1 group by a;
|
||||||
|
sql_error select derivative(f1, 1s, 0) from (select k from t1);
|
||||||
|
|
||||||
sql select derivative(k, 1s, 0) from m1 group by tbname
|
sql select derivative(k, 1s, 0) from m1 group by tbname
|
||||||
if $rows != 12 then
|
if $rows != 12 then
|
||||||
return -1
|
return -1
|
||||||
|
@ -1119,4 +1121,6 @@ endi
|
||||||
|
|
||||||
if $data92 != t1 then
|
if $data92 != t1 then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
sql select derivative(test_column_alias_name, 1s, 0) from (select avg(k) test_column_alias_name from t1 interval(1s));
|
||||||
|
|
|
@ -273,4 +273,18 @@ if $data03 != @20-09-15 00:00:00.000@ then
|
||||||
return -1
|
return -1
|
||||||
endi
|
endi
|
||||||
|
|
||||||
|
sql_error select derivative(val, 1s, 0) from (select c1 val from nest_tb0);
|
||||||
|
sql select diff(val) from (select c1 val from nest_tb0);
|
||||||
|
if $rows != 9999 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data00 != @70-01-01 08:00:00.000@ then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
|
if $data01 != 1 then
|
||||||
|
return -1
|
||||||
|
endi
|
||||||
|
|
||||||
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
system sh/exec.sh -n dnode1 -s stop -x SIGINT
|
Loading…
Reference in New Issue