TDengine/include/libs/parser/parser.h

165 lines
6.6 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"
2023-10-08 10:36:06 +00:00
#include "catalog.h"
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 (*setInfoFn)(TAOS_STMT*, STableMeta*, void*, SName*, bool, SHashObj*, SHashObj*, const char*);
2022-04-16 07:59:19 +00:00
int32_t (*getExecInfoFn)(TAOS_STMT*, SHashObj**, SHashObj**);
2022-04-14 12:14:52 +00:00
} SStmtCallback;
2023-10-08 10:36:06 +00:00
typedef enum {
PARSE_SQL_RES_QUERY = 1,
PARSE_SQL_RES_SCHEMA,
} SParseResType;
typedef struct SParseSchemaRes {
int8_t precision;
int32_t numOfCols;
SSchema* pSchema;
} SParseSchemaRes;
typedef struct SParseQueryRes {
SNode* pQuery;
SCatalogReq* pCatalogReq;
SMetaData meta;
} SParseQueryRes;
typedef struct SParseSqlRes {
SParseResType resType;
union {
SParseSchemaRes schemaRes;
SParseQueryRes queryRes;
};
} SParseSqlRes;
2023-10-24 03:29:04 +00:00
typedef int32_t (*parseSqlFn)(void*, const char*, const char*, bool, const char*, SParseSqlRes*);
2023-09-19 06:19:54 +00:00
typedef struct SParseCsvCxt {
TdFilePtr fp; // last parsed file
int32_t tableNo; // last parsed table
SName tableName; // last parsed table
const char* pLastSqlPos; // the location of the last parsed sql
} SParseCsvCxt;
2022-02-28 09:02:43 +00:00
typedef struct SParseContext {
uint64_t requestId;
2022-06-10 09:07:24 +00:00
int64_t requestRid;
2022-02-28 09:02:43 +00:00
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;
2023-10-20 00:41:49 +00:00
const char* pEffectiveUser;
2023-10-08 10:36:06 +00:00
bool parseOnly;
2022-05-05 06:49:00 +00:00
bool isSuperUser;
2022-08-24 09:36:10 +00:00
bool enableSysInfo;
bool async;
bool hasInvisibleCol;
2022-06-24 07:18:40 +00:00
const char* svrVer;
bool nodeOffline;
2022-08-10 09:47:28 +00:00
SArray* pTableMetaPos; // sql table pos => catalog data pos
SArray* pTableVgroupPos; // sql table pos => catalog data pos
int64_t allocatorId;
2023-10-08 10:36:06 +00:00
parseSqlFn parseSqlFp;
void* parseSqlParam;
int8_t biMode;
2023-10-27 03:36:17 +00:00
SArray* pSubMetaList;
2022-02-28 09:02:43 +00:00
} SParseContext;
2022-05-12 12:33:52 +00:00
int32_t qParseSql(SParseContext* pCxt, SQuery** pQuery);
2022-07-05 13:12:10 +00:00
bool qIsInsertValuesSql(const char* pStr, size_t length);
2022-02-28 09:02:43 +00:00
// for async mode
int32_t qParseSqlSyntax(SParseContext* pCxt, SQuery** pQuery, struct SCatalogReq* pCatalogReq);
int32_t qAnalyseSqlSemantic(SParseContext* pCxt, const struct SCatalogReq* pCatalogReq,
const struct SMetaData* pMetaData, SQuery* pQuery);
2022-11-04 07:21:38 +00:00
int32_t qContinueParseSql(SParseContext* pCxt, struct SCatalogReq* pCatalogReq, const struct SMetaData* pMetaData,
SQuery* pQuery);
int32_t qContinueParsePostQuery(SParseContext* pCxt, SQuery* pQuery, SSDataBlock* pBlock);
void qDestroyParseContext(SParseContext* pCxt);
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-06-11 02:53:52 +00:00
int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid);
2022-06-14 07:43:56 +00:00
void qCleanupKeywordsTable();
2022-03-25 04:46:26 +00:00
2022-05-12 12:33:52 +00:00
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash);
2022-12-03 06:56:51 +00:00
int32_t qResetStmtDataBlock(STableDataCxt* block, bool keepBuf);
int32_t qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool reset);
2023-02-03 09:13:11 +00:00
int32_t qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId,
bool rebuildCreateTb);
2022-12-03 06:56:51 +00:00
void qDestroyStmtDataBlock(STableDataCxt* pBlock);
STableMeta* qGetTableMetaInDataBlock(STableDataCxt* pDataBlock);
2023-02-03 09:13:11 +00:00
int32_t qCloneCurrentTbData(STableDataCxt* pDataBlock, SSubmitTbData** pData);
2022-05-06 03:28:34 +00:00
int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx);
2022-05-12 12:33:52 +00:00
int32_t qStmtParseQuerySql(SParseContext* pCxt, SQuery* pQuery);
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);
2022-05-31 13:03:47 +00:00
int32_t qBuildStmtColFields(void* pDataBlock, int32_t* fieldNum, TAOS_FIELD_E** fields);
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD_E** fields);
2022-08-10 09:47:28 +00:00
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName,
TAOS_MULTI_BIND* bind, 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
2023-02-03 09:13:11 +00:00
void qDestroyBoundColInfo(void* pInfo);
2023-02-03 09:13:11 +00:00
SQuery* smlInitHandle();
int32_t smlBuildRow(STableDataCxt* pTableCxt);
int32_t smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* kv, int32_t index);
STableDataCxt* smlInitTableDataCtx(SQuery* query, STableMeta* pTableMeta);
2023-08-25 08:32:01 +00:00
void clearColValArraySml(SArray* pCols);
2023-02-03 09:13:11 +00:00
int32_t smlBindData(SQuery* handle, bool dataFormat, SArray* tags, SArray* colsSchema, SArray* cols,
STableMeta* pTableMeta, char* tableName, const char* sTableName, int32_t sTableNameLen, int32_t ttl,
char* msgBuf, int32_t msgBufLen);
2022-12-03 06:44:47 +00:00
int32_t smlBuildOutput(SQuery* handle, SHashObj* pVgHash);
2024-01-19 07:28:23 +00:00
int rawBlockBindData(SQuery *query, STableMeta* pTableMeta, void* data, SVCreateTbReq** pCreateTb, TAOS_FIELD *fields, int numFields, bool needChangeLength);
2022-12-03 14:20:16 +00:00
2022-07-08 10:37:47 +00:00
int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray);
SArray* serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap);
SArray* serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap);
2023-10-27 03:36:17 +00:00
void destoryCatalogReq(SCatalogReq *pCatalogReq);
2021-09-23 07:50:12 +00:00
#ifdef __cplusplus
}
#endif
2021-12-28 09:01:09 +00:00
#endif /*_TD_PARSER_H_*/