feat: CREATE STREAM statement implement, and syntax of JSON data type implement.
This commit is contained in:
parent
ba1f3f7815
commit
01ea38586d
|
@ -592,15 +592,15 @@ expression_list(A) ::= expression_list(B) NK_COMMA expression(C).
|
|||
column_reference(A) ::= column_name(B). { A = createRawExprNode(pCxt, &B, createColumnNode(pCxt, NULL, &B)); }
|
||||
column_reference(A) ::= table_name(B) NK_DOT column_name(C). { A = createRawExprNodeExt(pCxt, &B, &C, createColumnNode(pCxt, &B, &C)); }
|
||||
|
||||
pseudo_column(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= TODAY(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= ROWTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= TBNAME(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= QSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= QENDTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WENDTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WDURATION(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= TODAY(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= ROWTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= TBNAME(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= QSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= QENDTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WENDTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WDURATION(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
|
||||
function_expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
|
||||
function_expression(A) ::= star_func(B) NK_LP star_func_para_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
|
||||
|
|
|
@ -51,6 +51,7 @@ static SKeyword keywordTable[] = {
|
|||
{"BY", TK_BY},
|
||||
{"CACHE", TK_CACHE},
|
||||
{"CACHELAST", TK_CACHELAST},
|
||||
{"CAST", TK_CAST},
|
||||
{"COLUMN", TK_COLUMN},
|
||||
{"COMMENT", TK_COMMENT},
|
||||
{"COMP", TK_COMP},
|
||||
|
|
|
@ -807,31 +807,32 @@ static SNode* createMultiResFunc(SFunctionNode* pSrcFunc, SExprNode* pExpr) {
|
|||
return (SNode*)pFunc;
|
||||
}
|
||||
|
||||
static int32_t createTableAllCols(STranslateContext* pCxt, SColumnNode* pCol, SNodeList** pOutput) {
|
||||
if (NULL == *pOutput) {
|
||||
*pOutput = nodesMakeList();
|
||||
}
|
||||
if (NULL == *pOutput) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
bool foundTable = false;
|
||||
static int32_t findTable(STranslateContext* pCxt, const char* pTableAlias, STableNode** pOutput) {
|
||||
SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel);
|
||||
size_t nums = taosArrayGetSize(pTables);
|
||||
for (size_t i = 0; i < nums; ++i) {
|
||||
STableNode* pTable = taosArrayGetP(pTables, i);
|
||||
if (0 == strcmp(pTable->tableAlias, pCol->tableAlias)) {
|
||||
int32_t code = createColumnNodeByTable(pCxt, pTable, *pOutput);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
foundTable = true;
|
||||
break;
|
||||
if (NULL == pTableAlias || 0 == strcmp(pTable->tableAlias, pTableAlias)) {
|
||||
*pOutput = pTable;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
if (!foundTable) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_TABLE_NOT_EXIST, pCol->tableAlias);
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_TABLE_NOT_EXIST, pTableAlias);
|
||||
}
|
||||
|
||||
static int32_t createTableAllCols(STranslateContext* pCxt, SColumnNode* pCol, SNodeList** pOutput) {
|
||||
STableNode* pTable = NULL;
|
||||
int32_t code = findTable(pCxt, pCol->tableAlias, &pTable);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL == *pOutput) {
|
||||
*pOutput = nodesMakeList();
|
||||
if (NULL == *pOutput) {
|
||||
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createColumnNodeByTable(pCxt, pTable, *pOutput);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool isStar(SNode* pNode) {
|
||||
|
@ -909,6 +910,24 @@ static int32_t createMultiResFuncsFromStar(STranslateContext* pCxt, SFunctionNod
|
|||
return code;
|
||||
}
|
||||
|
||||
static bool isCountStar(SNode* pNode) {
|
||||
if (QUERY_NODE_FUNCTION != nodeType(pNode)) {
|
||||
return false;
|
||||
}
|
||||
SNode* pPara = nodesListGetNode(((SFunctionNode*)pNode)->pParameterList, 0);
|
||||
return (QUERY_NODE_COLUMN == nodeType(pPara) && 0 == strcmp(((SColumnNode*)pPara)->colName, "*"));
|
||||
}
|
||||
|
||||
static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount) {
|
||||
SColumnNode* pCol = nodesListGetNode(pCount->pParameterList, 0);
|
||||
STableNode* pTable = NULL;
|
||||
int32_t code = findTable(pCxt, ('\0' == pCol->tableAlias[0] ? NULL : pCol->tableAlias), &pTable);
|
||||
if (TSDB_CODE_SUCCESS == code && QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
|
||||
setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, false, pCol);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||
if (NULL == pSelect->pProjectionList) { // select * ...
|
||||
return createAllColumns(pCxt, &pSelect->pProjectionList);
|
||||
|
@ -931,6 +950,11 @@ static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
|||
INSERT_LIST(pSelect->pProjectionList, pCols);
|
||||
ERASE_NODE(pSelect->pProjectionList);
|
||||
continue;
|
||||
} else if (isCountStar(pNode)) {
|
||||
int32_t code = rewriteCountStar(pCxt, (SFunctionNode*)pNode);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
WHERE_NEXT;
|
||||
}
|
||||
|
|
|
@ -264,7 +264,7 @@ private:
|
|||
}
|
||||
|
||||
std::string ftToString(int16_t colid, int16_t numOfColumns) const {
|
||||
return (0 == colid ? "column" : (colid <= numOfColumns ? "tag" : "column"));
|
||||
return (0 == colid ? "column" : (colid < numOfColumns ? "column" : "tag"));
|
||||
}
|
||||
|
||||
STableMeta* getTableSchemaMeta(const std::string& db, const std::string& tbname) const {
|
||||
|
|
|
@ -64,7 +64,7 @@ static bool osdMayBeOptimized(SLogicNode* pNode) {
|
|||
return false;
|
||||
}
|
||||
if (NULL == pNode->pParent ||
|
||||
(QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pNode->pParent))) {
|
||||
(QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
|
@ -196,14 +196,14 @@ TEST_F(PlannerTest, selectGroupBy) {
|
|||
bind("SELECT count(*) FROM t1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
// bind("SELECT c1, max(c3), min(c2), count(*) FROM t1 GROUP BY c1");
|
||||
// ASSERT_TRUE(run());
|
||||
bind("SELECT c1, max(c3), min(c3), count(*) FROM t1 GROUP BY c1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
// bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3");
|
||||
// ASSERT_TRUE(run());
|
||||
bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
// bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3");
|
||||
// ASSERT_TRUE(run());
|
||||
bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(PlannerTest, selectSubquery) {
|
||||
|
|
Loading…
Reference in New Issue