提交 06f0f1d3 编写于 作者: X Xiaoyu Wang

TD-13747 phase 1 function integration

上级 d3138fff
...@@ -112,6 +112,13 @@ typedef struct SDropTableStmt { ...@@ -112,6 +112,13 @@ typedef struct SDropTableStmt {
SNodeList* pTables; SNodeList* pTables;
} SDropTableStmt; } SDropTableStmt;
typedef struct SDropSuperTableStmt {
ENodeType type;
char dbName[TSDB_DB_NAME_LEN];
char tableName[TSDB_TABLE_NAME_LEN];
bool ignoreNotExists;
} SDropSuperTableStmt;
typedef struct SCreateUserStmt { typedef struct SCreateUserStmt {
ENodeType type; ENodeType type;
char useName[TSDB_USER_LEN]; char useName[TSDB_USER_LEN];
...@@ -143,6 +150,11 @@ typedef struct SDropDnodeStmt { ...@@ -143,6 +150,11 @@ typedef struct SDropDnodeStmt {
int32_t port; int32_t port;
} SDropDnodeStmt; } SDropDnodeStmt;
typedef struct SShowStmt {
ENodeType type;
char dbName[TSDB_DB_NAME_LEN];
} SShowStmt;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
...@@ -79,6 +79,7 @@ typedef enum ENodeType { ...@@ -79,6 +79,7 @@ typedef enum ENodeType {
QUERY_NODE_CREATE_MULTI_TABLE_STMT, QUERY_NODE_CREATE_MULTI_TABLE_STMT,
QUERY_NODE_DROP_TABLE_CLAUSE, QUERY_NODE_DROP_TABLE_CLAUSE,
QUERY_NODE_DROP_TABLE_STMT, QUERY_NODE_DROP_TABLE_STMT,
QUERY_NODE_DROP_SUPER_TABLE_STMT,
QUERY_NODE_SHOW_TABLES_STMT, // temp QUERY_NODE_SHOW_TABLES_STMT, // temp
QUERY_NODE_SHOW_STABLES_STMT, QUERY_NODE_SHOW_STABLES_STMT,
QUERY_NODE_CREATE_USER_STMT, QUERY_NODE_CREATE_USER_STMT,
......
...@@ -34,8 +34,11 @@ ...@@ -34,8 +34,11 @@
(pDst)->fldname = strdup((pSrc)->fldname); \ (pDst)->fldname = strdup((pSrc)->fldname); \
} while (0) } while (0)
#define COPY_NODE_FIELD(fldname) \ #define CLONE_NODE_FIELD(fldname) \
do { \ do { \
if (NULL == (pSrc)->fldname) { \
break; \
} \
(pDst)->fldname = nodesCloneNode((pSrc)->fldname); \ (pDst)->fldname = nodesCloneNode((pSrc)->fldname); \
if (NULL == (pDst)->fldname) { \ if (NULL == (pDst)->fldname) { \
nodesDestroyNode((SNode*)(pDst)); \ nodesDestroyNode((SNode*)(pDst)); \
...@@ -43,8 +46,11 @@ ...@@ -43,8 +46,11 @@
} \ } \
} while (0) } while (0)
#define COPY_NODE_LIST_FIELD(fldname) \ #define CLONE_NODE_LIST_FIELD(fldname) \
do { \ do { \
if (NULL == (pSrc)->fldname) { \
break; \
} \
(pDst)->fldname = nodesCloneList((pSrc)->fldname); \ (pDst)->fldname = nodesCloneList((pSrc)->fldname); \
if (NULL == (pDst)->fldname) { \ if (NULL == (pDst)->fldname) { \
nodesDestroyNode((SNode*)(pDst)); \ nodesDestroyNode((SNode*)(pDst)); \
...@@ -52,6 +58,22 @@ ...@@ -52,6 +58,22 @@
} \ } \
} while (0) } while (0)
#define CLONE_OBJECT_FIELD(fldname, cloneFunc) \
do { \
(pDst)->fldname = cloneFunc((pSrc)->fldname); \
if (NULL == (pDst)->fldname) { \
nodesDestroyNode((SNode*)(pDst)); \
return NULL; \
} \
} while (0)
#define COPY_BASE_OBJECT_FIELD(fldname, copyFunc) \
do { \
if (NULL == copyFunc(&((pSrc)->fldname), &((pDst)->fldname))) { \
return NULL; \
} \
} while (0)
static void dataTypeCopy(const SDataType* pSrc, SDataType* pDst) { static void dataTypeCopy(const SDataType* pSrc, SDataType* pDst) {
COPY_SCALAR_FIELD(type); COPY_SCALAR_FIELD(type);
COPY_SCALAR_FIELD(precision); COPY_SCALAR_FIELD(precision);
...@@ -62,7 +84,7 @@ static void dataTypeCopy(const SDataType* pSrc, SDataType* pDst) { ...@@ -62,7 +84,7 @@ static void dataTypeCopy(const SDataType* pSrc, SDataType* pDst) {
static void exprNodeCopy(const SExprNode* pSrc, SExprNode* pDst) { static void exprNodeCopy(const SExprNode* pSrc, SExprNode* pDst) {
dataTypeCopy(&pSrc->resType, &pDst->resType); dataTypeCopy(&pSrc->resType, &pDst->resType);
COPY_CHAR_ARRAY_FIELD(aliasName); COPY_CHAR_ARRAY_FIELD(aliasName);
// COPY_NODE_LIST_FIELD(pAssociationList); // CLONE_NODE_LIST_FIELD(pAssociationList);
} }
static SNode* columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) { static SNode* columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) {
...@@ -73,7 +95,7 @@ static SNode* columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) { ...@@ -73,7 +95,7 @@ static SNode* columnNodeCopy(const SColumnNode* pSrc, SColumnNode* pDst) {
COPY_CHAR_ARRAY_FIELD(tableName); COPY_CHAR_ARRAY_FIELD(tableName);
COPY_CHAR_ARRAY_FIELD(tableAlias); COPY_CHAR_ARRAY_FIELD(tableAlias);
COPY_CHAR_ARRAY_FIELD(colName); COPY_CHAR_ARRAY_FIELD(colName);
// COPY_NODE_FIELD(pProjectRef); // CLONE_NODE_FIELD(pProjectRef);
COPY_SCALAR_FIELD(dataBlockId); COPY_SCALAR_FIELD(dataBlockId);
COPY_SCALAR_FIELD(slotId); COPY_SCALAR_FIELD(slotId);
return (SNode*)pDst; return (SNode*)pDst;
...@@ -125,15 +147,15 @@ static SNode* valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) { ...@@ -125,15 +147,15 @@ static SNode* valueNodeCopy(const SValueNode* pSrc, SValueNode* pDst) {
static SNode* operatorNodeCopy(const SOperatorNode* pSrc, SOperatorNode* pDst) { static SNode* operatorNodeCopy(const SOperatorNode* pSrc, SOperatorNode* pDst) {
exprNodeCopy((const SExprNode*)pSrc, (SExprNode*)pDst); exprNodeCopy((const SExprNode*)pSrc, (SExprNode*)pDst);
COPY_SCALAR_FIELD(opType); COPY_SCALAR_FIELD(opType);
COPY_NODE_FIELD(pLeft); CLONE_NODE_FIELD(pLeft);
COPY_NODE_FIELD(pRight); CLONE_NODE_FIELD(pRight);
return (SNode*)pDst; return (SNode*)pDst;
} }
static SNode* logicConditionNodeCopy(const SLogicConditionNode* pSrc, SLogicConditionNode* pDst) { static SNode* logicConditionNodeCopy(const SLogicConditionNode* pSrc, SLogicConditionNode* pDst) {
exprNodeCopy((const SExprNode*)pSrc, (SExprNode*)pDst); exprNodeCopy((const SExprNode*)pSrc, (SExprNode*)pDst);
COPY_SCALAR_FIELD(condType); COPY_SCALAR_FIELD(condType);
COPY_NODE_LIST_FIELD(pParameterList); CLONE_NODE_LIST_FIELD(pParameterList);
return (SNode*)pDst; return (SNode*)pDst;
} }
...@@ -142,32 +164,89 @@ static SNode* functionNodeCopy(const SFunctionNode* pSrc, SFunctionNode* pDst) { ...@@ -142,32 +164,89 @@ static SNode* functionNodeCopy(const SFunctionNode* pSrc, SFunctionNode* pDst) {
COPY_CHAR_ARRAY_FIELD(functionName); COPY_CHAR_ARRAY_FIELD(functionName);
COPY_SCALAR_FIELD(funcId); COPY_SCALAR_FIELD(funcId);
COPY_SCALAR_FIELD(funcType); COPY_SCALAR_FIELD(funcType);
COPY_NODE_LIST_FIELD(pParameterList); CLONE_NODE_LIST_FIELD(pParameterList);
return (SNode*)pDst; return (SNode*)pDst;
} }
static SNode* targetNodeCopy(const STargetNode* pSrc, STargetNode* pDst) { static SNode* targetNodeCopy(const STargetNode* pSrc, STargetNode* pDst) {
COPY_SCALAR_FIELD(dataBlockId); COPY_SCALAR_FIELD(dataBlockId);
COPY_SCALAR_FIELD(slotId); COPY_SCALAR_FIELD(slotId);
COPY_NODE_FIELD(pExpr); CLONE_NODE_FIELD(pExpr);
return (SNode*)pDst; return (SNode*)pDst;
} }
static SNode* groupingSetNodeCopy(const SGroupingSetNode* pSrc, SGroupingSetNode* pDst) { static SNode* groupingSetNodeCopy(const SGroupingSetNode* pSrc, SGroupingSetNode* pDst) {
COPY_SCALAR_FIELD(groupingSetType); COPY_SCALAR_FIELD(groupingSetType);
COPY_NODE_LIST_FIELD(pParameterList); CLONE_NODE_LIST_FIELD(pParameterList);
return (SNode*)pDst;
}
static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) {
COPY_SCALAR_FIELD(id);
CLONE_NODE_LIST_FIELD(pTargets);
CLONE_NODE_FIELD(pConditions);
CLONE_NODE_LIST_FIELD(pChildren);
return (SNode*)pDst;
}
static STableMeta* tableMetaClone(const STableMeta* pSrc) {
int32_t len = sizeof(STableMeta) + (pSrc->tableInfo.numOfTags + pSrc->tableInfo.numOfColumns) * sizeof(SSchema);
STableMeta* pDst = malloc(len);
if (NULL == pDst) {
return NULL;
}
memcpy(pDst, pSrc, len);
return pDst;
}
static SVgroupsInfo* vgroupsInfoClone(const SVgroupsInfo* pSrc) {
int32_t len = sizeof(SVgroupsInfo) + pSrc->numOfVgroups * sizeof(SVgroupInfo);
SVgroupsInfo* pDst = malloc(len);
if (NULL == pDst) {
return NULL;
}
memcpy(pDst, pSrc, len);
return pDst;
}
static SNode* logicScanCopy(const SScanLogicNode* pSrc, SScanLogicNode* pDst) {
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
CLONE_NODE_LIST_FIELD(pScanCols);
CLONE_OBJECT_FIELD(pMeta, tableMetaClone);
CLONE_OBJECT_FIELD(pVgroupList, vgroupsInfoClone);
COPY_SCALAR_FIELD(scanType);
COPY_SCALAR_FIELD(scanFlag);
COPY_SCALAR_FIELD(scanRange);
return (SNode*)pDst;
}
static SNode* logicAggCopy(const SAggLogicNode* pSrc, SAggLogicNode* pDst) {
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
CLONE_NODE_LIST_FIELD(pGroupKeys);
CLONE_NODE_LIST_FIELD(pAggFuncs);
return (SNode*)pDst;
}
static SNode* logicProjectCopy(const SProjectLogicNode* pSrc, SProjectLogicNode* pDst) {
COPY_BASE_OBJECT_FIELD(node, logicNodeCopy);
CLONE_NODE_LIST_FIELD(pProjections);
return (SNode*)pDst;
}
static SNode* logicVnodeModifCopy(const SVnodeModifLogicNode* pSrc, SVnodeModifLogicNode* pDst) {
COPY_SCALAR_FIELD(msgType);
return (SNode*)pDst; return (SNode*)pDst;
} }
static SNode* logicSubplanCopy(const SSubLogicPlan* pSrc, SSubLogicPlan* pDst) { static SNode* logicSubplanCopy(const SSubLogicPlan* pSrc, SSubLogicPlan* pDst) {
COPY_NODE_FIELD(pNode); CLONE_NODE_FIELD(pNode);
COPY_SCALAR_FIELD(subplanType); COPY_SCALAR_FIELD(subplanType);
return (SNode*)pDst; return (SNode*)pDst;
} }
static SNode* dataBlockDescCopy(const SDataBlockDescNode* pSrc, SDataBlockDescNode* pDst) { static SNode* dataBlockDescCopy(const SDataBlockDescNode* pSrc, SDataBlockDescNode* pDst) {
COPY_SCALAR_FIELD(dataBlockId); COPY_SCALAR_FIELD(dataBlockId);
COPY_NODE_LIST_FIELD(pSlots); CLONE_NODE_LIST_FIELD(pSlots);
COPY_SCALAR_FIELD(resultRowSize); COPY_SCALAR_FIELD(resultRowSize);
COPY_SCALAR_FIELD(precision); COPY_SCALAR_FIELD(precision);
return (SNode*)pDst; return (SNode*)pDst;
...@@ -217,13 +296,22 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) { ...@@ -217,13 +296,22 @@ SNodeptr nodesCloneNode(const SNodeptr pNode) {
return dataBlockDescCopy((const SDataBlockDescNode*)pNode, (SDataBlockDescNode*)pDst); return dataBlockDescCopy((const SDataBlockDescNode*)pNode, (SDataBlockDescNode*)pDst);
case QUERY_NODE_SLOT_DESC: case QUERY_NODE_SLOT_DESC:
return slotDescCopy((const SSlotDescNode*)pNode, (SSlotDescNode*)pDst); return slotDescCopy((const SSlotDescNode*)pNode, (SSlotDescNode*)pDst);
case QUERY_NODE_LOGIC_PLAN_SCAN:
return logicScanCopy((const SScanLogicNode*)pNode, (SScanLogicNode*)pDst);
case QUERY_NODE_LOGIC_PLAN_AGG:
return logicAggCopy((const SAggLogicNode*)pNode, (SAggLogicNode*)pDst);
case QUERY_NODE_LOGIC_PLAN_PROJECT:
return logicProjectCopy((const SProjectLogicNode*)pNode, (SProjectLogicNode*)pDst);
case QUERY_NODE_LOGIC_PLAN_VNODE_MODIF:
return logicVnodeModifCopy((const SVnodeModifLogicNode*)pNode, (SVnodeModifLogicNode*)pDst);
case QUERY_NODE_LOGIC_SUBPLAN: case QUERY_NODE_LOGIC_SUBPLAN:
return logicSubplanCopy((const SSubLogicPlan*)pNode, (SSubLogicPlan*)pDst); return logicSubplanCopy((const SSubLogicPlan*)pNode, (SSubLogicPlan*)pDst);
default: default:
break; break;
} }
nodesWarn("nodesCloneNode unknown node = %s", nodesNodeName(nodeType(pNode))); nodesDestroyNode(pDst);
return pDst; nodesError("nodesCloneNode unknown node = %s", nodesNodeName(nodeType(pNode)));
return NULL;
} }
SNodeList* nodesCloneList(const SNodeList* pList) { SNodeList* nodesCloneList(const SNodeList* pList) {
......
...@@ -1532,7 +1532,8 @@ static int32_t jsonToNodeObject(const SJson* pJson, const char* pName, SNode** p ...@@ -1532,7 +1532,8 @@ static int32_t jsonToNodeObject(const SJson* pJson, const char* pName, SNode** p
int32_t nodesNodeToString(const SNodeptr pNode, bool format, char** pStr, int32_t* pLen) { int32_t nodesNodeToString(const SNodeptr pNode, bool format, char** pStr, int32_t* pLen) {
if (NULL == pNode || NULL == pStr || NULL == pLen) { if (NULL == pNode || NULL == pStr || NULL == pLen) {
return TSDB_CODE_SUCCESS; terrno = TSDB_CODE_FAILED;
return TSDB_CODE_FAILED;
} }
SJson* pJson = tjsonCreateObject(); SJson* pJson = tjsonCreateObject();
......
...@@ -85,7 +85,7 @@ SNodeptr nodesMakeNode(ENodeType type) { ...@@ -85,7 +85,7 @@ SNodeptr nodesMakeNode(ENodeType type) {
case QUERY_NODE_DROP_DATABASE_STMT: case QUERY_NODE_DROP_DATABASE_STMT:
return makeNode(type, sizeof(SDropDatabaseStmt)); return makeNode(type, sizeof(SDropDatabaseStmt));
case QUERY_NODE_SHOW_DATABASES_STMT: case QUERY_NODE_SHOW_DATABASES_STMT:
return makeNode(type, sizeof(SNode)); return makeNode(type, sizeof(SShowStmt));
case QUERY_NODE_CREATE_TABLE_STMT: case QUERY_NODE_CREATE_TABLE_STMT:
return makeNode(type, sizeof(SCreateTableStmt)); return makeNode(type, sizeof(SCreateTableStmt));
case QUERY_NODE_CREATE_SUBTABLE_CLAUSE: case QUERY_NODE_CREATE_SUBTABLE_CLAUSE:
...@@ -96,9 +96,11 @@ SNodeptr nodesMakeNode(ENodeType type) { ...@@ -96,9 +96,11 @@ SNodeptr nodesMakeNode(ENodeType type) {
return makeNode(type, sizeof(SDropTableClause)); return makeNode(type, sizeof(SDropTableClause));
case QUERY_NODE_DROP_TABLE_STMT: case QUERY_NODE_DROP_TABLE_STMT:
return makeNode(type, sizeof(SDropTableStmt)); return makeNode(type, sizeof(SDropTableStmt));
case QUERY_NODE_DROP_SUPER_TABLE_STMT:
return makeNode(type, sizeof(SDropSuperTableStmt));
case QUERY_NODE_SHOW_TABLES_STMT: case QUERY_NODE_SHOW_TABLES_STMT:
case QUERY_NODE_SHOW_STABLES_STMT: case QUERY_NODE_SHOW_STABLES_STMT:
return makeNode(type, sizeof(SNode)); return makeNode(type, sizeof(SShowStmt));
case QUERY_NODE_CREATE_USER_STMT: case QUERY_NODE_CREATE_USER_STMT:
return makeNode(type, sizeof(SCreateUserStmt)); return makeNode(type, sizeof(SCreateUserStmt));
case QUERY_NODE_ALTER_USER_STMT: case QUERY_NODE_ALTER_USER_STMT:
...@@ -106,7 +108,7 @@ SNodeptr nodesMakeNode(ENodeType type) { ...@@ -106,7 +108,7 @@ SNodeptr nodesMakeNode(ENodeType type) {
case QUERY_NODE_DROP_USER_STMT: case QUERY_NODE_DROP_USER_STMT:
return makeNode(type, sizeof(SDropUserStmt)); return makeNode(type, sizeof(SDropUserStmt));
case QUERY_NODE_SHOW_USERS_STMT: case QUERY_NODE_SHOW_USERS_STMT:
return makeNode(type, sizeof(SNode)); return makeNode(type, sizeof(SShowStmt));
case QUERY_NODE_USE_DATABASE_STMT: case QUERY_NODE_USE_DATABASE_STMT:
return makeNode(type, sizeof(SUseDatabaseStmt)); return makeNode(type, sizeof(SUseDatabaseStmt));
case QUERY_NODE_CREATE_DNODE_STMT: case QUERY_NODE_CREATE_DNODE_STMT:
...@@ -114,9 +116,9 @@ SNodeptr nodesMakeNode(ENodeType type) { ...@@ -114,9 +116,9 @@ SNodeptr nodesMakeNode(ENodeType type) {
case QUERY_NODE_DROP_DNODE_STMT: case QUERY_NODE_DROP_DNODE_STMT:
return makeNode(type, sizeof(SDropDnodeStmt)); return makeNode(type, sizeof(SDropDnodeStmt));
case QUERY_NODE_SHOW_DNODES_STMT: case QUERY_NODE_SHOW_DNODES_STMT:
return makeNode(type, sizeof(SNode)); return makeNode(type, sizeof(SShowStmt));
case QUERY_NODE_SHOW_VGROUPS_STMT: case QUERY_NODE_SHOW_VGROUPS_STMT:
return makeNode(type, sizeof(SNode)); return makeNode(type, sizeof(SShowStmt));
case QUERY_NODE_LOGIC_PLAN_SCAN: case QUERY_NODE_LOGIC_PLAN_SCAN:
return makeNode(type, sizeof(SScanLogicNode)); return makeNode(type, sizeof(SScanLogicNode));
case QUERY_NODE_LOGIC_PLAN_JOIN: case QUERY_NODE_LOGIC_PLAN_JOIN:
......
...@@ -124,8 +124,9 @@ SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SN ...@@ -124,8 +124,9 @@ SNode* createCreateSubTableClause(SAstCreateContext* pCxt, bool ignoreExists, SN
SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables); SNode* createCreateMultiTableStmt(SAstCreateContext* pCxt, SNodeList* pSubTables);
SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable); SNode* createDropTableClause(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables); SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables);
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable);
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName); SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName);
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type); SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDbName);
SNode* createCreateUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, const SToken* pPassword); SNode* createCreateUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, const SToken* pPassword);
SNode* createAlterUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, int8_t alterType, const SToken* pVal); SNode* createAlterUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, int8_t alterType, const SToken* pVal);
SNode* createDropUserStmt(SAstCreateContext* pCxt, const SToken* pUserName); SNode* createDropUserStmt(SAstCreateContext* pCxt, const SToken* pUserName);
......
...@@ -48,14 +48,14 @@ cmd ::= CREATE USER user_name(A) PASS NK_STRING(B). ...@@ -48,14 +48,14 @@ cmd ::= CREATE USER user_name(A) PASS NK_STRING(B).
cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B);} cmd ::= ALTER USER user_name(A) PASS NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PASSWD, &B);}
cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PRIVILEGES, &B);} cmd ::= ALTER USER user_name(A) PRIVILEGE NK_STRING(B). { pCxt->pRootNode = createAlterUserStmt(pCxt, &A, TSDB_ALTER_USER_PRIVILEGES, &B);}
cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); } cmd ::= DROP USER user_name(A). { pCxt->pRootNode = createDropUserStmt(pCxt, &A); }
cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT); } cmd ::= SHOW USERS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_USERS_STMT, NULL); }
/************************************************ create/drop/show dnode **********************************************/ /************************************************ create/drop/show dnode **********************************************/
cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL);} cmd ::= CREATE DNODE dnode_endpoint(A). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, NULL);}
cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B);} cmd ::= CREATE DNODE dnode_host_name(A) PORT NK_INTEGER(B). { pCxt->pRootNode = createCreateDnodeStmt(pCxt, &A, &B);}
cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A);} cmd ::= DROP DNODE NK_INTEGER(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A);}
cmd ::= DROP DNODE dnode_endpoint(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A);} cmd ::= DROP DNODE dnode_endpoint(A). { pCxt->pRootNode = createDropDnodeStmt(pCxt, &A);}
cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT); } cmd ::= SHOW DNODES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DNODES_STMT, NULL); }
%type dnode_endpoint { SToken } %type dnode_endpoint { SToken }
%destructor dnode_endpoint { } %destructor dnode_endpoint { }
...@@ -69,7 +69,7 @@ dnode_host_name(A) ::= NK_IPTOKEN(B). ...@@ -69,7 +69,7 @@ dnode_host_name(A) ::= NK_IPTOKEN(B).
/************************************************ create/drop/show/use database ***************************************/ /************************************************ create/drop/show/use database ***************************************/
cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C). { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C);} cmd ::= CREATE DATABASE not_exists_opt(A) db_name(B) db_options(C). { pCxt->pRootNode = createCreateDatabaseStmt(pCxt, A, &B, C);}
cmd ::= DROP DATABASE exists_opt(A) db_name(B). { pCxt->pRootNode = createDropDatabaseStmt(pCxt, A, &B); } cmd ::= DROP DATABASE exists_opt(A) db_name(B). { pCxt->pRootNode = createDropDatabaseStmt(pCxt, A, &B); }
cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT); } cmd ::= SHOW DATABASES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_DATABASES_STMT, NULL); }
cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A);} cmd ::= USE db_name(A). { pCxt->pRootNode = createUseDatabaseStmt(pCxt, &A);}
%type not_exists_opt { bool } %type not_exists_opt { bool }
...@@ -110,8 +110,9 @@ cmd ::= CREATE TABLE multi_create_clause(A). ...@@ -110,8 +110,9 @@ cmd ::= CREATE TABLE multi_create_clause(A).
cmd ::= CREATE STABLE not_exists_opt(A) full_table_name(B) cmd ::= CREATE STABLE not_exists_opt(A) full_table_name(B)
NK_LP column_def_list(C) NK_RP tags_def(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E);} NK_LP column_def_list(C) NK_RP tags_def(D) table_options(E). { pCxt->pRootNode = createCreateTableStmt(pCxt, A, B, C, D, E);}
cmd ::= DROP TABLE multi_drop_clause(A). { pCxt->pRootNode = createDropTableStmt(pCxt, A); } cmd ::= DROP TABLE multi_drop_clause(A). { pCxt->pRootNode = createDropTableStmt(pCxt, A); }
cmd ::= SHOW TABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT); } cmd ::= DROP STABLE exists_opt(A) full_table_name(B). { pCxt->pRootNode = createDropSuperTableStmt(pCxt, A, B); }
cmd ::= SHOW STABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT); } cmd ::= SHOW TABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_TABLES_STMT, NULL); }
cmd ::= SHOW STABLES. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STABLES_STMT, NULL); }
%type multi_create_clause { SNodeList* } %type multi_create_clause { SNodeList* }
%destructor multi_create_clause { nodesDestroyList($$); } %destructor multi_create_clause { nodesDestroyList($$); }
...@@ -195,10 +196,11 @@ col_name_list(A) ::= col_name_list(B) NK_COMMA col_name(C). ...@@ -195,10 +196,11 @@ col_name_list(A) ::= col_name_list(B) NK_COMMA col_name(C).
col_name(A) ::= column_name(B). { A = createColumnNode(pCxt, NULL, &B); } col_name(A) ::= column_name(B). { A = createColumnNode(pCxt, NULL, &B); }
/************************************************ show ***************************************************************/ /************************************************ show vgroups ********************************************************/
cmd ::= SHOW VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT); } cmd ::= SHOW VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, NULL); }
cmd ::= SHOW db_name(B) NK_DOT VGROUPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_VGROUPS_STMT, &B); }
/************************************************ select *************************************************************/ /************************************************ select **************************************************************/
cmd ::= query_expression(A). { pCxt->pRootNode = A; } cmd ::= query_expression(A). { pCxt->pRootNode = A; }
/************************************************ literal *************************************************************/ /************************************************ literal *************************************************************/
......
...@@ -883,6 +883,16 @@ SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables) { ...@@ -883,6 +883,16 @@ SNode* createDropTableStmt(SAstCreateContext* pCxt, SNodeList* pTables) {
return (SNode*)pStmt; return (SNode*)pStmt;
} }
SNode* createDropSuperTableStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SNode* pRealTable) {
SDropSuperTableStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_SUPER_TABLE_STMT);
CHECK_OUT_OF_MEM(pStmt);
strcpy(pStmt->dbName, ((SRealTableNode*)pRealTable)->table.dbName);
strcpy(pStmt->tableName, ((SRealTableNode*)pRealTable)->table.tableName);
pStmt->ignoreNotExists = ignoreNotExists;
nodesDestroyNode(pRealTable);
return (SNode*)pStmt;
}
SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName) { SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName) {
SUseDatabaseStmt* pStmt = (SUseDatabaseStmt*)nodesMakeNode(QUERY_NODE_USE_DATABASE_STMT); SUseDatabaseStmt* pStmt = (SUseDatabaseStmt*)nodesMakeNode(QUERY_NODE_USE_DATABASE_STMT);
CHECK_OUT_OF_MEM(pStmt); CHECK_OUT_OF_MEM(pStmt);
...@@ -890,10 +900,18 @@ SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName) { ...@@ -890,10 +900,18 @@ SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName) {
return (SNode*)pStmt; return (SNode*)pStmt;
} }
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type) { SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pDbName) {
SNode* pStmt = nodesMakeNode(type);; if (!checkDbName(pCxt, pDbName)) {
return NULL;
}
SShowStmt* pStmt = nodesMakeNode(type);;
CHECK_OUT_OF_MEM(pStmt); CHECK_OUT_OF_MEM(pStmt);
return pStmt; if (NULL != pDbName) {
strncpy(pStmt->dbName, pDbName->z, pDbName->n);
} else if (NULL != pCxt->pQueryCxt->db) {
strcpy(pStmt->dbName, pCxt->pQueryCxt->db);
}
return (SNode*)pStmt;
} }
SNode* createCreateUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, const SToken* pPassword) { SNode* createCreateUserStmt(SAstCreateContext* pCxt, const SToken* pUserName, const SToken* pPassword) {
......
...@@ -858,6 +858,55 @@ static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableSt ...@@ -858,6 +858,55 @@ static int32_t translateCreateSuperTable(STranslateContext* pCxt, SCreateTableSt
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
static int32_t doTranslateDropSuperTable(STranslateContext* pCxt, const SName* pTableName, bool ignoreNotExists) {
SMDropStbReq dropReq = {0};
tNameExtractFullName(pTableName, dropReq.name);
dropReq.igNotExists = ignoreNotExists;
pCxt->pCmdMsg = malloc(sizeof(SCmdMsgInfo));
if (NULL== pCxt->pCmdMsg) {
return TSDB_CODE_OUT_OF_MEMORY;
}
pCxt->pCmdMsg->epSet = pCxt->pParseCxt->mgmtEpSet;
pCxt->pCmdMsg->msgType = TDMT_MND_DROP_STB;
pCxt->pCmdMsg->msgLen = tSerializeSMDropStbReq(NULL, 0, &dropReq);
pCxt->pCmdMsg->pMsg = malloc(pCxt->pCmdMsg->msgLen);
if (NULL== pCxt->pCmdMsg->pMsg) {
return TSDB_CODE_OUT_OF_MEMORY;
}
tSerializeSMDropStbReq(pCxt->pCmdMsg->pMsg, pCxt->pCmdMsg->msgLen, &dropReq);
return TSDB_CODE_SUCCESS;
}
static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt) {
SDropTableClause* pClause = nodesListGetNode(pStmt->pTables, 0);
SName tableName = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId };
strcpy(tableName.dbname, pClause->dbName);
strcpy(tableName.tname, pClause->tableName);
STableMeta* pTableMeta = NULL;
int32_t code = catalogGetTableMeta(pCxt->pParseCxt->pCatalog, pCxt->pParseCxt->pTransporter, &(pCxt->pParseCxt->mgmtEpSet), &tableName, &pTableMeta);
if (TSDB_CODE_SUCCESS == code) {
if (TSDB_SUPER_TABLE == pTableMeta->tableType) {
code = doTranslateDropSuperTable(pCxt, &tableName, pClause->ignoreNotExists);
} else {
// todo;
code = TSDB_CODE_FAILED;
}
}
tfree(pTableMeta);
return code;
}
static int32_t translateDropSuperTable(STranslateContext* pCxt, SDropSuperTableStmt* pStmt) {
SName tableName = { .type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId };
strcpy(tableName.dbname, pStmt->dbName);
strcpy(tableName.tname, pStmt->tableName);
return doTranslateDropSuperTable(pCxt, &tableName, pStmt->ignoreNotExists);
}
static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* pStmt) { static int32_t translateUseDatabase(STranslateContext* pCxt, SUseDatabaseStmt* pStmt) {
SName name = {0}; SName name = {0};
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName)); tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
...@@ -1005,17 +1054,19 @@ static int32_t nodeTypeToShowType(ENodeType nt) { ...@@ -1005,17 +1054,19 @@ static int32_t nodeTypeToShowType(ENodeType nt) {
return TSDB_MGMT_TABLE_USER; return TSDB_MGMT_TABLE_USER;
case QUERY_NODE_SHOW_DNODES_STMT: case QUERY_NODE_SHOW_DNODES_STMT:
return TSDB_MGMT_TABLE_DNODE; return TSDB_MGMT_TABLE_DNODE;
case QUERY_NODE_SHOW_VGROUPS_STMT:
return TSDB_MGMT_TABLE_VGROUP;
default: default:
break; break;
} }
return 0; return 0;
} }
static int32_t translateShow(STranslateContext* pCxt, ENodeType type) { static int32_t translateShow(STranslateContext* pCxt, SShowStmt* pStmt) {
SShowReq showReq = { .type = nodeTypeToShowType(type) }; SShowReq showReq = { .type = nodeTypeToShowType(nodeType(pStmt)) };
if (NULL != pCxt->pParseCxt->db) { if ('\0' != pStmt->dbName[0]) {
SName name = {0}; SName name = {0};
tNameSetDbName(&name, pCxt->pParseCxt->acctId, pCxt->pParseCxt->db, strlen(pCxt->pParseCxt->db)); tNameSetDbName(&name, pCxt->pParseCxt->acctId, pStmt->dbName, strlen(pStmt->dbName));
char dbFname[TSDB_DB_FNAME_LEN] = {0}; char dbFname[TSDB_DB_FNAME_LEN] = {0};
tNameGetFullDbName(&name, showReq.db); tNameGetFullDbName(&name, showReq.db);
} }
...@@ -1079,6 +1130,12 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { ...@@ -1079,6 +1130,12 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
case QUERY_NODE_CREATE_TABLE_STMT: case QUERY_NODE_CREATE_TABLE_STMT:
code = translateCreateSuperTable(pCxt, (SCreateTableStmt*)pNode); code = translateCreateSuperTable(pCxt, (SCreateTableStmt*)pNode);
break; break;
case QUERY_NODE_DROP_TABLE_STMT:
code = translateDropTable(pCxt, (SDropTableStmt*)pNode);
break;
case QUERY_NODE_DROP_SUPER_TABLE_STMT:
code = translateDropSuperTable(pCxt, (SDropSuperTableStmt*)pNode);
break;
case QUERY_NODE_CREATE_USER_STMT: case QUERY_NODE_CREATE_USER_STMT:
code = translateCreateUser(pCxt, (SCreateUserStmt*)pNode); code = translateCreateUser(pCxt, (SCreateUserStmt*)pNode);
break; break;
...@@ -1101,7 +1158,8 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) { ...@@ -1101,7 +1158,8 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
case QUERY_NODE_SHOW_STABLES_STMT: case QUERY_NODE_SHOW_STABLES_STMT:
case QUERY_NODE_SHOW_USERS_STMT: case QUERY_NODE_SHOW_USERS_STMT:
case QUERY_NODE_SHOW_DNODES_STMT: case QUERY_NODE_SHOW_DNODES_STMT:
code = translateShow(pCxt, nodeType(pNode)); case QUERY_NODE_SHOW_VGROUPS_STMT:
code = translateShow(pCxt, (SShowStmt*)pNode);
break; break;
case QUERY_NODE_SHOW_TABLES_STMT: case QUERY_NODE_SHOW_TABLES_STMT:
code = translateShowTables(pCxt); code = translateShowTables(pCxt);
......
此差异已折叠。
...@@ -546,10 +546,12 @@ static SSubplan* createPhysiSubplan(SPhysiPlanContext* pCxt, SSubLogicPlan* pLog ...@@ -546,10 +546,12 @@ static SSubplan* createPhysiSubplan(SPhysiPlanContext* pCxt, SSubLogicPlan* pLog
static int32_t splitLogicPlan(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubLogicPlan** pSubLogicPlan) { static int32_t splitLogicPlan(SPhysiPlanContext* pCxt, SLogicNode* pLogicNode, SSubLogicPlan** pSubLogicPlan) {
*pSubLogicPlan = (SSubLogicPlan*)nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN); *pSubLogicPlan = (SSubLogicPlan*)nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN);
CHECK_ALLOC(*pSubLogicPlan, TSDB_CODE_OUT_OF_MEMORY); CHECK_ALLOC(*pSubLogicPlan, TSDB_CODE_OUT_OF_MEMORY);
// todo pSubplan->pNode = nodesCloneNode(pLogicNode); (*pSubLogicPlan)->pNode = nodesCloneNode(pLogicNode);
(*pSubLogicPlan)->pNode = pLogicNode;
if (QUERY_NODE_LOGIC_PLAN_VNODE_MODIF == nodeType(pLogicNode)) { if (QUERY_NODE_LOGIC_PLAN_VNODE_MODIF == nodeType(pLogicNode)) {
(*pSubLogicPlan)->subplanType = SUBPLAN_TYPE_MODIFY; (*pSubLogicPlan)->subplanType = SUBPLAN_TYPE_MODIFY;
TSWAP(((SVnodeModifLogicNode*)pLogicNode)->pDataBlocks, ((SVnodeModifLogicNode*)(*pSubLogicPlan)->pNode)->pDataBlocks, SArray*);
} else {
(*pSubLogicPlan)->subplanType = SUBPLAN_TYPE_MERGE;
} }
// todo split // todo split
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
...@@ -574,8 +576,7 @@ static int32_t pushSubplan(SPhysiPlanContext* pCxt, SNodeptr pSubplan, int32_t l ...@@ -574,8 +576,7 @@ static int32_t pushSubplan(SPhysiPlanContext* pCxt, SNodeptr pSubplan, int32_t l
SSubLogicPlan* singleCloneSubLogicPlan(SPhysiPlanContext* pCxt, SSubLogicPlan* pSrc, int32_t level) { SSubLogicPlan* singleCloneSubLogicPlan(SPhysiPlanContext* pCxt, SSubLogicPlan* pSrc, int32_t level) {
SSubLogicPlan* pDst = nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN); SSubLogicPlan* pDst = nodesMakeNode(QUERY_NODE_LOGIC_SUBPLAN);
CHECK_ALLOC(pDst, NULL); CHECK_ALLOC(pDst, NULL);
// todo pDst->pNode = nodesCloneNode(pSrc->pNode); pDst->pNode = nodesCloneNode(pSrc->pNode);
pDst->pNode = pSrc->pNode;
if (NULL == pDst->pNode) { if (NULL == pDst->pNode) {
nodesDestroyNode(pDst); nodesDestroyNode(pDst);
return NULL; return NULL;
...@@ -690,6 +691,7 @@ int32_t createPhysiPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SQueryPlan** ...@@ -690,6 +691,7 @@ int32_t createPhysiPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SQueryPlan**
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = buildPhysiPlan(&cxt, pLogicPlan, pPlan); code = buildPhysiPlan(&cxt, pLogicPlan, pPlan);
} }
nodesDestroyNode((SNode*)pLogicPlan); nodesDestroyNode(pSubLogicPlan);
nodesDestroyNode(pLogicPlan);
return code; return code;
} }
...@@ -30,6 +30,7 @@ int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNo ...@@ -30,6 +30,7 @@ int32_t qCreateQueryPlan(SPlanContext* pCxt, SQueryPlan** pPlan, SArray* pExecNo
if (TSDB_CODE_SUCCESS == code) { if (TSDB_CODE_SUCCESS == code) {
code = createPhysiPlan(pCxt, pLogicNode, pPlan, pExecNodeList); code = createPhysiPlan(pCxt, pLogicNode, pPlan, pExecNodeList);
} }
nodesDestroyNode(pLogicNode);
return code; return code;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册