Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_40195168达庆意
TDengine
提交
a41f5bda
TDengine
项目概览
weixin_40195168达庆意
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
a41f5bda
编写于
4月 23, 2021
作者:
H
haojun Liao
提交者:
GitHub
4月 23, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5886 from taosdata/hotfix/TD-3907
[TD-3907]filter timestamp
上级
2d4bc753
2ab82ca4
变更
6
展开全部
隐藏空白更改
内联
并排
Showing
6 changed file
with
419 addition
and
367 deletion
+419
-367
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+24
-3
src/inc/ttokendef.h
src/inc/ttokendef.h
+2
-0
src/query/inc/qSqlparser.h
src/query/inc/qSqlparser.h
+8
-1
src/query/inc/sql.y
src/query/inc/sql.y
+2
-0
src/query/src/qSqlParser.c
src/query/src/qSqlParser.c
+12
-1
src/query/src/sql.c
src/query/src/sql.c
+371
-362
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
a41f5bda
...
...
@@ -3078,7 +3078,7 @@ static SColumnFilterInfo* addColumnFilterInfo(SColumn* pColumn) {
return
pColFilterInfo
;
}
static
int32_t
doExtractColumnFilterInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
SColumnFilterInfo
*
pColumnFilter
,
static
int32_t
doExtractColumnFilterInfo
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
S
TableMeta
*
pTableMeta
,
S
ColumnFilterInfo
*
pColumnFilter
,
int16_t
colType
,
tSqlExpr
*
pExpr
)
{
const
char
*
msg
=
"not supported filter condition"
;
...
...
@@ -3093,6 +3093,12 @@ static int32_t doExtractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo,
if
(
TSDB_CODE_SUCCESS
!=
retVal
)
{
return
retVal
;
}
}
else
if
((
colType
==
TSDB_DATA_TYPE_TIMESTAMP
)
&&
(
TSDB_DATA_TYPE_BIGINT
==
pRight
->
value
.
nType
))
{
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMeta
);
if
((
tinfo
.
precision
==
TSDB_TIME_PRECISION_MILLI
)
&&
(
pRight
->
flags
&
(
1
<<
EXPR_FLAG_US_TIMESTAMP
)))
{
pRight
->
value
.
i64
/=
1000
;
}
}
int32_t
retVal
=
TSDB_CODE_SUCCESS
;
...
...
@@ -3291,7 +3297,7 @@ static int32_t extractColumnFilterInfo(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, SC
int16_t
colType
=
pSchema
->
type
;
return
doExtractColumnFilterInfo
(
pCmd
,
pQueryInfo
,
pColFilter
,
colType
,
pExpr
);
return
doExtractColumnFilterInfo
(
pCmd
,
pQueryInfo
,
p
TableMeta
,
p
ColFilter
,
colType
,
pExpr
);
}
static
int32_t
getTablenameCond
(
SSqlCmd
*
pCmd
,
SQueryInfo
*
pQueryInfo
,
tSqlExpr
*
pTableCond
,
SStringBuilder
*
sb
)
{
...
...
@@ -3916,6 +3922,10 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr
const
char
*
msg1
=
"query condition between different columns must use 'AND'"
;
if
((
*
pExpr
)
->
flags
&
(
1
<<
EXPR_FLAG_TS_ERROR
))
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
tSqlExpr
*
pLeft
=
(
*
pExpr
)
->
pLeft
;
tSqlExpr
*
pRight
=
(
*
pExpr
)
->
pRight
;
...
...
@@ -3953,6 +3963,14 @@ int32_t getQueryCondExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr** pExpr
exchangeExpr
(
*
pExpr
);
if
(
pLeft
->
tokenId
==
TK_ID
&&
pRight
->
tokenId
==
TK_TIMESTAMP
&&
(
pRight
->
flags
&
(
1
<<
EXPR_FLAG_TIMESTAMP_VAR
)))
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
if
((
pLeft
->
flags
&
(
1
<<
EXPR_FLAG_TS_ERROR
))
||
(
pRight
->
flags
&
(
1
<<
EXPR_FLAG_TS_ERROR
)))
{
return
TSDB_CODE_TSC_INVALID_SQL
;
}
return
handleExprInQueryCond
(
pCmd
,
pQueryInfo
,
pExpr
,
pCondExpr
,
type
,
parentOptr
);
}
...
...
@@ -6927,7 +6945,10 @@ static int32_t handleExprInHavingClause(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
}
}
int32_t
ret
=
doExtractColumnFilterInfo
(
pCmd
,
pQueryInfo
,
pColFilter
,
pInfo
->
field
.
type
,
pExpr
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
0
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
int32_t
ret
=
doExtractColumnFilterInfo
(
pCmd
,
pQueryInfo
,
pTableMeta
,
pColFilter
,
pInfo
->
field
.
type
,
pExpr
);
if
(
ret
)
{
return
ret
;
}
...
...
src/inc/ttokendef.h
浏览文件 @
a41f5bda
...
...
@@ -210,6 +210,8 @@
#define TK_SPACE 300
#define TK_COMMENT 301
#define TK_ILLEGAL 302
...
...
src/query/inc/qSqlparser.h
浏览文件 @
a41f5bda
...
...
@@ -44,6 +44,12 @@ enum SQL_NODE_FROM_TYPE {
SQL_NODE_FROM_NAMELIST
=
2
,
};
enum
SQL_EXPR_FLAG
{
EXPR_FLAG_TS_ERROR
=
1
,
EXPR_FLAG_US_TIMESTAMP
=
2
,
EXPR_FLAG_TIMESTAMP_VAR
=
3
,
};
extern
char
tTokenTypeSwitcher
[
13
];
#define toTSDBType(x) \
...
...
@@ -237,7 +243,8 @@ typedef struct tSqlExpr {
SStrToken
colInfo
;
// table column info
tVariant
value
;
// the use input value
SStrToken
token
;
// original sql expr string
uint32_t
flags
;
struct
tSqlExpr
*
pLeft
;
// left child
struct
tSqlExpr
*
pRight
;
// right child
struct
SArray
*
pParam
;
// function parameters list
...
...
src/query/inc/sql.y
浏览文件 @
a41f5bda
...
...
@@ -674,6 +674,8 @@ expr(A) ::= PLUS(X) FLOAT(Y). { X.n += Y.n; X.type = TK_FLOAT; A = tSqlExprCr
expr(A) ::= STRING(X). { A = tSqlExprCreateIdValue(&X, TK_STRING);}
expr(A) ::= NOW(X). { A = tSqlExprCreateIdValue(&X, TK_NOW); }
expr(A) ::= VARIABLE(X). { A = tSqlExprCreateIdValue(&X, TK_VARIABLE);}
expr(A) ::= PLUS(X) VARIABLE(Y). { X.n += Y.n; X.type = TK_VARIABLE; A = tSqlExprCreateIdValue(&X, TK_VARIABLE);}
expr(A) ::= MINUS(X) VARIABLE(Y). { X.n += Y.n; X.type = TK_VARIABLE; A = tSqlExprCreateIdValue(&X, TK_VARIABLE);}
expr(A) ::= BOOL(X). { A = tSqlExprCreateIdValue(&X, TK_BOOL);}
expr(A) ::= NULL(X). { A = tSqlExprCreateIdValue(&X, TK_NULL);}
...
...
src/query/src/qSqlParser.c
浏览文件 @
a41f5bda
...
...
@@ -144,12 +144,15 @@ tSqlExpr *tSqlExprCreateIdValue(SStrToken *pToken, int32_t optrType) {
pSqlExpr
->
value
.
nType
=
TSDB_DATA_TYPE_BIGINT
;
pSqlExpr
->
tokenId
=
TK_TIMESTAMP
;
// TK_TIMESTAMP used to denote the time value is in microsecond
pSqlExpr
->
type
=
SQL_NODE_VALUE
;
pSqlExpr
->
flags
|=
1
<<
EXPR_FLAG_US_TIMESTAMP
;
}
else
if
(
optrType
==
TK_VARIABLE
)
{
int32_t
ret
=
parseAbsoluteDuration
(
pToken
->
z
,
pToken
->
n
,
&
pSqlExpr
->
value
.
i64
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
TSDB_CODE_TSC_SQL_SYNTAX_ERROR
;
}
pSqlExpr
->
flags
|=
1
<<
EXPR_FLAG_US_TIMESTAMP
;
pSqlExpr
->
flags
|=
1
<<
EXPR_FLAG_TIMESTAMP_VAR
;
pSqlExpr
->
value
.
nType
=
TSDB_DATA_TYPE_BIGINT
;
pSqlExpr
->
tokenId
=
TK_TIMESTAMP
;
pSqlExpr
->
type
=
SQL_NODE_VALUE
;
...
...
@@ -217,6 +220,15 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
pExpr
->
value
.
nType
=
TSDB_DATA_TYPE_BIGINT
;
pExpr
->
tokenId
=
pLeft
->
tokenId
;
pExpr
->
type
=
SQL_NODE_VALUE
;
pExpr
->
flags
=
pLeft
->
flags
|
pRight
->
flags
;
if
((
pLeft
->
flags
&
(
1
<<
EXPR_FLAG_TIMESTAMP_VAR
))
&&
(
pRight
->
flags
&
(
1
<<
EXPR_FLAG_TIMESTAMP_VAR
)))
{
pExpr
->
flags
|=
1
<<
EXPR_FLAG_TS_ERROR
;
}
else
{
pExpr
->
flags
&=
~
(
1
<<
EXPR_FLAG_TIMESTAMP_VAR
);
pExpr
->
flags
&=
~
(
1
<<
EXPR_FLAG_TS_ERROR
);
}
switch
(
optrType
)
{
case
TK_PLUS
:
{
...
...
@@ -245,7 +257,6 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
tSqlExprDestroy
(
pLeft
);
tSqlExprDestroy
(
pRight
);
}
else
if
((
pLeft
->
tokenId
==
TK_FLOAT
&&
pRight
->
tokenId
==
TK_INTEGER
)
||
(
pLeft
->
tokenId
==
TK_INTEGER
&&
pRight
->
tokenId
==
TK_FLOAT
)
||
(
pLeft
->
tokenId
==
TK_FLOAT
&&
pRight
->
tokenId
==
TK_FLOAT
))
{
...
...
src/query/src/sql.c
浏览文件 @
a41f5bda
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录