parser.h 4.1 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

D
stmt  
dapan1121 已提交
26 27
typedef struct SStmtCallback {
  TAOS_STMT* pStmt;
D
stmt  
dapan1121 已提交
28
  int32_t (*getTbNameFn)(TAOS_STMT*, char**);
D
dapan 已提交
29
  int32_t (*setInfoFn)(TAOS_STMT*, STableMeta*, void*, char*, bool, SHashObj*, SHashObj*);
D
stmt  
dapan1121 已提交
30
  int32_t (*getExecInfoFn)(TAOS_STMT*, SHashObj**, SHashObj**);
D
stmt  
dapan1121 已提交
31 32
} SStmtCallback;

X
Xiaoyu Wang 已提交
33 34 35
typedef struct SParseContext {
  uint64_t         requestId;
  int32_t          acctId;
X
Xiaoyu Wang 已提交
36
  const char*      db;
X
Xiaoyu Wang 已提交
37
  bool             topicQuery;
X
Xiaoyu Wang 已提交
38
  void*            pTransporter;
X
Xiaoyu Wang 已提交
39
  SEpSet           mgmtEpSet;
X
Xiaoyu Wang 已提交
40 41 42 43 44 45 46 47
  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;
X
Xiaoyu Wang 已提交
48 49
} SParseContext;

50 51
typedef struct SCmdMsgInfo {
  int16_t msgType;
X
Xiaoyu Wang 已提交
52 53
  SEpSet  epSet;
  void*   pMsg;
54
  int32_t msgLen;
X
Xiaoyu Wang 已提交
55
  void*   pExtension;  // todo remove it soon
56 57
} SCmdMsgInfo;

X
Xiaoyu Wang 已提交
58 59 60 61 62 63 64
typedef enum EQueryExecMode {
  QUERY_EXEC_MODE_LOCAL = 1,
  QUERY_EXEC_MODE_RPC,
  QUERY_EXEC_MODE_SCHEDULE,
  QUERY_EXEC_MODE_EMPTY_RESULT
} EQueryExecMode;

X
Xiaoyu Wang 已提交
65
typedef struct SQuery {
X
Xiaoyu Wang 已提交
66
  EQueryExecMode execMode;
X
Xiaoyu Wang 已提交
67 68 69 70 71 72 73 74 75 76 77
  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;
X
Xiaoyu Wang 已提交
78 79 80
} SQuery;

int32_t qParseQuerySql(SParseContext* pCxt, SQuery** pQuery);
X
Xiaoyu Wang 已提交
81
bool    isInsertSql(const char* pStr, size_t length);
X
Xiaoyu Wang 已提交
82 83 84

void qDestroyQuery(SQuery* pQueryNode);

H
Haojun Liao 已提交
85 86
int32_t qExtractResultSchema(const SNode* pRoot, int32_t* numOfCols, SSchema** pSchema);

D
stmt  
dapan1121 已提交
87
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash);
D
stmt  
dapan1121 已提交
88
int32_t qResetStmtDataBlock(void* block, bool keepBuf);
D
stmt  
dapan1121 已提交
89 90
int32_t qCloneStmtDataBlock(void** pDst, void* pSrc);
void    qFreeStmtDataBlock(void* pDataBlock);
D
dapan 已提交
91
int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc, uint64_t uid);
D
stmt  
dapan1121 已提交
92
void    qDestroyStmtDataBlock(void* pBlock);
D
dapan 已提交
93
STableMeta *qGetTableMetaInDataBlock(void* pDataBlock);
wmmhello's avatar
wmmhello 已提交
94

X
Xiaoyu Wang 已提交
95 96 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);
int32_t qBuildStmtColFields(void* pDataBlock, int32_t* fieldNum, TAOS_FIELD** fields);
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD** fields);
wmmhello's avatar
wmmhello 已提交
100
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, char* tName, TAOS_MULTI_BIND* bind,
X
Xiaoyu Wang 已提交
101
                           char* msgBuf, int32_t msgBufLen);
wmmhello's avatar
wmmhello 已提交
102
void    destroyBoundColumnInfo(void* pBoundInfo);
X
Xiaoyu Wang 已提交
103 104
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
                     int32_t msgBufLen);
D
stmt  
dapan1121 已提交
105

wmmhello's avatar
wmmhello 已提交
106 107
void*   smlInitHandle(SQuery *pQuery);
void    smlDestroyHandle(void *pHandle);
108
int32_t smlBindData(void *handle, SArray *tags, SArray *colsFormat, SArray *colsSchema, SArray *cols, bool format, STableMeta *pTableMeta, char *tableName, char *msgBuf, int16_t msgBufLen);
wmmhello's avatar
wmmhello 已提交
109
int32_t smlBuildOutput(void* handle, SHashObj* pVgHash);
D
stmt  
dapan1121 已提交
110

H
refact  
Hongze Cheng 已提交
111 112 113 114
#ifdef __cplusplus
}
#endif

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