Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
f0a32e5c
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
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看板
提交
f0a32e5c
编写于
3月 11, 2021
作者:
D
dapan1121
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
pass expr filter to taosd
上级
a19ed6e9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
158 addition
and
36 deletion
+158
-36
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+16
-14
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+1
-0
src/client/src/tscServer.c
src/client/src/tscServer.c
+36
-0
src/inc/taosmsg.h
src/inc/taosmsg.h
+27
-21
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+78
-1
未找到文件。
src/client/inc/tsclient.h
浏览文件 @
f0a32e5c
...
...
@@ -96,20 +96,6 @@ typedef struct STableMetaInfo {
SArray
*
tagColList
;
// SArray<SColumn*>, involved tag columns
}
STableMetaInfo
;
/* the structure for sql function in select clause */
typedef
struct
SSqlExpr
{
char
aliasName
[
TSDB_COL_NAME_LEN
];
// as aliasName
SColIndex
colInfo
;
uint64_t
uid
;
// refactor use the pointer
int16_t
functionId
;
// function id in aAgg array
int16_t
resType
;
// return value type
int16_t
resBytes
;
// length of return value
int32_t
interBytes
;
// inter result buffer size
int16_t
numOfParams
;
// argument value of each function
tVariant
param
[
3
];
// parameters are not more than 3
int32_t
offset
;
// sub result column value of arithmetic expression.
int16_t
resColId
;
// result column id
}
SSqlExpr
;
typedef
struct
SColumnIndex
{
int16_t
tableIndex
;
...
...
@@ -129,6 +115,22 @@ typedef struct SColumn {
SColumnFilterInfo
*
filterInfo
;
}
SColumn
;
/* the structure for sql function in select clause */
typedef
struct
SSqlExpr
{
char
aliasName
[
TSDB_COL_NAME_LEN
];
// as aliasName
SColIndex
colInfo
;
uint64_t
uid
;
// refactor use the pointer
int16_t
functionId
;
// function id in aAgg array
int16_t
resType
;
// return value type
int16_t
resBytes
;
// length of return value
int32_t
interBytes
;
// inter result buffer size
int16_t
numOfParams
;
// argument value of each function
tVariant
param
[
3
];
// parameters are not more than 3
int32_t
offset
;
// sub result column value of arithmetic expression.
int16_t
resColId
;
// result column id
SColumn
*
pFilter
;
// expr filter
}
SSqlExpr
;
typedef
struct
SExprFilter
{
tSQLExpr
*
pExpr
;
//used for having parse
SSqlExpr
*
pSqlExpr
;
...
...
src/client/src/tscSQLParser.c
浏览文件 @
f0a32e5c
...
...
@@ -6735,6 +6735,7 @@ static int32_t checkQueryRangeForFill(SSqlCmd* pCmd, SQueryInfo* pQueryInfo) {
pFieldFilters
->
pFilters
=
pFilters
;
pFieldFilters
->
pSqlExpr
=
pSqlExpr
;
pSqlExpr
->
pFilter
=
pFilters
;
pInfo
->
pFieldFilters
=
pFieldFilters
;
}
...
...
src/client/src/tscServer.c
浏览文件 @
f0a32e5c
...
...
@@ -838,8 +838,44 @@ int tscBuildQueryMsg(SSqlObj *pSql, SSqlInfo *pInfo) {
pSqlFuncExpr
->
functionId
=
htons
(
pExpr
->
functionId
);
pSqlFuncExpr
->
numOfParams
=
htons
(
pExpr
->
numOfParams
);
pSqlFuncExpr
->
resColId
=
htons
(
pExpr
->
resColId
);
if
(
pExpr
->
pFilter
&&
pExpr
->
pFilter
->
numOfFilters
>
0
)
{
pSqlFuncExpr
->
filterNum
=
htonl
(
pExpr
->
pFilter
->
numOfFilters
);
}
else
{
pSqlFuncExpr
->
filterNum
=
0
;
}
pMsg
+=
sizeof
(
SSqlFuncMsg
);
if
(
pSqlFuncExpr
->
filterNum
)
{
pMsg
+=
sizeof
(
SColumnFilterInfo
)
*
pExpr
->
pFilter
->
numOfFilters
;
// append the filter information after the basic column information
for
(
int32_t
f
=
0
;
f
<
pExpr
->
pFilter
->
numOfFilters
;
++
f
)
{
SColumnFilterInfo
*
pColFilter
=
&
pExpr
->
pFilter
->
filterInfo
[
f
];
SColumnFilterInfo
*
pFilterMsg
=
&
pSqlFuncExpr
->
filterInfo
[
f
];
pFilterMsg
->
filterstr
=
htons
(
pColFilter
->
filterstr
);
if
(
pColFilter
->
filterstr
)
{
pFilterMsg
->
len
=
htobe64
(
pColFilter
->
len
);
memcpy
(
pMsg
,
(
void
*
)
pColFilter
->
pz
,
(
size_t
)(
pColFilter
->
len
+
1
));
pMsg
+=
(
pColFilter
->
len
+
1
);
// append the additional filter binary info
}
else
{
pFilterMsg
->
lowerBndi
=
htobe64
(
pColFilter
->
lowerBndi
);
pFilterMsg
->
upperBndi
=
htobe64
(
pColFilter
->
upperBndi
);
}
pFilterMsg
->
lowerRelOptr
=
htons
(
pColFilter
->
lowerRelOptr
);
pFilterMsg
->
upperRelOptr
=
htons
(
pColFilter
->
upperRelOptr
);
if
(
pColFilter
->
lowerRelOptr
==
TSDB_RELATION_INVALID
&&
pColFilter
->
upperRelOptr
==
TSDB_RELATION_INVALID
)
{
tscError
(
"invalid filter info"
);
return
TSDB_CODE_TSC_INVALID_SQL
;
}
}
}
for
(
int32_t
j
=
0
;
j
<
pExpr
->
numOfParams
;
++
j
)
{
// todo add log
pSqlFuncExpr
->
arg
[
j
].
argType
=
htons
((
uint16_t
)
pExpr
->
param
[
j
].
nType
);
...
...
src/inc/taosmsg.h
浏览文件 @
f0a32e5c
...
...
@@ -390,6 +390,28 @@ typedef struct SColIndex {
char
name
[
TSDB_COL_NAME_LEN
];
}
SColIndex
;
typedef
struct
SColumnFilterInfo
{
int16_t
lowerRelOptr
;
int16_t
upperRelOptr
;
int16_t
filterstr
;
// denote if current column is char(binary/nchar)
union
{
struct
{
int64_t
lowerBndi
;
int64_t
upperBndi
;
};
struct
{
double
lowerBndd
;
double
upperBndd
;
};
struct
{
int64_t
pz
;
int64_t
len
;
};
};
}
SColumnFilterInfo
;
/* sql function msg, to describe the message to vnode about sql function
* operations in select clause */
typedef
struct
SSqlFuncMsg
{
...
...
@@ -407,10 +429,15 @@ typedef struct SSqlFuncMsg {
char
*
pz
;
}
argValue
;
}
arg
[
3
];
int32_t
filterNum
;
SColumnFilterInfo
filterInfo
[];
}
SSqlFuncMsg
;
typedef
struct
SExprInfo
{
SSqlFuncMsg
base
;
SColumnFilterInfo
*
pFilter
;
struct
tExprNode
*
pExpr
;
int16_t
bytes
;
int16_t
type
;
...
...
@@ -418,27 +445,6 @@ typedef struct SExprInfo {
int64_t
uid
;
}
SExprInfo
;
typedef
struct
SColumnFilterInfo
{
int16_t
lowerRelOptr
;
int16_t
upperRelOptr
;
int16_t
filterstr
;
// denote if current column is char(binary/nchar)
union
{
struct
{
int64_t
lowerBndi
;
int64_t
upperBndi
;
};
struct
{
double
lowerBndd
;
double
upperBndd
;
};
struct
{
int64_t
pz
;
int64_t
len
;
};
};
}
SColumnFilterInfo
;
/*
* for client side struct, we only need the column id, type, bytes are not necessary
* But for data in vnode side, we need all the following information.
...
...
src/query/src/qExecutor.c
浏览文件 @
f0a32e5c
...
...
@@ -6120,9 +6120,35 @@ int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param) {
pExprMsg
->
functionId
=
htons
(
pExprMsg
->
functionId
);
pExprMsg
->
numOfParams
=
htons
(
pExprMsg
->
numOfParams
);
pExprMsg
->
resColId
=
htons
(
pExprMsg
->
resColId
);
pExprMsg
->
filterNum
=
htonl
(
pExprMsg
->
filterNum
);
pMsg
+=
sizeof
(
SSqlFuncMsg
);
SColumnFilterInfo
*
pExprFilterInfo
=
pExprMsg
->
filterInfo
;
pMsg
+=
sizeof
(
SColumnFilterInfo
)
*
pExprMsg
->
filterNum
;
for
(
int32_t
f
=
0
;
f
<
pExprMsg
->
filterNum
;
++
f
)
{
SColumnFilterInfo
*
pFilterMsg
=
(
SColumnFilterInfo
*
)
pExprFilterInfo
;
pFilterMsg
->
filterstr
=
htons
(
pFilterMsg
->
filterstr
);
if
(
pFilterMsg
->
filterstr
)
{
pFilterMsg
->
len
=
htobe64
(
pFilterMsg
->
len
);
pFilterMsg
->
pz
=
(
int64_t
)
pMsg
;
pMsg
+=
(
pFilterMsg
->
len
+
1
);
}
else
{
pFilterMsg
->
lowerBndi
=
htobe64
(
pFilterMsg
->
lowerBndi
);
pFilterMsg
->
upperBndi
=
htobe64
(
pFilterMsg
->
upperBndi
);
}
pFilterMsg
->
lowerRelOptr
=
htons
(
pFilterMsg
->
lowerRelOptr
);
pFilterMsg
->
upperRelOptr
=
htons
(
pFilterMsg
->
upperRelOptr
);
pExprFilterInfo
++
;
}
for
(
int32_t
j
=
0
;
j
<
pExprMsg
->
numOfParams
;
++
j
)
{
pExprMsg
->
arg
[
j
].
argType
=
htons
(
pExprMsg
->
arg
[
j
].
argType
);
pExprMsg
->
arg
[
j
].
argBytes
=
htons
(
pExprMsg
->
arg
[
j
].
argBytes
);
...
...
@@ -6304,6 +6330,42 @@ _cleanup:
return
code
;
}
int32_t
cloneExprFilterInfo
(
SColumnFilterInfo
**
dst
,
SColumnFilterInfo
*
src
,
int32_t
filterNum
)
{
if
(
filterNum
<=
0
)
{
return
TSDB_CODE_SUCCESS
;
}
*
dst
=
calloc
(
filterNum
,
sizeof
(
*
src
));
if
(
*
dst
==
NULL
)
{
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
memcpy
(
*
dst
,
src
,
sizeof
(
*
src
)
*
filterNum
);
for
(
int32_t
i
=
0
;
i
<
filterNum
;
i
++
)
{
if
(
dst
[
i
]
->
filterstr
&&
dst
[
i
]
->
len
>
0
)
{
void
*
pz
=
calloc
(
1
,
dst
[
i
]
->
len
+
1
);
if
(
pz
==
NULL
)
{
if
(
i
==
0
)
{
free
(
*
dst
);
}
else
{
freeColumnFilterInfo
(
*
dst
,
i
);
}
return
TSDB_CODE_QRY_OUT_OF_MEMORY
;
}
memcpy
(
pz
,
(
void
*
)
src
->
pz
,
src
->
len
+
1
);
dst
[
i
]
->
pz
=
(
int64_t
)
pz
;
}
}
return
TSDB_CODE_SUCCESS
;
}
static
int32_t
buildArithmeticExprFromMsg
(
SExprInfo
*
pArithExprInfo
,
SQueryTableMsg
*
pQueryMsg
)
{
qDebug
(
"qmsg:%p create arithmetic expr from binary"
,
pQueryMsg
);
...
...
@@ -6396,6 +6458,13 @@ int32_t createQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutpu
type
=
s
->
type
;
bytes
=
s
->
bytes
;
}
if
(
pExprs
[
i
].
base
.
filterNum
>
0
)
{
int32_t
ret
=
cloneExprFilterInfo
(
&
pExprs
[
i
].
pFilter
,
pExprMsg
[
i
]
->
filterInfo
,
pExprMsg
[
i
]
->
filterNum
);
if
(
ret
)
{
return
ret
;
}
}
}
int32_t
param
=
(
int32_t
)
pExprs
[
i
].
base
.
arg
[
0
].
argValue
.
i64
;
...
...
@@ -6770,6 +6839,10 @@ _cleanup_query:
tExprTreeDestroy
(
pExprInfo
->
pExpr
,
NULL
);
pExprInfo
->
pExpr
=
NULL
;
}
if
(
pExprInfo
->
pFilter
)
{
freeColumnFilterInfo
(
pExprInfo
->
pFilter
,
pExprInfo
->
base
.
filterNum
);
}
}
tfree
(
pExprs
);
...
...
@@ -6850,7 +6923,7 @@ void freeColumnFilterInfo(SColumnFilterInfo* pFilter, int32_t numOfFilters) {
}
for
(
int32_t
i
=
0
;
i
<
numOfFilters
;
i
++
)
{
if
(
pFilter
[
i
].
filterstr
)
{
if
(
pFilter
[
i
].
filterstr
&&
pFilter
[
i
].
pz
)
{
free
((
void
*
)(
pFilter
[
i
].
pz
));
}
}
...
...
@@ -6892,6 +6965,10 @@ static void* destroyQueryFuncExpr(SExprInfo* pExprInfo, int32_t numOfExpr) {
if
(
pExprInfo
[
i
].
pExpr
!=
NULL
)
{
tExprTreeDestroy
(
pExprInfo
[
i
].
pExpr
,
NULL
);
}
if
(
pExprInfo
[
i
].
pFilter
)
{
freeColumnFilterInfo
(
pExprInfo
[
i
].
pFilter
,
pExprInfo
[
i
].
base
.
filterNum
);
}
}
tfree
(
pExprInfo
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录