Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
1e6ebdcc
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看板
提交
1e6ebdcc
编写于
9月 22, 2021
作者:
wmmhello
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
TD-6129<feature> add tag-> select logic
上级
56671709
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
93 addition
and
6 deletion
+93
-6
src/client/src/tscSQLParser.c
src/client/src/tscSQLParser.c
+32
-2
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+42
-0
src/query/src/qExecutor.c
src/query/src/qExecutor.c
+12
-0
src/query/src/qSqlParser.c
src/query/src/qSqlParser.c
+5
-0
src/tsdb/src/tsdbMeta.c
src/tsdb/src/tsdbMeta.c
+2
-4
未找到文件。
src/client/src/tscSQLParser.c
浏览文件 @
1e6ebdcc
...
...
@@ -1857,6 +1857,14 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32
static
void
addProjectQueryCol
(
SQueryInfo
*
pQueryInfo
,
int32_t
startPos
,
SColumnIndex
*
pIndex
,
tSqlExprItem
*
pItem
,
int32_t
colId
)
{
SExprInfo
*
pExpr
=
doAddProjectCol
(
pQueryInfo
,
pIndex
->
columnIndex
,
pIndex
->
tableIndex
,
colId
);
if
(
pItem
->
pNode
->
tokenId
==
TK_ARROW
){
tSqlExpr
*
right
=
pItem
->
pNode
->
pRight
;
assert
(
right
!=
NULL
&&
right
->
type
==
SQL_NODE_VALUE
);
tVariantAssign
(
&
(
pExpr
->
base
.
param
[
pExpr
->
base
.
numOfParams
]),
&
right
->
value
);
pExpr
->
base
.
numOfParams
++
;
pExpr
->
base
.
resType
=
TSDB_DATA_TYPE_BINARY
;
// tag-> operation transform result type
assert
(
pExpr
->
base
.
numOfParams
<=
3
);
}
STableMetaInfo
*
pTableMetaInfo
=
tscGetMetaInfo
(
pQueryInfo
,
pIndex
->
tableIndex
);
STableMeta
*
pTableMeta
=
pTableMetaInfo
->
pTableMeta
;
...
...
@@ -2202,6 +2210,8 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
const
char
*
msg1
=
"tag for normal table query is not allowed"
;
const
char
*
msg2
=
"invalid column name"
;
const
char
*
msg3
=
"tbname not allowed in outer query"
;
const
char
*
msg4
=
"-> operate can only used in json type"
;
const
char
*
msg5
=
"the right value of -> operation must be string"
;
int32_t
startPos
=
(
int32_t
)
tscNumOfExprs
(
pQueryInfo
);
int32_t
tokenId
=
pItem
->
pNode
->
tokenId
;
...
...
@@ -2244,10 +2254,25 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
// NOTE: the first parameter is reserved for the tag column id during join query process.
pExpr
->
base
.
numOfParams
=
2
;
tVariantAssign
(
&
pExpr
->
base
.
param
[
1
],
&
pItem
->
pNode
->
value
);
}
else
if
(
tokenId
==
TK_ID
)
{
}
else
if
(
tokenId
==
TK_ID
||
tokenId
==
TK_ARROW
)
{
SColumnIndex
index
=
COLUMN_INDEX_INITIALIZER
;
if
(
getColumnIndexByName
(
&
pItem
->
pNode
->
columnName
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
SStrToken
*
pToken
=
NULL
;
if
(
tokenId
==
TK_ARROW
){
tSqlExpr
*
left
=
pItem
->
pNode
->
pLeft
;
assert
(
left
!=
NULL
&&
left
->
type
==
SQL_NODE_TABLE_COLUMN
);
pToken
=
&
left
->
columnName
;
tSqlExpr
*
right
=
pItem
->
pNode
->
pRight
;
assert
(
right
!=
NULL
&&
right
->
type
==
SQL_NODE_VALUE
);
if
(
right
->
tokenId
!=
TK_STRING
){
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg5
);
}
}
else
{
pToken
=
&
pItem
->
pNode
->
columnName
;
}
if
(
getColumnIndexByName
(
pToken
,
pQueryInfo
,
&
index
,
tscGetErrorMsgPayload
(
pCmd
))
!=
TSDB_CODE_SUCCESS
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg2
);
}
...
...
@@ -2294,6 +2319,11 @@ int32_t addProjectionExprAndResultField(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, t
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg1
);
}
SSchema
*
pSchema
=
tscGetTableColumnSchema
(
pTableMeta
,
index
.
columnIndex
);
if
(
tokenId
==
TK_ARROW
&&
pSchema
->
type
!=
TSDB_DATA_TYPE_JSON
)
{
return
invalidOperationMsg
(
tscGetErrorMsgPayload
(
pCmd
),
msg4
);
}
addProjectQueryCol
(
pQueryInfo
,
startPos
,
&
index
,
pItem
,
getNewResColId
(
pCmd
));
pQueryInfo
->
type
|=
TSDB_QUERY_TYPE_PROJECTION_QUERY
;
}
...
...
src/client/src/tscUtil.c
浏览文件 @
1e6ebdcc
...
...
@@ -5174,6 +5174,48 @@ char* cloneCurrentDBName(SSqlObj* pSql) {
return
p
;
}
pExprInfo
[
j
].
base
.
param
[
0
].
nLen
char
*
findTagValue
(
void
*
data
,
char
*
key
,
int32_t
keyLen
){
int16_t
nCols
=
kvRowNCols
(
data
);
bool
found
=
false
;
for
(
int
k
=
1
;
k
<
nCols
;
++
k
)
{
SColIdx
*
pColIdx
=
kvRowColIdxAt
(
data
,
k
);
void
*
result
=
kvRowColVal
(
data
,
pColIdx
);
if
(
k
%
2
!=
0
)
{
// json key
char
tagJsonKey
[
TSDB_MAX_TAGS_LEN
]
=
{
0
};
int32_t
length
=
taosUcs4ToMbs
(
varDataVal
(
result
),
varDataLen
(
result
),
tagJsonKey
);
if
(
length
==
0
)
{
tscError
(
"charset:%s to %s. val:%s convert json key failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
(
char
*
)
result
);
continue
;
}
if
(
strncmp
(
key
,
tagJsonKey
,
keyLen
)
!=
0
)
{
continue
;
}
found
=
true
;
}
else
{
// json value
if
(
!
found
)
continue
;
if
(
*
(
char
*
)
result
==
cJSON_String
)
{
char
tagJsonValue
[
TSDB_MAX_TAGS_LEN
]
=
{
0
};
int32_t
length
=
taosUcs4ToMbs
(
varDataVal
(
POINTER_SHIFT
(
result
,
CHAR_BYTES
)),
varDataLen
(
POINTER_SHIFT
(
result
,
CHAR_BYTES
)),
tagJsonValue
);
if
(
length
==
0
)
{
tscError
(
"charset:%s to %s. val:%s convert json value failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
(
char
*
)
result
);
}
}
else
if
(
*
(
char
*
)
result
==
cJSON_Number
)
{
double
jsonVd
=
*
(
double
*
)(
POINTER_SHIFT
(
result
,
CHAR_BYTES
));
}
else
{
tscError
(
"unsupportted json value"
);
}
}
}
}
char
*
parseTagDatatoJson
(
void
*
p
){
char
*
string
=
NULL
;
cJSON
*
json
=
cJSON_CreateObject
();
...
...
src/query/src/qExecutor.c
浏览文件 @
1e6ebdcc
...
...
@@ -30,6 +30,8 @@
#include "tscompression.h"
#include "qScript.h"
#include "tscLog.h"
#include "cJSON.h"
#include "tsdbMeta.h"
#define IS_MASTER_SCAN(runtime) ((runtime)->scanFlag == MASTER_SCAN)
#define IS_REVERSE_SCAN(runtime) ((runtime)->scanFlag == REVERSE_SCAN)
...
...
@@ -7176,6 +7178,16 @@ static SSDataBlock* doTagScan(void* param, bool* newgroup) {
data
=
tsdbGetTableName
(
item
->
pTable
);
}
else
{
data
=
tsdbGetTableTagVal
(
item
->
pTable
,
pExprInfo
[
j
].
base
.
colInfo
.
colId
,
type
,
bytes
);
if
(
pExprInfo
[
j
].
base
.
numOfParams
>
0
){
// tag-> operation
STSchema
*
pSchema
=
tsdbGetTableTagSchema
((
STable
*
)
item
->
pTable
);
STColumn
*
pCol
=
tdGetColOfID
(
pSchema
,
pExprInfo
[
j
].
base
.
colInfo
.
colId
);
if
(
pCol
==
NULL
)
{
continue
;
// No matched tag volumn
}
if
(
pCol
->
type
==
TSDB_DATA_TYPE_JSON
){
}
}
}
dst
=
pColInfo
->
pData
+
count
*
pExprInfo
[
j
].
base
.
resBytes
;
...
...
src/query/src/qSqlParser.c
浏览文件 @
1e6ebdcc
...
...
@@ -327,6 +327,11 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
pRSub
->
Expr
.
paramList
=
(
SArray
*
)
pRight
;
pExpr
->
pRight
=
pRSub
;
}
else
if
(
optrType
==
TK_ARROW
)
{
pExpr
->
tokenId
=
optrType
;
pExpr
->
pLeft
=
pLeft
;
pExpr
->
pRight
=
pRight
;
pExpr
->
type
=
SQL_NODE_TABLE_COLUMN
;
}
else
{
pExpr
->
tokenId
=
optrType
;
pExpr
->
pLeft
=
pLeft
;
...
...
src/tsdb/src/tsdbMeta.c
浏览文件 @
1e6ebdcc
...
...
@@ -211,14 +211,12 @@ void *tsdbGetTableTagVal(const void* pTable, int32_t colId, int16_t type, int16_
}
char
*
val
=
NULL
;
if
(
type
==
TSDB_DATA_TYPE_JSON
){
if
(
pCol
->
type
==
TSDB_DATA_TYPE_JSON
){
val
=
((
STable
*
)
pTable
)
->
tagVal
;
}
else
{
val
=
tdGetKVRowValOfCol
(((
STable
*
)
pTable
)
->
tagVal
,
colId
);
assert
(
type
==
pCol
->
type
&&
bytes
>=
pCol
->
bytes
);
}
assert
(
type
==
pCol
->
type
&&
bytes
>=
pCol
->
bytes
);
// if (val != NULL && IS_VAR_DATA_TYPE(type)) {
// assert(varDataLen(val) < pCol->bytes);
// }
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录