Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
b57f62f1
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看板
提交
b57f62f1
编写于
5月 12, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: adjust query stmt APIs
上级
fed7f170
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
138 addition
and
15 deletion
+138
-15
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+1
-0
include/libs/parser/parser.h
include/libs/parser/parser.h
+10
-8
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+3
-3
source/libs/parser/inc/parAst.h
source/libs/parser/inc/parAst.h
+1
-0
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+8
-0
source/libs/parser/src/parAstParser.c
source/libs/parser/src/parAstParser.c
+2
-0
source/libs/parser/src/parser.c
source/libs/parser/src/parser.c
+112
-3
source/libs/planner/test/planTestUtil.cpp
source/libs/planner/test/planTestUtil.cpp
+1
-1
未找到文件。
include/libs/nodes/querynodes.h
浏览文件 @
b57f62f1
...
...
@@ -324,6 +324,7 @@ typedef struct SQuery {
SArray
*
pTableList
;
bool
showRewrite
;
int32_t
placeholderNum
;
SArray
*
pPlaceholderValues
;
}
SQuery
;
void
nodesWalkSelectStmt
(
SSelectStmt
*
pSelect
,
ESqlClause
clause
,
FNodeWalker
walker
,
void
*
pContext
);
...
...
include/libs/parser/parser.h
浏览文件 @
b57f62f1
...
...
@@ -47,21 +47,23 @@ typedef struct SParseContext {
bool
isSuperUser
;
}
SParseContext
;
int32_t
qParse
Query
Sql
(
SParseContext
*
pCxt
,
SQuery
**
pQuery
);
int32_t
qParseSql
(
SParseContext
*
pCxt
,
SQuery
**
pQuery
);
bool
isInsertSql
(
const
char
*
pStr
,
size_t
length
);
void
qDestroyQuery
(
SQuery
*
pQueryNode
);
int32_t
qExtractResultSchema
(
const
SNode
*
pRoot
,
int32_t
*
numOfCols
,
SSchema
**
pSchema
);
int32_t
qBuildStmtOutput
(
SQuery
*
pQuery
,
SHashObj
*
pVgHash
,
SHashObj
*
pBlockHash
);
int32_t
qResetStmtDataBlock
(
void
*
block
,
bool
keepBuf
);
int32_t
qCloneStmtDataBlock
(
void
**
pDst
,
void
*
pSrc
);
void
qFreeStmtDataBlock
(
void
*
pDataBlock
);
int32_t
qRebuildStmtDataBlock
(
void
**
pDst
,
void
*
pSrc
,
uint64_t
uid
,
int32_t
vgId
);
void
qDestroyStmtDataBlock
(
void
*
pBlock
);
STableMeta
*
qGetTableMetaInDataBlock
(
void
*
pDataBlock
);
int32_t
qBuildStmtOutput
(
SQuery
*
pQuery
,
SHashObj
*
pVgHash
,
SHashObj
*
pBlockHash
);
int32_t
qResetStmtDataBlock
(
void
*
block
,
bool
keepBuf
);
int32_t
qCloneStmtDataBlock
(
void
**
pDst
,
void
*
pSrc
);
void
qFreeStmtDataBlock
(
void
*
pDataBlock
);
int32_t
qRebuildStmtDataBlock
(
void
**
pDst
,
void
*
pSrc
,
uint64_t
uid
,
int32_t
vgId
);
void
qDestroyStmtDataBlock
(
void
*
pBlock
);
STableMeta
*
qGetTableMetaInDataBlock
(
void
*
pDataBlock
);
int32_t
qStmtBindParams
(
SQuery
*
pQuery
,
TAOS_MULTI_BIND
*
pParams
,
int32_t
colIdx
,
uint64_t
queryId
);
int32_t
qStmtParseQuerySql
(
SParseContext
*
pCxt
,
SQuery
*
pQuery
);
int32_t
qBindStmtColsValue
(
void
*
pBlock
,
TAOS_MULTI_BIND
*
bind
,
char
*
msgBuf
,
int32_t
msgBufLen
);
int32_t
qBindStmtSingleColValue
(
void
*
pBlock
,
TAOS_MULTI_BIND
*
bind
,
char
*
msgBuf
,
int32_t
msgBufLen
,
int32_t
colIdx
,
int32_t
rowNum
);
...
...
source/client/src/clientImpl.c
浏览文件 @
b57f62f1
...
...
@@ -180,7 +180,7 @@ int32_t parseSql(SRequestObj* pRequest, bool topicQuery, SQuery** pQuery, SStmtC
return
code
;
}
code
=
qParse
Query
Sql
(
&
cxt
,
pQuery
);
code
=
qParseSql
(
&
cxt
,
pQuery
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
((
*
pQuery
)
->
haveResultSet
)
{
setResSchemaInfo
(
&
pRequest
->
body
.
resInfo
,
(
*
pQuery
)
->
pResSchema
,
(
*
pQuery
)
->
numOfResCols
);
...
...
@@ -554,8 +554,8 @@ static SMsgSendInfo* buildConnectMsg(SRequestObj* pRequest) {
}
taosMemoryFreeClear
(
db
);
connectReq
.
connType
=
pObj
->
connType
;
connectReq
.
pid
=
htonl
(
appInfo
.
pid
);
connectReq
.
connType
=
pObj
->
connType
;
connectReq
.
pid
=
htonl
(
appInfo
.
pid
);
connectReq
.
startTime
=
htobe64
(
appInfo
.
startTime
);
tstrncpy
(
connectReq
.
app
,
appInfo
.
appName
,
sizeof
(
connectReq
.
app
));
...
...
source/libs/parser/inc/parAst.h
浏览文件 @
b57f62f1
...
...
@@ -32,6 +32,7 @@ typedef struct SAstCreateContext {
bool
notSupport
;
SNode
*
pRootNode
;
int16_t
placeholderNo
;
SArray
*
pPlaceholderValues
;
int32_t
errCode
;
}
SAstCreateContext
;
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
b57f62f1
...
...
@@ -299,6 +299,14 @@ SNode* createPlaceholderValueNode(SAstCreateContext* pCxt, const SToken* pLitera
val
->
literal
=
strndup
(
pLiteral
->
z
,
pLiteral
->
n
);
CHECK_OUT_OF_MEM
(
val
->
literal
);
val
->
placeholderNo
=
++
pCxt
->
placeholderNo
;
if
(
NULL
==
pCxt
->
pPlaceholderValues
)
{
pCxt
->
pPlaceholderValues
=
taosArrayInit
(
TARRAY_MIN_SIZE
,
POINTER_BYTES
);
if
(
NULL
==
pCxt
->
pPlaceholderValues
)
{
nodesDestroyNode
(
val
);
return
NULL
;
}
}
taosArrayPush
(
pCxt
->
pPlaceholderValues
,
&
val
);
return
(
SNode
*
)
val
;
}
...
...
source/libs/parser/src/parAstParser.c
浏览文件 @
b57f62f1
...
...
@@ -81,6 +81,8 @@ abort_parse:
}
(
*
pQuery
)
->
pRoot
=
cxt
.
pRootNode
;
(
*
pQuery
)
->
placeholderNum
=
cxt
.
placeholderNo
;
TSWAP
((
*
pQuery
)
->
pPlaceholderValues
,
cxt
.
pPlaceholderValues
);
}
taosArrayDestroy
(
cxt
.
pPlaceholderValues
);
return
cxt
.
errCode
;
}
source/libs/parser/src/parser.c
浏览文件 @
b57f62f1
...
...
@@ -39,16 +39,99 @@ static int32_t parseSqlIntoAst(SParseContext* pCxt, SQuery** pQuery) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
authenticate
(
pCxt
,
*
pQuery
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
&&
0
==
(
*
pQuery
)
->
placeholderNum
)
{
code
=
translate
(
pCxt
,
*
pQuery
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
&&
0
==
(
*
pQuery
)
->
placeholderNum
)
{
code
=
calculateConstant
(
pCxt
,
*
pQuery
);
}
return
code
;
}
int32_t
qParseQuerySql
(
SParseContext
*
pCxt
,
SQuery
**
pQuery
)
{
static
int32_t
setValueByBindParam
(
SValueNode
*
pVal
,
TAOS_MULTI_BIND
*
pParam
)
{
if
(
pParam
->
is_null
&&
1
==
*
(
pParam
->
is_null
))
{
pVal
->
node
.
resType
.
type
=
TSDB_DATA_TYPE_NULL
;
pVal
->
node
.
resType
.
bytes
=
tDataTypes
[
TSDB_DATA_TYPE_NULL
].
bytes
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
inputSize
=
(
NULL
!=
pParam
->
length
?
*
(
pParam
->
length
)
:
tDataTypes
[
pParam
->
buffer_type
].
bytes
);
pVal
->
node
.
resType
.
type
=
pParam
->
buffer_type
;
pVal
->
node
.
resType
.
bytes
=
inputSize
;
switch
(
pParam
->
buffer_type
)
{
case
TSDB_DATA_TYPE_BOOL
:
pVal
->
datum
.
b
=
*
((
bool
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_TINYINT
:
pVal
->
datum
.
i
=
*
((
int8_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
pVal
->
datum
.
i
=
*
((
int16_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_INT
:
pVal
->
datum
.
i
=
*
((
int32_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_BIGINT
:
pVal
->
datum
.
i
=
*
((
int64_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_FLOAT
:
pVal
->
datum
.
d
=
*
((
float
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
pVal
->
datum
.
d
=
*
((
double
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_VARCHAR
:
case
TSDB_DATA_TYPE_VARBINARY
:
pVal
->
datum
.
p
=
taosMemoryCalloc
(
1
,
pVal
->
node
.
resType
.
bytes
+
VARSTR_HEADER_SIZE
+
1
);
if
(
NULL
==
pVal
->
datum
.
p
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
varDataSetLen
(
pVal
->
datum
.
p
,
pVal
->
node
.
resType
.
bytes
);
strncpy
(
varDataVal
(
pVal
->
datum
.
p
),
(
const
char
*
)
pParam
->
buffer
,
pVal
->
node
.
resType
.
bytes
);
break
;
case
TSDB_DATA_TYPE_NCHAR
:
{
pVal
->
node
.
resType
.
bytes
*=
TSDB_NCHAR_SIZE
;
pVal
->
datum
.
p
=
taosMemoryCalloc
(
1
,
pVal
->
node
.
resType
.
bytes
+
VARSTR_HEADER_SIZE
+
1
);
if
(
NULL
==
pVal
->
datum
.
p
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
int32_t
output
=
0
;
if
(
!
taosMbsToUcs4
(
pParam
->
buffer
,
inputSize
,
(
TdUcs4
*
)
varDataVal
(
pVal
->
datum
.
p
),
pVal
->
node
.
resType
.
bytes
,
&
output
))
{
return
errno
;
}
varDataSetLen
(
pVal
->
datum
.
p
,
output
);
pVal
->
node
.
resType
.
bytes
=
output
;
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
pVal
->
datum
.
i
=
*
((
int64_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
pVal
->
datum
.
u
=
*
((
uint8_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
pVal
->
datum
.
u
=
*
((
uint16_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_UINT
:
pVal
->
datum
.
u
=
*
((
uint32_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
pVal
->
datum
.
u
=
*
((
uint64_t
*
)
pParam
->
buffer
);
break
;
case
TSDB_DATA_TYPE_JSON
:
case
TSDB_DATA_TYPE_DECIMAL
:
case
TSDB_DATA_TYPE_BLOB
:
case
TSDB_DATA_TYPE_MEDIUMBLOB
:
// todo
default:
break
;
}
pVal
->
translate
=
true
;
return
TSDB_CODE_SUCCESS
;
}
int32_t
qParseSql
(
SParseContext
*
pCxt
,
SQuery
**
pQuery
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
isInsertSql
(
pCxt
->
pSql
,
pCxt
->
sqlLen
))
{
code
=
parseInsertSql
(
pCxt
,
pQuery
);
...
...
@@ -77,3 +160,29 @@ void qDestroyQuery(SQuery* pQueryNode) {
int32_t
qExtractResultSchema
(
const
SNode
*
pRoot
,
int32_t
*
numOfCols
,
SSchema
**
pSchema
)
{
return
extractResultSchema
(
pRoot
,
numOfCols
,
pSchema
);
}
int32_t
qStmtBindParams
(
SQuery
*
pQuery
,
TAOS_MULTI_BIND
*
pParams
,
int32_t
colIdx
,
uint64_t
queryId
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
if
(
colIdx
<
0
)
{
int32_t
size
=
taosArrayGetSize
(
pQuery
->
pPlaceholderValues
);
for
(
int32_t
i
=
0
;
i
<
size
;
++
i
)
{
code
=
setValueByBindParam
((
SValueNode
*
)
taosArrayGetP
(
pQuery
->
pPlaceholderValues
,
i
),
pParams
+
i
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
return
code
;
}
}
}
else
{
code
=
setValueByBindParam
((
SValueNode
*
)
taosArrayGetP
(
pQuery
->
pPlaceholderValues
,
colIdx
),
pParams
);
}
return
code
;
}
int32_t
qStmtParseQuerySql
(
SParseContext
*
pCxt
,
SQuery
*
pQuery
)
{
int32_t
code
=
translate
(
pCxt
,
pQuery
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
calculateConstant
(
pCxt
,
pQuery
);
}
return
code
;
}
source/libs/planner/test/planTestUtil.cpp
浏览文件 @
b57f62f1
...
...
@@ -198,7 +198,7 @@ class PlannerTestBaseImpl {
cxt
.
pMsg
=
stmtEnv_
.
msgBuf_
.
data
();
cxt
.
msgLen
=
stmtEnv_
.
msgBuf_
.
max_size
();
DO_WITH_THROW
(
qParse
Query
Sql
,
&
cxt
,
pQuery
);
DO_WITH_THROW
(
qParseSql
,
&
cxt
,
pQuery
);
res_
.
ast_
=
toString
((
*
pQuery
)
->
pRoot
);
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录