TD-2571
This commit is contained in:
parent
72719cc686
commit
5342e859f7
|
@ -16,105 +16,106 @@
|
||||||
#ifndef TDENGINE_TTOKENDEF_H
|
#ifndef TDENGINE_TTOKENDEF_H
|
||||||
#define TDENGINE_TTOKENDEF_H
|
#define TDENGINE_TTOKENDEF_H
|
||||||
|
|
||||||
#define TK_ID 1
|
|
||||||
#define TK_BOOL 2
|
#define TK_ID 1
|
||||||
#define TK_TINYINT 3
|
#define TK_BOOL 2
|
||||||
#define TK_SMALLINT 4
|
#define TK_TINYINT 3
|
||||||
#define TK_INTEGER 5
|
#define TK_SMALLINT 4
|
||||||
#define TK_BIGINT 6
|
#define TK_INTEGER 5
|
||||||
#define TK_FLOAT 7
|
#define TK_BIGINT 6
|
||||||
#define TK_DOUBLE 8
|
#define TK_FLOAT 7
|
||||||
#define TK_STRING 9
|
#define TK_DOUBLE 8
|
||||||
#define TK_TIMESTAMP 10
|
#define TK_STRING 9
|
||||||
#define TK_BINARY 11
|
#define TK_TIMESTAMP 10
|
||||||
#define TK_NCHAR 12
|
#define TK_BINARY 11
|
||||||
#define TK_OR 13
|
#define TK_NCHAR 12
|
||||||
#define TK_AND 14
|
#define TK_OR 13
|
||||||
#define TK_NOT 15
|
#define TK_AND 14
|
||||||
#define TK_EQ 16
|
#define TK_NOT 15
|
||||||
#define TK_NE 17
|
#define TK_EQ 16
|
||||||
#define TK_ISNULL 18
|
#define TK_NE 17
|
||||||
#define TK_NOTNULL 19
|
#define TK_ISNULL 18
|
||||||
#define TK_IS 20
|
#define TK_NOTNULL 19
|
||||||
#define TK_LIKE 21
|
#define TK_IS 20
|
||||||
#define TK_GLOB 22
|
#define TK_LIKE 21
|
||||||
#define TK_BETWEEN 23
|
#define TK_GLOB 22
|
||||||
#define TK_IN 24
|
#define TK_BETWEEN 23
|
||||||
#define TK_GT 25
|
#define TK_IN 24
|
||||||
#define TK_GE 26
|
#define TK_GT 25
|
||||||
#define TK_LT 27
|
#define TK_GE 26
|
||||||
#define TK_LE 28
|
#define TK_LT 27
|
||||||
#define TK_BITAND 29
|
#define TK_LE 28
|
||||||
#define TK_BITOR 30
|
#define TK_BITAND 29
|
||||||
#define TK_LSHIFT 31
|
#define TK_BITOR 30
|
||||||
#define TK_RSHIFT 32
|
#define TK_LSHIFT 31
|
||||||
#define TK_PLUS 33
|
#define TK_RSHIFT 32
|
||||||
#define TK_MINUS 34
|
#define TK_PLUS 33
|
||||||
#define TK_DIVIDE 35
|
#define TK_MINUS 34
|
||||||
#define TK_TIMES 36
|
#define TK_DIVIDE 35
|
||||||
#define TK_STAR 37
|
#define TK_TIMES 36
|
||||||
#define TK_SLASH 38
|
#define TK_STAR 37
|
||||||
#define TK_REM 39
|
#define TK_SLASH 38
|
||||||
#define TK_CONCAT 40
|
#define TK_REM 39
|
||||||
#define TK_UMINUS 41
|
#define TK_CONCAT 40
|
||||||
#define TK_UPLUS 42
|
#define TK_UMINUS 41
|
||||||
#define TK_BITNOT 43
|
#define TK_UPLUS 42
|
||||||
#define TK_SHOW 44
|
#define TK_BITNOT 43
|
||||||
#define TK_DATABASES 45
|
#define TK_SHOW 44
|
||||||
#define TK_MNODES 46
|
#define TK_DATABASES 45
|
||||||
#define TK_DNODES 47
|
#define TK_MNODES 46
|
||||||
#define TK_ACCOUNTS 48
|
#define TK_DNODES 47
|
||||||
#define TK_USERS 49
|
#define TK_ACCOUNTS 48
|
||||||
#define TK_MODULES 50
|
#define TK_USERS 49
|
||||||
#define TK_QUERIES 51
|
#define TK_MODULES 50
|
||||||
#define TK_CONNECTIONS 52
|
#define TK_QUERIES 51
|
||||||
#define TK_STREAMS 53
|
#define TK_CONNECTIONS 52
|
||||||
#define TK_VARIABLES 54
|
#define TK_STREAMS 53
|
||||||
#define TK_SCORES 55
|
#define TK_VARIABLES 54
|
||||||
#define TK_GRANTS 56
|
#define TK_SCORES 55
|
||||||
#define TK_VNODES 57
|
#define TK_GRANTS 56
|
||||||
#define TK_IPTOKEN 58
|
#define TK_VNODES 57
|
||||||
#define TK_DOT 59
|
#define TK_IPTOKEN 58
|
||||||
#define TK_CREATE 60
|
#define TK_DOT 59
|
||||||
#define TK_TABLE 61
|
#define TK_CREATE 60
|
||||||
#define TK_DATABASE 62
|
#define TK_TABLE 61
|
||||||
#define TK_TABLES 63
|
#define TK_DATABASE 62
|
||||||
#define TK_STABLES 64
|
#define TK_TABLES 63
|
||||||
#define TK_VGROUPS 65
|
#define TK_STABLES 64
|
||||||
#define TK_DROP 66
|
#define TK_VGROUPS 65
|
||||||
#define TK_DNODE 67
|
#define TK_DROP 66
|
||||||
#define TK_USER 68
|
#define TK_DNODE 67
|
||||||
#define TK_ACCOUNT 69
|
#define TK_USER 68
|
||||||
#define TK_USE 70
|
#define TK_ACCOUNT 69
|
||||||
#define TK_DESCRIBE 71
|
#define TK_USE 70
|
||||||
#define TK_ALTER 72
|
#define TK_DESCRIBE 71
|
||||||
#define TK_PASS 73
|
#define TK_ALTER 72
|
||||||
#define TK_PRIVILEGE 74
|
#define TK_PASS 73
|
||||||
#define TK_LOCAL 75
|
#define TK_PRIVILEGE 74
|
||||||
#define TK_IF 76
|
#define TK_LOCAL 75
|
||||||
#define TK_EXISTS 77
|
#define TK_IF 76
|
||||||
#define TK_PPS 78
|
#define TK_EXISTS 77
|
||||||
#define TK_TSERIES 79
|
#define TK_PPS 78
|
||||||
#define TK_DBS 80
|
#define TK_TSERIES 79
|
||||||
#define TK_STORAGE 81
|
#define TK_DBS 80
|
||||||
#define TK_QTIME 82
|
#define TK_STORAGE 81
|
||||||
#define TK_CONNS 83
|
#define TK_QTIME 82
|
||||||
#define TK_STATE 84
|
#define TK_CONNS 83
|
||||||
#define TK_KEEP 85
|
#define TK_STATE 84
|
||||||
#define TK_CACHE 86
|
#define TK_KEEP 85
|
||||||
#define TK_REPLICA 87
|
#define TK_CACHE 86
|
||||||
#define TK_QUORUM 88
|
#define TK_REPLICA 87
|
||||||
#define TK_DAYS 89
|
#define TK_QUORUM 88
|
||||||
#define TK_MINROWS 90
|
#define TK_DAYS 89
|
||||||
#define TK_MAXROWS 91
|
#define TK_MINROWS 90
|
||||||
#define TK_BLOCKS 92
|
#define TK_MAXROWS 91
|
||||||
#define TK_CTIME 93
|
#define TK_BLOCKS 92
|
||||||
#define TK_WAL 94
|
#define TK_CTIME 93
|
||||||
#define TK_FSYNC 95
|
#define TK_WAL 94
|
||||||
#define TK_COMP 96
|
#define TK_FSYNC 95
|
||||||
#define TK_PRECISION 97
|
#define TK_COMP 96
|
||||||
#define TK_UPDATE 98
|
#define TK_PRECISION 97
|
||||||
#define TK_CACHELAST 99
|
#define TK_UPDATE 98
|
||||||
|
#define TK_CACHELAST 99
|
||||||
#define TK_LP 100
|
#define TK_LP 100
|
||||||
#define TK_RP 101
|
#define TK_RP 101
|
||||||
#define TK_UNSIGNED 102
|
#define TK_UNSIGNED 102
|
||||||
|
@ -126,105 +127,105 @@
|
||||||
#define TK_SELECT 108
|
#define TK_SELECT 108
|
||||||
#define TK_UNION 109
|
#define TK_UNION 109
|
||||||
#define TK_ALL 110
|
#define TK_ALL 110
|
||||||
#define TK_FROM 111
|
#define TK_DISTINCT 111
|
||||||
#define TK_VARIABLE 112
|
#define TK_FROM 112
|
||||||
#define TK_INTERVAL 113
|
#define TK_VARIABLE 113
|
||||||
#define TK_FILL 114
|
#define TK_INTERVAL 114
|
||||||
#define TK_SLIDING 115
|
#define TK_FILL 115
|
||||||
#define TK_ORDER 116
|
#define TK_SLIDING 116
|
||||||
#define TK_BY 117
|
#define TK_ORDER 117
|
||||||
#define TK_ASC 118
|
#define TK_BY 118
|
||||||
#define TK_DESC 119
|
#define TK_ASC 119
|
||||||
#define TK_GROUP 120
|
#define TK_DESC 120
|
||||||
#define TK_HAVING 121
|
#define TK_GROUP 121
|
||||||
#define TK_LIMIT 122
|
#define TK_HAVING 122
|
||||||
#define TK_OFFSET 123
|
#define TK_LIMIT 123
|
||||||
#define TK_SLIMIT 124
|
#define TK_OFFSET 124
|
||||||
#define TK_SOFFSET 125
|
#define TK_SLIMIT 125
|
||||||
#define TK_WHERE 126
|
#define TK_SOFFSET 126
|
||||||
#define TK_NOW 127
|
#define TK_WHERE 127
|
||||||
#define TK_RESET 128
|
#define TK_NOW 128
|
||||||
#define TK_QUERY 129
|
#define TK_RESET 129
|
||||||
#define TK_ADD 130
|
#define TK_QUERY 130
|
||||||
#define TK_COLUMN 131
|
#define TK_ADD 131
|
||||||
#define TK_TAG 132
|
#define TK_COLUMN 132
|
||||||
#define TK_CHANGE 133
|
#define TK_TAG 133
|
||||||
#define TK_SET 134
|
#define TK_CHANGE 134
|
||||||
#define TK_KILL 135
|
#define TK_SET 135
|
||||||
#define TK_CONNECTION 136
|
#define TK_KILL 136
|
||||||
#define TK_STREAM 137
|
#define TK_CONNECTION 137
|
||||||
#define TK_COLON 138
|
#define TK_STREAM 138
|
||||||
#define TK_ABORT 139
|
#define TK_COLON 139
|
||||||
#define TK_AFTER 140
|
#define TK_ABORT 140
|
||||||
#define TK_ATTACH 141
|
#define TK_AFTER 141
|
||||||
#define TK_BEFORE 142
|
#define TK_ATTACH 142
|
||||||
#define TK_BEGIN 143
|
#define TK_BEFORE 143
|
||||||
#define TK_CASCADE 144
|
#define TK_BEGIN 144
|
||||||
#define TK_CLUSTER 145
|
#define TK_CASCADE 145
|
||||||
#define TK_CONFLICT 146
|
#define TK_CLUSTER 146
|
||||||
#define TK_COPY 147
|
#define TK_CONFLICT 147
|
||||||
#define TK_DEFERRED 148
|
#define TK_COPY 148
|
||||||
#define TK_DELIMITERS 149
|
#define TK_DEFERRED 149
|
||||||
#define TK_DETACH 150
|
#define TK_DELIMITERS 150
|
||||||
#define TK_EACH 151
|
#define TK_DETACH 151
|
||||||
#define TK_END 152
|
#define TK_EACH 152
|
||||||
#define TK_EXPLAIN 153
|
#define TK_END 153
|
||||||
#define TK_FAIL 154
|
#define TK_EXPLAIN 154
|
||||||
#define TK_FOR 155
|
#define TK_FAIL 155
|
||||||
#define TK_IGNORE 156
|
#define TK_FOR 156
|
||||||
#define TK_IMMEDIATE 157
|
#define TK_IGNORE 157
|
||||||
#define TK_INITIALLY 158
|
#define TK_IMMEDIATE 158
|
||||||
#define TK_INSTEAD 159
|
#define TK_INITIALLY 159
|
||||||
#define TK_MATCH 160
|
#define TK_INSTEAD 160
|
||||||
#define TK_KEY 161
|
#define TK_MATCH 161
|
||||||
#define TK_OF 162
|
#define TK_KEY 162
|
||||||
#define TK_RAISE 163
|
#define TK_OF 163
|
||||||
#define TK_REPLACE 164
|
#define TK_RAISE 164
|
||||||
#define TK_RESTRICT 165
|
#define TK_REPLACE 165
|
||||||
#define TK_ROW 166
|
#define TK_RESTRICT 166
|
||||||
#define TK_STATEMENT 167
|
#define TK_ROW 167
|
||||||
#define TK_TRIGGER 168
|
#define TK_STATEMENT 168
|
||||||
#define TK_VIEW 169
|
#define TK_TRIGGER 169
|
||||||
#define TK_COUNT 170
|
#define TK_VIEW 170
|
||||||
#define TK_SUM 171
|
#define TK_COUNT 171
|
||||||
#define TK_AVG 172
|
#define TK_SUM 172
|
||||||
#define TK_MIN 173
|
#define TK_AVG 173
|
||||||
#define TK_MAX 174
|
#define TK_MIN 174
|
||||||
#define TK_FIRST 175
|
#define TK_MAX 175
|
||||||
#define TK_LAST 176
|
#define TK_FIRST 176
|
||||||
#define TK_TOP 177
|
#define TK_LAST 177
|
||||||
#define TK_BOTTOM 178
|
#define TK_TOP 178
|
||||||
#define TK_STDDEV 179
|
#define TK_BOTTOM 179
|
||||||
#define TK_PERCENTILE 180
|
#define TK_STDDEV 180
|
||||||
#define TK_APERCENTILE 181
|
#define TK_PERCENTILE 181
|
||||||
#define TK_LEASTSQUARES 182
|
#define TK_APERCENTILE 182
|
||||||
#define TK_HISTOGRAM 183
|
#define TK_LEASTSQUARES 183
|
||||||
#define TK_DIFF 184
|
#define TK_HISTOGRAM 184
|
||||||
#define TK_SPREAD 185
|
#define TK_DIFF 185
|
||||||
#define TK_TWA 186
|
#define TK_SPREAD 186
|
||||||
#define TK_INTERP 187
|
#define TK_TWA 187
|
||||||
#define TK_LAST_ROW 188
|
#define TK_INTERP 188
|
||||||
#define TK_RATE 189
|
#define TK_LAST_ROW 189
|
||||||
#define TK_IRATE 190
|
#define TK_RATE 190
|
||||||
#define TK_SUM_RATE 191
|
#define TK_IRATE 191
|
||||||
#define TK_SUM_IRATE 192
|
#define TK_SUM_RATE 192
|
||||||
#define TK_AVG_RATE 193
|
#define TK_SUM_IRATE 193
|
||||||
#define TK_AVG_IRATE 194
|
#define TK_AVG_RATE 194
|
||||||
#define TK_TBID 195
|
#define TK_AVG_IRATE 195
|
||||||
#define TK_SEMI 196
|
#define TK_TBID 196
|
||||||
#define TK_NONE 197
|
#define TK_SEMI 197
|
||||||
#define TK_PREV 198
|
#define TK_NONE 198
|
||||||
#define TK_LINEAR 199
|
#define TK_PREV 199
|
||||||
#define TK_IMPORT 200
|
#define TK_LINEAR 200
|
||||||
#define TK_METRIC 201
|
#define TK_IMPORT 201
|
||||||
#define TK_TBNAME 202
|
#define TK_METRIC 202
|
||||||
#define TK_JOIN 203
|
#define TK_TBNAME 203
|
||||||
#define TK_METRICS 204
|
#define TK_JOIN 204
|
||||||
#define TK_STABLE 205
|
#define TK_METRICS 205
|
||||||
#define TK_INSERT 206
|
#define TK_STABLE 206
|
||||||
#define TK_INTO 207
|
#define TK_INSERT 207
|
||||||
#define TK_VALUES 208
|
#define TK_INTO 208
|
||||||
|
#define TK_VALUES 209
|
||||||
|
|
||||||
|
|
||||||
#define TK_SPACE 300
|
#define TK_SPACE 300
|
||||||
|
|
|
@ -206,6 +206,7 @@ typedef struct tSQLExpr {
|
||||||
typedef struct tSqlExprItem {
|
typedef struct tSqlExprItem {
|
||||||
tSQLExpr *pNode; // The list of expressions
|
tSQLExpr *pNode; // The list of expressions
|
||||||
char * aliasName; // alias name, null-terminated string
|
char * aliasName; // alias name, null-terminated string
|
||||||
|
bool distinct;
|
||||||
} tSqlExprItem;
|
} tSqlExprItem;
|
||||||
|
|
||||||
// todo refactor by using SArray
|
// todo refactor by using SArray
|
||||||
|
@ -238,7 +239,7 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType);
|
||||||
|
|
||||||
void tSqlExprDestroy(tSQLExpr *pExpr);
|
void tSqlExprDestroy(tSQLExpr *pExpr);
|
||||||
|
|
||||||
tSQLExprList *tSqlExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken *pToken);
|
tSQLExprList *tSqlExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken *pDistinct, SStrToken *pToken);
|
||||||
|
|
||||||
void tSqlExprListDestroy(tSQLExprList *pList);
|
void tSqlExprListDestroy(tSQLExprList *pList);
|
||||||
|
|
||||||
|
|
|
@ -448,13 +448,13 @@ select(A) ::= SELECT(T) selcollist(W). {
|
||||||
%destructor sclp {tSqlExprListDestroy($$);}
|
%destructor sclp {tSqlExprListDestroy($$);}
|
||||||
sclp(A) ::= selcollist(X) COMMA. {A = X;}
|
sclp(A) ::= selcollist(X) COMMA. {A = X;}
|
||||||
sclp(A) ::= . {A = 0;}
|
sclp(A) ::= . {A = 0;}
|
||||||
selcollist(A) ::= sclp(P) expr(X) as(Y). {
|
selcollist(A) ::= sclp(P) distinct(Z) expr(X) as(Y). {
|
||||||
A = tSqlExprListAppend(P, X, Y.n?&Y:0);
|
A = tSqlExprListAppend(P, X, Z.n? &Z:0, Y.n?&Y:0);
|
||||||
}
|
}
|
||||||
|
|
||||||
selcollist(A) ::= sclp(P) STAR. {
|
selcollist(A) ::= sclp(P) STAR. {
|
||||||
tSQLExpr *pNode = tSqlExprIdValueCreate(NULL, TK_ALL);
|
tSQLExpr *pNode = tSqlExprIdValueCreate(NULL, TK_ALL);
|
||||||
A = tSqlExprListAppend(P, pNode, 0);
|
A = tSqlExprListAppend(P, pNode, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// An option "AS <id>" phrase that can follow one of the expressions that
|
// An option "AS <id>" phrase that can follow one of the expressions that
|
||||||
|
@ -465,6 +465,10 @@ as(X) ::= AS ids(Y). { X = Y; }
|
||||||
as(X) ::= ids(Y). { X = Y; }
|
as(X) ::= ids(Y). { X = Y; }
|
||||||
as(X) ::= . { X.n = 0; }
|
as(X) ::= . { X.n = 0; }
|
||||||
|
|
||||||
|
%type distinct {SStrToken}
|
||||||
|
distinct(X) ::= DISTINCT(Y). { X = Y; }
|
||||||
|
distinct(X) ::= . { X.n = 0;}
|
||||||
|
|
||||||
// A complete FROM clause.
|
// A complete FROM clause.
|
||||||
%type from {SArray*}
|
%type from {SArray*}
|
||||||
// current not support query from no-table
|
// current not support query from no-table
|
||||||
|
@ -672,8 +676,8 @@ expr(A) ::= expr(X) IN LP exprlist(Y) RP. {A = tSqlExprCreate(X, (tSQLExpr*)Y,
|
||||||
%type expritem {tSQLExpr*}
|
%type expritem {tSQLExpr*}
|
||||||
%destructor expritem {tSqlExprDestroy($$);}
|
%destructor expritem {tSqlExprDestroy($$);}
|
||||||
|
|
||||||
exprlist(A) ::= exprlist(X) COMMA expritem(Y). {A = tSqlExprListAppend(X,Y,0);}
|
exprlist(A) ::= exprlist(X) COMMA expritem(Y). {A = tSqlExprListAppend(X,Y,0, 0);}
|
||||||
exprlist(A) ::= expritem(X). {A = tSqlExprListAppend(0,X,0);}
|
exprlist(A) ::= expritem(X). {A = tSqlExprListAppend(0,X,0, 0);}
|
||||||
expritem(A) ::= expr(X). {A = X;}
|
expritem(A) ::= expr(X). {A = X;}
|
||||||
expritem(A) ::= . {A = 0;}
|
expritem(A) ::= . {A = 0;}
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ abort_parse:
|
||||||
return sqlInfo;
|
return sqlInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
tSQLExprList *tSqlExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken *pToken) {
|
tSQLExprList *tSqlExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken *pDistinct, SStrToken *pToken) {
|
||||||
if (pList == NULL) {
|
if (pList == NULL) {
|
||||||
pList = calloc(1, sizeof(tSQLExprList));
|
pList = calloc(1, sizeof(tSQLExprList));
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,7 @@ tSQLExprList *tSqlExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken
|
||||||
|
|
||||||
strdequote(pItem->aliasName);
|
strdequote(pItem->aliasName);
|
||||||
}
|
}
|
||||||
|
pItem->distinct = (pDistinct != NULL);
|
||||||
}
|
}
|
||||||
return pList;
|
return pList;
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,6 +240,7 @@ static SKeyword keywordTable[] = {
|
||||||
{"AVG_RATE", TK_AVG_RATE},
|
{"AVG_RATE", TK_AVG_RATE},
|
||||||
{"AVG_IRATE", TK_AVG_IRATE},
|
{"AVG_IRATE", TK_AVG_IRATE},
|
||||||
{"CACHELAST", TK_CACHELAST},
|
{"CACHELAST", TK_CACHELAST},
|
||||||
|
{"DISTINCT", TK_DISTINCT},
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char isIdChar[] = {
|
static const char isIdChar[] = {
|
||||||
|
|
3238
src/query/src/sql.c
3238
src/query/src/sql.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue