Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a531411e
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看板
提交
a531411e
编写于
10月 26, 2021
作者:
H
Haojun Liao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[td-10564] refactor and add test cases.
上级
3f84c37d
变更
14
展开全部
隐藏空白更改
内联
并排
Showing
14 changed file
with
857 addition
and
405 deletion
+857
-405
include/util/tdef.h
include/util/tdef.h
+1
-0
include/util/tutil.h
include/util/tutil.h
+1
-0
source/libs/function/src/taggfunction.c
source/libs/function/src/taggfunction.c
+63
-63
source/libs/function/src/tfunction.c
source/libs/function/src/tfunction.c
+5
-2
source/libs/parser/inc/parserInt.h
source/libs/parser/inc/parserInt.h
+3
-2
source/libs/parser/inc/parserUtil.h
source/libs/parser/inc/parserUtil.h
+4
-2
source/libs/parser/inc/queryInfoUtil.h
source/libs/parser/inc/queryInfoUtil.h
+4
-2
source/libs/parser/src/astValidate.c
source/libs/parser/src/astValidate.c
+267
-293
source/libs/parser/src/parser.c
source/libs/parser/src/parser.c
+5
-8
source/libs/parser/src/parserUtil.c
source/libs/parser/src/parserUtil.c
+59
-7
source/libs/parser/src/queryInfoUtil.c
source/libs/parser/src/queryInfoUtil.c
+37
-22
source/libs/parser/test/parserTests.cpp
source/libs/parser/test/parserTests.cpp
+365
-1
source/libs/parser/test/tokenizerTest.cpp
source/libs/parser/test/tokenizerTest.cpp
+14
-2
source/util/src/tutil.c
source/util/src/tutil.c
+29
-1
未找到文件。
include/util/tdef.h
浏览文件 @
a531411e
...
...
@@ -81,6 +81,7 @@ extern const int32_t TYPE_BYTES[15];
#define TSDB_ERR -1
#define TS_PATH_DELIMITER "."
#define TS_ESCAPE_CHAR '`'
#define TSDB_TIME_PRECISION_MILLI 0
#define TSDB_TIME_PRECISION_MICRO 1
...
...
include/util/tutil.h
浏览文件 @
a531411e
...
...
@@ -26,6 +26,7 @@ extern "C" {
#include "tdef.h"
int32_t
strdequote
(
char
*
src
);
int32_t
strndequote
(
char
*
dst
,
const
char
*
z
,
int32_t
len
);
int32_t
strRmquote
(
char
*
z
,
int32_t
len
);
size_t
strtrim
(
char
*
src
);
char
*
strnchr
(
char
*
haystack
,
char
needle
,
int32_t
len
,
bool
skipquote
);
...
...
source/libs/function/src/taggfunction.c
浏览文件 @
a531411e
此差异已折叠。
点击以展开。
source/libs/function/src/tfunction.c
浏览文件 @
a531411e
...
...
@@ -12,13 +12,16 @@ static void doInitFunctionHashTable() {
functionHashTable
=
taosHashInit
(
numOfEntries
,
MurmurHash3_32
,
false
,
false
);
for
(
int32_t
i
=
0
;
i
<
numOfEntries
;
i
++
)
{
int32_t
len
=
(
uint32_t
)
strlen
(
aggFunc
[
i
].
name
);
taosHashPut
(
functionHashTable
,
aggFunc
[
i
].
name
,
len
,
(
void
*
)
&
aggFunc
[
i
],
POINTER_BYTES
);
SAggFunctionInfo
*
ptr
=
&
aggFunc
[
i
];
taosHashPut
(
functionHashTable
,
aggFunc
[
i
].
name
,
len
,
(
void
*
)
&
ptr
,
POINTER_BYTES
);
}
numOfEntries
=
tListLen
(
scalarFunc
);
for
(
int32_t
i
=
0
;
i
<
numOfEntries
;
++
i
)
{
int32_t
len
=
(
int32_t
)
strlen
(
scalarFunc
[
i
].
name
);
taosHashPut
(
functionHashTable
,
scalarFunc
[
i
].
name
,
len
,
(
void
*
)
&
scalarFunc
[
i
],
POINTER_BYTES
);
SScalarFunctionInfo
*
ptr
=
&
scalarFunc
[
i
];
taosHashPut
(
functionHashTable
,
scalarFunc
[
i
].
name
,
len
,
(
void
*
)
&
ptr
,
POINTER_BYTES
);
}
}
...
...
source/libs/parser/inc/parserInt.h
浏览文件 @
a531411e
...
...
@@ -48,8 +48,6 @@ typedef struct SSqlExpr {
SColIndex
colInfo
;
uint64_t
uid
;
// table uid, todo refactor use the pointer
int32_t
interBytes
;
// inter result buffer size
// int16_t colType; // table column type
// int16_t colBytes; // table column bytes
int16_t
numOfParams
;
// argument value of each function
SVariant
param
[
3
];
// parameters are not more than 3
}
SSqlExpr
;
...
...
@@ -101,6 +99,9 @@ int32_t qParserValidateSqlNode(struct SCatalog* pCatalog, SSqlInfo* pSqlInfo, SQ
*/
int32_t
evaluateSqlNode
(
SSqlNode
*
pNode
,
int32_t
tsPrecision
,
SMsgBuf
*
pMsgBuf
);
int32_t
validateSqlNode
(
SSqlNode
*
pSqlNode
,
SQueryStmtInfo
*
pQueryInfo
,
SMsgBuf
*
pMsgBuf
);
void
initQueryInfo
(
SQueryStmtInfo
*
pQueryInfo
);
/**
* Extract request meta info from the sql statement
* @param pSqlInfo
...
...
source/libs/parser/inc/parserUtil.h
浏览文件 @
a531411e
...
...
@@ -37,7 +37,7 @@ extern "C" {
(((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_TEMP_TABLE))
TAOS_FIELD
createField
(
const
SSchema
*
pSchema
);
void
setSchemaVal
(
SSchema
*
pSchema
,
uint8_t
type
,
int16_t
bytes
,
int16_t
colId
,
const
char
*
name
);
SSchema
createSchema
(
uint8_t
type
,
int16_t
bytes
,
int16_t
colId
,
const
char
*
name
);
SInternalField
*
insertFieldInfo
(
SFieldInfo
*
pFieldInfo
,
int32_t
index
,
SSchema
*
field
);
int32_t
getNumOfFields
(
SFieldInfo
*
pFieldInfo
);
...
...
@@ -45,7 +45,7 @@ SInternalField* getInternalField(SFieldInfo* pFieldInfo, int32_t index);
int32_t
parserValidateIdToken
(
SToken
*
pToken
);
int32_t
buildInvalidOperationMsg
(
SMsgBuf
*
pMsgBuf
,
const
char
*
msg
);
int32_t
parserSet
SyntaxErrMsg
(
char
*
dst
,
int32_t
dstBufLen
,
const
char
*
additionalInfo
,
const
char
*
sourceStr
);
int32_t
build
SyntaxErrMsg
(
char
*
dst
,
int32_t
dstBufLen
,
const
char
*
additionalInfo
,
const
char
*
sourceStr
);
int32_t
createProjectionExpr
(
SQueryStmtInfo
*
pQueryInfo
,
STableMetaInfo
*
pTableMetaInfo
,
SExprInfo
***
pExpr
,
int32_t
*
num
);
STableMetaInfo
*
addEmptyMetaInfo
(
SQueryStmtInfo
*
pQueryInfo
);
...
...
@@ -60,6 +60,8 @@ SColumn* insertPrimaryTsColumn(SArray* pColumnList, uint64_t tableUid);
void
cleanupTagCond
(
STagCond
*
pTagCond
);
void
cleanupColumnCond
(
SArray
**
pCond
);
uint32_t
convertRelationalOperator
(
SToken
*
pToken
);
#ifdef __cplusplus
}
#endif
...
...
source/libs/parser/inc/queryInfoUtil.h
浏览文件 @
a531411e
...
...
@@ -30,8 +30,10 @@ SSchema *getTableTagSchema(const STableMeta* pTableMeta);
SSchema
*
getOneColumnSchema
(
const
STableMeta
*
pTableMeta
,
int32_t
colIndex
);
size_t
getNumOfExprs
(
SQueryStmtInfo
*
pQueryInfo
);
SExprInfo
*
createExprInfo
(
STableMetaInfo
*
pTableMetaInfo
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
SSchema
*
pResSchema
,
int16_t
interSize
);
SExprInfo
*
createExprInfo
(
STableMetaInfo
*
pTableMetaInfo
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
struct
tExprNode
*
pParamExpr
,
SSchema
*
pResSchema
,
int16_t
interSize
);
SExprInfo
*
createBinaryExprInfo
(
struct
tExprNode
*
pNode
,
SSchema
*
pResSchema
);
void
addExprInfo
(
SQueryStmtInfo
*
pQueryInfo
,
int32_t
index
,
SExprInfo
*
pExprInfo
);
void
updateExprInfo
(
SExprInfo
*
pExprInfo
,
int16_t
functionId
,
int32_t
colId
,
int16_t
srcColumnIndex
,
int16_t
resType
,
int16_t
resSize
);
void
assignExprInfo
(
SExprInfo
*
dst
,
const
SExprInfo
*
src
);
...
...
source/libs/parser/src/astValidate.c
浏览文件 @
a531411e
此差异已折叠。
点击以展开。
source/libs/parser/src/parser.c
浏览文件 @
a531411e
...
...
@@ -23,7 +23,7 @@ bool qIsInsertSql(const char* pStr, size_t length) {
int32_t
index
=
0
;
do
{
SToken
t0
=
tStrGetToken
(
pStr
,
&
index
,
false
);
SToken
t0
=
tStrGetToken
(
(
char
*
)
pStr
,
&
index
,
false
);
if
(
t0
.
type
!=
TK_LP
)
{
return
t0
.
type
==
TK_INSERT
||
t0
.
type
==
TK_IMPORT
;
}
...
...
@@ -120,17 +120,12 @@ int32_t getTableNameFromSqlNode(SSqlNode* pSqlNode, SArray* tableNameList, SMsgB
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
}
// tscDequoteAndTrimToken(t);
if
(
parserValidateIdToken
(
t
)
!=
TSDB_CODE_SUCCESS
)
{
return
buildInvalidOperationMsg
(
pMsgBuf
,
msg1
);
}
SName
name
=
{
0
};
// int32_t code = tscSetTableFullName(&name, t, pSql);
// if (code != TSDB_CODE_SUCCESS) {
// return code;
// }
strndequote
(
name
.
tname
,
t
->
z
,
t
->
n
);
taosArrayPush
(
tableNameList
,
&
name
);
}
...
...
@@ -183,7 +178,7 @@ int32_t qParserExtractRequestedMetaInfo(const SSqlInfo* pSqlInfo, SMetaReq* pMet
assert
(
t
!=
NULL
);
if
(
t
->
n
>=
TSDB_FUNC_NAME_LEN
)
{
return
parserSet
SyntaxErrMsg
(
msg
,
msgBufLen
,
"too long function name"
,
t
->
z
);
return
build
SyntaxErrMsg
(
msg
,
msgBufLen
,
"too long function name"
,
t
->
z
);
}
// Let's assume that it is an UDF/UDAF, if it is not a built-in function.
...
...
@@ -193,4 +188,6 @@ int32_t qParserExtractRequestedMetaInfo(const SSqlInfo* pSqlInfo, SMetaReq* pMet
}
}
}
return
code
;
}
\ No newline at end of file
source/libs/parser/src/parserUtil.c
浏览文件 @
a531411e
...
...
@@ -26,6 +26,11 @@ int32_t parserValidateIdToken(SToken* pToken) {
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
// it is a token quoted with escape char '`'
if
(
pToken
->
z
[
0
]
==
TS_ESCAPE_CHAR
&&
pToken
->
z
[
pToken
->
n
-
1
]
==
TS_ESCAPE_CHAR
)
{
return
TSDB_CODE_SUCCESS
;
}
char
*
sep
=
strnchr
(
pToken
->
z
,
TS_PATH_DELIMITER
[
0
],
pToken
->
n
,
true
);
if
(
sep
==
NULL
)
{
// It is a single part token, not a complex type
if
(
isNumber
(
pToken
))
{
...
...
@@ -83,7 +88,7 @@ int32_t buildInvalidOperationMsg(SMsgBuf* pBuf, const char* msg) {
return
TSDB_CODE_TSC_INVALID_OPERATION
;
}
int32_t
parserSet
SyntaxErrMsg
(
char
*
dst
,
int32_t
dstBufLen
,
const
char
*
additionalInfo
,
const
char
*
sourceStr
)
{
int32_t
build
SyntaxErrMsg
(
char
*
dst
,
int32_t
dstBufLen
,
const
char
*
additionalInfo
,
const
char
*
sourceStr
)
{
const
char
*
msgFormat1
=
"syntax error near
\'
%s
\'
"
;
const
char
*
msgFormat2
=
"syntax error near
\'
%s
\'
(%s)"
;
const
char
*
msgFormat3
=
"%s"
;
...
...
@@ -499,13 +504,14 @@ TAOS_FIELD createField(const SSchema* pSchema) {
return
f
;
}
void
setSchemaVal
(
SSchema
*
pSchema
,
uint8_t
type
,
int16_t
bytes
,
int16_t
colId
,
const
char
*
name
)
{
assert
(
pSchema
!=
NULL
)
;
pSchema
->
type
=
type
;
pSchema
->
bytes
=
bytes
;
pSchema
->
colId
=
colId
;
SSchema
createSchema
(
uint8_t
type
,
int16_t
bytes
,
int16_t
colId
,
const
char
*
name
)
{
SSchema
s
=
{
0
}
;
s
.
type
=
type
;
s
.
bytes
=
bytes
;
s
.
colId
=
colId
;
tstrncpy
(
pSchema
->
name
,
name
,
tListLen
(
pSchema
->
name
));
tstrncpy
(
s
.
name
,
name
,
tListLen
(
s
.
name
));
return
s
;
}
int32_t
getNumOfFields
(
SFieldInfo
*
pFieldInfo
)
{
...
...
@@ -1598,6 +1604,52 @@ int32_t getTagFilterSerializeLen(SQueryStmtInfo* pQueryInfo) {
return
0
;
}
uint32_t
convertRelationalOperator
(
SToken
*
pToken
)
{
switch
(
pToken
->
type
)
{
case
TK_LT
:
return
TSDB_RELATION_LESS
;
case
TK_LE
:
return
TSDB_RELATION_LESS_EQUAL
;
case
TK_GT
:
return
TSDB_RELATION_GREATER
;
case
TK_GE
:
return
TSDB_RELATION_GREATER_EQUAL
;
case
TK_NE
:
return
TSDB_RELATION_NOT_EQUAL
;
case
TK_AND
:
return
TSDB_RELATION_AND
;
case
TK_OR
:
return
TSDB_RELATION_OR
;
case
TK_EQ
:
return
TSDB_RELATION_EQUAL
;
case
TK_PLUS
:
return
TSDB_BINARY_OP_ADD
;
case
TK_MINUS
:
return
TSDB_BINARY_OP_SUBTRACT
;
case
TK_STAR
:
return
TSDB_BINARY_OP_MULTIPLY
;
case
TK_SLASH
:
case
TK_DIVIDE
:
return
TSDB_BINARY_OP_DIVIDE
;
case
TK_REM
:
return
TSDB_BINARY_OP_REMAINDER
;
case
TK_LIKE
:
return
TSDB_RELATION_LIKE
;
case
TK_MATCH
:
return
TSDB_RELATION_MATCH
;
case
TK_NMATCH
:
return
TSDB_RELATION_NMATCH
;
case
TK_ISNULL
:
return
TSDB_RELATION_ISNULL
;
case
TK_NOTNULL
:
return
TSDB_RELATION_NOTNULL
;
case
TK_IN
:
return
TSDB_RELATION_IN
;
default:
{
return
0
;
}
}
}
#if 0
int32_t tscCreateQueryFromQueryInfo(SQueryStmtInfo* pQueryInfo, SQueryAttr* pQueryAttr, void* addr) {
memset(pQueryAttr, 0, sizeof(SQueryAttr));
...
...
source/libs/parser/src/queryInfoUtil.c
浏览文件 @
a531411e
...
...
@@ -55,11 +55,16 @@ SSchema* getTableTagSchema(const STableMeta* pTableMeta) {
return
getOneColumnSchema
(
pTableMeta
,
getTableInfo
(
pTableMeta
).
numOfColumns
);
}
static
tExprNode
*
createUnaryFunctionExprNode
(
int32_t
functionId
,
SSchema
*
pSchema
)
{
tExprNode
*
pColumnNode
=
calloc
(
1
,
sizeof
(
tExprNode
));
pColumnNode
->
nodeType
=
TEXPR_COL_NODE
;
pColumnNode
->
pSchema
=
calloc
(
1
,
sizeof
(
SSchema
));
memcpy
(
pColumnNode
->
pSchema
,
pSchema
,
sizeof
(
SSchema
));
static
tExprNode
*
createUnaryFunctionExprNode
(
int32_t
functionId
,
SSchema
*
pSchema
,
tExprNode
*
pColumnNode
)
{
if
(
pColumnNode
==
NULL
)
{
pColumnNode
=
calloc
(
1
,
sizeof
(
tExprNode
));
pColumnNode
->
nodeType
=
TEXPR_COL_NODE
;
pColumnNode
->
pSchema
=
calloc
(
1
,
sizeof
(
SSchema
));
memcpy
(
pColumnNode
->
pSchema
,
pSchema
,
sizeof
(
SSchema
));
}
else
{
assert
(
pSchema
==
NULL
);
}
tExprNode
*
pNode
=
calloc
(
1
,
sizeof
(
tExprNode
));
pNode
->
nodeType
=
TEXPR_UNARYEXPR_NODE
;
...
...
@@ -69,7 +74,20 @@ static tExprNode* createUnaryFunctionExprNode(int32_t functionId, SSchema* pSche
return
pNode
;
}
SExprInfo
*
createExprInfo
(
STableMetaInfo
*
pTableMetaInfo
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
SSchema
*
pResSchema
,
int16_t
interSize
)
{
SExprInfo
*
createBinaryExprInfo
(
tExprNode
*
pNode
,
SSchema
*
pResSchema
)
{
assert
(
pNode
!=
NULL
&&
pResSchema
!=
NULL
);
SExprInfo
*
pExpr
=
calloc
(
1
,
sizeof
(
SExprInfo
));
if
(
pExpr
==
NULL
)
{
return
NULL
;
}
pExpr
->
pExpr
=
pNode
;
memcpy
(
&
pExpr
->
base
.
resSchema
,
pResSchema
,
sizeof
(
SSchema
));
return
pExpr
;
}
SExprInfo
*
createExprInfo
(
STableMetaInfo
*
pTableMetaInfo
,
int16_t
functionId
,
SColumnIndex
*
pColIndex
,
tExprNode
*
pParamExpr
,
SSchema
*
pResSchema
,
int16_t
interSize
)
{
SExprInfo
*
pExpr
=
calloc
(
1
,
sizeof
(
SExprInfo
));
if
(
pExpr
==
NULL
)
{
return
NULL
;
...
...
@@ -77,29 +95,26 @@ SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, int16_t functionId, SC
SSqlExpr
*
p
=
&
pExpr
->
base
;
// set the correct columnIndex index
if
(
pColIndex
->
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
if
(
pParamExpr
!=
NULL
)
{
pExpr
->
pExpr
=
createUnaryFunctionExprNode
(
functionId
,
NULL
,
pParamExpr
);
}
else
if
(
pColIndex
->
columnIndex
==
TSDB_TBNAME_COLUMN_INDEX
)
{
assert
(
pParamExpr
==
NULL
);
SSchema
*
s
=
getTbnameColumnSchema
();
p
->
colInfo
.
colId
=
TSDB_TBNAME_COLUMN_INDEX
;
pExpr
->
pExpr
=
createUnaryFunctionExprNode
(
functionId
,
s
);
}
else
if
(
pColIndex
->
columnIndex
<=
TSDB_UD_COLUMN_INDEX
)
{
p
->
colInfo
.
colId
=
pColIndex
->
columnIndex
;
SSchema
s
=
{.
colId
=
pColIndex
->
columnIndex
,
.
bytes
=
pResSchema
->
bytes
,
.
type
=
pResSchema
->
type
};
tstrncpy
(
s
.
name
,
pResSchema
->
name
,
TSDB_COL_NAME_LEN
);
pExpr
->
pExpr
=
createUnaryFunctionExprNode
(
functionId
,
&
s
);
}
else
if
(
functionId
==
FUNCTION_BLKINFO
)
{
pExpr
->
pExpr
=
createUnaryFunctionExprNode
(
functionId
,
s
,
pParamExpr
);
}
else
if
(
pColIndex
->
columnIndex
<=
TSDB_UD_COLUMN_INDEX
||
functionId
==
FUNCTION_BLKINFO
)
{
assert
(
pParamExpr
==
NULL
);
p
->
colInfo
.
colId
=
pColIndex
->
columnIndex
;
SSchema
s
=
{.
colId
=
pColIndex
->
columnIndex
,
.
bytes
=
pResSchema
->
bytes
,
.
type
=
pResSchema
->
type
};
tstrncpy
(
s
.
name
,
pResSchema
->
name
,
TSDB_COL_NAME_LEN
);
pExpr
->
pExpr
=
createUnaryFunctionExprNode
(
functionId
,
&
s
);
// p->colBytes = TSDB_MAX_BINARY_LEN;
// p->colType = TSDB_DATA_TYPE_BINARY;
SSchema
s
=
createSchema
(
pResSchema
->
type
,
pResSchema
->
bytes
,
pColIndex
->
columnIndex
,
pResSchema
->
name
);
pExpr
->
pExpr
=
createUnaryFunctionExprNode
(
functionId
,
&
s
,
pParamExpr
);
}
else
{
int32_t
len
=
tListLen
(
p
->
colInfo
.
name
);
if
(
TSDB_COL_IS_TAG
(
pColIndex
->
type
))
{
SSchema
*
pSchema
=
getTableTagSchema
(
pTableMetaInfo
->
pTableMeta
);
p
->
colInfo
.
colId
=
pSchema
[
pColIndex
->
columnIndex
].
colId
;
pExpr
->
pExpr
=
createUnaryFunctionExprNode
(
functionId
,
&
pSchema
[
pColIndex
->
columnIndex
]);
pExpr
->
pExpr
=
createUnaryFunctionExprNode
(
functionId
,
&
pSchema
[
pColIndex
->
columnIndex
]
,
pParamExpr
);
snprintf
(
p
->
colInfo
.
name
,
len
,
"%s.%s"
,
pTableMetaInfo
->
aliasName
,
pSchema
[
pColIndex
->
columnIndex
].
name
);
}
else
if
(
pTableMetaInfo
->
pTableMeta
!=
NULL
)
{
// in handling select database/version/server_status(), the pTableMeta is NULL
...
...
@@ -107,7 +122,7 @@ SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, int16_t functionId, SC
p
->
colInfo
.
colId
=
pSchema
->
colId
;
snprintf
(
p
->
colInfo
.
name
,
len
,
"%s.%s"
,
pTableMetaInfo
->
aliasName
,
pSchema
->
name
);
pExpr
->
pExpr
=
createUnaryFunctionExprNode
(
functionId
,
pSchema
);
pExpr
->
pExpr
=
createUnaryFunctionExprNode
(
functionId
,
pSchema
,
pParamExpr
);
}
}
...
...
source/libs/parser/test/parserTests.cpp
浏览文件 @
a531411e
...
...
@@ -11,4 +11,368 @@
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
\ No newline at end of file
*/
#include <gtest/gtest.h>
#include <iostream>
#pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#include "os.h"
#include "astGenerator.h"
#include "parserInt.h"
#include "taos.h"
#include "tdef.h"
#include "tvariant.h"
namespace
{
void
setSchema
(
SSchema
*
p
,
int32_t
type
,
int32_t
bytes
,
const
char
*
name
,
int32_t
colId
)
{
p
->
colId
=
colId
;
p
->
bytes
=
bytes
;
p
->
type
=
type
;
strcpy
(
p
->
name
,
name
);
}
void
setTableMetaInfo
(
SQueryStmtInfo
*
pQueryInfo
,
SMetaReq
*
req
)
{
pQueryInfo
->
numOfTables
=
1
;
pQueryInfo
->
pTableMetaInfo
=
(
STableMetaInfo
**
)
calloc
(
1
,
POINTER_BYTES
);
STableMetaInfo
*
pTableMetaInfo
=
(
STableMetaInfo
*
)
calloc
(
1
,
sizeof
(
STableMetaInfo
));
pQueryInfo
->
pTableMetaInfo
[
0
]
=
pTableMetaInfo
;
SName
*
name
=
(
SName
*
)
taosArrayGet
(
req
->
pTableName
,
0
);
memcpy
(
&
pTableMetaInfo
->
name
,
taosArrayGet
(
req
->
pTableName
,
0
),
sizeof
(
SName
));
pTableMetaInfo
->
pTableMeta
=
(
STableMeta
*
)
calloc
(
1
,
sizeof
(
STableMeta
)
+
4
*
sizeof
(
SSchema
));
strcpy
(
pTableMetaInfo
->
aliasName
,
name
->
tname
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
pTableMeta
->
tableType
=
TSDB_NORMAL_TABLE
;
pTableMeta
->
tableInfo
.
numOfColumns
=
4
;
pTableMeta
->
tableInfo
.
rowSize
=
28
;
pTableMeta
->
uid
=
110
;
pTableMetaInfo
->
tagColList
=
(
SArray
*
)
taosArrayInit
(
4
,
POINTER_BYTES
);
SSchema
*
pSchema
=
pTableMetaInfo
->
pTableMeta
->
schema
;
setSchema
(
&
pSchema
[
0
],
TSDB_DATA_TYPE_TIMESTAMP
,
8
,
"ts"
,
0
);
setSchema
(
&
pSchema
[
1
],
TSDB_DATA_TYPE_INT
,
4
,
"a"
,
1
);
setSchema
(
&
pSchema
[
2
],
TSDB_DATA_TYPE_DOUBLE
,
8
,
"b"
,
2
);
setSchema
(
&
pSchema
[
3
],
TSDB_DATA_TYPE_DOUBLE
,
8
,
"col"
,
3
);
}
}
TEST
(
testCase
,
validateAST_test
)
{
SSqlInfo
info1
=
doGenerateAST
(
"select a a1111, a+b + 22, tbname from `t.1abc` where ts<now+2h and `col` < 20 + 99"
);
ASSERT_EQ
(
info1
.
valid
,
true
);
char
msg
[
128
]
=
{
0
};
SMsgBuf
buf
;
buf
.
len
=
128
;
buf
.
buf
=
msg
;
SSqlNode
*
pNode
=
(
SSqlNode
*
)
taosArrayGetP
(((
SArray
*
)
info1
.
list
),
0
);
int32_t
code
=
evaluateSqlNode
(
pNode
,
TSDB_TIME_PRECISION_NANO
,
&
buf
);
ASSERT_EQ
(
code
,
0
);
SMetaReq
req
=
{
0
};
int32_t
ret
=
qParserExtractRequestedMetaInfo
(
&
info1
,
&
req
,
msg
,
128
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
taosArrayGetSize
(
req
.
pTableName
),
1
);
SQueryStmtInfo
*
pQueryInfo
=
(
SQueryStmtInfo
*
)
calloc
(
1
,
sizeof
(
SQueryStmtInfo
));
initQueryInfo
(
pQueryInfo
);
setTableMetaInfo
(
pQueryInfo
,
&
req
);
SSqlNode
*
pSqlNode
=
(
SSqlNode
*
)
taosArrayGetP
(
info1
.
list
,
0
);
ret
=
validateSqlNode
(
pSqlNode
,
pQueryInfo
,
&
buf
);
SArray
*
pExprList
=
pQueryInfo
->
exprList
;
ASSERT_EQ
(
taosArrayGetSize
(
pExprList
),
3
);
SExprInfo
*
p1
=
(
SExprInfo
*
)
taosArrayGetP
(
pExprList
,
0
);
ASSERT_EQ
(
p1
->
base
.
uid
,
110
);
ASSERT_EQ
(
p1
->
base
.
numOfParams
,
0
);
ASSERT_EQ
(
p1
->
base
.
resSchema
.
type
,
TSDB_DATA_TYPE_INT
);
ASSERT_STRCASEEQ
(
p1
->
base
.
resSchema
.
name
,
"a1111"
);
ASSERT_STRCASEEQ
(
p1
->
base
.
colInfo
.
name
,
"t.1abc.a"
);
ASSERT_EQ
(
p1
->
base
.
colInfo
.
colId
,
1
);
ASSERT_EQ
(
p1
->
base
.
colInfo
.
flag
,
TSDB_COL_NORMAL
);
ASSERT_STRCASEEQ
(
p1
->
base
.
token
,
"a"
);
ASSERT_EQ
(
taosArrayGetSize
(
pExprList
),
3
);
SExprInfo
*
p2
=
(
SExprInfo
*
)
taosArrayGetP
(
pExprList
,
1
);
ASSERT_EQ
(
p2
->
base
.
uid
,
0
);
ASSERT_EQ
(
p2
->
base
.
numOfParams
,
1
);
// it is the serialized binary string of expression.
ASSERT_EQ
(
p2
->
base
.
resSchema
.
type
,
TSDB_DATA_TYPE_DOUBLE
);
ASSERT_STRCASEEQ
(
p2
->
base
.
resSchema
.
name
,
"a+b + 22"
);
// ASSERT_STRCASEEQ(p2->base.colInfo.name, "t.1abc.a");
// ASSERT_EQ(p1->base.colInfo.colId, 1);
// ASSERT_EQ(p1->base.colInfo.flag, TSDB_COL_NORMAL);
ASSERT_STRCASEEQ
(
p2
->
base
.
token
,
"a+b + 22"
);
ASSERT_EQ
(
taosArrayGetSize
(
pQueryInfo
->
colList
),
3
);
ASSERT_EQ
(
pQueryInfo
->
fieldsInfo
.
numOfOutput
,
3
);
}
TEST
(
testCase
,
function_Test
)
{
SSqlInfo
info1
=
doGenerateAST
(
"select count(a) from `t.1abc`"
);
ASSERT_EQ
(
info1
.
valid
,
true
);
char
msg
[
128
]
=
{
0
};
SMsgBuf
buf
;
buf
.
len
=
128
;
buf
.
buf
=
msg
;
SSqlNode
*
pNode
=
(
SSqlNode
*
)
taosArrayGetP
(((
SArray
*
)
info1
.
list
),
0
);
int32_t
code
=
evaluateSqlNode
(
pNode
,
TSDB_TIME_PRECISION_NANO
,
&
buf
);
ASSERT_EQ
(
code
,
0
);
SMetaReq
req
=
{
0
};
int32_t
ret
=
qParserExtractRequestedMetaInfo
(
&
info1
,
&
req
,
msg
,
128
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
taosArrayGetSize
(
req
.
pTableName
),
1
);
SQueryStmtInfo
*
pQueryInfo
=
(
SQueryStmtInfo
*
)
calloc
(
1
,
sizeof
(
SQueryStmtInfo
));
initQueryInfo
(
pQueryInfo
);
setTableMetaInfo
(
pQueryInfo
,
&
req
);
SSqlNode
*
pSqlNode
=
(
SSqlNode
*
)
taosArrayGetP
(
info1
.
list
,
0
);
ret
=
validateSqlNode
(
pSqlNode
,
pQueryInfo
,
&
buf
);
SArray
*
pExprList
=
pQueryInfo
->
exprList
;
ASSERT_EQ
(
taosArrayGetSize
(
pExprList
),
1
);
SExprInfo
*
p1
=
(
SExprInfo
*
)
taosArrayGetP
(
pExprList
,
0
);
ASSERT_EQ
(
p1
->
base
.
uid
,
110
);
ASSERT_EQ
(
p1
->
base
.
numOfParams
,
0
);
ASSERT_EQ
(
p1
->
base
.
resSchema
.
type
,
TSDB_DATA_TYPE_BIGINT
);
ASSERT_STRCASEEQ
(
p1
->
base
.
resSchema
.
name
,
"count(a)"
);
ASSERT_STRCASEEQ
(
p1
->
base
.
colInfo
.
name
,
"t.1abc.a"
);
ASSERT_EQ
(
p1
->
base
.
colInfo
.
colId
,
1
);
ASSERT_EQ
(
p1
->
base
.
colInfo
.
flag
,
TSDB_COL_NORMAL
);
ASSERT_STRCASEEQ
(
p1
->
base
.
token
,
"count(a)"
);
ASSERT_EQ
(
p1
->
base
.
interBytes
,
8
);
ASSERT_EQ
(
taosArrayGetSize
(
pQueryInfo
->
colList
),
2
);
ASSERT_EQ
(
pQueryInfo
->
fieldsInfo
.
numOfOutput
,
1
);
}
TEST
(
testCase
,
function_Test2
)
{
SSqlInfo
info1
=
doGenerateAST
(
"select count(a) abc from `t.1abc`"
);
ASSERT_EQ
(
info1
.
valid
,
true
);
char
msg
[
128
]
=
{
0
};
SMsgBuf
buf
;
buf
.
len
=
128
;
buf
.
buf
=
msg
;
SSqlNode
*
pNode
=
(
SSqlNode
*
)
taosArrayGetP
(((
SArray
*
)
info1
.
list
),
0
);
int32_t
code
=
evaluateSqlNode
(
pNode
,
TSDB_TIME_PRECISION_NANO
,
&
buf
);
ASSERT_EQ
(
code
,
0
);
SMetaReq
req
=
{
0
};
int32_t
ret
=
qParserExtractRequestedMetaInfo
(
&
info1
,
&
req
,
msg
,
128
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
taosArrayGetSize
(
req
.
pTableName
),
1
);
SQueryStmtInfo
*
pQueryInfo
=
(
SQueryStmtInfo
*
)
calloc
(
1
,
sizeof
(
SQueryStmtInfo
));
initQueryInfo
(
pQueryInfo
);
setTableMetaInfo
(
pQueryInfo
,
&
req
);
SSqlNode
*
pSqlNode
=
(
SSqlNode
*
)
taosArrayGetP
(
info1
.
list
,
0
);
ret
=
validateSqlNode
(
pSqlNode
,
pQueryInfo
,
&
buf
);
SArray
*
pExprList
=
pQueryInfo
->
exprList
;
ASSERT_EQ
(
taosArrayGetSize
(
pExprList
),
1
);
SExprInfo
*
p1
=
(
SExprInfo
*
)
taosArrayGetP
(
pExprList
,
0
);
ASSERT_EQ
(
p1
->
base
.
uid
,
110
);
ASSERT_EQ
(
p1
->
base
.
numOfParams
,
0
);
ASSERT_EQ
(
p1
->
base
.
resSchema
.
type
,
TSDB_DATA_TYPE_BIGINT
);
ASSERT_STRCASEEQ
(
p1
->
base
.
resSchema
.
name
,
"abc"
);
ASSERT_STRCASEEQ
(
p1
->
base
.
colInfo
.
name
,
"t.1abc.a"
);
ASSERT_EQ
(
p1
->
base
.
colInfo
.
colId
,
1
);
ASSERT_EQ
(
p1
->
base
.
colInfo
.
flag
,
TSDB_COL_NORMAL
);
ASSERT_STRCASEEQ
(
p1
->
base
.
token
,
"count(a)"
);
ASSERT_EQ
(
p1
->
base
.
interBytes
,
8
);
ASSERT_EQ
(
taosArrayGetSize
(
pQueryInfo
->
colList
),
2
);
ASSERT_EQ
(
pQueryInfo
->
fieldsInfo
.
numOfOutput
,
1
);
}
TEST
(
testCase
,
function_Test3
)
{
SSqlInfo
info1
=
doGenerateAST
(
"select first(*) from `t.1abc`"
);
ASSERT_EQ
(
info1
.
valid
,
true
);
char
msg
[
128
]
=
{
0
};
SMsgBuf
buf
;
buf
.
len
=
128
;
buf
.
buf
=
msg
;
SSqlNode
*
pNode
=
(
SSqlNode
*
)
taosArrayGetP
(((
SArray
*
)
info1
.
list
),
0
);
int32_t
code
=
evaluateSqlNode
(
pNode
,
TSDB_TIME_PRECISION_NANO
,
&
buf
);
ASSERT_EQ
(
code
,
0
);
SMetaReq
req
=
{
0
};
int32_t
ret
=
qParserExtractRequestedMetaInfo
(
&
info1
,
&
req
,
msg
,
128
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
taosArrayGetSize
(
req
.
pTableName
),
1
);
SQueryStmtInfo
*
pQueryInfo
=
(
SQueryStmtInfo
*
)
calloc
(
1
,
sizeof
(
SQueryStmtInfo
));
initQueryInfo
(
pQueryInfo
);
setTableMetaInfo
(
pQueryInfo
,
&
req
);
SSqlNode
*
pSqlNode
=
(
SSqlNode
*
)
taosArrayGetP
(
info1
.
list
,
0
);
ret
=
validateSqlNode
(
pSqlNode
,
pQueryInfo
,
&
buf
);
SArray
*
pExprList
=
pQueryInfo
->
exprList
;
ASSERT_EQ
(
taosArrayGetSize
(
pExprList
),
4
);
SExprInfo
*
p1
=
(
SExprInfo
*
)
taosArrayGetP
(
pExprList
,
0
);
ASSERT_EQ
(
p1
->
base
.
uid
,
110
);
ASSERT_EQ
(
p1
->
base
.
numOfParams
,
0
);
ASSERT_EQ
(
p1
->
base
.
resSchema
.
type
,
TSDB_DATA_TYPE_TIMESTAMP
);
ASSERT_STRCASEEQ
(
p1
->
base
.
resSchema
.
name
,
"first(ts)"
);
ASSERT_STRCASEEQ
(
p1
->
base
.
colInfo
.
name
,
"t.1abc.ts"
);
ASSERT_EQ
(
p1
->
base
.
colInfo
.
colId
,
0
);
ASSERT_EQ
(
p1
->
base
.
colInfo
.
flag
,
TSDB_COL_NORMAL
);
ASSERT_STRCASEEQ
(
p1
->
base
.
token
,
"first(ts)"
);
ASSERT_EQ
(
p1
->
base
.
interBytes
,
24
);
ASSERT_EQ
(
pQueryInfo
->
fieldsInfo
.
numOfOutput
,
4
);
}
TEST
(
testCase
,
function_Test4
)
{
SSqlInfo
info1
=
doGenerateAST
(
"select _block_dist() as a1 from `t.1abc`"
);
ASSERT_EQ
(
info1
.
valid
,
true
);
char
msg
[
128
]
=
{
0
};
SMsgBuf
buf
;
buf
.
len
=
128
;
buf
.
buf
=
msg
;
SSqlNode
*
pNode
=
(
SSqlNode
*
)
taosArrayGetP
(((
SArray
*
)
info1
.
list
),
0
);
int32_t
code
=
evaluateSqlNode
(
pNode
,
TSDB_TIME_PRECISION_NANO
,
&
buf
);
ASSERT_EQ
(
code
,
0
);
SMetaReq
req
=
{
0
};
int32_t
ret
=
qParserExtractRequestedMetaInfo
(
&
info1
,
&
req
,
msg
,
128
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
taosArrayGetSize
(
req
.
pTableName
),
1
);
SQueryStmtInfo
*
pQueryInfo
=
(
SQueryStmtInfo
*
)
calloc
(
1
,
sizeof
(
SQueryStmtInfo
));
initQueryInfo
(
pQueryInfo
);
setTableMetaInfo
(
pQueryInfo
,
&
req
);
SSqlNode
*
pSqlNode
=
(
SSqlNode
*
)
taosArrayGetP
(
info1
.
list
,
0
);
ret
=
validateSqlNode
(
pSqlNode
,
pQueryInfo
,
&
buf
);
SArray
*
pExprList
=
pQueryInfo
->
exprList
;
ASSERT_EQ
(
taosArrayGetSize
(
pExprList
),
1
);
SExprInfo
*
p1
=
(
SExprInfo
*
)
taosArrayGetP
(
pExprList
,
0
);
ASSERT_EQ
(
p1
->
base
.
uid
,
110
);
ASSERT_EQ
(
p1
->
base
.
numOfParams
,
1
);
ASSERT_EQ
(
p1
->
base
.
resSchema
.
type
,
TSDB_DATA_TYPE_BINARY
);
ASSERT_STRCASEEQ
(
p1
->
base
.
resSchema
.
name
,
"a1"
);
// ASSERT_STRCASEEQ(p1->base.colInfo.name, "t.1abc.ts");
// ASSERT_EQ(p1->base.colInfo.colId, 0);
ASSERT_EQ
(
p1
->
base
.
colInfo
.
flag
,
TSDB_COL_NORMAL
);
ASSERT_STRCASEEQ
(
p1
->
base
.
token
,
"_block_dist()"
);
ASSERT_EQ
(
p1
->
base
.
interBytes
,
0
);
ASSERT_EQ
(
taosArrayGetSize
(
pQueryInfo
->
colList
),
1
);
ASSERT_EQ
(
pQueryInfo
->
fieldsInfo
.
numOfOutput
,
1
);
}
TEST
(
testCase
,
function_Test5
)
{
SSqlInfo
info1
=
doGenerateAST
(
"select sum(a) + avg(b) as a1 from `t.1abc`"
);
ASSERT_EQ
(
info1
.
valid
,
true
);
char
msg
[
128
]
=
{
0
};
SMsgBuf
buf
;
buf
.
len
=
128
;
buf
.
buf
=
msg
;
SSqlNode
*
pNode
=
(
SSqlNode
*
)
taosArrayGetP
(((
SArray
*
)
info1
.
list
),
0
);
int32_t
code
=
evaluateSqlNode
(
pNode
,
TSDB_TIME_PRECISION_NANO
,
&
buf
);
ASSERT_EQ
(
code
,
0
);
SMetaReq
req
=
{
0
};
int32_t
ret
=
qParserExtractRequestedMetaInfo
(
&
info1
,
&
req
,
msg
,
128
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
taosArrayGetSize
(
req
.
pTableName
),
1
);
SQueryStmtInfo
*
pQueryInfo
=
(
SQueryStmtInfo
*
)
calloc
(
1
,
sizeof
(
SQueryStmtInfo
));
initQueryInfo
(
pQueryInfo
);
setTableMetaInfo
(
pQueryInfo
,
&
req
);
SSqlNode
*
pSqlNode
=
(
SSqlNode
*
)
taosArrayGetP
(
info1
.
list
,
0
);
ret
=
validateSqlNode
(
pSqlNode
,
pQueryInfo
,
&
buf
);
ASSERT_EQ
(
ret
,
0
);
SArray
*
pExprList
=
pQueryInfo
->
exprList
;
ASSERT_EQ
(
taosArrayGetSize
(
pExprList
),
3
);
SExprInfo
*
p1
=
(
SExprInfo
*
)
taosArrayGetP
(
pExprList
,
0
);
ASSERT_EQ
(
p1
->
base
.
uid
,
0
);
ASSERT_EQ
(
p1
->
base
.
numOfParams
,
1
);
ASSERT_EQ
(
p1
->
base
.
resSchema
.
type
,
TSDB_DATA_TYPE_DOUBLE
);
ASSERT_STRCASEEQ
(
p1
->
base
.
resSchema
.
name
,
"a1"
);
// ASSERT_STRCASEEQ(p1->base.colInfo.name, "t.1abc.ts");
// ASSERT_EQ(p1->base.colInfo.colId, 0);
ASSERT_EQ
(
p1
->
base
.
colInfo
.
flag
,
TSDB_COL_NORMAL
);
ASSERT_STRCASEEQ
(
p1
->
base
.
token
,
"sum(a) + avg(b)"
);
ASSERT_EQ
(
p1
->
base
.
interBytes
,
0
);
ASSERT_EQ
(
taosArrayGetSize
(
pQueryInfo
->
colList
),
3
);
ASSERT_EQ
(
pQueryInfo
->
fieldsInfo
.
numOfOutput
,
1
);
}
TEST
(
testCase
,
function_Test6
)
{
SSqlInfo
info1
=
doGenerateAST
(
"select sum(a+b) as a1 from `t.1abc`"
);
ASSERT_EQ
(
info1
.
valid
,
true
);
char
msg
[
128
]
=
{
0
};
SMsgBuf
buf
;
buf
.
len
=
128
;
buf
.
buf
=
msg
;
SSqlNode
*
pNode
=
(
SSqlNode
*
)
taosArrayGetP
(((
SArray
*
)
info1
.
list
),
0
);
int32_t
code
=
evaluateSqlNode
(
pNode
,
TSDB_TIME_PRECISION_NANO
,
&
buf
);
ASSERT_EQ
(
code
,
0
);
SMetaReq
req
=
{
0
};
int32_t
ret
=
qParserExtractRequestedMetaInfo
(
&
info1
,
&
req
,
msg
,
128
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
taosArrayGetSize
(
req
.
pTableName
),
1
);
SQueryStmtInfo
*
pQueryInfo
=
(
SQueryStmtInfo
*
)
calloc
(
1
,
sizeof
(
SQueryStmtInfo
));
initQueryInfo
(
pQueryInfo
);
setTableMetaInfo
(
pQueryInfo
,
&
req
);
SSqlNode
*
pSqlNode
=
(
SSqlNode
*
)
taosArrayGetP
(
info1
.
list
,
0
);
ret
=
validateSqlNode
(
pSqlNode
,
pQueryInfo
,
&
buf
);
ASSERT_EQ
(
ret
,
0
);
SArray
*
pExprList
=
pQueryInfo
->
exprList
;
ASSERT_EQ
(
taosArrayGetSize
(
pExprList
),
1
);
SExprInfo
*
p1
=
(
SExprInfo
*
)
taosArrayGetP
(
pExprList
,
0
);
ASSERT_EQ
(
p1
->
base
.
uid
,
110
);
ASSERT_EQ
(
p1
->
base
.
numOfParams
,
0
);
ASSERT_EQ
(
p1
->
base
.
resSchema
.
type
,
TSDB_DATA_TYPE_DOUBLE
);
ASSERT_STRCASEEQ
(
p1
->
base
.
resSchema
.
name
,
"a1"
);
ASSERT_EQ
(
p1
->
base
.
colInfo
.
flag
,
TSDB_COL_NORMAL
);
ASSERT_STRCASEEQ
(
p1
->
base
.
token
,
"sum(a+b)"
);
ASSERT_EQ
(
p1
->
base
.
interBytes
,
16
);
ASSERT_EQ
(
taosArrayGetSize
(
pQueryInfo
->
colList
),
3
);
ASSERT_EQ
(
pQueryInfo
->
fieldsInfo
.
numOfOutput
,
1
);
}
\ No newline at end of file
source/libs/parser/test/tokenizerTest.cpp
浏览文件 @
a531411e
...
...
@@ -4,7 +4,6 @@
#pragma GCC diagnostic ignored "-Wunused-function"
#pragma GCC diagnostic ignored "-Wunused-variable"
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#pragma GCC diagnostic ignored "-Wsign-compare"
#include "os.h"
...
...
@@ -89,6 +88,9 @@ TEST(testCase, validateToken_test) {
char
t01
[]
=
"abc"
;
EXPECT_EQ
(
testValidateName
(
t01
),
TSDB_CODE_SUCCESS
);
char
t110
[]
=
"`1233abc.911`"
;
EXPECT_EQ
(
testValidateName
(
t110
),
TSDB_CODE_SUCCESS
);
char
t02
[]
=
"'abc'"
;
EXPECT_EQ
(
testValidateName
(
t02
),
TSDB_CODE_TSC_INVALID_OPERATION
);
...
...
@@ -689,7 +691,7 @@ TEST(testCase, generateAST_test) {
}
TEST
(
testCase
,
evaluateAST_test
)
{
SSqlInfo
info1
=
doGenerateAST
(
"select a, b+22 from `t.1abc` where ts<now+2h and
col
< 20 + 99"
);
SSqlInfo
info1
=
doGenerateAST
(
"select a, b+22 from `t.1abc` where ts<now+2h and
`col`
< 20 + 99"
);
ASSERT_EQ
(
info1
.
valid
,
true
);
char
msg
[
128
]
=
{
0
};
...
...
@@ -700,6 +702,16 @@ TEST(testCase, evaluateAST_test) {
SSqlNode
*
pNode
=
(
SSqlNode
*
)
taosArrayGetP
(((
SArray
*
)
info1
.
list
),
0
);
int32_t
code
=
evaluateSqlNode
(
pNode
,
TSDB_TIME_PRECISION_NANO
,
&
msgBuf
);
ASSERT_EQ
(
code
,
0
);
}
TEST
(
testCase
,
extractMeta_test
)
{
SSqlInfo
info1
=
doGenerateAST
(
"select a, b+22 from `t.1abc` where ts<now+2h and `col` < 20 + 99"
);
ASSERT_EQ
(
info1
.
valid
,
true
);
char
msg
[
128
]
=
{
0
};
SMetaReq
req
=
{
0
};
int32_t
ret
=
qParserExtractRequestedMetaInfo
(
&
info1
,
&
req
,
msg
,
128
);
ASSERT_EQ
(
ret
,
0
);
ASSERT_EQ
(
taosArrayGetSize
(
req
.
pTableName
),
1
);
}
source/util/src/tutil.c
浏览文件 @
a531411e
...
...
@@ -22,7 +22,7 @@ int32_t strdequote(char *z) {
}
int32_t
quote
=
z
[
0
];
if
(
quote
!=
'\''
&&
quote
!=
'"'
)
{
if
(
quote
!=
'\''
&&
quote
!=
'"'
&&
quote
!=
'`'
)
{
return
(
int32_t
)
strlen
(
z
);
}
...
...
@@ -78,6 +78,34 @@ int32_t strRmquote(char *z, int32_t len){
return
len
-
2
-
cnt
;
}
int32_t
strndequote
(
char
*
dst
,
const
char
*
z
,
int32_t
len
)
{
assert
(
dst
!=
NULL
);
if
(
z
==
NULL
||
len
==
0
)
{
return
0
;
}
int32_t
quote
=
z
[
0
];
int32_t
i
=
1
,
j
=
0
;
while
(
z
[
i
]
!=
0
)
{
if
(
z
[
i
]
==
quote
)
{
if
(
z
[
i
+
1
]
==
quote
)
{
dst
[
j
++
]
=
(
char
)
quote
;
i
++
;
}
else
{
dst
[
j
++
]
=
0
;
return
(
j
-
1
);
}
}
else
{
dst
[
j
++
]
=
z
[
i
];
}
i
++
;
}
return
j
+
1
;
// only one quote, do nothing
}
size_t
strtrim
(
char
*
z
)
{
int32_t
i
=
0
;
int32_t
j
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录