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

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

D
stmt  
dapan1121 已提交
26 27
typedef struct SStmtCallback {
  TAOS_STMT* pStmt;
D
stmt  
dapan1121 已提交
28 29 30 31
  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**);
D
stmt  
dapan1121 已提交
32 33
} SStmtCallback;

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

49 50 51
typedef struct SCmdMsgInfo {
  int16_t msgType;
  SEpSet epSet;
52
  void* pMsg;
53
  int32_t msgLen;
54
  void* pExtension;  // todo remove it soon
55 56
} SCmdMsgInfo;

X
Xiaoyu Wang 已提交
57 58 59 60 61 62 63
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 已提交
64
typedef struct SQuery {
X
Xiaoyu Wang 已提交
65
  EQueryExecMode execMode;
66
  bool haveResultSet;
X
Xiaoyu Wang 已提交
67 68 69
  SNode* pRoot;
  int32_t numOfResCols;
  SSchema* pResSchema;
70
  int8_t   precision;
71
  SCmdMsgInfo* pCmdMsg;
72
  int32_t msgType;
X
Xiaoyu Wang 已提交
73 74
  SArray* pDbList;
  SArray* pTableList;
D
dapan1121 已提交
75
  bool showRewrite;
D
dapan1121 已提交
76
  int32_t placeholderNum;
X
Xiaoyu Wang 已提交
77 78 79
} SQuery;

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

void qDestroyQuery(SQuery* pQueryNode);

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

D
stmt  
dapan1121 已提交
86
int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash);
D
stmt  
dapan1121 已提交
87
int32_t qResetStmtDataBlock(void* block, bool keepBuf);
D
stmt  
dapan1121 已提交
88 89 90 91
int32_t qCloneStmtDataBlock(void** pDst, void* pSrc);
void    qFreeStmtDataBlock(void* pDataBlock);
int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc);
void    qDestroyStmtDataBlock(void* pBlock);
D
dapan1121 已提交
92 93
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
stmt  
dapan1121 已提交
94 95
int32_t qBuildStmtColFields(void *pDataBlock, int32_t *fieldNum, TAOS_FIELD** fields);
int32_t qBuildStmtTagFields(void *pBlock, void *boundTags, int32_t *fieldNum, TAOS_FIELD** fields);
D
dapan1121 已提交
96
int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *pName, TAOS_MULTI_BIND *bind, char *msgBuf, int32_t msgBufLen);
D
stmt  
dapan1121 已提交
97 98 99 100
void destroyBoundColumnInfo(void* pBoundInfo);
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char *msgBuf, int32_t msgBufLen);


H
refact  
Hongze Cheng 已提交
101 102 103 104
#ifdef __cplusplus
}
#endif

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