Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
59be5440
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
59be5440
编写于
1月 23, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' into feature/query
上级
9c58bfbd
0620cf5e
变更
12
展开全部
隐藏空白更改
内联
并排
Showing
12 changed file
with
1360 addition
and
1229 deletion
+1360
-1229
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+2
-0
src/client/src/tscLocalMerge.c
src/client/src/tscLocalMerge.c
+2
-2
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+31
-2
src/client/src/tscSubquery.c
src/client/src/tscSubquery.c
+35
-13
src/inc/ttokendef.h
src/inc/ttokendef.h
+99
-98
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+2
-1
src/query/inc/sql.y
src/query/inc/sql.y
+11
-7
src/query/src/qParserImpl.c
src/query/src/qParserImpl.c
+2
-1
src/query/src/qTokenizer.c
src/query/src/qTokenizer.c
+1
-0
src/query/src/sql.c
src/query/src/sql.c
+1113
-1105
tests/script/general/parser/select_distinct_tag.sim
tests/script/general/parser/select_distinct_tag.sim
+61
-0
tests/script/jenkins/basic.txt
tests/script/jenkins/basic.txt
+1
-0
未找到文件。
src/client/inc/tsclient.h
浏览文件 @
59be5440
...
...
@@ -223,6 +223,8 @@ typedef struct SQueryInfo {
int32_t
udColumnId
;
// current user-defined constant output field column id, monotonically decreases from TSDB_UD_COLUMN_INDEX
int16_t
resColumnId
;
// result column id
bool
distinctTag
;
// distinct tag or not
}
SQueryInfo
;
typedef
struct
{
...
...
src/client/src/tscLocalMerge.c
浏览文件 @
59be5440
...
...
@@ -1101,7 +1101,7 @@ static int64_t getNumOfResultLocal(SQueryInfo *pQueryInfo, SQLFunctionCtx *pCtx)
* the number of output result is decided by main output
*/
int32_t
functionId
=
pCtx
[
j
].
functionId
;
if
(
functionId
==
TSDB_FUNC_TS
||
functionId
==
TSDB_FUNC_TAG
||
functionId
==
TSDB_FUNC_TAGPRJ
)
{
if
(
functionId
==
TSDB_FUNC_TS
||
functionId
==
TSDB_FUNC_TAG
)
{
continue
;
}
...
...
@@ -1183,7 +1183,7 @@ bool needToMerge(SQueryInfo *pQueryInfo, SLocalMerger *pLocalMerge, tFilePage *t
int16_t
functionId
=
pLocalMerge
->
pCtx
[
0
].
functionId
;
// todo opt performance
if
((
/*functionId == TSDB_FUNC_PRJ || */
functionId
==
TSDB_FUNC_ARITHM
)
||
(
tscIsProjectionQueryOnSTable
(
pQueryInfo
,
0
)))
{
// column projection query
if
((
/*functionId == TSDB_FUNC_PRJ || */
functionId
==
TSDB_FUNC_ARITHM
)
||
(
tscIsProjectionQueryOnSTable
(
pQueryInfo
,
0
)
&&
pQueryInfo
->
distinctTag
==
false
))
{
// column projection query
ret
=
1
;
// disable merge procedure
}
else
{
tOrderDescriptor
*
pDesc
=
pLocalMerge
->
pDesc
;
...
...
src/client/src/tscSQLParser.c
浏览文件 @
59be5440
...
...
@@ -1505,23 +1505,39 @@ static void addPrimaryTsColIntoResult(SQueryInfo* pQueryInfo) {
pQueryInfo
->
type
|=
TSDB_QUERY_TYPE_PROJECTION_QUERY
;
}
bool
isValidDistinctSql
(
SQueryInfo
*
pQueryInfo
)
{
if
(
pQueryInfo
==
NULL
)
{
return
false
;
}
if
((
pQueryInfo
->
type
&
TSDB_QUERY_TYPE_STABLE_QUERY
)
!=
TSDB_QUERY_TYPE_STABLE_QUERY
)
{
return
false
;
}
if
(
tscQueryTags
(
pQueryInfo
)
&&
tscSqlExprNumOfExprs
(
pQueryInfo
)
==
1
){
return
true
;
}
return
false
;
}
int32_t
parseSelectClause
(
SSqlCmd
*
pCmd
,
int32_t
clauseIndex
,
tSQLExprList
*
pSelection
,
bool
isSTable
,
bool
joinQuery
,
bool
intervalQuery
)
{
assert
(
pSelection
!=
NULL
&&
pCmd
!=
NULL
);
const
char
*
msg2
=
"functions can not be mixed up"
;
const
char
*
msg3
=
"not support query expression"
;
const
char
*
msg5
=
"invalid function name"
;
const
char
*
msg6
=
"only support distinct one tag"
;
SQueryInfo
*
pQueryInfo
=
tscGetQueryInfoDetail
(
pCmd
,
clauseIndex
);
if
(
pQueryInfo
->
colList
==
NULL
)
{
pQueryInfo
->
colList
=
taosArrayInit
(
4
,
POINTER_BYTES
);
}
bool
hasDistinct
=
false
;
for
(
int32_t
i
=
0
;
i
<
pSelection
->
nExpr
;
++
i
)
{
int32_t
outputIndex
=
(
int32_t
)
tscSqlExprNumOfExprs
(
pQueryInfo
);
tSqlExprItem
*
pItem
=
&
pSelection
->
a
[
i
];
if
(
hasDistinct
==
false
)
{
hasDistinct
=
(
pItem
->
distinct
==
true
);
}
// project on all fields
int32_t
optr
=
pItem
->
pNode
->
nSQLOptr
;
...
...
@@ -1555,6 +1571,13 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
}
}
if
(
hasDistinct
==
true
)
{
if
(
!
isValidDistinctSql
(
pQueryInfo
))
{
return
invalidSqlErrMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
}
pQueryInfo
->
distinctTag
=
true
;
}
// there is only one user-defined column in the final result field, add the timestamp column.
size_t
numOfSrcCols
=
taosArrayGetSize
(
pQueryInfo
->
colList
);
if
(
numOfSrcCols
<=
0
&&
!
tscQueryTags
(
pQueryInfo
))
{
...
...
@@ -4657,6 +4680,12 @@ int32_t parseOrderbyClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQu
setDefaultOrderInfo
(
pQueryInfo
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
if
(
pQueryInfo
->
distinctTag
==
true
)
{
pQueryInfo
->
order
.
order
=
TSDB_ORDER_ASC
;
pQueryInfo
->
order
.
orderColId
=
0
;
return
TSDB_CODE_SUCCESS
;
}
if
(
pQuerySql
->
pSortOrder
==
NULL
)
{
return
TSDB_CODE_SUCCESS
;
}
...
...
src/client/src/tscSubquery.c
浏览文件 @
59be5440
...
...
@@ -582,13 +582,14 @@ void freeJoinSubqueryObj(SSqlObj* pSql) {
pSql
->
subState
.
numOfSub
=
0
;
}
static
void
quitAllSubquery
(
SSqlObj
*
pSqlSub
,
SSqlObj
*
pSqlObj
,
SJoinSupporter
*
pSupporter
)
{
static
int32_t
quitAllSubquery
(
SSqlObj
*
pSqlSub
,
SSqlObj
*
pSqlObj
,
SJoinSupporter
*
pSupporter
)
{
if
(
subAndCheckDone
(
pSqlSub
,
pSqlObj
,
pSupporter
->
subqueryIndex
))
{
tscError
(
"%p all subquery return and query failed, global code:%s"
,
pSqlObj
,
tstrerror
(
pSqlObj
->
res
.
code
));
freeJoinSubqueryObj
(
pSqlObj
);
return
;
return
0
;
}
return
1
;
//tscDestroyJoinSupporter(pSupporter);
}
...
...
@@ -835,7 +836,9 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
if
(
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"%p abort query due to other subquery failure. code:%d, global code:%d"
,
pSql
,
numOfRows
,
pParentSql
->
res
.
code
);
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
if
(
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
))
{
return
;
}
tscAsyncResultOnError
(
pParentSql
);
...
...
@@ -850,7 +853,9 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
tscError
(
"%p sub query failed, code:%s, index:%d"
,
pSql
,
tstrerror
(
numOfRows
),
pSupporter
->
subqueryIndex
);
pParentSql
->
res
.
code
=
numOfRows
;
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
if
(
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
))
{
return
;
}
tscAsyncResultOnError
(
pParentSql
);
return
;
...
...
@@ -867,7 +872,9 @@ static void tidTagRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
tscError
(
"%p failed to malloc memory"
,
pSql
);
pParentSql
->
res
.
code
=
TAOS_SYSTEM_ERROR
(
errno
);
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
if
(
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
))
{
return
;
}
tscAsyncResultOnError
(
pParentSql
);
return
;
...
...
@@ -985,7 +992,9 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
if
(
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"%p abort query due to other subquery failure. code:%d, global code:%d"
,
pSql
,
numOfRows
,
pParentSql
->
res
.
code
);
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
if
(
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
)){
return
;
}
tscAsyncResultOnError
(
pParentSql
);
...
...
@@ -999,7 +1008,9 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
tscError
(
"%p sub query failed, code:%s, index:%d"
,
pSql
,
tstrerror
(
numOfRows
),
pSupporter
->
subqueryIndex
);
pParentSql
->
res
.
code
=
numOfRows
;
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
if
(
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
)){
return
;
}
tscAsyncResultOnError
(
pParentSql
);
return
;
...
...
@@ -1014,7 +1025,9 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
pParentSql
->
res
.
code
=
TAOS_SYSTEM_ERROR
(
errno
);
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
if
(
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
))
{
return
;
}
tscAsyncResultOnError
(
pParentSql
);
...
...
@@ -1032,7 +1045,9 @@ static void tsCompRetrieveCallback(void* param, TAOS_RES* tres, int32_t numOfRow
pParentSql
->
res
.
code
=
TAOS_SYSTEM_ERROR
(
errno
);
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
if
(
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
)){
return
;
}
tscAsyncResultOnError
(
pParentSql
);
...
...
@@ -1129,8 +1144,10 @@ static void joinRetrieveFinalResCallback(void* param, TAOS_RES* tres, int numOfR
if
(
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"%p abort query due to other subquery failure. code:%d, global code:%d"
,
pSql
,
numOfRows
,
pParentSql
->
res
.
code
);
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
if
(
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
))
{
return
;
}
tscAsyncResultOnError
(
pParentSql
);
return
;
...
...
@@ -1472,7 +1489,9 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
// retrieve actual query results from vnode during the second stage join subquery
if
(
pParentSql
->
res
.
code
!=
TSDB_CODE_SUCCESS
)
{
tscError
(
"%p abort query due to other subquery failure. code:%d, global code:%d"
,
pSql
,
code
,
pParentSql
->
res
.
code
);
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
if
(
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
))
{
return
;
}
tscAsyncResultOnError
(
pParentSql
);
...
...
@@ -1486,7 +1505,10 @@ void tscJoinQueryCallback(void* param, TAOS_RES* tres, int code) {
tscError
(
"%p abort query, code:%s, global code:%s"
,
pSql
,
tstrerror
(
code
),
tstrerror
(
pParentSql
->
res
.
code
));
pParentSql
->
res
.
code
=
code
;
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
);
if
(
quitAllSubquery
(
pSql
,
pParentSql
,
pSupporter
))
{
return
;
}
tscAsyncResultOnError
(
pParentSql
);
return
;
...
...
src/inc/ttokendef.h
浏览文件 @
59be5440
...
...
@@ -16,6 +16,7 @@
#ifndef TDENGINE_TTOKENDEF_H
#define TDENGINE_TTOKENDEF_H
#define TK_ID 1
#define TK_BOOL 2
#define TK_TINYINT 3
...
...
@@ -127,104 +128,104 @@
#define TK_SELECT 109
#define TK_UNION 110
#define TK_ALL 111
#define TK_
FROM
112
#define TK_
VARIABLE
113
#define TK_
INTERVAL
114
#define TK_
FILL
115
#define TK_
SLIDING
116
#define TK_
ORDER
117
#define TK_
BY
118
#define TK_
ASC
119
#define TK_
DESC
120
#define TK_
GROUP
121
#define TK_
HAVING
122
#define TK_
LIMIT
123
#define TK_
OFFSET
124
#define TK_
SLIMI
T 125
#define TK_S
OFFSET
126
#define TK_
WHERE
127
#define TK_
NOW
128
#define TK_
RESET
129
#define TK_
QUERY
130
#define TK_
ADD
131
#define TK_
COLUMN
132
#define TK_
TAG
133
#define TK_
CHANGE
134
#define TK_
SET
135
#define TK_
KILL
136
#define TK_
CONNECTION
137
#define TK_
STREAM
138
#define TK_
COLON
139
#define TK_
ABORT
140
#define TK_A
FTER
141
#define TK_A
TTACH
142
#define TK_
BEFORE
143
#define TK_BE
GIN
144
#define TK_
CASCADE
145
#define TK_C
LUSTER
146
#define TK_C
ONFLICT
147
#define TK_CO
PY
148
#define TK_
DEFERRED
149
#define TK_DE
LIMITERS
150
#define TK_DE
TACH
151
#define TK_
EACH
152
#define TK_E
ND
153
#define TK_E
XPLAIN
154
#define TK_
FAIL
155
#define TK_F
OR
156
#define TK_
IGNORE
157
#define TK_I
MMEDIATE
158
#define TK_I
NITIALLY
159
#define TK_IN
STEAD
160
#define TK_
MATCH
161
#define TK_
KEY
162
#define TK_
OF
163
#define TK_
RAISE
164
#define TK_R
EPLACE
165
#define TK_RE
STRICT
166
#define TK_R
OW
167
#define TK_
STATEMENT
168
#define TK_
TRIGGER
169
#define TK_
VIEW
170
#define TK_
COUNT
171
#define TK_
SUM
172
#define TK_
AVG
173
#define TK_
MIN
174
#define TK_M
AX
175
#define TK_
FIRST
176
#define TK_
LAST
177
#define TK_
TOP
178
#define TK_
BOTTOM
179
#define TK_
STDDEV
180
#define TK_
PERCENTILE
181
#define TK_
APERCENTILE
182
#define TK_
LEASTSQUARES
183
#define TK_
HISTOGRAM
184
#define TK_
DIFF
185
#define TK_
SPREAD
186
#define TK_
TWA
187
#define TK_
INTERP
188
#define TK_
LAST_ROW
189
#define TK_
RATE
190
#define TK_
IRATE
191
#define TK_
SUM_RATE
192
#define TK_SUM_
IRATE
193
#define TK_
AVG_RATE
194
#define TK_AVG_
IRATE
195
#define TK_
TBID
196
#define TK_
SEMI
197
#define TK_
NONE
198
#define TK_
PREV
199
#define TK_
LINEAR
200
#define TK_
IMPORT
201
#define TK_
METRIC
202
#define TK_
TBNAME
203
#define TK_
JOIN
204
#define TK_
METRICS
205
#define TK_
INSERT
206
#define TK_IN
TO
207
#define TK_
VALUES
208
#define TK_
DISTINCT
112
#define TK_
FROM
113
#define TK_
VARIABLE
114
#define TK_
INTERVAL
115
#define TK_
FILL
116
#define TK_
SLIDING
117
#define TK_
ORDER
118
#define TK_
BY
119
#define TK_
ASC
120
#define TK_
DESC
121
#define TK_
GROUP
122
#define TK_
HAVING
123
#define TK_
LIMIT
124
#define TK_
OFFSE
T 125
#define TK_S
LIMIT
126
#define TK_
SOFFSET
127
#define TK_
WHERE
128
#define TK_
NOW
129
#define TK_
RESET
130
#define TK_
QUERY
131
#define TK_
ADD
132
#define TK_
COLUMN
133
#define TK_
TAG
134
#define TK_
CHANGE
135
#define TK_
SET
136
#define TK_
KILL
137
#define TK_
CONNECTION
138
#define TK_
STREAM
139
#define TK_
COLON
140
#define TK_A
BORT
141
#define TK_A
FTER
142
#define TK_
ATTACH
143
#define TK_BE
FORE
144
#define TK_
BEGIN
145
#define TK_C
ASCADE
146
#define TK_C
LUSTER
147
#define TK_CO
NFLICT
148
#define TK_
COPY
149
#define TK_DE
FERRED
150
#define TK_DE
LIMITERS
151
#define TK_
DETACH
152
#define TK_E
ACH
153
#define TK_E
ND
154
#define TK_
EXPLAIN
155
#define TK_F
AIL
156
#define TK_
FOR
157
#define TK_I
GNORE
158
#define TK_I
MMEDIATE
159
#define TK_IN
ITIALLY
160
#define TK_
INSTEAD
161
#define TK_
MATCH
162
#define TK_
KEY
163
#define TK_
OF
164
#define TK_R
AISE
165
#define TK_RE
PLACE
166
#define TK_R
ESTRICT
167
#define TK_
ROW
168
#define TK_
STATEMENT
169
#define TK_
TRIGGER
170
#define TK_
VIEW
171
#define TK_
COUNT
172
#define TK_
SUM
173
#define TK_
AVG
174
#define TK_M
IN
175
#define TK_
MAX
176
#define TK_
FIRST
177
#define TK_
LAST
178
#define TK_
TOP
179
#define TK_
BOTTOM
180
#define TK_
STDDEV
181
#define TK_
PERCENTILE
182
#define TK_
APERCENTILE
183
#define TK_
LEASTSQUARES
184
#define TK_
HISTOGRAM
185
#define TK_
DIFF
186
#define TK_
SPREAD
187
#define TK_
TWA
188
#define TK_
INTERP
189
#define TK_
LAST_ROW
190
#define TK_
RATE
191
#define TK_
IRATE
192
#define TK_SUM_
RATE
193
#define TK_
SUM_IRATE
194
#define TK_AVG_
RATE
195
#define TK_
AVG_IRATE
196
#define TK_
TBID
197
#define TK_
SEMI
198
#define TK_
NONE
199
#define TK_
PREV
200
#define TK_
LINEAR
201
#define TK_
IMPORT
202
#define TK_
METRIC
203
#define TK_
TBNAME
204
#define TK_
JOIN
205
#define TK_
METRICS
206
#define TK_IN
SERT
207
#define TK_
INTO
208
#define TK_VALUES 209
#define TK_SPACE 300
...
...
src/query/inc/qSqlparser.h
浏览文件 @
59be5440
...
...
@@ -200,6 +200,7 @@ typedef struct tSQLExpr {
typedef
struct
tSqlExprItem
{
tSQLExpr
*
pNode
;
// The list of expressions
char
*
aliasName
;
// alias name, null-terminated string
bool
distinct
;
}
tSqlExprItem
;
// todo refactor by using SArray
...
...
@@ -232,7 +233,7 @@ tSQLExpr *tSqlExprCreate(tSQLExpr *pLeft, tSQLExpr *pRight, int32_t optrType);
void
tSqlExprDestroy
(
tSQLExpr
*
pExpr
);
tSQLExprList
*
tSqlExprListAppend
(
tSQLExprList
*
pList
,
tSQLExpr
*
pNode
,
SStrToken
*
pToken
);
tSQLExprList
*
tSqlExprListAppend
(
tSQLExprList
*
pList
,
tSQLExpr
*
pNode
,
SStrToken
*
p
Distinct
,
SStrToken
*
p
Token
);
void
tSqlExprListDestroy
(
tSQLExprList
*
pList
);
...
...
src/query/inc/sql.y
浏览文件 @
59be5440
...
...
@@ -161,7 +161,7 @@ cmd ::= ALTER DNODE ids(X) ids(Y). { setDCLSQLElems(pInfo, TSDB_SQL
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); }
cmd ::= ALTER DATABASE ids(X) alter_db_optr(Y). { SStrToken t = {0}; setCreateD
BSQL
(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);}
cmd ::= ALTER DATABASE ids(X) alter_db_optr(Y). { SStrToken t = {0}; setCreateD
bInfo
(pInfo, TSDB_SQL_ALTER_DB, &X, &Y, &t);}
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);}
...
...
@@ -186,7 +186,7 @@ ifnotexists(X) ::= . { X.n = 0;}
cmd ::= CREATE DNODE ids(X). { setDCLSQLElems(pInfo, TSDB_SQL_CREATE_DNODE, 1, &X);}
cmd ::= CREATE ACCOUNT ids(X) PASS ids(Y) acct_optr(Z).
{ setCreateAcctSql(pInfo, TSDB_SQL_CREATE_ACCT, &X, &Y, &Z);}
cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateD
BSQL
(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);}
cmd ::= CREATE DATABASE ifnotexists(Z) ids(X) db_optr(Y). { setCreateD
bInfo
(pInfo, TSDB_SQL_CREATE_DB, &X, &Y, &Z);}
cmd ::= CREATE USER ids(X) PASS ids(Y). { setCreateUserSql(pInfo, &X, &Y);}
pps(Y) ::= . { Y.n = 0; }
...
...
@@ -457,13 +457,13 @@ select(A) ::= SELECT(T) selcollist(W). {
%destructor sclp {tSqlExprListDestroy($$);}
sclp(A) ::= selcollist(X) COMMA. {A = X;}
sclp(A) ::= . {A = 0;}
selcollist(A) ::= sclp(P) expr(X) as(Y). {
A = tSqlExprListAppend(P, X, Y.n?&Y:0);
selcollist(A) ::= sclp(P)
distinct(Z)
expr(X) as(Y). {
A = tSqlExprListAppend(P, X,
Z.n? &Z:0,
Y.n?&Y:0);
}
selcollist(A) ::= sclp(P) STAR. {
tSQLExpr *pNode = tSqlExprIdValueCreate(NULL, TK_ALL);
A = tSqlExprListAppend(P, pNode, 0);
A = tSqlExprListAppend(P, pNode, 0
, 0
);
}
// An option "AS <id>" phrase that can follow one of the expressions that
...
...
@@ -474,6 +474,10 @@ as(X) ::= AS ids(Y). { X = Y; }
as(X) ::= ids(Y). { X = Y; }
as(X) ::= . { X.n = 0; }
%type distinct {SStrToken}
distinct(X) ::= DISTINCT(Y). { X = Y; }
distinct(X) ::= . { X.n = 0;}
// A complete FROM clause.
%type from {SArray*}
// current not support query from no-table
...
...
@@ -681,8 +685,8 @@ expr(A) ::= expr(X) IN LP exprlist(Y) RP. {A = tSqlExprCreate(X, (tSQLExpr*)Y,
%type expritem {tSQLExpr*}
%destructor expritem {tSqlExprDestroy($$);}
exprlist(A) ::= exprlist(X) COMMA expritem(Y). {A = tSqlExprListAppend(X,Y,0);}
exprlist(A) ::= expritem(X). {A = tSqlExprListAppend(0,X,0);}
exprlist(A) ::= exprlist(X) COMMA expritem(Y). {A = tSqlExprListAppend(X,Y,0
, 0
);}
exprlist(A) ::= expritem(X). {A = tSqlExprListAppend(0,X,0
, 0
);}
expritem(A) ::= expr(X). {A = X;}
expritem(A) ::= . {A = 0;}
...
...
src/query/src/qParserImpl.c
浏览文件 @
59be5440
...
...
@@ -71,7 +71,7 @@ abort_parse:
return
sqlInfo
;
}
tSQLExprList
*
tSqlExprListAppend
(
tSQLExprList
*
pList
,
tSQLExpr
*
pNode
,
SStrToken
*
pToken
)
{
tSQLExprList
*
tSqlExprListAppend
(
tSQLExprList
*
pList
,
tSQLExpr
*
pNode
,
SStrToken
*
p
Distinct
,
SStrToken
*
p
Token
)
{
if
(
pList
==
NULL
)
{
pList
=
calloc
(
1
,
sizeof
(
tSQLExprList
));
}
...
...
@@ -97,6 +97,7 @@ tSQLExprList *tSqlExprListAppend(tSQLExprList *pList, tSQLExpr *pNode, SStrToken
strdequote
(
pItem
->
aliasName
);
}
pItem
->
distinct
=
(
pDistinct
!=
NULL
);
}
return
pList
;
}
...
...
src/query/src/qTokenizer.c
浏览文件 @
59be5440
...
...
@@ -240,6 +240,7 @@ static SKeyword keywordTable[] = {
{
"AVG_RATE"
,
TK_AVG_RATE
},
{
"AVG_IRATE"
,
TK_AVG_IRATE
},
{
"CACHELAST"
,
TK_CACHELAST
},
{
"DISTINCT"
,
TK_DISTINCT
},
};
static
const
char
isIdChar
[]
=
{
...
...
src/query/src/sql.c
浏览文件 @
59be5440
此差异已折叠。
点击以展开。
tests/script/general/parser/select_distinct_tag.sim
0 → 100644
浏览文件 @
59be5440
system sh/stop_dnodes.sh
system sh/deploy.sh -n dnode1 -i 1
system sh/cfg.sh -n dnode1 -c walLevel -v 0
system sh/cfg.sh -n dnode1 -c maxtablesPerVnode -v 5
system sh/exec.sh -n dnode1 -s start
sleep 100
sql connect
$dbPrefix = sav_db
$tbPrefix = sav_tb
$stbPrefix = sav_stb
$tbNum = 20
$rowNum = 10
$totalNum = $tbNum * $rowNum
$ts0 = 1537146000000
$delta = 600000
print ========== alter.sim
$i = 0
$db = $dbPrefix
$stb = $stbPrefix
sql drop database if exists $db
sql create database $db
sql use $db
print ====== create tables
sql create table $stb (ts timestamp, c1 int, c2 bigint, c3 float, c4 double, c5 smallint, c6 tinyint, c7 bool, c8 binary(10), c9 nchar(10)) tags(t1 int, t2 int)
$i = 0
$ts = $ts0
while $i < $tbNum
$tb = $tbPrefix . $i
sql create table $tb using $stb tags( $i , 0 )
$i = $i + 1
endw
print ====== table created
#### select distinct tag
sql select distinct t1 from $stb
if $rows != $tbNum then
return -1
endi
#### select distinct tag
sql select distinct t2 from $stb
if $rows != 1 then
print $rows
return -1
endi
#### unsupport sql
sql_error select distinct t1, t2 from &stb
sql drop database $db
sql show databases
if $rows != 0 then
return -1
endi
system sh/exec.sh -n dnode1 -s stop -x SIGINT
tests/script/jenkins/basic.txt
浏览文件 @
59be5440
...
...
@@ -159,6 +159,7 @@ cd ../../../debug; make
./test.sh -f general/parser/union.sim
./test.sh -f general/parser/topbot.sim
./test.sh -f general/parser/function.sim
./test.sh -f general/parser/select_distinct_tag.sim
./test.sh -f general/stable/disk.sim
./test.sh -f general/stable/dnode3.sim
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录