parser.h 3.4 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 "parsenodes.h"
24

25
typedef struct SParseContext {
H
Haojun Liao 已提交
26 27 28 29 30
  uint64_t         requestId;
  int32_t          acctId;
  const char      *db;
  void            *pTransporter;
  SEpSet           mgmtEpSet;
H
Haojun Liao 已提交
31 32
  const char      *pSql;           // sql string
  size_t           sqlLen;         // length of the sql string
33
  char            *pMsg;           // extended error message if exists to help identifying the problem in sql statement.
H
Haojun Liao 已提交
34
  int32_t          msgLen;         // max length of the msg
H
Haojun Liao 已提交
35 36

  struct SCatalog *pCatalog;
37 38
} SParseContext;

39 40 41 42 43 44 45 46
/**
 * Parse the sql statement and then return the SQueryStmtInfo as the result of bounded AST.
 * @param pSql     sql string
 * @param length   length of the sql string
 * @param id       operator id, generated by uuid generator
 * @param msg      extended error message if exists.
 * @return         error code
 */
H
Haojun Liao 已提交
47
int32_t qParseQuerySql(SParseContext* pContext, SQueryNode** pQueryNode);
48

H
Haojun Liao 已提交
49 50 51 52 53 54
/**
 * Return true if it is a ddl/dcl sql statement
 * @param pQuery
 * @return
 */
bool qIsDdlQuery(const SQueryNode* pQueryNode);
X
Xiaoyu Wang 已提交
55

H
Haojun Liao 已提交
56 57 58 59
/**
 * Destroy logic query plan
 * @param pQueryNode
 */
60
void qDestroyQuery(SQueryNode* pQueryNode);
61 62 63 64 65 66 67 68 69 70 71

/**
 * Convert a normal sql statement to only query tags information to enable that the subscribe client can be aware quickly of the true vgroup ids that
 * involved in the subscribe procedure.
 * @param pSql
 * @param length
 * @param pConvertSql
 * @return
 */
int32_t qParserConvertSql(const char* pStr, size_t length, char** pConvertSql);

72 73 74 75
void assignExprInfo(SExprInfo* dst, const SExprInfo* src);
void columnListCopy(SArray* dst, const SArray* src, uint64_t uid);
void columnListDestroy(SArray* pColumnList);

76
void dropAllExprInfo(SArray** pExprInfo, int32_t numOfLevel);
77
void dropOneLevelExprInfo(SArray* pExprInfo);
78 79

typedef struct SSourceParam {
H
Haojun Liao 已提交
80 81
  SArray    *pExprNodeList; //Array<struct tExprNode*>
  SArray    *pColumnList;   //Array<struct SColumn>
82 83 84
  int32_t    num;
} SSourceParam;

85
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, const char* funcName, SSourceParam* pSource, SSchema* pResSchema, int16_t interSize);
86
int32_t copyExprInfoList(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy);
87
int32_t copyAllExprInfo(SArray* dst, const SArray* src, bool deepcopy);
X
Xiaoyu Wang 已提交
88
int32_t getExprFunctionLevel(const SQueryStmtInfo* pQueryInfo);
89

X
Xiaoyu Wang 已提交
90
STableMetaInfo* getMetaInfo(const SQueryStmtInfo* pQueryInfo, int32_t tableIndex);
H
Haojun Liao 已提交
91 92
SSchema *getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex);

93
int32_t getNewResColId();
94
void addIntoSourceParam(SSourceParam* pSourceParam, tExprNode* pNode, SColumn* pColumn);
H
Haojun Liao 已提交
95
SExprInfo* createBinaryExprInfo(struct tExprNode* pNode, SSchema* pResSchema);
96

H
refact  
Hongze Cheng 已提交
97 98 99 100
#ifdef __cplusplus
}
#endif

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