未验证 提交 ddce7da2 编写于 作者: M Minglei Jin 提交者: GitHub

Merge pull request #13903 from taosdata/fix/TS-1612

enh: optimize diff_function and remove assert 
......@@ -3645,7 +3645,6 @@ static void diff_function(SQLFunctionCtx *pCtx) {
SDiffFuncInfo *pDiffInfo = GET_ROWCELL_INTERBUF(pResInfo);
void *data = GET_INPUT_DATA_LIST(pCtx);
bool isFirstBlock = (pDiffInfo->valueAssigned == false);
int32_t notNullElems = 0;
......@@ -3668,7 +3667,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if (pDiffInfo->valueAssigned) {
int32_t diff = (int32_t)(pData[i] - pDiffInfo->i64Prev);
if (diff >= 0 || !pDiffInfo->ignoreNegative) {
*pOutput = (int32_t)(pData[i] - pDiffInfo->i64Prev); // direct previous may be null
*pOutput = diff;
*pTimestamp = (tsList != NULL)? tsList[i]:0;
pOutput += 1;
pTimestamp += 1;
......@@ -3694,7 +3693,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if (pDiffInfo->valueAssigned) {
int64_t diff = pData[i] - pDiffInfo->i64Prev;
if (diff >= 0 || !pDiffInfo->ignoreNegative) {
*pOutput = pData[i] - pDiffInfo->i64Prev; // direct previous may be null
*pOutput = diff;
*pTimestamp = (tsList != NULL)? tsList[i]:0;
pOutput += 1;
pTimestamp += 1;
......@@ -3720,7 +3719,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if (pDiffInfo->valueAssigned) {
double diff = pData[i] - pDiffInfo->d64Prev;
if (diff >= 0 || !pDiffInfo->ignoreNegative) {
SET_DOUBLE_VAL(pOutput, pData[i] - pDiffInfo->d64Prev); // direct previous may be null
SET_DOUBLE_VAL(pOutput, diff);
*pTimestamp = (tsList != NULL)? tsList[i]:0;
pOutput += 1;
pTimestamp += 1;
......@@ -3746,7 +3745,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if (pDiffInfo->valueAssigned) {
float diff = (float)(pData[i] - pDiffInfo->d64Prev);
if (diff >= 0 || !pDiffInfo->ignoreNegative) {
*pOutput = (float)(pData[i] - pDiffInfo->d64Prev);
*pOutput = diff;
*pTimestamp = (tsList != NULL)? tsList[i]:0;
pOutput += 1;
pTimestamp += 1;
......@@ -3772,7 +3771,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if (pDiffInfo->valueAssigned) {
int16_t diff = (int16_t)(pData[i] - pDiffInfo->i64Prev);
if (diff >= 0 || !pDiffInfo->ignoreNegative) {
*pOutput = (int16_t)(pData[i] - pDiffInfo->i64Prev);
*pOutput = diff;
*pTimestamp = (tsList != NULL)? tsList[i]:0;
pOutput += 1;
pTimestamp += 1;
......@@ -3798,7 +3797,7 @@ static void diff_function(SQLFunctionCtx *pCtx) {
if (pDiffInfo->valueAssigned) {
int8_t diff = (int8_t)(pData[i] - pDiffInfo->i64Prev);
if (diff >= 0 || !pDiffInfo->ignoreNegative) {
*pOutput = (int8_t)(pData[i] - pDiffInfo->i64Prev);
*pOutput = diff;
*pTimestamp = (tsList != NULL)? tsList[i]:0;
pOutput += 1;
pTimestamp += 1;
......@@ -3816,23 +3815,15 @@ static void diff_function(SQLFunctionCtx *pCtx) {
qError("error input type");
}
// initial value is not set yet
if (!pDiffInfo->valueAssigned || notNullElems <= 0) {
/*
* 1. current block and blocks before are full of null
* 2. current block may be null value
*/
assert(pCtx->hasNull);
} else {
if (notNullElems > 0) {
for (int t = 0; t < pCtx->tagInfo.numOfTagCols; ++t) {
SQLFunctionCtx* tagCtx = pCtx->tagInfo.pTagCtxList[t];
if (tagCtx->functionId == TSDB_FUNC_TAG_DUMMY) {
aAggs[TSDB_FUNC_TAGPRJ].xFunction(tagCtx);
}
}
int32_t forwardStep = (isFirstBlock) ? notNullElems : notNullElems;
GET_RES_INFO(pCtx)->numOfRes += forwardStep;
GET_RES_INFO(pCtx)->numOfRes += notNullElems;
}
}
......
......@@ -16,6 +16,7 @@ import taos
from util.log import *
from util.cases import *
from util.sql import *
from util.dnodes import *
import numpy as np
......@@ -156,7 +157,25 @@ class TDTestCase:
tdSql.error("select diff(col) from st group by dev")
tdSql.error("select diff(col) from st group by col")
# TS-1612
os.system("tar -zxf %s/functions/data.tar.gz" % os.getcwd())
tdSql.execute("create database radb")
tdSql.execute("use radb")
tdSql.execute("CREATE TABLE `vehicle_automode` (`time` TIMESTAMP,`auto_ctl_odom` INT) TAGS (`mac_address` BINARY(30))")
tdSql.execute("CREATE TABLE `va_00545a230327` USING `vehicle_automode` TAGS ('00545a230327')")
tdSql.execute("insert into va_00545a230327 file 'data/va_00545a230327.csv' ")
tdSql.query("select * from vehicle_automode")
rows = tdSql.queryRows
tdSql.query("select diff(auto_ctl_odom,1) as aco from radb.vehicle_automode GROUP BY tbname")
tdSql.checkRows(rows - 1)
os.system("rm -rf data")
tdDnodes.stop(1)
tdDnodes.start(1)
tdSql.query("select diff(auto_ctl_odom,1) as aco from radb.vehicle_automode GROUP BY tbname")
tdSql.checkRows(rows - 1)
def stop(self):
tdSql.close()
tdLog.success("%s successfully executed" % __file__)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册