提交 18c1fba0 编写于 作者: X xywang

[TD-2573]<feature>: enhanced ceil, floor and round functions

上级 b005dad8
......@@ -3483,6 +3483,7 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool
int32_t scalarUdf = 0;
int32_t prjNum = 0;
int32_t aggNum = 0;
int32_t scalNum = 0;
size_t numOfExpr = tscNumOfExprs(pQueryInfo);
assert(numOfExpr > 0);
......@@ -3514,6 +3515,10 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool
++prjNum;
}
if (functionId == TSDB_FUNC_CEIL || functionId == TSDB_FUNC_FLOOR || functionId == TSDB_FUNC_ROUND) {
++scalNum;
}
if (functionId == TSDB_FUNC_PRJ && (pExpr1->base.colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX || TSDB_COL_IS_UD_COL(pExpr1->base.colInfo.flag))) {
continue;
}
......@@ -3535,15 +3540,19 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery, bool
}
}
aggNum = (int32_t)size - prjNum - aggUdf - scalarUdf;
aggNum = (int32_t)size - prjNum - scalNum - aggUdf - scalarUdf;
assert(aggNum >= 0);
if (aggUdf > 0 && (prjNum > 0 || aggNum > 0 || scalarUdf > 0)) {
if (aggUdf > 0 && (prjNum > 0 || aggNum > 0 || scalNum > 0 || scalarUdf > 0)) {
return false;
}
if (scalarUdf > 0 && aggNum > 0) {
if (scalarUdf > 0 && (aggNum > 0 || scalNum > 0)) {
return false;
}
if (aggNum > 0 && scalNum > 0) {
return false;
}
......@@ -6818,13 +6827,21 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) {
* if numOfSelectivity equals to 0, it is a super table projection query
*/
if (numOfSelectivity == 1 || numOfScalar == 1) {
if (numOfSelectivity == numOfScalar) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
doUpdateSqlFunctionForTagPrj(pQueryInfo);
int32_t code = doUpdateSqlFunctionForColPrj(pQueryInfo);
if (code != TSDB_CODE_SUCCESS) {
if (numOfSelectivity == 1 && code != TSDB_CODE_SUCCESS) {
return code;
}
} else if (numOfSelectivity > 1 || numOfScalar > 1) {
if (numOfSelectivity > 1 && numOfScalar > 1) {
return TSDB_CODE_TSC_INVALID_OPERATION;
}
/*
* If more than one selectivity functions exist, all the selectivity functions must be last_row.
* Otherwise, return with error code.
......@@ -6846,7 +6863,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) {
doUpdateSqlFunctionForTagPrj(pQueryInfo);
int32_t code = doUpdateSqlFunctionForColPrj(pQueryInfo);
if (code != TSDB_CODE_SUCCESS) {
if (numOfSelectivity == 1 && code != TSDB_CODE_SUCCESS) {
return code;
}
}
......@@ -6856,7 +6873,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, char* msg) {
return invalidOperationMsg(msg, msg2);
}
if (numOfAggregation > 0 || numOfScalar > 0 || numOfSelectivity > 0) {
if (numOfAggregation > 0 || numOfSelectivity > 0) {
// clear the projection type flag
pQueryInfo->type &= (~TSDB_QUERY_TYPE_PROJECTION_QUERY);
int32_t code = doUpdateSqlFunctionForColPrj(pQueryInfo);
......
......@@ -70,14 +70,14 @@ extern "C" {
#define TSDB_FUNC_DERIVATIVE 32
#define TSDB_FUNC_BLKINFO 33
#define TSDB_FUNC_HISTOGRAM 34
#define TSDB_FUNC_HLL 35
#define TSDB_FUNC_MODE 36
#define TSDB_FUNC_SAMPLE 37
#define TSDB_FUNC_CEIL 38
#define TSDB_FUNC_FLOOR 39
#define TSDB_FUNC_ROUND 40
#define TSDB_FUNC_CEIL 34
#define TSDB_FUNC_FLOOR 35
#define TSDB_FUNC_ROUND 36
#define TSDB_FUNC_HISTOGRAM 37
#define TSDB_FUNC_HLL 38
#define TSDB_FUNC_MODE 39
#define TSDB_FUNC_SAMPLE 40
#define TSDB_FUNC_MAVG 41
#define TSDB_FUNC_CSUM 42
......
......@@ -413,13 +413,7 @@ int32_t isValidFunction(const char* name, int32_t len) {
continue;
}
if (strncasecmp(aAggs[i].name, name, len) == 0 &&
aAggs[i].init != NULL &&
aAggs[i].xFunction != NULL &&
aAggs[i].xFinalize != NULL &&
aAggs[i].mergeFunc != NULL &&
aAggs[i].dataReqFunc != NULL)
{
if (strncasecmp(aAggs[i].name, name, len) == 0) {
return i;
}
}
......@@ -4613,8 +4607,8 @@ int32_t functionCompatList[] = {
4, -1, -1, 1, 1, 1, 1, 1, 1, -1,
// tag, colprj, tagprj, arithmetic, diff, first_dist, last_dist, stddev_dst, interp rate irate
1, 1, 1, 1, -1, 1, 1, 1, 5, 1, 1,
// tid_tag, derivative, blk_info
6, 8, 7,
// tid_tag, derivative, blk_info, histogram,hll, mode, sample, ceil, floor, round
6, 8, 7, -1, -1, -1, -1, 1, 1, 1
};
SAggFunctionInfo aAggs[] = {{
......@@ -5029,55 +5023,7 @@ SAggFunctionInfo aAggs[] = {{
dataBlockRequired,
},
{
// TODO 34
"histogram",
TSDB_FUNC_HISTOGRAM,
TSDB_FUNC_HISTOGRAM,
TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS,
NULL,
NULL,
NULL,
NULL,
NULL
},
{
// TODO 35
"hll",
TSDB_FUNC_HLL,
TSDB_FUNC_HLL,
TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS,
NULL,
NULL,
NULL,
NULL,
NULL
},
{
// TODO 36
"mode",
TSDB_FUNC_MODE,
TSDB_FUNC_MODE,
TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS,
NULL,
NULL,
NULL,
NULL,
NULL
},
{
// TODO 37
"sample",
TSDB_FUNC_SAMPLE,
TSDB_FUNC_SAMPLE,
TSDB_FUNCSTATE_MO | TSDB_FUNCSTATE_STABLE | TSDB_FUNCSTATE_NEED_TS,
NULL,
NULL,
NULL,
NULL,
NULL
},
{
// 38
// 34
"ceil",
TSDB_FUNC_CEIL,
TSDB_FUNC_CEIL,
......@@ -5089,7 +5035,7 @@ SAggFunctionInfo aAggs[] = {{
dataBlockRequired
},
{
// 39
// 35
"floor",
TSDB_FUNC_FLOOR,
TSDB_FUNC_FLOOR,
......@@ -5101,7 +5047,7 @@ SAggFunctionInfo aAggs[] = {{
dataBlockRequired
},
{
// 40
// 36
"round",
TSDB_FUNC_ROUND,
TSDB_FUNC_ROUND,
......
......@@ -162,8 +162,44 @@ print ===> $data10
if $data10 != 0 then
return -1
endi
sql select ts, ceil(c2) from $tb
sql select c2, ceil(c2) from $tb
sql select c2, c3, ceil(c2) from $tb
sql select ts, c2, c3, ceil(c2) from $tb
sql select ceil(c2), ceil(c6) from $tb
sql select ceil(c2) from $mt
sql select ts, ceil(c2), ceil(c6) from $tb
sql select c2, ceil(c2), ceil(c6) from $tb
sql select c2, c3, ceil(c2), ceil(c6) from $tb
sql select ts, c2, c3, ceil(c2), ceil(c6) from $tb
sql select ceil(c2), floor(c2), round(c2) from $tb
sql select ts, ceil(c2), floor(c2), round(c2) from $tb
sql select c2, ceil(c2), floor(c2), round(c2) from $tb
sql select c2, c3, ceil(c2), floor(c2), round(c2) from $tb
sql select ts, c2, c3, ceil(c2), floor(c2), round(c2) from $tb
sql select ts, ceil(c2) from $mt
sql select c2, ceil(c2) from $mt
sql select c2, c3, ceil(c2) from $mt
sql select ts, c2, c3, ceil(c2) from $mt
sql select ceil(c2), ceil(c6) from $mt
sql select ts, ceil(c2), ceil(c6) from $mt
sql select c2, ceil(c2), ceil(c6) from $mt
sql select c2, c3, ceil(c2), ceil(c6) from $mt
sql select ts, c2, c3, ceil(c2), ceil(c6) from $mt
sql select ceil(c2), ceil(c2), round(c2) from $mt
sql select ts, ceil(c2), floor(c2), round(c2) from $mt
sql select c2, ceil(c2), floor(c2), round(c2) from $mt
sql select c2, c3, ceil(c2), floor(c2), round(c2) from $mt
sql select ts, c2, c3, ceil(c2), floor(c2), round(c2) from $mt
sql_error select ceil(c7) from $tb
sql_error select ceil(c8) from $tb
sql_error select ceil(c9) from $tb
......
......@@ -162,8 +162,44 @@ print ===> $data10
if $data10 != 0 then
return -1
endi
sql select ts, floor(c2) from $tb
sql select c2, floor(c2) from $tb
sql select c2, c3, floor(c2) from $tb
sql select ts, c2, c3, floor(c2) from $tb
sql select floor(c2), floor(c6) from $tb
sql select floor(c2) from $mt
sql select ts, floor(c2), floor(c6) from $tb
sql select c2, floor(c2), floor(c6) from $tb
sql select c2, c3, floor(c2), floor(c6) from $tb
sql select ts, c2, c3, floor(c2), floor(c6) from $tb
sql select ceil(c2), floor(c2), round(c2) from $tb
sql select ts, ceil(c2), floor(c2), round(c2) from $tb
sql select c2, ceil(c2), floor(c2), round(c2) from $tb
sql select c2, c3, ceil(c2), floor(c2), round(c2) from $tb
sql select ts, c2, c3, ceil(c2), floor(c2), round(c2) from $tb
sql select ts, floor(c2) from $mt
sql select c2, floor(c2) from $mt
sql select c2, c3, floor(c2) from $mt
sql select ts, c2, c3, floor(c2) from $mt
sql select floor(c2), floor(c6) from $mt
sql select ts, floor(c2), floor(c6) from $mt
sql select c2, floor(c2), floor(c6) from $mt
sql select c2, c3, floor(c2), floor(c6) from $mt
sql select ts, c2, c3, floor(c2), floor(c6) from $mt
sql select ceil(c2), floor(c2), round(c2) from $mt
sql select ts, ceil(c2), floor(c2), round(c2) from $mt
sql select c2, ceil(c2), floor(c2), round(c2) from $mt
sql select c2, c3, ceil(c2), floor(c2), round(c2) from $mt
sql select ts, c2, c3, ceil(c2), floor(c2), round(c2) from $mt
sql_error select floor(c7) from $tb
sql_error select floor(c8) from $tb
sql_error select floor(c9) from $tb
......
......@@ -162,8 +162,44 @@ print ===> $data10
if $data10 != 0 then
return -1
endi
sql select ts, round(c2) from $tb
sql select c2, round(c2) from $tb
sql select c2, c3, round(c2) from $tb
sql select ts, c2, c3, round(c2) from $tb
sql select round(c2), round(c6) from $tb
sql select round(c2) from $mt
sql select ts, round(c2), round(c6) from $tb
sql select c2, round(c2), round(c6) from $tb
sql select c2, c3, round(c2), round(c6) from $tb
sql select ts, c2, c3, round(c2), round(c6) from $tb
sql select ceil(c2), floor(c2), round(c2) from $tb
sql select ts, ceil(c2), floor(c2), round(c2) from $tb
sql select c2, ceil(c2), floor(c2), round(c2) from $tb
sql select c2, c3, ceil(c2), floor(c2), round(c2) from $tb
sql select ts, c2, c3, ceil(c2), floor(c2), round(c2) from $tb
sql select ts, round(c2) from $mt
sql select c2, round(c2) from $mt
sql select c2, c3, round(c2) from $mt
sql select ts, c2, c3, round(c2) from $mt
sql select round(c2), round(c6) from $mt
sql select ts, round(c2), round(c6) from $mt
sql select c2, round(c2), round(c6) from $mt
sql select c2, c3, round(c2), round(c6) from $mt
sql select ts, c2, c3, round(c2), round(c6) from $mt
sql select ceil(c2), floor(c2), round(c2) from $mt
sql select ts, ceil(c2), floor(c2), round(c2) from $mt
sql select c2, ceil(c2), floor(c2), round(c2) from $mt
sql select c2, c3, ceil(c2), floor(c2), round(c2) from $mt
sql select ts, c2, c3, ceil(c2), floor(c2), round(c2) from $mt
sql_error select round(c7) from $tb
sql_error select round(c8) from $tb
sql_error select round(c9) from $tb
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册