Merge pull request #10160 from taosdata/feature/3.0_wxy
TD-13338 SELECT statement translate code
This commit is contained in:
commit
69d196815b
|
@ -55,7 +55,7 @@ typedef enum ENodeType {
|
||||||
QUERY_NODE_FILL,
|
QUERY_NODE_FILL,
|
||||||
|
|
||||||
// only for parser
|
// only for parser
|
||||||
QUERY_NODE_TARGET_EXPR,
|
QUERY_NODE_RAW_EXPR,
|
||||||
|
|
||||||
QUERY_NODE_SET_OPERATOR,
|
QUERY_NODE_SET_OPERATOR,
|
||||||
QUERY_NODE_SELECT_STMT,
|
QUERY_NODE_SELECT_STMT,
|
||||||
|
@ -81,6 +81,13 @@ typedef struct SNodeList {
|
||||||
SListCell* pTail;
|
SListCell* pTail;
|
||||||
} SNodeList;
|
} SNodeList;
|
||||||
|
|
||||||
|
typedef struct SRawExprNode {
|
||||||
|
ENodeType nodeType;
|
||||||
|
char* p;
|
||||||
|
uint32_t n;
|
||||||
|
SNode* pNode;
|
||||||
|
} SRawExprNode;
|
||||||
|
|
||||||
typedef struct SDataType {
|
typedef struct SDataType {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint8_t precision;
|
uint8_t precision;
|
||||||
|
|
|
@ -27,12 +27,10 @@ extern "C" {
|
||||||
|
|
||||||
extern SToken nil_token;
|
extern SToken nil_token;
|
||||||
|
|
||||||
typedef struct STargetExprNode {
|
SNode* createRawExprNode(SAstCreateContext* pCxt, const SToken* pToken, SNode* pNode);
|
||||||
ENodeType nodeType;
|
SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const SToken* pEnd, SNode* pNode);
|
||||||
char* p;
|
SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode);
|
||||||
uint32_t n;
|
SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode);
|
||||||
SNode* pNode;
|
|
||||||
} STargetExprNode;
|
|
||||||
|
|
||||||
SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode);
|
SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode);
|
||||||
SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode);
|
SNodeList* addNodeToList(SAstCreateContext* pCxt, SNodeList* pList, SNode* pNode);
|
||||||
|
|
|
@ -67,19 +67,19 @@ cmd ::= SHOW DATABASES.
|
||||||
cmd ::= query_expression(A). { PARSER_TRACE; pCxt->pRootNode = A; }
|
cmd ::= query_expression(A). { PARSER_TRACE; pCxt->pRootNode = A; }
|
||||||
|
|
||||||
/************************************************ literal *************************************************************/
|
/************************************************ literal *************************************************************/
|
||||||
literal(A) ::= NK_INTEGER(B). { PARSER_TRACE; A = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); }
|
literal(A) ::= NK_INTEGER(B). { PARSER_TRACE; A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B)); }
|
||||||
literal(A) ::= NK_FLOAT(B). { PARSER_TRACE; A = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &B); }
|
literal(A) ::= NK_FLOAT(B). { PARSER_TRACE; A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &B)); }
|
||||||
literal(A) ::= NK_STRING(B). { PARSER_TRACE; A = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); }
|
literal(A) ::= NK_STRING(B). { PARSER_TRACE; A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B)); }
|
||||||
literal(A) ::= NK_BOOL(B). { PARSER_TRACE; A = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &B); }
|
literal(A) ::= NK_BOOL(B). { PARSER_TRACE; A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &B)); }
|
||||||
literal(A) ::= TIMESTAMP NK_STRING(B). { PARSER_TRACE; A = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &B); }
|
literal(A) ::= TIMESTAMP(B) NK_STRING(C). { PARSER_TRACE; A = createRawExprNodeExt(pCxt, &B, &C, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &C)); }
|
||||||
literal(A) ::= duration_literal(B). { PARSER_TRACE; A = B; }
|
literal(A) ::= duration_literal(B). { PARSER_TRACE; A = B; }
|
||||||
|
|
||||||
duration_literal(A) ::= NK_VARIABLE(B). { PARSER_TRACE; A = createDurationValueNode(pCxt, &B); }
|
duration_literal(A) ::= NK_VARIABLE(B). { PARSER_TRACE; A = createRawExprNode(pCxt, &B, createDurationValueNode(pCxt, &B)); }
|
||||||
|
|
||||||
%type literal_list { SNodeList* }
|
%type literal_list { SNodeList* }
|
||||||
%destructor literal_list { PARSER_DESTRUCTOR_TRACE; nodesDestroyList($$); }
|
%destructor literal_list { PARSER_DESTRUCTOR_TRACE; nodesDestroyList($$); }
|
||||||
literal_list(A) ::= literal(B). { PARSER_TRACE; A = createNodeList(pCxt, B); }
|
literal_list(A) ::= literal(B). { PARSER_TRACE; A = createNodeList(pCxt, releaseRawExprNode(pCxt, B)); }
|
||||||
literal_list(A) ::= literal_list(B) NK_COMMA literal(C). { PARSER_TRACE; A = addNodeToList(pCxt, B, C); }
|
literal_list(A) ::= literal_list(B) NK_COMMA literal(C). { PARSER_TRACE; A = addNodeToList(pCxt, B, releaseRawExprNode(pCxt, C)); }
|
||||||
|
|
||||||
/************************************************ names and identifiers ***********************************************/
|
/************************************************ names and identifiers ***********************************************/
|
||||||
%type db_name { SToken }
|
%type db_name { SToken }
|
||||||
|
@ -111,37 +111,70 @@ expression(A) ::= literal(B).
|
||||||
//expression(A) ::= NK_QUESTION(B). { PARSER_TRACE; A = B; }
|
//expression(A) ::= NK_QUESTION(B). { PARSER_TRACE; A = B; }
|
||||||
//expression(A) ::= pseudo_column(B). { PARSER_TRACE; A = B; }
|
//expression(A) ::= pseudo_column(B). { PARSER_TRACE; A = B; }
|
||||||
expression(A) ::= column_reference(B). { PARSER_TRACE; A = B; }
|
expression(A) ::= column_reference(B). { PARSER_TRACE; A = B; }
|
||||||
expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP. { PARSER_TRACE; A = createFunctionNode(pCxt, &B, C); }
|
expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { PARSER_TRACE; A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
|
||||||
//expression(A) ::= cast_expression(B). { PARSER_TRACE; A = B; }
|
//expression(A) ::= cast_expression(B). { PARSER_TRACE; A = B; }
|
||||||
//expression(A) ::= case_expression(B). { PARSER_TRACE; A = B; }
|
//expression(A) ::= case_expression(B). { PARSER_TRACE; A = B; }
|
||||||
expression(A) ::= subquery(B). { PARSER_TRACE; A = B; }
|
expression(A) ::= subquery(B). { PARSER_TRACE; A = B; }
|
||||||
expression(A) ::= NK_LP expression(B) NK_RP. { PARSER_TRACE; A = B; }
|
expression(A) ::= NK_LP(B) expression(C) NK_RP(D). { PARSER_TRACE; A = createRawExprNodeExt(pCxt, &B, &D, releaseRawExprNode(pCxt, C)); }
|
||||||
expression(A) ::= NK_PLUS expression(B). { PARSER_TRACE; A = B; }
|
expression(A) ::= NK_PLUS(B) expression(C). {
|
||||||
expression(A) ::= NK_MINUS expression(B). { PARSER_TRACE; A = createOperatorNode(pCxt, OP_TYPE_SUB, B, NULL); }
|
PARSER_TRACE;
|
||||||
expression(A) ::= expression(B) NK_PLUS expression(C). { PARSER_TRACE; A = createOperatorNode(pCxt, OP_TYPE_ADD, B, C); }
|
SToken t = getTokenFromRawExprNode(pCxt, C);
|
||||||
expression(A) ::= expression(B) NK_MINUS expression(C). { PARSER_TRACE; A = createOperatorNode(pCxt, OP_TYPE_SUB, B, C); }
|
A = createRawExprNodeExt(pCxt, &B, &t, releaseRawExprNode(pCxt, C));
|
||||||
expression(A) ::= expression(B) NK_STAR expression(C). { PARSER_TRACE; A = createOperatorNode(pCxt, OP_TYPE_MULTI, B, C); }
|
}
|
||||||
expression(A) ::= expression(B) NK_SLASH expression(C). { PARSER_TRACE; A = createOperatorNode(pCxt, OP_TYPE_DIV, B, C); }
|
expression(A) ::= NK_MINUS(B) expression(C). {
|
||||||
expression(A) ::= expression(B) NK_REM expression(C). { PARSER_TRACE; A = createOperatorNode(pCxt, OP_TYPE_MOD, B, C); }
|
PARSER_TRACE;
|
||||||
|
SToken t = getTokenFromRawExprNode(pCxt, C);
|
||||||
|
A = createRawExprNodeExt(pCxt, &B, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, C), NULL));
|
||||||
|
}
|
||||||
|
expression(A) ::= expression(B) NK_PLUS expression(C). {
|
||||||
|
PARSER_TRACE;
|
||||||
|
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||||
|
SToken e = getTokenFromRawExprNode(pCxt, C);
|
||||||
|
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
|
||||||
|
}
|
||||||
|
expression(A) ::= expression(B) NK_MINUS expression(C). {
|
||||||
|
PARSER_TRACE;
|
||||||
|
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||||
|
SToken e = getTokenFromRawExprNode(pCxt, C);
|
||||||
|
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
|
||||||
|
}
|
||||||
|
expression(A) ::= expression(B) NK_STAR expression(C). {
|
||||||
|
PARSER_TRACE;
|
||||||
|
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||||
|
SToken e = getTokenFromRawExprNode(pCxt, C);
|
||||||
|
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
|
||||||
|
}
|
||||||
|
expression(A) ::= expression(B) NK_SLASH expression(C). {
|
||||||
|
PARSER_TRACE;
|
||||||
|
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||||
|
SToken e = getTokenFromRawExprNode(pCxt, C);
|
||||||
|
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
|
||||||
|
}
|
||||||
|
expression(A) ::= expression(B) NK_REM expression(C). {
|
||||||
|
PARSER_TRACE;
|
||||||
|
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||||
|
SToken e = getTokenFromRawExprNode(pCxt, C);
|
||||||
|
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
|
||||||
|
}
|
||||||
|
|
||||||
%type expression_list { SNodeList* }
|
%type expression_list { SNodeList* }
|
||||||
%destructor expression_list { PARSER_DESTRUCTOR_TRACE; nodesDestroyList($$); }
|
%destructor expression_list { PARSER_DESTRUCTOR_TRACE; nodesDestroyList($$); }
|
||||||
expression_list(A) ::= expression(B). { PARSER_TRACE; A = createNodeList(pCxt, B); }
|
expression_list(A) ::= expression(B). { PARSER_TRACE; A = createNodeList(pCxt, releaseRawExprNode(pCxt, B)); }
|
||||||
expression_list(A) ::= expression_list(B) NK_COMMA expression(C). { PARSER_TRACE; A = addNodeToList(pCxt, B, C); }
|
expression_list(A) ::= expression_list(B) NK_COMMA expression(C). { PARSER_TRACE; A = addNodeToList(pCxt, B, releaseRawExprNode(pCxt, C)); }
|
||||||
|
|
||||||
column_reference(A) ::= column_name(B). { PARSER_TRACE; A = createColumnNode(pCxt, NULL, &B); }
|
column_reference(A) ::= column_name(B). { PARSER_TRACE; A = createRawExprNode(pCxt, &B, createColumnNode(pCxt, NULL, &B)); }
|
||||||
column_reference(A) ::= table_name(B) NK_DOT column_name(C). { PARSER_TRACE; A = createColumnNode(pCxt, &B, &C); }
|
column_reference(A) ::= table_name(B) NK_DOT column_name(C). { PARSER_TRACE; A = createRawExprNodeExt(pCxt, &B, &C, createColumnNode(pCxt, &B, &C)); }
|
||||||
|
|
||||||
//pseudo_column(A) ::= NK_NOW. { PARSER_TRACE; A = createFunctionNode(pCxt, NULL, NULL); }
|
//pseudo_column(A) ::= NK_NOW. { PARSER_TRACE; A = createFunctionNode(pCxt, NULL, NULL); }
|
||||||
|
|
||||||
/************************************************ predicate ***********************************************************/
|
/************************************************ predicate ***********************************************************/
|
||||||
predicate(A) ::= expression(B) compare_op(C) expression(D). { PARSER_TRACE; A = createOperatorNode(pCxt, C, B, D); }
|
predicate(A) ::= expression(B) compare_op(C) expression(D). { PARSER_TRACE; A = createOperatorNode(pCxt, C, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, D)); }
|
||||||
//predicate(A) ::= expression(B) compare_op sub_type expression(B).
|
//predicate(A) ::= expression(B) compare_op sub_type expression(B).
|
||||||
predicate(A) ::= expression(B) BETWEEN expression(C) AND expression(D). { PARSER_TRACE; A = createBetweenAnd(pCxt, B, C, D); }
|
predicate(A) ::= expression(B) BETWEEN expression(C) AND expression(D). { PARSER_TRACE; A = createBetweenAnd(pCxt, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, D)); }
|
||||||
predicate(A) ::= expression(B) NOT BETWEEN expression(C) AND expression(D). { PARSER_TRACE; A = createNotBetweenAnd(pCxt, C, B, D); }
|
predicate(A) ::= expression(B) NOT BETWEEN expression(C) AND expression(D). { PARSER_TRACE; A = createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, C), releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, D)); }
|
||||||
predicate(A) ::= expression(B) IS NULL. { PARSER_TRACE; A = createIsNullCondNode(pCxt, B, true); }
|
predicate(A) ::= expression(B) IS NULL. { PARSER_TRACE; A = createIsNullCondNode(pCxt, releaseRawExprNode(pCxt, B), true); }
|
||||||
predicate(A) ::= expression(B) IS NOT NULL. { PARSER_TRACE; A = createIsNullCondNode(pCxt, B, false); }
|
predicate(A) ::= expression(B) IS NOT NULL. { PARSER_TRACE; A = createIsNullCondNode(pCxt, releaseRawExprNode(pCxt, B), false); }
|
||||||
predicate(A) ::= expression(B) in_op(C) in_predicate_value(D). { PARSER_TRACE; A = createOperatorNode(pCxt, C, B, D); }
|
predicate(A) ::= expression(B) in_op(C) in_predicate_value(D). { PARSER_TRACE; A = createOperatorNode(pCxt, C, releaseRawExprNode(pCxt, B), D); }
|
||||||
|
|
||||||
%type compare_op { EOperatorType }
|
%type compare_op { EOperatorType }
|
||||||
%destructor compare_op { PARSER_DESTRUCTOR_TRACE; }
|
%destructor compare_op { PARSER_DESTRUCTOR_TRACE; }
|
||||||
|
@ -186,7 +219,7 @@ table_reference(A) ::= joined_table(B).
|
||||||
|
|
||||||
table_primary(A) ::= table_name(B) alias_opt(C). { PARSER_TRACE; A = createRealTableNode(pCxt, NULL, &B, &C); }
|
table_primary(A) ::= table_name(B) alias_opt(C). { PARSER_TRACE; A = createRealTableNode(pCxt, NULL, &B, &C); }
|
||||||
table_primary(A) ::= db_name(B) NK_DOT table_name(C) alias_opt(D). { PARSER_TRACE; A = createRealTableNode(pCxt, &B, &C, &D); }
|
table_primary(A) ::= db_name(B) NK_DOT table_name(C) alias_opt(D). { PARSER_TRACE; A = createRealTableNode(pCxt, &B, &C, &D); }
|
||||||
table_primary(A) ::= subquery(B) alias_opt(C). { PARSER_TRACE; A = createTempTableNode(pCxt, B, &C); }
|
table_primary(A) ::= subquery(B) alias_opt(C). { PARSER_TRACE; A = createTempTableNode(pCxt, releaseRawExprNode(pCxt, B), &C); }
|
||||||
table_primary(A) ::= parenthesized_joined_table(B). { PARSER_TRACE; A = B; }
|
table_primary(A) ::= parenthesized_joined_table(B). { PARSER_TRACE; A = B; }
|
||||||
|
|
||||||
%type alias_opt { SToken }
|
%type alias_opt { SToken }
|
||||||
|
@ -236,9 +269,13 @@ select_list(A) ::= select_sublist(B).
|
||||||
select_sublist(A) ::= select_item(B). { PARSER_TRACE; 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). { PARSER_TRACE; 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) ::= expression(B). { PARSER_TRACE; A = B; }
|
select_item(A) ::= expression(B). {
|
||||||
select_item(A) ::= expression(B) column_alias(C). { PARSER_TRACE; A = setProjectionAlias(pCxt, B, &C); }
|
PARSER_TRACE;
|
||||||
select_item(A) ::= expression(B) AS column_alias(C). { PARSER_TRACE; A = setProjectionAlias(pCxt, B, &C); }
|
SToken t = getTokenFromRawExprNode(pCxt, B);
|
||||||
|
A = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, B), &t);
|
||||||
|
}
|
||||||
|
select_item(A) ::= expression(B) column_alias(C). { PARSER_TRACE; A = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, B), &C); }
|
||||||
|
select_item(A) ::= expression(B) AS column_alias(C). { PARSER_TRACE; A = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, B), &C); }
|
||||||
select_item(A) ::= table_name(B) NK_DOT NK_STAR(C). { PARSER_TRACE; A = createColumnNode(pCxt, &B, &C); }
|
select_item(A) ::= table_name(B) NK_DOT NK_STAR(C). { PARSER_TRACE; A = createColumnNode(pCxt, &B, &C); }
|
||||||
|
|
||||||
where_clause_opt(A) ::= . { PARSER_TRACE; A = NULL; }
|
where_clause_opt(A) ::= . { PARSER_TRACE; A = NULL; }
|
||||||
|
@ -251,8 +288,8 @@ partition_by_clause_opt(A) ::= PARTITION BY expression_list(B).
|
||||||
|
|
||||||
twindow_clause_opt(A) ::= . { PARSER_TRACE; A = NULL; }
|
twindow_clause_opt(A) ::= . { PARSER_TRACE; A = NULL; }
|
||||||
twindow_clause_opt(A) ::=
|
twindow_clause_opt(A) ::=
|
||||||
SESSION NK_LP column_reference(B) NK_COMMA NK_INTEGER(C) NK_RP. { PARSER_TRACE; A = createSessionWindowNode(pCxt, B, &C); }
|
SESSION NK_LP column_reference(B) NK_COMMA NK_INTEGER(C) NK_RP. { PARSER_TRACE; A = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, B), &C); }
|
||||||
twindow_clause_opt(A) ::= STATE_WINDOW NK_LP column_reference(B) NK_RP. { PARSER_TRACE; A = createStateWindowNode(pCxt, B); }
|
twindow_clause_opt(A) ::= STATE_WINDOW NK_LP column_reference(B) NK_RP. { PARSER_TRACE; A = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, B)); }
|
||||||
twindow_clause_opt(A) ::=
|
twindow_clause_opt(A) ::=
|
||||||
INTERVAL NK_LP duration_literal(B) NK_RP sliding_opt(C) fill_opt(D). { PARSER_TRACE; A = createIntervalWindowNode(pCxt, B, NULL, C, D); }
|
INTERVAL NK_LP duration_literal(B) NK_RP sliding_opt(C) fill_opt(D). { PARSER_TRACE; A = createIntervalWindowNode(pCxt, B, NULL, C, D); }
|
||||||
twindow_clause_opt(A) ::=
|
twindow_clause_opt(A) ::=
|
||||||
|
@ -317,7 +354,7 @@ limit_clause_opt(A) ::= LIMIT NK_INTEGER(B) OFFSET NK_INTEGER(C).
|
||||||
limit_clause_opt(A) ::= LIMIT NK_INTEGER(C) NK_COMMA NK_INTEGER(B). { PARSER_TRACE; A = createLimitNode(pCxt, &B, &C); }
|
limit_clause_opt(A) ::= LIMIT NK_INTEGER(C) NK_COMMA NK_INTEGER(B). { PARSER_TRACE; A = createLimitNode(pCxt, &B, &C); }
|
||||||
|
|
||||||
/************************************************ subquery ************************************************************/
|
/************************************************ subquery ************************************************************/
|
||||||
subquery(A) ::= NK_LP query_expression(B) NK_RP. { PARSER_TRACE; A = B; }
|
subquery(A) ::= NK_LP(B) query_expression(C) NK_RP(D). { PARSER_TRACE; A = createRawExprNodeExt(pCxt, &B, &D, C); }
|
||||||
|
|
||||||
/************************************************ search_condition ****************************************************/
|
/************************************************ search_condition ****************************************************/
|
||||||
search_condition(A) ::= boolean_value_expression(B). { PARSER_TRACE; A = B; }
|
search_condition(A) ::= boolean_value_expression(B). { PARSER_TRACE; A = B; }
|
||||||
|
@ -330,7 +367,7 @@ sort_specification_list(A) ::=
|
||||||
sort_specification_list(B) NK_COMMA sort_specification(C). { PARSER_TRACE; A = addNodeToList(pCxt, B, C); }
|
sort_specification_list(B) NK_COMMA sort_specification(C). { PARSER_TRACE; A = addNodeToList(pCxt, B, C); }
|
||||||
|
|
||||||
sort_specification(A) ::=
|
sort_specification(A) ::=
|
||||||
expression(B) ordering_specification_opt(C) null_ordering_opt(D). { PARSER_TRACE; A = createOrderByExprNode(pCxt, B, C, D); }
|
expression(B) ordering_specification_opt(C) null_ordering_opt(D). { PARSER_TRACE; A = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, B), C, D); }
|
||||||
|
|
||||||
%type ordering_specification_opt EOrder
|
%type ordering_specification_opt EOrder
|
||||||
%destructor ordering_specification_opt { PARSER_DESTRUCTOR_TRACE; }
|
%destructor ordering_specification_opt { PARSER_DESTRUCTOR_TRACE; }
|
||||||
|
|
|
@ -24,6 +24,14 @@
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define CHECK_RAW_EXPR_NODE(node) \
|
||||||
|
do { \
|
||||||
|
if (NULL == (node) || QUERY_NODE_RAW_EXPR != nodeType(node)) { \
|
||||||
|
pCxt->valid = false; \
|
||||||
|
return NULL; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
SToken nil_token = { .type = TK_NIL, .n = 0, .z = NULL };
|
SToken nil_token = { .type = TK_NIL, .n = 0, .z = NULL };
|
||||||
|
|
||||||
static bool checkDbName(SAstCreateContext* pCxt, const SToken* pDbName) {
|
static bool checkDbName(SAstCreateContext* pCxt, const SToken* pDbName) {
|
||||||
|
@ -50,6 +58,37 @@ static bool checkColumnName(SAstCreateContext* pCxt, const SToken* pColumnName)
|
||||||
return pCxt->valid;
|
return pCxt->valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SNode* createRawExprNode(SAstCreateContext* pCxt, const SToken* pToken, SNode* pNode) {
|
||||||
|
SRawExprNode* target = (SRawExprNode*)nodesMakeNode(QUERY_NODE_RAW_EXPR);
|
||||||
|
CHECK_OUT_OF_MEM(target);
|
||||||
|
target->p = pToken->z;
|
||||||
|
target->n = pToken->n;
|
||||||
|
target->pNode = pNode;
|
||||||
|
return (SNode*)target;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const SToken* pEnd, SNode* pNode) {
|
||||||
|
SRawExprNode* target = (SRawExprNode*)nodesMakeNode(QUERY_NODE_RAW_EXPR);
|
||||||
|
CHECK_OUT_OF_MEM(target);
|
||||||
|
target->p = pStart->z;
|
||||||
|
target->n = (pEnd->z + pEnd->n) - pStart->z;
|
||||||
|
target->pNode = pNode;
|
||||||
|
return (SNode*)target;
|
||||||
|
}
|
||||||
|
|
||||||
|
SNode* releaseRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
|
||||||
|
CHECK_RAW_EXPR_NODE(pNode);
|
||||||
|
SNode* tmp = ((SRawExprNode*)pNode)->pNode;
|
||||||
|
tfree(pNode);
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
|
||||||
|
SRawExprNode* target = (SRawExprNode*)pNode;
|
||||||
|
SToken t = { .type = 0, .z = target->p, .n = target->n};
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode) {
|
SNodeList* createNodeList(SAstCreateContext* pCxt, SNode* pNode) {
|
||||||
SNodeList* list = nodesMakeList();
|
SNodeList* list = nodesMakeList();
|
||||||
CHECK_OUT_OF_MEM(list);
|
CHECK_OUT_OF_MEM(list);
|
||||||
|
@ -86,7 +125,7 @@ SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken*
|
||||||
SNode* createDurationValueNode(SAstCreateContext* pCxt, const SToken* pLiteral) {
|
SNode* createDurationValueNode(SAstCreateContext* pCxt, const SToken* pLiteral) {
|
||||||
SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||||
CHECK_OUT_OF_MEM(val);
|
CHECK_OUT_OF_MEM(val);
|
||||||
// todo
|
// todo : calc, for example, 10s
|
||||||
return (SNode*)val;
|
return (SNode*)val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1517,23 +1517,24 @@ static YYACTIONTYPE yy_reduce(
|
||||||
{ PARSER_TRACE; pCxt->pRootNode = yymsp[0].minor.yy168; }
|
{ PARSER_TRACE; pCxt->pRootNode = yymsp[0].minor.yy168; }
|
||||||
break;
|
break;
|
||||||
case 2: /* literal ::= NK_INTEGER */
|
case 2: /* literal ::= NK_INTEGER */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &yymsp[0].minor.yy0)); }
|
||||||
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 3: /* literal ::= NK_FLOAT */
|
case 3: /* literal ::= NK_FLOAT */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_DOUBLE, &yymsp[0].minor.yy0)); }
|
||||||
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 4: /* literal ::= NK_STRING */
|
case 4: /* literal ::= NK_STRING */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &yymsp[0].minor.yy0)); }
|
||||||
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 5: /* literal ::= NK_BOOL */
|
case 5: /* literal ::= NK_BOOL */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_BOOL, &yymsp[0].minor.yy0)); }
|
||||||
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 6: /* literal ::= TIMESTAMP NK_STRING */
|
case 6: /* literal ::= TIMESTAMP NK_STRING */
|
||||||
{ PARSER_TRACE; yymsp[-1].minor.yy168 = createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &yymsp[0].minor.yy0, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &yymsp[0].minor.yy0)); }
|
||||||
|
yymsp[-1].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 7: /* literal ::= duration_literal */
|
case 7: /* literal ::= duration_literal */
|
||||||
case 17: /* expression ::= literal */ yytestcase(yyruleno==17);
|
case 17: /* expression ::= literal */ yytestcase(yyruleno==17);
|
||||||
|
@ -1545,7 +1546,6 @@ static YYACTIONTYPE yy_reduce(
|
||||||
case 61: /* table_reference ::= table_primary */ yytestcase(yyruleno==61);
|
case 61: /* table_reference ::= table_primary */ yytestcase(yyruleno==61);
|
||||||
case 62: /* table_reference ::= joined_table */ yytestcase(yyruleno==62);
|
case 62: /* table_reference ::= joined_table */ yytestcase(yyruleno==62);
|
||||||
case 66: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==66);
|
case 66: /* table_primary ::= parenthesized_joined_table */ yytestcase(yyruleno==66);
|
||||||
case 82: /* select_item ::= expression */ yytestcase(yyruleno==82);
|
|
||||||
case 110: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==110);
|
case 110: /* query_expression_body ::= query_primary */ yytestcase(yyruleno==110);
|
||||||
case 112: /* query_primary ::= query_specification */ yytestcase(yyruleno==112);
|
case 112: /* query_primary ::= query_specification */ yytestcase(yyruleno==112);
|
||||||
case 124: /* search_condition ::= boolean_value_expression */ yytestcase(yyruleno==124);
|
case 124: /* search_condition ::= boolean_value_expression */ yytestcase(yyruleno==124);
|
||||||
|
@ -1553,21 +1553,17 @@ static YYACTIONTYPE yy_reduce(
|
||||||
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 8: /* duration_literal ::= NK_VARIABLE */
|
case 8: /* duration_literal ::= NK_VARIABLE */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createDurationValueNode(pCxt, &yymsp[0].minor.yy0); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createRawExprNode(pCxt, &yymsp[0].minor.yy0, createDurationValueNode(pCxt, &yymsp[0].minor.yy0)); }
|
||||||
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 9: /* literal_list ::= literal */
|
case 9: /* literal_list ::= literal */
|
||||||
case 29: /* expression_list ::= expression */ yytestcase(yyruleno==29);
|
case 29: /* expression_list ::= expression */ yytestcase(yyruleno==29);
|
||||||
case 80: /* select_sublist ::= select_item */ yytestcase(yyruleno==80);
|
{ PARSER_TRACE; yylhsminor.yy192 = createNodeList(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy168)); }
|
||||||
case 125: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==125);
|
|
||||||
{ PARSER_TRACE; yylhsminor.yy192 = createNodeList(pCxt, yymsp[0].minor.yy168); }
|
|
||||||
yymsp[0].minor.yy192 = yylhsminor.yy192;
|
yymsp[0].minor.yy192 = yylhsminor.yy192;
|
||||||
break;
|
break;
|
||||||
case 10: /* literal_list ::= literal_list NK_COMMA literal */
|
case 10: /* literal_list ::= literal_list NK_COMMA literal */
|
||||||
case 30: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==30);
|
case 30: /* expression_list ::= expression_list NK_COMMA expression */ yytestcase(yyruleno==30);
|
||||||
case 81: /* select_sublist ::= select_sublist NK_COMMA select_item */ yytestcase(yyruleno==81);
|
{ PARSER_TRACE; yylhsminor.yy192 = addNodeToList(pCxt, yymsp[-2].minor.yy192, releaseRawExprNode(pCxt, yymsp[0].minor.yy168)); }
|
||||||
case 126: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==126);
|
|
||||||
{ PARSER_TRACE; yylhsminor.yy192 = addNodeToList(pCxt, yymsp[-2].minor.yy192, yymsp[0].minor.yy168); }
|
|
||||||
yymsp[-2].minor.yy192 = yylhsminor.yy192;
|
yymsp[-2].minor.yy192 = yylhsminor.yy192;
|
||||||
break;
|
break;
|
||||||
case 11: /* db_name ::= NK_ID */
|
case 11: /* db_name ::= NK_ID */
|
||||||
|
@ -1580,74 +1576,106 @@ static YYACTIONTYPE yy_reduce(
|
||||||
yymsp[0].minor.yy241 = yylhsminor.yy241;
|
yymsp[0].minor.yy241 = yylhsminor.yy241;
|
||||||
break;
|
break;
|
||||||
case 19: /* expression ::= function_name NK_LP expression_list NK_RP */
|
case 19: /* expression ::= function_name NK_LP expression_list NK_RP */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createFunctionNode(pCxt, &yymsp[-3].minor.yy241, yymsp[-1].minor.yy192); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createRawExprNodeExt(pCxt, &yymsp[-3].minor.yy241, &yymsp[0].minor.yy0, createFunctionNode(pCxt, &yymsp[-3].minor.yy241, yymsp[-1].minor.yy192)); }
|
||||||
yymsp[-3].minor.yy168 = yylhsminor.yy168;
|
yymsp[-3].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 21: /* expression ::= NK_LP expression NK_RP */
|
case 21: /* expression ::= NK_LP expression NK_RP */
|
||||||
case 57: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */ yytestcase(yyruleno==57);
|
{ PARSER_TRACE; yylhsminor.yy168 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, releaseRawExprNode(pCxt, yymsp[-1].minor.yy168)); }
|
||||||
case 70: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ yytestcase(yyruleno==70);
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
case 71: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==71);
|
|
||||||
case 123: /* subquery ::= NK_LP query_expression NK_RP */ yytestcase(yyruleno==123);
|
|
||||||
{ PARSER_TRACE; yymsp[-2].minor.yy168 = yymsp[-1].minor.yy168; }
|
|
||||||
break;
|
break;
|
||||||
case 22: /* expression ::= NK_PLUS expression */
|
case 22: /* expression ::= NK_PLUS expression */
|
||||||
case 58: /* from_clause ::= FROM table_reference_list */ yytestcase(yyruleno==58);
|
{
|
||||||
case 87: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==87);
|
PARSER_TRACE;
|
||||||
case 108: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==108);
|
SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy168);
|
||||||
{ PARSER_TRACE; yymsp[-1].minor.yy168 = yymsp[0].minor.yy168; }
|
yylhsminor.yy168 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, releaseRawExprNode(pCxt, yymsp[0].minor.yy168));
|
||||||
|
}
|
||||||
|
yymsp[-1].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 23: /* expression ::= NK_MINUS expression */
|
case 23: /* expression ::= NK_MINUS expression */
|
||||||
{ PARSER_TRACE; yymsp[-1].minor.yy168 = createOperatorNode(pCxt, OP_TYPE_SUB, yymsp[0].minor.yy168, NULL); }
|
{
|
||||||
|
PARSER_TRACE;
|
||||||
|
SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy168);
|
||||||
|
yylhsminor.yy168 = createRawExprNodeExt(pCxt, &yymsp[-1].minor.yy0, &t, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[0].minor.yy168), NULL));
|
||||||
|
}
|
||||||
|
yymsp[-1].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 24: /* expression ::= expression NK_PLUS expression */
|
case 24: /* expression ::= expression NK_PLUS expression */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createOperatorNode(pCxt, OP_TYPE_ADD, yymsp[-2].minor.yy168, yymsp[0].minor.yy168); }
|
{
|
||||||
|
PARSER_TRACE;
|
||||||
|
SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy168);
|
||||||
|
SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy168);
|
||||||
|
yylhsminor.yy168 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_ADD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy168), releaseRawExprNode(pCxt, yymsp[0].minor.yy168)));
|
||||||
|
}
|
||||||
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 25: /* expression ::= expression NK_MINUS expression */
|
case 25: /* expression ::= expression NK_MINUS expression */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createOperatorNode(pCxt, OP_TYPE_SUB, yymsp[-2].minor.yy168, yymsp[0].minor.yy168); }
|
{
|
||||||
|
PARSER_TRACE;
|
||||||
|
SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy168);
|
||||||
|
SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy168);
|
||||||
|
yylhsminor.yy168 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_SUB, releaseRawExprNode(pCxt, yymsp[-2].minor.yy168), releaseRawExprNode(pCxt, yymsp[0].minor.yy168)));
|
||||||
|
}
|
||||||
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 26: /* expression ::= expression NK_STAR expression */
|
case 26: /* expression ::= expression NK_STAR expression */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createOperatorNode(pCxt, OP_TYPE_MULTI, yymsp[-2].minor.yy168, yymsp[0].minor.yy168); }
|
{
|
||||||
|
PARSER_TRACE;
|
||||||
|
SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy168);
|
||||||
|
SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy168);
|
||||||
|
yylhsminor.yy168 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MULTI, releaseRawExprNode(pCxt, yymsp[-2].minor.yy168), releaseRawExprNode(pCxt, yymsp[0].minor.yy168)));
|
||||||
|
}
|
||||||
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 27: /* expression ::= expression NK_SLASH expression */
|
case 27: /* expression ::= expression NK_SLASH expression */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createOperatorNode(pCxt, OP_TYPE_DIV, yymsp[-2].minor.yy168, yymsp[0].minor.yy168); }
|
{
|
||||||
|
PARSER_TRACE;
|
||||||
|
SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy168);
|
||||||
|
SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy168);
|
||||||
|
yylhsminor.yy168 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_DIV, releaseRawExprNode(pCxt, yymsp[-2].minor.yy168), releaseRawExprNode(pCxt, yymsp[0].minor.yy168)));
|
||||||
|
}
|
||||||
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 28: /* expression ::= expression NK_REM expression */
|
case 28: /* expression ::= expression NK_REM expression */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createOperatorNode(pCxt, OP_TYPE_MOD, yymsp[-2].minor.yy168, yymsp[0].minor.yy168); }
|
{
|
||||||
|
PARSER_TRACE;
|
||||||
|
SToken s = getTokenFromRawExprNode(pCxt, yymsp[-2].minor.yy168);
|
||||||
|
SToken e = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy168);
|
||||||
|
yylhsminor.yy168 = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, yymsp[-2].minor.yy168), releaseRawExprNode(pCxt, yymsp[0].minor.yy168)));
|
||||||
|
}
|
||||||
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 31: /* column_reference ::= column_name */
|
case 31: /* column_reference ::= column_name */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createColumnNode(pCxt, NULL, &yymsp[0].minor.yy241); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createRawExprNode(pCxt, &yymsp[0].minor.yy241, createColumnNode(pCxt, NULL, &yymsp[0].minor.yy241)); }
|
||||||
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 32: /* column_reference ::= table_name NK_DOT column_name */
|
case 32: /* column_reference ::= table_name NK_DOT column_name */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createColumnNode(pCxt, &yymsp[-2].minor.yy241, &yymsp[0].minor.yy241); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy241, &yymsp[0].minor.yy241, createColumnNode(pCxt, &yymsp[-2].minor.yy241, &yymsp[0].minor.yy241)); }
|
||||||
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 33: /* predicate ::= expression compare_op expression */
|
case 33: /* predicate ::= expression compare_op expression */
|
||||||
case 38: /* predicate ::= expression in_op in_predicate_value */ yytestcase(yyruleno==38);
|
{ PARSER_TRACE; yylhsminor.yy168 = createOperatorNode(pCxt, yymsp[-1].minor.yy228, releaseRawExprNode(pCxt, yymsp[-2].minor.yy168), releaseRawExprNode(pCxt, yymsp[0].minor.yy168)); }
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createOperatorNode(pCxt, yymsp[-1].minor.yy228, yymsp[-2].minor.yy168, yymsp[0].minor.yy168); }
|
|
||||||
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 34: /* predicate ::= expression BETWEEN expression AND expression */
|
case 34: /* predicate ::= expression BETWEEN expression AND expression */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createBetweenAnd(pCxt, yymsp[-4].minor.yy168, yymsp[-2].minor.yy168, yymsp[0].minor.yy168); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-4].minor.yy168), releaseRawExprNode(pCxt, yymsp[-2].minor.yy168), releaseRawExprNode(pCxt, yymsp[0].minor.yy168)); }
|
||||||
yymsp[-4].minor.yy168 = yylhsminor.yy168;
|
yymsp[-4].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 35: /* predicate ::= expression NOT BETWEEN expression AND expression */
|
case 35: /* predicate ::= expression NOT BETWEEN expression AND expression */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createNotBetweenAnd(pCxt, yymsp[-2].minor.yy168, yymsp[-5].minor.yy168, yymsp[0].minor.yy168); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createNotBetweenAnd(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy168), releaseRawExprNode(pCxt, yymsp[-5].minor.yy168), releaseRawExprNode(pCxt, yymsp[0].minor.yy168)); }
|
||||||
yymsp[-5].minor.yy168 = yylhsminor.yy168;
|
yymsp[-5].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 36: /* predicate ::= expression IS NULL */
|
case 36: /* predicate ::= expression IS NULL */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createIsNullCondNode(pCxt, yymsp[-2].minor.yy168, true); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createIsNullCondNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy168), true); }
|
||||||
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 37: /* predicate ::= expression IS NOT NULL */
|
case 37: /* predicate ::= expression IS NOT NULL */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createIsNullCondNode(pCxt, yymsp[-3].minor.yy168, false); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createIsNullCondNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy168), false); }
|
||||||
yymsp[-3].minor.yy168 = yylhsminor.yy168;
|
yymsp[-3].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
|
case 38: /* predicate ::= expression in_op in_predicate_value */
|
||||||
|
{ PARSER_TRACE; yylhsminor.yy168 = createOperatorNode(pCxt, yymsp[-1].minor.yy228, releaseRawExprNode(pCxt, yymsp[-2].minor.yy168), yymsp[0].minor.yy168); }
|
||||||
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
|
break;
|
||||||
case 39: /* compare_op ::= NK_LT */
|
case 39: /* compare_op ::= NK_LT */
|
||||||
{ PARSER_TRACE; yymsp[0].minor.yy228 = OP_TYPE_LOWER_THAN; }
|
{ PARSER_TRACE; yymsp[0].minor.yy228 = OP_TYPE_LOWER_THAN; }
|
||||||
break;
|
break;
|
||||||
|
@ -1698,6 +1726,16 @@ static YYACTIONTYPE yy_reduce(
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, yymsp[-2].minor.yy168, yymsp[0].minor.yy168); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createLogicConditionNode(pCxt, LOGIC_COND_TYPE_AND, yymsp[-2].minor.yy168, yymsp[0].minor.yy168); }
|
||||||
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
|
case 57: /* boolean_primary ::= NK_LP boolean_value_expression NK_RP */
|
||||||
|
case 70: /* parenthesized_joined_table ::= NK_LP joined_table NK_RP */ yytestcase(yyruleno==70);
|
||||||
|
case 71: /* parenthesized_joined_table ::= NK_LP parenthesized_joined_table NK_RP */ yytestcase(yyruleno==71);
|
||||||
|
{ PARSER_TRACE; yymsp[-2].minor.yy168 = yymsp[-1].minor.yy168; }
|
||||||
|
break;
|
||||||
|
case 58: /* from_clause ::= FROM table_reference_list */
|
||||||
|
case 87: /* where_clause_opt ::= WHERE search_condition */ yytestcase(yyruleno==87);
|
||||||
|
case 108: /* having_clause_opt ::= HAVING search_condition */ yytestcase(yyruleno==108);
|
||||||
|
{ PARSER_TRACE; yymsp[-1].minor.yy168 = yymsp[0].minor.yy168; }
|
||||||
|
break;
|
||||||
case 60: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */
|
case 60: /* table_reference_list ::= table_reference_list NK_COMMA table_reference */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy168, yymsp[0].minor.yy168, NULL); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createJoinTableNode(pCxt, JOIN_TYPE_INNER, yymsp[-2].minor.yy168, yymsp[0].minor.yy168, NULL); }
|
||||||
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
|
@ -1711,7 +1749,7 @@ static YYACTIONTYPE yy_reduce(
|
||||||
yymsp[-3].minor.yy168 = yylhsminor.yy168;
|
yymsp[-3].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 65: /* table_primary ::= subquery alias_opt */
|
case 65: /* table_primary ::= subquery alias_opt */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createTempTableNode(pCxt, yymsp[-1].minor.yy168, &yymsp[0].minor.yy241); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createTempTableNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy168), &yymsp[0].minor.yy241); }
|
||||||
yymsp[-1].minor.yy168 = yylhsminor.yy168;
|
yymsp[-1].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 67: /* alias_opt ::= */
|
case 67: /* alias_opt ::= */
|
||||||
|
@ -1758,12 +1796,30 @@ static YYACTIONTYPE yy_reduce(
|
||||||
{ PARSER_TRACE; yylhsminor.yy192 = yymsp[0].minor.yy192; }
|
{ PARSER_TRACE; yylhsminor.yy192 = yymsp[0].minor.yy192; }
|
||||||
yymsp[0].minor.yy192 = yylhsminor.yy192;
|
yymsp[0].minor.yy192 = yylhsminor.yy192;
|
||||||
break;
|
break;
|
||||||
|
case 80: /* select_sublist ::= select_item */
|
||||||
|
case 125: /* sort_specification_list ::= sort_specification */ yytestcase(yyruleno==125);
|
||||||
|
{ PARSER_TRACE; yylhsminor.yy192 = createNodeList(pCxt, yymsp[0].minor.yy168); }
|
||||||
|
yymsp[0].minor.yy192 = yylhsminor.yy192;
|
||||||
|
break;
|
||||||
|
case 81: /* select_sublist ::= select_sublist NK_COMMA select_item */
|
||||||
|
case 126: /* sort_specification_list ::= sort_specification_list NK_COMMA sort_specification */ yytestcase(yyruleno==126);
|
||||||
|
{ PARSER_TRACE; yylhsminor.yy192 = addNodeToList(pCxt, yymsp[-2].minor.yy192, yymsp[0].minor.yy168); }
|
||||||
|
yymsp[-2].minor.yy192 = yylhsminor.yy192;
|
||||||
|
break;
|
||||||
|
case 82: /* select_item ::= expression */
|
||||||
|
{
|
||||||
|
PARSER_TRACE;
|
||||||
|
SToken t = getTokenFromRawExprNode(pCxt, yymsp[0].minor.yy168);
|
||||||
|
yylhsminor.yy168 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[0].minor.yy168), &t);
|
||||||
|
}
|
||||||
|
yymsp[0].minor.yy168 = yylhsminor.yy168;
|
||||||
|
break;
|
||||||
case 83: /* select_item ::= expression column_alias */
|
case 83: /* select_item ::= expression column_alias */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = setProjectionAlias(pCxt, yymsp[-1].minor.yy168, &yymsp[0].minor.yy241); }
|
{ PARSER_TRACE; yylhsminor.yy168 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy168), &yymsp[0].minor.yy241); }
|
||||||
yymsp[-1].minor.yy168 = yylhsminor.yy168;
|
yymsp[-1].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 84: /* select_item ::= expression AS column_alias */
|
case 84: /* select_item ::= expression AS column_alias */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = setProjectionAlias(pCxt, yymsp[-2].minor.yy168, &yymsp[0].minor.yy241); }
|
{ PARSER_TRACE; yylhsminor.yy168 = setProjectionAlias(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy168), &yymsp[0].minor.yy241); }
|
||||||
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 85: /* select_item ::= table_name NK_DOT NK_STAR */
|
case 85: /* select_item ::= table_name NK_DOT NK_STAR */
|
||||||
|
@ -1790,10 +1846,10 @@ static YYACTIONTYPE yy_reduce(
|
||||||
{ PARSER_TRACE; yymsp[-2].minor.yy192 = yymsp[0].minor.yy192; }
|
{ PARSER_TRACE; yymsp[-2].minor.yy192 = yymsp[0].minor.yy192; }
|
||||||
break;
|
break;
|
||||||
case 91: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP */
|
case 91: /* twindow_clause_opt ::= SESSION NK_LP column_reference NK_COMMA NK_INTEGER NK_RP */
|
||||||
{ PARSER_TRACE; yymsp[-5].minor.yy168 = createSessionWindowNode(pCxt, yymsp[-3].minor.yy168, &yymsp[-1].minor.yy0); }
|
{ PARSER_TRACE; yymsp[-5].minor.yy168 = createSessionWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-3].minor.yy168), &yymsp[-1].minor.yy0); }
|
||||||
break;
|
break;
|
||||||
case 92: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */
|
case 92: /* twindow_clause_opt ::= STATE_WINDOW NK_LP column_reference NK_RP */
|
||||||
{ PARSER_TRACE; yymsp[-3].minor.yy168 = createStateWindowNode(pCxt, yymsp[-1].minor.yy168); }
|
{ PARSER_TRACE; yymsp[-3].minor.yy168 = createStateWindowNode(pCxt, releaseRawExprNode(pCxt, yymsp[-1].minor.yy168)); }
|
||||||
break;
|
break;
|
||||||
case 93: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */
|
case 93: /* twindow_clause_opt ::= INTERVAL NK_LP duration_literal NK_RP sliding_opt fill_opt */
|
||||||
{ PARSER_TRACE; yymsp[-5].minor.yy168 = createIntervalWindowNode(pCxt, yymsp[-3].minor.yy168, NULL, yymsp[-1].minor.yy168, yymsp[0].minor.yy168); }
|
{ PARSER_TRACE; yymsp[-5].minor.yy168 = createIntervalWindowNode(pCxt, yymsp[-3].minor.yy168, NULL, yymsp[-1].minor.yy168, yymsp[0].minor.yy168); }
|
||||||
|
@ -1850,8 +1906,12 @@ static YYACTIONTYPE yy_reduce(
|
||||||
case 122: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==122);
|
case 122: /* limit_clause_opt ::= LIMIT NK_INTEGER NK_COMMA NK_INTEGER */ yytestcase(yyruleno==122);
|
||||||
{ PARSER_TRACE; yymsp[-3].minor.yy168 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); }
|
{ PARSER_TRACE; yymsp[-3].minor.yy168 = createLimitNode(pCxt, &yymsp[0].minor.yy0, &yymsp[-2].minor.yy0); }
|
||||||
break;
|
break;
|
||||||
|
case 123: /* subquery ::= NK_LP query_expression NK_RP */
|
||||||
|
{ PARSER_TRACE; yylhsminor.yy168 = createRawExprNodeExt(pCxt, &yymsp[-2].minor.yy0, &yymsp[0].minor.yy0, yymsp[-1].minor.yy168); }
|
||||||
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
|
break;
|
||||||
case 127: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */
|
case 127: /* sort_specification ::= expression ordering_specification_opt null_ordering_opt */
|
||||||
{ PARSER_TRACE; yylhsminor.yy168 = createOrderByExprNode(pCxt, yymsp[-2].minor.yy168, yymsp[-1].minor.yy10, yymsp[0].minor.yy177); }
|
{ PARSER_TRACE; yylhsminor.yy168 = createOrderByExprNode(pCxt, releaseRawExprNode(pCxt, yymsp[-2].minor.yy168), yymsp[-1].minor.yy10, yymsp[0].minor.yy177); }
|
||||||
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
yymsp[-2].minor.yy168 = yylhsminor.yy168;
|
||||||
break;
|
break;
|
||||||
case 128: /* ordering_specification_opt ::= */
|
case 128: /* ordering_specification_opt ::= */
|
||||||
|
|
|
@ -75,6 +75,35 @@ static bool walkNode(SNode* pNode, ETraversalOrder order, FQueryNodeWalker walke
|
||||||
case QUERY_NODE_ORDER_BY_EXPR:
|
case QUERY_NODE_ORDER_BY_EXPR:
|
||||||
res = walkNode(((SOrderByExprNode*)pNode)->pExpr, order, walker, pContext);
|
res = walkNode(((SOrderByExprNode*)pNode)->pExpr, order, walker, pContext);
|
||||||
break;
|
break;
|
||||||
|
case QUERY_NODE_STATE_WINDOW:
|
||||||
|
res = walkNode(((SStateWindowNode*)pNode)->pCol, order, walker, pContext);
|
||||||
|
break;
|
||||||
|
case QUERY_NODE_SESSION_WINDOW:
|
||||||
|
res = walkNode(((SSessionWindowNode*)pNode)->pCol, order, walker, pContext);
|
||||||
|
break;
|
||||||
|
case QUERY_NODE_INTERVAL_WINDOW: {
|
||||||
|
SIntervalWindowNode* pInterval = (SIntervalWindowNode*)pNode;
|
||||||
|
res = walkNode(pInterval->pInterval, order, walker, pContext);
|
||||||
|
if (res) {
|
||||||
|
res = walkNode(pInterval->pOffset, order, walker, pContext);
|
||||||
|
}
|
||||||
|
if (res) {
|
||||||
|
res = walkNode(pInterval->pSliding, order, walker, pContext);
|
||||||
|
}
|
||||||
|
if (res) {
|
||||||
|
res = walkNode(pInterval->pFill, order, walker, pContext);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case QUERY_NODE_NODE_LIST:
|
||||||
|
res = walkList(((SNodeListNode*)pNode)->pNodeList, order, walker, pContext);
|
||||||
|
break;
|
||||||
|
case QUERY_NODE_FILL:
|
||||||
|
res = walkNode(((SFillNode*)pNode)->pValues, order, walker, pContext);
|
||||||
|
break;
|
||||||
|
case QUERY_NODE_RAW_EXPR:
|
||||||
|
res = walkNode(((SRawExprNode*)pNode)->pNode, order, walker, pContext);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,12 @@ SNode* nodesMakeNode(ENodeType type) {
|
||||||
return makeNode(type, sizeof(SSessionWindowNode));
|
return makeNode(type, sizeof(SSessionWindowNode));
|
||||||
case QUERY_NODE_INTERVAL_WINDOW:
|
case QUERY_NODE_INTERVAL_WINDOW:
|
||||||
return makeNode(type, sizeof(SIntervalWindowNode));
|
return makeNode(type, sizeof(SIntervalWindowNode));
|
||||||
|
case QUERY_NODE_NODE_LIST:
|
||||||
|
return makeNode(type, sizeof(SNodeListNode));
|
||||||
|
case QUERY_NODE_FILL:
|
||||||
|
return makeNode(type, sizeof(SFillNode));
|
||||||
|
case QUERY_NODE_RAW_EXPR:
|
||||||
|
return makeNode(type, sizeof(SRawExprNode));
|
||||||
case QUERY_NODE_SET_OPERATOR:
|
case QUERY_NODE_SET_OPERATOR:
|
||||||
return makeNode(type, sizeof(SSetOperator));
|
return makeNode(type, sizeof(SSetOperator));
|
||||||
case QUERY_NODE_SELECT_STMT:
|
case QUERY_NODE_SELECT_STMT:
|
||||||
|
@ -74,7 +80,7 @@ static bool destroyNode(SNode* pNode, void* pContext) {
|
||||||
switch (nodeType(pNode)) {
|
switch (nodeType(pNode)) {
|
||||||
case QUERY_NODE_VALUE:
|
case QUERY_NODE_VALUE:
|
||||||
tfree(((SValueNode*)pNode)->literal);
|
tfree(((SValueNode*)pNode)->literal);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue