[td-1456]
This commit is contained in:
parent
4d6e0ef40e
commit
4454b077ff
|
@ -2601,7 +2601,7 @@ static bool functionCompatibleCheck(SQueryInfo* pQueryInfo, bool joinQuery) {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (functionId == TSDB_FUNC_PRJ && pExpr1->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX) {
|
||||
if (functionId == TSDB_FUNC_PRJ && (pExpr1->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX || TSDB_COL_IS_UD_COL(pExpr1->colInfo.flag))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -5246,7 +5246,8 @@ static void doUpdateSqlFunctionForTagPrj(SQueryInfo* pQueryInfo) {
|
|||
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
if (pExpr->functionId != TSDB_FUNC_TAG_DUMMY && pExpr->functionId != TSDB_FUNC_TS_DUMMY) {
|
||||
if ((pExpr->functionId != TSDB_FUNC_TAG_DUMMY && pExpr->functionId != TSDB_FUNC_TS_DUMMY) &&
|
||||
!(pExpr->functionId == TSDB_FUNC_PRJ && TSDB_COL_IS_UD_COL(pExpr->colInfo.flag))) {
|
||||
SSchema* pColSchema = &pSchema[pExpr->colInfo.colIndex];
|
||||
getResultDataInfo(pColSchema->type, pColSchema->bytes, pExpr->functionId, (int32_t)pExpr->param[0].i64Key, &pExpr->resType,
|
||||
&pExpr->resBytes, &pExpr->interBytes, tagLength, true);
|
||||
|
@ -5354,16 +5355,23 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd)
|
|||
const char* msg1 = "only one selectivity function allowed in presence of tags function";
|
||||
const char* msg3 = "aggregation function should not be mixed up with projection";
|
||||
|
||||
bool tagColExists = false;
|
||||
bool tagTsColExists = false;
|
||||
int16_t numOfSelectivity = 0;
|
||||
int16_t numOfAggregation = 0;
|
||||
|
||||
// todo is 0??
|
||||
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0);
|
||||
bool isSTable = UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo);
|
||||
if (!isSTable) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
size_t numOfExprs = taosArrayGetSize(pQueryInfo->exprList);
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
SSqlExpr* pExpr = taosArrayGetP(pQueryInfo->exprList, i);
|
||||
if (pExpr->functionId == TSDB_FUNC_TAGPRJ ||
|
||||
(pExpr->functionId == TSDB_FUNC_PRJ && pExpr->colInfo.colId == PRIMARYKEY_TIMESTAMP_COL_INDEX)) {
|
||||
tagColExists = true; // selectivity + ts/tag column
|
||||
tagTsColExists = true; // selectivity + ts/tag column
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -5384,7 +5392,7 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd)
|
|||
}
|
||||
}
|
||||
|
||||
if (tagColExists) { // check if the selectivity function exists
|
||||
if (tagTsColExists) { // check if the selectivity function exists
|
||||
// When the tag projection function on tag column that is not in the group by clause, aggregation function and
|
||||
// selectivity function exist in select clause is not allowed.
|
||||
if (numOfAggregation > 0) {
|
||||
|
@ -5407,13 +5415,16 @@ static int32_t checkUpdateTagPrjFunctions(SQueryInfo* pQueryInfo, SSqlCmd* pCmd)
|
|||
* Otherwise, return with error code.
|
||||
*/
|
||||
for (int32_t i = 0; i < numOfExprs; ++i) {
|
||||
|
||||
int16_t functionId = tscSqlExprGet(pQueryInfo, i)->functionId;
|
||||
if (functionId == TSDB_FUNC_TAGPRJ) {
|
||||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, i);
|
||||
int16_t functionId = pExpr->functionId;
|
||||
if (functionId == TSDB_FUNC_TAGPRJ || (aAggs[functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (((aAggs[functionId].nStatus & TSDB_FUNCSTATE_SELECTIVITY) != 0) && (functionId != TSDB_FUNC_LAST_ROW)) {
|
||||
if ((functionId == TSDB_FUNC_LAST_ROW) ||
|
||||
(functionId == TSDB_FUNC_LAST_DST && (pExpr->colInfo.flag & TSDB_COL_NULL) != 0)) {
|
||||
// do nothing
|
||||
} else {
|
||||
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,10 +62,9 @@ SSchema tGetUserSpecifiedColumnSchema(tVariant* pVal, SStrToken* exprStr, const
|
|||
if (name != NULL) {
|
||||
tstrncpy(s.name, name, sizeof(s.name));
|
||||
} else {
|
||||
size_t len = strdequote(exprStr->z);
|
||||
size_t tlen = MIN(sizeof(s.name), len + 1);
|
||||
|
||||
size_t tlen = MIN(sizeof(s.name), exprStr->n + 1);
|
||||
tstrncpy(s.name, exprStr->z, tlen);
|
||||
strdequote(s.name);
|
||||
}
|
||||
|
||||
return s;
|
||||
|
|
|
@ -172,3 +172,34 @@ sql select last_row(*) from m1 where tbname in ('t1')
|
|||
if $rows != 0 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql insert into t1 values('2019-1-1 1:1:1', 1);
|
||||
print ===================> last_row query against normal table along with ts/tbname
|
||||
sql select last_row(*),ts,'k' from t1;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print ===================> last_row + user-defined column + normal tables
|
||||
sql select last_row(ts), 'abc', 1234.9384, ts from t1
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data02 != 'abc' then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data03 != 1234.938400000 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
if $data04 != @2019-01-01 01:01:01.000@ then
|
||||
return -1
|
||||
endi
|
||||
|
||||
print ===================> last_row + stable + ts/tag column + condition + udf
|
||||
sql select last_row(*), ts, 'abc', 123.981, tbname from m1
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
|
|
Loading…
Reference in New Issue