Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
9487c1b9
T
TDengine
项目概览
taosdata
/
TDengine
大约 1 年 前同步成功
通知
1184
Star
22015
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
9487c1b9
编写于
11月 09, 2020
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[TD-1978]
上级
2b9a3b1e
变更
9
展开全部
显示空白变更内容
内联
并排
Showing
9 changed file
with
369 addition
and
390 deletion
+369
-390
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+172
-121
src/common/inc/tname.h
src/common/inc/tname.h
+0
-4
src/query/inc/qAst.h
src/query/inc/qAst.h
+1
-2
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+37
-59
src/query/inc/sql.y
src/query/inc/sql.y
+25
-25
src/query/src/qParserImpl.c
src/query/src/qParserImpl.c
+54
-124
src/query/src/sql.c
src/query/src/sql.c
+50
-55
src/util/inc/tarray.h
src/util/inc/tarray.h
+14
-0
src/util/src/tarray.c
src/util/src/tarray.c
+16
-0
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
9487c1b9
此差异已折叠。
点击以展开。
src/common/inc/tname.h
浏览文件 @
9487c1b9
...
...
@@ -35,10 +35,6 @@ bool tscValidateTableNameLength(size_t len);
SColumnFilterInfo
*
tscFilterInfoClone
(
const
SColumnFilterInfo
*
src
,
int32_t
numOfFilters
);
/**
* get the schema for the "tbname" column. it is a built column
* @return
*/
SSchema
tscGetTbnameColumnSchema
();
#endif // TDENGINE_NAME_H
src/query/inc/qAst.h
浏览文件 @
9487c1b9
...
...
@@ -74,8 +74,6 @@ typedef struct tExprNode {
};
}
tExprNode
;
void
tExprTreeDestroy
(
tExprNode
**
pExprs
,
void
(
*
fp
)(
void
*
));
void
tExprTreeTraverse
(
tExprNode
*
pExpr
,
SSkipList
*
pSkipList
,
SArray
*
result
,
SExprTraverseSupp
*
param
);
void
tExprTreeCalcTraverse
(
tExprNode
*
pExprs
,
int32_t
numOfRows
,
char
*
pOutput
,
void
*
param
,
int32_t
order
,
...
...
@@ -87,6 +85,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond);
void
exprTreeToBinary
(
SBufferWriter
*
bw
,
tExprNode
*
pExprTree
);
void
tExprNodeDestroy
(
tExprNode
*
pNode
,
void
(
*
fp
)(
void
*
));
void
tExprTreeDestroy
(
tExprNode
**
pExprs
,
void
(
*
fp
)(
void
*
));
#ifdef __cplusplus
}
...
...
src/query/inc/qSqlparser.h
浏览文件 @
9487c1b9
...
...
@@ -20,10 +20,10 @@
extern
"C"
{
#endif
#include <tstrbuild.h>
#include "taos.h"
#include "taosmsg.h"
#include "tstoken.h"
#include "tstrbuild.h"
#include "tvariant.h"
#define ParseTOKENTYPE SStrToken
...
...
@@ -38,12 +38,6 @@ extern char tTokenTypeSwitcher[13];
} \
} while (0)
typedef
struct
tFieldList
{
int32_t
nField
;
int32_t
nAlloc
;
TAOS_FIELD
*
p
;
}
tFieldList
;
typedef
struct
SLimitVal
{
int64_t
limit
;
int64_t
offset
;
...
...
@@ -59,12 +53,6 @@ typedef struct tVariantListItem {
uint8_t
sortOrder
;
}
tVariantListItem
;
typedef
struct
tVariantList
{
int32_t
nExpr
;
/* Number of expressions on the list */
int32_t
nAlloc
;
/* Number of entries allocated below */
tVariantListItem
*
a
;
/* One entry for each expression */
}
tVariantList
;
typedef
struct
SIntervalVal
{
SStrToken
interval
;
SStrToken
offset
;
...
...
@@ -72,16 +60,16 @@ typedef struct SIntervalVal {
typedef
struct
SQuerySQL
{
struct
tSQLExprList
*
pSelection
;
// select clause
tVariantList
*
from
;
// from clause
SArray
*
from
;
// from clause SArray<tVariantListItem>
struct
tSQLExpr
*
pWhere
;
// where clause [optional]
tVariantList
*
pGroupby
;
// groupby clause, only for tags[optional]
tVariantList
*
pSortOrder
;
// orderby [optional]
SArray
*
pGroupby
;
// groupby clause, only for tags[optional], SArray<tVariantListItem>
SArray
*
pSortOrder
;
// orderby [optional], SArray<tVariantListItem>
SStrToken
interval
;
// interval [optional]
SStrToken
offset
;
// offset window [optional]
SStrToken
sliding
;
// sliding window [optional]
SLimitVal
limit
;
// limit offset [optional]
SLimitVal
slimit
;
// group limit offset [optional]
tVariantList
*
fillType
;
// fill type[optional]
SArray
*
fillType
;
// fill type[optional], SArray<tVariantListItem>
SStrToken
selectToken
;
// sql string
}
SQuerySQL
;
...
...
@@ -91,13 +79,13 @@ typedef struct SCreateTableSQL {
int8_t
type
;
// create normal table/from super table/ stream
struct
{
tFieldList
*
pTagColumns
;
// for normal table, pTagColumns = NULL;
tFieldList
*
pColumns
;
SArray
*
pTagColumns
;
// SArray<TAOS_FIELD>
SArray
*
pColumns
;
// SArray<TAOS_FIELD>
}
colInfo
;
struct
{
SStrToken
stableName
;
// super table name, for using clause
tVariantList
*
pTagVals
;
// create by using metric, tag value
SArray
*
pTagVals
;
// create by using metric, tag value
STagData
tagdata
;
}
usingInfo
;
...
...
@@ -108,9 +96,8 @@ typedef struct SAlterTableSQL {
SStrToken
name
;
int16_t
type
;
STagData
tagData
;
tFieldList
*
pAddColumns
;
tVariantList
*
varList
;
// set t=val or: change src dst
SArray
*
pAddColumns
;
// SArray<TAOS_FIELD>
SArray
*
varList
;
// set t=val or: change src dst, SArray<tVariantListItem>
}
SAlterTableSQL
;
typedef
struct
SCreateDBInfo
{
...
...
@@ -130,7 +117,7 @@ typedef struct SCreateDBInfo {
SStrToken
precision
;
bool
ignoreExists
;
tVariantList
*
keep
;
SArray
*
keep
;
}
SCreateDBInfo
;
typedef
struct
SCreateAcctSQL
{
...
...
@@ -186,8 +173,8 @@ typedef struct SSqlInfo {
union
{
SCreateTableSQL
*
pCreateTableInfo
;
SAlterTableSQL
*
pAlterInfo
;
tDCLSQL
*
pDCLInfo
;
SAlterTableSQL
*
pAlterInfo
;
tDCLSQL
*
pDCLInfo
;
};
SSubclauseInfo
subclauseInfo
;
...
...
@@ -195,19 +182,18 @@ typedef struct SSqlInfo {
}
SSqlInfo
;
typedef
struct
tSQLExpr
{
// TK_FUNCTION: sql function, TK_LE: less than(binary expr)
uint32_t
nSQLOptr
;
uint32_t
nSQLOptr
;
// TK_FUNCTION: sql function, TK_LE: less than(binary expr)
// the full sql string of function(col, param), which is actually the raw
// field name, since the function name is kept in nSQLOptr already
SStrToken
operand
;
SStrToken
colInfo
;
// field id
tVariant
val
;
// value only for string, float, int
SStrToken
token
;
// original sql expr string
struct
tSQLExpr
*
pLeft
;
// left child
struct
tSQLExpr
*
pRight
;
// right child
struct
tSQLExprList
*
pParam
;
// function parameters
SStrToken
token
;
// original sql expr string
}
tSQLExpr
;
// used in select clause. select <tSQLExprList> from xxx
...
...
@@ -238,16 +224,9 @@ void Parse(void *yyp, int yymajor, ParseTOKENTYPE yyminor, SSqlInfo *);
*/
void
ParseFree
(
void
*
p
,
void
(
*
freeProc
)(
void
*
));
tVariantList
*
tVariantListAppend
(
tVariantList
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
);
tVariantList
*
tVariantListInsert
(
tVariantList
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
,
int32_t
index
);
tVariantList
*
tVariantListAppendToken
(
tVariantList
*
pList
,
SStrToken
*
pAliasToken
,
uint8_t
sortOrder
);
void
tVariantListDestroy
(
tVariantList
*
pList
);
tFieldList
*
tFieldListAppend
(
tFieldList
*
pList
,
TAOS_FIELD
*
pField
);
void
tFieldListDestroy
(
tFieldList
*
pList
);
SArray
*
tVariantListAppend
(
SArray
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
);
SArray
*
tVariantListInsert
(
SArray
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
,
int32_t
index
);
SArray
*
tVariantListAppendToken
(
SArray
*
pList
,
SStrToken
*
pAliasToken
,
uint8_t
sortOrder
);
tSQLExpr
*
tSQLExprCreate
(
tSQLExpr
*
pLeft
,
tSQLExpr
*
pRight
,
int32_t
optType
);
...
...
@@ -257,17 +236,16 @@ tSQLExprList *tSQLExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken
void
tSQLExprListDestroy
(
tSQLExprList
*
pList
);
SQuerySQL
*
tSetQuerySQLElems
(
SStrToken
*
pSelectToken
,
tSQLExprList
*
pSelection
,
tVariantList
*
pFrom
,
tSQLExpr
*
pWhere
,
tVariantList
*
pGroupby
,
tVariantList
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SStrToken
*
pSliding
,
tVariantList
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pGLimit
);
SQuerySQL
*
tSetQuerySQLElems
(
SStrToken
*
pSelectToken
,
tSQLExprList
*
pSelection
,
SArray
*
pFrom
,
tSQLExpr
*
pWhere
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pGLimit
);
SCreateTableSQL
*
tSetCreateSQLElems
(
tFieldList
*
pCols
,
tFieldList
*
pTags
,
SStrToken
*
pMetricName
,
tVariantList
*
pTagVals
,
SQuerySQL
*
pSelect
,
int32_t
type
);
SCreateTableSQL
*
tSetCreateSQLElems
(
SArray
*
pCols
,
SArray
*
pTags
,
SStrToken
*
pMetricName
,
SArray
*
pTagVals
,
SQuerySQL
*
pSelect
,
int32_t
type
);
void
tSQLExprNodeDestroy
(
tSQLExpr
*
pExpr
);
tSQLExpr
*
tSQLExprNodeClone
(
tSQLExpr
*
pExpr
);
SAlterTableSQL
*
tAlterTableSQLElems
(
SStrToken
*
pMeterName
,
tFieldList
*
pCols
,
tVariantList
*
pVals
,
int32_t
type
);
SAlterTableSQL
*
tAlterTableSQLElems
(
SStrToken
*
pMeterName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
);
void
destroyAllSelectClause
(
SSubclauseInfo
*
pSql
);
void
doDestroyQuerySql
(
SQuerySQL
*
pSql
);
...
...
src/query/inc/sql.y
浏览文件 @
9487c1b9
...
...
@@ -223,8 +223,8 @@ acct_optr(Y) ::= pps(C) tseries(D) storage(P) streams(F) qtime(Q) dbs(E) users(K
Y.stat = M;
}
%type keep {
tVariantList
*}
%destructor keep {t
VariantList
Destroy($$);}
%type keep {
SArray
*}
%destructor keep {t
aosArray
Destroy($$);}
keep(Y) ::= KEEP tagitemlist(X). { Y = X; }
cache(Y) ::= CACHE INTEGER(X). { Y = X; }
...
...
@@ -324,10 +324,10 @@ create_table_args(A) ::= AS select(S). {
}
%type column{TAOS_FIELD}
%type columnlist{
tFieldList
*}
%destructor columnlist {t
FieldList
Destroy($$);}
columnlist(A) ::= columnlist(X) COMMA column(Y). {A = t
FieldListAppend
(X, &Y); }
columnlist(A) ::= column(X). {A = t
FieldListAppend(NULL
, &X);}
%type columnlist{
SArray
*}
%destructor columnlist {t
aosArray
Destroy($$);}
columnlist(A) ::= columnlist(X) COMMA column(Y). {A = t
aosArrayPush
(X, &Y); }
columnlist(A) ::= column(X). {A = t
aosArrayInit(4, sizeof(TAOS_FIELD)); taosArrayPush(A
, &X);}
// 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)
...
...
@@ -335,8 +335,8 @@ column(A) ::= ids(X) typename(Y). {
tSQLSetColumnInfo(&A, &X, &Y);
}
%type tagitemlist {
tVariantList
*}
%destructor tagitemlist {t
VariantList
Destroy($$);}
%type tagitemlist {
SArray
*}
%destructor tagitemlist {t
aosArray
Destroy($$);}
%type tagitem {tVariant}
tagitemlist(A) ::= tagitemlist(X) COMMA tagitem(Y). { A = tVariantListAppend(X, &Y, -1); }
...
...
@@ -429,11 +429,11 @@ as(X) ::= ids(Y). { X = Y; }
as(X) ::= . { X.n = 0; }
// A complete FROM clause.
%type from {
tVariantList
*}
%type from {
SArray
*}
// current not support query from no-table
from(A) ::= FROM tablelist(X). {A = X;}
%type tablelist {
tVariantList
*}
%type tablelist {
SArray
*}
tablelist(A) ::= ids(X) cpxName(Y). {
toTSDBType(X.type);
X.n += Y.n;
...
...
@@ -473,15 +473,15 @@ interval_opt(N) ::= INTERVAL LP tmvar(E) RP. {N.interval = E; N.offset.n = 0;
interval_opt(N) ::= INTERVAL LP tmvar(E) COMMA tmvar(O) RP. {N.interval = E; N.offset = O;}
interval_opt(N) ::= . {memset(&N, 0, sizeof(N));}
%type fill_opt {
tVariantList
*}
%destructor fill_opt {t
VariantList
Destroy($$);}
%type fill_opt {
SArray
*}
%destructor fill_opt {t
aosArray
Destroy($$);}
fill_opt(N) ::= . {N = 0; }
fill_opt(N) ::= FILL LP ID(Y) COMMA tagitemlist(X) RP. {
tVariant A = {0};
toTSDBType(Y.type);
tVariantCreate(&A, &Y);
t
VariantListInsert(X, &A, -1, 0
);
t
aosArrayPush(X, &A
);
N = X;
}
...
...
@@ -494,11 +494,11 @@ fill_opt(N) ::= FILL LP ID(Y) RP. {
sliding_opt(K) ::= SLIDING LP tmvar(E) RP. {K = E; }
sliding_opt(K) ::= . {K.n = 0; K.z = NULL; K.type = 0; }
%type orderby_opt {
tVariantList
*}
%destructor orderby_opt {t
VariantList
Destroy($$);}
%type orderby_opt {
SArray
*}
%destructor orderby_opt {t
aosArray
Destroy($$);}
%type sortlist {
tVariantList
*}
%destructor sortlist {t
VariantList
Destroy($$);}
%type sortlist {
SArray
*}
%destructor sortlist {t
aosArray
Destroy($$);}
%type sortitem {tVariant}
%destructor sortitem {tVariantDestroy(&$$);}
...
...
@@ -528,10 +528,10 @@ sortorder(A) ::= DESC. {A = TSDB_ORDER_DESC;}
sortorder(A) ::= . {A = TSDB_ORDER_ASC;} //default is descend order
//group by clause
%type groupby_opt {
tVariantList
*}
%destructor groupby_opt {t
VariantList
Destroy($$);}
%type grouplist {
tVariantList
*}
%destructor grouplist {t
VariantList
Destroy($$);}
%type groupby_opt {
SArray
*}
%destructor groupby_opt {t
aosArray
Destroy($$);}
%type grouplist {
SArray
*}
%destructor grouplist {t
aosArray
Destroy($$);}
groupby_opt(A) ::= . {A = 0;}
groupby_opt(A) ::= GROUP BY grouplist(X). {A = X;}
...
...
@@ -654,7 +654,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) DROP COLUMN ids(A). {
X.n += F.n;
toTSDBType(A.type);
tVariantList
* K = tVariantListAppendToken(NULL, &A, -1);
SArray
* K = tVariantListAppendToken(NULL, &A, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, K, TSDB_ALTER_TABLE_DROP_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
...
...
@@ -670,7 +670,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(Z) DROP TAG ids(Y). {
X.n += Z.n;
toTSDBType(Y.type);
tVariantList
* A = tVariantListAppendToken(NULL, &Y, -1);
SArray
* A = tVariantListAppendToken(NULL, &Y, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, TSDB_ALTER_TABLE_DROP_TAG_COLUMN);
setSQLInfo(pInfo, pAlterTable, NULL, TSDB_SQL_ALTER_TABLE);
...
...
@@ -680,7 +680,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) CHANGE TAG ids(Y) ids(Z). {
X.n += F.n;
toTSDBType(Y.type);
tVariantList
* A = tVariantListAppendToken(NULL, &Y, -1);
SArray
* A = tVariantListAppendToken(NULL, &Y, -1);
toTSDBType(Z.type);
A = tVariantListAppendToken(A, &Z, -1);
...
...
@@ -693,7 +693,7 @@ cmd ::= ALTER TABLE ids(X) cpxName(F) SET TAG ids(Y) EQ tagitem(Z). {
X.n += F.n;
toTSDBType(Y.type);
tVariantList
* A = tVariantListAppendToken(NULL, &Y, -1);
SArray
* A = tVariantListAppendToken(NULL, &Y, -1);
A = tVariantListAppend(A, &Z, -1);
SAlterTableSQL* pAlterTable = tAlterTableSQLElems(&X, NULL, A, TSDB_ALTER_TABLE_UPDATE_TAG_VAL);
...
...
src/query/src/qParserImpl.c
浏览文件 @
9487c1b9
...
...
@@ -15,11 +15,9 @@
#include "os.h"
#include "qSqlparser.h"
#include "queryLog.h"
#include "taosdef.h"
#include "taosmsg.h"
#include "tcmdtype.h"
#include "tglobal.h"
#include "tstoken.h"
#include "tstrbuild.h"
#include "ttokendef.h"
...
...
@@ -314,132 +312,58 @@ void tSQLExprDestroy(tSQLExpr *pExpr) {
tSQLExprNodeDestroy
(
pExpr
);
}
static
void
*
tVariantListExpand
(
tVariantList
*
pList
)
{
if
(
pList
->
nAlloc
<=
pList
->
nExpr
)
{
//
int32_t
newSize
=
(
pList
->
nAlloc
<<
1
)
+
4
;
void
*
ptr
=
realloc
(
pList
->
a
,
newSize
*
sizeof
(
pList
->
a
[
0
]));
if
(
ptr
==
0
)
{
return
NULL
;
}
pList
->
nAlloc
=
newSize
;
pList
->
a
=
ptr
;
}
assert
(
pList
->
a
!=
0
);
return
pList
;
}
tVariantList
*
tVariantListAppend
(
tVariantList
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
)
{
SArray
*
tVariantListAppendToken
(
SArray
*
pList
,
SStrToken
*
pToken
,
uint8_t
order
)
{
if
(
pList
==
NULL
)
{
pList
=
calloc
(
1
,
sizeof
(
tVariantList
));
pList
=
taosArrayInit
(
4
,
sizeof
(
tVariantListItem
));
}
if
(
tVariantListExpand
(
pList
)
==
NULL
)
{
return
pList
;
}
if
(
pToken
)
{
tVariantListItem
item
=
{
0
};
tVariantCreate
(
&
item
.
pVar
,
pToken
);
item
.
sortOrder
=
order
;
if
(
pVar
)
{
tVariantListItem
*
pItem
=
&
pList
->
a
[
pList
->
nExpr
++
];
/*
* Here we do not employ the assign function, since we need the pz attribute of structure
* , which is the point to char string, to free it!
*
* Otherwise, the original pointer may be lost, which causes memory leak.
*/
memcpy
(
pItem
,
pVar
,
sizeof
(
tVariant
));
pItem
->
sortOrder
=
sortOrder
;
taosArrayPush
(
pList
,
&
item
);
}
return
pList
;
}
tVariantList
*
tVariantListInsert
(
tVariantList
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
,
int32_t
index
)
{
if
(
pList
==
NULL
||
index
>=
pList
->
nExpr
)
{
return
tVariantListAppend
(
NULL
,
pVar
,
sortOrder
);
SArray
*
tVariantListAppend
(
SArray
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
)
{
if
(
pList
==
NULL
)
{
pList
=
taosArrayInit
(
4
,
sizeof
(
tVariantListItem
)
);
}
if
(
tVariantListExpand
(
pList
)
==
NULL
)
{
if
(
pVar
==
NULL
)
{
return
pList
;
}
if
(
pVar
)
{
memmove
(
&
pList
->
a
[
index
+
1
],
&
pList
->
a
[
index
],
sizeof
(
tVariantListItem
)
*
(
pList
->
nExpr
-
index
));
tVariantListItem
*
pItem
=
&
pList
->
a
[
index
];
/*
* Here we do not employ the assign function, since we need the pz attribute of structure
* , which is the point to char string, to free it!
*
* Otherwise, the original pointer may be lost, which causes memory leak.
*/
memcpy
(
pItem
,
pVar
,
sizeof
(
tVariant
));
pItem
->
sortOrder
=
sortOrder
;
pList
->
nExpr
++
;
}
tVariantListItem
item
=
{
0
};
item
.
pVar
=
*
pVar
;
item
.
sortOrder
=
sortOrder
;
taosArrayPush
(
pList
,
&
item
);
return
pList
;
}
void
tVariantListDestroy
(
tVariantList
*
pList
)
{
if
(
pList
==
NULL
)
return
;
for
(
int32_t
i
=
0
;
i
<
pList
->
nExpr
;
++
i
)
{
tVariantDestroy
(
&
pList
->
a
[
i
].
pVar
);
}
free
(
pList
->
a
);
free
(
pList
);
}
tVariantList
*
tVariantListAppendToken
(
tVariantList
*
pList
,
SStrToken
*
pToken
,
uint8_t
sortOrder
)
{
if
(
pList
==
NULL
)
{
pList
=
calloc
(
1
,
sizeof
(
tVariantList
));
}
if
(
tVariantListExpand
(
pList
)
==
NULL
)
{
return
pList
;
}
if
(
pToken
)
{
tVariant
t
=
{
0
};
tVariantCreate
(
&
t
,
pToken
);
tVariantListItem
*
pItem
=
&
pList
->
a
[
pList
->
nExpr
++
];
memcpy
(
pItem
,
&
t
,
sizeof
(
tVariant
));
pItem
->
sortOrder
=
sortOrder
;
SArray
*
tVariantListInsert
(
SArray
*
pList
,
tVariant
*
pVar
,
uint8_t
sortOrder
,
int32_t
index
)
{
if
(
pList
==
NULL
||
pVar
==
NULL
||
index
>=
taosArrayGetSize
(
pList
))
{
return
tVariantListAppend
(
NULL
,
pVar
,
sortOrder
);
}
return
pList
;
}
tFieldList
*
tFieldListAppend
(
tFieldList
*
pList
,
TAOS_FIELD
*
pField
)
{
if
(
pList
==
NULL
)
pList
=
calloc
(
1
,
sizeof
(
tFieldList
));
tVariantListItem
item
=
{
0
};
item
.
pVar
=
*
pVar
;
item
.
sortOrder
=
sortOrder
;
if
(
pList
->
nAlloc
<=
pList
->
nField
)
{
//
pList
->
nAlloc
=
(
pList
->
nAlloc
<<
1
)
+
4
;
pList
->
p
=
realloc
(
pList
->
p
,
pList
->
nAlloc
*
sizeof
(
pList
->
p
[
0
]));
if
(
pList
->
p
==
0
)
{
pList
->
nField
=
pList
->
nAlloc
=
0
;
return
pList
;
}
}
assert
(
pList
->
p
!=
0
);
if
(
pField
)
{
struct
TAOS_FIELD
*
pItem
=
(
struct
TAOS_FIELD
*
)
&
pList
->
p
[
pList
->
nField
++
];
memcpy
(
pItem
,
pField
,
sizeof
(
TAOS_FIELD
));
}
taosArrayInsert
(
pList
,
index
,
&
item
);
return
pList
;
}
void
tFieldListDestroy
(
tFieldList
*
pList
)
{
if
(
pList
==
NULL
)
return
;
free
(
pList
->
p
);
free
(
pList
);
}
void
setDBName
(
SStrToken
*
pCpxName
,
SStrToken
*
pDB
)
{
pCpxName
->
type
=
pDB
->
type
;
pCpxName
->
z
=
pDB
->
z
;
...
...
@@ -499,9 +423,9 @@ void tSQLSetColumnType(TAOS_FIELD *pField, SStrToken *type) {
/*
* extract the select info out of sql string
*/
SQuerySQL
*
tSetQuerySQLElems
(
SStrToken
*
pSelectToken
,
tSQLExprList
*
pSelection
,
tVariantList
*
pFrom
,
tSQLExpr
*
pWhere
,
tVariantList
*
pGroupby
,
tVariantList
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SStrToken
*
pSliding
,
tVariantList
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pGLimit
)
{
SQuerySQL
*
tSetQuerySQLElems
(
SStrToken
*
pSelectToken
,
tSQLExprList
*
pSelection
,
SArray
*
pFrom
,
tSQLExpr
*
pWhere
,
SArray
*
pGroupby
,
SArray
*
pSortOrder
,
SIntervalVal
*
pInterval
,
SStrToken
*
pSliding
,
SArray
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pGLimit
)
{
assert
(
pSelection
!=
NULL
);
SQuerySQL
*
pQuery
=
calloc
(
1
,
sizeof
(
SQuerySQL
));
...
...
@@ -535,6 +459,11 @@ SQuerySQL *tSetQuerySQLElems(SStrToken *pSelectToken, tSQLExprList *pSelection,
return
pQuery
;
}
void
freeVariant
(
void
*
pItem
)
{
tVariantListItem
*
p
=
(
tVariantListItem
*
)
pItem
;
tVariantDestroy
(
&
p
->
pVar
);
}
void
doDestroyQuerySql
(
SQuerySQL
*
pQuerySql
)
{
if
(
pQuerySql
==
NULL
)
{
return
;
...
...
@@ -547,16 +476,17 @@ void doDestroyQuerySql(SQuerySQL *pQuerySql) {
tSQLExprDestroy
(
pQuerySql
->
pWhere
);
pQuerySql
->
pWhere
=
NULL
;
t
VariantListDestroy
(
pQuerySql
->
pSortOrder
);
t
aosArrayDestroyEx
(
pQuerySql
->
pSortOrder
,
freeVariant
);
pQuerySql
->
pSortOrder
=
NULL
;
t
VariantListDestroy
(
pQuerySql
->
pGroupby
);
t
aosArrayDestroyEx
(
pQuerySql
->
pGroupby
,
freeVariant
);
pQuerySql
->
pGroupby
=
NULL
;
t
VariantListDestroy
(
pQuerySql
->
from
);
t
aosArrayDestroyEx
(
pQuerySql
->
from
,
freeVariant
);
pQuerySql
->
from
=
NULL
;
tVariantListDestroy
(
pQuerySql
->
fillType
);
taosArrayDestroyEx
(
pQuerySql
->
fillType
,
freeVariant
);
pQuerySql
->
fillType
=
NULL
;
free
(
pQuerySql
);
}
...
...
@@ -574,8 +504,8 @@ void destroyAllSelectClause(SSubclauseInfo *pClause) {
taosTFree
(
pClause
->
pClause
);
}
SCreateTableSQL
*
tSetCreateSQLElems
(
tFieldList
*
pCols
,
tFieldList
*
pTags
,
SStrToken
*
pStableName
,
tVariantList
*
pTagVals
,
SQuerySQL
*
pSelect
,
int32_t
type
)
{
SCreateTableSQL
*
tSetCreateSQLElems
(
SArray
*
pCols
,
SArray
*
pTags
,
SStrToken
*
pStableName
,
SArray
*
pTagVals
,
SQuerySQL
*
pSelect
,
int32_t
type
)
{
SCreateTableSQL
*
pCreate
=
calloc
(
1
,
sizeof
(
SCreateTableSQL
));
switch
(
type
)
{
...
...
@@ -607,7 +537,7 @@ SCreateTableSQL *tSetCreateSQLElems(tFieldList *pCols, tFieldList *pTags, SStrTo
return
pCreate
;
}
SAlterTableSQL
*
tAlterTableSQLElems
(
SStrToken
*
pMeterName
,
tFieldList
*
pCols
,
tVariantList
*
pVals
,
int32_t
type
)
{
SAlterTableSQL
*
tAlterTableSQLElems
(
SStrToken
*
pMeterName
,
SArray
*
pCols
,
SArray
*
pVals
,
int32_t
type
)
{
SAlterTableSQL
*
pAlterTable
=
calloc
(
1
,
sizeof
(
SAlterTableSQL
));
pAlterTable
->
name
=
*
pMeterName
;
...
...
@@ -637,14 +567,14 @@ void SQLInfoDestroy(SSqlInfo *pInfo) {
SCreateTableSQL
*
pCreateTableInfo
=
pInfo
->
pCreateTableInfo
;
doDestroyQuerySql
(
pCreateTableInfo
->
pSelect
);
t
FieldList
Destroy
(
pCreateTableInfo
->
colInfo
.
pColumns
);
t
FieldList
Destroy
(
pCreateTableInfo
->
colInfo
.
pTagColumns
);
t
aosArray
Destroy
(
pCreateTableInfo
->
colInfo
.
pColumns
);
t
aosArray
Destroy
(
pCreateTableInfo
->
colInfo
.
pTagColumns
);
t
VariantListDestroy
(
pCreateTableInfo
->
usingInfo
.
pTagVals
);
t
aosArrayDestroyEx
(
pCreateTableInfo
->
usingInfo
.
pTagVals
,
freeVariant
);
taosTFree
(
pInfo
->
pCreateTableInfo
);
}
else
if
(
pInfo
->
type
==
TSDB_SQL_ALTER_TABLE
)
{
t
VariantListDestroy
(
pInfo
->
pAlterInfo
->
varLis
t
);
t
FieldList
Destroy
(
pInfo
->
pAlterInfo
->
pAddColumns
);
t
aosArrayDestroyEx
(
pInfo
->
pAlterInfo
->
varList
,
freeVarian
t
);
t
aosArray
Destroy
(
pInfo
->
pAlterInfo
->
pAddColumns
);
taosTFree
(
pInfo
->
pAlterInfo
);
}
else
{
...
...
@@ -653,7 +583,7 @@ void SQLInfoDestroy(SSqlInfo *pInfo) {
}
if
(
pInfo
->
pDCLInfo
!=
NULL
&&
pInfo
->
type
==
TSDB_SQL_CREATE_DB
)
{
t
VariantListDestroy
(
pInfo
->
pDCLInfo
->
dbOpt
.
keep
);
t
aosArrayDestroyEx
(
pInfo
->
pDCLInfo
->
dbOpt
.
keep
,
freeVariant
);
}
taosTFree
(
pInfo
->
pDCLInfo
);
...
...
src/query/src/sql.c
浏览文件 @
9487c1b9
...
...
@@ -115,9 +115,8 @@ typedef union {
int64_t
yy271
;
tVariant
yy312
;
SIntervalVal
yy314
;
SArray
*
yy347
;
SCreateTableSQL
*
yy374
;
tFieldList
*
yy449
;
tVariantList
*
yy494
;
}
YYMINORTYPE
;
#ifndef YYSTACKDEPTH
#define YYSTACKDEPTH 100
...
...
@@ -1361,18 +1360,14 @@ static void yy_destructor(
/********* Begin destructor definitions ***************************************/
case
226
:
/* keep */
case
227
:
/* tagitemlist */
case
243
:
/* columnlist */
case
251
:
/* fill_opt */
case
253
:
/* groupby_opt */
case
254
:
/* orderby_opt */
case
264
:
/* sortlist */
case
268
:
/* grouplist */
{
tVariantListDestroy
((
yypminor
->
yy494
));
}
break
;
case
243
:
/* columnlist */
{
tFieldListDestroy
((
yypminor
->
yy449
));
taosArrayDestroy
((
yypminor
->
yy347
));
}
break
;
case
244
:
/* select */
...
...
@@ -2228,7 +2223,7 @@ static void yy_reduce(
yymsp
[
-
8
].
minor
.
yy73
=
yylhsminor
.
yy73
;
break
;
case
72
:
/* keep ::= KEEP tagitemlist */
{
yymsp
[
-
1
].
minor
.
yy
494
=
yymsp
[
0
].
minor
.
yy494
;
}
{
yymsp
[
-
1
].
minor
.
yy
347
=
yymsp
[
0
].
minor
.
yy347
;
}
break
;
case
73
:
/* cache ::= CACHE INTEGER */
case
74
:
/* replica ::= REPLICA INTEGER */
yytestcase
(
yyruleno
==
74
);
...
...
@@ -2303,7 +2298,7 @@ static void yy_reduce(
break
;
case
98
:
/* db_optr ::= db_optr keep */
case
102
:
/* alter_db_optr ::= alter_db_optr keep */
yytestcase
(
yyruleno
==
102
);
{
yylhsminor
.
yy158
=
yymsp
[
-
1
].
minor
.
yy158
;
yylhsminor
.
yy158
.
keep
=
yymsp
[
0
].
minor
.
yy
494
;
}
{
yylhsminor
.
yy158
=
yymsp
[
-
1
].
minor
.
yy158
;
yylhsminor
.
yy158
.
keep
=
yymsp
[
0
].
minor
.
yy
347
;
}
yymsp
[
-
1
].
minor
.
yy158
=
yylhsminor
.
yy158
;
break
;
case
99
:
/* alter_db_optr ::= */
...
...
@@ -2346,20 +2341,20 @@ static void yy_reduce(
break
;
case
113
:
/* create_table_args ::= LP columnlist RP */
{
yymsp
[
-
2
].
minor
.
yy374
=
tSetCreateSQLElems
(
yymsp
[
-
1
].
minor
.
yy
449
,
NULL
,
NULL
,
NULL
,
NULL
,
TSQL_CREATE_TABLE
);
yymsp
[
-
2
].
minor
.
yy374
=
tSetCreateSQLElems
(
yymsp
[
-
1
].
minor
.
yy
347
,
NULL
,
NULL
,
NULL
,
NULL
,
TSQL_CREATE_TABLE
);
setSQLInfo
(
pInfo
,
yymsp
[
-
2
].
minor
.
yy374
,
NULL
,
TSDB_SQL_CREATE_TABLE
);
}
break
;
case
114
:
/* create_table_args ::= LP columnlist RP TAGS LP columnlist RP */
{
yymsp
[
-
6
].
minor
.
yy374
=
tSetCreateSQLElems
(
yymsp
[
-
5
].
minor
.
yy
449
,
yymsp
[
-
1
].
minor
.
yy449
,
NULL
,
NULL
,
NULL
,
TSQL_CREATE_STABLE
);
yymsp
[
-
6
].
minor
.
yy374
=
tSetCreateSQLElems
(
yymsp
[
-
5
].
minor
.
yy
347
,
yymsp
[
-
1
].
minor
.
yy347
,
NULL
,
NULL
,
NULL
,
TSQL_CREATE_STABLE
);
setSQLInfo
(
pInfo
,
yymsp
[
-
6
].
minor
.
yy374
,
NULL
,
TSDB_SQL_CREATE_TABLE
);
}
break
;
case
115
:
/* create_table_args ::= USING ids cpxName TAGS LP tagitemlist RP */
{
yymsp
[
-
5
].
minor
.
yy0
.
n
+=
yymsp
[
-
4
].
minor
.
yy0
.
n
;
yymsp
[
-
6
].
minor
.
yy374
=
tSetCreateSQLElems
(
NULL
,
NULL
,
&
yymsp
[
-
5
].
minor
.
yy0
,
yymsp
[
-
1
].
minor
.
yy
494
,
NULL
,
TSQL_CREATE_TABLE_FROM_STABLE
);
yymsp
[
-
6
].
minor
.
yy374
=
tSetCreateSQLElems
(
NULL
,
NULL
,
&
yymsp
[
-
5
].
minor
.
yy0
,
yymsp
[
-
1
].
minor
.
yy
347
,
NULL
,
TSQL_CREATE_TABLE_FROM_STABLE
);
setSQLInfo
(
pInfo
,
yymsp
[
-
6
].
minor
.
yy374
,
NULL
,
TSDB_SQL_CREATE_TABLE
);
}
break
;
...
...
@@ -2370,12 +2365,12 @@ static void yy_reduce(
}
break
;
case
117
:
/* columnlist ::= columnlist COMMA column */
{
yylhsminor
.
yy
449
=
tFieldListAppend
(
yymsp
[
-
2
].
minor
.
yy449
,
&
yymsp
[
0
].
minor
.
yy181
);
}
yymsp
[
-
2
].
minor
.
yy
449
=
yylhsminor
.
yy449
;
{
yylhsminor
.
yy
347
=
taosArrayPush
(
yymsp
[
-
2
].
minor
.
yy347
,
&
yymsp
[
0
].
minor
.
yy181
);
}
yymsp
[
-
2
].
minor
.
yy
347
=
yylhsminor
.
yy347
;
break
;
case
118
:
/* columnlist ::= column */
{
yylhsminor
.
yy
449
=
tFieldListAppend
(
NULL
,
&
yymsp
[
0
].
minor
.
yy181
);}
yymsp
[
0
].
minor
.
yy
449
=
yylhsminor
.
yy449
;
{
yylhsminor
.
yy
347
=
taosArrayInit
(
4
,
sizeof
(
TAOS_FIELD
));
taosArrayPush
(
yylhsminor
.
yy347
,
&
yymsp
[
0
].
minor
.
yy181
);}
yymsp
[
0
].
minor
.
yy
347
=
yylhsminor
.
yy347
;
break
;
case
119
:
/* column ::= ids typename */
{
...
...
@@ -2384,12 +2379,12 @@ static void yy_reduce(
yymsp
[
-
1
].
minor
.
yy181
=
yylhsminor
.
yy181
;
break
;
case
120
:
/* tagitemlist ::= tagitemlist COMMA tagitem */
{
yylhsminor
.
yy
494
=
tVariantListAppend
(
yymsp
[
-
2
].
minor
.
yy494
,
&
yymsp
[
0
].
minor
.
yy312
,
-
1
);
}
yymsp
[
-
2
].
minor
.
yy
494
=
yylhsminor
.
yy494
;
{
yylhsminor
.
yy
347
=
tVariantListAppend
(
yymsp
[
-
2
].
minor
.
yy347
,
&
yymsp
[
0
].
minor
.
yy312
,
-
1
);
}
yymsp
[
-
2
].
minor
.
yy
347
=
yylhsminor
.
yy347
;
break
;
case
121
:
/* tagitemlist ::= tagitem */
{
yylhsminor
.
yy
494
=
tVariantListAppend
(
NULL
,
&
yymsp
[
0
].
minor
.
yy312
,
-
1
);
}
yymsp
[
0
].
minor
.
yy
494
=
yylhsminor
.
yy494
;
{
yylhsminor
.
yy
347
=
tVariantListAppend
(
NULL
,
&
yymsp
[
0
].
minor
.
yy312
,
-
1
);
}
yymsp
[
0
].
minor
.
yy
347
=
yylhsminor
.
yy347
;
break
;
case
122
:
/* tagitem ::= INTEGER */
case
123
:
/* tagitem ::= FLOAT */
yytestcase
(
yyruleno
==
123
);
...
...
@@ -2416,7 +2411,7 @@ static void yy_reduce(
break
;
case
131
:
/* select ::= SELECT selcollist from where_opt interval_opt fill_opt sliding_opt groupby_opt orderby_opt having_opt slimit_opt limit_opt */
{
yylhsminor
.
yy150
=
tSetQuerySQLElems
(
&
yymsp
[
-
11
].
minor
.
yy0
,
yymsp
[
-
10
].
minor
.
yy224
,
yymsp
[
-
9
].
minor
.
yy
494
,
yymsp
[
-
8
].
minor
.
yy66
,
yymsp
[
-
4
].
minor
.
yy494
,
yymsp
[
-
3
].
minor
.
yy494
,
&
yymsp
[
-
7
].
minor
.
yy314
,
&
yymsp
[
-
5
].
minor
.
yy0
,
yymsp
[
-
6
].
minor
.
yy494
,
&
yymsp
[
0
].
minor
.
yy188
,
&
yymsp
[
-
1
].
minor
.
yy188
);
yylhsminor
.
yy150
=
tSetQuerySQLElems
(
&
yymsp
[
-
11
].
minor
.
yy0
,
yymsp
[
-
10
].
minor
.
yy224
,
yymsp
[
-
9
].
minor
.
yy
347
,
yymsp
[
-
8
].
minor
.
yy66
,
yymsp
[
-
4
].
minor
.
yy347
,
yymsp
[
-
3
].
minor
.
yy347
,
&
yymsp
[
-
7
].
minor
.
yy314
,
&
yymsp
[
-
5
].
minor
.
yy0
,
yymsp
[
-
6
].
minor
.
yy347
,
&
yymsp
[
0
].
minor
.
yy188
,
&
yymsp
[
-
1
].
minor
.
yy188
);
}
yymsp
[
-
11
].
minor
.
yy150
=
yylhsminor
.
yy150
;
break
;
...
...
@@ -2475,45 +2470,45 @@ static void yy_reduce(
{
yymsp
[
1
].
minor
.
yy0
.
n
=
0
;
}
break
;
case
145
:
/* from ::= FROM tablelist */
{
yymsp
[
-
1
].
minor
.
yy
494
=
yymsp
[
0
].
minor
.
yy494
;}
{
yymsp
[
-
1
].
minor
.
yy
347
=
yymsp
[
0
].
minor
.
yy347
;}
break
;
case
146
:
/* tablelist ::= ids cpxName */
{
toTSDBType
(
yymsp
[
-
1
].
minor
.
yy0
.
type
);
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yylhsminor
.
yy
494
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
yylhsminor
.
yy
494
=
tVariantListAppendToken
(
yylhsminor
.
yy494
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
// table alias name
yylhsminor
.
yy
347
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
yylhsminor
.
yy
347
=
tVariantListAppendToken
(
yylhsminor
.
yy347
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
// table alias name
}
yymsp
[
-
1
].
minor
.
yy
494
=
yylhsminor
.
yy494
;
yymsp
[
-
1
].
minor
.
yy
347
=
yylhsminor
.
yy347
;
break
;
case
147
:
/* tablelist ::= ids cpxName ids */
{
toTSDBType
(
yymsp
[
-
2
].
minor
.
yy0
.
type
);
toTSDBType
(
yymsp
[
0
].
minor
.
yy0
.
type
);
yymsp
[
-
2
].
minor
.
yy0
.
n
+=
yymsp
[
-
1
].
minor
.
yy0
.
n
;
yylhsminor
.
yy
494
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
2
].
minor
.
yy0
,
-
1
);
yylhsminor
.
yy
494
=
tVariantListAppendToken
(
yylhsminor
.
yy494
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
yylhsminor
.
yy
347
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
2
].
minor
.
yy0
,
-
1
);
yylhsminor
.
yy
347
=
tVariantListAppendToken
(
yylhsminor
.
yy347
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
}
yymsp
[
-
2
].
minor
.
yy
494
=
yylhsminor
.
yy494
;
yymsp
[
-
2
].
minor
.
yy
347
=
yylhsminor
.
yy347
;
break
;
case
148
:
/* tablelist ::= tablelist COMMA ids cpxName */
{
toTSDBType
(
yymsp
[
-
1
].
minor
.
yy0
.
type
);
yymsp
[
-
1
].
minor
.
yy0
.
n
+=
yymsp
[
0
].
minor
.
yy0
.
n
;
yylhsminor
.
yy
494
=
tVariantListAppendToken
(
yymsp
[
-
3
].
minor
.
yy494
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
yylhsminor
.
yy
494
=
tVariantListAppendToken
(
yylhsminor
.
yy494
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
yylhsminor
.
yy
347
=
tVariantListAppendToken
(
yymsp
[
-
3
].
minor
.
yy347
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
yylhsminor
.
yy
347
=
tVariantListAppendToken
(
yylhsminor
.
yy347
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
}
yymsp
[
-
3
].
minor
.
yy
494
=
yylhsminor
.
yy494
;
yymsp
[
-
3
].
minor
.
yy
347
=
yylhsminor
.
yy347
;
break
;
case
149
:
/* tablelist ::= tablelist COMMA ids cpxName ids */
{
toTSDBType
(
yymsp
[
-
2
].
minor
.
yy0
.
type
);
toTSDBType
(
yymsp
[
0
].
minor
.
yy0
.
type
);
yymsp
[
-
2
].
minor
.
yy0
.
n
+=
yymsp
[
-
1
].
minor
.
yy0
.
n
;
yylhsminor
.
yy
494
=
tVariantListAppendToken
(
yymsp
[
-
4
].
minor
.
yy494
,
&
yymsp
[
-
2
].
minor
.
yy0
,
-
1
);
yylhsminor
.
yy
494
=
tVariantListAppendToken
(
yylhsminor
.
yy494
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
yylhsminor
.
yy
347
=
tVariantListAppendToken
(
yymsp
[
-
4
].
minor
.
yy347
,
&
yymsp
[
-
2
].
minor
.
yy0
,
-
1
);
yylhsminor
.
yy
347
=
tVariantListAppendToken
(
yylhsminor
.
yy347
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
}
yymsp
[
-
4
].
minor
.
yy
494
=
yylhsminor
.
yy494
;
yymsp
[
-
4
].
minor
.
yy
347
=
yylhsminor
.
yy347
;
break
;
case
150
:
/* tmvar ::= VARIABLE */
{
yylhsminor
.
yy0
=
yymsp
[
0
].
minor
.
yy0
;}
...
...
@@ -2529,7 +2524,7 @@ static void yy_reduce(
{
memset
(
&
yymsp
[
1
].
minor
.
yy314
,
0
,
sizeof
(
yymsp
[
1
].
minor
.
yy314
));}
break
;
case
154
:
/* fill_opt ::= */
{
yymsp
[
1
].
minor
.
yy
494
=
0
;
}
{
yymsp
[
1
].
minor
.
yy
347
=
0
;
}
break
;
case
155
:
/* fill_opt ::= FILL LP ID COMMA tagitemlist RP */
{
...
...
@@ -2537,14 +2532,14 @@ static void yy_reduce(
toTSDBType
(
yymsp
[
-
3
].
minor
.
yy0
.
type
);
tVariantCreate
(
&
A
,
&
yymsp
[
-
3
].
minor
.
yy0
);
tVariantListInsert
(
yymsp
[
-
1
].
minor
.
yy
494
,
&
A
,
-
1
,
0
);
yymsp
[
-
5
].
minor
.
yy
494
=
yymsp
[
-
1
].
minor
.
yy494
;
tVariantListInsert
(
yymsp
[
-
1
].
minor
.
yy
347
,
&
A
,
-
1
,
0
);
yymsp
[
-
5
].
minor
.
yy
347
=
yymsp
[
-
1
].
minor
.
yy347
;
}
break
;
case
156
:
/* fill_opt ::= FILL LP ID RP */
{
toTSDBType
(
yymsp
[
-
1
].
minor
.
yy0
.
type
);
yymsp
[
-
3
].
minor
.
yy
494
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
yymsp
[
-
3
].
minor
.
yy
347
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
}
break
;
case
157
:
/* sliding_opt ::= SLIDING LP tmvar RP */
...
...
@@ -2555,23 +2550,23 @@ static void yy_reduce(
break
;
case
159
:
/* orderby_opt ::= */
case
167
:
/* groupby_opt ::= */
yytestcase
(
yyruleno
==
167
);
{
yymsp
[
1
].
minor
.
yy
494
=
0
;}
{
yymsp
[
1
].
minor
.
yy
347
=
0
;}
break
;
case
160
:
/* orderby_opt ::= ORDER BY sortlist */
case
168
:
/* groupby_opt ::= GROUP BY grouplist */
yytestcase
(
yyruleno
==
168
);
{
yymsp
[
-
2
].
minor
.
yy
494
=
yymsp
[
0
].
minor
.
yy494
;}
{
yymsp
[
-
2
].
minor
.
yy
347
=
yymsp
[
0
].
minor
.
yy347
;}
break
;
case
161
:
/* sortlist ::= sortlist COMMA item sortorder */
{
yylhsminor
.
yy
494
=
tVariantListAppend
(
yymsp
[
-
3
].
minor
.
yy494
,
&
yymsp
[
-
1
].
minor
.
yy312
,
yymsp
[
0
].
minor
.
yy82
);
yylhsminor
.
yy
347
=
tVariantListAppend
(
yymsp
[
-
3
].
minor
.
yy347
,
&
yymsp
[
-
1
].
minor
.
yy312
,
yymsp
[
0
].
minor
.
yy82
);
}
yymsp
[
-
3
].
minor
.
yy
494
=
yylhsminor
.
yy494
;
yymsp
[
-
3
].
minor
.
yy
347
=
yylhsminor
.
yy347
;
break
;
case
162
:
/* sortlist ::= item sortorder */
{
yylhsminor
.
yy
494
=
tVariantListAppend
(
NULL
,
&
yymsp
[
-
1
].
minor
.
yy312
,
yymsp
[
0
].
minor
.
yy82
);
yylhsminor
.
yy
347
=
tVariantListAppend
(
NULL
,
&
yymsp
[
-
1
].
minor
.
yy312
,
yymsp
[
0
].
minor
.
yy82
);
}
yymsp
[
-
1
].
minor
.
yy
494
=
yylhsminor
.
yy494
;
yymsp
[
-
1
].
minor
.
yy
347
=
yylhsminor
.
yy347
;
break
;
case
163
:
/* item ::= ids cpxName */
{
...
...
@@ -2593,15 +2588,15 @@ static void yy_reduce(
break
;
case
169
:
/* grouplist ::= grouplist COMMA item */
{
yylhsminor
.
yy
494
=
tVariantListAppend
(
yymsp
[
-
2
].
minor
.
yy494
,
&
yymsp
[
0
].
minor
.
yy312
,
-
1
);
yylhsminor
.
yy
347
=
tVariantListAppend
(
yymsp
[
-
2
].
minor
.
yy347
,
&
yymsp
[
0
].
minor
.
yy312
,
-
1
);
}
yymsp
[
-
2
].
minor
.
yy
494
=
yylhsminor
.
yy494
;
yymsp
[
-
2
].
minor
.
yy
347
=
yylhsminor
.
yy347
;
break
;
case
170
:
/* grouplist ::= item */
{
yylhsminor
.
yy
494
=
tVariantListAppend
(
NULL
,
&
yymsp
[
0
].
minor
.
yy312
,
-
1
);
yylhsminor
.
yy
347
=
tVariantListAppend
(
NULL
,
&
yymsp
[
0
].
minor
.
yy312
,
-
1
);
}
yymsp
[
0
].
minor
.
yy
494
=
yylhsminor
.
yy494
;
yymsp
[
0
].
minor
.
yy
347
=
yylhsminor
.
yy347
;
break
;
case
171
:
/* having_opt ::= */
case
181
:
/* where_opt ::= */
yytestcase
(
yyruleno
==
181
);
...
...
@@ -2771,7 +2766,7 @@ static void yy_reduce(
case
221
:
/* cmd ::= ALTER TABLE ids cpxName ADD COLUMN columnlist */
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
SAlterTableSQL
*
pAlterTable
=
tAlterTableSQLElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy
449
,
NULL
,
TSDB_ALTER_TABLE_ADD_COLUMN
);
SAlterTableSQL
*
pAlterTable
=
tAlterTableSQLElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy
347
,
NULL
,
TSDB_ALTER_TABLE_ADD_COLUMN
);
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
@@ -2780,7 +2775,7 @@ static void yy_reduce(
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
toTSDBType
(
yymsp
[
0
].
minor
.
yy0
.
type
);
tVariantList
*
K
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
SArray
*
K
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
SAlterTableSQL
*
pAlterTable
=
tAlterTableSQLElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
NULL
,
K
,
TSDB_ALTER_TABLE_DROP_COLUMN
);
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
...
...
@@ -2789,7 +2784,7 @@ static void yy_reduce(
case
223
:
/* cmd ::= ALTER TABLE ids cpxName ADD TAG columnlist */
{
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
SAlterTableSQL
*
pAlterTable
=
tAlterTableSQLElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy
449
,
NULL
,
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
);
SAlterTableSQL
*
pAlterTable
=
tAlterTableSQLElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
yymsp
[
0
].
minor
.
yy
347
,
NULL
,
TSDB_ALTER_TABLE_ADD_TAG_COLUMN
);
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
}
break
;
...
...
@@ -2798,7 +2793,7 @@ static void yy_reduce(
yymsp
[
-
4
].
minor
.
yy0
.
n
+=
yymsp
[
-
3
].
minor
.
yy0
.
n
;
toTSDBType
(
yymsp
[
0
].
minor
.
yy0
.
type
);
tVariantList
*
A
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
SArray
*
A
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
SAlterTableSQL
*
pAlterTable
=
tAlterTableSQLElems
(
&
yymsp
[
-
4
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_DROP_TAG_COLUMN
);
setSQLInfo
(
pInfo
,
pAlterTable
,
NULL
,
TSDB_SQL_ALTER_TABLE
);
...
...
@@ -2809,7 +2804,7 @@ static void yy_reduce(
yymsp
[
-
5
].
minor
.
yy0
.
n
+=
yymsp
[
-
4
].
minor
.
yy0
.
n
;
toTSDBType
(
yymsp
[
-
1
].
minor
.
yy0
.
type
);
tVariantList
*
A
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
SArray
*
A
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
1
].
minor
.
yy0
,
-
1
);
toTSDBType
(
yymsp
[
0
].
minor
.
yy0
.
type
);
A
=
tVariantListAppendToken
(
A
,
&
yymsp
[
0
].
minor
.
yy0
,
-
1
);
...
...
@@ -2823,7 +2818,7 @@ static void yy_reduce(
yymsp
[
-
6
].
minor
.
yy0
.
n
+=
yymsp
[
-
5
].
minor
.
yy0
.
n
;
toTSDBType
(
yymsp
[
-
2
].
minor
.
yy0
.
type
);
tVariantList
*
A
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
2
].
minor
.
yy0
,
-
1
);
SArray
*
A
=
tVariantListAppendToken
(
NULL
,
&
yymsp
[
-
2
].
minor
.
yy0
,
-
1
);
A
=
tVariantListAppend
(
A
,
&
yymsp
[
0
].
minor
.
yy312
,
-
1
);
SAlterTableSQL
*
pAlterTable
=
tAlterTableSQLElems
(
&
yymsp
[
-
6
].
minor
.
yy0
,
NULL
,
A
,
TSDB_ALTER_TABLE_UPDATE_TAG_VAL
);
...
...
src/util/inc/tarray.h
浏览文件 @
9487c1b9
...
...
@@ -70,6 +70,13 @@ void* taosArrayGet(const SArray* pArray, size_t index);
*/
void
*
taosArrayGetP
(
const
SArray
*
pArray
,
size_t
index
);
/**
* get the last element in the array list
* @param pArray
* @return
*/
void
*
taosArrayGetLast
(
const
SArray
*
pArray
);
/**
* return the size of array
* @param pArray
...
...
@@ -117,6 +124,13 @@ void taosArrayClear(SArray* pArray);
*/
void
taosArrayDestroy
(
SArray
*
pArray
);
/**
*
* @param pArray
* @param fp
*/
void
taosArrayDestroyEx
(
SArray
*
pArray
,
void
(
*
fp
)(
void
*
));
/**
* sort the array
* @param pArray
...
...
src/util/src/tarray.c
浏览文件 @
9487c1b9
...
...
@@ -99,6 +99,10 @@ void* taosArrayGetP(const SArray* pArray, size_t index) {
return
*
(
void
**
)
d
;
}
void
*
taosArrayGetLast
(
const
SArray
*
pArray
)
{
return
TARRAY_GET_ELEM
(
pArray
,
pArray
->
size
-
1
);
}
size_t
taosArrayGetSize
(
const
SArray
*
pArray
)
{
return
pArray
->
size
;
}
void
*
taosArrayInsert
(
SArray
*
pArray
,
size_t
index
,
void
*
pData
)
{
...
...
@@ -189,6 +193,18 @@ void taosArrayDestroy(SArray* pArray) {
free
(
pArray
);
}
void
taosArrayDestroyEx
(
SArray
*
pArray
,
void
(
*
fp
)(
void
*
))
{
if
(
fp
==
NULL
)
{
return
taosArrayDestroy
(
pArray
);
}
for
(
int32_t
i
=
0
;
i
<
pArray
->
size
;
++
i
)
{
fp
(
TARRAY_GET_ELEM
(
pArray
,
i
));
}
taosArrayDestroy
(
pArray
);
}
void
taosArraySort
(
SArray
*
pArray
,
int
(
*
compar
)(
const
void
*
,
const
void
*
))
{
assert
(
pArray
!=
NULL
);
assert
(
compar
!=
NULL
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录