parser.h 5.6 KB
Newer Older
H
refact  
Hongze Cheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * 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

D
stmt  
dapan1121 已提交
23
#include "query.h"
X
Xiaoyu Wang 已提交
24
#include "querynodes.h"
X
Xiaoyu Wang 已提交
25

26 27 28
struct SCatalogReq;
struct SMetaData;

D
stmt  
dapan1121 已提交
29 30
typedef struct SStmtCallback {
  TAOS_STMT* pStmt;
D
stmt  
dapan1121 已提交
31
  int32_t (*getTbNameFn)(TAOS_STMT*, char**);
32
  int32_t (*setInfoFn)(TAOS_STMT*, STableMeta*, void*, SName*, bool, SHashObj*, SHashObj*, const char*);
D
stmt  
dapan1121 已提交
33
  int32_t (*getExecInfoFn)(TAOS_STMT*, SHashObj**, SHashObj**);
D
stmt  
dapan1121 已提交
34 35
} SStmtCallback;

36 37 38 39 40 41 42
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;

X
Xiaoyu Wang 已提交
43 44
typedef struct SParseContext {
  uint64_t         requestId;
D
dapan1121 已提交
45
  int64_t          requestRid;
X
Xiaoyu Wang 已提交
46
  int32_t          acctId;
X
Xiaoyu Wang 已提交
47
  const char*      db;
X
Xiaoyu Wang 已提交
48
  bool             topicQuery;
X
Xiaoyu Wang 已提交
49
  void*            pTransporter;
X
Xiaoyu Wang 已提交
50
  SEpSet           mgmtEpSet;
X
Xiaoyu Wang 已提交
51 52 53 54 55 56 57 58
  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;
59
  bool             enableSysInfo;
60
  bool             async;
D
dapan1121 已提交
61 62
  const char*      svrVer;
  bool             nodeOffline;
X
Xiaoyu Wang 已提交
63 64
  SArray*          pTableMetaPos;    // sql table pos => catalog data pos
  SArray*          pTableVgroupPos;  // sql table pos => catalog data pos
65
  int64_t          allocatorId;
X
Xiaoyu Wang 已提交
66 67
} SParseContext;

X
Xiaoyu Wang 已提交
68
int32_t qParseSql(SParseContext* pCxt, SQuery** pQuery);
69
bool    qIsInsertValuesSql(const char* pStr, size_t length);
X
Xiaoyu Wang 已提交
70

71
// for async mode
72 73 74
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);
X
Xiaoyu Wang 已提交
75 76
int32_t qContinueParseSql(SParseContext* pCxt, struct SCatalogReq* pCatalogReq, const struct SMetaData* pMetaData,
                          SQuery* pQuery);
77

78 79
void qDestroyParseContext(SParseContext* pCxt);

X
Xiaoyu Wang 已提交
80 81
void qDestroyQuery(SQuery* pQueryNode);

H
Haojun Liao 已提交
82
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema);
L
Liu Jicong 已提交
83
int32_t qSetSTableIdForRsma(SNode* pStmt, int64_t uid);
X
Xiaoyu Wang 已提交
84
void    qCleanupKeywordsTable();
H
Haojun Liao 已提交
85

X
Xiaoyu Wang 已提交
86
int32_t     qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash);
D
dapan1121 已提交
87 88
int32_t     qResetStmtDataBlock(STableDataCxt* block, bool keepBuf);
int32_t     qCloneStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, bool reset);
X
Xiaoyu Wang 已提交
89 90
int32_t     qRebuildStmtDataBlock(STableDataCxt** pDst, STableDataCxt* pSrc, uint64_t uid, uint64_t suid, int32_t vgId,
                                  bool rebuildCreateTb);
D
dapan1121 已提交
91 92
void        qDestroyStmtDataBlock(STableDataCxt* pBlock);
STableMeta* qGetTableMetaInDataBlock(STableDataCxt* pDataBlock);
X
Xiaoyu Wang 已提交
93
int32_t     qCloneCurrentTbData(STableDataCxt* pDataBlock, SSubmitTbData** pData);
wmmhello's avatar
wmmhello 已提交
94

95
int32_t qStmtBindParams(SQuery* pQuery, TAOS_MULTI_BIND* pParams, int32_t colIdx);
X
Xiaoyu Wang 已提交
96
int32_t qStmtParseQuerySql(SParseContext* pCxt, SQuery* pQuery);
X
Xiaoyu Wang 已提交
97 98 99
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);
D
dapan1121 已提交
100 101
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);
X
Xiaoyu Wang 已提交
102 103
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, const char* sTableName, char* tName,
                           TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen);
wmmhello's avatar
wmmhello 已提交
104
void    destroyBoundColumnInfo(void* pBoundInfo);
X
Xiaoyu Wang 已提交
105 106
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
                     int32_t msgBufLen);
D
stmt  
dapan1121 已提交
107

X
Xiaoyu Wang 已提交
108
void qDestroyBoundColInfo(void* pInfo);
109

X
Xiaoyu Wang 已提交
110 111 112
SQuery*        smlInitHandle();
int32_t        smlBuildRow(STableDataCxt* pTableCxt);
int32_t        smlBuildCol(STableDataCxt* pTableCxt, SSchema* schema, void* kv, int32_t index);
113 114
STableDataCxt* smlInitTableDataCtx(SQuery* query, STableMeta* pTableMeta);

X
Xiaoyu Wang 已提交
115 116 117
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, int16_t msgBufLen);
wmmhello's avatar
wmmhello 已提交
118
int32_t smlBuildOutput(SQuery* handle, SHashObj* pVgHash);
119
int     rawBlockBindData(SQuery *query, STableMeta* pTableMeta, void* data, SVCreateTbReq* pCreateTb, TAOS_FIELD *fields, int numFields, bool needChangeLength);
wmmhello's avatar
wmmhello 已提交
120

wmmhello's avatar
wmmhello 已提交
121 122 123
int32_t rewriteToVnodeModifyOpStmt(SQuery* pQuery, SArray* pBufArray);
SArray* serializeVgroupsCreateTableBatch(SHashObj* pVgroupHashmap);
SArray* serializeVgroupsDropTableBatch(SHashObj* pVgroupHashmap);
H
refact  
Hongze Cheng 已提交
124 125 126 127
#ifdef __cplusplus
}
#endif

L
Liu Jicong 已提交
128
#endif /*_TD_PARSER_H_*/