提交 cb0f1f53 编写于 作者: X Xiaoyu Wang

enh: fill value supports implicit type conversion

上级 78378845
...@@ -2762,17 +2762,17 @@ static bool needFill(SNode* pNode) { ...@@ -2762,17 +2762,17 @@ static bool needFill(SNode* pNode) {
return hasFillFunc; return hasFillFunc;
} }
static bool mismatchFillDataType(SDataType origDt, SDataType fillDt) { static int32_t convertFillValue(STranslateContext* pCxt, SDataType dt, SNodeList* pValues, int32_t index) {
if (TSDB_DATA_TYPE_NULL == fillDt.type) { SListCell* pCell = nodesListGetCell(pValues, index);
return false; if (dataTypeEqual(&dt, &((SExprNode*)pCell->pNode)->resType)) {
} return TSDB_CODE_SUCCESS;
if (IS_NUMERIC_TYPE(origDt.type) && !IS_NUMERIC_TYPE(fillDt.type)) {
return true;
} }
if (IS_VAR_DATA_TYPE(origDt.type) && !IS_VAR_DATA_TYPE(fillDt.type)) { SNode* pCaseFunc = NULL;
return true; int32_t code = createCastFunc(pCxt, pCell->pNode, dt, &pCaseFunc);
if (TSDB_CODE_SUCCESS == code) {
pCell->pNode = pCaseFunc;
} }
return false; return code;
} }
static int32_t checkFillValues(STranslateContext* pCxt, SFillNode* pFill, SNodeList* pProjectionList) { static int32_t checkFillValues(STranslateContext* pCxt, SFillNode* pFill, SNodeList* pProjectionList) {
...@@ -2788,8 +2788,8 @@ static int32_t checkFillValues(STranslateContext* pCxt, SFillNode* pFill, SNodeL ...@@ -2788,8 +2788,8 @@ static int32_t checkFillValues(STranslateContext* pCxt, SFillNode* pFill, SNodeL
if (fillNo >= LIST_LENGTH(pFillValues->pNodeList)) { if (fillNo >= LIST_LENGTH(pFillValues->pNodeList)) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Filled values number mismatch"); return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Filled values number mismatch");
} }
if (mismatchFillDataType(((SExprNode*)pProject)->resType, if (TSDB_CODE_SUCCESS !=
((SExprNode*)nodesListGetNode(pFillValues->pNodeList, fillNo))->resType)) { convertFillValue(pCxt, ((SExprNode*)pProject)->resType, pFillValues->pNodeList, fillNo)) {
return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Filled data type mismatch"); return generateSyntaxErrMsgExt(&pCxt->msgBuf, TSDB_CODE_PAR_WRONG_VALUE_TYPE, "Filled data type mismatch");
} }
++fillNo; ++fillNo;
......
...@@ -354,7 +354,7 @@ endi ...@@ -354,7 +354,7 @@ endi
## NULL fill ## NULL fill
print fill(NULL) print fill(NULL)
print select _wstart, max(c1), min(c2), avg(c3), sum(c4), count(c5), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 4 partition by t1 interval(5m) fill(value, NULL) limit 5 print select _wstart, max(c1), min(c2), avg(c3), sum(c4), count(c5), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 4 partition by t1 interval(5m) fill(value, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) limit 5
sql select _wstart, max(c1), min(c2), avg(c3), sum(c4), count(c5), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 4 partition by t1 interval(5m) fill(NULL) limit 5 sql select _wstart, max(c1), min(c2), avg(c3), sum(c4), count(c5), first(c7), last(c8), first(c9) from $stb where ts >= $ts0 and ts <= $tsu and t1 > 4 partition by t1 interval(5m) fill(NULL) limit 5
if $rows != 25 then if $rows != 25 then
return -1 return -1
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册