TDengine/include/libs/parser/parser.h

116 lines
4 KiB
C
Raw Normal View History

2021-09-23 07:50:12 +00:00
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* 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/>.
*/
#ifndef _TD_PARSER_H_
#define _TD_PARSER_H_
#ifdef __cplusplus
extern "C" {
#endif
2022-04-16 11:41:18 +00:00
#include "query.h"
2022-05-05 06:49:00 +00:00
#include "querynodes.h"
2022-02-28 09:02:43 +00:00
2022-04-14 12:14:52 +00:00
typedef struct SStmtCallback {
TAOS_STMT* pStmt;
2022-04-16 07:59:19 +00:00
int32_t (*getTbNameFn)(TAOS_STMT*, char**);
int32_t (*setBindInfoFn)(TAOS_STMT*, STableMeta*, void*);
int32_t (*setExecInfoFn)(TAOS_STMT*, SHashObj*, SHashObj*);
int32_t (*getExecInfoFn)(TAOS_STMT*, SHashObj**, SHashObj**);
2022-04-14 12:14:52 +00:00
} SStmtCallback;
2022-02-28 09:02:43 +00:00
typedef struct SParseContext {
uint64_t requestId;
int32_t acctId;
2022-05-05 06:49:00 +00:00
const char* db;
2022-03-19 07:02:31 +00:00
bool topicQuery;
2022-05-05 06:49:00 +00:00
void* pTransporter;
2022-02-28 09:02:43 +00:00
SEpSet mgmtEpSet;
2022-05-05 06:49:00 +00:00
const char* pSql; // sql string
size_t sqlLen; // length of the sql string
char* pMsg; // extended error message if exists to help identifying the problem in sql statement.
int32_t msgLen; // max length of the msg
struct SCatalog* pCatalog;
SStmtCallback* pStmtCb;
const char* pUser;
bool isSuperUser;
2022-02-28 09:02:43 +00:00
} SParseContext;
typedef struct SCmdMsgInfo {
int16_t msgType;
2022-05-05 06:49:00 +00:00
SEpSet epSet;
void* pMsg;
int32_t msgLen;
2022-05-05 06:49:00 +00:00
void* pExtension; // todo remove it soon
} SCmdMsgInfo;
2022-04-09 02:09:17 +00:00
typedef enum EQueryExecMode {
QUERY_EXEC_MODE_LOCAL = 1,
QUERY_EXEC_MODE_RPC,
QUERY_EXEC_MODE_SCHEDULE,
QUERY_EXEC_MODE_EMPTY_RESULT
} EQueryExecMode;
2022-02-28 09:02:43 +00:00
typedef struct SQuery {
2022-04-09 02:09:17 +00:00
EQueryExecMode execMode;
2022-05-05 06:49:00 +00:00
bool haveResultSet;
SNode* pRoot;
int32_t numOfResCols;
SSchema* pResSchema;
int8_t precision;
SCmdMsgInfo* pCmdMsg;
int32_t msgType;
SArray* pDbList;
SArray* pTableList;
bool showRewrite;
int32_t placeholderNum;
2022-02-28 09:02:43 +00:00
} SQuery;
int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery);
2022-05-05 06:49:00 +00:00
bool isInsertSql(const char* pStr, size_t length);
2022-02-28 09:02:43 +00:00
void qDestroyQuery(SQuery* pQueryNode);
2022-03-25 04:46:26 +00:00
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema);
2022-04-18 02:19:15 +00:00
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash);
2022-04-18 11:08:27 +00:00
int32_t qResetStmtDataBlock(void* block, bool keepBuf);
2022-04-18 02:19:15 +00:00
int32_t qCloneStmtDataBlock(void** pDst, void* pSrc);
void qFreeStmtDataBlock(void* pDataBlock);
int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc);
void qDestroyStmtDataBlock(void* pBlock);
2022-05-06 03:28:34 +00:00
2022-05-05 06:49:00 +00:00
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);
int32_t qBuildStmtColFields(void* pDataBlock, int32_t* fieldNum, TAOS_FIELD** fields);
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD** fields);
2022-05-06 03:52:03 +00:00
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, char* tName, TAOS_MULTI_BIND* bind,
2022-05-05 06:49:00 +00:00
char* msgBuf, int32_t msgBufLen);
2022-04-29 09:39:33 +00:00
void destroyBoundColumnInfo(void* pBoundInfo);
2022-05-05 06:49:00 +00:00
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
int32_t msgBufLen);
2022-04-18 02:19:15 +00:00
2022-04-29 09:39:33 +00:00
void* smlInitHandle(SQuery *pQuery);
void smlDestroyHandle(void *pHandle);
int32_t smlBindData(void *handle, SArray *tags, SArray *colsFormat, SArray *colsSchema, SArray *cols, bool format, STableMeta *pTableMeta, char *tableName, char *msgBuf, int16_t msgBufLen);
2022-04-27 13:29:25 +00:00
int32_t smlBuildOutput(void* handle, SHashObj* pVgHash);
2022-04-18 02:19:15 +00:00
2021-09-23 07:50:12 +00:00
#ifdef __cplusplus
}
#endif
2021-12-28 09:01:09 +00:00
#endif /*_TD_PARSER_H_*/