Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
4456951e
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看板
提交
4456951e
编写于
9月 10, 2020
作者:
B
Bomin Zhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
td-1245: update sql grammar to support offset
上级
1487bc58
变更
8
展开全部
隐藏空白更改
内联
并排
Showing
8 changed file
with
1335 addition
and
996 deletion
+1335
-996
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+2
-1
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+42
-0
src/inc/taosmsg.h
src/inc/taosmsg.h
+2
-1
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+7
-1
src/query/inc/sql.y
src/query/inc/sql.y
+4
-3
src/query/src/qParserImpl.c
src/query/src/qParserImpl.c
+3
-2
src/query/src/sql.c
src/query/src/sql.c
+1275
-988
src/util/src/tarray.c
src/util/src/tarray.c
+0
-0
未找到文件。
src/client/inc/tsclient.h
浏览文件 @
4456951e
...
...
@@ -228,10 +228,11 @@ typedef struct SQueryInfo {
// TODO refactor
char
intervalTimeUnit
;
char
slidingTimeUnit
;
char
offsetTimeUnit
;
STimeWindow
window
;
// query time window
int64_t
intervalTime
;
// aggregation time window range
int64_t
slidingTime
;
// sliding window in mseconds
int64_t
intervalOffset
;
// start offset of each time window
int64_t
offsetTime
;
// start offset of each time window
int32_t
tz
;
// query client timezone
SSqlGroupbyExpr
groupbyExpr
;
// group by tags info
...
...
src/client/src/tscSQLParser.c
浏览文件 @
4456951e
...
...
@@ -81,6 +81,7 @@ static void setColumnOffsetValueInResultset(SQueryInfo* pQueryInfo);
static
int32_t
parseGroupbyClause
(
SQueryInfo
*
pQueryInfo
,
tVariantList
*
pList
,
SSqlCmd
*
pCmd
);
static
int32_t
parseIntervalClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQuerySQL
*
pQuerySql
);
static
int32_t
parseOffsetClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQuerySQL
*
pQuerySql
);
static
int32_t
parseSlidingClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQuerySQL
*
pQuerySql
);
static
int32_t
addProjectionExprAndResultField
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSQLExprItem
*
pItem
);
...
...
@@ -613,6 +614,10 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQ
// for top/bottom + interval query, we do not add additional timestamp column in the front
if
(
isTopBottomQuery
(
pQueryInfo
))
{
if
(
parseOffsetClause
(
pCmd
,
pQueryInfo
,
pQuerySql
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
if
(
parseSlidingClause
(
pCmd
,
pQueryInfo
,
pQuerySql
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
...
...
@@ -662,6 +667,10 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQ
SColumnIndex
index
=
{
tableIndex
,
PRIMARYKEY_TIMESTAMP_COL_INDEX
};
tscAddSpecialColumnForSelect
(
pQueryInfo
,
0
,
TSDB_FUNC_TS
,
&
index
,
&
s
,
TSDB_COL_NORMAL
);
if
(
parseOffsetClause
(
pCmd
,
pQueryInfo
,
pQuerySql
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
if
(
parseSlidingClause
(
pCmd
,
pQueryInfo
,
pQuerySql
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
...
...
@@ -669,6 +678,39 @@ int32_t parseIntervalClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SQuerySQL* pQ
return
TSDB_CODE_SUCCESS
;
}
int32_t
parseOffsetClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQuerySQL
*
pQuerySql
)
{
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMetaInfo
->
pTableMeta
);
SStrToken
*
pOffset
=
&
pQuerySql
->
offset
;
if
(
pOffset
->
n
==
0
)
{
pQueryInfo
->
offsetTimeUnit
=
pQueryInfo
->
offsetTimeUnit
;
pQueryInfo
->
offsetTime
=
0
;
return
TSDB_CODE_SUCCESS
;
}
getTimestampInUsFromStr
(
pOffset
->
z
,
pOffset
->
n
,
&
pQueryInfo
->
offsetTime
);
if
(
tinfo
.
precision
==
TSDB_TIME_PRECISION_MILLI
)
{
pQueryInfo
->
offsetTime
/=
1000
;
}
/*
if (pQueryInfo->offsetTime < 0) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg0);
}
if (pQueryInfo->slidingTime >= pQueryInfo->intervalTime) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg1);
}
if ((pQueryInfo->intervalTime != 0) && (pQueryInfo->intervalTime/pQueryInfo->slidingTime > INTERVAL_SLIDING_FACTOR)) {
return invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg2);
}
*/
return
TSDB_CODE_SUCCESS
;
}
int32_t
parseSlidingClause
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SQuerySQL
*
pQuerySql
)
{
const
char
*
msg0
=
"sliding value too small"
;
const
char
*
msg1
=
"sliding value no larger than the interval value"
;
...
...
src/inc/taosmsg.h
浏览文件 @
4456951e
...
...
@@ -461,10 +461,11 @@ typedef struct {
int16_t
orderColId
;
int16_t
numOfCols
;
// the number of columns will be load from vnode
int64_t
intervalTime
;
// time interval for aggregation, in million second
int64_t
intervalOffset
;
// start offset for interval query
int64_t
slidingTime
;
// value for sliding window
int64_t
offsetTime
;
// start offset for interval query
char
intervalTimeUnit
;
char
slidingTimeUnit
;
// time interval type, for revisement of interval(1d)
char
offsetTimeUnit
;
uint16_t
tagCondLen
;
// tag length in current query
int16_t
numOfGroupCols
;
// num of group by columns
int16_t
orderByIdx
;
...
...
src/query/inc/qSqlparser.h
浏览文件 @
4456951e
...
...
@@ -65,6 +65,11 @@ typedef struct tVariantList {
tVariantListItem
*
a
;
/* One entry for each expression */
}
tVariantList
;
typedef
struct
SIntervalVal
{
SStrToken
interval
;
SStrToken
offset
;
}
SIntervalVal
;
typedef
struct
SQuerySQL
{
struct
tSQLExprList
*
pSelection
;
// select clause
tVariantList
*
from
;
// from clause
...
...
@@ -72,6 +77,7 @@ typedef struct SQuerySQL {
tVariantList
*
pGroupby
;
// groupby clause, only for tags[optional]
tVariantList
*
pSortOrder
;
// orderby [optional]
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]
...
...
@@ -259,7 +265,7 @@ 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
,
S
StrToken
*
pInterval
,
tVariantList
*
pGroupby
,
tVariantList
*
pSortOrder
,
S
IntervalVal
*
pInterval
,
SStrToken
*
pSliding
,
tVariantList
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pGLimit
);
SCreateTableSQL
*
tSetCreateSQLElems
(
tFieldList
*
pCols
,
tFieldList
*
pTags
,
SStrToken
*
pMetricName
,
...
...
src/query/inc/sql.y
浏览文件 @
4456951e
...
...
@@ -458,9 +458,10 @@ tablelist(A) ::= tablelist(Y) COMMA ids(X) cpxName(Z) ids(F). {
%type tmvar {SStrToken}
tmvar(A) ::= VARIABLE(X). {A = X;}
%type interval_opt {SStrToken}
interval_opt(N) ::= INTERVAL LP tmvar(E) RP. {N = E; }
interval_opt(N) ::= . {N.n = 0; N.z = NULL; N.type = 0; }
%type interval_opt {SIntervalVal}
interval_opt(N) ::= INTERVAL LP tmvar(E) RP. {N.interval = E; N.offset.n = 0; N.offset.z = NULL; N.offset.type = 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 {tVariantListDestroy($$);}
...
...
src/query/src/qParserImpl.c
浏览文件 @
4456951e
...
...
@@ -535,7 +535,7 @@ 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
,
S
StrToken
*
pInterval
,
tVariantList
*
pGroupby
,
tVariantList
*
pSortOrder
,
S
IntervalVal
*
pInterval
,
SStrToken
*
pSliding
,
tVariantList
*
pFill
,
SLimitVal
*
pLimit
,
SLimitVal
*
pGLimit
)
{
assert
(
pSelection
!=
NULL
);
...
...
@@ -558,7 +558,8 @@ SQuerySQL *tSetQuerySQLElems(SStrToken *pSelectToken, tSQLExprList *pSelection,
}
if
(
pInterval
!=
NULL
)
{
pQuery
->
interval
=
*
pInterval
;
pQuery
->
interval
=
pInterval
->
interval
;
pQuery
->
offset
=
pInterval
->
offset
;
}
if
(
pSliding
!=
NULL
)
{
...
...
src/query/src/sql.c
浏览文件 @
4456951e
此差异已折叠。
点击以展开。
src/util/src/tarray.c
100755 → 100644
浏览文件 @
4456951e
文件模式从 100755 更改为 100644
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录