TD-13675 create sma index parser implement
This commit is contained in:
parent
eae2d7b661
commit
c2aebb25bf
|
@ -51,6 +51,7 @@ typedef struct SQuery {
|
||||||
SSchema* pResSchema;
|
SSchema* pResSchema;
|
||||||
SCmdMsgInfo* pCmdMsg;
|
SCmdMsgInfo* pCmdMsg;
|
||||||
int32_t msgType;
|
int32_t msgType;
|
||||||
|
bool streamQuery;
|
||||||
} SQuery;
|
} SQuery;
|
||||||
|
|
||||||
int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery);
|
int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery);
|
||||||
|
|
|
@ -26,6 +26,7 @@ typedef struct SPlanContext {
|
||||||
uint64_t queryId;
|
uint64_t queryId;
|
||||||
int32_t acctId;
|
int32_t acctId;
|
||||||
SNode* pAstRoot;
|
SNode* pAstRoot;
|
||||||
|
bool streamQuery;
|
||||||
} SPlanContext;
|
} SPlanContext;
|
||||||
|
|
||||||
// Create the physical plan for the query, according to the AST.
|
// Create the physical plan for the query, according to the AST.
|
||||||
|
|
|
@ -21,6 +21,7 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
#include "planner.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
#include "tcommon.h"
|
#include "tcommon.h"
|
||||||
|
@ -229,6 +230,7 @@ void setResultDataPtr(SReqResultInfo* pResultInfo, TAOS_FIELD* pFields, int32_t
|
||||||
int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest);
|
int32_t buildRequest(STscObj* pTscObj, const char* sql, int sqlLen, SRequestObj** pRequest);
|
||||||
|
|
||||||
int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery);
|
int32_t parseSql(SRequestObj* pRequest, SQuery** pQuery);
|
||||||
|
int32_t getPlan(SRequestObj* pRequest, SQuery* pQuery, SQueryPlan** pPlan, SArray* pNodeList);
|
||||||
|
|
||||||
// --- heartbeat
|
// --- heartbeat
|
||||||
// global, called by mgmt
|
// global, called by mgmt
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
|
|
||||||
#include "clientInt.h"
|
#include "clientInt.h"
|
||||||
#include "clientLog.h"
|
#include "clientLog.h"
|
||||||
#include "parser.h"
|
|
||||||
#include "planner.h"
|
|
||||||
#include "scheduler.h"
|
#include "scheduler.h"
|
||||||
#include "tdatablock.h"
|
#include "tdatablock.h"
|
||||||
#include "tdef.h"
|
#include "tdef.h"
|
||||||
|
@ -211,7 +209,6 @@ void setResSchemaInfo(SReqResultInfo* pResInfo, const SSchema* pSchema, int32_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) {
|
int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList) {
|
||||||
void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter;
|
void* pTransporter = pRequest->pTscObj->pAppInfo->pTransporter;
|
||||||
|
|
||||||
|
|
|
@ -482,21 +482,19 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i
|
||||||
}
|
}
|
||||||
|
|
||||||
tscDebug("start to create topic, %s", topicName);
|
tscDebug("start to create topic, %s", topicName);
|
||||||
#if 0
|
|
||||||
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
CHECK_CODE_GOTO(buildRequest(pTscObj, sql, sqlLen, &pRequest), _return);
|
||||||
CHECK_CODE_GOTO(parseSql(pRequest, &pQueryNode), _return);
|
CHECK_CODE_GOTO(parseSql(pRequest, &pQueryNode), _return);
|
||||||
|
|
||||||
SQueryStmtInfo* pQueryStmtInfo = (SQueryStmtInfo*)pQueryNode;
|
pQueryNode->streamQuery = true;
|
||||||
pQueryStmtInfo->info.continueQuery = true;
|
|
||||||
|
|
||||||
// todo check for invalid sql statement and return with error code
|
// todo check for invalid sql statement and return with error code
|
||||||
|
|
||||||
SSchema* schema = NULL;
|
SSchema* schema = NULL;
|
||||||
int32_t numOfCols = 0;
|
int32_t numOfCols = 0;
|
||||||
CHECK_CODE_GOTO(qCreateQueryDag(pQueryNode, &pRequest->body.pDag, &schema, &numOfCols, NULL, pRequest->requestId),
|
CHECK_CODE_GOTO(getPlan(pRequest, pQueryNode, &pRequest->body.pDag, NULL), _return);
|
||||||
_return);
|
|
||||||
|
|
||||||
pStr = qDagToString(pRequest->body.pDag);
|
pStr = qQueryPlanToString(pRequest->body.pDag);
|
||||||
if (pStr == NULL) {
|
if (pStr == NULL) {
|
||||||
goto _return;
|
goto _return;
|
||||||
}
|
}
|
||||||
|
@ -506,7 +504,7 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i
|
||||||
// The topic should be related to a database that the queried table is belonged to.
|
// The topic should be related to a database that the queried table is belonged to.
|
||||||
SName name = {0};
|
SName name = {0};
|
||||||
char dbName[TSDB_DB_FNAME_LEN] = {0};
|
char dbName[TSDB_DB_FNAME_LEN] = {0};
|
||||||
tNameGetFullDbName(&((SQueryStmtInfo*)pQueryNode)->pTableMetaInfo[0]->name, dbName);
|
// tNameGetFullDbName(&((SQueryStmtInfo*)pQueryNode)->pTableMetaInfo[0]->name, dbName);
|
||||||
|
|
||||||
tNameFromString(&name, dbName, T_NAME_ACCT | T_NAME_DB);
|
tNameFromString(&name, dbName, T_NAME_ACCT | T_NAME_DB);
|
||||||
tNameFromString(&name, topicName, T_NAME_TABLE);
|
tNameFromString(&name, topicName, T_NAME_TABLE);
|
||||||
|
@ -538,7 +536,7 @@ TAOS_RES* tmq_create_topic(TAOS* taos, const char* topicName, const char* sql, i
|
||||||
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
asyncSendMsgToServer(pTscObj->pAppInfo->pTransporter, &epSet, &transporterId, sendInfo);
|
||||||
|
|
||||||
tsem_wait(&pRequest->body.rspSem);
|
tsem_wait(&pRequest->body.rspSem);
|
||||||
#endif
|
|
||||||
_return:
|
_return:
|
||||||
qDestroyQuery(pQueryNode);
|
qDestroyQuery(pQueryNode);
|
||||||
/*if (sendInfo != NULL) {*/
|
/*if (sendInfo != NULL) {*/
|
||||||
|
|
|
@ -216,6 +216,14 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) {
|
||||||
case QUERY_NODE_NODE_LIST:
|
case QUERY_NODE_NODE_LIST:
|
||||||
nodesClearList(((SNodeListNode*)(*pNode))->pNodeList);
|
nodesClearList(((SNodeListNode*)(*pNode))->pNodeList);
|
||||||
break;
|
break;
|
||||||
|
case QUERY_NODE_INDEX_OPTIONS: {
|
||||||
|
SIndexOptions* pStmt = (SIndexOptions*)*pNode;
|
||||||
|
nodesDestroyList(pStmt->pFuncs);
|
||||||
|
nodesDestroyNode(pStmt->pInterval);
|
||||||
|
nodesDestroyNode(pStmt->pOffset);
|
||||||
|
nodesDestroyNode(pStmt->pSliding);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case QUERY_NODE_SELECT_STMT: {
|
case QUERY_NODE_SELECT_STMT: {
|
||||||
SSelectStmt* pStmt = (SSelectStmt*)*pNode;
|
SSelectStmt* pStmt = (SSelectStmt*)*pNode;
|
||||||
nodesDestroyList(pStmt->pProjectionList);
|
nodesDestroyList(pStmt->pProjectionList);
|
||||||
|
@ -256,6 +264,12 @@ static EDealRes destroyNode(SNode** pNode, void* pContext) {
|
||||||
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
|
case QUERY_NODE_CREATE_MULTI_TABLE_STMT:
|
||||||
nodesDestroyList(((SCreateMultiTableStmt*)(*pNode))->pSubTables);
|
nodesDestroyList(((SCreateMultiTableStmt*)(*pNode))->pSubTables);
|
||||||
break;
|
break;
|
||||||
|
case QUERY_NODE_CREATE_INDEX_STMT: {
|
||||||
|
SCreateIndexStmt* pStmt = (SCreateIndexStmt*)*pNode;
|
||||||
|
nodesDestroyNode(pStmt->pOptions);
|
||||||
|
nodesDestroyList(pStmt->pCols);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -197,9 +197,9 @@ cmd ::= CREATE FULLTEXT INDEX
|
||||||
|
|
||||||
index_options(A) ::= . { A = NULL; }
|
index_options(A) ::= . { A = NULL; }
|
||||||
index_options(A) ::= FUNCTION NK_LP func_list(B) NK_RP INTERVAL
|
index_options(A) ::= FUNCTION NK_LP func_list(B) NK_RP INTERVAL
|
||||||
NK_LP duration_literal(C) NK_RP sliding_opt(D). { A = createIndexOption(pCxt, B, C, NULL, D); }
|
NK_LP duration_literal(C) NK_RP sliding_opt(D). { A = createIndexOption(pCxt, B, releaseRawExprNode(pCxt, C), NULL, D); }
|
||||||
index_options(A) ::= FUNCTION NK_LP func_list(B) NK_RP INTERVAL
|
index_options(A) ::= FUNCTION NK_LP func_list(B) NK_RP INTERVAL
|
||||||
NK_LP duration_literal(C) NK_COMMA duration_literal(D) NK_RP sliding_opt(E). { A = createIndexOption(pCxt, B, C, D, E); }
|
NK_LP duration_literal(C) NK_COMMA duration_literal(D) NK_RP sliding_opt(E). { A = createIndexOption(pCxt, B, releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, D), E); }
|
||||||
|
|
||||||
%type func_list { SNodeList* }
|
%type func_list { SNodeList* }
|
||||||
%destructor func_list { nodesDestroyList($$); }
|
%destructor func_list { nodesDestroyList($$); }
|
||||||
|
|
|
@ -1167,7 +1167,7 @@ static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt
|
||||||
createSmaReq.tSma.tableUid = pMeta->uid;
|
createSmaReq.tSma.tableUid = pMeta->uid;
|
||||||
createSmaReq.tSma.interval = ((SValueNode*)pStmt->pOptions->pInterval)->datum.i;
|
createSmaReq.tSma.interval = ((SValueNode*)pStmt->pOptions->pInterval)->datum.i;
|
||||||
createSmaReq.tSma.sliding = (NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->datum.i : 0);
|
createSmaReq.tSma.sliding = (NULL != pStmt->pOptions->pSliding ? ((SValueNode*)pStmt->pOptions->pSliding)->datum.i : 0);
|
||||||
code = nodesListToString(pStmt->pCols, false, &createSmaReq.tSma.expr, &createSmaReq.tSma.exprLen);
|
code = nodesListToString(pStmt->pOptions->pFuncs, false, &createSmaReq.tSma.expr, &createSmaReq.tSma.exprLen);
|
||||||
if (TSDB_CODE_SUCCESS != code) {
|
if (TSDB_CODE_SUCCESS != code) {
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -1183,7 +1183,9 @@ static int32_t translateCreateSmaIndex(STranslateContext* pCxt, SCreateIndexStmt
|
||||||
if (NULL == pCxt->pCmdMsg->pMsg) {
|
if (NULL == pCxt->pCmdMsg->pMsg) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
tSerializeSVCreateTSmaReq(pCxt->pCmdMsg->pMsg, &createSmaReq);
|
void* pBuf = pCxt->pCmdMsg->pMsg;
|
||||||
|
tSerializeSVCreateTSmaReq(&pBuf, &createSmaReq);
|
||||||
|
// todo clear SVCreateTSmaReq
|
||||||
|
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2292,10 +2292,10 @@ static YYACTIONTYPE yy_reduce(
|
||||||
{ yymsp[1].minor.yy344 = NULL; }
|
{ yymsp[1].minor.yy344 = NULL; }
|
||||||
break;
|
break;
|
||||||
case 97: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */
|
case 97: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_RP sliding_opt */
|
||||||
{ yymsp[-8].minor.yy344 = createIndexOption(pCxt, yymsp[-6].minor.yy280, yymsp[-2].minor.yy344, NULL, yymsp[0].minor.yy344); }
|
{ yymsp[-8].minor.yy344 = createIndexOption(pCxt, yymsp[-6].minor.yy280, releaseRawExprNode(pCxt, yymsp[-2].minor.yy344), NULL, yymsp[0].minor.yy344); }
|
||||||
break;
|
break;
|
||||||
case 98: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */
|
case 98: /* index_options ::= FUNCTION NK_LP func_list NK_RP INTERVAL NK_LP duration_literal NK_COMMA duration_literal NK_RP sliding_opt */
|
||||||
{ yymsp[-10].minor.yy344 = createIndexOption(pCxt, yymsp[-8].minor.yy280, yymsp[-4].minor.yy344, yymsp[-2].minor.yy344, yymsp[0].minor.yy344); }
|
{ yymsp[-10].minor.yy344 = createIndexOption(pCxt, yymsp[-8].minor.yy280, releaseRawExprNode(pCxt, yymsp[-4].minor.yy344), releaseRawExprNode(pCxt, yymsp[-2].minor.yy344), yymsp[0].minor.yy344); }
|
||||||
break;
|
break;
|
||||||
case 101: /* func ::= function_name NK_LP expression_list NK_RP */
|
case 101: /* func ::= function_name NK_LP expression_list NK_RP */
|
||||||
{ yylhsminor.yy344 = createFunctionNode(pCxt, &yymsp[-3].minor.yy209, yymsp[-1].minor.yy280); }
|
{ yylhsminor.yy344 = createFunctionNode(pCxt, &yymsp[-3].minor.yy209, yymsp[-1].minor.yy280); }
|
||||||
|
|
|
@ -402,6 +402,6 @@ TEST_F(ParserTest, createTable) {
|
||||||
TEST_F(ParserTest, createSmaIndex) {
|
TEST_F(ParserTest, createSmaIndex) {
|
||||||
setDatabase("root", "test");
|
setDatabase("root", "test");
|
||||||
|
|
||||||
bind("create sma index index1 on t1 function(max(c1), min(c3 + 10), sum(c4))");
|
bind("create sma index index1 on t1 function(max(c1), min(c3 + 10), sum(c4)) INTERVAL(10s)");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue