Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
455006cc
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
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看板
未验证
提交
455006cc
编写于
12月 24, 2021
作者:
S
Shengliang Guan
提交者:
GitHub
12月 24, 2021
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9368 from taosdata/feature/3.0_wxy
TD-12506 implement taos_query_l
上级
50ffa8c4
217d2684
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
117 addition
and
84 deletion
+117
-84
include/libs/parser/parser.h
include/libs/parser/parser.h
+3
-1
include/libs/planner/planner.h
include/libs/planner/planner.h
+1
-1
source/client/CMakeLists.txt
source/client/CMakeLists.txt
+1
-1
source/client/inc/clientInt.h
source/client/inc/clientInt.h
+1
-0
source/client/src/clientImpl.c
source/client/src/clientImpl.c
+104
-78
source/libs/parser/src/parser.c
source/libs/parser/src/parser.c
+5
-1
source/libs/planner/src/planner.c
source/libs/planner/src/planner.c
+1
-1
source/libs/planner/test/phyPlanTests.cpp
source/libs/planner/test/phyPlanTests.cpp
+1
-1
未找到文件。
include/libs/parser/parser.h
浏览文件 @
455006cc
...
@@ -44,7 +44,9 @@ typedef struct SParseContext {
...
@@ -44,7 +44,9 @@ typedef struct SParseContext {
*/
*/
int32_t
qParseQuerySql
(
SParseContext
*
pContext
,
SQueryNode
**
pQuery
);
int32_t
qParseQuerySql
(
SParseContext
*
pContext
,
SQueryNode
**
pQuery
);
bool
qIsDclQuery
(
const
SQueryNode
*
pQuery
);
bool
qIsDdlQuery
(
const
SQueryNode
*
pQuery
);
void
qDestoryQuery
(
SQueryNode
*
pQuery
);
/**
/**
* Convert a normal sql statement to only query tags information to enable that the subscribe client can be aware quickly of the true vgroup ids that
* Convert a normal sql statement to only query tags information to enable that the subscribe client can be aware quickly of the true vgroup ids that
...
...
include/libs/planner/planner.h
浏览文件 @
455006cc
...
@@ -139,7 +139,7 @@ struct SQueryNode;
...
@@ -139,7 +139,7 @@ struct SQueryNode;
/**
/**
* Create the physical plan for the query, according to the AST.
* Create the physical plan for the query, according to the AST.
*/
*/
int32_t
qCreateQueryDag
(
const
struct
SQueryNode
*
pQueryInfo
,
struct
S
EpSet
*
pQnode
,
struct
S
QueryDag
**
pDag
);
int32_t
qCreateQueryDag
(
const
struct
SQueryNode
*
pQueryInfo
,
struct
SQueryDag
**
pDag
);
// Set datasource of this subplan, multiple calls may be made to a subplan.
// Set datasource of this subplan, multiple calls may be made to a subplan.
// @subplan subplan to be schedule
// @subplan subplan to be schedule
...
...
source/client/CMakeLists.txt
浏览文件 @
455006cc
...
@@ -8,7 +8,7 @@ target_include_directories(
...
@@ -8,7 +8,7 @@ target_include_directories(
target_link_libraries
(
target_link_libraries
(
taos
taos
INTERFACE api
INTERFACE api
PRIVATE os util common transport parser
catalog
function qcom
PRIVATE os util common transport parser
planner catalog scheduler
function qcom
)
)
ADD_SUBDIRECTORY
(
test
)
ADD_SUBDIRECTORY
(
test
)
\ No newline at end of file
source/client/inc/clientInt.h
浏览文件 @
455006cc
...
@@ -121,6 +121,7 @@ typedef struct SRequestObj {
...
@@ -121,6 +121,7 @@ typedef struct SRequestObj {
STscObj
*
pTscObj
;
STscObj
*
pTscObj
;
SQueryExecMetric
metric
;
SQueryExecMetric
metric
;
char
*
sqlstr
;
// sql string
char
*
sqlstr
;
// sql string
int32_t
sqlLen
;
SRequestSendRecvBody
body
;
SRequestSendRecvBody
body
;
int64_t
self
;
int64_t
self
;
char
*
msgBuf
;
char
*
msgBuf
;
...
...
source/client/src/clientImpl.c
浏览文件 @
455006cc
...
@@ -9,6 +9,17 @@
...
@@ -9,6 +9,17 @@
#include "tpagedfile.h"
#include "tpagedfile.h"
#include "tref.h"
#include "tref.h"
#include "parser.h"
#include "parser.h"
#include "planner.h"
#include "scheduler.h"
#define CHECK_CODE_GOTO(expr, lable) \
do { \
int32_t code = expr; \
if (TSDB_CODE_SUCCESS != code) { \
terrno = code; \
goto lable; \
} \
} while (0)
static
int32_t
initEpSetFromCfg
(
const
char
*
firstEp
,
const
char
*
secondEp
,
SCorEpSet
*
pEpSet
);
static
int32_t
initEpSetFromCfg
(
const
char
*
firstEp
,
const
char
*
secondEp
,
SCorEpSet
*
pEpSet
);
static
int32_t
buildConnectMsg
(
SRequestObj
*
pRequest
,
SRequestMsgBody
*
pMsgBody
);
static
int32_t
buildConnectMsg
(
SRequestObj
*
pRequest
,
SRequestMsgBody
*
pMsgBody
);
...
@@ -113,110 +124,125 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass,
...
@@ -113,110 +124,125 @@ TAOS *taos_connect_internal(const char *ip, const char *user, const char *pass,
return
taosConnectImpl
(
ip
,
user
,
&
secretEncrypt
[
0
],
db
,
port
,
NULL
,
NULL
,
*
pInst
);
return
taosConnectImpl
(
ip
,
user
,
&
secretEncrypt
[
0
],
db
,
port
,
NULL
,
NULL
,
*
pInst
);
}
}
static
bool
supportedQueryType
(
int32_t
type
)
{
int32_t
buildRequest
(
STscObj
*
pTscObj
,
const
char
*
sql
,
int
sqlLen
,
SRequestObj
**
pRequest
)
{
return
(
type
==
TDMT_MND_CREATE_USER
||
type
==
TDMT_MND_SHOW
||
type
==
TDMT_MND_DROP_USER
||
*
pRequest
=
createRequest
(
pTscObj
,
NULL
,
NULL
,
TSDB_SQL_SELECT
);
type
==
TDMT_MND_DROP_ACCT
||
type
==
TDMT_MND_CREATE_DB
||
type
==
TDMT_MND_CREATE_ACCT
||
if
(
*
pRequest
==
NULL
)
{
type
==
TDMT_MND_CREATE_TABLE
||
type
==
TDMT_MND_CREATE_STB
||
type
==
TDMT_MND_USE_DB
||
type
==
TDMT_MND_DROP_DB
||
type
==
TDMT_MND_DROP_STB
);
}
TAOS_RES
*
taos_query_l
(
TAOS
*
taos
,
const
char
*
sql
,
int
sqlLen
)
{
STscObj
*
pTscObj
=
(
STscObj
*
)
taos
;
if
(
sqlLen
>
(
size_t
)
tsMaxSQLStringLen
)
{
tscError
(
"sql string exceeds max length:%d"
,
tsMaxSQLStringLen
);
terrno
=
TSDB_CODE_TSC_EXCEED_SQL_LIMIT
;
return
NULL
;
}
nPrintTsc
(
"%s"
,
sql
)
SRequestObj
*
pRequest
=
createRequest
(
pTscObj
,
NULL
,
NULL
,
TSDB_SQL_SELECT
);
if
(
pRequest
==
NULL
)
{
tscError
(
"failed to malloc sqlObj"
);
tscError
(
"failed to malloc sqlObj"
);
terrno
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
return
NULL
;
}
}
pRequest
->
sqlstr
=
malloc
(
sqlLen
+
1
);
(
*
pRequest
)
->
sqlstr
=
malloc
(
sqlLen
+
1
);
if
(
pRequest
->
sqlstr
==
NULL
)
{
if
((
*
pRequest
)
->
sqlstr
==
NULL
)
{
tscError
(
"0x%"
PRIx64
" failed to prepare sql string buffer"
,
pRequest
->
self
);
tscError
(
"0x%"
PRIx64
" failed to prepare sql string buffer"
,
(
*
pRequest
)
->
self
);
(
*
pRequest
)
->
msgBuf
=
strdup
(
"failed to prepare sql string buffer"
);
pRequest
->
msgBuf
=
strdup
(
"failed to prepare sql string buffer"
);
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
terrno
=
pRequest
->
code
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
return
pRequest
;
}
}
strntolower
(
pRequest
->
sqlstr
,
sql
,
(
int32_t
)
sqlLen
);
strntolower
((
*
pRequest
)
->
sqlstr
,
sql
,
(
int32_t
)
sqlLen
);
pRequest
->
sqlstr
[
sqlLen
]
=
0
;
(
*
pRequest
)
->
sqlstr
[
sqlLen
]
=
0
;
(
*
pRequest
)
->
sqlLen
=
sqlLen
;
tscDebugL
(
"0x%"
PRIx64
" SQL: %s"
,
pRequest
->
requestId
,
pRequest
->
sqlstr
);
tscDebugL
(
"0x%"
PRIx64
" SQL: %s"
,
(
*
pRequest
)
->
requestId
,
(
*
pRequest
)
->
sqlstr
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
parseSql
(
SRequestObj
*
pRequest
,
SQueryNode
**
pQuery
)
{
SParseContext
cxt
=
{
SParseContext
cxt
=
{
.
ctx
=
{.
requestId
=
pRequest
->
requestId
,
.
acctId
=
pTscObj
->
acctId
,
.
db
=
getConnectionDB
(
pTscObj
)},
.
ctx
=
{.
requestId
=
pRequest
->
requestId
,
.
acctId
=
pRequest
->
pTscObj
->
acctId
,
.
db
=
getConnectionDB
(
pRequest
->
pTscObj
)},
.
pSql
=
pRequest
->
sqlstr
,
.
pSql
=
pRequest
->
sqlstr
,
.
sqlLen
=
sqlLen
,
.
sqlLen
=
pRequest
->
sqlLen
,
.
pMsg
=
pRequest
->
msgBuf
,
.
pMsg
=
pRequest
->
msgBuf
,
.
msgLen
=
ERROR_MSG_BUF_DEFAULT_SIZE
.
msgLen
=
ERROR_MSG_BUF_DEFAULT_SIZE
};
};
int32_t
code
=
qParseQuerySql
(
&
cxt
,
pQuery
);
tfree
(
cxt
.
ctx
.
db
);
return
code
;
}
SQueryNode
*
pQuery
=
NULL
;
int32_t
execDdlQuery
(
SRequestObj
*
pRequest
,
SQueryNode
*
pQuery
)
{
int32_t
code
=
qParseQuerySql
(
&
cxt
,
&
pQuery
);
SDclStmtInfo
*
pDcl
=
(
SDclStmtInfo
*
)
pQuery
;
if
(
qIsDclQuery
(
pQuery
))
{
pRequest
->
type
=
pDcl
->
msgType
;
SDclStmtInfo
*
pDcl
=
(
SDclStmtInfo
*
)
pQuery
;
pRequest
->
body
.
requestMsg
=
(
SReqMsgInfo
){.
pMsg
=
pDcl
->
pMsg
,
.
len
=
pDcl
->
msgLen
};
pRequest
->
type
=
pDcl
->
msgType
;
pRequest
->
body
.
requestMsg
=
(
SReqMsgInfo
){.
pMsg
=
pDcl
->
pMsg
,
.
len
=
pDcl
->
msgLen
};
SRequestMsgBody
body
=
buildRequestMsgImpl
(
pRequest
);
SRequestMsgBody
body
=
buildRequestMsgImpl
(
pRequest
);
SEpSet
*
pEpSet
=
&
pTscObj
->
pAppInfo
->
mgmtEp
.
epSet
;
SEpSet
*
pEpSet
=
&
pRequest
->
pTscObj
->
pAppInfo
->
mgmtEp
.
epSet
;
if
(
pDcl
->
msgType
==
TDMT_MND_CREATE_TABLE
)
{
if
(
pDcl
->
msgType
==
TDMT_MND_CREATE_TABLE
)
{
struct
SCatalog
*
pCatalog
=
NULL
;
struct
SCatalog
*
pCatalog
=
NULL
;
char
buf
[
12
]
=
{
0
};
char
buf
[
12
]
=
{
0
};
sprintf
(
buf
,
"%d"
,
pTscObj
->
pAppInfo
->
clusterId
);
sprintf
(
buf
,
"%d"
,
pRequest
->
pTscObj
->
pAppInfo
->
clusterId
);
code
=
catalogGetHandle
(
buf
,
&
pCatalog
);
int32_t
code
=
catalogGetHandle
(
buf
,
&
pCatalog
);
if
(
code
!=
0
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
pRequest
->
code
=
code
;
return
code
;
return
pRequest
;
}
}
SCreateTableMsg
*
pMsg
=
body
.
msgInfo
.
pMsg
;
SCreateTableMsg
*
pMsg
=
body
.
msgInfo
.
pMsg
;
SName
t
=
{
0
};
SName
t
=
{
0
};
tNameFromString
(
&
t
,
pMsg
->
name
,
T_NAME_ACCT
|
T_NAME_DB
|
T_NAME_TABLE
);
tNameFromString
(
&
t
,
pMsg
->
name
,
T_NAME_ACCT
|
T_NAME_DB
|
T_NAME_TABLE
);
char
db
[
TSDB_DB_NAME_LEN
+
TS_PATH_DELIMITER_LEN
+
TSDB_ACCT_ID_LEN
]
=
{
0
};
char
db
[
TSDB_DB_NAME_LEN
+
TS_PATH_DELIMITER_LEN
+
TSDB_ACCT_ID_LEN
]
=
{
0
};
tNameGetFullDbName
(
&
t
,
db
);
tNameGetFullDbName
(
&
t
,
db
);
SVgroupInfo
info
=
{
0
};
SVgroupInfo
info
=
{
0
};
catalogGetTableHashVgroup
(
pCatalog
,
pTscObj
->
pTransporter
,
pEpSet
,
db
,
tNameGetTableName
(
&
t
),
&
info
);
catalogGetTableHashVgroup
(
pCatalog
,
pRequest
->
pTscObj
->
pTransporter
,
pEpSet
,
db
,
tNameGetTableName
(
&
t
),
&
info
);
int64_t
transporterId
=
0
;
int64_t
transporterId
=
0
;
SEpSet
ep
=
{
0
};
SEpSet
ep
=
{
0
};
ep
.
inUse
=
info
.
inUse
;
ep
.
inUse
=
info
.
inUse
;
ep
.
numOfEps
=
info
.
numOfEps
;
ep
.
numOfEps
=
info
.
numOfEps
;
for
(
int32_t
i
=
0
;
i
<
ep
.
numOfEps
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
ep
.
numOfEps
;
++
i
)
{
ep
.
port
[
i
]
=
info
.
epAddr
[
i
].
port
;
ep
.
port
[
i
]
=
info
.
epAddr
[
i
].
port
;
tstrncpy
(
ep
.
fqdn
[
i
],
info
.
epAddr
[
i
].
fqdn
,
tListLen
(
ep
.
fqdn
[
i
]));
tstrncpy
(
ep
.
fqdn
[
i
],
info
.
epAddr
[
i
].
fqdn
,
tListLen
(
ep
.
fqdn
[
i
]));
}
sendMsgToServer
(
pTscObj
->
pTransporter
,
&
ep
,
&
body
,
&
transporterId
);
}
else
{
int64_t
transporterId
=
0
;
sendMsgToServer
(
pTscObj
->
pTransporter
,
pEpSet
,
&
body
,
&
transporterId
);
}
}
tsem_wait
(
&
pRequest
->
body
.
rspSem
);
sendMsgToServer
(
pRequest
->
pTscObj
->
pTransporter
,
&
ep
,
&
body
,
&
transporterId
);
destroyRequestMsgBody
(
&
body
);
}
else
{
int64_t
transporterId
=
0
;
sendMsgToServer
(
pRequest
->
pTscObj
->
pTransporter
,
pEpSet
,
&
body
,
&
transporterId
);
}
}
tfree
(
cxt
.
ctx
.
db
);
tsem_wait
(
&
pRequest
->
body
.
rspSem
);
destroyRequestMsgBody
(
&
body
);
return
TSDB_CODE_SUCCESS
;
}
int32_t
scheduleQuery
(
SRequestObj
*
pRequest
,
SQueryDag
*
pDag
,
void
**
pJob
)
{
return
scheduleExecJob
(
pRequest
->
pTscObj
->
pTransporter
,
NULL
/*todo appInfo.xxx*/
,
pDag
,
pJob
);
}
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
TAOS_RES
*
taos_query_l
(
TAOS
*
taos
,
const
char
*
sql
,
int
sqlLen
)
{
pRequest
->
code
=
code
;
STscObj
*
pTscObj
=
(
STscObj
*
)
taos
;
return
pRequest
;
if
(
sqlLen
>
(
size_t
)
tsMaxSQLStringLen
)
{
tscError
(
"sql string exceeds max length:%d"
,
tsMaxSQLStringLen
);
terrno
=
TSDB_CODE_TSC_EXCEED_SQL_LIMIT
;
return
NULL
;
}
}
nPrintTsc
(
"%s"
,
sql
)
SRequestObj
*
pRequest
=
NULL
;
SQueryNode
*
pQuery
=
NULL
;
SQueryDag
*
pDag
=
NULL
;
void
*
pJob
=
NULL
;
terrno
=
TSDB_CODE_SUCCESS
;
CHECK_CODE_GOTO
(
buildRequest
(
pTscObj
,
sql
,
sqlLen
,
&
pRequest
),
_return
);
CHECK_CODE_GOTO
(
parseSql
(
pRequest
,
&
pQuery
),
_return
);
if
(
qIsDdlQuery
(
pQuery
))
{
CHECK_CODE_GOTO
(
execDdlQuery
(
pRequest
,
pQuery
),
_return
);
goto
_return
;
}
CHECK_CODE_GOTO
(
qCreateQueryDag
(
pQuery
,
&
pDag
),
_return
);
CHECK_CODE_GOTO
(
scheduleQuery
(
pRequest
,
pDag
,
&
pJob
),
_return
);
_return:
qDestoryQuery
(
pQuery
);
qDestroyQueryDag
(
pDag
);
if
(
NULL
!=
pRequest
&&
TSDB_CODE_SUCCESS
!=
terrno
)
{
pRequest
->
code
=
terrno
;
}
return
pRequest
;
return
pRequest
;
}
}
...
...
source/libs/parser/src/parser.c
浏览文件 @
455006cc
...
@@ -31,7 +31,7 @@ bool isInsertSql(const char* pStr, size_t length) {
...
@@ -31,7 +31,7 @@ bool isInsertSql(const char* pStr, size_t length) {
}
while
(
1
);
}
while
(
1
);
}
}
bool
qIsD
c
lQuery
(
const
SQueryNode
*
pQuery
)
{
bool
qIsD
d
lQuery
(
const
SQueryNode
*
pQuery
)
{
return
TSDB_SQL_INSERT
!=
pQuery
->
type
&&
TSDB_SQL_SELECT
!=
pQuery
->
type
;
return
TSDB_SQL_INSERT
!=
pQuery
->
type
&&
TSDB_SQL_SELECT
!=
pQuery
->
type
;
}
}
...
@@ -227,3 +227,7 @@ void qParserClearupMetaRequestInfo(SCatalogReq* pMetaReq) {
...
@@ -227,3 +227,7 @@ void qParserClearupMetaRequestInfo(SCatalogReq* pMetaReq) {
taosArrayDestroy
(
pMetaReq
->
pTableName
);
taosArrayDestroy
(
pMetaReq
->
pTableName
);
taosArrayDestroy
(
pMetaReq
->
pUdf
);
taosArrayDestroy
(
pMetaReq
->
pUdf
);
}
}
void
qDestoryQuery
(
SQueryNode
*
pQuery
)
{
// todo
}
source/libs/planner/src/planner.c
浏览文件 @
455006cc
...
@@ -24,7 +24,7 @@ void qDestroyQueryDag(struct SQueryDag* pDag) {
...
@@ -24,7 +24,7 @@ void qDestroyQueryDag(struct SQueryDag* pDag) {
// todo
// todo
}
}
int32_t
qCreateQueryDag
(
const
struct
SQueryNode
*
pNode
,
struct
S
EpSet
*
pEpSet
,
struct
S
QueryDag
**
pDag
)
{
int32_t
qCreateQueryDag
(
const
struct
SQueryNode
*
pNode
,
struct
SQueryDag
**
pDag
)
{
SQueryPlanNode
*
logicPlan
;
SQueryPlanNode
*
logicPlan
;
int32_t
code
=
createQueryPlan
(
pNode
,
&
logicPlan
);
int32_t
code
=
createQueryPlan
(
pNode
,
&
logicPlan
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
...
...
source/libs/planner/test/phyPlanTests.cpp
浏览文件 @
455006cc
...
@@ -60,7 +60,7 @@ protected:
...
@@ -60,7 +60,7 @@ protected:
return
code
;
return
code
;
}
}
SQueryDag
*
dag
=
nullptr
;
SQueryDag
*
dag
=
nullptr
;
code
=
qCreateQueryDag
(
query
,
nullptr
,
&
dag
);
code
=
qCreateQueryDag
(
query
,
&
dag
);
dag_
.
reset
(
dag
);
dag_
.
reset
(
dag
);
return
code
;
return
code
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录