enh: refactor unit test of parser and planner
This commit is contained in:
parent
ab0e6896c5
commit
95f7f165c8
|
@ -30,7 +30,6 @@ typedef struct SAstCreateContext {
|
||||||
SParseContext* pQueryCxt;
|
SParseContext* pQueryCxt;
|
||||||
SMsgBuf msgBuf;
|
SMsgBuf msgBuf;
|
||||||
bool notSupport;
|
bool notSupport;
|
||||||
bool valid;
|
|
||||||
SNode* pRootNode;
|
SNode* pRootNode;
|
||||||
int16_t placeholderNo;
|
int16_t placeholderNo;
|
||||||
int32_t errCode;
|
int32_t errCode;
|
||||||
|
|
|
@ -23,13 +23,12 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
%syntax_error {
|
%syntax_error {
|
||||||
if (pCxt->valid) {
|
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||||
if(TOKEN.z) {
|
if(TOKEN.z) {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z);
|
||||||
} else {
|
} else {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL);
|
||||||
}
|
}
|
||||||
pCxt->valid = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,8 +41,8 @@
|
||||||
%left NK_CONCAT.
|
%left NK_CONCAT.
|
||||||
|
|
||||||
/************************************************ create/alter account *****************************************/
|
/************************************************ create/alter account *****************************************/
|
||||||
cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options. { pCxt->valid = false; pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
|
cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options. { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
|
||||||
cmd ::= ALTER ACCOUNT NK_ID alter_account_options. { pCxt->valid = false; pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
|
cmd ::= ALTER ACCOUNT NK_ID alter_account_options. { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
|
||||||
|
|
||||||
%type account_options { int32_t }
|
%type account_options { int32_t }
|
||||||
%destructor account_options { }
|
%destructor account_options { }
|
||||||
|
@ -323,7 +322,7 @@ cmd ::= SHOW QNODES.
|
||||||
cmd ::= SHOW FUNCTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); }
|
cmd ::= SHOW FUNCTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_FUNCTIONS_STMT, NULL, NULL); }
|
||||||
cmd ::= SHOW INDEXES FROM table_name_cond(A) from_db_opt(B). { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, A, B); }
|
cmd ::= SHOW INDEXES FROM table_name_cond(A) from_db_opt(B). { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_INDEXES_STMT, A, B); }
|
||||||
cmd ::= SHOW STREAMS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); }
|
cmd ::= SHOW STREAMS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); }
|
||||||
cmd ::= SHOW ACCOUNTS. { pCxt->valid = false; pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
|
cmd ::= SHOW ACCOUNTS. { pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
|
||||||
cmd ::= SHOW APPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); }
|
cmd ::= SHOW APPS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); }
|
||||||
cmd ::= SHOW CONNECTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); }
|
cmd ::= SHOW CONNECTIONS. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_CONNECTIONS_STMT, NULL, NULL); }
|
||||||
cmd ::= SHOW LICENCE. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); }
|
cmd ::= SHOW LICENCE. { pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_LICENCE_STMT, NULL, NULL); }
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#define CHECK_OUT_OF_MEM(p) \
|
#define CHECK_OUT_OF_MEM(p) \
|
||||||
do { \
|
do { \
|
||||||
if (NULL == (p)) { \
|
if (NULL == (p)) { \
|
||||||
pCxt->valid = false; \
|
pCxt->errCode = TSDB_CODE_OUT_OF_MEMORY; \
|
||||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "Out of memory"); \
|
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "Out of memory"); \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
} \
|
} \
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
#define CHECK_RAW_EXPR_NODE(node) \
|
#define CHECK_RAW_EXPR_NODE(node) \
|
||||||
do { \
|
do { \
|
||||||
if (NULL == (node) || QUERY_NODE_RAW_EXPR != nodeType(node)) { \
|
if (NULL == (node) || QUERY_NODE_RAW_EXPR != nodeType(node)) { \
|
||||||
pCxt->valid = false; \
|
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR; \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
@ -42,7 +42,6 @@ void initAstCreateContext(SParseContext* pParseCxt, SAstCreateContext* pCxt) {
|
||||||
pCxt->msgBuf.buf = pParseCxt->pMsg;
|
pCxt->msgBuf.buf = pParseCxt->pMsg;
|
||||||
pCxt->msgBuf.len = pParseCxt->msgLen;
|
pCxt->msgBuf.len = pParseCxt->msgLen;
|
||||||
pCxt->notSupport = false;
|
pCxt->notSupport = false;
|
||||||
pCxt->valid = true;
|
|
||||||
pCxt->pRootNode = NULL;
|
pCxt->pRootNode = NULL;
|
||||||
pCxt->placeholderNo = 0;
|
pCxt->placeholderNo = 0;
|
||||||
pCxt->errCode = TSDB_CODE_SUCCESS;
|
pCxt->errCode = TSDB_CODE_SUCCESS;
|
||||||
|
@ -64,42 +63,38 @@ static void trimEscape(SToken* pName) {
|
||||||
|
|
||||||
static bool checkUserName(SAstCreateContext* pCxt, SToken* pUserName) {
|
static bool checkUserName(SAstCreateContext* pCxt, SToken* pUserName) {
|
||||||
if (NULL == pUserName) {
|
if (NULL == pUserName) {
|
||||||
pCxt->valid = false;
|
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||||
} else {
|
} else {
|
||||||
if (pUserName->n >= TSDB_USER_LEN) {
|
if (pUserName->n >= TSDB_USER_LEN) {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
|
||||||
pCxt->valid = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (pCxt->valid) {
|
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||||
trimEscape(pUserName);
|
trimEscape(pUserName);
|
||||||
}
|
}
|
||||||
return pCxt->valid;
|
return TSDB_CODE_SUCCESS == pCxt->errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken, char* pPassword) {
|
static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken, char* pPassword) {
|
||||||
if (NULL == pPasswordToken) {
|
if (NULL == pPasswordToken) {
|
||||||
pCxt->valid = false;
|
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||||
} else if (pPasswordToken->n >= (TSDB_USET_PASSWORD_LEN - 2)) {
|
} else if (pPasswordToken->n >= (TSDB_USET_PASSWORD_LEN - 2)) {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
|
||||||
pCxt->valid = false;
|
|
||||||
} else {
|
} else {
|
||||||
strncpy(pPassword, pPasswordToken->z, pPasswordToken->n);
|
strncpy(pPassword, pPasswordToken->z, pPasswordToken->n);
|
||||||
strdequote(pPassword);
|
strdequote(pPassword);
|
||||||
if (strtrim(pPassword) <= 0) {
|
if (strtrim(pPassword) <= 0) {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_PASSWD_EMPTY);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_PASSWD_EMPTY);
|
||||||
pCxt->valid = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pCxt->valid;
|
return TSDB_CODE_SUCCESS == pCxt->errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool checkAndSplitEndpoint(SAstCreateContext* pCxt, const SToken* pEp, char* pFqdn, int32_t* pPort) {
|
static bool checkAndSplitEndpoint(SAstCreateContext* pCxt, const SToken* pEp, char* pFqdn, int32_t* pPort) {
|
||||||
if (NULL == pEp) {
|
if (NULL == pEp) {
|
||||||
pCxt->valid = false;
|
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||||
} else if (pEp->n >= TSDB_FQDN_LEN + 2 + 6) { // format 'fqdn:port'
|
} else if (pEp->n >= TSDB_FQDN_LEN + 2 + 6) { // format 'fqdn:port'
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
|
||||||
pCxt->valid = false;
|
|
||||||
} else {
|
} else {
|
||||||
char ep[TSDB_FQDN_LEN + 2 + 6];
|
char ep[TSDB_FQDN_LEN + 2 + 6];
|
||||||
strncpy(ep, pEp->z, pEp->n);
|
strncpy(ep, pEp->z, pEp->n);
|
||||||
|
@ -108,65 +103,58 @@ static bool checkAndSplitEndpoint(SAstCreateContext* pCxt, const SToken* pEp, ch
|
||||||
char* pColon = strchr(ep, ':');
|
char* pColon = strchr(ep, ':');
|
||||||
if (NULL == pColon) {
|
if (NULL == pColon) {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ENDPOINT);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_ENDPOINT);
|
||||||
pCxt->valid = false;
|
|
||||||
} else {
|
} else {
|
||||||
strncpy(pFqdn, ep, pColon - ep);
|
strncpy(pFqdn, ep, pColon - ep);
|
||||||
*pPort = strtol(pColon + 1, NULL, 10);
|
*pPort = strtol(pColon + 1, NULL, 10);
|
||||||
if (*pPort >= UINT16_MAX || *pPort <= 0) {
|
if (*pPort >= UINT16_MAX || *pPort <= 0) {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PORT);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PORT);
|
||||||
pCxt->valid = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pCxt->valid;
|
return TSDB_CODE_SUCCESS == pCxt->errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool checkFqdn(SAstCreateContext* pCxt, const SToken* pFqdn) {
|
static bool checkFqdn(SAstCreateContext* pCxt, const SToken* pFqdn) {
|
||||||
if (NULL == pFqdn) {
|
if (NULL == pFqdn) {
|
||||||
pCxt->valid = false;
|
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||||
} else {
|
} else {
|
||||||
if (pFqdn->n >= TSDB_FQDN_LEN) {
|
if (pFqdn->n >= TSDB_FQDN_LEN) {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG);
|
||||||
pCxt->valid = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pCxt->valid;
|
return TSDB_CODE_SUCCESS == pCxt->errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool checkPort(SAstCreateContext* pCxt, const SToken* pPortToken, int32_t* pPort) {
|
static bool checkPort(SAstCreateContext* pCxt, const SToken* pPortToken, int32_t* pPort) {
|
||||||
if (NULL == pPortToken) {
|
if (NULL == pPortToken) {
|
||||||
pCxt->valid = false;
|
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||||
} else {
|
} else {
|
||||||
*pPort = strtol(pPortToken->z, NULL, 10);
|
*pPort = strtol(pPortToken->z, NULL, 10);
|
||||||
if (*pPort >= UINT16_MAX || *pPort <= 0) {
|
if (*pPort >= UINT16_MAX || *pPort <= 0) {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PORT);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_PORT);
|
||||||
pCxt->valid = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pCxt->valid;
|
return TSDB_CODE_SUCCESS == pCxt->errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool checkDbName(SAstCreateContext* pCxt, SToken* pDbName, bool query) {
|
static bool checkDbName(SAstCreateContext* pCxt, SToken* pDbName, bool query) {
|
||||||
if (NULL == pDbName) {
|
if (NULL == pDbName) {
|
||||||
if (query && NULL == pCxt->pQueryCxt->db) {
|
if (query && NULL == pCxt->pQueryCxt->db) {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_DB_NOT_SPECIFIED);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_DB_NOT_SPECIFIED);
|
||||||
pCxt->valid = false;
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
trimEscape(pDbName);
|
trimEscape(pDbName);
|
||||||
if (pDbName->n >= TSDB_DB_NAME_LEN) {
|
if (pDbName->n >= TSDB_DB_NAME_LEN) {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pDbName->z);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pDbName->z);
|
||||||
pCxt->valid = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return pCxt->valid;
|
return TSDB_CODE_SUCCESS == pCxt->errCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool checkTableName(SAstCreateContext* pCxt, SToken* pTableName) {
|
static bool checkTableName(SAstCreateContext* pCxt, SToken* pTableName) {
|
||||||
trimEscape(pTableName);
|
trimEscape(pTableName);
|
||||||
if (NULL != pTableName && pTableName->n >= TSDB_TABLE_NAME_LEN) {
|
if (NULL != pTableName && pTableName->n >= TSDB_TABLE_NAME_LEN) {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pTableName->z);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pTableName->z);
|
||||||
pCxt->valid = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -176,7 +164,6 @@ static bool checkColumnName(SAstCreateContext* pCxt, SToken* pColumnName) {
|
||||||
trimEscape(pColumnName);
|
trimEscape(pColumnName);
|
||||||
if (NULL != pColumnName && pColumnName->n >= TSDB_COL_NAME_LEN) {
|
if (NULL != pColumnName && pColumnName->n >= TSDB_COL_NAME_LEN) {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pColumnName->z);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pColumnName->z);
|
||||||
pCxt->valid = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -186,7 +173,6 @@ static bool checkIndexName(SAstCreateContext* pCxt, SToken* pIndexName) {
|
||||||
trimEscape(pIndexName);
|
trimEscape(pIndexName);
|
||||||
if (NULL != pIndexName && pIndexName->n >= TSDB_INDEX_NAME_LEN) {
|
if (NULL != pIndexName && pIndexName->n >= TSDB_INDEX_NAME_LEN) {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pIndexName->z);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME, pIndexName->z);
|
||||||
pCxt->valid = false;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -225,7 +211,7 @@ SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
|
||||||
|
|
||||||
SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
|
SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
|
||||||
if (NULL == pNode || QUERY_NODE_RAW_EXPR != nodeType(pNode)) {
|
if (NULL == pNode || QUERY_NODE_RAW_EXPR != nodeType(pNode)) {
|
||||||
pCxt->valid = false;
|
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||||
return nil_token;
|
return nil_token;
|
||||||
}
|
}
|
||||||
SRawExprNode* target = (SRawExprNode*)pNode;
|
SRawExprNode* target = (SRawExprNode*)pNode;
|
||||||
|
@ -236,16 +222,12 @@ SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
|
||||||
SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode) {
|
SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode) {
|
||||||
SNodeList* list = nodesMakeList();
|
SNodeList* list = nodesMakeList();
|
||||||
CHECK_OUT_OF_MEM(list);
|
CHECK_OUT_OF_MEM(list);
|
||||||
if (TSDB_CODE_SUCCESS != nodesListAppend(list, pNode)) {
|
pCxt->errCode = nodesListAppend(list, pNode);
|
||||||
pCxt->valid = false;
|
|
||||||
}
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode) {
|
SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode) {
|
||||||
if (TSDB_CODE_SUCCESS != nodesListAppend(pList, pNode)) {
|
pCxt->errCode = nodesListAppend(pList, pNode);
|
||||||
pCxt->valid = false;
|
|
||||||
}
|
|
||||||
return pList;
|
return pList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -532,7 +514,7 @@ SNode* createGroupingSetNode(SAstCreateContext* pCxt, SNode* pNode) {
|
||||||
}
|
}
|
||||||
|
|
||||||
SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* pAlias) {
|
SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* pAlias) {
|
||||||
if (NULL == pNode || !pCxt->valid) {
|
if (NULL == pNode || TSDB_CODE_SUCCESS != pCxt->errCode) {
|
||||||
return pNode;
|
return pNode;
|
||||||
}
|
}
|
||||||
int32_t len = TMIN(sizeof(((SExprNode*)pNode)->aliasName) - 1, pAlias->n);
|
int32_t len = TMIN(sizeof(((SExprNode*)pNode)->aliasName) - 1, pAlias->n);
|
||||||
|
@ -996,7 +978,7 @@ static bool needDbShowStmt(ENodeType type) {
|
||||||
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern) {
|
SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, SNode* pTbNamePattern) {
|
||||||
if (needDbShowStmt(type) && NULL == pDbName && NULL == pCxt->pQueryCxt->db) {
|
if (needDbShowStmt(type) && NULL == pDbName && NULL == pCxt->pQueryCxt->db) {
|
||||||
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "db not specified");
|
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "db not specified");
|
||||||
pCxt->valid = false;
|
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
SShowStmt* pStmt = nodesMakeNode(type);
|
SShowStmt* pStmt = nodesMakeNode(type);
|
||||||
|
@ -1257,7 +1239,7 @@ SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups) {
|
||||||
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName,
|
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool ignoreExists, bool aggFunc, const SToken* pFuncName,
|
||||||
const SToken* pLibPath, SDataType dataType, int32_t bufSize) {
|
const SToken* pLibPath, SDataType dataType, int32_t bufSize) {
|
||||||
if (pLibPath->n <= 2) {
|
if (pLibPath->n <= 2) {
|
||||||
pCxt->valid = false;
|
pCxt->errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
SCreateFunctionStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_FUNCTION_STMT);
|
SCreateFunctionStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_FUNCTION_STMT);
|
||||||
|
|
|
@ -53,20 +53,20 @@ int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) {
|
||||||
}
|
}
|
||||||
case TK_NK_ILLEGAL: {
|
case TK_NK_ILLEGAL: {
|
||||||
snprintf(cxt.pQueryCxt->pMsg, cxt.pQueryCxt->msgLen, "unrecognized token: \"%s\"", t0.z);
|
snprintf(cxt.pQueryCxt->pMsg, cxt.pQueryCxt->msgLen, "unrecognized token: \"%s\"", t0.z);
|
||||||
cxt.valid = false;
|
cxt.errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||||
goto abort_parse;
|
goto abort_parse;
|
||||||
}
|
}
|
||||||
case TK_NK_HEX:
|
case TK_NK_HEX:
|
||||||
case TK_NK_OCT:
|
case TK_NK_OCT:
|
||||||
case TK_NK_BIN: {
|
case TK_NK_BIN: {
|
||||||
snprintf(cxt.pQueryCxt->pMsg, cxt.pQueryCxt->msgLen, "unsupported token: \"%s\"", t0.z);
|
snprintf(cxt.pQueryCxt->pMsg, cxt.pQueryCxt->msgLen, "unsupported token: \"%s\"", t0.z);
|
||||||
cxt.valid = false;
|
cxt.errCode = TSDB_CODE_PAR_SYNTAX_ERROR;
|
||||||
goto abort_parse;
|
goto abort_parse;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
Parse(pParser, t0.type, t0, &cxt);
|
Parse(pParser, t0.type, t0, &cxt);
|
||||||
// ParseTrace(stdout, "");
|
// ParseTrace(stdout, "");
|
||||||
if (!cxt.valid) {
|
if (TSDB_CODE_SUCCESS != cxt.errCode) {
|
||||||
goto abort_parse;
|
goto abort_parse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) {
|
||||||
|
|
||||||
abort_parse:
|
abort_parse:
|
||||||
ParseFree(pParser, (FFree)taosMemoryFree);
|
ParseFree(pParser, (FFree)taosMemoryFree);
|
||||||
if (cxt.valid) {
|
if (TSDB_CODE_SUCCESS == cxt.errCode) {
|
||||||
*pQuery = taosMemoryCalloc(1, sizeof(SQuery));
|
*pQuery = taosMemoryCalloc(1, sizeof(SQuery));
|
||||||
if (NULL == *pQuery) {
|
if (NULL == *pQuery) {
|
||||||
return TSDB_CODE_OUT_OF_MEMORY;
|
return TSDB_CODE_OUT_OF_MEMORY;
|
||||||
|
|
|
@ -3021,11 +3021,11 @@ static YYACTIONTYPE yy_reduce(
|
||||||
/********** Begin reduce actions **********************************************/
|
/********** Begin reduce actions **********************************************/
|
||||||
YYMINORTYPE yylhsminor;
|
YYMINORTYPE yylhsminor;
|
||||||
case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */
|
case 0: /* cmd ::= CREATE ACCOUNT NK_ID PASS NK_STRING account_options */
|
||||||
{ pCxt->valid = false; pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
|
{ pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
|
||||||
yy_destructor(yypParser,232,&yymsp[0].minor);
|
yy_destructor(yypParser,232,&yymsp[0].minor);
|
||||||
break;
|
break;
|
||||||
case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */
|
case 1: /* cmd ::= ALTER ACCOUNT NK_ID alter_account_options */
|
||||||
{ pCxt->valid = false; pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
|
{ pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
|
||||||
yy_destructor(yypParser,233,&yymsp[0].minor);
|
yy_destructor(yypParser,233,&yymsp[0].minor);
|
||||||
break;
|
break;
|
||||||
case 2: /* account_options ::= */
|
case 2: /* account_options ::= */
|
||||||
|
@ -3591,7 +3591,7 @@ static YYACTIONTYPE yy_reduce(
|
||||||
{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); }
|
{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_STREAMS_STMT, NULL, NULL); }
|
||||||
break;
|
break;
|
||||||
case 178: /* cmd ::= SHOW ACCOUNTS */
|
case 178: /* cmd ::= SHOW ACCOUNTS */
|
||||||
{ pCxt->valid = false; pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
|
{ pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_EXPRIE_STATEMENT); }
|
||||||
break;
|
break;
|
||||||
case 179: /* cmd ::= SHOW APPS */
|
case 179: /* cmd ::= SHOW APPS */
|
||||||
{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); }
|
{ pCxt->pRootNode = createShowStmt(pCxt, QUERY_NODE_SHOW_APPS_STMT, NULL, NULL); }
|
||||||
|
@ -4353,13 +4353,12 @@ static void yy_syntax_error(
|
||||||
#define TOKEN yyminor
|
#define TOKEN yyminor
|
||||||
/************ Begin %syntax_error code ****************************************/
|
/************ Begin %syntax_error code ****************************************/
|
||||||
|
|
||||||
if (pCxt->valid) {
|
if (TSDB_CODE_SUCCESS == pCxt->errCode) {
|
||||||
if(TOKEN.z) {
|
if(TOKEN.z) {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_SYNTAX_ERROR, TOKEN.z);
|
||||||
} else {
|
} else {
|
||||||
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL);
|
pCxt->errCode = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INCOMPLETE_SQL);
|
||||||
}
|
}
|
||||||
pCxt->valid = false;
|
|
||||||
}
|
}
|
||||||
/************ End %syntax_error code ******************************************/
|
/************ End %syntax_error code ******************************************/
|
||||||
ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
|
ParseARG_STORE /* Suppress warning about unused %extra_argument variable */
|
||||||
|
|
|
@ -53,4 +53,10 @@ TEST_F(ParserInitialATest, alterUser) {
|
||||||
run("alter user wxy privilege 'write'");
|
run("alter user wxy privilege 'write'");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(ParserInitialATest, bug001) {
|
||||||
|
useDb("root", "test");
|
||||||
|
|
||||||
|
run("alter database db wal 0 # td-14436");
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ParserTest
|
} // namespace ParserTest
|
Loading…
Reference in New Issue