From 3b9e868e2a3e29e6d205ebb6f76ccadfae25434c Mon Sep 17 00:00:00 2001 From: Xiaoyu Wang Date: Fri, 1 Apr 2022 06:40:47 -0400 Subject: [PATCH] fill plan implement --- source/libs/nodes/src/nodesCloneFuncs.c | 8 +++++++ source/libs/nodes/src/nodesCodeFuncs.c | 29 +++++++++++++++++++++++- source/libs/parser/src/parTokenizer.c | 1 + source/libs/planner/test/plannerTest.cpp | 12 +++++++--- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/source/libs/nodes/src/nodesCloneFuncs.c b/source/libs/nodes/src/nodesCloneFuncs.c index e728078a38..f8bc99b975 100644 --- a/source/libs/nodes/src/nodesCloneFuncs.c +++ b/source/libs/nodes/src/nodesCloneFuncs.c @@ -206,6 +206,12 @@ static SNode* orderByExprNodeCopy(const SOrderByExprNode* pSrc, SOrderByExprNode return (SNode*)pDst; } +static SNode* nodeListNodeCopy(const SNodeListNode* pSrc, SNodeListNode* pDst) { + COPY_ALL_SCALAR_FIELDS; + CLONE_NODE_LIST_FIELD(pNodeList); + return (SNode*)pDst; +} + static SNode* fillNodeCopy(const SFillNode* pSrc, SFillNode* pDst) { COPY_SCALAR_FIELD(mode); CLONE_NODE_FIELD(pValues); @@ -360,6 +366,8 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) { return orderByExprNodeCopy((const SOrderByExprNode*)pNode, (SOrderByExprNode*)pDst); case QUERY_NODE_LIMIT: break; + case QUERY_NODE_NODE_LIST: + return nodeListNodeCopy((const SNodeListNode*)pNode, (SNodeListNode*)pDst); case QUERY_NODE_FILL: return fillNodeCopy((const SFillNode*)pNode, (SFillNode*)pDst); case QUERY_NODE_DATABLOCK_DESC: diff --git a/source/libs/nodes/src/nodesCodeFuncs.c b/source/libs/nodes/src/nodesCodeFuncs.c index 32040a2e3f..5337965164 100644 --- a/source/libs/nodes/src/nodesCodeFuncs.c +++ b/source/libs/nodes/src/nodesCodeFuncs.c @@ -2015,6 +2015,31 @@ static int32_t jsonToNodeListNode(const SJson* pJson, void* pObj) { return code; } +static const char* jkFillMode = "Mode"; +static const char* jkFillValues = "Values"; + +static int32_t fillNodeToJson(const void* pObj, SJson* pJson) { + const SFillNode* pNode = (const SFillNode*)pObj; + + int32_t code = tjsonAddIntegerToObject(pJson, jkFillMode, pNode->mode); + if (TSDB_CODE_SUCCESS == code) { + code = tjsonAddObject(pJson, jkFillValues, nodeToJson, pNode->pValues); + } + + return code; +} + +static int32_t jsonToFillNode(const SJson* pJson, void* pObj) { + SFillNode* pNode = (SFillNode*)pObj; + + int32_t code = tjsonGetNumberValue(pJson, jkFillMode, pNode->mode); + if (TSDB_CODE_SUCCESS == code) { + code = jsonToNodeObject(pJson, jkFillValues, &pNode->pValues); + } + + return code; +} + static const char* jkTargetDataBlockId = "DataBlockId"; static const char* jkTargetSlotId = "SlotId"; static const char* jkTargetExpr = "Expr"; @@ -2328,6 +2353,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) { case QUERY_NODE_NODE_LIST: return nodeListNodeToJson(pObj, pJson); case QUERY_NODE_FILL: + return fillNodeToJson(pObj, pJson); case QUERY_NODE_RAW_EXPR: break; case QUERY_NODE_TARGET: @@ -2431,7 +2457,8 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) { return jsonToIntervalWindowNode(pJson, pObj); case QUERY_NODE_NODE_LIST: return jsonToNodeListNode(pJson, pObj); - // case QUERY_NODE_FILL: + case QUERY_NODE_FILL: + return jsonToFillNode(pJson, pObj); case QUERY_NODE_TARGET: return jsonToTargetNode(pJson, pObj); // case QUERY_NODE_RAW_EXPR: diff --git a/source/libs/parser/src/parTokenizer.c b/source/libs/parser/src/parTokenizer.c index be2bd0d0b6..d89bee6fdc 100644 --- a/source/libs/parser/src/parTokenizer.c +++ b/source/libs/parser/src/parTokenizer.c @@ -176,6 +176,7 @@ static SKeyword keywordTable[] = { {"USER", TK_USER}, {"USERS", TK_USERS}, {"USING", TK_USING}, + {"VALUE", TK_VALUE}, {"VALUES", TK_VALUES}, {"VARCHAR", TK_VARCHAR}, {"VARIABLES", TK_VARIABLES}, diff --git a/source/libs/planner/test/plannerTest.cpp b/source/libs/planner/test/plannerTest.cpp index d19d88f455..00af808078 100644 --- a/source/libs/planner/test/plannerTest.cpp +++ b/source/libs/planner/test/plannerTest.cpp @@ -190,10 +190,16 @@ TEST_F(PlannerTest, subquery) { TEST_F(PlannerTest, interval) { setDatabase("root", "test"); - bind("SELECT count(*) FROM t1 interval(10s)"); - ASSERT_TRUE(run()); + // bind("SELECT count(*) FROM t1 interval(10s)"); + // ASSERT_TRUE(run()); + + // bind("SELECT _wstartts, _wduration, _wendts, count(*) FROM t1 interval(10s)"); + // ASSERT_TRUE(run()); + + // bind("SELECT count(*) FROM t1 interval(10s) fill(linear)"); + // ASSERT_TRUE(run()); - bind("SELECT _wstartts, _wduration, _wendts, count(*) FROM t1 interval(10s)"); + bind("SELECT count(*), sum(c1) FROM t1 interval(10s) fill(value, 10, 20)"); ASSERT_TRUE(run()); } -- GitLab