Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
036695d4
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看板
提交
036695d4
编写于
4月 27, 2020
作者:
weixin_48148422
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-153: make whole project compile
上级
241f7a22
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
156 addition
and
126 deletion
+156
-126
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+2
-1
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+21
-5
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+4
-4
src/query/inc/qast.h
src/query/inc/qast.h
+3
-2
src/query/src/qast.c
src/query/src/qast.c
+89
-93
src/query/tests/astTest.cpp
src/query/tests/astTest.cpp
+10
-8
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+26
-11
src/util/inc/tbuffer.h
src/util/inc/tbuffer.h
+1
-2
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
036695d4
...
@@ -25,6 +25,7 @@ extern "C" {
...
@@ -25,6 +25,7 @@ extern "C" {
*/
*/
#include "os.h"
#include "os.h"
#include "tbuffer.h"
#include "tbuffer.h"
#include "exception.h"
#include "qextbuffer.h"
#include "qextbuffer.h"
#include "taosdef.h"
#include "taosdef.h"
#include "tscSecondaryMerge.h"
#include "tscSecondaryMerge.h"
...
@@ -177,7 +178,7 @@ bool tscValidateColumnId(STableMetaInfo* pTableMetaInfo, int32_t colId);
...
@@ -177,7 +178,7 @@ bool tscValidateColumnId(STableMetaInfo* pTableMetaInfo, int32_t colId);
// get starter position of metric query condition (query on tags) in SSqlCmd.payload
// get starter position of metric query condition (query on tags) in SSqlCmd.payload
SCond
*
tsGetSTableQueryCond
(
STagCond
*
pCond
,
uint64_t
uid
);
SCond
*
tsGetSTableQueryCond
(
STagCond
*
pCond
,
uint64_t
uid
);
void
tsSetSTableQueryCond
(
STagCond
*
pTagCond
,
uint64_t
uid
,
SBuffer
*
pBuf
);
void
tsSetSTableQueryCond
(
STagCond
*
pTagCond
,
uint64_t
uid
,
SBuffer
Writer
*
bw
);
void
tscTagCondCopy
(
STagCond
*
dest
,
const
STagCond
*
src
);
void
tscTagCondCopy
(
STagCond
*
dest
,
const
STagCond
*
src
);
void
tscTagCondRelease
(
STagCond
*
pCond
);
void
tscTagCondRelease
(
STagCond
*
pCond
);
...
...
src/client/src/tscSQLParser.c
浏览文件 @
036695d4
...
@@ -1185,10 +1185,18 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
...
@@ -1185,10 +1185,18 @@ int32_t parseSelectClause(SSqlCmd* pCmd, int32_t clauseIndex, tSQLExprList* pSel
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
"invalid arithmetic expression in select clause"
);
return
invalidSqlErrMsg
(
pQueryInfo
->
msg
,
"invalid arithmetic expression in select clause"
);
}
}
SBuffer
buf
=
exprTreeToBinary
(
pNod
e
);
SBuffer
Writer
bw
=
tbufInitWriter
(
NULL
,
fals
e
);
size_t
len
=
tbufTell
(
&
buf
);
TRY
(
0
)
{
char
*
c
=
tbufGetData
(
&
buf
,
true
);
exprTreeToBinary
(
&
bw
,
pNode
);
}
CATCH
(
code
)
{
tbufCloseWriter
(
&
bw
);
UNUSED
(
code
);
// TODO: other error handling
}
END_TRY
size_t
len
=
tbufTell
(
&
bw
);
char
*
c
=
tbufGetData
(
&
bw
,
true
);
// set the serialized binary string as the parameter of arithmetic expression
// set the serialized binary string as the parameter of arithmetic expression
addExprParams
(
pExpr
,
c
,
TSDB_DATA_TYPE_BINARY
,
len
,
index
.
tableIndex
);
addExprParams
(
pExpr
,
c
,
TSDB_DATA_TYPE_BINARY
,
len
,
index
.
tableIndex
);
...
@@ -3751,7 +3759,15 @@ static int32_t getTagQueryCondExpr(SQueryInfo* pQueryInfo, SCondExpr* pCondExpr,
...
@@ -3751,7 +3759,15 @@ static int32_t getTagQueryCondExpr(SQueryInfo* pQueryInfo, SCondExpr* pCondExpr,
SArray
*
colList
=
taosArrayInit
(
10
,
sizeof
(
SColIndex
));
SArray
*
colList
=
taosArrayInit
(
10
,
sizeof
(
SColIndex
));
ret
=
exprTreeFromSqlExpr
(
&
p
,
p1
,
NULL
,
pQueryInfo
,
colList
);
ret
=
exprTreeFromSqlExpr
(
&
p
,
p1
,
NULL
,
pQueryInfo
,
colList
);
SBuffer
buf
=
exprTreeToBinary
(
p
);
SBufferWriter
bw
=
tbufInitWriter
(
NULL
,
false
);
TRY
(
0
)
{
exprTreeToBinary
(
&
bw
,
p
);
}
CATCH
(
code
)
{
tbufCloseWriter
(
&
bw
);
UNUSED
(
code
);
// TODO: more error handling
}
END_TRY
// add to source column list
// add to source column list
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
i
);
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
i
);
...
@@ -3765,7 +3781,7 @@ static int32_t getTagQueryCondExpr(SQueryInfo* pQueryInfo, SCondExpr* pCondExpr,
...
@@ -3765,7 +3781,7 @@ static int32_t getTagQueryCondExpr(SQueryInfo* pQueryInfo, SCondExpr* pCondExpr,
addRequiredTagColumn
(
pTableMetaInfo
,
&
index
);
addRequiredTagColumn
(
pTableMetaInfo
,
&
index
);
}
}
tsSetSTableQueryCond
(
&
pQueryInfo
->
tagCond
,
uid
,
&
b
uf
);
tsSetSTableQueryCond
(
&
pQueryInfo
->
tagCond
,
uid
,
&
b
w
);
doCompactQueryExpr
(
pExpr
);
doCompactQueryExpr
(
pExpr
);
tSQLExprDestroy
(
p1
);
tSQLExprDestroy
(
p1
);
...
...
src/client/src/tscUtil.c
浏览文件 @
036695d4
...
@@ -47,18 +47,18 @@ SCond* tsGetSTableQueryCond(STagCond* pTagCond, uint64_t uid) {
...
@@ -47,18 +47,18 @@ SCond* tsGetSTableQueryCond(STagCond* pTagCond, uint64_t uid) {
return
NULL
;
return
NULL
;
}
}
void
tsSetSTableQueryCond
(
STagCond
*
pTagCond
,
uint64_t
uid
,
SBuffer
*
pBuf
)
{
void
tsSetSTableQueryCond
(
STagCond
*
pTagCond
,
uint64_t
uid
,
SBuffer
Writer
*
bw
)
{
if
(
tbufTell
(
pBuf
)
==
0
)
{
if
(
tbufTell
(
bw
)
==
0
)
{
return
;
return
;
}
}
SCond
cond
=
{
SCond
cond
=
{
.
uid
=
uid
,
.
uid
=
uid
,
.
len
=
tbufTell
(
pBuf
),
.
len
=
tbufTell
(
bw
),
.
cond
=
NULL
,
.
cond
=
NULL
,
};
};
cond
.
cond
=
tbufGetData
(
pBuf
,
true
);
cond
.
cond
=
tbufGetData
(
bw
,
true
);
if
(
pTagCond
->
pCond
==
NULL
)
{
if
(
pTagCond
->
pCond
==
NULL
)
{
pTagCond
->
pCond
=
taosArrayInit
(
3
,
sizeof
(
SCond
));
pTagCond
->
pCond
=
taosArrayInit
(
3
,
sizeof
(
SCond
));
...
...
src/query/inc/qast.h
浏览文件 @
036695d4
...
@@ -90,9 +90,10 @@ void tSQLBinaryExprTrv(tExprNode *pExprs, SArray* res);
...
@@ -90,9 +90,10 @@ void tSQLBinaryExprTrv(tExprNode *pExprs, SArray* res);
uint8_t
getBinaryExprOptr
(
SSQLToken
*
pToken
);
uint8_t
getBinaryExprOptr
(
SSQLToken
*
pToken
);
SBuffer
exprTreeToBinary
(
tExprNode
*
pExprTree
);
void
tExprNodeDestroy
(
tExprNode
*
pNode
,
void
(
*
fp
)(
void
*
));
void
exprTreeToBinary
(
SBufferWriter
*
bw
,
tExprNode
*
pExprTree
);
tExprNode
*
exprTreeFromBinary
(
const
void
*
pBuf
,
size_t
size
);
tExprNode
*
exprTreeFromBinary
(
const
void
*
data
,
size_t
size
);
tExprNode
*
exprTreeFromTableName
(
const
char
*
tbnameCond
);
tExprNode
*
exprTreeFromTableName
(
const
char
*
tbnameCond
);
#ifdef __cplusplus
#ifdef __cplusplus
...
...
src/query/src/qast.c
浏览文件 @
036695d4
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
#include "tskiplist.h"
#include "tskiplist.h"
#include "queryLog.h"
#include "queryLog.h"
#include "tsdbMain.h"
#include "tsdbMain.h"
#include "exception.h"
/*
/*
*
*
...
@@ -44,7 +45,6 @@
...
@@ -44,7 +45,6 @@
*
*
*/
*/
static
tExprNode
*
tExprNodeCreate
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
SSQLToken
*
pToken
);
static
tExprNode
*
tExprNodeCreate
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
SSQLToken
*
pToken
);
static
void
tExprNodeDestroy
(
tExprNode
*
pNode
,
void
(
*
fp
)(
void
*
));
static
tExprNode
*
createSyntaxTree
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
char
*
str
,
int32_t
*
i
);
static
tExprNode
*
createSyntaxTree
(
SSchema
*
pSchema
,
int32_t
numOfCols
,
char
*
str
,
int32_t
*
i
);
static
void
destroySyntaxTree
(
tExprNode
*
);
static
void
destroySyntaxTree
(
tExprNode
*
);
...
@@ -428,7 +428,7 @@ void tSQLBinaryExprToString(tExprNode *pExpr, char *dst, int32_t *len) {
...
@@ -428,7 +428,7 @@ void tSQLBinaryExprToString(tExprNode *pExpr, char *dst, int32_t *len) {
static
void
UNUSED_FUNC
destroySyntaxTree
(
tExprNode
*
pNode
)
{
tExprNodeDestroy
(
pNode
,
NULL
);
}
static
void
UNUSED_FUNC
destroySyntaxTree
(
tExprNode
*
pNode
)
{
tExprNodeDestroy
(
pNode
,
NULL
);
}
static
void
tExprNodeDestroy
(
tExprNode
*
pNode
,
void
(
*
fp
)(
void
*
))
{
void
tExprNodeDestroy
(
tExprNode
*
pNode
,
void
(
*
fp
)(
void
*
))
{
if
(
pNode
==
NULL
)
{
if
(
pNode
==
NULL
)
{
return
;
return
;
}
}
...
@@ -1023,104 +1023,116 @@ void tSQLBinaryExprTrv(tExprNode *pExprs, SArray* res) {
...
@@ -1023,104 +1023,116 @@ void tSQLBinaryExprTrv(tExprNode *pExprs, SArray* res) {
}
}
}
}
static
void
exprTreeToBinaryImpl
(
tExprNode
*
pExprTree
,
SBuffer
*
pBuf
)
{
static
void
exprTreeToBinaryImpl
(
SBufferWriter
*
bw
,
tExprNode
*
expr
)
{
tbufWrite
(
pBuf
,
&
pExprTree
->
nodeType
,
sizeof
(
pExprTree
->
nodeType
)
);
tbufWrite
Uint8
(
bw
,
expr
->
nodeType
);
if
(
pExprTree
->
nodeType
==
TSQL_NODE_VALUE
)
{
if
(
expr
->
nodeType
==
TSQL_NODE_VALUE
)
{
tVariant
*
pVal
=
pExprTree
->
pVal
;
tVariant
*
pVal
=
expr
->
pVal
;
tbufWrite
(
pBuf
,
&
pVal
->
nType
,
sizeof
(
pVal
->
nType
)
);
tbufWrite
Uint32
(
bw
,
pVal
->
nType
);
if
(
pVal
->
nType
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
pVal
->
nType
==
TSDB_DATA_TYPE_BINARY
)
{
tbufWrite
(
pBuf
,
&
pVal
->
nLen
,
sizeof
(
pVal
->
nLen
)
);
tbufWrite
Int32
(
bw
,
pVal
->
nLen
);
tbufWrite
(
pBuf
,
pVal
->
pz
,
pVal
->
nLen
);
tbufWrite
(
bw
,
pVal
->
pz
,
pVal
->
nLen
);
}
else
{
}
else
{
tbufWrite
(
pBuf
,
&
pVal
->
pz
,
sizeof
(
pVal
->
i64Key
)
);
tbufWrite
Int64
(
bw
,
pVal
->
i64Key
);
}
}
}
else
if
(
pExprTree
->
nodeType
==
TSQL_NODE_COL
)
{
}
else
if
(
expr
->
nodeType
==
TSQL_NODE_COL
)
{
SSchema
*
pSchema
=
pExprTree
->
pSchema
;
SSchema
*
pSchema
=
expr
->
pSchema
;
tbufWrite
(
pBuf
,
&
pSchema
->
colId
,
sizeof
(
pSchema
->
colId
));
tbufWriteInt16
(
bw
,
pSchema
->
colId
);
tbufWrite
(
pBuf
,
&
pSchema
->
bytes
,
sizeof
(
pSchema
->
bytes
));
tbufWriteInt16
(
bw
,
pSchema
->
bytes
);
tbufWrite
(
pBuf
,
&
pSchema
->
type
,
sizeof
(
pSchema
->
type
));
tbufWriteUint8
(
bw
,
pSchema
->
type
);
tbufWriteString
(
bw
,
pSchema
->
name
);
int32_t
len
=
strlen
(
pSchema
->
name
);
}
else
if
(
expr
->
nodeType
==
TSQL_NODE_EXPR
)
{
tbufWriteStringLen
(
pBuf
,
pSchema
->
name
,
len
);
tbufWriteUint8
(
bw
,
expr
->
_node
.
optr
);
tbufWriteUint8
(
bw
,
expr
->
_node
.
hasPK
);
}
else
if
(
pExprTree
->
nodeType
==
TSQL_NODE_EXPR
)
{
exprTreeToBinaryImpl
(
bw
,
expr
->
_node
.
pLeft
);
tbufWrite
(
pBuf
,
&
pExprTree
->
_node
.
optr
,
sizeof
(
pExprTree
->
_node
.
optr
));
exprTreeToBinaryImpl
(
bw
,
expr
->
_node
.
pRight
);
tbufWrite
(
pBuf
,
&
pExprTree
->
_node
.
hasPK
,
sizeof
(
pExprTree
->
_node
.
hasPK
));
}
}
exprTreeToBinaryImpl
(
pExprTree
->
_node
.
pLeft
,
pBuf
);
void
exprTreeToBinary
(
SBufferWriter
*
bw
,
tExprNode
*
expr
)
{
exprTreeToBinaryImpl
(
pExprTree
->
_node
.
pRight
,
pBuf
);
if
(
expr
!=
NULL
)
{
exprTreeToBinaryImpl
(
bw
,
expr
);
}
}
}
}
SBuffer
exprTreeToBinary
(
tExprNode
*
pExprTree
)
{
// TODO: these three functions should be made global
SBuffer
buf
=
{
0
};
static
void
*
exception_calloc
(
size_t
nmemb
,
size_t
size
)
{
if
(
pExprTree
==
NULL
)
{
void
*
p
=
calloc
(
nmemb
,
size
);
return
buf
;
if
(
p
==
NULL
)
{
THROW
(
TSDB_CODE_SERV_OUT_OF_MEMORY
);
}
}
return
p
;
}
int32_t
code
=
tbufBeginWrite
(
&
buf
);
static
void
*
exception_malloc
(
size_t
size
)
{
if
(
code
!=
0
)
{
void
*
p
=
malloc
(
size
);
return
buf
;
if
(
p
==
NULL
)
{
THROW
(
TSDB_CODE_SERV_OUT_OF_MEMORY
);
}
}
return
p
;
}
exprTreeToBinaryImpl
(
pExprTree
,
&
buf
);
static
char
*
exception_strdup
(
const
char
*
str
)
{
return
buf
;
char
*
p
=
strdup
(
str
);
if
(
p
==
NULL
)
{
THROW
(
TSDB_CODE_SERV_OUT_OF_MEMORY
);
}
return
p
;
}
}
static
tExprNode
*
exprTreeFromBinaryImpl
(
SBuffer
*
pBuf
)
{
tExprNode
*
pExpr
=
calloc
(
1
,
sizeof
(
tExprNode
));
static
tExprNode
*
exprTreeFromBinaryImpl
(
SBufferReader
*
br
)
{
pExpr
->
nodeType
=
tbufReadUint8
(
pBuf
);
int32_t
anchor
=
CLEANUP_GET_ANCHOR
();
tExprNode
*
pExpr
=
exception_calloc
(
1
,
sizeof
(
tExprNode
));
CLEANUP_PUSH_VOID_PTR_PTR
(
true
,
tExprNodeDestroy
,
pExpr
,
NULL
);
pExpr
->
nodeType
=
tbufReadUint8
(
br
);
if
(
pExpr
->
nodeType
==
TSQL_NODE_VALUE
)
{
if
(
pExpr
->
nodeType
==
TSQL_NODE_VALUE
)
{
tVariant
*
pVal
=
calloc
(
1
,
sizeof
(
tVariant
));
tVariant
*
pVal
=
exception_calloc
(
1
,
sizeof
(
tVariant
));
if
(
pVal
==
NULL
)
{
// TODO:
}
pExpr
->
pVal
=
pVal
;
pExpr
->
pVal
=
pVal
;
pVal
->
nType
=
tbufReadUint32
(
pBuf
);
pVal
->
nType
=
tbufReadUint32
(
br
);
if
(
pVal
->
nType
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
pVal
->
nType
==
TSDB_DATA_TYPE_BINARY
)
{
tbufReadToBuffer
(
pBuf
,
&
pVal
->
nLen
,
sizeof
(
pVal
->
nLen
));
tbufReadToBuffer
(
br
,
&
pVal
->
nLen
,
sizeof
(
pVal
->
nLen
));
pVal
->
pz
=
calloc
(
1
,
pVal
->
nLen
+
1
);
pVal
->
pz
=
calloc
(
1
,
pVal
->
nLen
+
1
);
tbufReadToBuffer
(
pBuf
,
pVal
->
pz
,
pVal
->
nLen
);
tbufReadToBuffer
(
br
,
pVal
->
pz
,
pVal
->
nLen
);
}
else
{
}
else
{
pVal
->
i64Key
=
tbufReadInt64
(
pBuf
);
pVal
->
i64Key
=
tbufReadInt64
(
br
);
}
}
}
else
if
(
pExpr
->
nodeType
==
TSQL_NODE_COL
)
{
}
else
if
(
pExpr
->
nodeType
==
TSQL_NODE_COL
)
{
SSchema
*
pSchema
=
calloc
(
1
,
sizeof
(
SSchema
));
SSchema
*
pSchema
=
exception_calloc
(
1
,
sizeof
(
SSchema
));
if
(
pSchema
==
NULL
)
{
// TODO:
}
pExpr
->
pSchema
=
pSchema
;
pExpr
->
pSchema
=
pSchema
;
pSchema
->
colId
=
tbufReadInt16
(
pBuf
);
pSchema
->
colId
=
tbufReadInt16
(
br
);
pSchema
->
bytes
=
tbufReadInt16
(
pBuf
);
pSchema
->
bytes
=
tbufReadInt16
(
br
);
pSchema
->
type
=
tbufReadUint8
(
pBuf
);
pSchema
->
type
=
tbufReadUint8
(
br
);
tbufReadToString
(
pBuf
,
pSchema
->
name
,
TSDB_COL_NAME_LEN
);
tbufReadToString
(
br
,
pSchema
->
name
,
TSDB_COL_NAME_LEN
);
}
else
if
(
pExpr
->
nodeType
==
TSQL_NODE_EXPR
)
{
}
else
if
(
pExpr
->
nodeType
==
TSQL_NODE_EXPR
)
{
pExpr
->
_node
.
optr
=
tbufReadUint8
(
pBuf
);
pExpr
->
_node
.
optr
=
tbufReadUint8
(
br
);
pExpr
->
_node
.
hasPK
=
tbufReadUint8
(
pBuf
);
pExpr
->
_node
.
hasPK
=
tbufReadUint8
(
br
);
pExpr
->
_node
.
pLeft
=
exprTreeFromBinaryImpl
(
pBuf
);
pExpr
->
_node
.
pLeft
=
exprTreeFromBinaryImpl
(
br
);
pExpr
->
_node
.
pRight
=
exprTreeFromBinaryImpl
(
pBuf
);
pExpr
->
_node
.
pRight
=
exprTreeFromBinaryImpl
(
br
);
assert
(
pExpr
->
_node
.
pLeft
!=
NULL
&&
pExpr
->
_node
.
pRight
!=
NULL
);
assert
(
pExpr
->
_node
.
pLeft
!=
NULL
&&
pExpr
->
_node
.
pRight
!=
NULL
);
}
}
CLEANUP_EXECUTE_TO
(
anchor
,
false
);
return
pExpr
;
return
pExpr
;
}
}
tExprNode
*
exprTreeFromBinary
(
const
void
*
pBuf
,
size_t
size
)
{
tExprNode
*
exprTreeFromBinary
(
const
void
*
data
,
size_t
size
)
{
if
(
size
==
0
)
{
if
(
size
==
0
)
{
return
NULL
;
return
NULL
;
}
}
SBuffer
rbuf
=
{
0
};
SBufferReader
br
=
tbufInitReader
(
data
,
size
,
false
);
tbufBeginRead
(
&
rbuf
,
pBuf
,
size
);
return
exprTreeFromBinaryImpl
(
&
br
);
return
exprTreeFromBinaryImpl
(
&
rbuf
);
}
}
tExprNode
*
exprTreeFromTableName
(
const
char
*
tbnameCond
)
{
tExprNode
*
exprTreeFromTableName
(
const
char
*
tbnameCond
)
{
...
@@ -1128,23 +1140,18 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
...
@@ -1128,23 +1140,18 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
return
NULL
;
return
NULL
;
}
}
tExprNode
*
expr
=
calloc
(
1
,
sizeof
(
tExprNode
));
int32_t
anchor
=
CLEANUP_GET_ANCHOR
();
if
(
expr
==
NULL
)
{
// TODO:
tExprNode
*
expr
=
exception_calloc
(
1
,
sizeof
(
tExprNode
));
}
CLEANUP_PUSH_VOID_PTR_PTR
(
true
,
tExprNodeDestroy
,
expr
,
NULL
);
expr
->
nodeType
=
TSQL_NODE_EXPR
;
expr
->
nodeType
=
TSQL_NODE_EXPR
;
tExprNode
*
left
=
calloc
(
1
,
sizeof
(
tExprNode
));
tExprNode
*
left
=
exception_calloc
(
1
,
sizeof
(
tExprNode
));
if
(
left
==
NULL
)
{
// TODO:
}
expr
->
_node
.
pLeft
=
left
;
expr
->
_node
.
pLeft
=
left
;
left
->
nodeType
=
TSQL_NODE_COL
;
left
->
nodeType
=
TSQL_NODE_COL
;
SSchema
*
pSchema
=
calloc
(
1
,
sizeof
(
SSchema
));
SSchema
*
pSchema
=
exception_calloc
(
1
,
sizeof
(
SSchema
));
if
(
pSchema
==
NULL
)
{
// TODO:
}
left
->
pSchema
=
pSchema
;
left
->
pSchema
=
pSchema
;
pSchema
->
type
=
TSDB_DATA_TYPE_BINARY
;
pSchema
->
type
=
TSDB_DATA_TYPE_BINARY
;
...
@@ -1152,36 +1159,24 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
...
@@ -1152,36 +1159,24 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
strcpy
(
pSchema
->
name
,
TSQL_TBNAME_L
);
strcpy
(
pSchema
->
name
,
TSQL_TBNAME_L
);
pSchema
->
colId
=
-
1
;
pSchema
->
colId
=
-
1
;
tExprNode
*
right
=
calloc
(
1
,
sizeof
(
tExprNode
));
tExprNode
*
right
=
exception_calloc
(
1
,
sizeof
(
tExprNode
));
if
(
right
==
NULL
)
{
// TODO
}
expr
->
_node
.
pRight
=
right
;
expr
->
_node
.
pRight
=
right
;
if
(
strncmp
(
tbnameCond
,
QUERY_COND_REL_PREFIX_LIKE
,
QUERY_COND_REL_PREFIX_LIKE_LEN
)
==
0
)
{
if
(
strncmp
(
tbnameCond
,
QUERY_COND_REL_PREFIX_LIKE
,
QUERY_COND_REL_PREFIX_LIKE_LEN
)
==
0
)
{
right
->
nodeType
=
TSQL_NODE_VALUE
;
right
->
nodeType
=
TSQL_NODE_VALUE
;
expr
->
_node
.
optr
=
TSDB_RELATION_LIKE
;
expr
->
_node
.
optr
=
TSDB_RELATION_LIKE
;
tVariant
*
pVal
=
calloc
(
1
,
sizeof
(
tVariant
));
tVariant
*
pVal
=
exception_calloc
(
1
,
sizeof
(
tVariant
));
if
(
pVal
==
NULL
)
{
// TODO:
}
right
->
pVal
=
pVal
;
right
->
pVal
=
pVal
;
pVal
->
nType
=
TSDB_DATA_TYPE_BINARY
;
size_t
len
=
strlen
(
tbnameCond
+
QUERY_COND_REL_PREFIX_LIKE_LEN
)
+
1
;
size_t
len
=
strlen
(
tbnameCond
+
QUERY_COND_REL_PREFIX_LIKE_LEN
)
+
1
;
pVal
->
pz
=
malloc
(
len
);
pVal
->
pz
=
exception_malloc
(
len
);
if
(
pVal
->
pz
==
NULL
)
{
// TODO:
}
memcpy
(
pVal
->
pz
,
tbnameCond
+
QUERY_COND_REL_PREFIX_LIKE_LEN
,
len
);
memcpy
(
pVal
->
pz
,
tbnameCond
+
QUERY_COND_REL_PREFIX_LIKE_LEN
,
len
);
pVal
->
nType
=
TSDB_DATA_TYPE_BINARY
;
pVal
->
nLen
=
(
int32_t
)
len
;
pVal
->
nLen
=
(
int32_t
)
len
;
}
else
if
(
strncmp
(
tbnameCond
,
QUERY_COND_REL_PREFIX_IN
,
QUERY_COND_REL_PREFIX_IN_LEN
)
==
0
)
{
}
else
if
(
strncmp
(
tbnameCond
,
QUERY_COND_REL_PREFIX_IN
,
QUERY_COND_REL_PREFIX_IN_LEN
)
==
0
)
{
right
->
nodeType
=
TSQL_NODE_VALUE
;
right
->
nodeType
=
TSQL_NODE_VALUE
;
expr
->
_node
.
optr
=
TSDB_RELATION_IN
;
expr
->
_node
.
optr
=
TSDB_RELATION_IN
;
tVariant
*
pVal
=
calloc
(
1
,
sizeof
(
tVariant
));
tVariant
*
pVal
=
exception_calloc
(
1
,
sizeof
(
tVariant
));
if
(
pVal
==
NULL
)
{
// TODO:
}
right
->
pVal
=
pVal
;
right
->
pVal
=
pVal
;
pVal
->
nType
=
TSDB_DATA_TYPE_ARRAY
;
pVal
->
nType
=
TSDB_DATA_TYPE_ARRAY
;
pVal
->
arr
=
taosArrayInit
(
2
,
sizeof
(
char
*
));
pVal
->
arr
=
taosArrayInit
(
2
,
sizeof
(
char
*
));
...
@@ -1192,7 +1187,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
...
@@ -1192,7 +1187,7 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
cond
=
e
+
1
;
cond
=
e
+
1
;
}
else
if
(
*
e
==
','
)
{
}
else
if
(
*
e
==
','
)
{
size_t
len
=
e
-
cond
+
1
;
size_t
len
=
e
-
cond
+
1
;
char
*
p
=
malloc
(
len
);
char
*
p
=
exception_
malloc
(
len
);
memcpy
(
p
,
cond
,
len
);
memcpy
(
p
,
cond
,
len
);
p
[
len
-
1
]
=
0
;
p
[
len
-
1
]
=
0
;
cond
+=
len
;
cond
+=
len
;
...
@@ -1201,12 +1196,13 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
...
@@ -1201,12 +1196,13 @@ tExprNode* exprTreeFromTableName(const char* tbnameCond) {
}
}
if
(
*
cond
!=
0
)
{
if
(
*
cond
!=
0
)
{
char
*
p
=
strdup
(
cond
);
char
*
p
=
exception_
strdup
(
cond
);
taosArrayPush
(
pVal
->
arr
,
&
p
);
taosArrayPush
(
pVal
->
arr
,
&
p
);
}
}
taosArraySortString
(
pVal
->
arr
);
taosArraySortString
(
pVal
->
arr
);
}
}
CLEANUP_EXECUTE_TO
(
anchor
,
false
);
return
expr
;
return
expr
;
}
}
\ No newline at end of file
src/query/tests/astTest.cpp
浏览文件 @
036695d4
...
@@ -550,11 +550,12 @@ tExprNode* createExpr2() {
...
@@ -550,11 +550,12 @@ tExprNode* createExpr2() {
void
exprSerializeTest1
()
{
void
exprSerializeTest1
()
{
tExprNode
*
p1
=
createExpr1
();
tExprNode
*
p1
=
createExpr1
();
SBuffer
buf
=
exprTreeToBinary
(
p1
);
SBufferWriter
bw
=
tbufInitWriter
(
NULL
,
false
);
exprTreeToBinary
(
&
bw
,
p1
);
size_t
size
=
tbufTell
(
&
b
uf
);
size_t
size
=
tbufTell
(
&
b
w
);
ASSERT_TRUE
(
size
>
0
);
ASSERT_TRUE
(
size
>
0
);
char
*
b
=
tbufGetData
(
&
b
uf
,
false
);
char
*
b
=
tbufGetData
(
&
b
w
,
false
);
tExprNode
*
p2
=
exprTreeFromBinary
(
b
,
size
);
tExprNode
*
p2
=
exprTreeFromBinary
(
b
,
size
);
ASSERT_EQ
(
p1
->
nodeType
,
p2
->
nodeType
);
ASSERT_EQ
(
p1
->
nodeType
,
p2
->
nodeType
);
...
@@ -581,16 +582,17 @@ void exprSerializeTest1() {
...
@@ -581,16 +582,17 @@ void exprSerializeTest1() {
tExprTreeDestroy
(
&
p1
,
nullptr
);
tExprTreeDestroy
(
&
p1
,
nullptr
);
tExprTreeDestroy
(
&
p2
,
nullptr
);
tExprTreeDestroy
(
&
p2
,
nullptr
);
tbufClose
(
&
b
uf
,
false
);
tbufClose
(
&
b
w
);
}
}
void
exprSerializeTest2
()
{
void
exprSerializeTest2
()
{
tExprNode
*
p1
=
createExpr2
();
tExprNode
*
p1
=
createExpr2
();
SBuffer
buf
=
exprTreeToBinary
(
p1
);
SBufferWriter
bw
=
tbufInitWriter
(
NULL
,
false
);
exprTreeToBinary
(
&
bw
,
p1
);
size_t
size
=
tbufTell
(
&
b
uf
);
size_t
size
=
tbufTell
(
&
b
w
);
ASSERT_TRUE
(
size
>
0
);
ASSERT_TRUE
(
size
>
0
);
char
*
b
=
tbufGetData
(
&
b
uf
,
false
);
char
*
b
=
tbufGetData
(
&
b
w
,
false
);
tExprNode
*
p2
=
exprTreeFromBinary
(
b
,
size
);
tExprNode
*
p2
=
exprTreeFromBinary
(
b
,
size
);
ASSERT_EQ
(
p1
->
nodeType
,
p2
->
nodeType
);
ASSERT_EQ
(
p1
->
nodeType
,
p2
->
nodeType
);
...
@@ -625,7 +627,7 @@ void exprSerializeTest2() {
...
@@ -625,7 +627,7 @@ void exprSerializeTest2() {
tExprTreeDestroy
(
&
p1
,
nullptr
);
tExprTreeDestroy
(
&
p1
,
nullptr
);
tExprTreeDestroy
(
&
p2
,
nullptr
);
tExprTreeDestroy
(
&
p2
,
nullptr
);
tbufClose
(
&
b
uf
,
false
);
tbufClose
(
&
b
w
);
}
}
}
// namespace
}
// namespace
TEST
(
testCase
,
astTest
)
{
TEST
(
testCase
,
astTest
)
{
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
036695d4
...
@@ -18,6 +18,7 @@
...
@@ -18,6 +18,7 @@
#include "talgo.h"
#include "talgo.h"
#include "tutil.h"
#include "tutil.h"
#include "tcompare.h"
#include "tcompare.h"
#include "exception.h"
#include "../../../query/inc/qast.h" // todo move to common module
#include "../../../query/inc/qast.h" // todo move to common module
#include "../../../query/inc/tlosertree.h" // todo move to util module
#include "../../../query/inc/tlosertree.h" // todo move to util module
...
@@ -1473,21 +1474,35 @@ int32_t tsdbQueryByTagsCond(
...
@@ -1473,21 +1474,35 @@ int32_t tsdbQueryByTagsCond(
}
}
int32_t
ret
=
TSDB_CODE_SUCCESS
;
int32_t
ret
=
TSDB_CODE_SUCCESS
;
tExprNode
*
expr
=
NULL
;
tExprNode
*
expr
=
exprTreeFromTableName
(
tbnameCond
);
TRY
(
32
)
{
tExprNode
*
tagExpr
=
exprTreeFromBinary
(
pTagCond
,
len
);
expr
=
exprTreeFromTableName
(
tbnameCond
);
if
(
tagExpr
!=
NULL
)
{
if
(
expr
==
NULL
)
{
if
(
expr
==
NULL
)
{
expr
=
tagExpr
;
expr
=
exprTreeFromBinary
(
pTagCond
,
len
)
;
}
else
{
}
else
{
CLEANUP_PUSH_VOID_PTR_PTR
(
true
,
tExprNodeDestroy
,
expr
,
NULL
);
tExprNode
*
tagExpr
=
exprTreeFromBinary
(
pTagCond
,
len
);
if
(
tagExpr
!=
NULL
)
{
CLEANUP_PUSH_VOID_PTR_PTR
(
true
,
tExprNodeDestroy
,
tagExpr
,
NULL
);
tExprNode
*
tbnameExpr
=
expr
;
tExprNode
*
tbnameExpr
=
expr
;
expr
=
calloc
(
1
,
sizeof
(
tExprNode
));
expr
=
calloc
(
1
,
sizeof
(
tExprNode
));
if
(
expr
==
NULL
)
{
THROW
(
TSDB_CODE_SERV_OUT_OF_MEMORY
);
}
expr
->
nodeType
=
TSQL_NODE_EXPR
;
expr
->
nodeType
=
TSQL_NODE_EXPR
;
expr
->
_node
.
optr
=
tagNameRelType
;
expr
->
_node
.
optr
=
tagNameRelType
;
expr
->
_node
.
pLeft
=
tagExpr
;
expr
->
_node
.
pLeft
=
tagExpr
;
expr
->
_node
.
pRight
=
tbnameExpr
;
expr
->
_node
.
pRight
=
tbnameExpr
;
}
}
}
}
CLEANUP_EXECUTE
();
}
CATCH
(
code
)
{
CLEANUP_EXECUTE
();
ret
=
code
;
// TODO: more error handling
}
END_TRY
doQueryTableList
(
pSTable
,
res
,
expr
);
doQueryTableList
(
pSTable
,
res
,
expr
);
pGroupInfo
->
numOfTables
=
taosArrayGetSize
(
res
);
pGroupInfo
->
numOfTables
=
taosArrayGetSize
(
res
);
...
...
src/util/inc/tbuffer.h
浏览文件 @
036695d4
...
@@ -66,8 +66,6 @@ int main( int argc, char** argv ) {
...
@@ -66,8 +66,6 @@ int main( int argc, char** argv ) {
printf( "you should not see this message.\n" );
printf( "you should not see this message.\n" );
} CATCH( code ) {
} CATCH( code ) {
printf( "exception code is: %d, you will see this message after print out 5 integers and a string.\n", code );
printf( "exception code is: %d, you will see this message after print out 5 integers and a string.\n", code );
// throw it again and the exception will be caught in main
THROW( code );
} END_TRY
} END_TRY
tbufCloseWriter( &bw );
tbufCloseWriter( &bw );
...
@@ -92,6 +90,7 @@ typedef struct {
...
@@ -92,6 +90,7 @@ typedef struct {
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
// common functions & macros for both reader & writer
// common functions & macros for both reader & writer
#define tbufTell( buf ) ((buf)->pos)
#define tbufTell( buf ) ((buf)->pos)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录