parUtil.h 5.6 KB
Newer Older
H
Haojun Liao 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/*
 * 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/>.
 */

X
Xiaoyu Wang 已提交
16 17
#ifndef TDENGINE_PARSER_UTIL_H
#define TDENGINE_PARSER_UTIL_H
H
Haojun Liao 已提交
18 19 20 21 22

#ifdef __cplusplus
extern "C" {
#endif

23
#include "catalog.h"
24
#include "os.h"
X
Xiaoyu Wang 已提交
25
#include "query.h"
26

27 28 29 30 31 32
#define parserFatal(param, ...) qFatal("PARSER: " param, ##__VA_ARGS__)
#define parserError(param, ...) qError("PARSER: " param, ##__VA_ARGS__)
#define parserWarn(param, ...)  qWarn("PARSER: " param, ##__VA_ARGS__)
#define parserInfo(param, ...)  qInfo("PARSER: " param, ##__VA_ARGS__)
#define parserDebug(param, ...) qDebug("PARSER: " param, ##__VA_ARGS__)
#define parserTrace(param, ...) qTrace("PARSER: " param, ##__VA_ARGS__)
X
Xiaoyu Wang 已提交
33

X
bugfix  
Xiaoyu Wang 已提交
34 35
#define PK_TS_COL_INTERNAL_NAME "_rowts"

X
Xiaoyu Wang 已提交
36 37
typedef struct SMsgBuf {
  int32_t len;
X
Xiaoyu Wang 已提交
38
  char*   buf;
X
Xiaoyu Wang 已提交
39
} SMsgBuf;
40

41 42 43 44
typedef struct SParseMetaCache {
  SHashObj* pTableMeta;    // key is tbFName, element is STableMeta*
  SHashObj* pDbVgroup;     // key is dbFName, element is SArray<SVgroupInfo>*
  SHashObj* pTableVgroup;  // key is tbFName, element is SVgroupInfo*
45 46 47
  SHashObj* pDbCfg;        // key is tbFName, element is SDbCfgInfo*
  SHashObj* pDbInfo;       // key is tbFName, element is SDbInfo*
  SHashObj* pUserAuth;     // key is SUserAuthInfo serialized string, element is bool indicating whether or not to pass
48
  SHashObj* pUdf;          // key is funcName, element is SFuncInfo*
X
Xiaoyu Wang 已提交
49
  SHashObj* pTableIndex;   // key is tbFName, element is SArray<STableIndexInfo>*
D
dapan1121 已提交
50
  SHashObj* pTableCfg;     // key is tbFName, element is STableCfg*
51 52
  SArray*   pDnodes;       // element is SEpSet
  bool      dnodeRequired;
53 54
} SParseMetaCache;

55
int32_t generateSyntaxErrMsg(SMsgBuf* pBuf, int32_t errCode, ...);
56
int32_t buildInvalidOperationMsg(SMsgBuf* pMsgBuf, const char* msg);
X
Xiaoyu Wang 已提交
57
int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char* sourceStr);
H
Haojun Liao 已提交
58

X
Xiaoyu Wang 已提交
59 60 61 62
SSchema*      getTableColumnSchema(const STableMeta* pTableMeta);
SSchema*      getTableTagSchema(const STableMeta* pTableMeta);
int32_t       getNumOfColumns(const STableMeta* pTableMeta);
int32_t       getNumOfTags(const STableMeta* pTableMeta);
X
Xiaoyu Wang 已提交
63
STableComInfo getTableInfo(const STableMeta* pTableMeta);
X
Xiaoyu Wang 已提交
64
STableMeta*   tableMetaDup(const STableMeta* pTableMeta);
X
Xiaoyu Wang 已提交
65
int32_t       parseJsontoTagData(const char* json, SArray* pTagVals, STag** ppTag, SMsgBuf* pMsgBuf);
H
Haojun Liao 已提交
66

67 68
int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen);

69 70 71
int32_t buildCatalogReq(const SParseMetaCache* pMetaCache, SCatalogReq* pCatalogReq);
int32_t putMetaDataToCache(const SCatalogReq* pCatalogReq, const SMetaData* pMetaData, SParseMetaCache* pMetaCache);
int32_t reserveTableMetaInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache);
72
int32_t reserveTableMetaInCacheExt(const SName* pName, SParseMetaCache* pMetaCache);
73 74
int32_t reserveDbVgInfoInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache);
int32_t reserveTableVgroupInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache);
75
int32_t reserveTableVgroupInCacheExt(const SName* pName, SParseMetaCache* pMetaCache);
76
int32_t reserveDbVgVersionInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache);
77
int32_t reserveDbCfgInCache(int32_t acctId, const char* pDb, SParseMetaCache* pMetaCache);
78 79
int32_t reserveUserAuthInCache(int32_t acctId, const char* pUser, const char* pDb, AUTH_TYPE type,
                               SParseMetaCache* pMetaCache);
80
int32_t reserveUserAuthInCacheExt(const char* pUser, const SName* pName, AUTH_TYPE type, SParseMetaCache* pMetaCache);
81
int32_t reserveUdfInCache(const char* pFunc, SParseMetaCache* pMetaCache);
X
Xiaoyu Wang 已提交
82
int32_t reserveTableIndexInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache);
D
dapan1121 已提交
83
int32_t reserveTableCfgInCache(int32_t acctId, const char* pDb, const char* pTable, SParseMetaCache* pMetaCache);
84
int32_t reserveDnodeRequiredInCache(SParseMetaCache* pMetaCache);
85
int32_t getTableMetaFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableMeta** pMeta);
86 87 88
int32_t getDbVgInfoFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SArray** pVgInfo);
int32_t getTableVgroupFromCache(SParseMetaCache* pMetaCache, const SName* pName, SVgroupInfo* pVgroup);
int32_t getDbVgVersionFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, int32_t* pVersion, int64_t* pDbId,
89
                                int32_t* pTableNum);
90
int32_t getDbCfgFromCache(SParseMetaCache* pMetaCache, const char* pDbFName, SDbCfgInfo* pInfo);
91
int32_t getUserAuthFromCache(SParseMetaCache* pMetaCache, const char* pUser, const char* pDbFName, AUTH_TYPE type,
92
                             bool* pPass);
93
int32_t getUdfInfoFromCache(SParseMetaCache* pMetaCache, const char* pFunc, SFuncInfo* pInfo);
X
Xiaoyu Wang 已提交
94
int32_t getTableIndexFromCache(SParseMetaCache* pMetaCache, const SName* pName, SArray** pIndexes);
D
dapan1121 已提交
95
int32_t getTableCfgFromCache(SParseMetaCache* pMetaCache, const SName* pName, STableCfg** pOutput);
96
int32_t getDnodeListFromCache(SParseMetaCache* pMetaCache, SArray** pDnodes);
97
void    destoryParseMetaCache(SParseMetaCache* pMetaCache);
98

H
Haojun Liao 已提交
99 100 101 102
#ifdef __cplusplus
}
#endif

X
Xiaoyu Wang 已提交
103
#endif  // TDENGINE_PARSER_UTIL_H