sql.y 42.1 KB
Newer Older
H
hzcheng 已提交
1 2 3 4
//lemon parser file to generate sql parse by using finite-state-machine code used to parse sql
//usage: lemon sql.y
%token_prefix TK_

H
Haojun Liao 已提交
5 6
%token_type {SStrToken}
%default_type {SStrToken}
H
hzcheng 已提交
7 8
%extra_argument {SSqlInfo* pInfo}

wmmhello's avatar
wmmhello 已提交
9
%fallback ID BOOL TINYINT SMALLINT INTEGER BIGINT FLOAT DOUBLE STRING TIMESTAMP BINARY NCHAR JSON.
H
hzcheng 已提交
10 11 12 13

%left OR.
%left AND.
%right NOT.
14
%left EQ NE ISNULL NOTNULL IS LIKE MATCH NMATCH CONTAINS GLOB BETWEEN IN.
H
hzcheng 已提交
15
%left GT GE LT LE.
X
xywang 已提交
16
%left BITAND BITOR BITXOR LSHIFT RSHIFT.
H
hzcheng 已提交
17 18 19 20
%left PLUS MINUS.
%left DIVIDE TIMES.
%left STAR SLASH REM.
%right UMINUS UPLUS BITNOT.
21
%right ARROW.
H
hzcheng 已提交
22 23 24 25 26 27 28

%include {
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdbool.h>
H
Haojun Liao 已提交
29 30
#include "qSqlparser.h"
#include "tcmdtype.h"
H
Haojun Liao 已提交
31
#include "ttoken.h"
H
Haojun Liao 已提交
32
#include "ttokendef.h"
H
hzcheng 已提交
33
#include "tutil.h"
H
Haojun Liao 已提交
34
#include "tvariant.h"
H
hzcheng 已提交
35 36 37
}

%syntax_error {
38
  pInfo->valid = false;
H
Haojun Liao 已提交
39
  int32_t outputBufLen = tListLen(pInfo->msg);
H
hzcheng 已提交
40 41 42 43 44 45 46 47 48
  int32_t len = 0;

  if(TOKEN.z) {
    char msg[] = "syntax error near \"%s\"";
    int32_t sqlLen = strlen(&TOKEN.z[0]);

    if (sqlLen + sizeof(msg)/sizeof(msg[0]) + 1 > outputBufLen) {
        char tmpstr[128] = {0};
        memcpy(tmpstr, &TOKEN.z[0], sizeof(tmpstr)/sizeof(tmpstr[0]) - 1);
H
Haojun Liao 已提交
49
        len = sprintf(pInfo->msg, msg, tmpstr);
H
hzcheng 已提交
50
    } else {
H
Haojun Liao 已提交
51
        len = sprintf(pInfo->msg, msg, &TOKEN.z[0]);
H
hzcheng 已提交
52 53 54
    }

  } else {
H
Haojun Liao 已提交
55
    len = sprintf(pInfo->msg, "Incomplete SQL statement");
H
hzcheng 已提交
56 57 58 59 60 61 62 63 64 65
  }

  assert(len <= outputBufLen);
}

%parse_accept       {}

program ::= cmd.    {}

//////////////////////////////////THE SHOW STATEMENT///////////////////////////////////////////
66
cmd ::= SHOW DATABASES.  { setShowOptions(pInfo, TSDB_MGMT_TABLE_DB, 0, 0);}
D
fix bug  
dapan1121 已提交
67
cmd ::= SHOW TOPICS.     { setShowOptions(pInfo, TSDB_MGMT_TABLE_TP, 0, 0);}
D
dapan1121 已提交
68
cmd ::= SHOW FUNCTIONS.  { setShowOptions(pInfo, TSDB_MGMT_TABLE_FUNCTION, 0, 0);}
69 70 71 72 73 74 75 76 77
cmd ::= SHOW MNODES.     { setShowOptions(pInfo, TSDB_MGMT_TABLE_MNODE, 0, 0);}
cmd ::= SHOW DNODES.     { setShowOptions(pInfo, TSDB_MGMT_TABLE_DNODE, 0, 0);}
cmd ::= SHOW ACCOUNTS.   { setShowOptions(pInfo, TSDB_MGMT_TABLE_ACCT, 0, 0);}
cmd ::= SHOW USERS.      { setShowOptions(pInfo, TSDB_MGMT_TABLE_USER, 0, 0);}

cmd ::= SHOW MODULES.    { setShowOptions(pInfo, TSDB_MGMT_TABLE_MODULE, 0, 0);  }
cmd ::= SHOW QUERIES.    { setShowOptions(pInfo, TSDB_MGMT_TABLE_QUERIES, 0, 0);  }
cmd ::= SHOW CONNECTIONS.{ setShowOptions(pInfo, TSDB_MGMT_TABLE_CONNS, 0, 0);}
cmd ::= SHOW STREAMS.    { setShowOptions(pInfo, TSDB_MGMT_TABLE_STREAMS, 0, 0);  }
H
Haojun Liao 已提交
78
cmd ::= SHOW VARIABLES.  { setShowOptions(pInfo, TSDB_MGMT_TABLE_VARIABLES, 0, 0);  }
79 80 81 82
cmd ::= SHOW SCORES.     { setShowOptions(pInfo, TSDB_MGMT_TABLE_SCORES, 0, 0);   }
cmd ::= SHOW GRANTS.     { setShowOptions(pInfo, TSDB_MGMT_TABLE_GRANTS, 0, 0);   }

cmd ::= SHOW VNODES.                { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, 0, 0); }
83
cmd ::= SHOW VNODES ids(X).     { setShowOptions(pInfo, TSDB_MGMT_TABLE_VNODES, &X, 0); }
L
lihui 已提交
84

85

H
Haojun Liao 已提交
86
%type dbPrefix {SStrToken}
87
dbPrefix(A) ::=.                   {A.n = 0; A.type = 0;}
H
hzcheng 已提交
88 89
dbPrefix(A) ::= ids(X) DOT.        {A = X;  }

H
Haojun Liao 已提交
90
%type cpxName {SStrToken}
H
hzcheng 已提交
91 92
cpxName(A) ::= .             {A.n = 0;  }
cpxName(A) ::= DOT ids(Y).   {A = Y; A.n += 1;    }
93 94
cmd ::= SHOW CREATE TABLE ids(X) cpxName(Y).    {
   X.n += Y.n;
H
Haojun Liao 已提交
95
   setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_TABLE, 1, &X);
W
wpan 已提交
96
}
97 98 99
cmd ::= SHOW CREATE STABLE ids(X) cpxName(Y).    {
   X.n += Y.n;
   setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_STABLE, 1, &X);
100
}
101 102

cmd ::= SHOW CREATE DATABASE ids(X). {
H
Haojun Liao 已提交
103
  setDCLSqlElems(pInfo, TSDB_SQL_SHOW_CREATE_DATABASE, 1, &X);
104
}
105

H
hzcheng 已提交
106
cmd ::= SHOW dbPrefix(X) TABLES.         {
107
    setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &X, 0);
H
hzcheng 已提交
108 109
}

110
cmd ::= SHOW dbPrefix(X) TABLES LIKE STRING(Y).         {
111
    setShowOptions(pInfo, TSDB_MGMT_TABLE_TABLE, &X, &Y);
H
hzcheng 已提交
112 113 114
}

cmd ::= SHOW dbPrefix(X) STABLES.      {
115
    setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &X, 0);
H
hzcheng 已提交
116 117
}

118
cmd ::= SHOW dbPrefix(X) STABLES LIKE STRING(Y).      {
H
Haojun Liao 已提交
119
    SStrToken token;
H
Haojun Liao 已提交
120
    tSetDbName(&token, &X);
121
    setShowOptions(pInfo, TSDB_MGMT_TABLE_METRIC, &token, &Y);
H
hzcheng 已提交
122 123 124
}

cmd ::= SHOW dbPrefix(X) VGROUPS.    {
H
Haojun Liao 已提交
125
    SStrToken token;
H
Haojun Liao 已提交
126
    tSetDbName(&token, &X);
127
    setShowOptions(pInfo, TSDB_MGMT_TABLE_VGROUP, &token, 0);
H
hzcheng 已提交
128 129 130 131 132
}

//drop configure for tables
cmd ::= DROP TABLE ifexists(Y) ids(X) cpxName(Z).   {
    X.n += Z.n;
D
fix bug  
dapan1121 已提交
133
    setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &X, &Y, -1, -1);
H
hzcheng 已提交
134 135
}

D
dapan1121 已提交
136 137 138
//drop stable
cmd ::= DROP STABLE ifexists(Y) ids(X) cpxName(Z).   {
    X.n += Z.n;
D
fix bug  
dapan1121 已提交
139
    setDropDbTableInfo(pInfo, TSDB_SQL_DROP_TABLE, &X, &Y, -1, TSDB_SUPER_TABLE);
D
dapan1121 已提交
140 141
}

D
fix bug  
dapan1121 已提交
142 143
cmd ::= DROP DATABASE ifexists(Y) ids(X).    { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y, TSDB_DB_TYPE_DEFAULT, -1); }
cmd ::= DROP TOPIC ifexists(Y) ids(X).    { setDropDbTableInfo(pInfo, TSDB_SQL_DROP_DB, &X, &Y, TSDB_DB_TYPE_TOPIC, -1); }
D
dapan1121 已提交
144
cmd ::= DROP FUNCTION ids(X).    { setDropFuncInfo(pInfo, TSDB_SQL_DROP_FUNCTION, &X); }
D
fix bug  
dapan1121 已提交
145

H
Haojun Liao 已提交
146 147 148
cmd ::= DROP DNODE ids(X).       { setDCLSqlElems(pInfo, TSDB_SQL_DROP_DNODE, 1, &X);    }
cmd ::= DROP USER ids(X).        { setDCLSqlElems(pInfo, TSDB_SQL_DROP_USER, 1, &X);     }
cmd ::= DROP ACCOUNT ids(X).     { setDCLSqlElems(pInfo, TSDB_SQL_DROP_ACCT, 1, &X);  }
H
hzcheng 已提交
149 150

/////////////////////////////////THE USE STATEMENT//////////////////////////////////////////
H
Haojun Liao 已提交
151
cmd ::= USE ids(X).              { setDCLSqlElems(pInfo, TSDB_SQL_USE_DB, 1, &X);}
H
hzcheng 已提交
152 153 154 155

/////////////////////////////////THE DESCRIBE STATEMENT/////////////////////////////////////
cmd ::= DESCRIBE ids(X) cpxName(Y). {
    X.n += Y.n;
H
Haojun Liao 已提交
156
    setDCLSqlElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &X);
H
hzcheng 已提交
157
}
W
wpan 已提交
158

S
SunShine Chan 已提交
159 160 161 162
cmd ::= DESC ids(X) cpxName(Y). {
    X.n += Y.n;
    setDCLSqlElems(pInfo, TSDB_SQL_DESCRIBE_TABLE, 1, &X);
}
H
hzcheng 已提交
163
/////////////////////////////////THE ALTER STATEMENT////////////////////////////////////////
164 165 166
cmd ::= ALTER USER ids(X) PASS ids(Y).          { setAlterUserSql(pInfo, TSDB_ALTER_USER_PASSWD,     &X, &Y,   NULL, NULL);}
cmd ::= ALTER USER ids(X) PRIVILEGE ids(Y).     { setAlterUserSql(pInfo, TSDB_ALTER_USER_PRIVILEGES, &X, NULL, &Y,   NULL);}
cmd ::= ALTER USER ids(X) TAGS ids(Y).          { setAlterUserSql(pInfo, TSDB_ALTER_USER_TAGS,       &X, NULL, NULL, &Y);}
H
Haojun Liao 已提交
167 168 169 170
cmd ::= ALTER DNODE ids(X) ids(Y).              { setDCLSqlElems(pInfo, TSDB_SQL_CFG_DNODE, 2, &X, &Y);          }
cmd ::= ALTER DNODE ids(X) ids(Y) ids(Z).       { setDCLSqlElems(pInfo, TSDB_SQL_CFG_DNODE, 3, &X, &Y, &Z);      }
cmd ::= ALTER LOCAL ids(X).                     { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 1, &X);              }
cmd ::= ALTER LOCAL ids(X) ids(Y).              { setDCLSqlElems(pInfo, TSDB_SQL_CFG_LOCAL, 2, &X, &Y);          }
H
Haojun Liao 已提交
171
cmd ::= ALTER DATABASE ids(X) alter_db_optr(Y). { SStrToken t = {0};  setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);}
D
fix bug  
dapan1121 已提交
172
cmd ::= ALTER TOPIC ids(X) alter_topic_optr(Y). { SStrToken t = {0};  setCreateDbInfo(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);}
H
hzcheng 已提交
173

D
dapan1121 已提交
174 175
cmd ::= ALTER ACCOUNT ids(X) acct_optr(Z).      { setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &X, NULL, &Z);}
cmd ::= ALTER ACCOUNT ids(X) PASS ids(Y) acct_optr(Z).      { setCreateAcctSql(pInfo, TSDB_SQL_ALTER_ACCT, &X, &Y, &Z);}
S
slguan 已提交
176

Y
yihaoDeng 已提交
177 178
////////////////////////////// COMPACT STATEMENT //////////////////////////////////////////////

H
Haojun Liao 已提交
179
cmd ::= COMPACT VNODES IN LP exprlist(Y) RP.    { setCompactVnodeSql(pInfo, TSDB_SQL_COMPACT_VNODE, Y);}
Y
yihaoDeng 已提交
180

H
hzcheng 已提交
181 182 183
// An IDENTIFIER can be a generic identifier, or one of several keywords.
// Any non-standard keyword can also be an identifier.
// And "ids" is an identifer-or-string.
H
Haojun Liao 已提交
184
%type ids {SStrToken}
H
hzcheng 已提交
185 186 187
ids(A) ::= ID(X).        {A = X; }
ids(A) ::= STRING(X).    {A = X; }

H
Haojun Liao 已提交
188
%type ifexists {SStrToken}
189 190
ifexists(X) ::= IF EXISTS.          { X.n = 1;}
ifexists(X) ::= .                   { X.n = 0;}
H
hzcheng 已提交
191

H
Haojun Liao 已提交
192
%type ifnotexists {SStrToken}
193 194
ifnotexists(X) ::= IF NOT EXISTS.   { X.n = 1;}
ifnotexists(X) ::= .                { X.n = 0;}
H
hzcheng 已提交
195 196

/////////////////////////////////THE CREATE STATEMENT///////////////////////////////////////
S
slguan 已提交
197
//create option for dnode/db/user/account
H
Haojun Liao 已提交
198
cmd ::= CREATE DNODE   ids(X).     { setDCLSqlElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &X);}
S
slguan 已提交
199
cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z).
D
dapan1121 已提交
200
                                { setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &X, &Y, &Z);}
H
Haojun Liao 已提交
201
cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y).  { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);}
D
fix bug  
dapan1121 已提交
202
cmd ::= CREATE TOPIC ifnotexists(Z) ids(X) topic_optr(Y).  { setCreateDbInfo(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);}
D
dapan1121 已提交
203 204
cmd ::= CREATE FUNCTION ids(X) AS ids(Y) OUTPUTTYPE typename(Z) bufsize(B).   { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &X, &Y, &Z, &B, 1);}
cmd ::= CREATE AGGREGATE FUNCTION ids(X) AS ids(Y) OUTPUTTYPE typename(Z) bufsize(B).   { setCreateFuncInfo(pInfo, TSDB_SQL_CREATE_FUNCTION, &X, &Y, &Z, &B, 2);}
205 206
cmd ::= CREATE USER ids(X) PASS ids(Y).     { setCreateUserSql(pInfo, &X, &Y, NULL);}
cmd ::= CREATE USER ids(X) PASS ids(Y) TAGS ids(Z).     { setCreateUserSql(pInfo, &X, &Y, &Z);}
H
hzcheng 已提交
207

D
dapan1121 已提交
208 209 210
bufsize(Y) ::= .                                { Y.n = 0;   }
bufsize(Y) ::= BUFSIZE INTEGER(X).              { Y = X;     }

211 212
pps(Y) ::= .                                { Y.n = 0;   }
pps(Y) ::= PPS INTEGER(X).                  { Y = X;     }
S
slguan 已提交
213

214 215
tseries(Y) ::= .                            { Y.n = 0;   }
tseries(Y) ::= TSERIES INTEGER(X).          { Y = X;     }
S
slguan 已提交
216

217 218
dbs(Y) ::= .                                { Y.n = 0;   }
dbs(Y) ::= DBS INTEGER(X).                  { Y = X;     }
S
slguan 已提交
219

220 221
streams(Y) ::= .                            { Y.n = 0;   }
streams(Y) ::= STREAMS INTEGER(X).          { Y = X;     }
S
slguan 已提交
222

223 224
storage(Y) ::= .                            { Y.n = 0;   }
storage(Y) ::= STORAGE INTEGER(X).          { Y = X;     }
S
slguan 已提交
225

226 227
qtime(Y) ::= .                              { Y.n = 0;   }
qtime(Y) ::= QTIME INTEGER(X).              { Y = X;     }
S
slguan 已提交
228

229 230
users(Y) ::= .                              { Y.n = 0;   }
users(Y) ::= USERS INTEGER(X).              { Y = X;     }
S
slguan 已提交
231

232 233
conns(Y) ::= .                              { Y.n = 0;   }
conns(Y) ::= CONNS INTEGER(X).              { Y = X;     }
S
slguan 已提交
234

235 236
state(Y) ::= .                              { Y.n = 0;   }
state(Y) ::= STATE ids(X).                  { Y = X;     }
S
slguan 已提交
237

H
Haojun Liao 已提交
238
%type acct_optr {SCreateAcctInfo}
S
slguan 已提交
239
acct_optr(Y) ::= pps(C) tseries(D) storage(P) streams(F) qtime(Q) dbs(E) users(K) conns(L) state(M). {
240 241 242 243 244 245 246 247
    Y.maxUsers   = (K.n>0)?atoi(K.z):-1;
    Y.maxDbs     = (E.n>0)?atoi(E.z):-1;
    Y.maxTimeSeries = (D.n>0)?atoi(D.z):-1;
    Y.maxStreams = (F.n>0)?atoi(F.z):-1;
    Y.maxPointsPerSecond     = (C.n>0)?atoi(C.z):-1;
    Y.maxStorage = (P.n>0)?strtoll(P.z, NULL, 10):-1;
    Y.maxQueryTime   = (Q.n>0)?strtoll(Q.z, NULL, 10):-1;
    Y.maxConnections   = (L.n>0)?atoi(L.z):-1;
S
slguan 已提交
248 249 250
    Y.stat    = M;
}

D
dapan1121 已提交
251
%type intitemlist {SArray*}
252
%destructor intitemlist {taosArrayDestroy(&$$);}
D
dapan1121 已提交
253 254 255 256 257

%type intitem {tVariant}
intitemlist(A) ::= intitemlist(X) COMMA intitem(Y). { A = tVariantListAppend(X, &Y, -1);    }
intitemlist(A) ::= intitem(X).                      { A = tVariantListAppend(NULL, &X, -1); }

258
intitem(A) ::= INTEGER(X).      { toTSDBType(X.type); tVariantCreate(&A, &X); }
D
dapan1121 已提交
259

H
Haojun Liao 已提交
260
%type keep {SArray*}
261
%destructor keep {taosArrayDestroy(&$$);}
D
dapan1121 已提交
262
keep(Y)    ::= KEEP intitemlist(X).           { Y = X; }
263 264 265

cache(Y)   ::= CACHE INTEGER(X).              { Y = X; }
replica(Y) ::= REPLICA INTEGER(X).            { Y = X; }
266
quorum(Y)  ::= QUORUM INTEGER(X).             { Y = X; }
267
days(Y)    ::= DAYS INTEGER(X).               { Y = X; }
H
hjxilinx 已提交
268 269 270
minrows(Y) ::= MINROWS INTEGER(X).            { Y = X; }
maxrows(Y) ::= MAXROWS INTEGER(X).            { Y = X; }
blocks(Y)  ::= BLOCKS INTEGER(X).             { Y = X; }
271
ctime(Y)   ::= CTIME INTEGER(X).              { Y = X; }
H
hjxilinx 已提交
272
wal(Y)     ::= WAL INTEGER(X).                { Y = X; }
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
273
fsync(Y)   ::= FSYNC INTEGER(X).              { Y = X; }
274 275
comp(Y)    ::= COMP INTEGER(X).               { Y = X; }
prec(Y)    ::= PRECISION STRING(X).           { Y = X; }
276
update(Y)  ::= UPDATE INTEGER(X).             { Y = X; }
D
dapan1121 已提交
277
cachelast(Y) ::= CACHELAST INTEGER(X).        { Y = X; }
D
fix bug  
dapan1121 已提交
278
partitions(Y) ::= PARTITIONS INTEGER(X).      { Y = X; }
279

H
Haojun Liao 已提交
280
%type db_optr {SCreateDbInfo}
D
fix bug  
dapan1121 已提交
281
db_optr(Y) ::= . {setDefaultCreateDbOption(&Y); Y.dbType = TSDB_DB_TYPE_DEFAULT;}
H
hjxilinx 已提交
282

283 284
db_optr(Y) ::= db_optr(Z) cache(X).          { Y = Z; Y.cacheBlockSize = strtol(X.z, NULL, 10); }
db_optr(Y) ::= db_optr(Z) replica(X).        { Y = Z; Y.replica = strtol(X.z, NULL, 10); }
285
db_optr(Y) ::= db_optr(Z) quorum(X).         { Y = Z; Y.quorum = strtol(X.z, NULL, 10); }
286
db_optr(Y) ::= db_optr(Z) days(X).           { Y = Z; Y.daysPerFile = strtol(X.z, NULL, 10); }
H
hjxilinx 已提交
287 288 289
db_optr(Y) ::= db_optr(Z) minrows(X).        { Y = Z; Y.minRowsPerBlock = strtod(X.z, NULL); }
db_optr(Y) ::= db_optr(Z) maxrows(X).        { Y = Z; Y.maxRowsPerBlock = strtod(X.z, NULL); }
db_optr(Y) ::= db_optr(Z) blocks(X).         { Y = Z; Y.numOfBlocks = strtol(X.z, NULL, 10); }
290
db_optr(Y) ::= db_optr(Z) ctime(X).          { Y = Z; Y.commitTime = strtol(X.z, NULL, 10); }
H
hjxilinx 已提交
291
db_optr(Y) ::= db_optr(Z) wal(X).            { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); }
陶建辉(Jeff)'s avatar
陶建辉(Jeff) 已提交
292
db_optr(Y) ::= db_optr(Z) fsync(X).          { Y = Z; Y.fsyncPeriod = strtol(X.z, NULL, 10); }
293 294 295
db_optr(Y) ::= db_optr(Z) comp(X).           { Y = Z; Y.compressionLevel = strtol(X.z, NULL, 10); }
db_optr(Y) ::= db_optr(Z) prec(X).           { Y = Z; Y.precision = X; }
db_optr(Y) ::= db_optr(Z) keep(X).           { Y = Z; Y.keep = X; }
Y
yihaoDeng 已提交
296
db_optr(Y) ::= db_optr(Z) update(X).         { Y = Z; Y.update = strtol(X.z, NULL, 10); }
D
dapan1121 已提交
297
db_optr(Y) ::= db_optr(Z) cachelast(X).      { Y = Z; Y.cachelast = strtol(X.z, NULL, 10); }
298

D
fix bug  
dapan1121 已提交
299 300 301 302 303
%type topic_optr {SCreateDbInfo}

topic_optr(Y) ::= db_optr(Z).                       { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; }
topic_optr(Y) ::= topic_optr(Z) partitions(X).      { Y = Z; Y.partitions = strtol(X.z, NULL, 10); }

H
Haojun Liao 已提交
304
%type alter_db_optr {SCreateDbInfo}
D
fix bug  
dapan1121 已提交
305
alter_db_optr(Y) ::= . { setDefaultCreateDbOption(&Y); Y.dbType = TSDB_DB_TYPE_DEFAULT;}
S
slguan 已提交
306 307

alter_db_optr(Y) ::= alter_db_optr(Z) replica(X).     { Y = Z; Y.replica = strtol(X.z, NULL, 10); }
308
alter_db_optr(Y) ::= alter_db_optr(Z) quorum(X).      { Y = Z; Y.quorum = strtol(X.z, NULL, 10); }
H
hjxilinx 已提交
309 310 311
alter_db_optr(Y) ::= alter_db_optr(Z) keep(X).        { Y = Z; Y.keep = X; }
alter_db_optr(Y) ::= alter_db_optr(Z) blocks(X).      { Y = Z; Y.numOfBlocks = strtol(X.z, NULL, 10); }
alter_db_optr(Y) ::= alter_db_optr(Z) comp(X).        { Y = Z; Y.compressionLevel = strtol(X.z, NULL, 10); }
312
alter_db_optr(Y) ::= alter_db_optr(Z) update(X).      { Y = Z; Y.update = strtol(X.z, NULL, 10); }
D
dapan1121 已提交
313
alter_db_optr(Y) ::= alter_db_optr(Z) cachelast(X).   { Y = Z; Y.cachelast = strtol(X.z, NULL, 10); }
H
hzcheng 已提交
314

315 316
// dynamically update the following two parameters are not allowed.
//alter_db_optr(Y) ::= alter_db_optr(Z) fsync(X).       { Y = Z; Y.fsyncPeriod = strtol(X.z, NULL, 10); }
H
Haojun Liao 已提交
317 318
//alter_db_optr(Y) ::= alter_db_optr(Z) wal(X).         { Y = Z; Y.walLevel = strtol(X.z, NULL, 10); } not support yet

D
fix bug  
dapan1121 已提交
319 320 321 322 323
%type alter_topic_optr {SCreateDbInfo}

alter_topic_optr(Y) ::= alter_db_optr(Z).                       { Y = Z; Y.dbType = TSDB_DB_TYPE_TOPIC; }
alter_topic_optr(Y) ::= alter_topic_optr(Z) partitions(X).      { Y = Z; Y.partitions = strtol(X.z, NULL, 10); }

H
hzcheng 已提交
324
%type typename {TAOS_FIELD}
325
typename(A) ::= ids(X). {
dengyihao's avatar
dengyihao 已提交
326
  X.type = 0;
H
Haojun Liao 已提交
327
  tSetColumnType (&A, &X);
dengyihao's avatar
dengyihao 已提交
328
}
H
hzcheng 已提交
329 330 331

//define binary type, e.g., binary(10), nchar(10)
typename(A) ::= ids(X) LP signed(Y) RP.    {
332 333
  if (Y <= 0) {
    X.type = 0;
H
Haojun Liao 已提交
334
    tSetColumnType(&A, &X);
335 336
  } else {
    X.type = -Y;  // negative value of name length
H
Haojun Liao 已提交
337
    tSetColumnType(&A, &X);
338
  }
H
hzcheng 已提交
339 340
}

341 342 343 344
// define the unsigned number type
typename(A) ::= ids(X) UNSIGNED(Z). {
  X.type = 0;
  X.n = ((Z.z + Z.n) - X.z);
H
Haojun Liao 已提交
345
  tSetColumnType (&A, &X);
346 347
}

348 349
%type signed {int64_t}
signed(A) ::= INTEGER(X).         { A = strtol(X.z, NULL, 10); }
H
hzcheng 已提交
350 351 352 353
signed(A) ::= PLUS INTEGER(X).    { A = strtol(X.z, NULL, 10); }
signed(A) ::= MINUS INTEGER(X).   { A = -strtol(X.z, NULL, 10);}

////////////////////////////////// The CREATE TABLE statement ///////////////////////////////
354 355
cmd ::= CREATE TABLE  create_table_args.  {}
cmd ::= CREATE TABLE  create_stable_args. {}
D
dapan1121 已提交
356
cmd ::= CREATE STABLE create_stable_args. {}
357 358
cmd ::= CREATE TABLE create_table_list(Z). { pInfo->type = TSDB_SQL_CREATE_TABLE; pInfo->pCreateTableInfo = Z;}

H
Haojun Liao 已提交
359
%type create_table_list{SCreateTableSql*}
H
Haojun Liao 已提交
360
%destructor create_table_list{destroyCreateTableSql($$);}
361
create_table_list(A) ::= create_from_stable(Z). {
H
Haojun Liao 已提交
362
  SCreateTableSql* pCreateTable = calloc(1, sizeof(SCreateTableSql));
363 364 365 366 367 368 369 370 371 372
  pCreateTable->childTableInfo = taosArrayInit(4, sizeof(SCreatedTableInfo));

  taosArrayPush(pCreateTable->childTableInfo, &Z);
  pCreateTable->type = TSQL_CREATE_TABLE_FROM_STABLE;
  A = pCreateTable;
}

create_table_list(A) ::= create_table_list(X) create_from_stable(Z). {
  taosArrayPush(X->childTableInfo, &Z);
  A = X;
H
hzcheng 已提交
373 374
}

H
Haojun Liao 已提交
375
%type create_table_args{SCreateTableSql*}
376
create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP. {
H
Haojun Liao 已提交
377
  A = tSetCreateTableInfo(X, NULL, NULL, TSQL_CREATE_TABLE);
D
dapan1121 已提交
378
  setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
379 380 381

  V.n += Z.n;
  setCreatedTableName(pInfo, &V, &U);
H
hzcheng 已提交
382 383
}

384
// create super table
H
Haojun Liao 已提交
385
%type create_stable_args{SCreateTableSql*}
D
dapan1121 已提交
386
create_stable_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) LP columnlist(X) RP TAGS LP columnlist(Y) RP. {
H
Haojun Liao 已提交
387
  A = tSetCreateTableInfo(X, Y, NULL, TSQL_CREATE_STABLE);
D
dapan1121 已提交
388
  setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
389 390 391

  V.n += Z.n;
  setCreatedTableName(pInfo, &V, &U);
H
hzcheng 已提交
392 393
}

394 395
// create table by using super table
// create table table_name using super_table_name tags(tag_values1, tag_values2)
396 397 398 399
%type create_from_stable{SCreatedTableInfo}
create_from_stable(A) ::= ifnotexists(U) ids(V) cpxName(Z) USING ids(X) cpxName(F) TAGS LP tagitemlist(Y) RP.  {
  X.n += F.n;
  V.n += Z.n;
400
  A = createNewChildTableInfo(&X, NULL, Y, &V, &U);
H
hzcheng 已提交
401 402
}

403 404 405 406 407 408 409
create_from_stable(A) ::= ifnotexists(U) ids(V) cpxName(Z) USING ids(X) cpxName(F) LP tagNamelist(P) RP TAGS LP tagitemlist(Y) RP.  {
  X.n += F.n;
  V.n += Z.n;
  A = createNewChildTableInfo(&X, P, Y, &V, &U);
}

%type tagNamelist{SArray*}
410
%destructor tagNamelist {taosArrayDestroy(&$$);}
411 412 413
tagNamelist(A) ::= tagNamelist(X) COMMA ids(Y).  {taosArrayPush(X, &Y); A = X;  }
tagNamelist(A) ::= ids(X).                      {A = taosArrayInit(4, sizeof(SStrToken)); taosArrayPush(A, &X);}

H
hzcheng 已提交
414
// create stream
415
// create table table_name as select count(*) from super_table_name interval(time)
416
create_table_args(A) ::= ifnotexists(U) ids(V) cpxName(Z) to_opt(E) split_opt(F) AS select(S). {
H
Haojun Liao 已提交
417
  A = tSetCreateTableInfo(NULL, NULL, S, TSQL_CREATE_STREAM);
D
dapan1121 已提交
418
  setSqlInfo(pInfo, A, NULL, TSDB_SQL_CREATE_TABLE);
419

420
  setCreatedStreamOpt(pInfo, &E, &F);
B
Bomin Zhang 已提交
421 422
  V.n += Z.n;
  setCreatedTableName(pInfo, &V, &U);
H
hzcheng 已提交
423 424
}

425 426 427 428 429 430 431 432 433 434 435 436 437
// to_opt
%type to_opt {SStrToken}
to_opt(A) ::= . {A.n = 0;}
to_opt(A) ::= TO ids(X) cpxName(Y). {
   A = X;
   A.n += Y.n;
}

// split_opt
%type to_split {SStrToken}
split_opt(A) ::= . {A.n = 0;}
split_opt(A) ::= SPLIT ids(X). { A = X;}

H
hzcheng 已提交
438
%type column{TAOS_FIELD}
H
Haojun Liao 已提交
439
%type columnlist{SArray*}
440
%destructor columnlist {taosArrayDestroy(&$$);}
H
Haojun Liao 已提交
441
columnlist(A) ::= columnlist(X) COMMA column(Y).  {taosArrayPush(X, &Y); A = X;  }
H
Haojun Liao 已提交
442
columnlist(A) ::= column(X).                      {A = taosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(A, &X);}
H
hzcheng 已提交
443 444 445 446

// The information used for a column is the name and type of column:
// tinyint smallint int bigint float double bool timestamp binary(x) nchar(x)
column(A) ::= ids(X) typename(Y).          {
H
Haojun Liao 已提交
447
  tSetColumnInfo(&A, &X, &Y);
H
hzcheng 已提交
448 449
}

H
Haojun Liao 已提交
450
%type tagitemlist {SArray*}
451
%destructor tagitemlist {taosArrayDestroy(&$$);}
H
hzcheng 已提交
452 453 454 455 456

%type tagitem {tVariant}
tagitemlist(A) ::= tagitemlist(X) COMMA tagitem(Y). { A = tVariantListAppend(X, &Y, -1);    }
tagitemlist(A) ::= tagitem(X).                      { A = tVariantListAppend(NULL, &X, -1); }

457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
tagitem(A) ::= INTEGER(X).      { toTSDBType(X.type); tVariantCreate(&A, &X); }
tagitem(A) ::= FLOAT(X).        { toTSDBType(X.type); tVariantCreate(&A, &X); }
tagitem(A) ::= STRING(X).       { toTSDBType(X.type); tVariantCreate(&A, &X); }
tagitem(A) ::= BOOL(X).         { toTSDBType(X.type); tVariantCreate(&A, &X); }
tagitem(A) ::= NULL(X).         { X.type = 0; tVariantCreate(&A, &X); }
tagitem(A) ::= NOW(X).          { X.type = TSDB_DATA_TYPE_TIMESTAMP; tVariantCreateExt(&A, &X, TK_NOW, true);}

tagitem(A) ::= NOW PLUS VARIABLE(X).{
    X.type = TSDB_DATA_TYPE_TIMESTAMP;
    tVariantCreateExt(&A, &X, TK_PLUS, true);
}

tagitem(A) ::= NOW MINUS VARIABLE(X).{
    X.type = TSDB_DATA_TYPE_TIMESTAMP;
    tVariantCreateExt(&A, &X, TK_MINUS, true);
}
H
hzcheng 已提交
473 474 475 476 477

tagitem(A) ::= MINUS(X) INTEGER(Y).{
    X.n += Y.n;
    X.type = Y.type;
    toTSDBType(X.type);
478
    tVariantCreate(&A, &X);
H
hzcheng 已提交
479 480 481 482 483 484
}

tagitem(A) ::= MINUS(X) FLOAT(Y).  {
    X.n += Y.n;
    X.type = Y.type;
    toTSDBType(X.type);
485
    tVariantCreate(&A, &X);
H
hzcheng 已提交
486 487
}

S
slguan 已提交
488 489 490 491
tagitem(A) ::= PLUS(X) INTEGER(Y). {
    X.n += Y.n;
    X.type = Y.type;
    toTSDBType(X.type);
492
    tVariantCreate(&A, &X);
S
slguan 已提交
493 494 495 496 497 498
}

tagitem(A) ::= PLUS(X) FLOAT(Y).  {
    X.n += Y.n;
    X.type = Y.type;
    toTSDBType(X.type);
499
    tVariantCreate(&A, &X);
S
slguan 已提交
500
}
H
hzcheng 已提交
501 502

//////////////////////// The SELECT statement /////////////////////////////////
503 504
%type select {SSqlNode*}
%destructor select {destroySqlNode($$);}
D
dapan1121 已提交
505 506
select(A) ::= SELECT(T) selcollist(W) from(X) where_opt(Y) range_option(R) interval_option(K) sliding_opt(S) session_option(H) windowstate_option(D) fill_opt(F)groupby_opt(P) having_opt(N) orderby_opt(Z) slimit_opt(G) limit_opt(L). {
  A = tSetQuerySqlNode(&T, W, X, Y, P, Z, &K, &H, &D, &S, F, &L, &G, N, &R);
H
hzcheng 已提交
507 508
}

H
Haojun Liao 已提交
509 510
select(A) ::= LP select(B) RP. {A = B;}

511 512
%type union {SArray*}
%destructor union {destroyAllSqlNode($$);}
513
union(Y) ::= select(X). { Y = setSubclause(NULL, X); }
514
union(Y) ::= union(Z) UNION ALL select(X). { Y = appendSelectClause(Z, X); }
515

D
dapan1121 已提交
516
cmd ::= union(X). { setSqlInfo(pInfo, X, NULL, TSDB_SQL_SELECT); }
517

H
hjxilinx 已提交
518
// Support for the SQL exprssion without from & where subclauses, e.g.,
519
// select database()
H
Haojun Liao 已提交
520 521 522
// select server_version()
// select client_version()
// select server_state()
H
hjxilinx 已提交
523
select(A) ::= SELECT(T) selcollist(W). {
D
dapan1121 已提交
524
  A = tSetQuerySqlNode(&T, W, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL);
H
hjxilinx 已提交
525 526
}

H
hzcheng 已提交
527 528 529
// selcollist is a list of expressions that are to become the return
// values of the SELECT statement.  The "*" in statements like
// "SELECT * FROM ..." is encoded as a special expression with an opcode of TK_ALL.
H
Haojun Liao 已提交
530
%type selcollist {SArray*}
D
dapan1121 已提交
531
%destructor selcollist {tSqlExprListDestroy($$);}
H
hzcheng 已提交
532

H
Haojun Liao 已提交
533
%type sclp {SArray*}
D
dapan1121 已提交
534
%destructor sclp {tSqlExprListDestroy($$);}
H
hzcheng 已提交
535 536
sclp(A) ::= selcollist(X) COMMA.             {A = X;}
sclp(A) ::= .                                {A = 0;}
dengyihao's avatar
TD-2571  
dengyihao 已提交
537 538
selcollist(A) ::= sclp(P) distinct(Z) expr(X) as(Y).     {
   A = tSqlExprListAppend(P, X,  Z.n? &Z:0, Y.n?&Y:0);
H
hzcheng 已提交
539 540 541
}

selcollist(A) ::= sclp(P) STAR. {
542
   tSqlExpr *pNode = tSqlExprCreateIdValue(pInfo, NULL, TK_ALL);
dengyihao's avatar
TD-2571  
dengyihao 已提交
543
   A = tSqlExprListAppend(P, pNode, 0, 0);
H
hzcheng 已提交
544 545 546 547
}

// An option "AS <id>" phrase that can follow one of the expressions that
// define the result set, or one of the tables in the FROM clause.
H
Haojun Liao 已提交
548
%type as {SStrToken}
H
hzcheng 已提交
549 550 551 552
as(X) ::= AS ids(Y).    { X = Y;    }
as(X) ::= ids(Y).       { X = Y;    }
as(X) ::= .             { X.n = 0;  }

dengyihao's avatar
TD-2571  
dengyihao 已提交
553 554 555 556
%type distinct {SStrToken}
distinct(X) ::= DISTINCT(Y). { X = Y;  }
distinct(X) ::= .            { X.n = 0;}

H
hzcheng 已提交
557
// A complete FROM clause.
558
%type from {SRelationInfo*}
H
Haojun Liao 已提交
559
%destructor from {destroyRelationInfo($$);}
S
slguan 已提交
560
from(A) ::= FROM tablelist(X).                 {A = X;}
H
Haojun Liao 已提交
561 562 563 564 565 566 567
from(A) ::= FROM sub(X).                       {A = X;}

%type sub {SRelationInfo*}
%destructor sub {destroyRelationInfo($$);}
sub(A)  ::= LP union(Y) RP.                    {A = addSubqueryElem(NULL, Y, NULL);}
sub(A)  ::= LP union(Y) RP ids(Z).             {A = addSubqueryElem(NULL, Y, &Z);}
sub(A)  ::= sub(X) COMMA LP union(Y) RP ids(Z).{A = addSubqueryElem(X, Y, &Z);}
S
slguan 已提交
568

569
%type tablelist {SRelationInfo*}
H
Haojun Liao 已提交
570
%destructor tablelist {destroyRelationInfo($$);}
H
Haojun Liao 已提交
571 572
tablelist(A) ::= ids(X) cpxName(Y).                     {
  X.n += Y.n;
H
Haojun Liao 已提交
573
  A = setTableNameList(NULL, &X, NULL);
H
Haojun Liao 已提交
574 575 576
}

tablelist(A) ::= ids(X) cpxName(Y) ids(Z).             {
577
  X.n += Y.n;
H
Haojun Liao 已提交
578
  A = setTableNameList(NULL, &X, &Z);
H
Haojun Liao 已提交
579 580 581 582
}

tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z).  {
  X.n += Z.n;
H
Haojun Liao 已提交
583
  A = setTableNameList(Y, &X, NULL);
H
Haojun Liao 已提交
584 585 586
}

tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z) ids(F). {
587
  X.n += Z.n;
H
Haojun Liao 已提交
588
  A = setTableNameList(Y, &X, &F);
H
Haojun Liao 已提交
589
}
H
hzcheng 已提交
590 591

// The value of interval should be the form of "number+[a,s,m,h,d,n,y]" or "now"
H
Haojun Liao 已提交
592
%type tmvar {SStrToken}
H
hzcheng 已提交
593 594
tmvar(A) ::= VARIABLE(X).   {A = X;}

D
dapan1121 已提交
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610

%type timestamp {tSqlExpr*}
%destructor timestamp {tSqlExprDestroy($$);}

timestamp(A) ::= INTEGER(X).          { A = tSqlExprCreateTimestamp(&X, TK_INTEGER);}
timestamp(A) ::= MINUS(X) INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSqlExprCreateTimestamp(&X, TK_INTEGER);}
timestamp(A) ::= PLUS(X)  INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSqlExprCreateTimestamp(&X, TK_INTEGER);}
timestamp(A) ::= STRING(X).           { A = tSqlExprCreateTimestamp(&X, TK_STRING);}
timestamp(A) ::= NOW(X).              { A = tSqlExprCreateTimestamp(&X, TK_NOW); }
timestamp(A) ::= NOW PLUS  VARIABLE(Y).   {A = tSqlExprCreateTimestamp(&Y, TK_PLUS);  }
timestamp(A) ::= NOW MINUS VARIABLE(Y).   {A = tSqlExprCreateTimestamp(&Y, TK_MINUS); }

%type range_option {SRangeVal}
range_option(N) ::= . {N.start = 0; N.end = 0;}
range_option(N) ::= RANGE LP timestamp(E) COMMA timestamp(X) RP. {N.start = E; N.end = X;}

611 612 613 614 615 616 617 618
%type interval_option {SIntervalVal}
interval_option(N) ::= intervalKey(A) LP tmvar(E) RP.                {N.interval = E; N.offset.n = 0; N.token = A;}
interval_option(N) ::= intervalKey(A) LP tmvar(E) COMMA tmvar(X) RP. {N.interval = E; N.offset = X;   N.token = A;}
interval_option(N) ::= .                                             {memset(&N, 0, sizeof(N));}

%type intervalKey {int32_t}
intervalKey(A)     ::= INTERVAL.                                     {A = TK_INTERVAL;}
intervalKey(A)     ::= EVERY.                                        {A = TK_EVERY;   }
H
hzcheng 已提交
619

620 621 622 623 624 625 626
%type session_option {SSessionWindowVal}
session_option(X) ::= .                                                  {X.col.n = 0; X.gap.n = 0;}
session_option(X) ::= SESSION LP ids(V) cpxName(Z) COMMA tmvar(Y) RP.    {
   V.n += Z.n;
   X.col = V;
   X.gap = Y;
}
627

Y
TD-2570  
yihaoDeng 已提交
628
%type windowstate_option {SWindowStateVal}
629 630
windowstate_option(X) ::= .                                                { X.col.n = 0; X.col.z = NULL;}
windowstate_option(X) ::= STATE_WINDOW LP ids(V) RP.                       { X.col = V; }
631

H
Haojun Liao 已提交
632
%type fill_opt {SArray*}
633
%destructor fill_opt {taosArrayDestroy(&$$);}
634
fill_opt(N) ::= .                                           { N = 0;     }
H
hzcheng 已提交
635 636 637
fill_opt(N) ::= FILL LP ID(Y) COMMA tagitemlist(X) RP.      {
    tVariant A = {0};
    toTSDBType(Y.type);
638
    tVariantCreate(&A, &Y);
H
hzcheng 已提交
639

H
Haojun Liao 已提交
640
    tVariantListInsert(X, &A, -1, 0);
H
hzcheng 已提交
641 642 643 644 645
    N = X;
}

fill_opt(N) ::= FILL LP ID(Y) RP.               {
    toTSDBType(Y.type);
646
    N = tVariantListAppendToken(NULL, &Y, -1, true);
H
hzcheng 已提交
647 648
}

H
Haojun Liao 已提交
649
%type sliding_opt {SStrToken}
H
hzcheng 已提交
650
sliding_opt(K) ::= SLIDING LP tmvar(E) RP.      {K = E;     }
H
hjxilinx 已提交
651
sliding_opt(K) ::= .                            {K.n = 0; K.z = NULL; K.type = 0;   }
H
hzcheng 已提交
652

H
Haojun Liao 已提交
653
%type orderby_opt {SArray*}
654
%destructor orderby_opt {taosArrayDestroy(&$$);}
H
hzcheng 已提交
655

H
Haojun Liao 已提交
656
%type sortlist {SArray*}
657
%destructor sortlist {taosArrayDestroy(&$$);}
H
hzcheng 已提交
658 659 660 661 662

orderby_opt(A) ::= .                          {A = 0;}
orderby_opt(A) ::= ORDER BY sortlist(X).      {A = X;}

sortlist(A) ::= sortlist(X) COMMA item(Y) sortorder(Z). {
wmmhello's avatar
wmmhello 已提交
663 664 665 666 667
  A = commonItemAppend(X, &Y, NULL, false, Z);
}

sortlist(A) ::= sortlist(X) COMMA arrow(Y) sortorder(Z). {
  A = commonItemAppend(X, NULL, Y, true, Z);
H
hzcheng 已提交
668 669 670
}

sortlist(A) ::= item(Y) sortorder(Z). {
wmmhello's avatar
wmmhello 已提交
671 672 673 674 675
  A = commonItemAppend(NULL, &Y, NULL, false, Z);
}

sortlist(A) ::= arrow(Y) sortorder(Z). {
  A = commonItemAppend(NULL, NULL, Y, true, Z);
H
hzcheng 已提交
676 677
}

678
%type item {tVariant}
679 680
item(A) ::= ID(X).   {
  toTSDBType(X.type);
681
  tVariantCreate(&A, &X);
682
}
wmmhello's avatar
wmmhello 已提交
683
item(A) ::= ID(X) DOT ID(Y).   {
H
hzcheng 已提交
684
  toTSDBType(X.type);
685
  X.n += (1+Y.n);
686
  tVariantCreate(&A, &X);
H
hzcheng 已提交
687 688 689
}

%type sortorder {int}
690 691 692
sortorder(A) ::= ASC.           { A = TSDB_ORDER_ASC; }
sortorder(A) ::= DESC.          { A = TSDB_ORDER_DESC;}
sortorder(A) ::= .              { A = TSDB_ORDER_ASC; }  // Ascending order by default
H
hzcheng 已提交
693 694

//group by clause
H
Haojun Liao 已提交
695
%type groupby_opt {SArray*}
696
%destructor groupby_opt {taosArrayDestroy(&$$);}
H
Haojun Liao 已提交
697
%type grouplist {SArray*}
698
%destructor grouplist {taosArrayDestroy(&$$);}
H
hzcheng 已提交
699

700 701
groupby_opt(A) ::= .                       { A = 0;}
groupby_opt(A) ::= GROUP BY grouplist(X).  { A = X;}
H
hzcheng 已提交
702 703

grouplist(A) ::= grouplist(X) COMMA item(Y).    {
wmmhello's avatar
wmmhello 已提交
704 705 706 707 708
  A = commonItemAppend(X, &Y, NULL, false, -1);
}

grouplist(A) ::= grouplist(X) COMMA arrow(Y).    {
  A = commonItemAppend(X, NULL, Y, true, -1);
H
hzcheng 已提交
709 710 711
}

grouplist(A) ::= item(X).                       {
wmmhello's avatar
wmmhello 已提交
712 713 714 715 716
  A = commonItemAppend(NULL, &X, NULL, false, -1);
}

grouplist(A) ::= arrow(X).                       {
  A = commonItemAppend(NULL, NULL, X, true, -1);
H
hzcheng 已提交
717 718 719
}

//having clause, ignore the input condition in having
H
Haojun Liao 已提交
720
%type having_opt {tSqlExpr*}
D
dapan1121 已提交
721
%destructor having_opt {tSqlExprDestroy($$);}
H
hzcheng 已提交
722 723 724 725 726 727
having_opt(A) ::=.                  {A = 0;}
having_opt(A) ::= HAVING expr(X).   {A = X;}

//limit-offset subclause
%type limit_opt {SLimitVal}
limit_opt(A) ::= .                     {A.limit = -1; A.offset = 0;}
728
limit_opt(A) ::= LIMIT signed(X).      {A.limit = X;  A.offset = 0;}
H
hzcheng 已提交
729
limit_opt(A) ::= LIMIT signed(X) OFFSET signed(Y).
730
                                       { A.limit = X;  A.offset = Y;}
H
hzcheng 已提交
731
limit_opt(A) ::= LIMIT signed(X) COMMA signed(Y).
732
                                       { A.limit = Y;  A.offset = X;}
H
hzcheng 已提交
733 734 735 736 737 738 739

%type slimit_opt {SLimitVal}
slimit_opt(A) ::= .                    {A.limit = -1; A.offset = 0;}
slimit_opt(A) ::= SLIMIT signed(X).    {A.limit = X;  A.offset = 0;}
slimit_opt(A) ::= SLIMIT signed(X) SOFFSET signed(Y).
                                       {A.limit = X;  A.offset = Y;}
slimit_opt(A) ::= SLIMIT signed(X) COMMA  signed(Y).
S
slguan 已提交
740
                                       {A.limit = Y;  A.offset = X;}
H
hzcheng 已提交
741

H
Haojun Liao 已提交
742
%type where_opt {tSqlExpr*}
D
dapan1121 已提交
743
%destructor where_opt {tSqlExprDestroy($$);}
H
hzcheng 已提交
744 745 746 747 748 749

where_opt(A) ::= .                    {A = 0;}
where_opt(A) ::= WHERE expr(X).       {A = X;}

/////////////////////////// Expression Processing /////////////////////////////
//
H
Haojun Liao 已提交
750
%type expr {tSqlExpr*}
D
dapan1121 已提交
751
%destructor expr {tSqlExprDestroy($$);}
H
hzcheng 已提交
752

H
Haojun Liao 已提交
753
expr(A) ::= LP(X) expr(Y) RP(Z).       {A = Y; A->exprToken.z = X.z; A->exprToken.n = (Z.z - X.z + 1);}
H
hzcheng 已提交
754

755 756 757 758 759 760 761 762 763 764 765 766
expr(A) ::= ID(X).               { A = tSqlExprCreateIdValue(pInfo, &X, TK_ID);}
expr(A) ::= ID(X) DOT ID(Y).     { X.n += (1+Y.n); A = tSqlExprCreateIdValue(pInfo, &X, TK_ID);}
expr(A) ::= ID(X) DOT STAR(Y).   { X.n += (1+Y.n); A = tSqlExprCreateIdValue(pInfo, &X, TK_ALL);}

expr(A) ::= INTEGER(X).          { A = tSqlExprCreateIdValue(pInfo, &X, TK_INTEGER);}
expr(A) ::= MINUS(X) INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSqlExprCreateIdValue(pInfo, &X, TK_INTEGER);}
expr(A) ::= PLUS(X)  INTEGER(Y). { X.n += Y.n; X.type = TK_INTEGER; A = tSqlExprCreateIdValue(pInfo, &X, TK_INTEGER);}
expr(A) ::= FLOAT(X).            { A = tSqlExprCreateIdValue(pInfo, &X, TK_FLOAT);}
expr(A) ::= MINUS(X) FLOAT(Y).   { X.n += Y.n; X.type = TK_FLOAT; A = tSqlExprCreateIdValue(pInfo, &X, TK_FLOAT);}
expr(A) ::= PLUS(X) FLOAT(Y).    { X.n += Y.n; X.type = TK_FLOAT; A = tSqlExprCreateIdValue(pInfo, &X, TK_FLOAT);}
expr(A) ::= STRING(X).           { A = tSqlExprCreateIdValue(pInfo, &X, TK_STRING);}
expr(A) ::= NOW(X).              { A = tSqlExprCreateIdValue(pInfo, &X, TK_NOW); }
767
expr(A) ::= TODAY(X).            { A = tSqlExprCreateIdValue(pInfo, &X, TK_TODAY); }
768 769 770 771 772
expr(A) ::= VARIABLE(X).         { A = tSqlExprCreateIdValue(pInfo, &X, TK_VARIABLE);}
expr(A) ::= PLUS(X) VARIABLE(Y).   { X.n += Y.n; X.type = TK_VARIABLE; A = tSqlExprCreateIdValue(pInfo, &X, TK_VARIABLE);}
expr(A) ::= MINUS(X) VARIABLE(Y).  { X.n += Y.n; X.type = TK_VARIABLE; A = tSqlExprCreateIdValue(pInfo, &X, TK_VARIABLE);}
expr(A) ::= BOOL(X).             { A = tSqlExprCreateIdValue(pInfo, &X, TK_BOOL);}
expr(A) ::= NULL(X).             { A = tSqlExprCreateIdValue(pInfo, &X, TK_NULL);}
H
Haojun Liao 已提交
773 774

// ordinary functions: min(x), max(x), top(k, 20)
D
dapan1121 已提交
775
expr(A) ::= ID(X) LP exprlist(Y) RP(E). { tStrTokenAppend(pInfo->funcs, &X); A = tSqlExprCreateFunction(Y, &X, &E, X.type); }
H
Haojun Liao 已提交
776 777

// for parsing sql functions with wildcard for parameters. e.g., count(*)/first(*)/last(*) operation
D
dapan1121 已提交
778
expr(A) ::= ID(X) LP STAR RP(Y).     { tStrTokenAppend(pInfo->funcs, &X); A = tSqlExprCreateFunction(NULL, &X, &Y, X.type); }
H
Haojun Liao 已提交
779

D
cast  
dapan1121 已提交
780 781 782
// for parsing sql function CAST(column as typename) 
expr(A) ::= ID(X) LP expr(B) AS typename(C) RP(Y).     { tStrTokenAppend(pInfo->funcs, &X); A = tSqlExprCreateFuncWithParams(pInfo, B, &C, &X, &Y, X.type); }

H
Haojun Liao 已提交
783
// is (not) null expression
D
dapan1121 已提交
784 785
expr(A) ::= expr(X) IS NULL.           {A = tSqlExprCreate(X, NULL, TK_ISNULL);}
expr(A) ::= expr(X) IS NOT NULL.       {A = tSqlExprCreate(X, NULL, TK_NOTNULL);}
H
Haojun Liao 已提交
786 787

// relational expression
D
dapan1121 已提交
788 789 790 791 792 793
expr(A) ::= expr(X) LT expr(Y).      {A = tSqlExprCreate(X, Y, TK_LT);}
expr(A) ::= expr(X) GT expr(Y).      {A = tSqlExprCreate(X, Y, TK_GT);}
expr(A) ::= expr(X) LE expr(Y).      {A = tSqlExprCreate(X, Y, TK_LE);}
expr(A) ::= expr(X) GE expr(Y).      {A = tSqlExprCreate(X, Y, TK_GE);}
expr(A) ::= expr(X) NE expr(Y).      {A = tSqlExprCreate(X, Y, TK_NE);}
expr(A) ::= expr(X) EQ expr(Y).      {A = tSqlExprCreate(X, Y, TK_EQ);}
H
Haojun Liao 已提交
794

H
Haojun Liao 已提交
795
expr(A) ::= expr(X) BETWEEN expr(Y) AND expr(Z).      { tSqlExpr* X2 = tSqlExprClone(X); A = tSqlExprCreate(tSqlExprCreate(X, Y, TK_GE), tSqlExprCreate(X2, Z, TK_LE), TK_AND);}
D
dapan1121 已提交
796

D
dapan1121 已提交
797 798
expr(A) ::= expr(X) AND expr(Y).     {A = tSqlExprCreate(X, Y, TK_AND);}
expr(A) ::= expr(X) OR  expr(Y).     {A = tSqlExprCreate(X, Y, TK_OR); }
H
Haojun Liao 已提交
799 800

// binary arithmetic expression
D
dapan1121 已提交
801 802 803 804 805
expr(A) ::= expr(X) PLUS  expr(Y).   {A = tSqlExprCreate(X, Y, TK_PLUS);  }
expr(A) ::= expr(X) MINUS expr(Y).   {A = tSqlExprCreate(X, Y, TK_MINUS); }
expr(A) ::= expr(X) STAR  expr(Y).   {A = tSqlExprCreate(X, Y, TK_STAR);  }
expr(A) ::= expr(X) SLASH expr(Y).   {A = tSqlExprCreate(X, Y, TK_DIVIDE);}
expr(A) ::= expr(X) REM   expr(Y).   {A = tSqlExprCreate(X, Y, TK_REM);   }
X
xywang 已提交
806
expr(A) ::= expr(X) BITAND expr(Y).  {A = tSqlExprCreate(X, Y, TK_BITAND);}
X
xywang 已提交
807 808 809 810 811
expr(A) ::= expr(X) BITOR expr(Y).   {A = tSqlExprCreate(X, Y, TK_BITOR); }
expr(A) ::= expr(X) BITXOR expr(Y).  {A = tSqlExprCreate(X, Y, TK_BITXOR);}
expr(A) ::= BITNOT expr(X).          {A = tSqlExprCreate(X, NULL, TK_BITNOT);}
expr(A) ::= expr(X) LSHIFT expr(Y).  {A = tSqlExprCreate(X, Y, TK_LSHIFT);}
expr(A) ::= expr(X) RSHIFT expr(Y).  {A = tSqlExprCreate(X, Y, TK_RSHIFT);}
H
hzcheng 已提交
812

H
Haojun Liao 已提交
813
// like expression
D
dapan1121 已提交
814
expr(A) ::= expr(X) LIKE expr(Y).    {A = tSqlExprCreate(X, Y, TK_LIKE);  }
H
hzcheng 已提交
815

816 817
// match expression
expr(A) ::= expr(X) MATCH expr(Y).    {A = tSqlExprCreate(X, Y, TK_MATCH);  }
818
expr(A) ::= expr(X) NMATCH expr(Y).    {A = tSqlExprCreate(X, Y, TK_NMATCH);  }
819

820 821 822
// contains expression
expr(A) ::= ID(X) CONTAINS STRING(Y).    { tSqlExpr* S = tSqlExprCreateIdValue(pInfo, &X, TK_ID); tSqlExpr* M = tSqlExprCreateIdValue(pInfo, &Y, TK_STRING); A = tSqlExprCreate(S, M, TK_CONTAINS);  }
expr(A) ::= ID(X) DOT ID(Y) CONTAINS STRING(Z).    { X.n += (1+Y.n); tSqlExpr* S = tSqlExprCreateIdValue(pInfo, &X, TK_ID); tSqlExpr* M = tSqlExprCreateIdValue(pInfo, &Z, TK_STRING); A = tSqlExprCreate(S, M, TK_CONTAINS);  }
wmmhello's avatar
wmmhello 已提交
823 824

// arrow expression
wmmhello's avatar
wmmhello 已提交
825 826 827 828 829 830
%type arrow {tSqlExpr*}
%destructor arrow {tSqlExprDestroy($$);}
arrow(A) ::= ID(X) ARROW STRING(Y).    {tSqlExpr* S = tSqlExprCreateIdValue(pInfo, &X, TK_ID); tSqlExpr* M = tSqlExprCreateIdValue(pInfo, &Y, TK_STRING); A = tSqlExprCreate(S, M, TK_ARROW);  }
arrow(A) ::= ID(X) DOT ID(Y) ARROW STRING(Z).    {X.n += (1+Y.n); tSqlExpr* S = tSqlExprCreateIdValue(pInfo, &X, TK_ID); tSqlExpr* M = tSqlExprCreateIdValue(pInfo, &Z, TK_STRING); A = tSqlExprCreate(S, M, TK_ARROW);  }

expr(A) ::= arrow(X). {A = X;}
wmmhello's avatar
wmmhello 已提交
831

H
hzcheng 已提交
832
//in expression
H
Haojun Liao 已提交
833
expr(A) ::= expr(X) IN LP exprlist(Y) RP.   {A = tSqlExprCreate(X, (tSqlExpr*)Y, TK_IN); }
H
hzcheng 已提交
834

H
Haojun Liao 已提交
835
%type exprlist {SArray*}
D
dapan1121 已提交
836
%destructor exprlist {tSqlExprListDestroy($$);}
H
hzcheng 已提交
837

H
Haojun Liao 已提交
838
%type expritem {tSqlExpr*}
D
dapan1121 已提交
839
%destructor expritem {tSqlExprDestroy($$);}
H
hzcheng 已提交
840

dengyihao's avatar
TD-2571  
dengyihao 已提交
841 842
exprlist(A) ::= exprlist(X) COMMA expritem(Y). {A = tSqlExprListAppend(X,Y,0, 0);}
exprlist(A) ::= expritem(X).                   {A = tSqlExprListAppend(0,X,0, 0);}
H
Haojun Liao 已提交
843 844
expritem(A) ::= expr(X).                       {A = X;}
expritem(A) ::= .                              {A = 0;}
H
hzcheng 已提交
845 846

///////////////////////////////////reset query cache//////////////////////////////////////
H
Haojun Liao 已提交
847
cmd ::= RESET QUERY CACHE.  { setDCLSqlElems(pInfo, TSDB_SQL_RESET_CACHE, 0);}
H
hzcheng 已提交
848

849 850 851
///////////////////////////////////sync replica database//////////////////////////////////
cmd ::= SYNCDB ids(X) REPLICA.{ setDCLSqlElems(pInfo, TSDB_SQL_SYNC_DB_REPLICA, 1, &X);}

H
hzcheng 已提交
852 853 854
///////////////////////////////////ALTER TABLE statement//////////////////////////////////
cmd ::= ALTER TABLE ids(X) cpxName(F) ADD COLUMN columnlist(A).     {
    X.n += F.n;
H
Haojun Liao 已提交
855
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, -1);
D
dapan1121 已提交
856
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
H
hzcheng 已提交
857 858 859 860 861 862
}

cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A).     {
    X.n += F.n;

    toTSDBType(A.type);
863
    SArray* K = tVariantListAppendToken(NULL, &A, -1, false);
H
hzcheng 已提交
864

H
Haojun Liao 已提交
865
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, -1);
D
dapan1121 已提交
866
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
H
hzcheng 已提交
867 868
}

D
dapan1121 已提交
869
cmd ::= ALTER TABLE ids(X) cpxName(F) MODIFY COLUMN columnlist(A).     {
D
dapan1121 已提交
870
    X.n += F.n;
D
dapan1121 已提交
871
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, -1);
D
dapan1121 已提交
872 873 874
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}

H
hzcheng 已提交
875 876 877
//////////////////////////////////ALTER TAGS statement/////////////////////////////////////
cmd ::= ALTER TABLE ids(X) cpxName(Y) ADD TAG columnlist(A).        {
    X.n += Y.n;
H
Haojun Liao 已提交
878
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, -1);
D
dapan1121 已提交
879
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
H
hzcheng 已提交
880 881 882 883 884
}
cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y).          {
    X.n += Z.n;

    toTSDBType(Y.type);
885
    SArray* A = tVariantListAppendToken(NULL, &Y, -1, false);
H
hzcheng 已提交
886

H
Haojun Liao 已提交
887
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, -1);
D
dapan1121 已提交
888
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
H
hzcheng 已提交
889 890 891 892 893 894
}

cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
    X.n += F.n;

    toTSDBType(Y.type);
895
    SArray* A = tVariantListAppendToken(NULL, &Y, -1, false);
H
hzcheng 已提交
896 897

    toTSDBType(Z.type);
898
    A = tVariantListAppendToken(A, &Z, -1, false);
H
hzcheng 已提交
899

H
Haojun Liao 已提交
900
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, -1);
D
dapan1121 已提交
901
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
H
hzcheng 已提交
902 903
}

904
cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z).     {
H
hzcheng 已提交
905 906 907
    X.n += F.n;

    toTSDBType(Y.type);
908
    SArray* A = tVariantListAppendToken(NULL, &Y, -1, false);
H
hzcheng 已提交
909 910
    A = tVariantListAppend(A, &Z, -1);

H
Haojun Liao 已提交
911
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, -1);
D
dapan1121 已提交
912 913 914
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}

D
dapan1121 已提交
915 916 917 918 919
cmd ::= ALTER TABLE ids(X) cpxName(F) MODIFY TAG columnlist(A).     {
    X.n += F.n;
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, -1);
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
D
dapan1121 已提交
920 921 922 923

///////////////////////////////////ALTER STABLE statement//////////////////////////////////
cmd ::= ALTER STABLE ids(X) cpxName(F) ADD COLUMN columnlist(A).     {
    X.n += F.n;
H
Haojun Liao 已提交
924
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_COLUMN, TSDB_SUPER_TABLE);
D
dapan1121 已提交
925 926 927 928 929 930 931
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}

cmd ::= ALTER STABLE ids(X) cpxName(F) DROP COLUMN ids(A).     {
    X.n += F.n;

    toTSDBType(A.type);
932
    SArray* K = tVariantListAppendToken(NULL, &A, -1, false);
D
dapan1121 已提交
933

H
Haojun Liao 已提交
934
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN, TSDB_SUPER_TABLE);
D
dapan1121 已提交
935 936 937
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}

D
dapan1121 已提交
938
cmd ::= ALTER STABLE ids(X) cpxName(F) MODIFY COLUMN columnlist(A).     {
D
dapan1121 已提交
939
    X.n += F.n;
D
dapan1121 已提交
940
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_CHANGE_COLUMN, TSDB_SUPER_TABLE);
D
dapan1121 已提交
941 942 943
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}

D
dapan1121 已提交
944 945 946
//////////////////////////////////ALTER TAGS statement/////////////////////////////////////
cmd ::= ALTER STABLE ids(X) cpxName(Y) ADD TAG columnlist(A).        {
    X.n += Y.n;
H
Haojun Liao 已提交
947
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_ADD_TAG_COLUMN, TSDB_SUPER_TABLE);
D
dapan1121 已提交
948 949 950 951 952 953
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}
cmd ::= ALTER STABLE ids(X) cpxName(Z) DROP TAG ids(Y).          {
    X.n += Z.n;

    toTSDBType(Y.type);
954
    SArray* A = tVariantListAppendToken(NULL, &Y, -1, false);
D
dapan1121 已提交
955

H
Haojun Liao 已提交
956
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN, TSDB_SUPER_TABLE);
D
dapan1121 已提交
957 958 959 960 961 962 963
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}

cmd ::= ALTER STABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
    X.n += F.n;

    toTSDBType(Y.type);
964
    SArray* A = tVariantListAppendToken(NULL, &Y, -1, false);
D
dapan1121 已提交
965 966

    toTSDBType(Z.type);
967
    A = tVariantListAppendToken(A, &Z, -1, false);
D
dapan1121 已提交
968

H
Haojun Liao 已提交
969
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_CHANGE_TAG_COLUMN, TSDB_SUPER_TABLE);
D
dapan1121 已提交
970
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
H
hzcheng 已提交
971 972
}

D
dapan1121 已提交
973 974 975 976
cmd ::= ALTER STABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z).     {
    X.n += F.n;

    toTSDBType(Y.type);
977
    SArray* A = tVariantListAppendToken(NULL, &Y, -1, false);
D
dapan1121 已提交
978 979 980 981 982 983 984 985 986 987 988 989
    A = tVariantListAppend(A, &Z, -1);

    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL, TSDB_SUPER_TABLE);
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}

cmd ::= ALTER STABLE ids(X) cpxName(F) MODIFY TAG columnlist(A).     {
    X.n += F.n;
    SAlterTableInfo* pAlterTable = tSetAlterTableInfo(&X, A, NULL, TSDB_ALTER_TABLE_MODIFY_TAG_COLUMN, TSDB_SUPER_TABLE);
    setSqlInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
}

H
hzcheng 已提交
990
////////////////////////////////////////kill statement///////////////////////////////////////
D
dapan1121 已提交
991 992 993
cmd ::= KILL CONNECTION INTEGER(Y).   {setKillSql(pInfo, TSDB_SQL_KILL_CONNECTION, &Y);}
cmd ::= KILL STREAM INTEGER(X) COLON(Z) INTEGER(Y).       {X.n += (Z.n + Y.n); setKillSql(pInfo, TSDB_SQL_KILL_STREAM, &X);}
cmd ::= KILL QUERY INTEGER(X) COLON(Z) INTEGER(Y).        {X.n += (Z.n + Y.n); setKillSql(pInfo, TSDB_SQL_KILL_QUERY, &X);}
H
hzcheng 已提交
994

995 996 997 998 999 1000 1001 1002 1003
//////////////////////////////////// DEL TRUNCATE TABLE /////////////////////////////////////

//1 DELETE FROM TBNAME/STBNAME WHERE TS AND TAG CONDICTION
cmd ::= DELETE FROM ifexists(Y) ids(X) cpxName(Z) where_opt(W). {
  X.n += Z.n; 
  SDelData * pDelData = tGetDelData(&X, &Y, W);
  setSqlInfo(pInfo, pDelData, NULL, TSDB_SQL_DELETE_DATA);
}

H
hzcheng 已提交
1004 1005
%fallback ID ABORT AFTER ASC ATTACH BEFORE BEGIN CASCADE CLUSTER CONFLICT COPY DATABASE DEFERRED
  DELIMITERS DESC DETACH EACH END EXPLAIN FAIL FOR GLOB IGNORE IMMEDIATE INITIALLY INSTEAD
1006
  LIKE MATCH NMATCH KEY OF OFFSET RAISE REPLACE RESTRICT ROW STATEMENT TRIGGER VIEW ALL
X
xywang 已提交
1007
  NOW TODAY IPTOKEN SEMI NONE PREV LINEAR IMPORT TBNAME JOIN STABLE NULL INSERT INTO VALUES FILE.