提交 d5107df7 编写于 作者: X Xiaoyu Wang

TD-13120 SELECT statement syntax definition

上级 d7e304f0
...@@ -207,52 +207,36 @@ ...@@ -207,52 +207,36 @@
#define TK_INTO 189 #define TK_INTO 189
#define TK_VALUES 190 #define TK_VALUES 190
#define NEW_TK_OR 1 #define NEW_TK_UNION 1
#define NEW_TK_AND 2 #define NEW_TK_ALL 2
#define NEW_TK_NOT 3 #define NEW_TK_MINUS 3
#define NEW_TK_EQ 4 #define NEW_TK_EXCEPT 4
#define NEW_TK_NE 5 #define NEW_TK_INTERSECT 5
#define NEW_TK_ISNULL 6 #define NEW_TK_NK_PLUS 6
#define NEW_TK_NOTNULL 7 #define NEW_TK_NK_MINUS 7
#define NEW_TK_IS 8 #define NEW_TK_NK_STAR 8
#define NEW_TK_LIKE 9 #define NEW_TK_NK_SLASH 9
#define NEW_TK_MATCH 10 #define NEW_TK_SHOW 10
#define NEW_TK_NMATCH 11 #define NEW_TK_DATABASES 11
#define NEW_TK_GLOB 12 #define NEW_TK_NK_ID 12
#define NEW_TK_BETWEEN 13 #define NEW_TK_NK_LP 13
#define NEW_TK_IN 14 #define NEW_TK_NK_RP 14
#define NEW_TK_GT 15 #define NEW_TK_NK_COMMA 15
#define NEW_TK_GE 16 #define NEW_TK_NK_LITERAL 16
#define NEW_TK_LT 17 #define NEW_TK_NK_DOT 17
#define NEW_TK_LE 18 #define NEW_TK_SELECT 18
#define NEW_TK_BITAND 19 #define NEW_TK_DISTINCT 19
#define NEW_TK_BITOR 20 #define NEW_TK_AS 20
#define NEW_TK_LSHIFT 21 #define NEW_TK_FROM 21
#define NEW_TK_RSHIFT 22 #define NEW_TK_WITH 22
#define NEW_TK_NK_PLUS 23 #define NEW_TK_RECURSIVE 23
#define NEW_TK_NK_MINUS 24 #define NEW_TK_ORDER 24
#define NEW_TK_DIVIDE 25 #define NEW_TK_BY 25
#define NEW_TK_TIMES 26 #define NEW_TK_ASC 26
#define NEW_TK_NK_STAR 27 #define NEW_TK_DESC 27
#define NEW_TK_NK_SLASH 28 #define NEW_TK_NULLS 28
#define NEW_TK_REM 29 #define NEW_TK_FIRST 29
#define NEW_TK_CONCAT 30 #define NEW_TK_LAST 30
#define NEW_TK_UMINUS 31
#define NEW_TK_UPLUS 32
#define NEW_TK_BITNOT 33
#define NEW_TK_SHOW 34
#define NEW_TK_DATABASES 35
#define NEW_TK_NK_ID 36
#define NEW_TK_NK_LP 37
#define NEW_TK_NK_RP 38
#define NEW_TK_NK_COMMA 39
#define NEW_TK_NK_LITERAL 40
#define NEW_TK_NK_DOT 41
#define NEW_TK_SELECT 42
#define NEW_TK_DISTINCT 43
#define NEW_TK_ALL 44
#define NEW_TK_AS 45
#define NEW_TK_FROM 46
#define TK_SPACE 300 #define TK_SPACE 300
#define TK_COMMENT 301 #define TK_COMMENT 301
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
extern "C" { extern "C" {
#endif #endif
#include "tarray.h"
#include "tdef.h" #include "tdef.h"
typedef enum ENodeType { typedef enum ENodeType {
...@@ -35,6 +34,7 @@ typedef enum ENodeType { ...@@ -35,6 +34,7 @@ typedef enum ENodeType {
QUERY_NODE_JOIN_TABLE, QUERY_NODE_JOIN_TABLE,
QUERY_NODE_GROUPING_SET, QUERY_NODE_GROUPING_SET,
QUERY_NODE_ORDER_BY_EXPR, QUERY_NODE_ORDER_BY_EXPR,
QUERY_NODE_LIMIT,
QUERY_NODE_STATE_WINDOW, QUERY_NODE_STATE_WINDOW,
QUERY_NODE_SESSION_WINDOW, QUERY_NODE_SESSION_WINDOW,
QUERY_NODE_INTERVAL_WINDOW, QUERY_NODE_INTERVAL_WINDOW,
...@@ -53,6 +53,7 @@ typedef struct SNode { ...@@ -53,6 +53,7 @@ typedef struct SNode {
} SNode; } SNode;
#define nodeType(nodeptr) (((const SNode*)(nodeptr))->type) #define nodeType(nodeptr) (((const SNode*)(nodeptr))->type)
#define setNodeType(nodeptr, type) (((SNode*)(nodeptr))->type = (type))
typedef struct SListCell { typedef struct SListCell {
SNode* pNode; SNode* pNode;
...@@ -64,8 +65,15 @@ typedef struct SNodeList { ...@@ -64,8 +65,15 @@ typedef struct SNodeList {
SListCell* pHeader; SListCell* pHeader;
} SNodeList; } SNodeList;
#define foreach(node, list) \ #define LIST_LENGTH(l) (NULL != (l) ? (l)->length : 0)
for (SListCell* cell = (NULL != list ? list->pHeader : NULL); (NULL != cell && ? (node = cell->pNode, true) : (node = NULL, false)); cell = cell->pNext)
#define FOREACH(node, list) \
for (SListCell* cell = (NULL != (list) ? (list)->pHeader : NULL); (NULL != cell ? (node = cell->pNode, true) : (node = NULL, false)); cell = cell->pNext)
#define FORBOTH(node1, list1, node2, list2) \
for (SListCell* cell1 = (NULL != (list1) ? (list1)->pHeader : NULL), *cell2 = (NULL != (list2) ? (list2)->pHeader : NULL); \
(NULL == cell1 ? (node1 = NULL, false) : (node1 = cell1->pNode, true)), (NULL == cell2 ? (node2 = NULL, false) : (node2 = cell2->pNode, true)), (node1 != NULL && node2 != NULL); \
cell1 = cell1->pNext, cell2 = cell2->pNext)
typedef struct SDataType { typedef struct SDataType {
uint8_t type; uint8_t type;
...@@ -142,7 +150,7 @@ typedef enum ELogicConditionType { ...@@ -142,7 +150,7 @@ typedef enum ELogicConditionType {
typedef struct SLogicConditionNode { typedef struct SLogicConditionNode {
ENodeType type; // QUERY_NODE_LOGIC_CONDITION ENodeType type; // QUERY_NODE_LOGIC_CONDITION
ELogicConditionType condType; ELogicConditionType condType;
SArray* pParameterList; SNodeList* pParameterList;
} SLogicConditionNode; } SLogicConditionNode;
typedef struct SIsNullCondNode { typedef struct SIsNullCondNode {
...@@ -155,7 +163,7 @@ typedef struct SFunctionNode { ...@@ -155,7 +163,7 @@ typedef struct SFunctionNode {
SExprNode type; // QUERY_NODE_FUNCTION SExprNode type; // QUERY_NODE_FUNCTION
char functionName[TSDB_FUNC_NAME_LEN]; char functionName[TSDB_FUNC_NAME_LEN];
int32_t funcId; int32_t funcId;
SArray* pParameterList; // SNode SNodeList* pParameterList; // SNode
} SFunctionNode; } SFunctionNode;
typedef struct STableNode { typedef struct STableNode {
...@@ -165,12 +173,12 @@ typedef struct STableNode { ...@@ -165,12 +173,12 @@ typedef struct STableNode {
} STableNode; } STableNode;
typedef struct SRealTableNode { typedef struct SRealTableNode {
STableNode type; // QUERY_NODE_REAL_TABLE STableNode table; // QUERY_NODE_REAL_TABLE
char dbName[TSDB_DB_NAME_LEN]; char dbName[TSDB_DB_NAME_LEN];
} SRealTableNode; } SRealTableNode;
typedef struct STempTableNode { typedef struct STempTableNode {
STableNode type; // QUERY_NODE_TEMP_TABLE STableNode table; // QUERY_NODE_TEMP_TABLE
SNode* pSubquery; SNode* pSubquery;
} STempTableNode; } STempTableNode;
...@@ -179,7 +187,7 @@ typedef enum EJoinType { ...@@ -179,7 +187,7 @@ typedef enum EJoinType {
} EJoinType; } EJoinType;
typedef struct SJoinTableNode { typedef struct SJoinTableNode {
STableNode type; // QUERY_NODE_JOIN_TABLE STableNode table; // QUERY_NODE_JOIN_TABLE
EJoinType joinType; EJoinType joinType;
SNode* pLeft; SNode* pLeft;
SNode* pRight; SNode* pRight;
...@@ -193,7 +201,7 @@ typedef enum EGroupingSetType { ...@@ -193,7 +201,7 @@ typedef enum EGroupingSetType {
typedef struct SGroupingSetNode { typedef struct SGroupingSetNode {
ENodeType type; // QUERY_NODE_GROUPING_SET ENodeType type; // QUERY_NODE_GROUPING_SET
EGroupingSetType groupingSetType; EGroupingSetType groupingSetType;
SArray* pParameterList; SNodeList* pParameterList;
} SGroupingSetNode; } SGroupingSetNode;
typedef enum EOrder { typedef enum EOrder {
...@@ -214,10 +222,11 @@ typedef struct SOrderByExprNode { ...@@ -214,10 +222,11 @@ typedef struct SOrderByExprNode {
ENullOrder nullOrder; ENullOrder nullOrder;
} SOrderByExprNode; } SOrderByExprNode;
typedef struct SLimitInfo { typedef struct SLimitNode {
ENodeType type; // QUERY_NODE_LIMIT
uint64_t limit; uint64_t limit;
uint64_t offset; uint64_t offset;
} SLimitInfo; } SLimitNode;
typedef struct SStateWindowNode { typedef struct SStateWindowNode {
ENodeType type; // QUERY_NODE_STATE_WINDOW ENodeType type; // QUERY_NODE_STATE_WINDOW
...@@ -240,15 +249,16 @@ typedef struct SIntervalWindowNode { ...@@ -240,15 +249,16 @@ typedef struct SIntervalWindowNode {
typedef struct SSelectStmt { typedef struct SSelectStmt {
ENodeType type; // QUERY_NODE_SELECT_STMT ENodeType type; // QUERY_NODE_SELECT_STMT
bool isDistinct; bool isDistinct;
SArray* pProjectionList; // SNode bool isStar;
SNodeList* pProjectionList; // SNode
SNode* pFromTable; SNode* pFromTable;
SNode* pWhereCond; SNode* pWhereCond;
SArray* pPartitionByList; // SNode SNodeList* pPartitionByList; // SNode
SNode* pWindowClause; SNode* pWindowClause;
SArray* pGroupByList; // SGroupingSetNode SNodeList* pGroupByList; // SGroupingSetNode
SArray* pOrderByList; // SOrderByExprNode SNodeList* pOrderByList; // SOrderByExprNode
SLimitInfo limit; SLimitNode limit;
SLimitInfo slimit; SLimitNode slimit;
} SSelectStmt; } SSelectStmt;
typedef enum ESetOperatorType { typedef enum ESetOperatorType {
...@@ -264,8 +274,8 @@ typedef struct SSetOperator { ...@@ -264,8 +274,8 @@ typedef struct SSetOperator {
typedef bool (*FQueryNodeWalker)(SNode* pNode, void* pContext); typedef bool (*FQueryNodeWalker)(SNode* pNode, void* pContext);
bool nodesWalkArray(SArray* pArray, FQueryNodeWalker walker, void* pContext);
bool nodesWalkNode(SNode* pNode, FQueryNodeWalker walker, void* pContext); bool nodesWalkNode(SNode* pNode, FQueryNodeWalker walker, void* pContext);
bool nodesWalkNodeList(SNodeList* pNodeList, FQueryNodeWalker walker, void* pContext);
bool nodesWalkStmt(SNode* pNode, FQueryNodeWalker walker, void* pContext); bool nodesWalkStmt(SNode* pNode, FQueryNodeWalker walker, void* pContext);
......
...@@ -17,23 +17,37 @@ ...@@ -17,23 +17,37 @@
#include "nodesShowStmts.h" #include "nodesShowStmts.h"
#include "parser.h" #include "parser.h"
typedef void* (*FMalloc)(size_t); #ifndef _TD_AST_CREATE_FUNCS_H_
typedef void (*FFree)(void*); #define _TD_AST_CREATE_FUNCS_H_
typedef struct SAstCreaterContext { #ifdef __cplusplus
extern "C" {
#endif
typedef struct SAstCreateContext {
SParseContext* pQueryCxt; SParseContext* pQueryCxt;
bool notSupport; bool notSupport;
bool valid; bool valid;
SNode* pRootNode; SNode* pRootNode;
FMalloc mallocFunc; } SAstCreateContext;
FFree freeFunc;
} SAstCreaterContext; int32_t createAstCreater(const SParseContext* pQueryCxt, SAstCreateContext* pCxt);
int32_t destroyAstCreater(SAstCreateContext* pCxt);
SNodeList* addNodeToList(SAstCreaterContext* pCxt, SNodeList* pList, SNode* pNode);
SNode* createColumnNode(SAstCreaterContext* pCxt, SToken* pDbName, SToken* pTableName, SToken* pColumnName); bool checkTableName(const SToken* pTableName);
SNodeList* createNodeList(SAstCreaterContext* pCxt, SNode* pNode);
SNode* createOrderByExprNode(SAstCreaterContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder); SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode);
SNode* createSelectStmt(SAstCreaterContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable); SNode* createColumnNode(SAstCreateContext* pCxt, const SToken* pTableName, const SToken* pColumnName);
SNode* createSetOperator(SAstCreaterContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight); SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode);
SNode* createShowStmt(SAstCreaterContext* pCxt, EShowStmtType type); SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder);
SNode* setProjectionAlias(SAstCreaterContext* pCxt, SNode* pNode, SToken* pAlias); SNode* createRealTableNode(SAstCreateContext* pCxt, const SToken* pDbName, const SToken* pTableName);
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable);
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight);
SNode* createShowStmt(SAstCreateContext* pCxt, EShowStmtType type);
SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* pAlias);
#ifdef __cplusplus
}
#endif
#endif /*_TD_AST_CREATE_FUNCS_H_*/
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _TD_AST_CREATER_H_
#define _TD_AST_CREATER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "nodes.h"
#include "parser.h"
typedef struct SQuery {
SNode* pRoot;
} SQuery;
int32_t doParse(SParseContext* pParseCxt, SQuery* pQuery);
#ifdef __cplusplus
}
#endif
#endif /*_TD_AST_CREATER_H_*/
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
%name NewParse %name NewParse
%token_prefix NEW_TK_ %token_prefix NEW_TK_
%token_type { SToken* } %token_type { SToken }
%default_type { SNode* } %default_type { SNode* }
%default_destructor { nodesDestroyNode($$); } %default_destructor { nodesDestroyNode($$); }
%extra_argument { SAstCreaterContext* pCxt } %extra_argument { SAstCreateContext* pCxt }
%include { %include {
#include <stdio.h> #include <stdio.h>
...@@ -21,19 +21,21 @@ ...@@ -21,19 +21,21 @@
#include "ttoken.h" #include "ttoken.h"
#include "ttokendef.h" #include "ttokendef.h"
#include "astCreateFuncs.h" #include "astCreateFuncs.h"
#define PARSER_TRACE printf("rule = %s\n", yyRuleName[yyruleno])
} }
%syntax_error { %syntax_error {
if(TOKEN->z) { if(TOKEN.z) {
char msg[] = "syntax error near \"%s\""; char msg[] = "syntax error near \"%s\"";
int32_t sqlLen = strlen(&TOKEN->z[0]); int32_t sqlLen = strlen(&TOKEN.z[0]);
if (sqlLen + sizeof(msg)/sizeof(msg[0]) + 1 > pCxt->pQueryCxt->msgLen) { if (sqlLen + sizeof(msg)/sizeof(msg[0]) + 1 > pCxt->pQueryCxt->msgLen) {
char tmpstr[128] = {0}; char tmpstr[128] = {0};
memcpy(tmpstr, &TOKEN->z[0], sizeof(tmpstr)/sizeof(tmpstr[0]) - 1); memcpy(tmpstr, &TOKEN.z[0], sizeof(tmpstr)/sizeof(tmpstr[0]) - 1);
sprintf(pCxt->pQueryCxt->pMsg, msg, tmpstr); sprintf(pCxt->pQueryCxt->pMsg, msg, tmpstr);
} else { } else {
sprintf(pCxt->pQueryCxt->pMsg, msg, &TOKEN->z[0]); sprintf(pCxt->pQueryCxt->pMsg, msg, &TOKEN.z[0]);
} }
} else { } else {
sprintf(pCxt->pQueryCxt->pMsg, "Incomplete SQL statement"); sprintf(pCxt->pQueryCxt->pMsg, "Incomplete SQL statement");
...@@ -56,9 +58,9 @@ ...@@ -56,9 +58,9 @@
//%left CONCAT. //%left CONCAT.
//%right UMINUS UPLUS BITNOT. //%right UMINUS UPLUS BITNOT.
cmd ::= SHOW DATABASES. { createShowStmt(pCxt, SHOW_TYPE_DATABASE); } cmd ::= SHOW DATABASES. { PARSER_TRACE; createShowStmt(pCxt, SHOW_TYPE_DATABASE); }
cmd ::= query_expression(A). { pCxt->pRootNode = A; } cmd ::= query_expression(A). { PARSER_TRACE; pCxt->pRootNode = A; }
//////////////////////// value_function ///////////////////////////////// //////////////////////// value_function /////////////////////////////////
value_function ::= NK_ID NK_LP value_expression NK_RP. value_function ::= NK_ID NK_LP value_expression NK_RP.
...@@ -74,9 +76,8 @@ nonparenthesized_value_expression_primary ::= column_reference. ...@@ -74,9 +76,8 @@ nonparenthesized_value_expression_primary ::= column_reference.
literal ::= NK_LITERAL. literal ::= NK_LITERAL.
column_reference(A) ::= NK_ID(B). { A = createColumnNode(pCxt, NULL, NULL, B); } column_reference(A) ::= NK_ID(B). { PARSER_TRACE; A = createColumnNode(pCxt, NULL, &B); }
column_reference(A) ::= NK_ID(B) NK_DOT NK_ID(C). { A = createColumnNode(pCxt, NULL, B, C); } column_reference(A) ::= table_name(B) NK_DOT NK_ID(C). { PARSER_TRACE; A = createColumnNode(pCxt, &B, &C); }
column_reference(A) ::= NK_ID(B) NK_DOT NK_ID(C) NK_DOT NK_ID(D). { A = createColumnNode(pCxt, B, C, D); }
//////////////////////// value_expression ///////////////////////////////// //////////////////////// value_expression /////////////////////////////////
value_expression ::= common_value_expression. value_expression ::= common_value_expression.
...@@ -95,43 +96,64 @@ numeric_primary ::= value_expression_primary. ...@@ -95,43 +96,64 @@ numeric_primary ::= value_expression_primary.
numeric_primary ::= value_function. numeric_primary ::= value_function.
//////////////////////// query_specification ///////////////////////////////// //////////////////////// query_specification /////////////////////////////////
query_specification(A) ::= SELECT set_quantifier_opt(B) select_list(C) from_clause(D). { A = createSelectStmt(pCxt, B, C, D); } query_specification(A) ::= SELECT set_quantifier_opt(B) select_list(C) from_clause(D). { PARSER_TRACE; A = createSelectStmt(pCxt, B, C, D); }
%type set_quantifier_opt { bool } %type set_quantifier_opt { bool }
%destructor set_quantifier_opt {} %destructor set_quantifier_opt {}
set_quantifier_opt(A) ::= . { A = false; } set_quantifier_opt(A) ::= . { PARSER_TRACE; A = false; }
set_quantifier_opt(A) ::= DISTINCT. { A = true; } set_quantifier_opt(A) ::= DISTINCT. { PARSER_TRACE; A = true; }
set_quantifier_opt(A) ::= ALL. { A = false; } set_quantifier_opt(A) ::= ALL. { PARSER_TRACE; A = false; }
%type select_list { SNodeList* } %type select_list { SNodeList* }
%destructor select_list { nodesDestroyNodeList($$); } %destructor select_list { nodesDestroyNodeList($$); }
select_list(A) ::= NK_STAR. { A = NULL; } select_list(A) ::= NK_STAR. { PARSER_TRACE; A = NULL; }
select_list(A) ::= select_sublist(B). { A = B; } select_list(A) ::= select_sublist(B). { PARSER_TRACE; A = B; }
%type select_sublist { SNodeList* } %type select_sublist { SNodeList* }
%destructor select_sublist { nodesDestroyNodeList($$); } %destructor select_sublist { nodesDestroyNodeList($$); }
select_sublist(A) ::= select_item(B). { A = createNodeList(pCxt, B); } select_sublist(A) ::= select_item(B). { PARSER_TRACE; A = createNodeList(pCxt, B); }
select_sublist(A) ::= select_sublist(B) NK_COMMA select_item(C). { A = addNodeToList(pCxt, B, C); } select_sublist(A) ::= select_sublist(B) NK_COMMA select_item(C). { PARSER_TRACE; A = addNodeToList(pCxt, B, C); }
select_item(A) ::= value_expression(B). { A = B; } select_item(A) ::= value_expression(B). { PARSER_TRACE; A = B; }
select_item(A) ::= value_expression(B) AS NK_ID(C). { A = setProjectionAlias(pCxt, B, C); } select_item(A) ::= value_expression(B) AS NK_ID(C). { PARSER_TRACE; A = setProjectionAlias(pCxt, B, &C); }
select_item(A) ::= NK_ID(B) NK_DOT NK_STAR(C). { A = createColumnNode(pCxt, NULL, B, C); } select_item(A) ::= table_name(B) NK_DOT NK_STAR(C). { PARSER_TRACE; A = createColumnNode(pCxt, &B, &C); }
select_item(A) ::= NK_ID(B) NK_DOT NK_ID(C) NK_DOT NK_STAR(D). { A = createColumnNode(pCxt, B, C, D); }
from_clause ::= FROM table_reference_list. from_clause(A) ::= FROM table_reference_list(B). { PARSER_TRACE; A = B; }
table_reference_list ::= table_reference. //%type table_reference_list { SNodeList* }
table_reference_list ::= table_reference_list NK_COMMA table_reference. //%destructor table_reference_list { nodesDestroyNodeList($$); }
table_reference_list(A) ::= table_reference(B). { PARSER_TRACE; A = B; }
//table_reference_list(A) ::= table_reference_list(B) NK_COMMA table_reference(C). { PARSER_TRACE; A = createJoinTableNode(pCxt, B, C); }
table_reference ::= NK_ID. //table_reference(A) ::= NK_ID(B). { PARSER_TRACE; A = createRealTableNode(pCxt, ); }
table_reference(A) ::= table_factor(B). { PARSER_TRACE; A = B; }
//table_reference ::= joined_table. //table_reference ::= joined_table.
table_factor(A) ::= table_primary(B). { PARSER_TRACE; A = B; }
table_primary(A) ::= table_name(B). { PARSER_TRACE; A = createRealTableNode(pCxt, NULL, &B); }
table_primary(A) ::= db_name(B) NK_DOT table_name(C). { PARSER_TRACE; A = createRealTableNode(pCxt, &B, &C); }
table_primary ::= derived_table.
derived_table ::= table_subquery.
%type db_name { SToken }
db_name(A) ::= NK_ID(B). { PARSER_TRACE; A = B; }
%type table_name { SToken }
table_name(A) ::= NK_ID(B). { PARSER_TRACE; A = B; }
//////////////////////// subquery /////////////////////////////////
subquery ::= NK_LR query_expression NK_RP.
table_subquery ::= subquery.
//////////////////////// query_expression ///////////////////////////////// //////////////////////// query_expression /////////////////////////////////
query_expression(A) ::= with_clause_opt query_expression_body(B) order_by_clause_opt limit_clause_opt slimit_clause_opt. { A = B; } query_expression(A) ::= with_clause_opt query_expression_body(B) order_by_clause_opt limit_clause_opt slimit_clause_opt. { PARSER_TRACE; A = B; }
with_clause_opt ::= . {} with_clause_opt ::= . {}
with_clause_opt ::= WITH with_list. { pCxt->notSupport = true; pCxt->valid = false; } with_clause_opt ::= WITH with_list. { PARSER_TRACE; pCxt->notSupport = true; pCxt->valid = false; }
with_clause_opt ::= WITH RECURSIVE with_list. { pCxt->notSupport = true; pCxt->valid = false; } with_clause_opt ::= WITH RECURSIVE with_list. { PARSER_TRACE; pCxt->notSupport = true; pCxt->valid = false; }
with_list ::= with_list_element. {} with_list ::= with_list_element. {}
with_list ::= with_list NK_COMMA with_list_element. {} with_list ::= with_list NK_COMMA with_list_element. {}
...@@ -140,16 +162,16 @@ with_list_element ::= NK_ID AS table_subquery. {} ...@@ -140,16 +162,16 @@ with_list_element ::= NK_ID AS table_subquery. {}
table_subquery ::= . {} table_subquery ::= . {}
query_expression_body(A) ::= query_primary(B). { A = B; } query_expression_body(A) ::= query_primary(B). { PARSER_TRACE; A = B; }
query_expression_body(A) ::= query_expression_body(B) UNION ALL query_expression_body(C). { A = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, B, C); } query_expression_body(A) ::= query_expression_body(B) UNION ALL query_expression_body(C). { PARSER_TRACE; A = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, B, C); }
query_primary(A) ::= query_specification(B). { A = B; } query_primary(A) ::= query_specification(B). { PARSER_TRACE; A = B; }
query_primary(A) ::= NK_LP query_expression_body(B) order_by_clause_opt limit_clause_opt slimit_clause_opt NK_RP. { A = B;} query_primary(A) ::= NK_LP query_expression_body(B) order_by_clause_opt limit_clause_opt slimit_clause_opt NK_RP. { PARSER_TRACE; A = B;}
%type order_by_clause_opt { SNodeList* } %type order_by_clause_opt { SNodeList* }
%destructor order_by_clause_opt { nodesDestroyNodeList($$); } %destructor order_by_clause_opt { nodesDestroyNodeList($$); }
order_by_clause_opt(A) ::= . { A = NULL; } order_by_clause_opt(A) ::= . { PARSER_TRACE; A = NULL; }
order_by_clause_opt(A) ::= ORDER BY sort_specification_list(B). { A = B; } order_by_clause_opt(A) ::= ORDER BY sort_specification_list(B). { PARSER_TRACE; A = B; }
limit_clause_opt ::= . limit_clause_opt ::= .
...@@ -158,19 +180,19 @@ slimit_clause_opt ::= . ...@@ -158,19 +180,19 @@ slimit_clause_opt ::= .
//////////////////////// sort_specification_list ///////////////////////////////// //////////////////////// sort_specification_list /////////////////////////////////
%type sort_specification_list { SNodeList* } %type sort_specification_list { SNodeList* }
%destructor sort_specification_list { nodesDestroyNodeList($$); } %destructor sort_specification_list { nodesDestroyNodeList($$); }
sort_specification_list(A) ::= sort_specification(B). { A = createNodeList(pCxt, B); } sort_specification_list(A) ::= sort_specification(B). { PARSER_TRACE; A = createNodeList(pCxt, B); }
sort_specification_list(A) ::= sort_specification_list(B) NK_COMMA sort_specification(C). { A = addNodeToList(pCxt, B, C); } sort_specification_list(A) ::= sort_specification_list(B) NK_COMMA sort_specification(C). { PARSER_TRACE; A = addNodeToList(pCxt, B, C); }
sort_specification(A) ::= value_expression(B) ordering_specification_opt(C) null_ordering_opt(D). { A = createOrderByExprNode(pCxt, B, C, D); } sort_specification(A) ::= value_expression(B) ordering_specification_opt(C) null_ordering_opt(D). { PARSER_TRACE; A = createOrderByExprNode(pCxt, B, C, D); }
%type ordering_specification_opt EOrder %type ordering_specification_opt EOrder
%destructor ordering_specification_opt {} %destructor ordering_specification_opt {}
ordering_specification_opt(A) ::= . { A = ORDER_ASC; } ordering_specification_opt(A) ::= . { PARSER_TRACE; A = ORDER_ASC; }
ordering_specification_opt(A) ::= ASC. { A = ORDER_ASC; } ordering_specification_opt(A) ::= ASC. { PARSER_TRACE; A = ORDER_ASC; }
ordering_specification_opt(A) ::= DESC. { A = ORDER_DESC; } ordering_specification_opt(A) ::= DESC. { PARSER_TRACE; A = ORDER_DESC; }
%type null_ordering_opt ENullOrder %type null_ordering_opt ENullOrder
%destructor null_ordering_opt {} %destructor null_ordering_opt {}
null_ordering_opt(A) ::= . { A = NULL_ORDER_DEFAULT; } null_ordering_opt(A) ::= . { PARSER_TRACE; A = NULL_ORDER_DEFAULT; }
null_ordering_opt(A) ::= NULLS FIRST. { A = NULL_ORDER_FIRST; } null_ordering_opt(A) ::= NULLS FIRST. { PARSER_TRACE; A = NULL_ORDER_FIRST; }
null_ordering_opt(A) ::= NULLS LAST. { A = NULL_ORDER_LAST; } null_ordering_opt(A) ::= NULLS LAST. { PARSER_TRACE; A = NULL_ORDER_LAST; }
...@@ -15,57 +15,162 @@ ...@@ -15,57 +15,162 @@
#include "ttoken.h" #include "ttoken.h"
#include "astCreateFuncs.h" #include "astCreateFuncs.h"
#include "astCreater.h"
typedef void* (*FMalloc)(size_t);
typedef void (*FFree)(void*);
extern void* NewParseAlloc(FMalloc); extern void* NewParseAlloc(FMalloc);
extern void NewParse(void*, int, SToken*, void*); extern void NewParse(void*, int, SToken, void*);
extern void NewParseFree(void*, FFree); extern void NewParseFree(void*, FFree);
SNodeList* addNodeToList(SAstCreaterContext* pCxt, SNodeList* pList, SNode* pNode) { static void* acquireRaii(SAstCreateContext* pCxt, void* p) {
if (NULL == p) {
return NULL;
}
return p;
}
static void* releaseRaii(SAstCreateContext* pCxt, void* p) {
if (NULL == p) {
return NULL;
}
return p;
} }
SNode* createColumnNode(SAstCreaterContext* pCxt, SToken* pDbName, SToken* pTableName, SToken* pColumnName) { int32_t createAstCreater(const SParseContext* pQueryCxt, SAstCreateContext* pCxt) {
} }
SNodeList* createNodeList(SAstCreaterContext* pCxt, SNode* pNode) { int32_t destroyAstCreater(SAstCreateContext* pCxt) {
} }
SNode* createOrderByExprNode(SAstCreaterContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder) { bool checkTableName(const SToken* pTableName) {
printf("%p : %d, %d, %s\n", pTableName, pTableName->type, pTableName->n, pTableName->z);
return pTableName->n < TSDB_TABLE_NAME_LEN ? true : false;
}
SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode) {
} }
SNode* createSelectStmt(SAstCreaterContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable) { SNode* createColumnNode(SAstCreateContext* pCxt, const SToken* pTableName, const SToken* pColumnName) {
} }
SNode* createSetOperator(SAstCreaterContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight) { SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode) {
} }
SNode* createShowStmt(SAstCreaterContext* pCxt, EShowStmtType type) { SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order, ENullOrder nullOrder) {
} }
SNode* setProjectionAlias(SAstCreaterContext* pCxt, SNode* pNode, SToken* pAlias) { SNode* createRealTableNode(SAstCreateContext* pCxt, const SToken* pDbName, const SToken* pTableName) {
SRealTableNode* realTable = (SRealTableNode*)nodesMakeNode(QUERY_NODE_REAL_TABLE);
if (NULL != pDbName) {
printf("DbName %p : %d, %d, %s\n", pDbName, pDbName->type, pDbName->n, pDbName->z);
strncpy(realTable->dbName, pDbName->z, pDbName->n);
}
printf("TableName %p : %d, %d, %s\n", pTableName, pTableName->type, pTableName->n, pTableName->z);
strncpy(realTable->table.tableName, pTableName->z, pTableName->n);
return acquireRaii(pCxt, realTable);
}
SNode* createSelectStmt(SAstCreateContext* pCxt, bool isDistinct, SNodeList* pProjectionList, SNode* pTable) {
SSelectStmt* select = (SSelectStmt*)nodesMakeNode(QUERY_NODE_SELECT_STMT);
select->isDistinct = isDistinct;
if (NULL == pProjectionList) {
select->isStar = true;
}
select->pProjectionList = releaseRaii(pCxt, pProjectionList);
printf("pTable = %p, name = %s\n", pTable, ((SRealTableNode*)pTable)->table.tableName);
select->pFromTable = releaseRaii(pCxt, pTable);
return acquireRaii(pCxt, select);
}
SNode* createSetOperator(SAstCreateContext* pCxt, ESetOperatorType type, SNode* pLeft, SNode* pRight) {
} }
SNode* doParse(SParseContext* pParseCxt) { SNode* createShowStmt(SAstCreateContext* pCxt, EShowStmtType type) {
SAstCreaterContext cxt = { .pQueryCxt = pParseCxt, .valid = true, .pRootNode = NULL, .mallocFunc = malloc, .freeFunc = free};
void *pParser = NewParseAlloc(cxt.mallocFunc); }
SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* pAlias) {
}
uint32_t toNewTokenId(uint32_t tokenId) {
switch (tokenId) {
case TK_UNION:
return NEW_TK_UNION;
case TK_ALL:
return NEW_TK_ALL;
case TK_MINUS:
return NEW_TK_NK_MINUS;
case TK_PLUS:
return NEW_TK_NK_PLUS;
case TK_STAR:
return NEW_TK_NK_STAR;
case TK_SLASH:
return NEW_TK_NK_SLASH;
case TK_SHOW:
return NEW_TK_SHOW;
case TK_DATABASES:
return NEW_TK_DATABASES;
case TK_ID:
return NEW_TK_NK_ID;
case TK_LP:
return NEW_TK_NK_LP;
case TK_RP:
return NEW_TK_NK_RP;
case TK_COMMA:
return NEW_TK_NK_COMMA;
case TK_DOT:
return NEW_TK_NK_DOT;
case TK_SELECT:
return NEW_TK_SELECT;
case TK_DISTINCT:
return NEW_TK_DISTINCT;
case TK_AS:
return NEW_TK_AS;
case TK_FROM:
return NEW_TK_FROM;
case TK_ORDER:
return NEW_TK_ORDER;
case TK_BY:
return NEW_TK_BY;
case TK_ASC:
return NEW_TK_ASC;
case TK_DESC:
return NEW_TK_DESC;
}
return tokenId;
}
uint32_t getToken(const char* z, uint32_t* tokenId) {
uint32_t n = tGetToken(z, tokenId);
*tokenId = toNewTokenId(*tokenId);
return n;
}
int32_t doParse(SParseContext* pParseCxt, SQuery* pQuery) {
SAstCreateContext cxt = { .pQueryCxt = pParseCxt, .valid = true, .pRootNode = NULL };
void *pParser = NewParseAlloc(malloc);
int32_t i = 0; int32_t i = 0;
while (1) { while (1) {
SToken t0 = {0}; SToken t0 = {0};
printf("===========================\n");
if (cxt.pQueryCxt->pSql[i] == 0) { if (cxt.pQueryCxt->pSql[i] == 0) {
NewParse(pParser, 0, &t0, &cxt); NewParse(pParser, 0, t0, &cxt);
goto abort_parse; goto abort_parse;
} }
printf("input: [%s]\n", cxt.pQueryCxt->pSql + i);
t0.n = tGetToken((char *)&cxt.pQueryCxt->pSql[i], &t0.type); t0.n = getToken((char *)&cxt.pQueryCxt->pSql[i], &t0.type);
t0.z = (char *)(cxt.pQueryCxt->pSql + i); t0.z = (char *)(cxt.pQueryCxt->pSql + i);
printf("token %p : %d %d [%s]\n", &t0, t0.type, t0.n, t0.z);
i += t0.n; i += t0.n;
switch (t0.type) { switch (t0.type) {
...@@ -74,13 +179,14 @@ SNode* doParse(SParseContext* pParseCxt) { ...@@ -74,13 +179,14 @@ SNode* doParse(SParseContext* pParseCxt) {
break; break;
} }
case TK_SEMI: { case TK_SEMI: {
NewParse(pParser, 0, &t0, &cxt); NewParse(pParser, 0, t0, &cxt);
goto abort_parse; goto abort_parse;
} }
case TK_QUESTION: case TK_QUESTION:
case TK_ILLEGAL: { case TK_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;
goto abort_parse; goto abort_parse;
} }
...@@ -88,11 +194,12 @@ SNode* doParse(SParseContext* pParseCxt) { ...@@ -88,11 +194,12 @@ SNode* doParse(SParseContext* pParseCxt) {
case TK_OCT: case TK_OCT:
case TK_BIN: { case TK_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;
goto abort_parse; goto abort_parse;
} }
default: default:
NewParse(pParser, t0.type, &t0, &cxt); NewParse(pParser, t0.type, t0, &cxt);
if (!cxt.valid) { if (!cxt.valid) {
goto abort_parse; goto abort_parse;
} }
...@@ -100,6 +207,7 @@ SNode* doParse(SParseContext* pParseCxt) { ...@@ -100,6 +207,7 @@ SNode* doParse(SParseContext* pParseCxt) {
} }
abort_parse: abort_parse:
NewParseFree(pParser, cxt.freeFunc); NewParseFree(pParser, free);
return cxt.pRootNode; pQuery->pRoot = cxt.pRootNode;
return cxt.valid ? TSDB_CODE_SUCCESS : TSDB_CODE_FAILED;
} }
...@@ -36,6 +36,8 @@ ...@@ -36,6 +36,8 @@
#include "ttoken.h" #include "ttoken.h"
#include "ttokendef.h" #include "ttokendef.h"
#include "astCreateFuncs.h" #include "astCreateFuncs.h"
#define PARSER_TRACE printf("rule = %s\n", yyRuleName[yyruleno])
/**************** End of %include directives **********************************/ /**************** End of %include directives **********************************/
/* These constants specify the various numeric values for terminal symbols /* These constants specify the various numeric values for terminal symbols
** in a format understandable to "makeheaders". This section is blank unless ** in a format understandable to "makeheaders". This section is blank unless
...@@ -99,25 +101,26 @@ ...@@ -99,25 +101,26 @@
#endif #endif
/************* Begin control #defines *****************************************/ /************* Begin control #defines *****************************************/
#define YYCODETYPE unsigned char #define YYCODETYPE unsigned char
#define YYNOCODE 63 #define YYNOCODE 70
#define YYACTIONTYPE unsigned char #define YYACTIONTYPE unsigned char
#define NewParseTOKENTYPE SToken* #define NewParseTOKENTYPE SToken
typedef union { typedef union {
int yyinit; int yyinit;
NewParseTOKENTYPE yy0; NewParseTOKENTYPE yy0;
bool yy47; SToken yy29;
SNode* yy56; EOrder yy78;
SNodeList* yy82; SNode* yy112;
EOrder yy92; bool yy117;
ENullOrder yy109; SNodeList* yy124;
ENullOrder yy137;
} YYMINORTYPE; } YYMINORTYPE;
#ifndef YYSTACKDEPTH #ifndef YYSTACKDEPTH
#define YYSTACKDEPTH 100 #define YYSTACKDEPTH 100
#endif #endif
#define NewParseARG_SDECL SAstCreaterContext* pCxt ; #define NewParseARG_SDECL SAstCreateContext* pCxt ;
#define NewParseARG_PDECL , SAstCreaterContext* pCxt #define NewParseARG_PDECL , SAstCreateContext* pCxt
#define NewParseARG_PARAM ,pCxt #define NewParseARG_PARAM ,pCxt
#define NewParseARG_FETCH SAstCreaterContext* pCxt =yypParser->pCxt ; #define NewParseARG_FETCH SAstCreateContext* pCxt =yypParser->pCxt ;
#define NewParseARG_STORE yypParser->pCxt =pCxt ; #define NewParseARG_STORE yypParser->pCxt =pCxt ;
#define NewParseCTX_SDECL #define NewParseCTX_SDECL
#define NewParseCTX_PDECL #define NewParseCTX_PDECL
...@@ -125,16 +128,16 @@ typedef union { ...@@ -125,16 +128,16 @@ typedef union {
#define NewParseCTX_FETCH #define NewParseCTX_FETCH
#define NewParseCTX_STORE #define NewParseCTX_STORE
#define YYNSTATE 62 #define YYNSTATE 62
#define YYNRULE 64 #define YYNRULE 70
#define YYNTOKEN 31 #define YYNTOKEN 32
#define YY_MAX_SHIFT 61 #define YY_MAX_SHIFT 61
#define YY_MIN_SHIFTREDUCE 105 #define YY_MIN_SHIFTREDUCE 112
#define YY_MAX_SHIFTREDUCE 168 #define YY_MAX_SHIFTREDUCE 181
#define YY_ERROR_ACTION 169 #define YY_ERROR_ACTION 182
#define YY_ACCEPT_ACTION 170 #define YY_ACCEPT_ACTION 183
#define YY_NO_ACTION 171 #define YY_NO_ACTION 184
#define YY_MIN_REDUCE 172 #define YY_MIN_REDUCE 185
#define YY_MAX_REDUCE 235 #define YY_MAX_REDUCE 254
/************* End control #defines *******************************************/ /************* End control #defines *******************************************/
#define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0]))) #define YY_NLOOKAHEAD ((int)(sizeof(yy_lookahead)/sizeof(yy_lookahead[0])))
...@@ -201,87 +204,91 @@ typedef union { ...@@ -201,87 +204,91 @@ typedef union {
** yy_default[] Default action for each state. ** yy_default[] Default action for each state.
** **
*********** Begin parsing tables **********************************************/ *********** Begin parsing tables **********************************************/
#define YY_ACTTAB_COUNT (213) #define YY_ACTTAB_COUNT (232)
static const YYACTIONTYPE yy_action[] = { static const YYACTIONTYPE yy_action[] = {
/* 0 */ 33, 50, 33, 33, 33, 33, 50, 33, 33, 44, /* 0 */ 34, 46, 34, 34, 34, 34, 54, 46, 34, 34,
/* 10 */ 193, 27, 43, 51, 183, 33, 20, 33, 33, 33, /* 10 */ 50, 212, 29, 49, 47, 195, 34, 22, 34, 34,
/* 20 */ 33, 20, 33, 33, 33, 20, 33, 33, 33, 33, /* 20 */ 34, 34, 56, 22, 34, 34, 34, 22, 34, 34,
/* 30 */ 20, 33, 33, 13, 12, 114, 42, 193, 61, 41, /* 30 */ 34, 34, 56, 22, 34, 34, 34, 46, 34, 34,
/* 40 */ 5, 45, 203, 151, 52, 52, 11, 10, 9, 8, /* 40 */ 34, 34, 54, 46, 34, 34, 14, 13, 41, 222,
/* 50 */ 17, 204, 33, 50, 33, 33, 33, 33, 50, 33, /* 50 */ 21, 196, 40, 5, 40, 5, 164, 26, 164, 223,
/* 60 */ 33, 140, 141, 43, 25, 227, 184, 227, 227, 227, /* 60 */ 34, 57, 34, 34, 34, 34, 56, 57, 34, 34,
/* 70 */ 227, 166, 227, 227, 18, 33, 54, 33, 33, 33, /* 70 */ 34, 58, 34, 34, 34, 34, 56, 58, 34, 34,
/* 80 */ 33, 54, 33, 33, 1, 33, 55, 33, 33, 33, /* 80 */ 34, 39, 34, 34, 34, 34, 56, 39, 34, 34,
/* 90 */ 33, 55, 33, 33, 33, 39, 33, 33, 33, 33, /* 90 */ 204, 12, 11, 10, 9, 7, 61, 48, 212, 207,
/* 100 */ 39, 33, 33, 226, 14, 226, 226, 226, 226, 23, /* 100 */ 200, 201, 202, 203, 53, 203, 203, 203, 246, 18,
/* 110 */ 226, 226, 37, 194, 37, 37, 37, 37, 121, 37, /* 110 */ 246, 246, 246, 246, 56, 218, 246, 246, 245, 52,
/* 120 */ 37, 38, 109, 38, 38, 38, 38, 120, 38, 38, /* 120 */ 245, 245, 245, 245, 56, 18, 245, 245, 15, 21,
/* 130 */ 223, 53, 223, 223, 223, 223, 30, 222, 223, 222, /* 130 */ 23, 218, 44, 25, 1, 37, 216, 37, 37, 37,
/* 140 */ 222, 222, 222, 170, 59, 222, 13, 12, 13, 12, /* 140 */ 37, 56, 51, 37, 37, 38, 217, 38, 38, 38,
/* 150 */ 32, 48, 40, 5, 41, 5, 151, 199, 151, 40, /* 150 */ 38, 56, 216, 38, 38, 242, 42, 242, 242, 242,
/* 160 */ 5, 113, 16, 151, 143, 144, 21, 199, 199, 9, /* 160 */ 242, 56, 214, 214, 242, 153, 154, 17, 218, 35,
/* 170 */ 8, 145, 6, 197, 46, 7, 198, 22, 112, 58, /* 170 */ 241, 119, 241, 241, 241, 241, 56, 183, 59, 241,
/* 180 */ 34, 7, 205, 197, 197, 36, 232, 19, 177, 195, /* 180 */ 14, 13, 120, 24, 213, 49, 40, 5, 118, 216,
/* 190 */ 47, 29, 24, 189, 31, 28, 3, 2, 133, 15, /* 190 */ 164, 156, 157, 31, 126, 10, 9, 19, 115, 33,
/* 200 */ 119, 4, 49, 173, 26, 147, 146, 35, 109, 172, /* 200 */ 134, 224, 205, 17, 158, 6, 8, 189, 43, 30,
/* 210 */ 56, 57, 60, /* 210 */ 3, 208, 32, 146, 16, 2, 125, 45, 4, 206,
/* 220 */ 27, 20, 178, 28, 36, 115, 55, 186, 160, 159,
/* 230 */ 185, 60,
}; };
static const YYCODETYPE yy_lookahead[] = { static const YYCODETYPE yy_lookahead[] = {
/* 0 */ 33, 34, 35, 36, 37, 38, 39, 40, 41, 55, /* 0 */ 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
/* 10 */ 56, 44, 12, 46, 47, 33, 34, 35, 36, 37, /* 10 */ 63, 64, 46, 12, 48, 49, 34, 35, 36, 37,
/* 20 */ 38, 39, 40, 41, 33, 34, 35, 36, 37, 38, /* 20 */ 38, 39, 40, 41, 42, 43, 34, 35, 36, 37,
/* 30 */ 39, 40, 41, 6, 7, 8, 55, 56, 10, 12, /* 30 */ 38, 39, 40, 41, 42, 43, 34, 35, 36, 37,
/* 40 */ 13, 59, 60, 16, 48, 49, 6, 7, 8, 9, /* 40 */ 38, 39, 40, 41, 42, 43, 6, 7, 66, 67,
/* 50 */ 22, 60, 33, 34, 35, 36, 37, 38, 39, 40, /* 50 */ 22, 49, 12, 13, 12, 13, 16, 68, 16, 67,
/* 60 */ 41, 26, 27, 12, 61, 33, 47, 35, 36, 37, /* 60 */ 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
/* 70 */ 38, 12, 40, 41, 23, 33, 34, 35, 36, 37, /* 70 */ 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
/* 80 */ 38, 39, 40, 41, 43, 33, 34, 35, 36, 37, /* 80 */ 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
/* 90 */ 38, 39, 40, 41, 33, 34, 35, 36, 37, 38, /* 90 */ 40, 6, 7, 8, 9, 13, 10, 63, 64, 17,
/* 100 */ 39, 40, 41, 33, 13, 35, 36, 37, 38, 18, /* 100 */ 50, 51, 52, 53, 54, 55, 56, 57, 34, 23,
/* 110 */ 40, 41, 33, 56, 35, 36, 37, 38, 8, 40, /* 110 */ 36, 37, 38, 39, 40, 44, 42, 43, 34, 12,
/* 120 */ 41, 33, 12, 35, 36, 37, 38, 8, 40, 41, /* 120 */ 36, 37, 38, 39, 40, 23, 42, 43, 13, 22,
/* 130 */ 33, 12, 35, 36, 37, 38, 52, 33, 41, 35, /* 130 */ 59, 44, 1, 18, 45, 34, 65, 36, 37, 38,
/* 140 */ 36, 37, 38, 31, 32, 41, 6, 7, 6, 7, /* 140 */ 39, 40, 33, 42, 43, 34, 59, 36, 37, 38,
/* 150 */ 52, 1, 12, 13, 12, 13, 16, 42, 16, 12, /* 150 */ 39, 40, 65, 42, 43, 34, 25, 36, 37, 38,
/* 160 */ 13, 2, 50, 16, 29, 30, 51, 42, 42, 8, /* 160 */ 39, 40, 56, 57, 43, 27, 28, 58, 44, 29,
/* 170 */ 9, 14, 15, 58, 24, 13, 51, 51, 19, 17, /* 170 */ 34, 2, 36, 37, 38, 39, 40, 32, 33, 43,
/* 180 */ 28, 13, 62, 58, 58, 17, 49, 21, 45, 57, /* 180 */ 6, 7, 8, 59, 64, 12, 12, 13, 19, 65,
/* 190 */ 54, 53, 15, 54, 53, 20, 15, 25, 14, 2, /* 190 */ 16, 30, 31, 60, 8, 8, 9, 24, 12, 60,
/* 200 */ 12, 15, 20, 0, 15, 14, 14, 17, 12, 0, /* 200 */ 12, 69, 40, 58, 14, 15, 21, 47, 62, 61,
/* 210 */ 17, 12, 11, 63, 63, 63, 63, 63, 63, 63, /* 210 */ 15, 62, 61, 14, 2, 26, 12, 20, 15, 17,
/* 220 */ 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, /* 220 */ 15, 20, 14, 17, 17, 12, 17, 0, 14, 14,
/* 230 */ 63, 63, 63, 63, 63, 63, 63, 63, 63, 63, /* 230 */ 0, 11, 70, 70, 70, 70, 70, 70, 70, 70,
/* 240 */ 63, 63, 63, 63, /* 240 */ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
/* 250 */ 70, 70, 70, 70, 70, 70, 70, 70, 70, 70,
/* 260 */ 70, 70, 70, 70,
}; };
#define YY_SHIFT_COUNT (61) #define YY_SHIFT_COUNT (61)
#define YY_SHIFT_MIN (0) #define YY_SHIFT_MIN (0)
#define YY_SHIFT_MAX (209) #define YY_SHIFT_MAX (230)
static const unsigned char yy_shift_ofst[] = { static const unsigned short int yy_shift_ofst[] = {
/* 0 */ 28, 27, 140, 140, 142, 140, 140, 140, 140, 140, /* 0 */ 86, 174, 40, 40, 40, 40, 40, 40, 107, 40,
/* 10 */ 140, 140, 147, 147, 91, 91, 91, 51, 0, 59, /* 10 */ 40, 40, 40, 42, 42, 115, 115, 115, 173, 1,
/* 20 */ 35, 150, 150, 159, 0, 152, 59, 166, 213, 213, /* 20 */ 28, 102, 138, 131, 131, 169, 140, 1, 188, 185,
/* 30 */ 213, 213, 213, 40, 135, 110, 119, 161, 161, 157, /* 30 */ 232, 232, 232, 232, 85, 161, 186, 187, 187, 190,
/* 40 */ 162, 168, 177, 175, 177, 181, 172, 184, 197, 188, /* 40 */ 82, 195, 189, 199, 212, 204, 197, 203, 205, 201,
/* 50 */ 182, 186, 189, 190, 191, 192, 196, 193, 199, 203, /* 50 */ 205, 208, 202, 206, 207, 213, 209, 214, 215, 227,
/* 60 */ 209, 201, /* 60 */ 230, 220,
}; };
#define YY_REDUCE_COUNT (32) #define YY_REDUCE_COUNT (33)
#define YY_REDUCE_MIN (-46) #define YY_REDUCE_MIN (-53)
#define YY_REDUCE_MAX (143) #define YY_REDUCE_MAX (162)
static const short yy_reduce_ofst[] = { static const short yy_reduce_ofst[] = {
/* 0 */ 112, -33, -18, -9, 19, 42, 52, 61, 32, 70, /* 0 */ 145, -34, -18, -8, 2, 26, 36, 46, 50, 74,
/* 10 */ 79, 88, 97, 104, 115, 125, 126, -46, -19, -4, /* 10 */ 84, 101, 111, 121, 136, 71, 87, 124, -53, 34,
/* 20 */ 3, 84, 98, 41, 57, 120, 137, 143, 132, 136, /* 20 */ 106, 109, -11, 133, 139, 89, 132, 120, 162, 160,
/* 30 */ 138, 139, 141, /* 30 */ 146, 148, 149, 151,
}; };
static const YYACTIONTYPE yy_default[] = { static const YYACTIONTYPE yy_default[] = {
/* 0 */ 190, 169, 169, 169, 169, 169, 169, 169, 169, 169, /* 0 */ 209, 182, 182, 182, 182, 182, 182, 182, 215, 182,
/* 10 */ 169, 169, 169, 169, 169, 169, 169, 169, 169, 169, /* 10 */ 182, 182, 182, 182, 182, 182, 182, 182, 182, 182,
/* 20 */ 206, 201, 201, 178, 169, 209, 169, 169, 196, 235, /* 20 */ 215, 209, 225, 220, 220, 190, 228, 182, 182, 182,
/* 30 */ 234, 235, 234, 220, 169, 169, 169, 225, 224, 169, /* 30 */ 254, 253, 254, 253, 239, 182, 182, 244, 243, 182,
/* 40 */ 174, 174, 192, 169, 191, 202, 169, 169, 169, 169, /* 40 */ 187, 221, 182, 182, 182, 182, 197, 194, 211, 182,
/* 50 */ 185, 182, 230, 175, 169, 169, 169, 175, 169, 169, /* 50 */ 210, 182, 207, 182, 182, 182, 182, 182, 182, 182,
/* 60 */ 169, 169, /* 60 */ 182, 182,
}; };
/********** End of lemon-generated parsing tables *****************************/ /********** End of lemon-generated parsing tables *****************************/
...@@ -410,47 +417,54 @@ static const char *const yyTokenName[] = { ...@@ -410,47 +417,54 @@ static const char *const yyTokenName[] = {
/* 19 */ "DISTINCT", /* 19 */ "DISTINCT",
/* 20 */ "AS", /* 20 */ "AS",
/* 21 */ "FROM", /* 21 */ "FROM",
/* 22 */ "WITH", /* 22 */ "NK_LR",
/* 23 */ "RECURSIVE", /* 23 */ "WITH",
/* 24 */ "ORDER", /* 24 */ "RECURSIVE",
/* 25 */ "BY", /* 25 */ "ORDER",
/* 26 */ "ASC", /* 26 */ "BY",
/* 27 */ "DESC", /* 27 */ "ASC",
/* 28 */ "NULLS", /* 28 */ "DESC",
/* 29 */ "FIRST", /* 29 */ "NULLS",
/* 30 */ "LAST", /* 30 */ "FIRST",
/* 31 */ "cmd", /* 31 */ "LAST",
/* 32 */ "query_expression", /* 32 */ "cmd",
/* 33 */ "value_function", /* 33 */ "query_expression",
/* 34 */ "value_expression", /* 34 */ "value_function",
/* 35 */ "value_expression_primary", /* 35 */ "value_expression",
/* 36 */ "nonparenthesized_value_expression_primary", /* 36 */ "value_expression_primary",
/* 37 */ "literal", /* 37 */ "nonparenthesized_value_expression_primary",
/* 38 */ "column_reference", /* 38 */ "literal",
/* 39 */ "common_value_expression", /* 39 */ "column_reference",
/* 40 */ "numeric_value_expression", /* 40 */ "table_name",
/* 41 */ "numeric_primary", /* 41 */ "common_value_expression",
/* 42 */ "query_specification", /* 42 */ "numeric_value_expression",
/* 43 */ "set_quantifier_opt", /* 43 */ "numeric_primary",
/* 44 */ "select_list", /* 44 */ "query_specification",
/* 45 */ "from_clause", /* 45 */ "set_quantifier_opt",
/* 46 */ "select_sublist", /* 46 */ "select_list",
/* 47 */ "select_item", /* 47 */ "from_clause",
/* 48 */ "table_reference_list", /* 48 */ "select_sublist",
/* 49 */ "table_reference", /* 49 */ "select_item",
/* 50 */ "with_clause_opt", /* 50 */ "table_reference_list",
/* 51 */ "query_expression_body", /* 51 */ "table_reference",
/* 52 */ "order_by_clause_opt", /* 52 */ "table_factor",
/* 53 */ "limit_clause_opt", /* 53 */ "table_primary",
/* 54 */ "slimit_clause_opt", /* 54 */ "db_name",
/* 55 */ "with_list", /* 55 */ "derived_table",
/* 56 */ "with_list_element", /* 56 */ "table_subquery",
/* 57 */ "table_subquery", /* 57 */ "subquery",
/* 58 */ "query_primary", /* 58 */ "with_clause_opt",
/* 59 */ "sort_specification_list", /* 59 */ "query_expression_body",
/* 60 */ "sort_specification", /* 60 */ "order_by_clause_opt",
/* 61 */ "ordering_specification_opt", /* 61 */ "limit_clause_opt",
/* 62 */ "null_ordering_opt", /* 62 */ "slimit_clause_opt",
/* 63 */ "with_list",
/* 64 */ "with_list_element",
/* 65 */ "query_primary",
/* 66 */ "sort_specification_list",
/* 67 */ "sort_specification",
/* 68 */ "ordering_specification_opt",
/* 69 */ "null_ordering_opt",
}; };
#endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */ #endif /* defined(YYCOVERAGE) || !defined(NDEBUG) */
...@@ -461,67 +475,73 @@ static const char *const yyRuleName[] = { ...@@ -461,67 +475,73 @@ static const char *const yyRuleName[] = {
/* 0 */ "cmd ::= SHOW DATABASES", /* 0 */ "cmd ::= SHOW DATABASES",
/* 1 */ "cmd ::= query_expression", /* 1 */ "cmd ::= query_expression",
/* 2 */ "column_reference ::= NK_ID", /* 2 */ "column_reference ::= NK_ID",
/* 3 */ "column_reference ::= NK_ID NK_DOT NK_ID", /* 3 */ "column_reference ::= table_name NK_DOT NK_ID",
/* 4 */ "column_reference ::= NK_ID NK_DOT NK_ID NK_DOT NK_ID", /* 4 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause",
/* 5 */ "query_specification ::= SELECT set_quantifier_opt select_list from_clause", /* 5 */ "set_quantifier_opt ::=",
/* 6 */ "set_quantifier_opt ::=", /* 6 */ "set_quantifier_opt ::= DISTINCT",
/* 7 */ "set_quantifier_opt ::= DISTINCT", /* 7 */ "set_quantifier_opt ::= ALL",
/* 8 */ "set_quantifier_opt ::= ALL", /* 8 */ "select_list ::= NK_STAR",
/* 9 */ "select_list ::= NK_STAR", /* 9 */ "select_list ::= select_sublist",
/* 10 */ "select_list ::= select_sublist", /* 10 */ "select_sublist ::= select_item",
/* 11 */ "select_sublist ::= select_item", /* 11 */ "select_sublist ::= select_sublist NK_COMMA select_item",
/* 12 */ "select_sublist ::= select_sublist NK_COMMA select_item", /* 12 */ "select_item ::= value_expression",
/* 13 */ "select_item ::= value_expression", /* 13 */ "select_item ::= value_expression AS NK_ID",
/* 14 */ "select_item ::= value_expression AS NK_ID", /* 14 */ "select_item ::= table_name NK_DOT NK_STAR",
/* 15 */ "select_item ::= NK_ID NK_DOT NK_STAR", /* 15 */ "from_clause ::= FROM table_reference_list",
/* 16 */ "select_item ::= NK_ID NK_DOT NK_ID NK_DOT NK_STAR", /* 16 */ "table_reference_list ::= table_reference",
/* 17 */ "query_expression ::= with_clause_opt query_expression_body order_by_clause_opt limit_clause_opt slimit_clause_opt", /* 17 */ "table_reference ::= table_factor",
/* 18 */ "with_clause_opt ::=", /* 18 */ "table_factor ::= table_primary",
/* 19 */ "with_clause_opt ::= WITH with_list", /* 19 */ "table_primary ::= table_name",
/* 20 */ "with_clause_opt ::= WITH RECURSIVE with_list", /* 20 */ "table_primary ::= db_name NK_DOT table_name",
/* 21 */ "with_list ::= with_list_element", /* 21 */ "db_name ::= NK_ID",
/* 22 */ "with_list ::= with_list NK_COMMA with_list_element", /* 22 */ "table_name ::= NK_ID",
/* 23 */ "with_list_element ::= NK_ID AS table_subquery", /* 23 */ "query_expression ::= with_clause_opt query_expression_body order_by_clause_opt limit_clause_opt slimit_clause_opt",
/* 24 */ "table_subquery ::=", /* 24 */ "with_clause_opt ::=",
/* 25 */ "query_expression_body ::= query_primary", /* 25 */ "with_clause_opt ::= WITH with_list",
/* 26 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body", /* 26 */ "with_clause_opt ::= WITH RECURSIVE with_list",
/* 27 */ "query_primary ::= query_specification", /* 27 */ "with_list ::= with_list_element",
/* 28 */ "query_primary ::= NK_LP query_expression_body order_by_clause_opt limit_clause_opt slimit_clause_opt NK_RP", /* 28 */ "with_list ::= with_list NK_COMMA with_list_element",
/* 29 */ "order_by_clause_opt ::=", /* 29 */ "with_list_element ::= NK_ID AS table_subquery",
/* 30 */ "order_by_clause_opt ::= ORDER BY sort_specification_list", /* 30 */ "table_subquery ::=",
/* 31 */ "sort_specification_list ::= sort_specification", /* 31 */ "query_expression_body ::= query_primary",
/* 32 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification", /* 32 */ "query_expression_body ::= query_expression_body UNION ALL query_expression_body",
/* 33 */ "sort_specification ::= value_expression ordering_specification_opt null_ordering_opt", /* 33 */ "query_primary ::= query_specification",
/* 34 */ "ordering_specification_opt ::=", /* 34 */ "query_primary ::= NK_LP query_expression_body order_by_clause_opt limit_clause_opt slimit_clause_opt NK_RP",
/* 35 */ "ordering_specification_opt ::= ASC", /* 35 */ "order_by_clause_opt ::=",
/* 36 */ "ordering_specification_opt ::= DESC", /* 36 */ "order_by_clause_opt ::= ORDER BY sort_specification_list",
/* 37 */ "null_ordering_opt ::=", /* 37 */ "sort_specification_list ::= sort_specification",
/* 38 */ "null_ordering_opt ::= NULLS FIRST", /* 38 */ "sort_specification_list ::= sort_specification_list NK_COMMA sort_specification",
/* 39 */ "null_ordering_opt ::= NULLS LAST", /* 39 */ "sort_specification ::= value_expression ordering_specification_opt null_ordering_opt",
/* 40 */ "value_function ::= NK_ID NK_LP value_expression NK_RP", /* 40 */ "ordering_specification_opt ::=",
/* 41 */ "value_function ::= NK_ID NK_LP value_expression NK_COMMA value_expression NK_RP", /* 41 */ "ordering_specification_opt ::= ASC",
/* 42 */ "value_expression_primary ::= NK_LP value_expression NK_RP", /* 42 */ "ordering_specification_opt ::= DESC",
/* 43 */ "value_expression_primary ::= nonparenthesized_value_expression_primary", /* 43 */ "null_ordering_opt ::=",
/* 44 */ "nonparenthesized_value_expression_primary ::= literal", /* 44 */ "null_ordering_opt ::= NULLS FIRST",
/* 45 */ "nonparenthesized_value_expression_primary ::= column_reference", /* 45 */ "null_ordering_opt ::= NULLS LAST",
/* 46 */ "literal ::= NK_LITERAL", /* 46 */ "value_function ::= NK_ID NK_LP value_expression NK_RP",
/* 47 */ "value_expression ::= common_value_expression", /* 47 */ "value_function ::= NK_ID NK_LP value_expression NK_COMMA value_expression NK_RP",
/* 48 */ "common_value_expression ::= numeric_value_expression", /* 48 */ "value_expression_primary ::= NK_LP value_expression NK_RP",
/* 49 */ "numeric_value_expression ::= numeric_primary", /* 49 */ "value_expression_primary ::= nonparenthesized_value_expression_primary",
/* 50 */ "numeric_value_expression ::= NK_PLUS numeric_primary", /* 50 */ "nonparenthesized_value_expression_primary ::= literal",
/* 51 */ "numeric_value_expression ::= NK_MINUS numeric_primary", /* 51 */ "nonparenthesized_value_expression_primary ::= column_reference",
/* 52 */ "numeric_value_expression ::= numeric_value_expression NK_PLUS numeric_value_expression", /* 52 */ "literal ::= NK_LITERAL",
/* 53 */ "numeric_value_expression ::= numeric_value_expression NK_MINUS numeric_value_expression", /* 53 */ "value_expression ::= common_value_expression",
/* 54 */ "numeric_value_expression ::= numeric_value_expression NK_STAR numeric_value_expression", /* 54 */ "common_value_expression ::= numeric_value_expression",
/* 55 */ "numeric_value_expression ::= numeric_value_expression NK_SLASH numeric_value_expression", /* 55 */ "numeric_value_expression ::= numeric_primary",
/* 56 */ "numeric_primary ::= value_expression_primary", /* 56 */ "numeric_value_expression ::= NK_PLUS numeric_primary",
/* 57 */ "numeric_primary ::= value_function", /* 57 */ "numeric_value_expression ::= NK_MINUS numeric_primary",
/* 58 */ "from_clause ::= FROM table_reference_list", /* 58 */ "numeric_value_expression ::= numeric_value_expression NK_PLUS numeric_value_expression",
/* 59 */ "table_reference_list ::= table_reference", /* 59 */ "numeric_value_expression ::= numeric_value_expression NK_MINUS numeric_value_expression",
/* 60 */ "table_reference_list ::= table_reference_list NK_COMMA table_reference", /* 60 */ "numeric_value_expression ::= numeric_value_expression NK_STAR numeric_value_expression",
/* 61 */ "table_reference ::= NK_ID", /* 61 */ "numeric_value_expression ::= numeric_value_expression NK_SLASH numeric_value_expression",
/* 62 */ "limit_clause_opt ::=", /* 62 */ "numeric_primary ::= value_expression_primary",
/* 63 */ "slimit_clause_opt ::=", /* 63 */ "numeric_primary ::= value_function",
/* 64 */ "table_primary ::= derived_table",
/* 65 */ "derived_table ::= table_subquery",
/* 66 */ "subquery ::= NK_LR query_expression NK_RP",
/* 67 */ "table_subquery ::= subquery",
/* 68 */ "limit_clause_opt ::=",
/* 69 */ "slimit_clause_opt ::=",
}; };
#endif /* NDEBUG */ #endif /* NDEBUG */
...@@ -648,54 +668,60 @@ static void yy_destructor( ...@@ -648,54 +668,60 @@ static void yy_destructor(
*/ */
/********* Begin destructor definitions ***************************************/ /********* Begin destructor definitions ***************************************/
/* Default NON-TERMINAL Destructor */ /* Default NON-TERMINAL Destructor */
case 31: /* cmd */ case 32: /* cmd */
case 32: /* query_expression */ case 33: /* query_expression */
case 33: /* value_function */ case 34: /* value_function */
case 34: /* value_expression */ case 35: /* value_expression */
case 35: /* value_expression_primary */ case 36: /* value_expression_primary */
case 36: /* nonparenthesized_value_expression_primary */ case 37: /* nonparenthesized_value_expression_primary */
case 37: /* literal */ case 38: /* literal */
case 38: /* column_reference */ case 39: /* column_reference */
case 39: /* common_value_expression */ case 40: /* table_name */
case 40: /* numeric_value_expression */ case 41: /* common_value_expression */
case 41: /* numeric_primary */ case 42: /* numeric_value_expression */
case 42: /* query_specification */ case 43: /* numeric_primary */
case 45: /* from_clause */ case 44: /* query_specification */
case 47: /* select_item */ case 47: /* from_clause */
case 48: /* table_reference_list */ case 49: /* select_item */
case 49: /* table_reference */ case 50: /* table_reference_list */
case 50: /* with_clause_opt */ case 51: /* table_reference */
case 51: /* query_expression_body */ case 52: /* table_factor */
case 53: /* limit_clause_opt */ case 53: /* table_primary */
case 54: /* slimit_clause_opt */ case 54: /* db_name */
case 55: /* with_list */ case 55: /* derived_table */
case 56: /* with_list_element */ case 56: /* table_subquery */
case 57: /* table_subquery */ case 57: /* subquery */
case 58: /* query_primary */ case 58: /* with_clause_opt */
case 60: /* sort_specification */ case 59: /* query_expression_body */
case 61: /* limit_clause_opt */
case 62: /* slimit_clause_opt */
case 63: /* with_list */
case 64: /* with_list_element */
case 65: /* query_primary */
case 67: /* sort_specification */
{ {
nodesDestroyNode((yypminor->yy56)); nodesDestroyNode((yypminor->yy112));
} }
break; break;
case 43: /* set_quantifier_opt */ case 45: /* set_quantifier_opt */
{ {
} }
break; break;
case 44: /* select_list */ case 46: /* select_list */
case 46: /* select_sublist */ case 48: /* select_sublist */
case 52: /* order_by_clause_opt */ case 60: /* order_by_clause_opt */
case 59: /* sort_specification_list */ case 66: /* sort_specification_list */
{ {
nodesDestroyNodeList((yypminor->yy82)); nodesDestroyNodeList((yypminor->yy124));
} }
break; break;
case 61: /* ordering_specification_opt */ case 68: /* ordering_specification_opt */
{ {
} }
break; break;
case 62: /* null_ordering_opt */ case 69: /* null_ordering_opt */
{ {
} }
...@@ -994,70 +1020,76 @@ static const struct { ...@@ -994,70 +1020,76 @@ static const struct {
YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */ YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
signed char nrhs; /* Negative of the number of RHS symbols in the rule */ signed char nrhs; /* Negative of the number of RHS symbols in the rule */
} yyRuleInfo[] = { } yyRuleInfo[] = {
{ 31, -2 }, /* (0) cmd ::= SHOW DATABASES */ { 32, -2 }, /* (0) cmd ::= SHOW DATABASES */
{ 31, -1 }, /* (1) cmd ::= query_expression */ { 32, -1 }, /* (1) cmd ::= query_expression */
{ 38, -1 }, /* (2) column_reference ::= NK_ID */ { 39, -1 }, /* (2) column_reference ::= NK_ID */
{ 38, -3 }, /* (3) column_reference ::= NK_ID NK_DOT NK_ID */ { 39, -3 }, /* (3) column_reference ::= table_name NK_DOT NK_ID */
{ 38, -5 }, /* (4) column_reference ::= NK_ID NK_DOT NK_ID NK_DOT NK_ID */ { 44, -4 }, /* (4) query_specification ::= SELECT set_quantifier_opt select_list from_clause */
{ 42, -4 }, /* (5) query_specification ::= SELECT set_quantifier_opt select_list from_clause */ { 45, 0 }, /* (5) set_quantifier_opt ::= */
{ 43, 0 }, /* (6) set_quantifier_opt ::= */ { 45, -1 }, /* (6) set_quantifier_opt ::= DISTINCT */
{ 43, -1 }, /* (7) set_quantifier_opt ::= DISTINCT */ { 45, -1 }, /* (7) set_quantifier_opt ::= ALL */
{ 43, -1 }, /* (8) set_quantifier_opt ::= ALL */ { 46, -1 }, /* (8) select_list ::= NK_STAR */
{ 44, -1 }, /* (9) select_list ::= NK_STAR */ { 46, -1 }, /* (9) select_list ::= select_sublist */
{ 44, -1 }, /* (10) select_list ::= select_sublist */ { 48, -1 }, /* (10) select_sublist ::= select_item */
{ 46, -1 }, /* (11) select_sublist ::= select_item */ { 48, -3 }, /* (11) select_sublist ::= select_sublist NK_COMMA select_item */
{ 46, -3 }, /* (12) select_sublist ::= select_sublist NK_COMMA select_item */ { 49, -1 }, /* (12) select_item ::= value_expression */
{ 47, -1 }, /* (13) select_item ::= value_expression */ { 49, -3 }, /* (13) select_item ::= value_expression AS NK_ID */
{ 47, -3 }, /* (14) select_item ::= value_expression AS NK_ID */ { 49, -3 }, /* (14) select_item ::= table_name NK_DOT NK_STAR */
{ 47, -3 }, /* (15) select_item ::= NK_ID NK_DOT NK_STAR */ { 47, -2 }, /* (15) from_clause ::= FROM table_reference_list */
{ 47, -5 }, /* (16) select_item ::= NK_ID NK_DOT NK_ID NK_DOT NK_STAR */ { 50, -1 }, /* (16) table_reference_list ::= table_reference */
{ 32, -5 }, /* (17) query_expression ::= with_clause_opt query_expression_body order_by_clause_opt limit_clause_opt slimit_clause_opt */ { 51, -1 }, /* (17) table_reference ::= table_factor */
{ 50, 0 }, /* (18) with_clause_opt ::= */ { 52, -1 }, /* (18) table_factor ::= table_primary */
{ 50, -2 }, /* (19) with_clause_opt ::= WITH with_list */ { 53, -1 }, /* (19) table_primary ::= table_name */
{ 50, -3 }, /* (20) with_clause_opt ::= WITH RECURSIVE with_list */ { 53, -3 }, /* (20) table_primary ::= db_name NK_DOT table_name */
{ 55, -1 }, /* (21) with_list ::= with_list_element */ { 54, -1 }, /* (21) db_name ::= NK_ID */
{ 55, -3 }, /* (22) with_list ::= with_list NK_COMMA with_list_element */ { 40, -1 }, /* (22) table_name ::= NK_ID */
{ 56, -3 }, /* (23) with_list_element ::= NK_ID AS table_subquery */ { 33, -5 }, /* (23) query_expression ::= with_clause_opt query_expression_body order_by_clause_opt limit_clause_opt slimit_clause_opt */
{ 57, 0 }, /* (24) table_subquery ::= */ { 58, 0 }, /* (24) with_clause_opt ::= */
{ 51, -1 }, /* (25) query_expression_body ::= query_primary */ { 58, -2 }, /* (25) with_clause_opt ::= WITH with_list */
{ 51, -4 }, /* (26) query_expression_body ::= query_expression_body UNION ALL query_expression_body */ { 58, -3 }, /* (26) with_clause_opt ::= WITH RECURSIVE with_list */
{ 58, -1 }, /* (27) query_primary ::= query_specification */ { 63, -1 }, /* (27) with_list ::= with_list_element */
{ 58, -6 }, /* (28) query_primary ::= NK_LP query_expression_body order_by_clause_opt limit_clause_opt slimit_clause_opt NK_RP */ { 63, -3 }, /* (28) with_list ::= with_list NK_COMMA with_list_element */
{ 52, 0 }, /* (29) order_by_clause_opt ::= */ { 64, -3 }, /* (29) with_list_element ::= NK_ID AS table_subquery */
{ 52, -3 }, /* (30) order_by_clause_opt ::= ORDER BY sort_specification_list */ { 56, 0 }, /* (30) table_subquery ::= */
{ 59, -1 }, /* (31) sort_specification_list ::= sort_specification */ { 59, -1 }, /* (31) query_expression_body ::= query_primary */
{ 59, -3 }, /* (32) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ { 59, -4 }, /* (32) query_expression_body ::= query_expression_body UNION ALL query_expression_body */
{ 60, -3 }, /* (33) sort_specification ::= value_expression ordering_specification_opt null_ordering_opt */ { 65, -1 }, /* (33) query_primary ::= query_specification */
{ 61, 0 }, /* (34) ordering_specification_opt ::= */ { 65, -6 }, /* (34) query_primary ::= NK_LP query_expression_body order_by_clause_opt limit_clause_opt slimit_clause_opt NK_RP */
{ 61, -1 }, /* (35) ordering_specification_opt ::= ASC */ { 60, 0 }, /* (35) order_by_clause_opt ::= */
{ 61, -1 }, /* (36) ordering_specification_opt ::= DESC */ { 60, -3 }, /* (36) order_by_clause_opt ::= ORDER BY sort_specification_list */
{ 62, 0 }, /* (37) null_ordering_opt ::= */ { 66, -1 }, /* (37) sort_specification_list ::= sort_specification */
{ 62, -2 }, /* (38) null_ordering_opt ::= NULLS FIRST */ { 66, -3 }, /* (38) sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */
{ 62, -2 }, /* (39) null_ordering_opt ::= NULLS LAST */ { 67, -3 }, /* (39) sort_specification ::= value_expression ordering_specification_opt null_ordering_opt */
{ 33, -4 }, /* (40) value_function ::= NK_ID NK_LP value_expression NK_RP */ { 68, 0 }, /* (40) ordering_specification_opt ::= */
{ 33, -6 }, /* (41) value_function ::= NK_ID NK_LP value_expression NK_COMMA value_expression NK_RP */ { 68, -1 }, /* (41) ordering_specification_opt ::= ASC */
{ 35, -3 }, /* (42) value_expression_primary ::= NK_LP value_expression NK_RP */ { 68, -1 }, /* (42) ordering_specification_opt ::= DESC */
{ 35, -1 }, /* (43) value_expression_primary ::= nonparenthesized_value_expression_primary */ { 69, 0 }, /* (43) null_ordering_opt ::= */
{ 36, -1 }, /* (44) nonparenthesized_value_expression_primary ::= literal */ { 69, -2 }, /* (44) null_ordering_opt ::= NULLS FIRST */
{ 36, -1 }, /* (45) nonparenthesized_value_expression_primary ::= column_reference */ { 69, -2 }, /* (45) null_ordering_opt ::= NULLS LAST */
{ 37, -1 }, /* (46) literal ::= NK_LITERAL */ { 34, -4 }, /* (46) value_function ::= NK_ID NK_LP value_expression NK_RP */
{ 34, -1 }, /* (47) value_expression ::= common_value_expression */ { 34, -6 }, /* (47) value_function ::= NK_ID NK_LP value_expression NK_COMMA value_expression NK_RP */
{ 39, -1 }, /* (48) common_value_expression ::= numeric_value_expression */ { 36, -3 }, /* (48) value_expression_primary ::= NK_LP value_expression NK_RP */
{ 40, -1 }, /* (49) numeric_value_expression ::= numeric_primary */ { 36, -1 }, /* (49) value_expression_primary ::= nonparenthesized_value_expression_primary */
{ 40, -2 }, /* (50) numeric_value_expression ::= NK_PLUS numeric_primary */ { 37, -1 }, /* (50) nonparenthesized_value_expression_primary ::= literal */
{ 40, -2 }, /* (51) numeric_value_expression ::= NK_MINUS numeric_primary */ { 37, -1 }, /* (51) nonparenthesized_value_expression_primary ::= column_reference */
{ 40, -3 }, /* (52) numeric_value_expression ::= numeric_value_expression NK_PLUS numeric_value_expression */ { 38, -1 }, /* (52) literal ::= NK_LITERAL */
{ 40, -3 }, /* (53) numeric_value_expression ::= numeric_value_expression NK_MINUS numeric_value_expression */ { 35, -1 }, /* (53) value_expression ::= common_value_expression */
{ 40, -3 }, /* (54) numeric_value_expression ::= numeric_value_expression NK_STAR numeric_value_expression */ { 41, -1 }, /* (54) common_value_expression ::= numeric_value_expression */
{ 40, -3 }, /* (55) numeric_value_expression ::= numeric_value_expression NK_SLASH numeric_value_expression */ { 42, -1 }, /* (55) numeric_value_expression ::= numeric_primary */
{ 41, -1 }, /* (56) numeric_primary ::= value_expression_primary */ { 42, -2 }, /* (56) numeric_value_expression ::= NK_PLUS numeric_primary */
{ 41, -1 }, /* (57) numeric_primary ::= value_function */ { 42, -2 }, /* (57) numeric_value_expression ::= NK_MINUS numeric_primary */
{ 45, -2 }, /* (58) from_clause ::= FROM table_reference_list */ { 42, -3 }, /* (58) numeric_value_expression ::= numeric_value_expression NK_PLUS numeric_value_expression */
{ 48, -1 }, /* (59) table_reference_list ::= table_reference */ { 42, -3 }, /* (59) numeric_value_expression ::= numeric_value_expression NK_MINUS numeric_value_expression */
{ 48, -3 }, /* (60) table_reference_list ::= table_reference_list NK_COMMA table_reference */ { 42, -3 }, /* (60) numeric_value_expression ::= numeric_value_expression NK_STAR numeric_value_expression */
{ 49, -1 }, /* (61) table_reference ::= NK_ID */ { 42, -3 }, /* (61) numeric_value_expression ::= numeric_value_expression NK_SLASH numeric_value_expression */
{ 53, 0 }, /* (62) limit_clause_opt ::= */ { 43, -1 }, /* (62) numeric_primary ::= value_expression_primary */
{ 54, 0 }, /* (63) slimit_clause_opt ::= */ { 43, -1 }, /* (63) numeric_primary ::= value_function */
{ 53, -1 }, /* (64) table_primary ::= derived_table */
{ 55, -1 }, /* (65) derived_table ::= table_subquery */
{ 57, -3 }, /* (66) subquery ::= NK_LR query_expression NK_RP */
{ 56, -1 }, /* (67) table_subquery ::= subquery */
{ 61, 0 }, /* (68) limit_clause_opt ::= */
{ 62, 0 }, /* (69) slimit_clause_opt ::= */
}; };
static void yy_accept(yyParser*); /* Forward Declaration */ static void yy_accept(yyParser*); /* Forward Declaration */
...@@ -1145,233 +1177,251 @@ static YYACTIONTYPE yy_reduce( ...@@ -1145,233 +1177,251 @@ static YYACTIONTYPE yy_reduce(
/********** Begin reduce actions **********************************************/ /********** Begin reduce actions **********************************************/
YYMINORTYPE yylhsminor; YYMINORTYPE yylhsminor;
case 0: /* cmd ::= SHOW DATABASES */ case 0: /* cmd ::= SHOW DATABASES */
{ createShowStmt(pCxt, SHOW_TYPE_DATABASE); } { PARSER_TRACE; createShowStmt(pCxt, SHOW_TYPE_DATABASE); }
break; break;
case 1: /* cmd ::= query_expression */ case 1: /* cmd ::= query_expression */
{ pCxt->pRootNode = yymsp[0].minor.yy56; } { PARSER_TRACE; pCxt->pRootNode = yymsp[0].minor.yy112; }
break; break;
case 2: /* column_reference ::= NK_ID */ case 2: /* column_reference ::= NK_ID */
{ yylhsminor.yy56 = createColumnNode(pCxt, NULL, NULL, yymsp[0].minor.yy0); } { PARSER_TRACE; yylhsminor.yy112 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy0); }
yymsp[0].minor.yy56 = yylhsminor.yy56; yymsp[0].minor.yy112 = yylhsminor.yy112;
break;
case 3: /* column_reference ::= table_name NK_DOT NK_ID */
case 14: /* select_item ::= table_name NK_DOT NK_STAR */ yytestcase(yyruleno==14);
{ PARSER_TRACE; yylhsminor.yy112 = createColumnNode(pCxt, &yymsp[-2].minor.yy29, &yymsp[0].minor.yy0); }
yymsp[-2].minor.yy112 = yylhsminor.yy112;
break;
case 4: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause */
{ PARSER_TRACE; yymsp[-3].minor.yy112 = createSelectStmt(pCxt, yymsp[-2].minor.yy117, yymsp[-1].minor.yy124, yymsp[0].minor.yy112); }
break; break;
case 3: /* column_reference ::= NK_ID NK_DOT NK_ID */ case 5: /* set_quantifier_opt ::= */
case 15: /* select_item ::= NK_ID NK_DOT NK_STAR */ yytestcase(yyruleno==15); { PARSER_TRACE; yymsp[1].minor.yy117 = false; }
{ yylhsminor.yy56 = createColumnNode(pCxt, NULL, yymsp[-2].minor.yy0, yymsp[0].minor.yy0); }
yymsp[-2].minor.yy56 = yylhsminor.yy56;
break; break;
case 4: /* column_reference ::= NK_ID NK_DOT NK_ID NK_DOT NK_ID */ case 6: /* set_quantifier_opt ::= DISTINCT */
case 16: /* select_item ::= NK_ID NK_DOT NK_ID NK_DOT NK_STAR */ yytestcase(yyruleno==16); { PARSER_TRACE; yymsp[0].minor.yy117 = true; }
{ yylhsminor.yy56 = createColumnNode(pCxt, yymsp[-4].minor.yy0, yymsp[-2].minor.yy0, yymsp[0].minor.yy0); }
yymsp[-4].minor.yy56 = yylhsminor.yy56;
break; break;
case 5: /* query_specification ::= SELECT set_quantifier_opt select_list from_clause */ case 7: /* set_quantifier_opt ::= ALL */
{ yymsp[-3].minor.yy56 = createSelectStmt(pCxt, yymsp[-2].minor.yy47, yymsp[-1].minor.yy82, yymsp[0].minor.yy56); } { PARSER_TRACE; yymsp[0].minor.yy117 = false; }
break; break;
case 6: /* set_quantifier_opt ::= */ case 8: /* select_list ::= NK_STAR */
{ yymsp[1].minor.yy47 = false; } { PARSER_TRACE; yymsp[0].minor.yy124 = NULL; }
break; break;
case 7: /* set_quantifier_opt ::= DISTINCT */ case 9: /* select_list ::= select_sublist */
{ yymsp[0].minor.yy47 = true; } { PARSER_TRACE; yylhsminor.yy124 = yymsp[0].minor.yy124; }
yymsp[0].minor.yy124 = yylhsminor.yy124;
break; break;
case 8: /* set_quantifier_opt ::= ALL */ case 10: /* select_sublist ::= select_item */
{ yymsp[0].minor.yy47 = false; } case 37: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==37);
{ PARSER_TRACE; yylhsminor.yy124 = createNodeList(pCxt, yymsp[0].minor.yy112); }
yymsp[0].minor.yy124 = yylhsminor.yy124;
break; break;
case 9: /* select_list ::= NK_STAR */ case 11: /* select_sublist ::= select_sublist NK_COMMA select_item */
{ yymsp[0].minor.yy82 = NULL; } case 38: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==38);
{ PARSER_TRACE; yylhsminor.yy124 = addNodeToList(pCxt, yymsp[-2].minor.yy124, yymsp[0].minor.yy112); }
yymsp[-2].minor.yy124 = yylhsminor.yy124;
break; break;
case 10: /* select_list ::= select_sublist */ case 12: /* select_item ::= value_expression */
{ yylhsminor.yy82 = yymsp[0].minor.yy82; } case 16: /* table_reference_list ::= table_reference */ yytestcase(yyruleno==16);
yymsp[0].minor.yy82 = yylhsminor.yy82; case 17: /* table_reference ::= table_factor */ yytestcase(yyruleno==17);
case 18: /* table_factor ::= table_primary */ yytestcase(yyruleno==18);
case 31: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==31);
case 33: /* query_primary ::= query_specification */ yytestcase(yyruleno==33);
{ PARSER_TRACE; yylhsminor.yy112 = yymsp[0].minor.yy112; }
yymsp[0].minor.yy112 = yylhsminor.yy112;
break; break;
case 11: /* select_sublist ::= select_item */ case 13: /* select_item ::= value_expression AS NK_ID */
case 31: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==31); { PARSER_TRACE; yylhsminor.yy112 = setProjectionAlias(pCxt, yymsp[-2].minor.yy112, &yymsp[0].minor.yy0); }
{ yylhsminor.yy82 = createNodeList(pCxt, yymsp[0].minor.yy56); } yymsp[-2].minor.yy112 = yylhsminor.yy112;
yymsp[0].minor.yy82 = yylhsminor.yy82;
break; break;
case 12: /* select_sublist ::= select_sublist NK_COMMA select_item */ case 15: /* from_clause ::= FROM table_reference_list */
case 32: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==32); { PARSER_TRACE; yymsp[-1].minor.yy112 = yymsp[0].minor.yy112; }
{ yylhsminor.yy82 = addNodeToList(pCxt, yymsp[-2].minor.yy82, yymsp[0].minor.yy56); }
yymsp[-2].minor.yy82 = yylhsminor.yy82;
break; break;
case 13: /* select_item ::= value_expression */ case 19: /* table_primary ::= table_name */
case 25: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==25); { PARSER_TRACE; yylhsminor.yy112 = createRealTableNode(pCxt, NULL, &yymsp[0].minor.yy29); }
case 27: /* query_primary ::= query_specification */ yytestcase(yyruleno==27); yymsp[0].minor.yy112 = yylhsminor.yy112;
{ yylhsminor.yy56 = yymsp[0].minor.yy56; }
yymsp[0].minor.yy56 = yylhsminor.yy56;
break; break;
case 14: /* select_item ::= value_expression AS NK_ID */ case 20: /* table_primary ::= db_name NK_DOT table_name */
{ yylhsminor.yy56 = setProjectionAlias(pCxt, yymsp[-2].minor.yy56, yymsp[0].minor.yy0); } { PARSER_TRACE; yylhsminor.yy112 = createRealTableNode(pCxt, &yymsp[-2].minor.yy29, &yymsp[0].minor.yy29); }
yymsp[-2].minor.yy56 = yylhsminor.yy56; yymsp[-2].minor.yy112 = yylhsminor.yy112;
break; break;
case 17: /* query_expression ::= with_clause_opt query_expression_body order_by_clause_opt limit_clause_opt slimit_clause_opt */ case 21: /* db_name ::= NK_ID */
{ yy_destructor(yypParser,50,&yymsp[-4].minor); case 22: /* table_name ::= NK_ID */ yytestcase(yyruleno==22);
{ yymsp[-4].minor.yy56 = yymsp[-3].minor.yy56; } { PARSER_TRACE; yylhsminor.yy29 = yymsp[0].minor.yy0; }
yy_destructor(yypParser,52,&yymsp[-2].minor); yymsp[0].minor.yy29 = yylhsminor.yy29;
yy_destructor(yypParser,53,&yymsp[-1].minor); break;
yy_destructor(yypParser,54,&yymsp[0].minor); case 23: /* query_expression ::= with_clause_opt query_expression_body order_by_clause_opt limit_clause_opt slimit_clause_opt */
{ yy_destructor(yypParser,58,&yymsp[-4].minor);
{ PARSER_TRACE; yymsp[-4].minor.yy112 = yymsp[-3].minor.yy112; }
yy_destructor(yypParser,60,&yymsp[-2].minor);
yy_destructor(yypParser,61,&yymsp[-1].minor);
yy_destructor(yypParser,62,&yymsp[0].minor);
} }
break; break;
case 18: /* with_clause_opt ::= */ case 24: /* with_clause_opt ::= */
case 24: /* table_subquery ::= */ yytestcase(yyruleno==24); case 30: /* table_subquery ::= */ yytestcase(yyruleno==30);
{} {}
break; break;
case 19: /* with_clause_opt ::= WITH with_list */ case 25: /* with_clause_opt ::= WITH with_list */
case 20: /* with_clause_opt ::= WITH RECURSIVE with_list */ yytestcase(yyruleno==20); case 26: /* with_clause_opt ::= WITH RECURSIVE with_list */ yytestcase(yyruleno==26);
{ pCxt->notSupport = true; pCxt->valid = false; } { PARSER_TRACE; pCxt->notSupport = true; pCxt->valid = false; }
yy_destructor(yypParser,55,&yymsp[0].minor); yy_destructor(yypParser,63,&yymsp[0].minor);
break; break;
case 21: /* with_list ::= with_list_element */ case 27: /* with_list ::= with_list_element */
{ yy_destructor(yypParser,56,&yymsp[0].minor); { yy_destructor(yypParser,64,&yymsp[0].minor);
{} {}
} }
break; break;
case 22: /* with_list ::= with_list NK_COMMA with_list_element */ case 28: /* with_list ::= with_list NK_COMMA with_list_element */
{ yy_destructor(yypParser,55,&yymsp[-2].minor); { yy_destructor(yypParser,63,&yymsp[-2].minor);
{} {}
yy_destructor(yypParser,56,&yymsp[0].minor); yy_destructor(yypParser,64,&yymsp[0].minor);
} }
break; break;
case 23: /* with_list_element ::= NK_ID AS table_subquery */ case 29: /* with_list_element ::= NK_ID AS table_subquery */
{} {}
yy_destructor(yypParser,57,&yymsp[0].minor); yy_destructor(yypParser,56,&yymsp[0].minor);
break; break;
case 26: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */ case 32: /* query_expression_body ::= query_expression_body UNION ALL query_expression_body */
{ yylhsminor.yy56 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy56, yymsp[0].minor.yy56); } { PARSER_TRACE; yylhsminor.yy112 = createSetOperator(pCxt, SET_OP_TYPE_UNION_ALL, yymsp[-3].minor.yy112, yymsp[0].minor.yy112); }
yymsp[-3].minor.yy56 = yylhsminor.yy56; yymsp[-3].minor.yy112 = yylhsminor.yy112;
break; break;
case 28: /* query_primary ::= NK_LP query_expression_body order_by_clause_opt limit_clause_opt slimit_clause_opt NK_RP */ case 34: /* query_primary ::= NK_LP query_expression_body order_by_clause_opt limit_clause_opt slimit_clause_opt NK_RP */
{ yymsp[-5].minor.yy56 = yymsp[-4].minor.yy56;} { PARSER_TRACE; yymsp[-5].minor.yy112 = yymsp[-4].minor.yy112;}
yy_destructor(yypParser,52,&yymsp[-3].minor); yy_destructor(yypParser,60,&yymsp[-3].minor);
yy_destructor(yypParser,53,&yymsp[-2].minor); yy_destructor(yypParser,61,&yymsp[-2].minor);
yy_destructor(yypParser,54,&yymsp[-1].minor); yy_destructor(yypParser,62,&yymsp[-1].minor);
break; break;
case 29: /* order_by_clause_opt ::= */ case 35: /* order_by_clause_opt ::= */
{ yymsp[1].minor.yy82 = NULL; } { PARSER_TRACE; yymsp[1].minor.yy124 = NULL; }
break; break;
case 30: /* order_by_clause_opt ::= ORDER BY sort_specification_list */ case 36: /* order_by_clause_opt ::= ORDER BY sort_specification_list */
{ yymsp[-2].minor.yy82 = yymsp[0].minor.yy82; } { PARSER_TRACE; yymsp[-2].minor.yy124 = yymsp[0].minor.yy124; }
break; break;
case 33: /* sort_specification ::= value_expression ordering_specification_opt null_ordering_opt */ case 39: /* sort_specification ::= value_expression ordering_specification_opt null_ordering_opt */
{ yylhsminor.yy56 = createOrderByExprNode(pCxt, yymsp[-2].minor.yy56, yymsp[-1].minor.yy92, yymsp[0].minor.yy109); } { PARSER_TRACE; yylhsminor.yy112 = createOrderByExprNode(pCxt, yymsp[-2].minor.yy112, yymsp[-1].minor.yy78, yymsp[0].minor.yy137); }
yymsp[-2].minor.yy56 = yylhsminor.yy56; yymsp[-2].minor.yy112 = yylhsminor.yy112;
break; break;
case 34: /* ordering_specification_opt ::= */ case 40: /* ordering_specification_opt ::= */
{ yymsp[1].minor.yy92 = ORDER_ASC; } { PARSER_TRACE; yymsp[1].minor.yy78 = ORDER_ASC; }
break; break;
case 35: /* ordering_specification_opt ::= ASC */ case 41: /* ordering_specification_opt ::= ASC */
{ yymsp[0].minor.yy92 = ORDER_ASC; } { PARSER_TRACE; yymsp[0].minor.yy78 = ORDER_ASC; }
break; break;
case 36: /* ordering_specification_opt ::= DESC */ case 42: /* ordering_specification_opt ::= DESC */
{ yymsp[0].minor.yy92 = ORDER_DESC; } { PARSER_TRACE; yymsp[0].minor.yy78 = ORDER_DESC; }
break; break;
case 37: /* null_ordering_opt ::= */ case 43: /* null_ordering_opt ::= */
{ yymsp[1].minor.yy109 = NULL_ORDER_DEFAULT; } { PARSER_TRACE; yymsp[1].minor.yy137 = NULL_ORDER_DEFAULT; }
break; break;
case 38: /* null_ordering_opt ::= NULLS FIRST */ case 44: /* null_ordering_opt ::= NULLS FIRST */
{ yymsp[-1].minor.yy109 = NULL_ORDER_FIRST; } { PARSER_TRACE; yymsp[-1].minor.yy137 = NULL_ORDER_FIRST; }
break; break;
case 39: /* null_ordering_opt ::= NULLS LAST */ case 45: /* null_ordering_opt ::= NULLS LAST */
{ yymsp[-1].minor.yy109 = NULL_ORDER_LAST; } { PARSER_TRACE; yymsp[-1].minor.yy137 = NULL_ORDER_LAST; }
break; break;
case 40: /* value_function ::= NK_ID NK_LP value_expression NK_RP */ case 46: /* value_function ::= NK_ID NK_LP value_expression NK_RP */
case 42: /* value_expression_primary ::= NK_LP value_expression NK_RP */ yytestcase(yyruleno==42); case 48: /* value_expression_primary ::= NK_LP value_expression NK_RP */ yytestcase(yyruleno==48);
{ {
} }
yy_destructor(yypParser,34,&yymsp[-1].minor); yy_destructor(yypParser,35,&yymsp[-1].minor);
break; break;
case 41: /* value_function ::= NK_ID NK_LP value_expression NK_COMMA value_expression NK_RP */ case 47: /* value_function ::= NK_ID NK_LP value_expression NK_COMMA value_expression NK_RP */
{ {
} }
yy_destructor(yypParser,34,&yymsp[-3].minor); yy_destructor(yypParser,35,&yymsp[-3].minor);
yy_destructor(yypParser,34,&yymsp[-1].minor); yy_destructor(yypParser,35,&yymsp[-1].minor);
break; break;
case 43: /* value_expression_primary ::= nonparenthesized_value_expression_primary */ case 49: /* value_expression_primary ::= nonparenthesized_value_expression_primary */
{ yy_destructor(yypParser,36,&yymsp[0].minor); { yy_destructor(yypParser,37,&yymsp[0].minor);
{ {
} }
} }
break; break;
case 44: /* nonparenthesized_value_expression_primary ::= literal */ case 50: /* nonparenthesized_value_expression_primary ::= literal */
{ yy_destructor(yypParser,37,&yymsp[0].minor); { yy_destructor(yypParser,38,&yymsp[0].minor);
{ {
} }
} }
break; break;
case 45: /* nonparenthesized_value_expression_primary ::= column_reference */ case 51: /* nonparenthesized_value_expression_primary ::= column_reference */
{ yy_destructor(yypParser,38,&yymsp[0].minor); { yy_destructor(yypParser,39,&yymsp[0].minor);
{ {
} }
} }
break; break;
case 47: /* value_expression ::= common_value_expression */ case 53: /* value_expression ::= common_value_expression */
{ yy_destructor(yypParser,39,&yymsp[0].minor); { yy_destructor(yypParser,41,&yymsp[0].minor);
{ {
} }
} }
break; break;
case 48: /* common_value_expression ::= numeric_value_expression */ case 54: /* common_value_expression ::= numeric_value_expression */
{ yy_destructor(yypParser,40,&yymsp[0].minor); { yy_destructor(yypParser,42,&yymsp[0].minor);
{ {
} }
} }
break; break;
case 49: /* numeric_value_expression ::= numeric_primary */ case 55: /* numeric_value_expression ::= numeric_primary */
{ yy_destructor(yypParser,41,&yymsp[0].minor); { yy_destructor(yypParser,43,&yymsp[0].minor);
{ {
} }
} }
break; break;
case 50: /* numeric_value_expression ::= NK_PLUS numeric_primary */ case 56: /* numeric_value_expression ::= NK_PLUS numeric_primary */
case 51: /* numeric_value_expression ::= NK_MINUS numeric_primary */ yytestcase(yyruleno==51); case 57: /* numeric_value_expression ::= NK_MINUS numeric_primary */ yytestcase(yyruleno==57);
{ {
} }
yy_destructor(yypParser,41,&yymsp[0].minor); yy_destructor(yypParser,43,&yymsp[0].minor);
break; break;
case 52: /* numeric_value_expression ::= numeric_value_expression NK_PLUS numeric_value_expression */ case 58: /* numeric_value_expression ::= numeric_value_expression NK_PLUS numeric_value_expression */
case 53: /* numeric_value_expression ::= numeric_value_expression NK_MINUS numeric_value_expression */ yytestcase(yyruleno==53); case 59: /* numeric_value_expression ::= numeric_value_expression NK_MINUS numeric_value_expression */ yytestcase(yyruleno==59);
case 54: /* numeric_value_expression ::= numeric_value_expression NK_STAR numeric_value_expression */ yytestcase(yyruleno==54); case 60: /* numeric_value_expression ::= numeric_value_expression NK_STAR numeric_value_expression */ yytestcase(yyruleno==60);
case 55: /* numeric_value_expression ::= numeric_value_expression NK_SLASH numeric_value_expression */ yytestcase(yyruleno==55); case 61: /* numeric_value_expression ::= numeric_value_expression NK_SLASH numeric_value_expression */ yytestcase(yyruleno==61);
{ yy_destructor(yypParser,40,&yymsp[-2].minor); { yy_destructor(yypParser,42,&yymsp[-2].minor);
{ {
} }
yy_destructor(yypParser,40,&yymsp[0].minor); yy_destructor(yypParser,42,&yymsp[0].minor);
} }
break; break;
case 56: /* numeric_primary ::= value_expression_primary */ case 62: /* numeric_primary ::= value_expression_primary */
{ yy_destructor(yypParser,35,&yymsp[0].minor); { yy_destructor(yypParser,36,&yymsp[0].minor);
{ {
} }
} }
break; break;
case 57: /* numeric_primary ::= value_function */ case 63: /* numeric_primary ::= value_function */
{ yy_destructor(yypParser,33,&yymsp[0].minor); { yy_destructor(yypParser,34,&yymsp[0].minor);
{ {
} }
} }
break; break;
case 58: /* from_clause ::= FROM table_reference_list */ case 64: /* table_primary ::= derived_table */
{ yy_destructor(yypParser,55,&yymsp[0].minor);
{ {
} }
yy_destructor(yypParser,48,&yymsp[0].minor); }
break; break;
case 59: /* table_reference_list ::= table_reference */ case 65: /* derived_table ::= table_subquery */
{ yy_destructor(yypParser,49,&yymsp[0].minor); { yy_destructor(yypParser,56,&yymsp[0].minor);
{ {
} }
} }
break; break;
case 60: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */ case 66: /* subquery ::= NK_LR query_expression NK_RP */
{ yy_destructor(yypParser,48,&yymsp[-2].minor); {
}
yy_destructor(yypParser,33,&yymsp[-1].minor);
break;
case 67: /* table_subquery ::= subquery */
{ yy_destructor(yypParser,57,&yymsp[0].minor);
{ {
} }
yy_destructor(yypParser,49,&yymsp[0].minor);
} }
break; break;
default: default:
/* (46) literal ::= NK_LITERAL */ yytestcase(yyruleno==46); /* (52) literal ::= NK_LITERAL */ yytestcase(yyruleno==52);
/* (61) table_reference ::= NK_ID */ yytestcase(yyruleno==61); /* (68) limit_clause_opt ::= */ yytestcase(yyruleno==68);
/* (62) limit_clause_opt ::= */ yytestcase(yyruleno==62); /* (69) slimit_clause_opt ::= */ yytestcase(yyruleno==69);
/* (63) slimit_clause_opt ::= */ yytestcase(yyruleno==63);
break; break;
/********** End reduce actions ************************************************/ /********** End reduce actions ************************************************/
}; };
...@@ -1432,16 +1482,16 @@ static void yy_syntax_error( ...@@ -1432,16 +1482,16 @@ static void yy_syntax_error(
#define TOKEN yyminor #define TOKEN yyminor
/************ Begin %syntax_error code ****************************************/ /************ Begin %syntax_error code ****************************************/
if(TOKEN->z) { if(TOKEN.z) {
char msg[] = "syntax error near \"%s\""; char msg[] = "syntax error near \"%s\"";
int32_t sqlLen = strlen(&TOKEN->z[0]); int32_t sqlLen = strlen(&TOKEN.z[0]);
if (sqlLen + sizeof(msg)/sizeof(msg[0]) + 1 > pCxt->pQueryCxt->msgLen) { if (sqlLen + sizeof(msg)/sizeof(msg[0]) + 1 > pCxt->pQueryCxt->msgLen) {
char tmpstr[128] = {0}; char tmpstr[128] = {0};
memcpy(tmpstr, &TOKEN->z[0], sizeof(tmpstr)/sizeof(tmpstr[0]) - 1); memcpy(tmpstr, &TOKEN.z[0], sizeof(tmpstr)/sizeof(tmpstr[0]) - 1);
sprintf(pCxt->pQueryCxt->pMsg, msg, tmpstr); sprintf(pCxt->pQueryCxt->pMsg, msg, tmpstr);
} else { } else {
sprintf(pCxt->pQueryCxt->pMsg, msg, &TOKEN->z[0]); sprintf(pCxt->pQueryCxt->pMsg, msg, &TOKEN.z[0]);
} }
} else { } else {
sprintf(pCxt->pQueryCxt->pMsg, "Incomplete SQL statement"); sprintf(pCxt->pQueryCxt->pMsg, "Incomplete SQL statement");
......
...@@ -15,5 +15,5 @@ TARGET_INCLUDE_DIRECTORIES( ...@@ -15,5 +15,5 @@ TARGET_INCLUDE_DIRECTORIES(
TARGET_LINK_LIBRARIES( TARGET_LINK_LIBRARIES(
parserTest parserTest
PUBLIC os util common parser catalog transport gtest function planner qcom PUBLIC os util common nodes parser catalog transport gtest function planner qcom
) )
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <gtest/gtest.h>
#include "astCreater.h"
using namespace std;
using namespace testing;
class NewParserTest : public Test {
protected:
void setDatabase(const string& acctId, const string& db) {
acctId_ = acctId;
db_ = db;
}
void bind(const char* sql) {
reset();
cxt_.acctId = atoi(acctId_.c_str());
cxt_.db = (char*) db_.c_str();
strcpy(sqlBuf_, sql);
cxt_.sqlLen = strlen(sql);
sqlBuf_[cxt_.sqlLen] = '\0';
cxt_.pSql = sqlBuf_;
}
int32_t run() {
int32_t code = doParse(&cxt_, &query_);
if (code != TSDB_CODE_SUCCESS) {
cout << "code:" << tstrerror(code) << ", msg:" << errMagBuf_ << endl;
return code;
}
cout << nodeType(query_.pRoot) << endl;
if (NULL != query_.pRoot && QUERY_NODE_SELECT_STMT == nodeType(query_.pRoot)) {
// SNode* pWhereCond;
// SNodeList* pPartitionByList; // SNode
// SNode* pWindowClause;
// SNodeList* pGroupByList; // SGroupingSetNode
// SNodeList* pOrderByList; // SOrderByExprNode
// SLimitNode limit;
// SLimitNode slimit;
SSelectStmt* select = (SSelectStmt*)query_.pRoot;
string sql("SELECT ");
if (select->isDistinct) {
sql.append("DISTINCT ");
}
if (nullptr == select->pProjectionList) {
sql.append("* ");
} else {
nodeListToSql(select->pProjectionList, sql);
}
sql.append("FROM ");
tableToSql(select->pFromTable, sql);
cout << sql << endl;
}
// char* pStr = NULL;
// int32_t len = 0;
// code = nodesNodeToString(query_.pRoot, &pStr, &len);
// if (code != TSDB_CODE_SUCCESS) {
// cout << "code:" << tstrerror(code) << ", msg:" << errMagBuf_ << endl;
// return code;
// }
// cout << "node tree:\n" << pStr << endl;
return TSDB_CODE_SUCCESS;
}
private:
static const int max_err_len = 1024;
static const int max_sql_len = 1024 * 1024;
void tableToSql(const SNode* node, string& sql) {
const STableNode* table = (const STableNode*)node;
cout << "node : " << nodeType(node) << endl;
switch (nodeType(node)) {
case QUERY_NODE_REAL_TABLE: {
SRealTableNode* realTable = (SRealTableNode*)table;
if ('\0' != realTable->dbName[0]) {
sql.append(realTable->dbName);
sql.append(".");
}
sql.append(realTable->table.tableName);
break;
}
default:
break;
}
}
void nodeListToSql(const SNodeList* nodelist, string& sql, const string& seq = ",") {
SNode* node = nullptr;
bool firstNode = true;
FOREACH(node, nodelist) {
if (!firstNode) {
sql.append(", ");
}
switch (nodeType(node)) {
case QUERY_NODE_COLUMN:
sql.append(((SColumnNode*)node)->colName);
break;
}
}
}
void reset() {
memset(&cxt_, 0, sizeof(cxt_));
memset(errMagBuf_, 0, max_err_len);
cxt_.pMsg = errMagBuf_;
cxt_.msgLen = max_err_len;
}
string acctId_;
string db_;
char errMagBuf_[max_err_len];
char sqlBuf_[max_sql_len];
SParseContext cxt_;
SQuery query_;
};
// SELECT * FROM t1
TEST_F(NewParserTest, selectStar) {
setDatabase("root", "test");
bind("SELECT * FROM t1");
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
bind("SELECT * FROM test.t1");
ASSERT_EQ(run(), TSDB_CODE_SUCCESS);
}
...@@ -16,7 +16,28 @@ ...@@ -16,7 +16,28 @@
#include "nodes.h" #include "nodes.h"
int32_t nodesNodeToString(const SNode* pNode, char** pStr, int32_t* pLen) { int32_t nodesNodeToString(const SNode* pNode, char** pStr, int32_t* pLen) {
switch (nodeType(pNode)) {
case QUERY_NODE_COLUMN:
case QUERY_NODE_VALUE:
case QUERY_NODE_OPERATOR:
case QUERY_NODE_LOGIC_CONDITION:
case QUERY_NODE_IS_NULL_CONDITION:
case QUERY_NODE_FUNCTION:
case QUERY_NODE_REAL_TABLE:
case QUERY_NODE_TEMP_TABLE:
case QUERY_NODE_JOIN_TABLE:
case QUERY_NODE_GROUPING_SET:
case QUERY_NODE_ORDER_BY_EXPR:
case QUERY_NODE_LIMIT:
case QUERY_NODE_STATE_WINDOW:
case QUERY_NODE_SESSION_WINDOW:
case QUERY_NODE_INTERVAL_WINDOW:
case QUERY_NODE_SET_OPERATOR:
case QUERY_NODE_SELECT_STMT:
case QUERY_NODE_SHOW_STMT:
default:
break;
}
} }
int32_t nodesStringToNode(const char* pStr, SNode** pNode) { int32_t nodesStringToNode(const char* pStr, SNode** pNode) {
......
...@@ -36,13 +36,13 @@ ...@@ -36,13 +36,13 @@
return false; \ return false; \
} while (0) } while (0)
#define COMPARE_ARRAY_FIELD(fldname) \ #define COMPARE_NODE_LIST_FIELD(fldname) \
do { \ do { \
if (!nodeArrayEqual(a->fldname, b->fldname)) \ if (!nodeNodeListEqual(a->fldname, b->fldname)) \
return false; \ return false; \
} while (0) } while (0)
static bool nodeArrayEqual(const SArray* a, const SArray* b) { static bool nodeNodeListEqual(const SNodeList* a, const SNodeList* b) {
if (a == b) { if (a == b) {
return true; return true;
} }
...@@ -51,13 +51,13 @@ static bool nodeArrayEqual(const SArray* a, const SArray* b) { ...@@ -51,13 +51,13 @@ static bool nodeArrayEqual(const SArray* a, const SArray* b) {
return false; return false;
} }
if (taosArrayGetSize(a) != taosArrayGetSize(b)) { if (LIST_LENGTH(a) != LIST_LENGTH(b)) {
return false; return false;
} }
size_t size = taosArrayGetSize(a); SNode* na, *nb;
for (size_t i = 0; i < size; ++i) { FORBOTH(na, a, nb, b) {
if (!nodesEqualNode((SNode*)taosArrayGetP(a, i), (SNode*)taosArrayGetP(b, i))) { if (!nodesEqualNode(na, nb)) {
return false; return false;
} }
} }
...@@ -85,7 +85,7 @@ static bool operatorNodeEqual(const SOperatorNode* a, const SOperatorNode* b) { ...@@ -85,7 +85,7 @@ static bool operatorNodeEqual(const SOperatorNode* a, const SOperatorNode* b) {
static bool logicConditionNodeEqual(const SLogicConditionNode* a, const SLogicConditionNode* b) { static bool logicConditionNodeEqual(const SLogicConditionNode* a, const SLogicConditionNode* b) {
COMPARE_SCALAR_FIELD(condType); COMPARE_SCALAR_FIELD(condType);
COMPARE_ARRAY_FIELD(pParameterList); COMPARE_NODE_LIST_FIELD(pParameterList);
return true; return true;
} }
...@@ -97,7 +97,7 @@ static bool isNullConditionNodeEqual(const SIsNullCondNode* a, const SIsNullCond ...@@ -97,7 +97,7 @@ static bool isNullConditionNodeEqual(const SIsNullCondNode* a, const SIsNullCond
static bool functionNodeEqual(const SFunctionNode* a, const SFunctionNode* b) { static bool functionNodeEqual(const SFunctionNode* a, const SFunctionNode* b) {
COMPARE_SCALAR_FIELD(funcId); COMPARE_SCALAR_FIELD(funcId);
COMPARE_ARRAY_FIELD(pParameterList); COMPARE_NODE_LIST_FIELD(pParameterList);
return true; return true;
} }
...@@ -132,6 +132,7 @@ bool nodesEqualNode(const SNode* a, const SNode* b) { ...@@ -132,6 +132,7 @@ bool nodesEqualNode(const SNode* a, const SNode* b) {
case QUERY_NODE_JOIN_TABLE: case QUERY_NODE_JOIN_TABLE:
case QUERY_NODE_GROUPING_SET: case QUERY_NODE_GROUPING_SET:
case QUERY_NODE_ORDER_BY_EXPR: case QUERY_NODE_ORDER_BY_EXPR:
case QUERY_NODE_LIMIT:
return false; // todo return false; // todo
default: default:
break; break;
......
...@@ -17,14 +17,14 @@ ...@@ -17,14 +17,14 @@
typedef bool (*FQueryNodeWalker)(SNode* pNode, void* pContext); typedef bool (*FQueryNodeWalker)(SNode* pNode, void* pContext);
bool nodesWalkArray(SArray* pArray, FQueryNodeWalker walker, void* pContext) { bool nodesWalkNodeList(SNodeList* pNodeList, FQueryNodeWalker walker, void* pContext) {
size_t size = taosArrayGetSize(pArray); SNode* node;
for (size_t i = 0; i < size; ++i) { FOREACH(node, pNodeList) {
if (!nodesWalkNode((SNode*)taosArrayGetP(pArray, i), walker, pContext)) { if (!nodesWalkNode(node, walker, pContext)) {
return false; return false;
}
} }
return true; }
return true;
} }
bool nodesWalkNode(SNode* pNode, FQueryNodeWalker walker, void* pContext) { bool nodesWalkNode(SNode* pNode, FQueryNodeWalker walker, void* pContext) {
...@@ -39,6 +39,7 @@ bool nodesWalkNode(SNode* pNode, FQueryNodeWalker walker, void* pContext) { ...@@ -39,6 +39,7 @@ bool nodesWalkNode(SNode* pNode, FQueryNodeWalker walker, void* pContext) {
switch (nodeType(pNode)) { switch (nodeType(pNode)) {
case QUERY_NODE_COLUMN: case QUERY_NODE_COLUMN:
case QUERY_NODE_VALUE: case QUERY_NODE_VALUE:
case QUERY_NODE_LIMIT:
// these node types with no subnodes // these node types with no subnodes
return true; return true;
case QUERY_NODE_OPERATOR: { case QUERY_NODE_OPERATOR: {
...@@ -49,11 +50,11 @@ bool nodesWalkNode(SNode* pNode, FQueryNodeWalker walker, void* pContext) { ...@@ -49,11 +50,11 @@ bool nodesWalkNode(SNode* pNode, FQueryNodeWalker walker, void* pContext) {
return nodesWalkNode(pOpNode->pRight, walker, pContext); return nodesWalkNode(pOpNode->pRight, walker, pContext);
} }
case QUERY_NODE_LOGIC_CONDITION: case QUERY_NODE_LOGIC_CONDITION:
return nodesWalkArray(((SLogicConditionNode*)pNode)->pParameterList, walker, pContext); return nodesWalkNodeList(((SLogicConditionNode*)pNode)->pParameterList, walker, pContext);
case QUERY_NODE_IS_NULL_CONDITION: case QUERY_NODE_IS_NULL_CONDITION:
return nodesWalkNode(((SIsNullCondNode*)pNode)->pExpr, walker, pContext); return nodesWalkNode(((SIsNullCondNode*)pNode)->pExpr, walker, pContext);
case QUERY_NODE_FUNCTION: case QUERY_NODE_FUNCTION:
return nodesWalkArray(((SFunctionNode*)pNode)->pParameterList, walker, pContext); return nodesWalkNodeList(((SFunctionNode*)pNode)->pParameterList, walker, pContext);
case QUERY_NODE_REAL_TABLE: case QUERY_NODE_REAL_TABLE:
case QUERY_NODE_TEMP_TABLE: case QUERY_NODE_TEMP_TABLE:
return true; // todo return true; // todo
...@@ -68,7 +69,7 @@ bool nodesWalkNode(SNode* pNode, FQueryNodeWalker walker, void* pContext) { ...@@ -68,7 +69,7 @@ bool nodesWalkNode(SNode* pNode, FQueryNodeWalker walker, void* pContext) {
return nodesWalkNode(pJoinTableNode->pOnCond, walker, pContext); return nodesWalkNode(pJoinTableNode->pOnCond, walker, pContext);
} }
case QUERY_NODE_GROUPING_SET: case QUERY_NODE_GROUPING_SET:
return nodesWalkArray(((SGroupingSetNode*)pNode)->pParameterList, walker, pContext); return nodesWalkNodeList(((SGroupingSetNode*)pNode)->pParameterList, walker, pContext);
case QUERY_NODE_ORDER_BY_EXPR: case QUERY_NODE_ORDER_BY_EXPR:
return nodesWalkNode(((SOrderByExprNode*)pNode)->pExpr, walker, pContext); return nodesWalkNode(((SOrderByExprNode*)pNode)->pExpr, walker, pContext);
default: default:
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
*/ */
#include "nodes.h" #include "nodes.h"
#include "nodesShowStmts.h"
bool nodesIsTimeorderQuery(const SNode* pQuery) { bool nodesIsTimeorderQuery(const SNode* pQuery) {
...@@ -23,8 +24,54 @@ bool nodesIsTimelineQuery(const SNode* pQuery) { ...@@ -23,8 +24,54 @@ bool nodesIsTimelineQuery(const SNode* pQuery) {
} }
SNode* nodesMakeNode(ENodeType type) { static SNode* makeNode(ENodeType type, size_t size) {
SNode* p = calloc(1, size);
setNodeType(p, type);
return p;
}
SNode* nodesMakeNode(ENodeType type) {
switch (type) {
case QUERY_NODE_COLUMN:
return makeNode(type, sizeof(SColumnNode));
case QUERY_NODE_VALUE:
return makeNode(type, sizeof(SValueNode));
case QUERY_NODE_OPERATOR:
return makeNode(type, sizeof(SOperatorNode));
case QUERY_NODE_LOGIC_CONDITION:
return makeNode(type, sizeof(SLogicConditionNode));
case QUERY_NODE_IS_NULL_CONDITION:
return makeNode(type, sizeof(SIsNullCondNode));
case QUERY_NODE_FUNCTION:
return makeNode(type, sizeof(SFunctionNode));
case QUERY_NODE_REAL_TABLE:
return makeNode(type, sizeof(SRealTableNode));
case QUERY_NODE_TEMP_TABLE:
return makeNode(type, sizeof(STempTableNode));
case QUERY_NODE_JOIN_TABLE:
return makeNode(type, sizeof(SJoinTableNode));
case QUERY_NODE_GROUPING_SET:
return makeNode(type, sizeof(SGroupingSetNode));
case QUERY_NODE_ORDER_BY_EXPR:
return makeNode(type, sizeof(SOrderByExprNode));
case QUERY_NODE_LIMIT:
return makeNode(type, sizeof(SLimitNode));
case QUERY_NODE_STATE_WINDOW:
return makeNode(type, sizeof(SStateWindowNode));
case QUERY_NODE_SESSION_WINDOW:
return makeNode(type, sizeof(SSessionWindowNode));
case QUERY_NODE_INTERVAL_WINDOW:
return makeNode(type, sizeof(SIntervalWindowNode));
case QUERY_NODE_SET_OPERATOR:
return makeNode(type, sizeof(SSetOperator));
case QUERY_NODE_SELECT_STMT:
return makeNode(type, sizeof(SSelectStmt));
case QUERY_NODE_SHOW_STMT:
return makeNode(type, sizeof(SShowStmt));
default:
break;
}
return NULL;
} }
void nodesDestroyNode(SNode* pNode) { void nodesDestroyNode(SNode* pNode) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册