Merge pull request #16825 from taosdata/fix/maxmin_type
fix(query): restrict max/min function input type not including timestamp type
This commit is contained in:
commit
06e38c1dcc
|
@ -917,7 +917,7 @@ SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
|
||||
**Return value type**:Same as the data type of the column being operated upon
|
||||
|
||||
**Applicable data types**: Numeric, Timestamp
|
||||
**Applicable data types**: Numeric
|
||||
|
||||
**Applicable table types**: standard tables and supertables
|
||||
|
||||
|
@ -932,7 +932,7 @@ SELECT MIN(field_name) FROM {tb_name | stb_name} [WHERE clause];
|
|||
|
||||
**Return value type**:Same as the data type of the column being operated upon
|
||||
|
||||
**Applicable data types**: Numeric, Timestamp
|
||||
**Applicable data types**: Numeric
|
||||
|
||||
**Applicable table types**: standard tables and supertables
|
||||
|
||||
|
|
|
@ -918,7 +918,7 @@ SELECT MAX(field_name) FROM { tb_name | stb_name } [WHERE clause];
|
|||
|
||||
**返回数据类型**:同应用的字段。
|
||||
|
||||
**适用数据类型**:数值类型,时间戳类型。
|
||||
**适用数据类型**:数值类型。
|
||||
|
||||
**适用于**:表和超级表。
|
||||
|
||||
|
@ -933,7 +933,7 @@ SELECT MIN(field_name) FROM {tb_name | stb_name} [WHERE clause];
|
|||
|
||||
**返回数据类型**:同应用的字段。
|
||||
|
||||
**适用数据类型**:数值类型,时间戳类型。
|
||||
**适用数据类型**:数值类型。
|
||||
|
||||
**适用于**:表和超级表。
|
||||
|
||||
|
|
|
@ -311,22 +311,6 @@ static int32_t translateInOutStr(SFunctionNode* pFunc, char* pErrBuf, int32_t le
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateMinMax(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
if (1 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
uint8_t paraType = ((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType.type;
|
||||
if (!IS_TIMESTAMP_TYPE(paraType) && !IS_NUMERIC_TYPE(paraType) && !IS_NULL_TYPE(paraType)) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
} else if (IS_NULL_TYPE(paraType)) {
|
||||
paraType = TSDB_DATA_TYPE_BIGINT;
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType){.bytes = tDataTypes[paraType].bytes, .type = paraType};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateTrimStr(SFunctionNode* pFunc, char* pErrBuf, int32_t len, bool isLtrim) {
|
||||
if (1 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
|
@ -2076,7 +2060,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "min",
|
||||
.type = FUNCTION_TYPE_MIN,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED | FUNC_MGT_SELECT_FUNC,
|
||||
.translateFunc = translateMinMax,
|
||||
.translateFunc = translateInOutNum,
|
||||
.dataRequiredFunc = statisDataRequired,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = minmaxFunctionSetup,
|
||||
|
@ -2091,7 +2075,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.name = "max",
|
||||
.type = FUNCTION_TYPE_MAX,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED | FUNC_MGT_SELECT_FUNC,
|
||||
.translateFunc = translateMinMax,
|
||||
.translateFunc = translateInOutNum,
|
||||
.dataRequiredFunc = statisDataRequired,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = minmaxFunctionSetup,
|
||||
|
|
|
@ -1204,7 +1204,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
|||
pBuf->tuplePos = saveTupleData(pCtx, index, pCtx->pSrcBlock);
|
||||
}
|
||||
} else {
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type) || IS_TIMESTAMP_TYPE(type)) {
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type)) {
|
||||
int64_t prev = 0;
|
||||
GET_TYPED_DATA(prev, int64_t, type, &pBuf->v);
|
||||
|
||||
|
@ -1263,7 +1263,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
|||
int32_t start = pInput->startRowIndex;
|
||||
int32_t numOfRows = pInput->numOfRows;
|
||||
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type) || IS_TIMESTAMP_TYPE(type) || type == TSDB_DATA_TYPE_BOOL) {
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type) || type == TSDB_DATA_TYPE_BOOL) {
|
||||
if (type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_BOOL) {
|
||||
int8_t* pData = (int8_t*)pCol->pData;
|
||||
int8_t* val = (int8_t*)&pBuf->v;
|
||||
|
@ -1357,7 +1357,7 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
|||
|
||||
numOfElems += 1;
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_BIGINT || type == TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
} else if (type == TSDB_DATA_TYPE_BIGINT) {
|
||||
int64_t* pData = (int64_t*)pCol->pData;
|
||||
int64_t* val = (int64_t*)&pBuf->v;
|
||||
|
||||
|
|
|
@ -38,18 +38,7 @@ class TDTestCase:
|
|||
elif i>=9:
|
||||
tdSql.checkData(0, 0, np.max(floatData))
|
||||
|
||||
tdSql.query(f"select max(now()) from {dbname}.stb_1")
|
||||
tdSql.checkRows(1)
|
||||
|
||||
tdSql.query(f"select last(ts) from {dbname}.stb_1")
|
||||
lastTs = tdSql.getData(0, 0)
|
||||
tdSql.query(f"select max(ts) from {dbname}.stb_1")
|
||||
tdSql.checkData(0, 0, lastTs)
|
||||
|
||||
tdSql.query(f"select last(ts) from {dbname}.stb")
|
||||
lastTs = tdSql.getData(0, 0)
|
||||
tdSql.query(f"select max(ts) from {dbname}.stb")
|
||||
tdSql.checkData(0, 0, lastTs)
|
||||
tdSql.error(f"select max(now()) from {dbname}.stb_1")
|
||||
|
||||
tdSql.query(f"select max(col1) from {dbname}.stb_1 where col2<=5")
|
||||
tdSql.checkData(0,0,5)
|
||||
|
@ -78,13 +67,7 @@ class TDTestCase:
|
|||
elif i>=9:
|
||||
tdSql.checkData(0, 0, np.max(floatData))
|
||||
|
||||
tdSql.query(f"select max(now()) from {dbname}.ntb")
|
||||
tdSql.checkRows(1)
|
||||
|
||||
tdSql.query(f"select last(ts) from {dbname}.ntb")
|
||||
lastTs = tdSql.getData(0, 0)
|
||||
tdSql.query(f"select max(ts) from {dbname}.ntb")
|
||||
tdSql.checkData(0, 0, lastTs)
|
||||
tdSql.error(f"select max(now()) from {dbname}.ntb")
|
||||
|
||||
tdSql.query(f"select max(col1) from {dbname}.ntb where col2<=5")
|
||||
tdSql.checkData(0,0,5)
|
||||
|
|
|
@ -37,6 +37,8 @@ class TDTestCase:
|
|||
floatData.append(i + 0.1)
|
||||
|
||||
# max verifacation
|
||||
tdSql.error(f"select min(now()) from {dbname}.stb_1")
|
||||
tdSql.error(f"select min(ts) from {dbname}.stb_1")
|
||||
tdSql.error(f"select min(col7) from {dbname}.stb_1")
|
||||
tdSql.error(f"select min(col8) from {dbname}.stb_1")
|
||||
tdSql.error(f"select min(col9) from {dbname}.stb_1")
|
||||
|
@ -67,20 +69,9 @@ class TDTestCase:
|
|||
tdSql.query(f"select min(col1) from {dbname}.stb_1 where col2>=5")
|
||||
tdSql.checkData(0,0,5)
|
||||
|
||||
tdSql.query(f"select min(now()) from {dbname}.stb_1")
|
||||
tdSql.checkRows(1)
|
||||
|
||||
tdSql.query(f"select first(ts) from {dbname}.stb_1")
|
||||
firstTs = tdSql.getData(0, 0)
|
||||
tdSql.query(f"select min(ts) from {dbname}.stb_1")
|
||||
tdSql.checkData(0, 0, firstTs)
|
||||
|
||||
tdSql.query(f"select first(ts) from {dbname}.stb_1")
|
||||
firstTs = tdSql.getData(0, 0)
|
||||
tdSql.query(f"select min(ts) from {dbname}.stb_1")
|
||||
tdSql.checkData(0, 0, firstTs)
|
||||
|
||||
|
||||
tdSql.error(f"select min(now()) from {dbname}.stb_1")
|
||||
tdSql.error(f"select min(ts) from {dbname}.stb_1")
|
||||
tdSql.error(f"select min(col7) from {dbname}.stb_1")
|
||||
tdSql.error(f"select min(col8) from {dbname}.stb_1")
|
||||
tdSql.error(f"select min(col9) from {dbname}.stb_1")
|
||||
|
@ -111,19 +102,8 @@ class TDTestCase:
|
|||
tdSql.query(f"select min(col1) from {dbname}.stb where col2>=5")
|
||||
tdSql.checkData(0,0,5)
|
||||
|
||||
tdSql.query(f"select min(now()) from {dbname}.stb_1")
|
||||
tdSql.checkRows(1)
|
||||
|
||||
tdSql.query(f"select first(ts) from {dbname}.stb_1")
|
||||
firstTs = tdSql.getData(0, 0)
|
||||
tdSql.query(f"select min(ts) from {dbname}.stb_1")
|
||||
tdSql.checkData(0, 0, firstTs)
|
||||
|
||||
tdSql.query(f"select first(ts) from {dbname}.stb_1")
|
||||
firstTs = tdSql.getData(0, 0)
|
||||
tdSql.query(f"select min(ts) from {dbname}.stb_1")
|
||||
tdSql.checkData(0, 0, firstTs)
|
||||
|
||||
tdSql.error(f"select min(now()) from {dbname}.stb_1")
|
||||
tdSql.error(f"select min(ts) from {dbname}.stb_1")
|
||||
tdSql.error(f"select min(col7) from {dbname}.ntb")
|
||||
tdSql.error(f"select min(col8) from {dbname}.ntb")
|
||||
tdSql.error(f"select min(col9) from {dbname}.ntb")
|
||||
|
@ -154,19 +134,6 @@ class TDTestCase:
|
|||
tdSql.query(f"select min(col1) from {dbname}.ntb where col2>=5")
|
||||
tdSql.checkData(0,0,5)
|
||||
|
||||
tdSql.query(f"select min(now()) from {dbname}.stb_1")
|
||||
tdSql.checkRows(1)
|
||||
|
||||
tdSql.query(f"select first(ts) from {dbname}.stb_1")
|
||||
firstTs = tdSql.getData(0, 0)
|
||||
tdSql.query(f"select min(ts) from {dbname}.stb_1")
|
||||
tdSql.checkData(0, 0, firstTs)
|
||||
|
||||
tdSql.query(f"select first(ts) from {dbname}.stb_1")
|
||||
firstTs = tdSql.getData(0, 0)
|
||||
tdSql.query(f"select min(ts) from {dbname}.stb_1")
|
||||
tdSql.checkData(0, 0, firstTs)
|
||||
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
|
|
Loading…
Reference in New Issue