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

X
Xiaoyu Wang 已提交
23
#include "parsenodes.h"
24

25
typedef struct SParseContext {
26
  SParseBasicCtx   ctx;
H
Haojun Liao 已提交
27 28 29
  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
30
  char            *pMsg;           // extended error message if exists to help identifying the problem in sql statement.
H
Haojun Liao 已提交
31
  int32_t          msgLen;         // max length of the msg
32 33
} SParseContext;

34 35 36 37 38 39 40 41
/**
 * 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 已提交
42
int32_t qParseQuerySql(SParseContext* pContext, SQueryNode** pQuery);
43

X
Xiaoyu Wang 已提交
44 45
bool qIsDdlQuery(const SQueryNode* pQuery);

46
void qDestroyQuery(SQueryNode* pQueryNode);
47 48 49 50 51 52 53 54 55 56 57

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

58 59 60 61
void assignExprInfo(SExprInfo* dst, const SExprInfo* src);
void columnListCopy(SArray* dst, const SArray* src, uint64_t uid);
void columnListDestroy(SArray* pColumnList);

62
void dropAllExprInfo(SArray** pExprInfo, int32_t numOfLevel);
63 64 65 66 67 68 69

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

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

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

78
int32_t getNewResColId();
79
void addIntoSourceParam(SSourceParam* pSourceParam, tExprNode* pNode, SColumn* pColumn);
80

H
refact  
Hongze Cheng 已提交
81 82 83 84
#ifdef __cplusplus
}
#endif

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