parser.h 3.2 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 31 32 33 34
  SParseBasicCtx  ctx;
  void            *pRpc;
  struct SCatalog *pCatalog;
  const SEpSet    *pEpSet;
  int8_t           schemaAttached; // denote if submit block is built with table schema or not
  const char      *pSql;           // sql string
  size_t           sqlLen;         // length of the sql string
  char            *pMsg;           // extended error message if exists to help avoid the problem in sql statement.
  int32_t          msgLen;         // max length of the msg
35 36
} SParseContext;

37 38 39 40 41 42 43 44
/**
 * 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
 */
X
Xiaoyu Wang 已提交
45
int32_t qParseQuerySql(SParseContext* pContext, SQueryNode** pQuery);
46

X
Xiaoyu Wang 已提交
47 48 49
bool qIsDdlQuery(const SQueryNode* pQuery);

void qDestoryQuery(SQueryNode* pQuery);
50 51 52 53 54 55 56 57 58 59 60

/**
 * 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);

61 62 63 64
void assignExprInfo(SExprInfo* dst, const SExprInfo* src);
void columnListCopy(SArray* dst, const SArray* src, uint64_t uid);
void columnListDestroy(SArray* pColumnList);

65
void dropAllExprInfo(SArray** pExprInfo, int32_t numOfLevel);
66 67 68 69 70 71 72

typedef struct SSourceParam {
  SArray            *pExprNodeList; //Array<struct tExprNode*>
  SArray            *pColumnList;   //Array<struct SColumn>
  int32_t    num;
} SSourceParam;

73
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, const char* funcName, SSourceParam* pSource, SSchema* pResSchema, int16_t interSize);
74
int32_t copyExprInfoList(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy);
75
int32_t copyAllExprInfo(SArray* dst, const SArray* src, bool deepcopy);
X
Xiaoyu Wang 已提交
76
int32_t getExprFunctionLevel(const SQueryStmtInfo* pQueryInfo);
77

X
Xiaoyu Wang 已提交
78
STableMetaInfo* getMetaInfo(const SQueryStmtInfo* pQueryInfo, int32_t tableIndex);
H
Haojun Liao 已提交
79
SSchema *getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex);
80
SSchema createSchema(uint8_t type, int16_t bytes, int16_t colId, const char* name);
H
Haojun Liao 已提交
81

82
int32_t getNewResColId();
83
void addIntoSourceParam(SSourceParam* pSourceParam, tExprNode* pNode, SColumn* pColumn);
84

H
refact  
Hongze Cheng 已提交
85 86 87 88 89
#ifdef __cplusplus
}
#endif

#endif /*_TD_PARSER_H_*/