Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
d56c3a29
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看板
提交
d56c3a29
编写于
9月 26, 2021
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-6129<feature> add tag-> where logic
上级
24ca420e
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
153 addition
and
27 deletion
+153
-27
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+13
-3
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+6
-0
src/common/src/texpr.c
src/common/src/texpr.c
+1
-0
src/query/inc/qFilter.h
src/query/inc/qFilter.h
+1
-1
src/query/src/qFilter.c
src/query/src/qFilter.c
+23
-12
src/query/src/qSqlParser.c
src/query/src/qSqlParser.c
+3
-1
src/tsdb/src/tsdbRead.c
src/tsdb/src/tsdbRead.c
+106
-10
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
d56c3a29
...
...
@@ -4249,7 +4249,7 @@ static void exchangeExpr(tSqlExpr* pExpr) {
tSqlExpr
*
pLeft
=
pExpr
->
pLeft
;
tSqlExpr
*
pRight
=
pExpr
->
pRight
;
if
(
pRight
->
tokenId
==
TK_ID
&&
(
pLeft
->
tokenId
==
TK_INTEGER
||
pLeft
->
tokenId
==
TK_FLOAT
||
if
(
(
pRight
->
tokenId
==
TK_ID
||
pRight
->
tokenId
==
TK_ARROW
)
&&
(
pLeft
->
tokenId
==
TK_INTEGER
||
pLeft
->
tokenId
==
TK_FLOAT
||
pLeft
->
tokenId
==
TK_STRING
||
pLeft
->
tokenId
==
TK_BOOL
))
{
/*
* exchange value of the left handside and the value of the right-handside
...
...
@@ -4487,6 +4487,8 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql
const
char
*
msg2
=
"illegal column name"
;
const
char
*
msg4
=
"too many join tables"
;
const
char
*
msg5
=
"not support ordinary column join"
;
const
char
*
msg6
=
"not support json tag column filter"
;
const
char
*
msg7
=
"tag json key is too long, exceed to 64"
;
tSqlExpr
*
pLeft
=
(
*
pExpr
)
->
pLeft
;
tSqlExpr
*
pRight
=
(
*
pExpr
)
->
pRight
;
...
...
@@ -4603,6 +4605,15 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_JSON
&&
pLeft
!=
NULL
&&
(
pLeft
->
tokenId
==
TK_ID
)){
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg6
);
}
if
(
pSchema
->
type
==
TSDB_DATA_TYPE_JSON
&&
pLeft
!=
NULL
&&
(
pLeft
->
tokenId
==
TK_ARROW
)){
if
(
pLeft
->
pRight
&&
pLeft
->
pRight
->
value
.
nLen
>=
TSDB_COL_NAME_LEN
)
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg7
);
}
if
(
pRight
!=
NULL
&&
pRight
->
tokenId
==
TK_ID
)
{
// join on tag columns for stable query
if
(
!
validateJoinExprNode
(
pCmd
,
pQueryInfo
,
*
pExpr
,
&
index
))
{
return
TSDB_CODE_TSC_INVALID_OPERATION
;
...
...
@@ -4621,8 +4632,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql
tSqlExpr
*
rexpr
=
NULL
;
if
((
*
pExpr
)
->
tokenId
==
TK_NE
&&
(
pSchema
->
type
!=
TSDB_DATA_TYPE_BINARY
&&
pSchema
->
type
!=
TSDB_DATA_TYPE_NCHAR
&&
pSchema
->
type
!=
TSDB_DATA_TYPE_BOOL
&&
pSchema
->
type
!=
TSDB_DATA_TYPE_JSON
))
{
&&
pSchema
->
type
!=
TSDB_DATA_TYPE_BOOL
))
{
handleNeOptr
(
&
rexpr
,
*
pExpr
);
*
pExpr
=
rexpr
;
}
...
...
src/client/src/tscUtil.c
浏览文件 @
d56c3a29
...
...
@@ -5330,6 +5330,12 @@ int parseJsontoTagData(char* json, SKVRowBuilder* kvRowBuilder, char* errMsg, in
retCode
=
tscSQLSyntaxErrMsg
(
errMsg
,
"json inner error"
,
NULL
);
goto
end
;
}
if
(
strlen
(
item
->
string
)
>=
TSDB_COL_NAME_LEN
){
tscError
(
"json key too long error"
);
retCode
=
tscSQLSyntaxErrMsg
(
errMsg
,
"json key too long, exceed 64"
,
NULL
);
goto
end
;
}
char
tagVal
[
TSDB_MAX_TAGS_LEN
]
=
{
0
};
int32_t
outLen
=
0
;
if
(
JSON_TYPE_BINARY
){
...
...
src/common/src/texpr.c
浏览文件 @
d56c3a29
...
...
@@ -117,6 +117,7 @@ void tExprTreeDestroy(tExprNode *pNode, void (*fp)(void *)) {
doExprTreeDestroy
(
&
pNode
,
fp
);
}
else
if
(
pNode
->
nodeType
==
TSQL_NODE_VALUE
)
{
tVariantDestroy
(
pNode
->
pVal
);
tfree
(
pNode
->
pVal
);
}
else
if
(
pNode
->
nodeType
==
TSQL_NODE_COL
)
{
tfree
(
pNode
->
pSchema
);
}
...
...
src/query/inc/qFilter.h
浏览文件 @
d56c3a29
...
...
@@ -250,7 +250,7 @@ typedef struct SFilterInfo {
#define COL_FIELD_SIZE (sizeof(SFilterField) + 2 * sizeof(int64_t))
#define FILTER_NO_MERGE_DATA_TYPE(t) ((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_NCHAR)
#define FILTER_NO_MERGE_DATA_TYPE(t) ((t) == TSDB_DATA_TYPE_BINARY || (t) == TSDB_DATA_TYPE_NCHAR
|| (t) == TSDB_DATA_TYPE_JSON
)
#define FILTER_NO_MERGE_OPTR(o) ((o) == TSDB_RELATION_ISNULL || (o) == TSDB_RELATION_NOTNULL || (o) == FILTER_DUMMY_EMPTY_OPTR)
#define MR_EMPTY_RES(ctx) (ctx->rs == NULL)
...
...
src/query/src/qFilter.c
浏览文件 @
d56c3a29
...
...
@@ -42,7 +42,12 @@ static FORCE_INLINE int32_t filterFieldColDescCompare(const void *desc1, const v
const
SSchema
*
sch1
=
desc1
;
const
SSchema
*
sch2
=
desc2
;
if
(
sch1
->
type
==
TSDB_DATA_TYPE_JSON
&&
sch2
->
type
==
TSDB_DATA_TYPE_JSON
){
return
strcmp
(
sch1
->
name
,
sch2
->
name
);
}
else
{
return
sch1
->
colId
!=
sch2
->
colId
;
}
}
static
FORCE_INLINE
int32_t
filterFieldValDescCompare
(
const
void
*
desc1
,
const
void
*
desc2
)
{
...
...
@@ -849,11 +854,17 @@ static FORCE_INLINE int32_t filterAddColFieldFromField(SFilterInfo *info, SFilte
int32_t
filterAddFieldFromNode
(
SFilterInfo
*
info
,
tExprNode
*
node
,
SFilterFieldId
*
fid
)
{
CHK_LRET
(
node
==
NULL
,
TSDB_CODE_QRY_APP_ERROR
,
"empty node"
);
CHK_RET
(
node
->
nodeType
!=
TSQL_NODE_COL
&&
node
->
nodeType
!=
TSQL_NODE_VALUE
,
TSDB_CODE_QRY_APP_ERROR
);
int32_t
type
;
void
*
v
;
if
(
node
->
nodeType
==
TSQL_NODE_EXPR
&&
node
->
_node
.
optr
==
TSDB_RELATION_ARROW
){
// json tag -> operation
type
=
FLD_TYPE_COLUMN
;
assert
(
node
->
_node
.
pRight
->
pVal
->
nLen
<
TSDB_COL_NAME_LEN
);
strncpy
(
node
->
_node
.
pLeft
->
pSchema
->
name
,
node
->
_node
.
pRight
->
pVal
->
pz
,
node
->
_node
.
pRight
->
pVal
->
nLen
);
v
=
node
->
pSchema
;
node
->
pSchema
=
NULL
;
}
else
{
CHK_RET
(
node
->
nodeType
!=
TSQL_NODE_COL
&&
node
->
nodeType
!=
TSQL_NODE_VALUE
,
TSDB_CODE_QRY_APP_ERROR
);
if
(
node
->
nodeType
==
TSQL_NODE_COL
)
{
type
=
FLD_TYPE_COLUMN
;
v
=
node
->
pSchema
;
...
...
@@ -863,7 +874,7 @@ int32_t filterAddFieldFromNode(SFilterInfo *info, tExprNode *node, SFilterFieldI
v
=
node
->
pVal
;
node
->
pVal
=
NULL
;
}
}
filterAddField
(
info
,
v
,
NULL
,
type
,
fid
,
0
,
true
);
return
TSDB_CODE_SUCCESS
;
...
...
@@ -1531,7 +1542,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
if
(
unit
->
right
.
type
==
FLD_TYPE_VALUE
&&
FILTER_UNIT_OPTR
(
unit
)
!=
TSDB_RELATION_IN
)
{
SFilterField
*
right
=
FILTER_UNIT_RIGHT_FIELD
(
info
,
unit
);
char
*
data
=
right
->
data
;
if
(
IS_VAR_DATA_TYPE
(
type
)
||
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
IS_VAR_DATA_TYPE
(
type
)
{
tlen
=
varDataLen
(
data
);
data
+=
VARSTR_HEADER_SIZE
;
}
...
...
@@ -1548,7 +1559,7 @@ void filterDumpInfoToString(SFilterInfo *info, const char *msg, int32_t options)
if
(
unit
->
right2
.
type
==
FLD_TYPE_VALUE
&&
FILTER_UNIT_OPTR
(
unit
)
!=
TSDB_RELATION_IN
)
{
SFilterField
*
right
=
FILTER_UNIT_RIGHT2_FIELD
(
info
,
unit
);
char
*
data
=
right
->
data
;
if
(
IS_VAR_DATA_TYPE
(
type
)
||
type
==
TSDB_DATA_TYPE_JSON
)
{
if
(
IS_VAR_DATA_TYPE
(
type
))
{
tlen
=
varDataLen
(
data
);
data
+=
VARSTR_HEADER_SIZE
;
}
...
...
src/query/src/qSqlParser.c
浏览文件 @
d56c3a29
...
...
@@ -473,7 +473,9 @@ bool tSqlExprIsLeaf(tSqlExpr* pExpr) {
(
pExpr
->
tokenId
==
TK_ID
)
||
(
pExpr
->
tokenId
>=
TK_BOOL
&&
pExpr
->
tokenId
<=
TK_NCHAR
)
||
(
pExpr
->
tokenId
==
TK_NULL
)
||
(
pExpr
->
tokenId
==
TK_SET
));
(
pExpr
->
tokenId
==
TK_SET
)
||
(
pExpr
->
tokenId
==
TK_ARROW
)
||
(
pExpr
->
tokenId
==
TK_QUESTION
));
}
bool
tSqlExprIsParentOfLeaf
(
tSqlExpr
*
pExpr
)
{
...
...
src/tsdb/src/tsdbRead.c
浏览文件 @
d56c3a29
...
...
@@ -3648,6 +3648,70 @@ SArray* createTableGroup(SArray* pTableList, STSchema* pTagSchema, SColIndex* pC
return
pTableGroup
;
}
//bool checkJsonKey(STable* pTable, tVariant* key){
// void* data = taosHashGet(pTable->jsonKeyMap, key->pz, key->nLen);
// if(data == NULL) return false;
// else return true;
//}
//
//int32_t dealWithTree(STable* pTable, tExprNode* expr){
// STSchema* pTagSchema = tsdbGetTableTagSchema(pTable);
// if(pTagSchema->columns->type != TSDB_DATA_TYPE_JSON){
// return TSDB_CODE_SUCCESS;
// }
//
// if (expr->nodeType != TSQL_NODE_EXPR) {
// tsdbError("invalid nodeType:%d", expr->nodeType);
// return TSDB_CODE_QRY_APP_ERROR;
// }
//
// if (tree->_node.optr == TSDB_RELATION_AND) {
// leftGroup = taosArrayInit(4, sizeof(SFilterGroup));
// rightGroup = taosArrayInit(4, sizeof(SFilterGroup));
// ERR_JRET(filterTreeToGroup(tree->_node.pLeft, info, leftGroup));
// ERR_JRET(filterTreeToGroup(tree->_node.pRight, info, rightGroup));
//
// ERR_JRET(filterDetachCnfGroups(group, leftGroup, rightGroup));
//
// taosArrayDestroyEx(leftGroup, filterFreeGroup);
// taosArrayDestroyEx(rightGroup, filterFreeGroup);
//
// return TSDB_CODE_SUCCESS;
// }
//
// if (tree->_node.optr == TSDB_RELATION_OR) {
// ERR_RET(filterTreeToGroup(tree->_node.pLeft, info, group));
// ERR_RET(filterTreeToGroup(tree->_node.pRight, info, group));
//
// return TSDB_CODE_SUCCESS;
// }
//
// tExprNode* tLeft = expr->_node.pLeft;
//
// tVariant* var = tree->_node.pRight->pVal;
// int32_t type = FILTER_GET_COL_FIELD_TYPE(FILTER_GET_FIELD(info, left));
// int32_t len = 0;
// uint16_t uidx = 0;
//
//
// assert(tLeft->nodeType == TSQL_NODE_EXPR);
//
// if (tLeft->_node.optr == TSDB_RELATION_ARROW) {
// if(!checkJsonKey(pTable, tLeft->_node.pRight->pVal)){
// tsdbError("no key in json:%d", expr->nodeType);
// return TSDB_CODE_QRY_APP_ERROR;
// }
//
// tExprTreeDestroy(tLeft, NULL);
//
// expr->_node.pLeft = calloc(1, sizeof(tExprNode));
//
// expr->_node.pLeft->nodeType = TSQL_NODE_COL;
// expr->_node.pLeft->pSchema = calloc(1, sizeof(SSchema));
// }
// return 0;
//}
int32_t
tsdbQuerySTableByTagCond
(
STsdbRepo
*
tsdb
,
uint64_t
uid
,
TSKEY
skey
,
const
char
*
pTagCond
,
size_t
len
,
STableGroupInfo
*
pGroupInfo
,
SColIndex
*
pColIndex
,
int32_t
numOfCols
)
{
SArray
*
res
=
NULL
;
...
...
@@ -3711,7 +3775,6 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo* tsdb, uint64_t uid, TSKEY skey, cons
}
END_TRY
void
*
filterInfo
=
NULL
;
ret
=
filterInitFromTree
(
expr
,
&
filterInfo
,
0
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
ret
;
...
...
@@ -4001,9 +4064,41 @@ static void queryIndexlessColumn(SSkipList* pSkipList, void* filterInfo, SArray*
tSkipListDestroyIter
(
iter
);
}
static
FORCE_INLINE
int32_t
tsdbGetJsonTagDataFromId
(
void
*
param
,
int32_t
id
,
void
**
data
)
{
JsonMapValue
*
jsonMapV
=
(
JsonMapValue
*
)(
param
);
STable
*
pTable
=
(
STable
*
)(
jsonMapV
->
table
);
if
(
id
==
TSDB_TBNAME_COLUMN_INDEX
)
{
*
data
=
TABLE_NAME
(
pTable
);
}
else
{
*
data
=
tdGetKVRowValOfCol
(
pTable
->
tagVal
,
jsonMapV
->
colId
+
1
);
}
return
TSDB_CODE_SUCCESS
;
}
static
void
queryByJsonTag
(
SArray
*
pTableList
,
void
*
filterInfo
,
SArray
*
res
){
int32_t
size
=
taosArrayGetSize
(
pTableList
);
int8_t
*
addToResult
=
NULL
;
for
(
int
i
=
0
;
i
<
size
;
i
++
){
JsonMapValue
*
data
=
taosArrayGet
(
pTableList
,
i
);
filterSetColFieldData
(
filterInfo
,
data
,
tsdbGetJsonTagDataFromId
);
bool
all
=
filterExecute
(
filterInfo
,
1
,
&
addToResult
,
NULL
,
0
);
if
(
all
||
(
addToResult
&&
*
addToResult
))
{
STableKeyInfo
info
=
{.
pTable
=
(
void
*
)(
data
->
table
),
.
lastKey
=
TSKEY_INITIAL_VAL
};
taosArrayPush
(
res
,
&
info
);
}
}
tfree
(
addToResult
);
}
static
int32_t
tsdbQueryTableList
(
STable
*
pTable
,
SArray
*
pRes
,
void
*
filterInfo
)
{
STSchema
*
pTSSchema
=
pTable
->
tagSchema
;
if
(
pTSSchema
->
columns
->
type
==
TSDB_DATA_TYPE_JSON
){
queryByJsonTag
(
pTable
,
filterInfo
,
pRes
);
}
else
{
bool
indexQuery
=
false
;
SSkipList
*
pSkipList
=
pTable
->
pIndex
;
...
...
@@ -4014,6 +4109,7 @@ static int32_t tsdbQueryTableList(STable* pTable, SArray* pRes, void* filterInfo
}
else
{
queryIndexlessColumn
(
pSkipList
,
filterInfo
,
pRes
);
}
}
return
TSDB_CODE_SUCCESS
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录