Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
ac874f9e
T
TDengine
项目概览
taosdata
/
TDengine
大约 2 年 前同步成功
通知
1192
Star
22018
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
ac874f9e
编写于
4月 26, 2022
作者:
X
Xiaoyu Wang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
enh: format code
上级
547ff174
变更
44
展开全部
隐藏空白更改
内联
并排
Showing
44 changed file
with
1746 addition
and
1620 deletion
+1746
-1620
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+124
-140
source/libs/nodes/inc/nodesUtil.h
source/libs/nodes/inc/nodesUtil.h
+31
-9
source/libs/nodes/src/nodesCloneFuncs.c
source/libs/nodes/src/nodesCloneFuncs.c
+55
-55
source/libs/nodes/src/nodesCodeFuncs.c
source/libs/nodes/src/nodesCodeFuncs.c
+21
-31
source/libs/nodes/src/nodesEqualFuncs.c
source/libs/nodes/src/nodesEqualFuncs.c
+23
-28
source/libs/nodes/src/nodesToSQLFuncs.c
source/libs/nodes/src/nodesToSQLFuncs.c
+59
-33
source/libs/nodes/src/nodesTraverseFuncs.c
source/libs/nodes/src/nodesTraverseFuncs.c
+9
-7
source/libs/nodes/src/nodesUtilFuncs.c
source/libs/nodes/src/nodesUtilFuncs.c
+53
-68
source/libs/nodes/test/nodesTest.cpp
source/libs/nodes/test/nodesTest.cpp
+31
-31
source/libs/parser/inc/parAst.h
source/libs/parser/inc/parAst.h
+34
-25
source/libs/parser/inc/parInsertData.h
source/libs/parser/inc/parInsertData.h
+23
-20
source/libs/parser/inc/parInt.h
source/libs/parser/inc/parInt.h
+1
-1
source/libs/parser/inc/parToken.h
source/libs/parser/inc/parToken.h
+14
-12
source/libs/parser/inc/parUtil.h
source/libs/parser/inc/parUtil.h
+14
-14
source/libs/parser/src/parAstCreater.c
source/libs/parser/src/parAstCreater.c
+53
-41
source/libs/parser/src/parAstParser.c
source/libs/parser/src/parAstParser.c
+6
-6
source/libs/parser/src/parCalcConst.c
source/libs/parser/src/parCalcConst.c
+11
-13
source/libs/parser/src/parInsert.c
source/libs/parser/src/parInsert.c
+136
-141
source/libs/parser/src/parInsertData.c
source/libs/parser/src/parInsertData.c
+69
-69
source/libs/parser/src/parTokenizer.c
source/libs/parser/src/parTokenizer.c
+208
-211
source/libs/parser/src/parTranslater.c
source/libs/parser/src/parTranslater.c
+20
-18
source/libs/parser/src/parUtil.c
source/libs/parser/src/parUtil.c
+68
-62
source/libs/parser/src/parser.c
source/libs/parser/src/parser.c
+3
-3
source/libs/parser/test/mockCatalog.cpp
source/libs/parser/test/mockCatalog.cpp
+54
-31
source/libs/parser/test/mockCatalogService.cpp
source/libs/parser/test/mockCatalogService.cpp
+61
-65
source/libs/parser/test/mockCatalogService.h
source/libs/parser/test/mockCatalogService.h
+12
-15
source/libs/parser/test/parserAstTest.cpp
source/libs/parser/test/parserAstTest.cpp
+89
-77
source/libs/parser/test/parserInsertTest.cpp
source/libs/parser/test/parserInsertTest.cpp
+30
-28
source/libs/parser/test/parserTestMain.cpp
source/libs/parser/test/parserTestMain.cpp
+11
-14
source/libs/planner/inc/planInt.h
source/libs/planner/inc/planInt.h
+6
-6
source/libs/planner/src/planLogicCreater.c
source/libs/planner/src/planLogicCreater.c
+67
-55
source/libs/planner/src/planOptimizer.c
source/libs/planner/src/planOptimizer.c
+53
-50
source/libs/planner/src/planPhysiCreater.c
source/libs/planner/src/planPhysiCreater.c
+158
-116
source/libs/planner/src/planScaleOut.c
source/libs/planner/src/planScaleOut.c
+6
-6
source/libs/planner/src/planSpliter.c
source/libs/planner/src/planSpliter.c
+26
-27
source/libs/planner/src/planner.c
source/libs/planner/src/planner.c
+10
-16
source/libs/planner/test/planOptTest.cpp
source/libs/planner/test/planOptTest.cpp
+1
-3
source/libs/planner/test/planSTableTest.cpp
source/libs/planner/test/planSTableTest.cpp
+26
-0
source/libs/planner/test/planSetOpTest.cpp
source/libs/planner/test/planSetOpTest.cpp
+1
-3
source/libs/planner/test/planStmtTest.cpp
source/libs/planner/test/planStmtTest.cpp
+3
-3
source/libs/planner/test/planTestMain.cpp
source/libs/planner/test/planTestMain.cpp
+8
-13
source/libs/planner/test/planTestUtil.cpp
source/libs/planner/test/planTestUtil.cpp
+27
-34
source/libs/planner/test/planTestUtil.h
source/libs/planner/test/planTestUtil.h
+2
-2
source/libs/planner/test/plannerTest.cpp
source/libs/planner/test/plannerTest.cpp
+29
-18
未找到文件。
include/libs/nodes/querynodes.h
浏览文件 @
ac874f9e
...
@@ -25,14 +25,16 @@ extern "C" {
...
@@ -25,14 +25,16 @@ extern "C" {
#include "tvariant.h"
#include "tvariant.h"
#define TABLE_TOTAL_COL_NUM(pMeta) ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags)
#define TABLE_TOTAL_COL_NUM(pMeta) ((pMeta)->tableInfo.numOfColumns + (pMeta)->tableInfo.numOfTags)
#define TABLE_META_SIZE(pMeta) (NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema)))
#define TABLE_META_SIZE(pMeta) \
#define VGROUPS_INFO_SIZE(pInfo) (NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
(NULL == (pMeta) ? 0 : (sizeof(STableMeta) + TABLE_TOTAL_COL_NUM((pMeta)) * sizeof(SSchema)))
#define VGROUPS_INFO_SIZE(pInfo) \
(NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
typedef
struct
SRawExprNode
{
typedef
struct
SRawExprNode
{
ENodeType
nodeType
;
ENodeType
nodeType
;
char
*
p
;
char
*
p
;
uint32_t
n
;
uint32_t
n
;
SNode
*
pNode
;
SNode
*
pNode
;
}
SRawExprNode
;
}
SRawExprNode
;
typedef
struct
SDataType
{
typedef
struct
SDataType
{
...
@@ -45,170 +47,155 @@ typedef struct SDataType {
...
@@ -45,170 +47,155 @@ typedef struct SDataType {
typedef
struct
SExprNode
{
typedef
struct
SExprNode
{
ENodeType
type
;
ENodeType
type
;
SDataType
resType
;
SDataType
resType
;
char
aliasName
[
TSDB_COL_NAME_LEN
];
char
aliasName
[
TSDB_COL_NAME_LEN
];
SArray
*
pAssociation
;
SArray
*
pAssociation
;
}
SExprNode
;
}
SExprNode
;
typedef
enum
EColumnType
{
typedef
enum
EColumnType
{
COLUMN_TYPE_COLUMN
=
1
,
COLUMN_TYPE_TAG
}
EColumnType
;
COLUMN_TYPE_COLUMN
=
1
,
COLUMN_TYPE_TAG
}
EColumnType
;
typedef
struct
SColumnNode
{
typedef
struct
SColumnNode
{
SExprNode
node
;
// QUERY_NODE_COLUMN
SExprNode
node
;
// QUERY_NODE_COLUMN
uint64_t
tableId
;
uint64_t
tableId
;
int8_t
tableType
;
int8_t
tableType
;
col_id_t
colId
;
col_id_t
colId
;
EColumnType
colType
;
// column or tag
EColumnType
colType
;
// column or tag
char
dbName
[
TSDB_DB_NAME_LEN
];
char
dbName
[
TSDB_DB_NAME_LEN
];
char
tableName
[
TSDB_TABLE_NAME_LEN
];
char
tableName
[
TSDB_TABLE_NAME_LEN
];
char
tableAlias
[
TSDB_TABLE_NAME_LEN
];
char
tableAlias
[
TSDB_TABLE_NAME_LEN
];
char
colName
[
TSDB_COL_NAME_LEN
];
char
colName
[
TSDB_COL_NAME_LEN
];
SNode
*
pProjectRef
;
SNode
*
pProjectRef
;
int16_t
dataBlockId
;
int16_t
dataBlockId
;
int16_t
slotId
;
int16_t
slotId
;
}
SColumnNode
;
}
SColumnNode
;
typedef
struct
STargetNode
{
typedef
struct
STargetNode
{
ENodeType
type
;
ENodeType
type
;
int16_t
dataBlockId
;
int16_t
dataBlockId
;
int16_t
slotId
;
int16_t
slotId
;
SNode
*
pExpr
;
SNode
*
pExpr
;
}
STargetNode
;
}
STargetNode
;
typedef
struct
SValueNode
{
typedef
struct
SValueNode
{
SExprNode
node
;
// QUERY_NODE_VALUE
SExprNode
node
;
// QUERY_NODE_VALUE
char
*
literal
;
char
*
literal
;
bool
isDuration
;
bool
isDuration
;
bool
translate
;
bool
translate
;
int16_t
placeholderNo
;
int16_t
placeholderNo
;
union
{
union
{
bool
b
;
bool
b
;
int64_t
i
;
int64_t
i
;
uint64_t
u
;
uint64_t
u
;
double
d
;
double
d
;
char
*
p
;
char
*
p
;
}
datum
;
}
datum
;
char
unit
;
char
unit
;
}
SValueNode
;
}
SValueNode
;
typedef
struct
SOperatorNode
{
typedef
struct
SOperatorNode
{
SExprNode
node
;
// QUERY_NODE_OPERATOR
SExprNode
node
;
// QUERY_NODE_OPERATOR
EOperatorType
opType
;
EOperatorType
opType
;
SNode
*
pLeft
;
SNode
*
pLeft
;
SNode
*
pRight
;
SNode
*
pRight
;
}
SOperatorNode
;
}
SOperatorNode
;
typedef
struct
SLogicConditionNode
{
typedef
struct
SLogicConditionNode
{
SExprNode
node
;
// QUERY_NODE_LOGIC_CONDITION
SExprNode
node
;
// QUERY_NODE_LOGIC_CONDITION
ELogicConditionType
condType
;
ELogicConditionType
condType
;
SNodeList
*
pParameterList
;
SNodeList
*
pParameterList
;
}
SLogicConditionNode
;
}
SLogicConditionNode
;
typedef
struct
SNodeListNode
{
typedef
struct
SNodeListNode
{
ENodeType
type
;
// QUERY_NODE_NODE_LIST
ENodeType
type
;
// QUERY_NODE_NODE_LIST
SDataType
dataType
;
SDataType
dataType
;
SNodeList
*
pNodeList
;
SNodeList
*
pNodeList
;
}
SNodeListNode
;
}
SNodeListNode
;
typedef
struct
SFunctionNode
{
typedef
struct
SFunctionNode
{
SExprNode
node
;
// QUERY_NODE_FUNCTION
SExprNode
node
;
// QUERY_NODE_FUNCTION
char
functionName
[
TSDB_FUNC_NAME_LEN
];
char
functionName
[
TSDB_FUNC_NAME_LEN
];
int32_t
funcId
;
int32_t
funcId
;
int32_t
funcType
;
int32_t
funcType
;
SNodeList
*
pParameterList
;
SNodeList
*
pParameterList
;
int32_t
udfBufSize
;
int32_t
udfBufSize
;
}
SFunctionNode
;
}
SFunctionNode
;
typedef
struct
STableNode
{
typedef
struct
STableNode
{
SExprNode
node
;
SExprNode
node
;
char
dbName
[
TSDB_DB_NAME_LEN
];
char
dbName
[
TSDB_DB_NAME_LEN
];
char
tableName
[
TSDB_TABLE_NAME_LEN
];
char
tableName
[
TSDB_TABLE_NAME_LEN
];
char
tableAlias
[
TSDB_TABLE_NAME_LEN
];
char
tableAlias
[
TSDB_TABLE_NAME_LEN
];
uint8_t
precision
;
uint8_t
precision
;
}
STableNode
;
}
STableNode
;
struct
STableMeta
;
struct
STableMeta
;
typedef
struct
SRealTableNode
{
typedef
struct
SRealTableNode
{
STableNode
table
;
// QUERY_NODE_REAL_TABLE
STableNode
table
;
// QUERY_NODE_REAL_TABLE
struct
STableMeta
*
pMeta
;
struct
STableMeta
*
pMeta
;
SVgroupsInfo
*
pVgroupList
;
SVgroupsInfo
*
pVgroupList
;
char
qualDbName
[
TSDB_DB_NAME_LEN
];
// SHOW qualDbName.TABLES
char
qualDbName
[
TSDB_DB_NAME_LEN
];
// SHOW qualDbName.TABLES
double
ratio
;
double
ratio
;
}
SRealTableNode
;
}
SRealTableNode
;
typedef
struct
STempTableNode
{
typedef
struct
STempTableNode
{
STableNode
table
;
// QUERY_NODE_TEMP_TABLE
STableNode
table
;
// QUERY_NODE_TEMP_TABLE
SNode
*
pSubquery
;
SNode
*
pSubquery
;
}
STempTableNode
;
}
STempTableNode
;
typedef
enum
EJoinType
{
typedef
enum
EJoinType
{
JOIN_TYPE_INNER
=
1
}
EJoinType
;
JOIN_TYPE_INNER
=
1
}
EJoinType
;
typedef
struct
SJoinTableNode
{
typedef
struct
SJoinTableNode
{
STableNode
table
;
// QUERY_NODE_JOIN_TABLE
STableNode
table
;
// QUERY_NODE_JOIN_TABLE
EJoinType
joinType
;
EJoinType
joinType
;
SNode
*
pLeft
;
SNode
*
pLeft
;
SNode
*
pRight
;
SNode
*
pRight
;
SNode
*
pOnCond
;
SNode
*
pOnCond
;
}
SJoinTableNode
;
}
SJoinTableNode
;
typedef
enum
EGroupingSetType
{
typedef
enum
EGroupingSetType
{
GP_TYPE_NORMAL
=
1
}
EGroupingSetType
;
GP_TYPE_NORMAL
=
1
}
EGroupingSetType
;
typedef
struct
SGroupingSetNode
{
typedef
struct
SGroupingSetNode
{
ENodeType
type
;
// QUERY_NODE_GROUPING_SET
ENodeType
type
;
// QUERY_NODE_GROUPING_SET
EGroupingSetType
groupingSetType
;
EGroupingSetType
groupingSetType
;
SNodeList
*
pParameterList
;
SNodeList
*
pParameterList
;
}
SGroupingSetNode
;
}
SGroupingSetNode
;
typedef
enum
EOrder
{
typedef
enum
EOrder
{
ORDER_ASC
=
1
,
ORDER_DESC
}
EOrder
;
ORDER_ASC
=
1
,
ORDER_DESC
}
EOrder
;
typedef
enum
ENullOrder
{
typedef
enum
ENullOrder
{
NULL_ORDER_DEFAULT
=
1
,
NULL_ORDER_FIRST
,
NULL_ORDER_LAST
}
ENullOrder
;
NULL_ORDER_DEFAULT
=
1
,
NULL_ORDER_FIRST
,
NULL_ORDER_LAST
}
ENullOrder
;
typedef
struct
SOrderByExprNode
{
typedef
struct
SOrderByExprNode
{
ENodeType
type
;
// QUERY_NODE_ORDER_BY_EXPR
ENodeType
type
;
// QUERY_NODE_ORDER_BY_EXPR
SNode
*
pExpr
;
SNode
*
pExpr
;
EOrder
order
;
EOrder
order
;
ENullOrder
nullOrder
;
ENullOrder
nullOrder
;
}
SOrderByExprNode
;
}
SOrderByExprNode
;
typedef
struct
SLimitNode
{
typedef
struct
SLimitNode
{
ENodeType
type
;
// QUERY_NODE_LIMIT
ENodeType
type
;
// QUERY_NODE_LIMIT
int64_t
limit
;
int64_t
limit
;
int64_t
offset
;
int64_t
offset
;
}
SLimitNode
;
}
SLimitNode
;
typedef
struct
SStateWindowNode
{
typedef
struct
SStateWindowNode
{
ENodeType
type
;
// QUERY_NODE_STATE_WINDOW
ENodeType
type
;
// QUERY_NODE_STATE_WINDOW
SNode
*
pCol
;
// timestamp primary key
SNode
*
pCol
;
// timestamp primary key
SNode
*
pExpr
;
SNode
*
pExpr
;
}
SStateWindowNode
;
}
SStateWindowNode
;
typedef
struct
SSessionWindowNode
{
typedef
struct
SSessionWindowNode
{
ENodeType
type
;
// QUERY_NODE_SESSION_WINDOW
ENodeType
type
;
// QUERY_NODE_SESSION_WINDOW
SColumnNode
*
pCol
;
// timestamp primary key
SColumnNode
*
pCol
;
// timestamp primary key
SValueNode
*
pGap
;
// gap between two session window(in microseconds)
SValueNode
*
pGap
;
// gap between two session window(in microseconds)
}
SSessionWindowNode
;
}
SSessionWindowNode
;
typedef
struct
SIntervalWindowNode
{
typedef
struct
SIntervalWindowNode
{
ENodeType
type
;
// QUERY_NODE_INTERVAL_WINDOW
ENodeType
type
;
// QUERY_NODE_INTERVAL_WINDOW
SNode
*
pCol
;
// timestamp primary key
SNode
*
pCol
;
// timestamp primary key
SNode
*
pInterval
;
// SValueNode
SNode
*
pInterval
;
// SValueNode
SNode
*
pOffset
;
// SValueNode
SNode
*
pOffset
;
// SValueNode
SNode
*
pSliding
;
// SValueNode
SNode
*
pSliding
;
// SValueNode
SNode
*
pFill
;
SNode
*
pFill
;
}
SIntervalWindowNode
;
}
SIntervalWindowNode
;
typedef
enum
EFillMode
{
typedef
enum
EFillMode
{
...
@@ -221,42 +208,40 @@ typedef enum EFillMode {
...
@@ -221,42 +208,40 @@ typedef enum EFillMode {
}
EFillMode
;
}
EFillMode
;
typedef
struct
SFillNode
{
typedef
struct
SFillNode
{
ENodeType
type
;
// QUERY_NODE_FILL
ENodeType
type
;
// QUERY_NODE_FILL
EFillMode
mode
;
EFillMode
mode
;
SNode
*
pValues
;
// SNodeListNode
SNode
*
pValues
;
// SNodeListNode
}
SFillNode
;
}
SFillNode
;
typedef
struct
SSelectStmt
{
typedef
struct
SSelectStmt
{
ENodeType
type
;
// QUERY_NODE_SELECT_STMT
ENodeType
type
;
// QUERY_NODE_SELECT_STMT
bool
isDistinct
;
bool
isDistinct
;
SNodeList
*
pProjectionList
;
SNodeList
*
pProjectionList
;
SNode
*
pFromTable
;
SNode
*
pFromTable
;
SNode
*
pWhere
;
SNode
*
pWhere
;
SNodeList
*
pPartitionByList
;
SNodeList
*
pPartitionByList
;
SNode
*
pWindow
;
SNode
*
pWindow
;
SNodeList
*
pGroupByList
;
// SGroupingSetNode
SNodeList
*
pGroupByList
;
// SGroupingSetNode
SNode
*
pHaving
;
SNode
*
pHaving
;
SNodeList
*
pOrderByList
;
// SOrderByExprNode
SNodeList
*
pOrderByList
;
// SOrderByExprNode
SLimitNode
*
pLimit
;
SLimitNode
*
pLimit
;
SLimitNode
*
pSlimit
;
SLimitNode
*
pSlimit
;
char
stmtName
[
TSDB_TABLE_NAME_LEN
];
char
stmtName
[
TSDB_TABLE_NAME_LEN
];
uint8_t
precision
;
uint8_t
precision
;
bool
isEmptyResult
;
bool
isEmptyResult
;
bool
hasAggFuncs
;
}
SSelectStmt
;
}
SSelectStmt
;
typedef
enum
ESetOperatorType
{
typedef
enum
ESetOperatorType
{
SET_OP_TYPE_UNION_ALL
=
1
,
SET_OP_TYPE_UNION
}
ESetOperatorType
;
SET_OP_TYPE_UNION_ALL
=
1
,
SET_OP_TYPE_UNION
}
ESetOperatorType
;
typedef
struct
SSetOperator
{
typedef
struct
SSetOperator
{
ENodeType
type
;
// QUERY_NODE_SET_OPERATOR
ENodeType
type
;
// QUERY_NODE_SET_OPERATOR
ESetOperatorType
opType
;
ESetOperatorType
opType
;
SNodeList
*
pProjectionList
;
SNodeList
*
pProjectionList
;
SNode
*
pLeft
;
SNode
*
pLeft
;
SNode
*
pRight
;
SNode
*
pRight
;
SNodeList
*
pOrderByList
;
// SOrderByExprNode
SNodeList
*
pOrderByList
;
// SOrderByExprNode
SNode
*
pLimit
;
SNode
*
pLimit
;
}
SSetOperator
;
}
SSetOperator
;
typedef
enum
ESqlClause
{
typedef
enum
ESqlClause
{
...
@@ -271,7 +256,6 @@ typedef enum ESqlClause {
...
@@ -271,7 +256,6 @@ typedef enum ESqlClause {
SQL_CLAUSE_ORDER_BY
SQL_CLAUSE_ORDER_BY
}
ESqlClause
;
}
ESqlClause
;
typedef
enum
{
typedef
enum
{
PAYLOAD_TYPE_KV
=
0
,
PAYLOAD_TYPE_KV
=
0
,
PAYLOAD_TYPE_RAW
=
1
,
PAYLOAD_TYPE_RAW
=
1
,
...
@@ -281,29 +265,29 @@ typedef struct SVgDataBlocks {
...
@@ -281,29 +265,29 @@ typedef struct SVgDataBlocks {
SVgroupInfo
vg
;
SVgroupInfo
vg
;
int32_t
numOfTables
;
// number of tables in current submit block
int32_t
numOfTables
;
// number of tables in current submit block
uint32_t
size
;
uint32_t
size
;
char
*
pData
;
// SMsgDesc + SSubmitReq + SSubmitBlk + ...
char
*
pData
;
// SMsgDesc + SSubmitReq + SSubmitBlk + ...
}
SVgDataBlocks
;
}
SVgDataBlocks
;
typedef
struct
SVnodeModifOpStmt
{
typedef
struct
SVnodeModifOpStmt
{
ENodeType
nodeType
;
ENodeType
nodeType
;
ENodeType
sqlNodeType
;
ENodeType
sqlNodeType
;
SArray
*
pDataBlocks
;
// data block for each vgroup, SArray<SVgDataBlocks*>.
SArray
*
pDataBlocks
;
// data block for each vgroup, SArray<SVgDataBlocks*>.
uint8_t
payloadType
;
// EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
uint8_t
payloadType
;
// EPayloadType. 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
uint32_t
insertType
;
// insert data from [file|sql statement| bound statement]
uint32_t
insertType
;
// insert data from [file|sql statement| bound statement]
const
char
*
sql
;
// current sql statement position
const
char
*
sql
;
// current sql statement position
}
SVnodeModifOpStmt
;
}
SVnodeModifOpStmt
;
typedef
struct
SExplainOptions
{
typedef
struct
SExplainOptions
{
ENodeType
type
;
ENodeType
type
;
bool
verbose
;
bool
verbose
;
double
ratio
;
double
ratio
;
}
SExplainOptions
;
}
SExplainOptions
;
typedef
struct
SExplainStmt
{
typedef
struct
SExplainStmt
{
ENodeType
type
;
ENodeType
type
;
bool
analyze
;
bool
analyze
;
SExplainOptions
*
pOptions
;
SExplainOptions
*
pOptions
;
SNode
*
pQuery
;
SNode
*
pQuery
;
}
SExplainStmt
;
}
SExplainStmt
;
void
nodesWalkSelectStmt
(
SSelectStmt
*
pSelect
,
ESqlClause
clause
,
FNodeWalker
walker
,
void
*
pContext
);
void
nodesWalkSelectStmt
(
SSelectStmt
*
pSelect
,
ESqlClause
clause
,
FNodeWalker
walker
,
void
*
pContext
);
...
@@ -324,10 +308,10 @@ bool nodesIsJsonOp(const SOperatorNode* pOp);
...
@@ -324,10 +308,10 @@ bool nodesIsJsonOp(const SOperatorNode* pOp);
bool
nodesIsTimeorderQuery
(
const
SNode
*
pQuery
);
bool
nodesIsTimeorderQuery
(
const
SNode
*
pQuery
);
bool
nodesIsTimelineQuery
(
const
SNode
*
pQuery
);
bool
nodesIsTimelineQuery
(
const
SNode
*
pQuery
);
void
*
nodesGetValueFromNode
(
SValueNode
*
pNode
);
void
*
nodesGetValueFromNode
(
SValueNode
*
pNode
);
char
*
nodesGetStrValueFromNode
(
SValueNode
*
pNode
);
char
*
nodesGetStrValueFromNode
(
SValueNode
*
pNode
);
char
*
getFillModeString
(
EFillMode
mode
);
char
*
getFillModeString
(
EFillMode
mode
);
void
valueNodeToVariant
(
const
SValueNode
*
pNode
,
SVariant
*
pVal
);
void
valueNodeToVariant
(
const
SValueNode
*
pNode
,
SVariant
*
pVal
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/libs/nodes/inc/nodesUtil.h
浏览文件 @
ac874f9e
...
@@ -20,17 +20,39 @@
...
@@ -20,17 +20,39 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#define nodesFatal(...)
qFatal("NODES: " __VA_ARGS__)
#define nodesFatal(...) qFatal("NODES: " __VA_ARGS__)
#define nodesError(...)
qError("NODES: " __VA_ARGS__)
#define nodesError(...) qError("NODES: " __VA_ARGS__)
#define nodesWarn(...)
qWarn("NODES: " __VA_ARGS__)
#define nodesWarn(...) qWarn("NODES: " __VA_ARGS__)
#define nodesInfo(...)
qInfo("NODES: " __VA_ARGS__)
#define nodesInfo(...) qInfo("NODES: " __VA_ARGS__)
#define nodesDebug(...)
qDebug("NODES: " __VA_ARGS__)
#define nodesDebug(...) qDebug("NODES: " __VA_ARGS__)
#define nodesTrace(...)
qTrace("NODES: " __VA_ARGS__)
#define nodesTrace(...) qTrace("NODES: " __VA_ARGS__)
#define NODES_ERR_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; return _code; } } while (0)
#define NODES_ERR_RET(c) \
#define NODES_RET(c) do { int32_t _code = c; if (_code != TSDB_CODE_SUCCESS) { terrno = _code; } return _code; } while (0)
do { \
#define NODES_ERR_JRET(c) do { code = c; if (code != TSDB_CODE_SUCCESS) { terrno = code; goto _return; } } while (0)
int32_t _code = c; \
if (_code != TSDB_CODE_SUCCESS) { \
terrno = _code; \
return _code; \
} \
} while (0)
#define NODES_RET(c) \
do { \
int32_t _code = c; \
if (_code != TSDB_CODE_SUCCESS) { \
terrno = _code; \
} \
return _code; \
} while (0)
#define NODES_ERR_JRET(c) \
do { \
code = c; \
if (code != TSDB_CODE_SUCCESS) { \
terrno = code; \
goto _return; \
} \
} while (0)
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/libs/nodes/src/nodesCloneFuncs.c
浏览文件 @
ac874f9e
...
@@ -19,71 +19,71 @@
...
@@ -19,71 +19,71 @@
#include "taos.h"
#include "taos.h"
#include "taoserror.h"
#include "taoserror.h"
#define COPY_ALL_SCALAR_FIELDS \
#define COPY_ALL_SCALAR_FIELDS
\
do {
\
do {
\
memcpy((pDst), (pSrc), sizeof(*pSrc)); \
memcpy((pDst), (pSrc), sizeof(*pSrc)); \
} while (0)
} while (0)
#define COPY_SCALAR_FIELD(fldname) \
#define COPY_SCALAR_FIELD(fldname)
\
do {
\
do {
\
(pDst)->fldname = (pSrc)->fldname; \
(pDst)->fldname = (pSrc)->fldname; \
} while (0)
} while (0)
#define COPY_CHAR_ARRAY_FIELD(fldname) \
#define COPY_CHAR_ARRAY_FIELD(fldname)
\
do {
\
do {
\
strcpy((pDst)->fldname, (pSrc)->fldname); \
strcpy((pDst)->fldname, (pSrc)->fldname); \
} while (0)
} while (0)
#define COPY_CHAR_POINT_FIELD(fldname) \
#define COPY_CHAR_POINT_FIELD(fldname)
\
do {
\
do {
\
if (NULL == (pSrc)->fldname) { \
if (NULL == (pSrc)->fldname) {
\
break; \
break;
\
} \
}
\
(pDst)->fldname = strdup((pSrc)->fldname); \
(pDst)->fldname = strdup((pSrc)->fldname); \
} while (0)
} while (0)
#define CLONE_NODE_FIELD(fldname) \
#define CLONE_NODE_FIELD(fldname)
\
do {
\
do {
\
if (NULL == (pSrc)->fldname) { \
if (NULL == (pSrc)->fldname) {
\
break; \
break;
\
} \
}
\
(pDst)->fldname = nodesCloneNode((pSrc)->fldname); \
(pDst)->fldname = nodesCloneNode((pSrc)->fldname); \
if (NULL == (pDst)->fldname) { \
if (NULL == (pDst)->fldname) {
\
nodesDestroyNode((SNode*)(pDst)); \
nodesDestroyNode((SNode*)(pDst));
\
return NULL; \
return NULL;
\
} \
}
\
} while (0)
} while (0)
#define CLONE_NODE_LIST_FIELD(fldname) \
#define CLONE_NODE_LIST_FIELD(fldname)
\
do {
\
do {
\
if (NULL == (pSrc)->fldname) { \
if (NULL == (pSrc)->fldname) {
\
break; \
break;
\
} \
}
\
(pDst)->fldname = nodesCloneList((pSrc)->fldname); \
(pDst)->fldname = nodesCloneList((pSrc)->fldname); \
if (NULL == (pDst)->fldname) { \
if (NULL == (pDst)->fldname) {
\
nodesDestroyNode((SNode*)(pDst)); \
nodesDestroyNode((SNode*)(pDst));
\
return NULL; \
return NULL;
\
} \
}
\
} while (0)
} while (0)
#define CLONE_OBJECT_FIELD(fldname, cloneFunc) \
#define CLONE_OBJECT_FIELD(fldname, cloneFunc)
\
do {
\
do {
\
if (NULL == (pSrc)->fldname) { \
if (NULL == (pSrc)->fldname) {
\
break; \
break;
\
} \
}
\
(pDst)->fldname = cloneFunc((pSrc)->fldname); \
(pDst)->fldname = cloneFunc((pSrc)->fldname); \
if (NULL == (pDst)->fldname) { \
if (NULL == (pDst)->fldname) {
\
nodesDestroyNode((SNode*)(pDst)); \
nodesDestroyNode((SNode*)(pDst));
\
return NULL; \
return NULL;
\
} \
}
\
} while (0)
} while (0)
#define COPY_BASE_OBJECT_FIELD(fldname, copyFunc) \
#define COPY_BASE_OBJECT_FIELD(fldname, copyFunc)
\
do {
\
do {
\
if (NULL == copyFunc(&((pSrc)->fldname), &((pDst)->fldname))) { \
if (NULL == copyFunc(&((pSrc)->fldname), &((pDst)->fldname))) { \
return NULL; \
return NULL;
\
} \
}
\
} while (0)
} while (0)
static
void
dataTypeCopy
(
const
SDataType
*
pSrc
,
SDataType
*
pDst
)
{
static
void
dataTypeCopy
(
const
SDataType
*
pSrc
,
SDataType
*
pDst
)
{
COPY_SCALAR_FIELD
(
type
);
COPY_SCALAR_FIELD
(
type
);
...
@@ -201,7 +201,7 @@ static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) {
...
@@ -201,7 +201,7 @@ static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) {
}
}
static
STableMeta
*
tableMetaClone
(
const
STableMeta
*
pSrc
)
{
static
STableMeta
*
tableMetaClone
(
const
STableMeta
*
pSrc
)
{
int32_t
len
=
TABLE_META_SIZE
(
pSrc
);
int32_t
len
=
TABLE_META_SIZE
(
pSrc
);
STableMeta
*
pDst
=
taosMemoryMalloc
(
len
);
STableMeta
*
pDst
=
taosMemoryMalloc
(
len
);
if
(
NULL
==
pDst
)
{
if
(
NULL
==
pDst
)
{
return
NULL
;
return
NULL
;
...
@@ -211,7 +211,7 @@ static STableMeta* tableMetaClone(const STableMeta* pSrc) {
...
@@ -211,7 +211,7 @@ static STableMeta* tableMetaClone(const STableMeta* pSrc) {
}
}
static
SVgroupsInfo
*
vgroupsInfoClone
(
const
SVgroupsInfo
*
pSrc
)
{
static
SVgroupsInfo
*
vgroupsInfoClone
(
const
SVgroupsInfo
*
pSrc
)
{
int32_t
len
=
VGROUPS_INFO_SIZE
(
pSrc
);
int32_t
len
=
VGROUPS_INFO_SIZE
(
pSrc
);
SVgroupsInfo
*
pDst
=
taosMemoryMalloc
(
len
);
SVgroupsInfo
*
pDst
=
taosMemoryMalloc
(
len
);
if
(
NULL
==
pDst
)
{
if
(
NULL
==
pDst
)
{
return
NULL
;
return
NULL
;
...
...
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
ac874f9e
...
@@ -16,8 +16,8 @@
...
@@ -16,8 +16,8 @@
#include "cmdnodes.h"
#include "cmdnodes.h"
#include "nodesUtil.h"
#include "nodesUtil.h"
#include "plannodes.h"
#include "plannodes.h"
#include "querynodes.h"
#include "query.h"
#include "query.h"
#include "querynodes.h"
#include "taoserror.h"
#include "taoserror.h"
#include "tjson.h"
#include "tjson.h"
...
@@ -29,7 +29,7 @@ static int32_t makeNodeByJson(const SJson* pJson, SNode** pNode);
...
@@ -29,7 +29,7 @@ static int32_t makeNodeByJson(const SJson* pJson, SNode** pNode);
const
char
*
nodesNodeName
(
ENodeType
type
)
{
const
char
*
nodesNodeName
(
ENodeType
type
)
{
switch
(
type
)
{
switch
(
type
)
{
case
QUERY_NODE_COLUMN
:
case
QUERY_NODE_COLUMN
:
return
"Column"
;
return
"Column"
;
case
QUERY_NODE_VALUE
:
case
QUERY_NODE_VALUE
:
return
"Value"
;
return
"Value"
;
case
QUERY_NODE_OPERATOR
:
case
QUERY_NODE_OPERATOR
:
...
@@ -306,7 +306,7 @@ static int32_t tableComInfoToJson(const void* pObj, SJson* pJson) {
...
@@ -306,7 +306,7 @@ static int32_t tableComInfoToJson(const void* pObj, SJson* pJson) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddIntegerToObject
(
pJson
,
jkTableComInfoRowSize
,
pNode
->
rowSize
);
code
=
tjsonAddIntegerToObject
(
pJson
,
jkTableComInfoRowSize
,
pNode
->
rowSize
);
}
}
return
code
;
return
code
;
}
}
...
@@ -323,7 +323,7 @@ static int32_t jsonToTableComInfo(const SJson* pJson, void* pObj) {
...
@@ -323,7 +323,7 @@ static int32_t jsonToTableComInfo(const SJson* pJson, void* pObj) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetNumberValue
(
pJson
,
jkTableComInfoRowSize
,
pNode
->
rowSize
);
code
=
tjsonGetNumberValue
(
pJson
,
jkTableComInfoRowSize
,
pNode
->
rowSize
);
}
}
return
code
;
return
code
;
}
}
...
@@ -345,7 +345,7 @@ static int32_t schemaToJson(const void* pObj, SJson* pJson) {
...
@@ -345,7 +345,7 @@ static int32_t schemaToJson(const void* pObj, SJson* pJson) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddStringToObject
(
pJson
,
jkSchemaName
,
pNode
->
name
);
code
=
tjsonAddStringToObject
(
pJson
,
jkSchemaName
,
pNode
->
name
);
}
}
return
code
;
return
code
;
}
}
...
@@ -362,7 +362,7 @@ static int32_t jsonToSchema(const SJson* pJson, void* pObj) {
...
@@ -362,7 +362,7 @@ static int32_t jsonToSchema(const SJson* pJson, void* pObj) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetStringValue
(
pJson
,
jkSchemaName
,
pNode
->
name
);
code
=
tjsonGetStringValue
(
pJson
,
jkSchemaName
,
pNode
->
name
);
}
}
return
code
;
return
code
;
}
}
...
@@ -398,7 +398,8 @@ static int32_t tableMetaToJson(const void* pObj, SJson* pJson) {
...
@@ -398,7 +398,8 @@ static int32_t tableMetaToJson(const void* pObj, SJson* pJson) {
code
=
tjsonAddObject
(
pJson
,
jkTableMetaComInfo
,
tableComInfoToJson
,
&
pNode
->
tableInfo
);
code
=
tjsonAddObject
(
pJson
,
jkTableMetaComInfo
,
tableComInfoToJson
,
&
pNode
->
tableInfo
);
}
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddArray
(
pJson
,
jkTableMetaColSchemas
,
schemaToJson
,
pNode
->
schema
,
sizeof
(
SSchema
),
TABLE_TOTAL_COL_NUM
(
pNode
));
code
=
tjsonAddArray
(
pJson
,
jkTableMetaColSchemas
,
schemaToJson
,
pNode
->
schema
,
sizeof
(
SSchema
),
TABLE_TOTAL_COL_NUM
(
pNode
));
}
}
return
code
;
return
code
;
...
@@ -713,13 +714,9 @@ static int32_t jsonToPhysiScanNode(const SJson* pJson, void* pObj) {
...
@@ -713,13 +714,9 @@ static int32_t jsonToPhysiScanNode(const SJson* pJson, void* pObj) {
return
code
;
return
code
;
}
}
static
int32_t
physiTagScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
static
int32_t
physiTagScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
return
physiScanNodeToJson
(
pObj
,
pJson
);
}
return
physiScanNodeToJson
(
pObj
,
pJson
);
}
static
int32_t
jsonToPhysiTagScanNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
static
int32_t
jsonToPhysiTagScanNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
return
jsonToPhysiScanNode
(
pJson
,
pObj
);
}
return
jsonToPhysiScanNode
(
pJson
,
pObj
);
}
static
const
char
*
jkTableScanPhysiPlanScanCount
=
"ScanCount"
;
static
const
char
*
jkTableScanPhysiPlanScanCount
=
"ScanCount"
;
static
const
char
*
jkTableScanPhysiPlanReverseScanCount
=
"ReverseScanCount"
;
static
const
char
*
jkTableScanPhysiPlanReverseScanCount
=
"ReverseScanCount"
;
...
@@ -732,7 +729,7 @@ static const char* jkTableScanPhysiPlanInterval = "Interval";
...
@@ -732,7 +729,7 @@ static const char* jkTableScanPhysiPlanInterval = "Interval";
static
const
char
*
jkTableScanPhysiPlanOffset
=
"Offset"
;
static
const
char
*
jkTableScanPhysiPlanOffset
=
"Offset"
;
static
const
char
*
jkTableScanPhysiPlanSliding
=
"Sliding"
;
static
const
char
*
jkTableScanPhysiPlanSliding
=
"Sliding"
;
static
const
char
*
jkTableScanPhysiPlanIntervalUnit
=
"intervalUnit"
;
static
const
char
*
jkTableScanPhysiPlanIntervalUnit
=
"intervalUnit"
;
static
const
char
*
jkTableScanPhysiPlanSlidingUnit
=
"slidingUnit"
;
static
const
char
*
jkTableScanPhysiPlanSlidingUnit
=
"slidingUnit"
;
static
int32_t
physiTableScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
static
int32_t
physiTableScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
STableScanPhysiNode
*
pNode
=
(
const
STableScanPhysiNode
*
)
pObj
;
const
STableScanPhysiNode
*
pNode
=
(
const
STableScanPhysiNode
*
)
pObj
;
...
@@ -822,13 +819,9 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
...
@@ -822,13 +819,9 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
return
code
;
return
code
;
}
}
static
int32_t
physiStreamScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
static
int32_t
physiStreamScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
return
physiScanNodeToJson
(
pObj
,
pJson
);
}
return
physiScanNodeToJson
(
pObj
,
pJson
);
}
static
int32_t
jsonToPhysiStreamScanNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
static
int32_t
jsonToPhysiStreamScanNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
return
jsonToPhysiScanNode
(
pJson
,
pObj
);
}
return
jsonToPhysiScanNode
(
pJson
,
pObj
);
}
static
const
char
*
jkEndPointFqdn
=
"Fqdn"
;
static
const
char
*
jkEndPointFqdn
=
"Fqdn"
;
static
const
char
*
jkEndPointPort
=
"Port"
;
static
const
char
*
jkEndPointPort
=
"Port"
;
...
@@ -1178,7 +1171,7 @@ static const char* jkIntervalPhysiPlanInterval = "Interval";
...
@@ -1178,7 +1171,7 @@ static const char* jkIntervalPhysiPlanInterval = "Interval";
static
const
char
*
jkIntervalPhysiPlanOffset
=
"Offset"
;
static
const
char
*
jkIntervalPhysiPlanOffset
=
"Offset"
;
static
const
char
*
jkIntervalPhysiPlanSliding
=
"Sliding"
;
static
const
char
*
jkIntervalPhysiPlanSliding
=
"Sliding"
;
static
const
char
*
jkIntervalPhysiPlanIntervalUnit
=
"intervalUnit"
;
static
const
char
*
jkIntervalPhysiPlanIntervalUnit
=
"intervalUnit"
;
static
const
char
*
jkIntervalPhysiPlanSlidingUnit
=
"slidingUnit"
;
static
const
char
*
jkIntervalPhysiPlanSlidingUnit
=
"slidingUnit"
;
static
const
char
*
jkIntervalPhysiPlanFill
=
"Fill"
;
static
const
char
*
jkIntervalPhysiPlanFill
=
"Fill"
;
static
int32_t
physiIntervalNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
static
int32_t
physiIntervalNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
...
@@ -1331,13 +1324,9 @@ static int32_t jsonToPhysicDataSinkNode(const SJson* pJson, void* pObj) {
...
@@ -1331,13 +1324,9 @@ static int32_t jsonToPhysicDataSinkNode(const SJson* pJson, void* pObj) {
return
jsonToNodeObject
(
pJson
,
jkDataSinkInputDataBlockDesc
,
(
SNode
**
)
&
pNode
->
pInputDataBlockDesc
);
return
jsonToNodeObject
(
pJson
,
jkDataSinkInputDataBlockDesc
,
(
SNode
**
)
&
pNode
->
pInputDataBlockDesc
);
}
}
static
int32_t
physiDispatchNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
static
int32_t
physiDispatchNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
return
physicDataSinkNodeToJson
(
pObj
,
pJson
);
}
return
physicDataSinkNodeToJson
(
pObj
,
pJson
);
}
static
int32_t
jsonToPhysiDispatchNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
static
int32_t
jsonToPhysiDispatchNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
return
jsonToPhysicDataSinkNode
(
pJson
,
pObj
);
}
return
jsonToPhysicDataSinkNode
(
pJson
,
pObj
);
}
static
const
char
*
jkSubplanIdQueryId
=
"QueryId"
;
static
const
char
*
jkSubplanIdQueryId
=
"QueryId"
;
static
const
char
*
jkSubplanIdGroupId
=
"GroupId"
;
static
const
char
*
jkSubplanIdGroupId
=
"GroupId"
;
...
@@ -1709,7 +1698,7 @@ static int32_t datumToJson(const void* pObj, SJson* pJson) {
...
@@ -1709,7 +1698,7 @@ static int32_t datumToJson(const void* pObj, SJson* pJson) {
break
;
break
;
}
}
return
code
;
return
code
;
}
}
static
int32_t
valueNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
static
int32_t
valueNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
...
@@ -2015,7 +2004,8 @@ static int32_t vgroupsInfoToJson(const void* pObj, SJson* pJson) {
...
@@ -2015,7 +2004,8 @@ static int32_t vgroupsInfoToJson(const void* pObj, SJson* pJson) {
int32_t
code
=
tjsonAddIntegerToObject
(
pJson
,
jkVgroupsInfoNum
,
pNode
->
numOfVgroups
);
int32_t
code
=
tjsonAddIntegerToObject
(
pJson
,
jkVgroupsInfoNum
,
pNode
->
numOfVgroups
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddArray
(
pJson
,
jkVgroupsInfoVgroups
,
vgroupInfoToJson
,
pNode
->
vgroups
,
sizeof
(
SVgroupInfo
),
pNode
->
numOfVgroups
);
code
=
tjsonAddArray
(
pJson
,
jkVgroupsInfoVgroups
,
vgroupInfoToJson
,
pNode
->
vgroups
,
sizeof
(
SVgroupInfo
),
pNode
->
numOfVgroups
);
}
}
return
code
;
return
code
;
...
@@ -2660,10 +2650,10 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
...
@@ -2660,10 +2650,10 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
return
jsonToPhysiTagScanNode
(
pJson
,
pObj
);
return
jsonToPhysiTagScanNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN
:
case
QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN
:
return
jsonToPhysiTableScanNode
(
pJson
,
pObj
);
return
jsonToPhysiTableScanNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
:
case
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
:
return
jsonToPhysiStreamScanNode
(
pJson
,
pObj
);
return
jsonToPhysiStreamScanNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN
:
case
QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN
:
return
jsonToPhysiSysTableScanNode
(
pJson
,
pObj
);
return
jsonToPhysiSysTableScanNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_PROJECT
:
case
QUERY_NODE_PHYSICAL_PLAN_PROJECT
:
return
jsonToPhysiProjectNode
(
pJson
,
pObj
);
return
jsonToPhysiProjectNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_JOIN
:
case
QUERY_NODE_PHYSICAL_PLAN_JOIN
:
...
...
source/libs/nodes/src/nodesEqualFuncs.c
浏览文件 @
ac874f9e
...
@@ -15,32 +15,27 @@
...
@@ -15,32 +15,27 @@
#include "querynodes.h"
#include "querynodes.h"
#define COMPARE_SCALAR_FIELD(fldname) \
#define COMPARE_SCALAR_FIELD(fldname) \
do { \
do { \
if (a->fldname != b->fldname) \
if (a->fldname != b->fldname) return false; \
return false; \
} while (0)
} while (0)
#define COMPARE_STRING(a, b) (((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
#define COMPARE_STRING(a, b) \
(((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
#define COMPARE_STRING_FIELD(fldname) \
do { \
#define COMPARE_STRING_FIELD(fldname) \
if (!COMPARE_STRING(a->fldname, b->fldname)) return false; \
do { \
} while (0)
if (!COMPARE_STRING(a->fldname, b->fldname)) \
return false; \
#define COMPARE_NODE_FIELD(fldname) \
} while (0)
do { \
if (!nodesEqualNode(a->fldname, b->fldname)) return false; \
#define COMPARE_NODE_FIELD(fldname) \
} while (0)
do { \
if (!nodesEqualNode(a->fldname, b->fldname)) \
#define COMPARE_NODE_LIST_FIELD(fldname) \
return false; \
do { \
} while (0)
if (!nodeNodeListEqual(a->fldname, b->fldname)) return false; \
} while (0)
#define COMPARE_NODE_LIST_FIELD(fldname) \
do { \
if (!nodeNodeListEqual(a->fldname, b->fldname)) \
return false; \
} while (0)
static
bool
nodeNodeListEqual
(
const
SNodeList
*
a
,
const
SNodeList
*
b
)
{
static
bool
nodeNodeListEqual
(
const
SNodeList
*
a
,
const
SNodeList
*
b
)
{
if
(
a
==
b
)
{
if
(
a
==
b
)
{
...
@@ -55,7 +50,7 @@ static bool nodeNodeListEqual(const SNodeList* a, const SNodeList* b) {
...
@@ -55,7 +50,7 @@ static bool nodeNodeListEqual(const SNodeList* a, const SNodeList* b) {
return
false
;
return
false
;
}
}
SNode
*
na
,
*
nb
;
SNode
*
na
,
*
nb
;
FORBOTH
(
na
,
a
,
nb
,
b
)
{
FORBOTH
(
na
,
a
,
nb
,
b
)
{
if
(
!
nodesEqualNode
(
na
,
nb
))
{
if
(
!
nodesEqualNode
(
na
,
nb
))
{
return
false
;
return
false
;
...
@@ -125,7 +120,7 @@ bool nodesEqualNode(const SNodeptr a, const SNodeptr b) {
...
@@ -125,7 +120,7 @@ bool nodesEqualNode(const SNodeptr a, const SNodeptr b) {
case
QUERY_NODE_GROUPING_SET
:
case
QUERY_NODE_GROUPING_SET
:
case
QUERY_NODE_ORDER_BY_EXPR
:
case
QUERY_NODE_ORDER_BY_EXPR
:
case
QUERY_NODE_LIMIT
:
case
QUERY_NODE_LIMIT
:
return
false
;
// todo
return
false
;
// todo
default:
default:
break
;
break
;
}
}
...
...
source/libs/nodes/src/nodesToSQLFuncs.c
浏览文件 @
ac874f9e
...
@@ -21,9 +21,35 @@
...
@@ -21,9 +21,35 @@
#include "taoserror.h"
#include "taoserror.h"
#include "thash.h"
#include "thash.h"
char
*
gOperatorStr
[]
=
{
NULL
,
"+"
,
"-"
,
"*"
,
"/"
,
"%"
,
"-"
,
"&"
,
"|"
,
">"
,
">="
,
"<"
,
"<="
,
"="
,
"<>"
,
char
*
gOperatorStr
[]
=
{
NULL
,
"IN"
,
"NOT IN"
,
"LIKE"
,
"NOT LIKE"
,
"MATCH"
,
"NMATCH"
,
"IS NULL"
,
"IS NOT NULL"
,
"+"
,
"IS TRUE"
,
"IS FALSE"
,
"IS UNKNOWN"
,
"IS NOT TRUE"
,
"IS NOT FALSE"
,
"IS NOT UNKNOWN"
};
"-"
,
"*"
,
"/"
,
"%"
,
"-"
,
"&"
,
"|"
,
">"
,
">="
,
"<"
,
"<="
,
"="
,
"<>"
,
"IN"
,
"NOT IN"
,
"LIKE"
,
"NOT LIKE"
,
"MATCH"
,
"NMATCH"
,
"IS NULL"
,
"IS NOT NULL"
,
"IS TRUE"
,
"IS FALSE"
,
"IS UNKNOWN"
,
"IS NOT TRUE"
,
"IS NOT FALSE"
,
"IS NOT UNKNOWN"
};
char
*
gLogicConditionStr
[]
=
{
"AND"
,
"OR"
,
"NOT"
};
char
*
gLogicConditionStr
[]
=
{
"AND"
,
"OR"
,
"NOT"
};
int32_t
nodesNodeToSQL
(
SNode
*
pNode
,
char
*
buf
,
int32_t
bufSize
,
int32_t
*
len
)
{
int32_t
nodesNodeToSQL
(
SNode
*
pNode
,
char
*
buf
,
int32_t
bufSize
,
int32_t
*
len
)
{
...
@@ -33,36 +59,36 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
...
@@ -33,36 +59,36 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
if
(
colNode
->
dbName
[
0
])
{
if
(
colNode
->
dbName
[
0
])
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"`%s`."
,
colNode
->
dbName
);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"`%s`."
,
colNode
->
dbName
);
}
}
if
(
colNode
->
tableAlias
[
0
])
{
if
(
colNode
->
tableAlias
[
0
])
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"`%s`."
,
colNode
->
tableAlias
);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"`%s`."
,
colNode
->
tableAlias
);
}
else
if
(
colNode
->
tableName
[
0
])
{
}
else
if
(
colNode
->
tableName
[
0
])
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"`%s`."
,
colNode
->
tableName
);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"`%s`."
,
colNode
->
tableName
);
}
}
if
(
colNode
->
tableAlias
[
0
])
{
if
(
colNode
->
tableAlias
[
0
])
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"`%s`"
,
colNode
->
colName
);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"`%s`"
,
colNode
->
colName
);
}
else
{
}
else
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"%s"
,
colNode
->
colName
);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"%s"
,
colNode
->
colName
);
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
case
QUERY_NODE_VALUE
:{
case
QUERY_NODE_VALUE
:
{
SValueNode
*
colNode
=
(
SValueNode
*
)
pNode
;
SValueNode
*
colNode
=
(
SValueNode
*
)
pNode
;
char
*
t
=
nodesGetStrValueFromNode
(
colNode
);
char
*
t
=
nodesGetStrValueFromNode
(
colNode
);
if
(
NULL
==
t
)
{
if
(
NULL
==
t
)
{
nodesError
(
"fail to get str value from valueNode"
);
nodesError
(
"fail to get str value from valueNode"
);
NODES_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
NODES_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
}
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"%s"
,
t
);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"%s"
,
t
);
taosMemoryFree
(
t
);
taosMemoryFree
(
t
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
case
QUERY_NODE_OPERATOR
:
{
case
QUERY_NODE_OPERATOR
:
{
SOperatorNode
*
pOpNode
=
(
SOperatorNode
*
)
pNode
;
SOperatorNode
*
pOpNode
=
(
SOperatorNode
*
)
pNode
;
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"("
);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"("
);
if
(
pOpNode
->
pLeft
)
{
if
(
pOpNode
->
pLeft
)
{
NODES_ERR_RET
(
nodesNodeToSQL
(
pOpNode
->
pLeft
,
buf
,
bufSize
,
len
));
NODES_ERR_RET
(
nodesNodeToSQL
(
pOpNode
->
pLeft
,
buf
,
bufSize
,
len
));
...
@@ -72,24 +98,24 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
...
@@ -72,24 +98,24 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
nodesError
(
"unknown operation type:%d"
,
pOpNode
->
opType
);
nodesError
(
"unknown operation type:%d"
,
pOpNode
->
opType
);
NODES_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
NODES_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
}
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
" %s "
,
gOperatorStr
[
pOpNode
->
opType
]);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
" %s "
,
gOperatorStr
[
pOpNode
->
opType
]);
if
(
pOpNode
->
pRight
)
{
if
(
pOpNode
->
pRight
)
{
NODES_ERR_RET
(
nodesNodeToSQL
(
pOpNode
->
pRight
,
buf
,
bufSize
,
len
));
NODES_ERR_RET
(
nodesNodeToSQL
(
pOpNode
->
pRight
,
buf
,
bufSize
,
len
));
}
}
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
")"
);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
")"
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
case
QUERY_NODE_LOGIC_CONDITION
:{
case
QUERY_NODE_LOGIC_CONDITION
:
{
SLogicConditionNode
*
pLogicNode
=
(
SLogicConditionNode
*
)
pNode
;
SLogicConditionNode
*
pLogicNode
=
(
SLogicConditionNode
*
)
pNode
;
SNode
*
node
=
NULL
;
SNode
*
node
=
NULL
;
bool
first
=
true
;
bool
first
=
true
;
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"("
);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"("
);
FOREACH
(
node
,
pLogicNode
->
pParameterList
)
{
FOREACH
(
node
,
pLogicNode
->
pParameterList
)
{
if
(
!
first
)
{
if
(
!
first
)
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
" %s "
,
gLogicConditionStr
[
pLogicNode
->
condType
]);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
" %s "
,
gLogicConditionStr
[
pLogicNode
->
condType
]);
...
@@ -102,13 +128,13 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
...
@@ -102,13 +128,13 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
case
QUERY_NODE_FUNCTION
:{
case
QUERY_NODE_FUNCTION
:
{
SFunctionNode
*
pFuncNode
=
(
SFunctionNode
*
)
pNode
;
SFunctionNode
*
pFuncNode
=
(
SFunctionNode
*
)
pNode
;
SNode
*
node
=
NULL
;
SNode
*
node
=
NULL
;
bool
first
=
true
;
bool
first
=
true
;
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"%s("
,
pFuncNode
->
functionName
);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"%s("
,
pFuncNode
->
functionName
);
FOREACH
(
node
,
pFuncNode
->
pParameterList
)
{
FOREACH
(
node
,
pFuncNode
->
pParameterList
)
{
if
(
!
first
)
{
if
(
!
first
)
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
", "
);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
", "
);
...
@@ -121,13 +147,13 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
...
@@ -121,13 +147,13 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
case
QUERY_NODE_NODE_LIST
:{
case
QUERY_NODE_NODE_LIST
:
{
SNodeListNode
*
pListNode
=
(
SNodeListNode
*
)
pNode
;
SNodeListNode
*
pListNode
=
(
SNodeListNode
*
)
pNode
;
SNode
*
node
=
NULL
;
SNode
*
node
=
NULL
;
bool
first
=
true
;
bool
first
=
true
;
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"("
);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"("
);
FOREACH
(
node
,
pListNode
->
pNodeList
)
{
FOREACH
(
node
,
pListNode
->
pNodeList
)
{
if
(
!
first
)
{
if
(
!
first
)
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
", "
);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
", "
);
...
@@ -135,7 +161,7 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
...
@@ -135,7 +161,7 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
NODES_ERR_RET
(
nodesNodeToSQL
(
node
,
buf
,
bufSize
,
len
));
NODES_ERR_RET
(
nodesNodeToSQL
(
node
,
buf
,
bufSize
,
len
));
first
=
false
;
first
=
false
;
}
}
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
")"
);
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
")"
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -143,7 +169,7 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
...
@@ -143,7 +169,7 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
default:
default:
break
;
break
;
}
}
nodesError
(
"nodesNodeToSQL unknown node = %s"
,
nodesNodeName
(
pNode
->
type
));
nodesError
(
"nodesNodeToSQL unknown node = %s"
,
nodesNodeName
(
pNode
->
type
));
NODES_RET
(
TSDB_CODE_QRY_APP_ERROR
);
NODES_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
}
source/libs/nodes/src/nodesTraverseFuncs.c
浏览文件 @
ac874f9e
...
@@ -13,8 +13,8 @@
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "querynodes.h"
#include "plannodes.h"
#include "plannodes.h"
#include "querynodes.h"
typedef
enum
ETraversalOrder
{
typedef
enum
ETraversalOrder
{
TRAVERSAL_PREORDER
=
1
,
TRAVERSAL_PREORDER
=
1
,
...
@@ -29,7 +29,8 @@ static EDealRes walkExprs(SNodeList* pNodeList, ETraversalOrder order, FNodeWalk
...
@@ -29,7 +29,8 @@ static EDealRes walkExprs(SNodeList* pNodeList, ETraversalOrder order, FNodeWalk
static
EDealRes
walkPhysiPlan
(
SNode
*
pNode
,
ETraversalOrder
order
,
FNodeWalker
walker
,
void
*
pContext
);
static
EDealRes
walkPhysiPlan
(
SNode
*
pNode
,
ETraversalOrder
order
,
FNodeWalker
walker
,
void
*
pContext
);
static
EDealRes
walkPhysiPlans
(
SNodeList
*
pNodeList
,
ETraversalOrder
order
,
FNodeWalker
walker
,
void
*
pContext
);
static
EDealRes
walkPhysiPlans
(
SNodeList
*
pNodeList
,
ETraversalOrder
order
,
FNodeWalker
walker
,
void
*
pContext
);
static
EDealRes
walkNode
(
SNode
*
pNode
,
ETraversalOrder
order
,
FNodeWalker
walker
,
void
*
pContext
,
FNodeDispatcher
dispatcher
)
{
static
EDealRes
walkNode
(
SNode
*
pNode
,
ETraversalOrder
order
,
FNodeWalker
walker
,
void
*
pContext
,
FNodeDispatcher
dispatcher
)
{
if
(
NULL
==
pNode
)
{
if
(
NULL
==
pNode
)
{
return
DEAL_RES_CONTINUE
;
return
DEAL_RES_CONTINUE
;
}
}
...
@@ -77,7 +78,7 @@ static EDealRes dispatchExpr(SNode* pNode, ETraversalOrder order, FNodeWalker wa
...
@@ -77,7 +78,7 @@ static EDealRes dispatchExpr(SNode* pNode, ETraversalOrder order, FNodeWalker wa
break
;
break
;
case
QUERY_NODE_REAL_TABLE
:
case
QUERY_NODE_REAL_TABLE
:
case
QUERY_NODE_TEMP_TABLE
:
case
QUERY_NODE_TEMP_TABLE
:
break
;
// todo
break
;
// todo
case
QUERY_NODE_JOIN_TABLE
:
{
case
QUERY_NODE_JOIN_TABLE
:
{
SJoinTableNode
*
pJoinTableNode
=
(
SJoinTableNode
*
)
pNode
;
SJoinTableNode
*
pJoinTableNode
=
(
SJoinTableNode
*
)
pNode
;
res
=
walkExpr
(
pJoinTableNode
->
pLeft
,
order
,
walker
,
pContext
);
res
=
walkExpr
(
pJoinTableNode
->
pLeft
,
order
,
walker
,
pContext
);
...
@@ -217,7 +218,7 @@ static EDealRes rewriteExpr(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
...
@@ -217,7 +218,7 @@ static EDealRes rewriteExpr(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
break
;
break
;
case
QUERY_NODE_REAL_TABLE
:
case
QUERY_NODE_REAL_TABLE
:
case
QUERY_NODE_TEMP_TABLE
:
case
QUERY_NODE_TEMP_TABLE
:
break
;
// todo
break
;
// todo
case
QUERY_NODE_JOIN_TABLE
:
{
case
QUERY_NODE_JOIN_TABLE
:
{
SJoinTableNode
*
pJoinTableNode
=
(
SJoinTableNode
*
)
pNode
;
SJoinTableNode
*
pJoinTableNode
=
(
SJoinTableNode
*
)
pNode
;
res
=
rewriteExpr
(
&
(
pJoinTableNode
->
pLeft
),
order
,
rewriter
,
pContext
);
res
=
rewriteExpr
(
&
(
pJoinTableNode
->
pLeft
),
order
,
rewriter
,
pContext
);
...
@@ -339,7 +340,7 @@ void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker wa
...
@@ -339,7 +340,7 @@ void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker wa
case
SQL_CLAUSE_DISTINCT
:
case
SQL_CLAUSE_DISTINCT
:
nodesWalkExprs
(
pSelect
->
pOrderByList
,
walker
,
pContext
);
nodesWalkExprs
(
pSelect
->
pOrderByList
,
walker
,
pContext
);
case
SQL_CLAUSE_ORDER_BY
:
case
SQL_CLAUSE_ORDER_BY
:
nodesWalkExprs
(
pSelect
->
pProjectionList
,
walker
,
pContext
);
nodesWalkExprs
(
pSelect
->
pProjectionList
,
walker
,
pContext
);
default:
default:
break
;
break
;
}
}
...
@@ -368,7 +369,7 @@ void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewrit
...
@@ -368,7 +369,7 @@ void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewrit
case
SQL_CLAUSE_DISTINCT
:
case
SQL_CLAUSE_DISTINCT
:
nodesRewriteExprs
(
pSelect
->
pOrderByList
,
rewriter
,
pContext
);
nodesRewriteExprs
(
pSelect
->
pOrderByList
,
rewriter
,
pContext
);
case
SQL_CLAUSE_ORDER_BY
:
case
SQL_CLAUSE_ORDER_BY
:
nodesRewriteExprs
(
pSelect
->
pProjectionList
,
rewriter
,
pContext
);
nodesRewriteExprs
(
pSelect
->
pProjectionList
,
rewriter
,
pContext
);
default:
default:
break
;
break
;
}
}
...
@@ -395,7 +396,8 @@ static EDealRes walkScanPhysi(SScanPhysiNode* pScan, ETraversalOrder order, FNod
...
@@ -395,7 +396,8 @@ static EDealRes walkScanPhysi(SScanPhysiNode* pScan, ETraversalOrder order, FNod
return
res
;
return
res
;
}
}
static
EDealRes
walkTableScanPhysi
(
STableScanPhysiNode
*
pScan
,
ETraversalOrder
order
,
FNodeWalker
walker
,
void
*
pContext
)
{
static
EDealRes
walkTableScanPhysi
(
STableScanPhysiNode
*
pScan
,
ETraversalOrder
order
,
FNodeWalker
walker
,
void
*
pContext
)
{
EDealRes
res
=
walkScanPhysi
((
SScanPhysiNode
*
)
pScan
,
order
,
walker
,
pContext
);
EDealRes
res
=
walkScanPhysi
((
SScanPhysiNode
*
)
pScan
,
order
,
walker
,
pContext
);
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
walkPhysiPlans
(
pScan
->
pDynamicScanFuncs
,
order
,
walker
,
pContext
);
res
=
walkPhysiPlans
(
pScan
->
pDynamicScanFuncs
,
order
,
walker
,
pContext
);
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
ac874f9e
...
@@ -97,7 +97,7 @@ SNodeptr nodesMakeNode(ENodeType type) {
...
@@ -97,7 +97,7 @@ SNodeptr nodesMakeNode(ENodeType type) {
case
QUERY_NODE_CREATE_DATABASE_STMT
:
case
QUERY_NODE_CREATE_DATABASE_STMT
:
return
makeNode
(
type
,
sizeof
(
SCreateDatabaseStmt
));
return
makeNode
(
type
,
sizeof
(
SCreateDatabaseStmt
));
case
QUERY_NODE_DROP_DATABASE_STMT
:
case
QUERY_NODE_DROP_DATABASE_STMT
:
return
makeNode
(
type
,
sizeof
(
SDropDatabaseStmt
));
return
makeNode
(
type
,
sizeof
(
SDropDatabaseStmt
));
case
QUERY_NODE_ALTER_DATABASE_STMT
:
case
QUERY_NODE_ALTER_DATABASE_STMT
:
return
makeNode
(
type
,
sizeof
(
SAlterDatabaseStmt
));
return
makeNode
(
type
,
sizeof
(
SAlterDatabaseStmt
));
case
QUERY_NODE_CREATE_TABLE_STMT
:
case
QUERY_NODE_CREATE_TABLE_STMT
:
...
@@ -298,9 +298,7 @@ static void destroyScanPhysiNode(SScanPhysiNode* pNode) {
...
@@ -298,9 +298,7 @@ static void destroyScanPhysiNode(SScanPhysiNode* pNode) {
nodesDestroyList
(
pNode
->
pScanCols
);
nodesDestroyList
(
pNode
->
pScanCols
);
}
}
static
void
destroyDataSinkNode
(
SDataSinkNode
*
pNode
)
{
static
void
destroyDataSinkNode
(
SDataSinkNode
*
pNode
)
{
nodesDestroyNode
(
pNode
->
pInputDataBlockDesc
);
}
nodesDestroyNode
(
pNode
->
pInputDataBlockDesc
);
}
void
nodesDestroyNode
(
SNodeptr
pNode
)
{
void
nodesDestroyNode
(
SNodeptr
pNode
)
{
if
(
NULL
==
pNode
)
{
if
(
NULL
==
pNode
)
{
...
@@ -308,7 +306,7 @@ void nodesDestroyNode(SNodeptr pNode) {
...
@@ -308,7 +306,7 @@ void nodesDestroyNode(SNodeptr pNode) {
}
}
switch
(
nodeType
(
pNode
))
{
switch
(
nodeType
(
pNode
))
{
case
QUERY_NODE_COLUMN
:
// pProjectRef is weak reference, no need to release
case
QUERY_NODE_COLUMN
:
// pProjectRef is weak reference, no need to release
break
;
break
;
case
QUERY_NODE_VALUE
:
{
case
QUERY_NODE_VALUE
:
{
SValueNode
*
pValue
=
(
SValueNode
*
)
pNode
;
SValueNode
*
pValue
=
(
SValueNode
*
)
pNode
;
...
@@ -352,7 +350,7 @@ void nodesDestroyNode(SNodeptr pNode) {
...
@@ -352,7 +350,7 @@ void nodesDestroyNode(SNodeptr pNode) {
case
QUERY_NODE_ORDER_BY_EXPR
:
case
QUERY_NODE_ORDER_BY_EXPR
:
nodesDestroyNode
(((
SOrderByExprNode
*
)
pNode
)
->
pExpr
);
nodesDestroyNode
(((
SOrderByExprNode
*
)
pNode
)
->
pExpr
);
break
;
break
;
case
QUERY_NODE_LIMIT
:
// no pointer field
case
QUERY_NODE_LIMIT
:
// no pointer field
break
;
break
;
case
QUERY_NODE_STATE_WINDOW
:
case
QUERY_NODE_STATE_WINDOW
:
nodesDestroyNode
(((
SStateWindowNode
*
)
pNode
)
->
pExpr
);
nodesDestroyNode
(((
SStateWindowNode
*
)
pNode
)
->
pExpr
);
...
@@ -387,9 +385,9 @@ void nodesDestroyNode(SNodeptr pNode) {
...
@@ -387,9 +385,9 @@ void nodesDestroyNode(SNodeptr pNode) {
case
QUERY_NODE_DATABLOCK_DESC
:
case
QUERY_NODE_DATABLOCK_DESC
:
nodesDestroyList
(((
SDataBlockDescNode
*
)
pNode
)
->
pSlots
);
nodesDestroyList
(((
SDataBlockDescNode
*
)
pNode
)
->
pSlots
);
break
;
break
;
case
QUERY_NODE_SLOT_DESC
:
// no pointer field
case
QUERY_NODE_SLOT_DESC
:
// no pointer field
case
QUERY_NODE_COLUMN_DEF
:
// no pointer field
case
QUERY_NODE_COLUMN_DEF
:
// no pointer field
case
QUERY_NODE_DOWNSTREAM_SOURCE
:
// no pointer field
case
QUERY_NODE_DOWNSTREAM_SOURCE
:
// no pointer field
break
;
break
;
case
QUERY_NODE_DATABASE_OPTIONS
:
case
QUERY_NODE_DATABASE_OPTIONS
:
nodesDestroyList
(((
SDatabaseOptions
*
)
pNode
)
->
pRetentions
);
nodesDestroyList
(((
SDatabaseOptions
*
)
pNode
)
->
pRetentions
);
...
@@ -436,7 +434,7 @@ void nodesDestroyNode(SNodeptr pNode) {
...
@@ -436,7 +434,7 @@ void nodesDestroyNode(SNodeptr pNode) {
case
QUERY_NODE_CREATE_DATABASE_STMT
:
case
QUERY_NODE_CREATE_DATABASE_STMT
:
nodesDestroyNode
(((
SCreateDatabaseStmt
*
)
pNode
)
->
pOptions
);
nodesDestroyNode
(((
SCreateDatabaseStmt
*
)
pNode
)
->
pOptions
);
break
;
break
;
case
QUERY_NODE_DROP_DATABASE_STMT
:
// no pointer field
case
QUERY_NODE_DROP_DATABASE_STMT
:
// no pointer field
break
;
break
;
case
QUERY_NODE_ALTER_DATABASE_STMT
:
case
QUERY_NODE_ALTER_DATABASE_STMT
:
nodesDestroyNode
(((
SAlterDatabaseStmt
*
)
pNode
)
->
pOptions
);
nodesDestroyNode
(((
SAlterDatabaseStmt
*
)
pNode
)
->
pOptions
);
...
@@ -457,12 +455,12 @@ void nodesDestroyNode(SNodeptr pNode) {
...
@@ -457,12 +455,12 @@ void nodesDestroyNode(SNodeptr pNode) {
case
QUERY_NODE_CREATE_MULTI_TABLE_STMT
:
case
QUERY_NODE_CREATE_MULTI_TABLE_STMT
:
nodesDestroyList
(((
SCreateMultiTableStmt
*
)
pNode
)
->
pSubTables
);
nodesDestroyList
(((
SCreateMultiTableStmt
*
)
pNode
)
->
pSubTables
);
break
;
break
;
case
QUERY_NODE_DROP_TABLE_CLAUSE
:
// no pointer field
case
QUERY_NODE_DROP_TABLE_CLAUSE
:
// no pointer field
break
;
break
;
case
QUERY_NODE_DROP_TABLE_STMT
:
case
QUERY_NODE_DROP_TABLE_STMT
:
nodesDestroyNode
(((
SDropTableStmt
*
)
pNode
)
->
pTables
);
nodesDestroyNode
(((
SDropTableStmt
*
)
pNode
)
->
pTables
);
break
;
break
;
case
QUERY_NODE_DROP_SUPER_TABLE_STMT
:
// no pointer field
case
QUERY_NODE_DROP_SUPER_TABLE_STMT
:
// no pointer field
break
;
break
;
case
QUERY_NODE_ALTER_TABLE_STMT
:
{
case
QUERY_NODE_ALTER_TABLE_STMT
:
{
SAlterTableStmt
*
pStmt
=
(
SAlterTableStmt
*
)
pNode
;
SAlterTableStmt
*
pStmt
=
(
SAlterTableStmt
*
)
pNode
;
...
@@ -470,13 +468,13 @@ void nodesDestroyNode(SNodeptr pNode) {
...
@@ -470,13 +468,13 @@ void nodesDestroyNode(SNodeptr pNode) {
nodesDestroyNode
(
pStmt
->
pVal
);
nodesDestroyNode
(
pStmt
->
pVal
);
break
;
break
;
}
}
case
QUERY_NODE_CREATE_USER_STMT
:
// no pointer field
case
QUERY_NODE_CREATE_USER_STMT
:
// no pointer field
case
QUERY_NODE_ALTER_USER_STMT
:
// no pointer field
case
QUERY_NODE_ALTER_USER_STMT
:
// no pointer field
case
QUERY_NODE_DROP_USER_STMT
:
// no pointer field
case
QUERY_NODE_DROP_USER_STMT
:
// no pointer field
case
QUERY_NODE_USE_DATABASE_STMT
:
// no pointer field
case
QUERY_NODE_USE_DATABASE_STMT
:
// no pointer field
case
QUERY_NODE_CREATE_DNODE_STMT
:
// no pointer field
case
QUERY_NODE_CREATE_DNODE_STMT
:
// no pointer field
case
QUERY_NODE_DROP_DNODE_STMT
:
// no pointer field
case
QUERY_NODE_DROP_DNODE_STMT
:
// no pointer field
case
QUERY_NODE_ALTER_DNODE_STMT
:
// no pointer field
case
QUERY_NODE_ALTER_DNODE_STMT
:
// no pointer field
break
;
break
;
case
QUERY_NODE_CREATE_INDEX_STMT
:
{
case
QUERY_NODE_CREATE_INDEX_STMT
:
{
SCreateIndexStmt
*
pStmt
=
(
SCreateIndexStmt
*
)
pNode
;
SCreateIndexStmt
*
pStmt
=
(
SCreateIndexStmt
*
)
pNode
;
...
@@ -484,15 +482,15 @@ void nodesDestroyNode(SNodeptr pNode) {
...
@@ -484,15 +482,15 @@ void nodesDestroyNode(SNodeptr pNode) {
nodesDestroyList
(
pStmt
->
pCols
);
nodesDestroyList
(
pStmt
->
pCols
);
break
;
break
;
}
}
case
QUERY_NODE_DROP_INDEX_STMT
:
// no pointer field
case
QUERY_NODE_DROP_INDEX_STMT
:
// no pointer field
case
QUERY_NODE_CREATE_QNODE_STMT
:
// no pointer field
case
QUERY_NODE_CREATE_QNODE_STMT
:
// no pointer field
case
QUERY_NODE_DROP_QNODE_STMT
:
// no pointer field
case
QUERY_NODE_DROP_QNODE_STMT
:
// no pointer field
break
;
break
;
case
QUERY_NODE_CREATE_TOPIC_STMT
:
case
QUERY_NODE_CREATE_TOPIC_STMT
:
nodesDestroyNode
(((
SCreateTopicStmt
*
)
pNode
)
->
pQuery
);
nodesDestroyNode
(((
SCreateTopicStmt
*
)
pNode
)
->
pQuery
);
break
;
break
;
case
QUERY_NODE_DROP_TOPIC_STMT
:
// no pointer field
case
QUERY_NODE_DROP_TOPIC_STMT
:
// no pointer field
case
QUERY_NODE_ALTER_LOCAL_STMT
:
// no pointer field
case
QUERY_NODE_ALTER_LOCAL_STMT
:
// no pointer field
break
;
break
;
case
QUERY_NODE_SHOW_DATABASES_STMT
:
case
QUERY_NODE_SHOW_DATABASES_STMT
:
case
QUERY_NODE_SHOW_TABLES_STMT
:
case
QUERY_NODE_SHOW_TABLES_STMT
:
...
@@ -658,7 +656,7 @@ void nodesDestroyNode(SNodeptr pNode) {
...
@@ -658,7 +656,7 @@ void nodesDestroyNode(SNodeptr pNode) {
SQueryPlan
*
pPlan
=
(
SQueryPlan
*
)
pNode
;
SQueryPlan
*
pPlan
=
(
SQueryPlan
*
)
pNode
;
if
(
NULL
!=
pPlan
->
pSubplans
)
{
if
(
NULL
!=
pPlan
->
pSubplans
)
{
// only need to destroy the top-level subplans, because they will recurse to all the subplans below
// only need to destroy the top-level subplans, because they will recurse to all the subplans below
bool
first
=
true
;
bool
first
=
true
;
SNode
*
pElement
=
NULL
;
SNode
*
pElement
=
NULL
;
FOREACH
(
pElement
,
pPlan
->
pSubplans
)
{
FOREACH
(
pElement
,
pPlan
->
pSubplans
)
{
if
(
first
)
{
if
(
first
)
{
...
@@ -866,7 +864,7 @@ void nodesClearList(SNodeList* pList) {
...
@@ -866,7 +864,7 @@ void nodesClearList(SNodeList* pList) {
taosMemoryFreeClear
(
pList
);
taosMemoryFreeClear
(
pList
);
}
}
void
*
nodesGetValueFromNode
(
SValueNode
*
pNode
)
{
void
*
nodesGetValueFromNode
(
SValueNode
*
pNode
)
{
switch
(
pNode
->
node
.
resType
.
type
)
{
switch
(
pNode
->
node
.
resType
.
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_BOOL
:
return
(
void
*
)
&
pNode
->
datum
.
b
;
return
(
void
*
)
&
pNode
->
datum
.
b
;
...
@@ -895,10 +893,10 @@ void* nodesGetValueFromNode(SValueNode *pNode) {
...
@@ -895,10 +893,10 @@ void* nodesGetValueFromNode(SValueNode *pNode) {
return
NULL
;
return
NULL
;
}
}
char
*
nodesGetStrValueFromNode
(
SValueNode
*
pNode
)
{
char
*
nodesGetStrValueFromNode
(
SValueNode
*
pNode
)
{
switch
(
pNode
->
node
.
resType
.
type
)
{
switch
(
pNode
->
node
.
resType
.
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
{
case
TSDB_DATA_TYPE_BOOL
:
{
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
if
(
NULL
==
buf
)
{
if
(
NULL
==
buf
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -911,7 +909,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
...
@@ -911,7 +909,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
if
(
NULL
==
buf
)
{
if
(
NULL
==
buf
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -923,7 +921,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
...
@@ -923,7 +921,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
case
TSDB_DATA_TYPE_USMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
{
case
TSDB_DATA_TYPE_UBIGINT
:
{
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
if
(
NULL
==
buf
)
{
if
(
NULL
==
buf
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -933,7 +931,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
...
@@ -933,7 +931,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
}
}
case
TSDB_DATA_TYPE_FLOAT
:
case
TSDB_DATA_TYPE_FLOAT
:
case
TSDB_DATA_TYPE_DOUBLE
:
{
case
TSDB_DATA_TYPE_DOUBLE
:
{
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
if
(
NULL
==
buf
)
{
if
(
NULL
==
buf
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -945,7 +943,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
...
@@ -945,7 +943,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
case
TSDB_DATA_TYPE_VARCHAR
:
case
TSDB_DATA_TYPE_VARCHAR
:
case
TSDB_DATA_TYPE_VARBINARY
:
{
case
TSDB_DATA_TYPE_VARBINARY
:
{
int32_t
bufSize
=
varDataLen
(
pNode
->
datum
.
p
)
+
2
+
1
;
int32_t
bufSize
=
varDataLen
(
pNode
->
datum
.
p
)
+
2
+
1
;
void
*
buf
=
taosMemoryMalloc
(
bufSize
);
void
*
buf
=
taosMemoryMalloc
(
bufSize
);
if
(
NULL
==
buf
)
{
if
(
NULL
==
buf
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -962,7 +960,8 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
...
@@ -962,7 +960,8 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
bool
nodesIsExprNode
(
const
SNode
*
pNode
)
{
bool
nodesIsExprNode
(
const
SNode
*
pNode
)
{
ENodeType
type
=
nodeType
(
pNode
);
ENodeType
type
=
nodeType
(
pNode
);
return
(
QUERY_NODE_COLUMN
==
type
||
QUERY_NODE_VALUE
==
type
||
QUERY_NODE_OPERATOR
==
type
||
QUERY_NODE_FUNCTION
==
type
);
return
(
QUERY_NODE_COLUMN
==
type
||
QUERY_NODE_VALUE
==
type
||
QUERY_NODE_OPERATOR
==
type
||
QUERY_NODE_FUNCTION
==
type
);
}
}
bool
nodesIsUnaryOp
(
const
SOperatorNode
*
pOp
)
{
bool
nodesIsUnaryOp
(
const
SOperatorNode
*
pOp
)
{
...
@@ -1037,23 +1036,19 @@ bool nodesIsJsonOp(const SOperatorNode* pOp) {
...
@@ -1037,23 +1036,19 @@ bool nodesIsJsonOp(const SOperatorNode* pOp) {
return
false
;
return
false
;
}
}
bool
nodesIsTimeorderQuery
(
const
SNode
*
pQuery
)
{
bool
nodesIsTimeorderQuery
(
const
SNode
*
pQuery
)
{
return
false
;
}
return
false
;
}
bool
nodesIsTimelineQuery
(
const
SNode
*
pQuery
)
{
bool
nodesIsTimelineQuery
(
const
SNode
*
pQuery
)
{
return
false
;
}
return
false
;
}
typedef
struct
SCollectColumnsCxt
{
typedef
struct
SCollectColumnsCxt
{
int32_t
errCode
;
int32_t
errCode
;
const
char
*
pTableAlias
;
const
char
*
pTableAlias
;
SNodeList
*
pCols
;
SNodeList
*
pCols
;
SHashObj
*
pColHash
;
SHashObj
*
pColHash
;
}
SCollectColumnsCxt
;
}
SCollectColumnsCxt
;
static
EDealRes
doCollect
(
SCollectColumnsCxt
*
pCxt
,
SColumnNode
*
pCol
,
SNode
*
pNode
)
{
static
EDealRes
doCollect
(
SCollectColumnsCxt
*
pCxt
,
SColumnNode
*
pCol
,
SNode
*
pNode
)
{
char
name
[
TSDB_TABLE_NAME_LEN
+
TSDB_COL_NAME_LEN
];
char
name
[
TSDB_TABLE_NAME_LEN
+
TSDB_COL_NAME_LEN
];
int32_t
len
=
0
;
int32_t
len
=
0
;
if
(
'\0'
==
pCol
->
tableAlias
[
0
])
{
if
(
'\0'
==
pCol
->
tableAlias
[
0
])
{
len
=
sprintf
(
name
,
"%s"
,
pCol
->
colName
);
len
=
sprintf
(
name
,
"%s"
,
pCol
->
colName
);
...
@@ -1086,11 +1081,10 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char*
...
@@ -1086,11 +1081,10 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char*
}
}
SCollectColumnsCxt
cxt
=
{
SCollectColumnsCxt
cxt
=
{
.
errCode
=
TSDB_CODE_SUCCESS
,
.
errCode
=
TSDB_CODE_SUCCESS
,
.
pTableAlias
=
pTableAlias
,
.
pTableAlias
=
pTableAlias
,
.
pCols
=
nodesMakeList
(),
.
pCols
=
nodesMakeList
(),
.
pColHash
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
)
.
pColHash
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
)};
};
if
(
NULL
==
cxt
.
pCols
||
NULL
==
cxt
.
pColHash
)
{
if
(
NULL
==
cxt
.
pCols
||
NULL
==
cxt
.
pColHash
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
...
@@ -1110,9 +1104,9 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char*
...
@@ -1110,9 +1104,9 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char*
}
}
typedef
struct
SCollectFuncsCxt
{
typedef
struct
SCollectFuncsCxt
{
int32_t
errCode
;
int32_t
errCode
;
FFuncClassifier
classifier
;
FFuncClassifier
classifier
;
SNodeList
*
pFuncs
;
SNodeList
*
pFuncs
;
}
SCollectFuncsCxt
;
}
SCollectFuncsCxt
;
static
EDealRes
collectFuncs
(
SNode
*
pNode
,
void
*
pContext
)
{
static
EDealRes
collectFuncs
(
SNode
*
pNode
,
void
*
pContext
)
{
...
@@ -1129,11 +1123,7 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod
...
@@ -1129,11 +1123,7 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SCollectFuncsCxt
cxt
=
{
SCollectFuncsCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
classifier
=
classifier
,
.
pFuncs
=
nodesMakeList
()};
.
errCode
=
TSDB_CODE_SUCCESS
,
.
classifier
=
classifier
,
.
pFuncs
=
nodesMakeList
()
};
if
(
NULL
==
cxt
.
pFuncs
)
{
if
(
NULL
==
cxt
.
pFuncs
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
...
@@ -1148,12 +1138,11 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod
...
@@ -1148,12 +1138,11 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod
nodesDestroyList
(
cxt
.
pFuncs
);
nodesDestroyList
(
cxt
.
pFuncs
);
*
pFuncs
=
NULL
;
*
pFuncs
=
NULL
;
}
}
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
char
*
getFillModeString
(
EFillMode
mode
)
{
char
*
getFillModeString
(
EFillMode
mode
)
{
switch
(
mode
)
{
switch
(
mode
)
{
case
FILL_MODE_NONE
:
case
FILL_MODE_NONE
:
return
"none"
;
return
"none"
;
...
@@ -1172,12 +1161,12 @@ char *getFillModeString(EFillMode mode) {
...
@@ -1172,12 +1161,12 @@ char *getFillModeString(EFillMode mode) {
}
}
}
}
char
*
nodesGetNameFromColumnNode
(
SNode
*
pNode
)
{
char
*
nodesGetNameFromColumnNode
(
SNode
*
pNode
)
{
if
(
NULL
==
pNode
||
QUERY_NODE_COLUMN
!=
pNode
->
type
)
{
if
(
NULL
==
pNode
||
QUERY_NODE_COLUMN
!=
pNode
->
type
)
{
return
"NULL"
;
return
"NULL"
;
}
}
return
((
SColumnNode
*
)
pNode
)
->
colName
;
return
((
SColumnNode
*
)
pNode
)
->
colName
;
}
}
int32_t
nodesGetOutputNumFromSlotList
(
SNodeList
*
pSlots
)
{
int32_t
nodesGetOutputNumFromSlotList
(
SNodeList
*
pSlots
)
{
...
@@ -1185,14 +1174,14 @@ int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) {
...
@@ -1185,14 +1174,14 @@ int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) {
return
0
;
return
0
;
}
}
SNode
*
pNode
=
NULL
;
SNode
*
pNode
=
NULL
;
int32_t
num
=
0
;
int32_t
num
=
0
;
FOREACH
(
pNode
,
pSlots
)
{
FOREACH
(
pNode
,
pSlots
)
{
if
(
QUERY_NODE_SLOT_DESC
!=
pNode
->
type
)
{
if
(
QUERY_NODE_SLOT_DESC
!=
pNode
->
type
)
{
continue
;
continue
;
}
}
SSlotDescNode
*
descNode
=
(
SSlotDescNode
*
)
pNode
;
SSlotDescNode
*
descNode
=
(
SSlotDescNode
*
)
pNode
;
if
(
descNode
->
output
)
{
if
(
descNode
->
output
)
{
++
num
;
++
num
;
}
}
...
@@ -1201,13 +1190,12 @@ int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) {
...
@@ -1201,13 +1190,12 @@ int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) {
return
num
;
return
num
;
}
}
void
valueNodeToVariant
(
const
SValueNode
*
pNode
,
SVariant
*
pVal
)
{
void
valueNodeToVariant
(
const
SValueNode
*
pNode
,
SVariant
*
pVal
)
{
pVal
->
nType
=
pNode
->
node
.
resType
.
type
;
pVal
->
nType
=
pNode
->
node
.
resType
.
type
;
pVal
->
nLen
=
pNode
->
node
.
resType
.
bytes
;
pVal
->
nLen
=
pNode
->
node
.
resType
.
bytes
;
switch
(
pNode
->
node
.
resType
.
type
)
{
switch
(
pNode
->
node
.
resType
.
type
)
{
case
TSDB_DATA_TYPE_NULL
:
case
TSDB_DATA_TYPE_NULL
:
break
;
break
;
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_BOOL
:
pVal
->
i
=
pNode
->
datum
.
b
;
pVal
->
i
=
pNode
->
datum
.
b
;
break
;
break
;
...
@@ -1241,6 +1229,3 @@ void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
...
@@ -1241,6 +1229,3 @@ void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
break
;
break
;
}
}
}
}
source/libs/nodes/test/nodesTest.cpp
浏览文件 @
ac874f9e
...
@@ -20,42 +20,42 @@
...
@@ -20,42 +20,42 @@
using
namespace
std
;
using
namespace
std
;
static
EDealRes
rewriterTest
(
SNode
**
pNode
,
void
*
pContext
)
{
static
EDealRes
rewriterTest
(
SNode
**
pNode
,
void
*
pContext
)
{
EDealRes
*
pRes
=
(
EDealRes
*
)
pContext
;
EDealRes
*
pRes
=
(
EDealRes
*
)
pContext
;
if
(
QUERY_NODE_OPERATOR
==
nodeType
(
*
pNode
))
{
if
(
QUERY_NODE_OPERATOR
==
nodeType
(
*
pNode
))
{
SOperatorNode
*
pOp
=
(
SOperatorNode
*
)(
*
pNode
);
SOperatorNode
*
pOp
=
(
SOperatorNode
*
)(
*
pNode
);
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pOp
->
pLeft
)
||
QUERY_NODE_VALUE
!=
nodeType
(
pOp
->
pRight
))
{
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pOp
->
pLeft
)
||
QUERY_NODE_VALUE
!=
nodeType
(
pOp
->
pRight
))
{
*
pRes
=
DEAL_RES_ERROR
;
*
pRes
=
DEAL_RES_ERROR
;
}
}
SValueNode
*
pVal
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
SValueNode
*
pVal
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
string
tmp
=
to_string
(
stoi
(((
SValueNode
*
)(
pOp
->
pLeft
))
->
literal
)
+
stoi
(((
SValueNode
*
)(
pOp
->
pRight
))
->
literal
));
string
tmp
=
to_string
(
stoi
(((
SValueNode
*
)(
pOp
->
pLeft
))
->
literal
)
+
stoi
(((
SValueNode
*
)(
pOp
->
pRight
))
->
literal
));
pVal
->
literal
=
strdup
(
tmp
.
c_str
());
pVal
->
literal
=
strdup
(
tmp
.
c_str
());
nodesDestroyNode
(
*
pNode
);
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
pVal
;
*
pNode
=
(
SNode
*
)
pVal
;
}
}
return
DEAL_RES_CONTINUE
;
return
DEAL_RES_CONTINUE
;
}
}
TEST
(
NodesTest
,
traverseTest
)
{
TEST
(
NodesTest
,
traverseTest
)
{
SNode
*
pRoot
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_OPERATOR
);
SNode
*
pRoot
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_OPERATOR
);
SOperatorNode
*
pOp
=
(
SOperatorNode
*
)
pRoot
;
SOperatorNode
*
pOp
=
(
SOperatorNode
*
)
pRoot
;
SOperatorNode
*
pLeft
=
(
SOperatorNode
*
)
nodesMakeNode
(
QUERY_NODE_OPERATOR
);
SOperatorNode
*
pLeft
=
(
SOperatorNode
*
)
nodesMakeNode
(
QUERY_NODE_OPERATOR
);
pLeft
->
pLeft
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
pLeft
->
pLeft
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
((
SValueNode
*
)(
pLeft
->
pLeft
))
->
literal
=
strdup
(
"10"
);
((
SValueNode
*
)(
pLeft
->
pLeft
))
->
literal
=
strdup
(
"10"
);
pLeft
->
pRight
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
pLeft
->
pRight
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
((
SValueNode
*
)(
pLeft
->
pRight
))
->
literal
=
strdup
(
"5"
);
((
SValueNode
*
)(
pLeft
->
pRight
))
->
literal
=
strdup
(
"5"
);
pOp
->
pLeft
=
(
SNode
*
)
pLeft
;
pOp
->
pLeft
=
(
SNode
*
)
pLeft
;
pOp
->
pRight
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
pOp
->
pRight
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
((
SValueNode
*
)(
pOp
->
pRight
))
->
literal
=
strdup
(
"3"
);
((
SValueNode
*
)(
pOp
->
pRight
))
->
literal
=
strdup
(
"3"
);
EXPECT_EQ
(
nodeType
(
pRoot
),
QUERY_NODE_OPERATOR
);
EXPECT_EQ
(
nodeType
(
pRoot
),
QUERY_NODE_OPERATOR
);
EDealRes
res
=
DEAL_RES_CONTINUE
;
EDealRes
res
=
DEAL_RES_CONTINUE
;
nodesRewriteExprPostOrder
(
&
pRoot
,
rewriterTest
,
&
res
);
nodesRewriteExprPostOrder
(
&
pRoot
,
rewriterTest
,
&
res
);
EXPECT_EQ
(
res
,
DEAL_RES_CONTINUE
);
EXPECT_EQ
(
res
,
DEAL_RES_CONTINUE
);
EXPECT_EQ
(
nodeType
(
pRoot
),
QUERY_NODE_VALUE
);
EXPECT_EQ
(
nodeType
(
pRoot
),
QUERY_NODE_VALUE
);
EXPECT_EQ
(
string
(((
SValueNode
*
)
pRoot
)
->
literal
),
"18"
);
EXPECT_EQ
(
string
(((
SValueNode
*
)
pRoot
)
->
literal
),
"18"
);
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
return
RUN_ALL_TESTS
();
}
}
source/libs/parser/inc/parAst.h
浏览文件 @
ac874f9e
...
@@ -21,18 +21,18 @@ extern "C" {
...
@@ -21,18 +21,18 @@ extern "C" {
#endif
#endif
#include "cmdnodes.h"
#include "cmdnodes.h"
#include "parser.h"
#include "parToken.h"
#include "parToken.h"
#include "parUtil.h"
#include "parUtil.h"
#include "parser.h"
#include "querynodes.h"
#include "querynodes.h"
typedef
struct
SAstCreateContext
{
typedef
struct
SAstCreateContext
{
SParseContext
*
pQueryCxt
;
SParseContext
*
pQueryCxt
;
SMsgBuf
msgBuf
;
SMsgBuf
msgBuf
;
bool
notSupport
;
bool
notSupport
;
bool
valid
;
bool
valid
;
SNode
*
pRootNode
;
SNode
*
pRootNode
;
int16_t
placeholderNo
;
int16_t
placeholderNo
;
}
SAstCreateContext
;
}
SAstCreateContext
;
typedef
enum
EDatabaseOptionType
{
typedef
enum
EDatabaseOptionType
{
...
@@ -67,9 +67,9 @@ typedef enum ETableOptionType {
...
@@ -67,9 +67,9 @@ typedef enum ETableOptionType {
}
ETableOptionType
;
}
ETableOptionType
;
typedef
struct
SAlterOption
{
typedef
struct
SAlterOption
{
int32_t
type
;
int32_t
type
;
SValueNode
*
pVal
;
SValueNode
*
pVal
;
SNodeList
*
pList
;
SNodeList
*
pList
;
}
SAlterOption
;
}
SAlterOption
;
extern
SToken
nil_token
;
extern
SToken
nil_token
;
...
@@ -105,7 +105,8 @@ SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const STok
...
@@ -105,7 +105,8 @@ SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const STok
SNode
*
createOrderByExprNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
,
EOrder
order
,
ENullOrder
nullOrder
);
SNode
*
createOrderByExprNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
,
EOrder
order
,
ENullOrder
nullOrder
);
SNode
*
createSessionWindowNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pCol
,
SNode
*
pGap
);
SNode
*
createSessionWindowNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pCol
,
SNode
*
pGap
);
SNode
*
createStateWindowNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
);
SNode
*
createStateWindowNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
);
SNode
*
createIntervalWindowNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pInterval
,
SNode
*
pOffset
,
SNode
*
pSliding
,
SNode
*
pFill
);
SNode
*
createIntervalWindowNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pInterval
,
SNode
*
pOffset
,
SNode
*
pSliding
,
SNode
*
pFill
);
SNode
*
createFillNode
(
SAstCreateContext
*
pCxt
,
EFillMode
mode
,
SNode
*
pValues
);
SNode
*
createFillNode
(
SAstCreateContext
*
pCxt
,
EFillMode
mode
,
SNode
*
pValues
);
SNode
*
createGroupingSetNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
);
SNode
*
createGroupingSetNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
);
...
@@ -120,26 +121,30 @@ SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit);
...
@@ -120,26 +121,30 @@ SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit);
SNode
*
createSelectStmt
(
SAstCreateContext
*
pCxt
,
bool
isDistinct
,
SNodeList
*
pProjectionList
,
SNode
*
pTable
);
SNode
*
createSelectStmt
(
SAstCreateContext
*
pCxt
,
bool
isDistinct
,
SNodeList
*
pProjectionList
,
SNode
*
pTable
);
SNode
*
createSetOperator
(
SAstCreateContext
*
pCxt
,
ESetOperatorType
type
,
SNode
*
pLeft
,
SNode
*
pRight
);
SNode
*
createSetOperator
(
SAstCreateContext
*
pCxt
,
ESetOperatorType
type
,
SNode
*
pLeft
,
SNode
*
pRight
);
SNode
*
createDatabaseOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
createDatabaseOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
setDatabaseAlterOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SAlterOption
*
pAlterOption
);
SNode
*
setDatabaseAlterOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SAlterOption
*
pAlterOption
);
SNode
*
createCreateDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SToken
*
pDbName
,
SNode
*
pOptions
);
SNode
*
createCreateDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SToken
*
pDbName
,
SNode
*
pOptions
);
SNode
*
createDropDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SToken
*
pDbName
);
SNode
*
createDropDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SToken
*
pDbName
);
SNode
*
createAlterDatabaseStmt
(
SAstCreateContext
*
pCxt
,
SToken
*
pDbName
,
SNode
*
pOptions
);
SNode
*
createAlterDatabaseStmt
(
SAstCreateContext
*
pCxt
,
SToken
*
pDbName
,
SNode
*
pOptions
);
SNode
*
createTableOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
createTableOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
setTableAlterOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SAlterOption
*
pAlterOption
);
SNode
*
setTableAlterOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SAlterOption
*
pAlterOption
);
SNode
*
createColumnDefNode
(
SAstCreateContext
*
pCxt
,
SToken
*
pColName
,
SDataType
dataType
,
const
SToken
*
pComment
);
SNode
*
createColumnDefNode
(
SAstCreateContext
*
pCxt
,
SToken
*
pColName
,
SDataType
dataType
,
const
SToken
*
pComment
);
SDataType
createDataType
(
uint8_t
type
);
SDataType
createDataType
(
uint8_t
type
);
SDataType
createVarLenDataType
(
uint8_t
type
,
const
SToken
*
pLen
);
SDataType
createVarLenDataType
(
uint8_t
type
,
const
SToken
*
pLen
);
SNode
*
createCreateTableStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNodeList
*
pCols
,
SNodeList
*
pTags
,
SNode
*
pOptions
);
SNode
*
createCreateTableStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNodeList
*
pCols
,
SNode
*
createCreateSubTableClause
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNode
*
pUseRealTable
,
SNodeList
*
pSpecificTags
,
SNodeList
*
pValsOfTags
);
SNodeList
*
pTags
,
SNode
*
pOptions
);
SNode
*
createCreateSubTableClause
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNode
*
pUseRealTable
,
SNodeList
*
pSpecificTags
,
SNodeList
*
pValsOfTags
);
SNode
*
createCreateMultiTableStmt
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pSubTables
);
SNode
*
createCreateMultiTableStmt
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pSubTables
);
SNode
*
createDropTableClause
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SNode
*
pRealTable
);
SNode
*
createDropTableClause
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SNode
*
pRealTable
);
SNode
*
createDropTableStmt
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pTables
);
SNode
*
createDropTableStmt
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pTables
);
SNode
*
createDropSuperTableStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SNode
*
pRealTable
);
SNode
*
createDropSuperTableStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SNode
*
pRealTable
);
SNode
*
createAlterTableOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
SNode
*
pOptions
);
SNode
*
createAlterTableOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
SNode
*
pOptions
);
SNode
*
createAlterTableAddModifyCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pColName
,
SDataType
dataType
);
SNode
*
createAlterTableAddModifyCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pColName
,
SDataType
dataType
);
SNode
*
createAlterTableDropCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pColName
);
SNode
*
createAlterTableDropCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pColName
);
SNode
*
createAlterTableRenameCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pOldColName
,
const
SToken
*
pNewColName
);
SNode
*
createAlterTableRenameCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pOldColName
,
const
SToken
*
pNewColName
);
SNode
*
createAlterTableSetTag
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
const
SToken
*
pTagName
,
SNode
*
pVal
);
SNode
*
createAlterTableSetTag
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
const
SToken
*
pTagName
,
SNode
*
pVal
);
SNode
*
createUseDatabaseStmt
(
SAstCreateContext
*
pCxt
,
SToken
*
pDbName
);
SNode
*
createUseDatabaseStmt
(
SAstCreateContext
*
pCxt
,
SToken
*
pDbName
);
SNode
*
createShowStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
SNode
*
pDbName
,
SNode
*
pTbNamePattern
);
SNode
*
createShowStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
SNode
*
pDbName
,
SNode
*
pTbNamePattern
);
...
@@ -151,13 +156,15 @@ SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName);
...
@@ -151,13 +156,15 @@ SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName);
SNode
*
createCreateDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFqdn
,
const
SToken
*
pPort
);
SNode
*
createCreateDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFqdn
,
const
SToken
*
pPort
);
SNode
*
createDropDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDnode
);
SNode
*
createDropDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDnode
);
SNode
*
createAlterDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDnode
,
const
SToken
*
pConfig
,
const
SToken
*
pValue
);
SNode
*
createAlterDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDnode
,
const
SToken
*
pConfig
,
const
SToken
*
pValue
);
SNode
*
createCreateIndexStmt
(
SAstCreateContext
*
pCxt
,
EIndexType
type
,
bool
ignoreExists
,
SToken
*
pIndexName
,
SToken
*
pTableName
,
SNodeList
*
pCols
,
SNode
*
pOptions
);
SNode
*
createCreateIndexStmt
(
SAstCreateContext
*
pCxt
,
EIndexType
type
,
bool
ignoreExists
,
SToken
*
pIndexName
,
SToken
*
pTableName
,
SNodeList
*
pCols
,
SNode
*
pOptions
);
SNode
*
createIndexOption
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pFuncs
,
SNode
*
pInterval
,
SNode
*
pOffset
,
SNode
*
pSliding
);
SNode
*
createIndexOption
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pFuncs
,
SNode
*
pInterval
,
SNode
*
pOffset
,
SNode
*
pSliding
);
SNode
*
createDropIndexStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SToken
*
pIndexName
,
SToken
*
pTableName
);
SNode
*
createDropIndexStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SToken
*
pIndexName
,
SToken
*
pTableName
);
SNode
*
createCreateComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
);
SNode
*
createCreateComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
);
SNode
*
createDropComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
);
SNode
*
createDropComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
);
SNode
*
createTopicOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
createTopicOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
createCreateTopicStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
const
SToken
*
pTopicName
,
SNode
*
pQuery
,
const
SToken
*
pSubscribeDbName
,
SNode
*
pOptions
);
SNode
*
createCreateTopicStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
const
SToken
*
pTopicName
,
SNode
*
pQuery
,
const
SToken
*
pSubscribeDbName
,
SNode
*
pOptions
);
SNode
*
createDropTopicStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
const
SToken
*
pTopicName
);
SNode
*
createDropTopicStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
const
SToken
*
pTopicName
);
SNode
*
createAlterLocalStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pConfig
,
const
SToken
*
pValue
);
SNode
*
createAlterLocalStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pConfig
,
const
SToken
*
pValue
);
SNode
*
createDefaultExplainOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
createDefaultExplainOptions
(
SAstCreateContext
*
pCxt
);
...
@@ -167,10 +174,12 @@ SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions,
...
@@ -167,10 +174,12 @@ SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions,
SNode
*
createDescribeStmt
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
);
SNode
*
createDescribeStmt
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
);
SNode
*
createResetQueryCacheStmt
(
SAstCreateContext
*
pCxt
);
SNode
*
createResetQueryCacheStmt
(
SAstCreateContext
*
pCxt
);
SNode
*
createCompactStmt
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pVgroups
);
SNode
*
createCompactStmt
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pVgroups
);
SNode
*
createCreateFunctionStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
bool
aggFunc
,
const
SToken
*
pFuncName
,
const
SToken
*
pLibPath
,
SDataType
dataType
,
int32_t
bufSize
);
SNode
*
createCreateFunctionStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
bool
aggFunc
,
const
SToken
*
pFuncName
,
const
SToken
*
pLibPath
,
SDataType
dataType
,
int32_t
bufSize
);
SNode
*
createDropFunctionStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFuncName
);
SNode
*
createDropFunctionStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFuncName
);
SNode
*
createStreamOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
createStreamOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
createCreateStreamStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
const
SToken
*
pStreamName
,
SNode
*
pRealTable
,
SNode
*
pOptions
,
SNode
*
pQuery
);
SNode
*
createCreateStreamStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
const
SToken
*
pStreamName
,
SNode
*
pRealTable
,
SNode
*
pOptions
,
SNode
*
pQuery
);
SNode
*
createDropStreamStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
const
SToken
*
pStreamName
);
SNode
*
createDropStreamStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
const
SToken
*
pStreamName
);
SNode
*
createKillStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pId
);
SNode
*
createKillStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pId
);
SNode
*
createMergeVgroupStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pVgId1
,
const
SToken
*
pVgId2
);
SNode
*
createMergeVgroupStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pVgId1
,
const
SToken
*
pVgId2
);
...
...
source/libs/parser/inc/parInsertData.h
浏览文件 @
ac874f9e
...
@@ -18,8 +18,8 @@
...
@@ -18,8 +18,8 @@
#include "catalog.h"
#include "catalog.h"
#include "os.h"
#include "os.h"
#include "ttypes.h"
#include "tname.h"
#include "tname.h"
#include "ttypes.h"
#define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED)
#define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED)
...
@@ -52,8 +52,8 @@ typedef struct SParsedDataColInfo {
...
@@ -52,8 +52,8 @@ typedef struct SParsedDataColInfo {
uint16_t
flen
;
// TODO: get from STSchema
uint16_t
flen
;
// TODO: get from STSchema
uint16_t
allNullLen
;
// TODO: get from STSchema(base on SDataRow)
uint16_t
allNullLen
;
// TODO: get from STSchema(base on SDataRow)
uint16_t
extendedVarLen
;
uint16_t
extendedVarLen
;
uint16_t
boundNullLen
;
// bound column len with all NULL value(without VarDataOffsetT/SColIdx part)
uint16_t
boundNullLen
;
// bound column len with all NULL value(without VarDataOffsetT/SColIdx part)
col_id_t
*
boundColumns
;
// bound column idx according to schema
col_id_t
*
boundColumns
;
// bound column idx according to schema
SBoundColumn
*
cols
;
SBoundColumn
*
cols
;
SBoundIdxInfo
*
colIdxInfo
;
SBoundIdxInfo
*
colIdxInfo
;
int8_t
orderStatus
;
// bound columns
int8_t
orderStatus
;
// bound columns
...
@@ -72,12 +72,13 @@ typedef struct STableDataBlocks {
...
@@ -72,12 +72,13 @@ typedef struct STableDataBlocks {
int32_t
numOfTables
;
// number of tables in current submit block
int32_t
numOfTables
;
// number of tables in current submit block
int32_t
rowSize
;
// row size for current table
int32_t
rowSize
;
// row size for current table
uint32_t
nAllocSize
;
uint32_t
nAllocSize
;
uint32_t
headerSize
;
// header for table info (uid, tid, submit metadata)
uint32_t
headerSize
;
// header for table info (uid, tid, submit metadata)
uint32_t
size
;
uint32_t
size
;
STableMeta
*
pTableMeta
;
// the tableMeta of current table, the table meta will be used during submit, keep a ref to avoid to be removed from cache
STableMeta
*
pTableMeta
;
// the tableMeta of current table, the table meta will be used during submit, keep a ref to
char
*
pData
;
// avoid to be removed from cache
bool
cloned
;
char
*
pData
;
int32_t
createTbReqLen
;
bool
cloned
;
int32_t
createTbReqLen
;
SParsedDataColInfo
boundColumnInfo
;
SParsedDataColInfo
boundColumnInfo
;
SRowBuilder
rowBuilder
;
SRowBuilder
rowBuilder
;
}
STableDataBlocks
;
}
STableDataBlocks
;
...
@@ -89,8 +90,8 @@ static FORCE_INLINE int32_t getExtendedRowSize(STableDataBlocks *pBlock) {
...
@@ -89,8 +90,8 @@ static FORCE_INLINE int32_t getExtendedRowSize(STableDataBlocks *pBlock) {
(
int32_t
)
TD_BITMAP_BYTES
(
pTableInfo
->
numOfColumns
-
1
);
(
int32_t
)
TD_BITMAP_BYTES
(
pTableInfo
->
numOfColumns
-
1
);
}
}
static
FORCE_INLINE
void
getSTSRowAppendInfo
(
uint8_t
rowType
,
SParsedDataColInfo
*
spd
,
col_id_t
idx
,
static
FORCE_INLINE
void
getSTSRowAppendInfo
(
uint8_t
rowType
,
SParsedDataColInfo
*
spd
,
col_id_t
idx
,
int32_t
*
toffset
,
int32_t
*
toffset
,
col_id_t
*
colIdx
)
{
col_id_t
*
colIdx
)
{
col_id_t
schemaIdx
=
0
;
col_id_t
schemaIdx
=
0
;
if
(
IS_DATA_COL_ORDERED
(
spd
))
{
if
(
IS_DATA_COL_ORDERED
(
spd
))
{
schemaIdx
=
spd
->
boundColumns
[
idx
]
-
PRIMARYKEY_TIMESTAMP_COL_ID
;
schemaIdx
=
spd
->
boundColumns
[
idx
]
-
PRIMARYKEY_TIMESTAMP_COL_ID
;
...
@@ -114,8 +115,9 @@ static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo
...
@@ -114,8 +115,9 @@ static FORCE_INLINE void getSTSRowAppendInfo(uint8_t rowType, SParsedDataColInfo
}
}
}
}
static
FORCE_INLINE
int32_t
setBlockInfo
(
SSubmitBlk
*
pBlocks
,
STableDataBlocks
*
dataBuf
,
int32_t
numOfRows
)
{
static
FORCE_INLINE
int32_t
setBlockInfo
(
SSubmitBlk
*
pBlocks
,
STableDataBlocks
*
dataBuf
,
int32_t
numOfRows
)
{
pBlocks
->
suid
=
(
TSDB_NORMAL_TABLE
==
dataBuf
->
pTableMeta
->
tableType
?
dataBuf
->
pTableMeta
->
uid
:
dataBuf
->
pTableMeta
->
suid
);
pBlocks
->
suid
=
(
TSDB_NORMAL_TABLE
==
dataBuf
->
pTableMeta
->
tableType
?
dataBuf
->
pTableMeta
->
uid
:
dataBuf
->
pTableMeta
->
suid
);
pBlocks
->
uid
=
dataBuf
->
pTableMeta
->
uid
;
pBlocks
->
uid
=
dataBuf
->
pTableMeta
->
uid
;
pBlocks
->
sversion
=
dataBuf
->
pTableMeta
->
sversion
;
pBlocks
->
sversion
=
dataBuf
->
pTableMeta
->
sversion
;
pBlocks
->
schemaLen
=
dataBuf
->
createTbReqLen
;
pBlocks
->
schemaLen
=
dataBuf
->
createTbReqLen
;
...
@@ -131,14 +133,15 @@ static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks*
...
@@ -131,14 +133,15 @@ static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks*
int32_t
schemaIdxCompar
(
const
void
*
lhs
,
const
void
*
rhs
);
int32_t
schemaIdxCompar
(
const
void
*
lhs
,
const
void
*
rhs
);
int32_t
boundIdxCompar
(
const
void
*
lhs
,
const
void
*
rhs
);
int32_t
boundIdxCompar
(
const
void
*
lhs
,
const
void
*
rhs
);
void
setBoundColumnInfo
(
SParsedDataColInfo
*
pColList
,
SSchema
*
pSchema
,
col_id_t
numOfCols
);
void
setBoundColumnInfo
(
SParsedDataColInfo
*
pColList
,
SSchema
*
pSchema
,
col_id_t
numOfCols
);
void
destroyBlockArrayList
(
SArray
*
pDataBlockList
);
void
destroyBlockArrayList
(
SArray
*
pDataBlockList
);
void
destroyBlockHashmap
(
SHashObj
*
pDataBlockHash
);
void
destroyBlockHashmap
(
SHashObj
*
pDataBlockHash
);
int
initRowBuilder
(
SRowBuilder
*
pBuilder
,
int16_t
schemaVer
,
SParsedDataColInfo
*
pColInfo
);
int
initRowBuilder
(
SRowBuilder
*
pBuilder
,
int16_t
schemaVer
,
SParsedDataColInfo
*
pColInfo
);
int32_t
allocateMemIfNeed
(
STableDataBlocks
*
pDataBlock
,
int32_t
rowSize
,
int32_t
*
numOfRows
);
int32_t
allocateMemIfNeed
(
STableDataBlocks
*
pDataBlock
,
int32_t
rowSize
,
int32_t
*
numOfRows
);
int32_t
getDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
int32_t
getDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
,
SVCreateTbReq
*
pCreateTbReq
);
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
,
int32_t
mergeTableDataBlocks
(
SHashObj
*
pHashObj
,
uint8_t
payloadType
,
SArray
**
pVgDataBlocks
);
SVCreateTbReq
*
pCreateTbReq
);
int32_t
buildCreateTbMsg
(
STableDataBlocks
*
pBlocks
,
SVCreateTbReq
*
pCreateTbReq
);
int32_t
mergeTableDataBlocks
(
SHashObj
*
pHashObj
,
uint8_t
payloadType
,
SArray
**
pVgDataBlocks
);
int32_t
buildCreateTbMsg
(
STableDataBlocks
*
pBlocks
,
SVCreateTbReq
*
pCreateTbReq
);
int32_t
allocateMemForSize
(
STableDataBlocks
*
pDataBlock
,
int32_t
allSize
);
int32_t
allocateMemForSize
(
STableDataBlocks
*
pDataBlock
,
int32_t
allSize
);
#endif // TDENGINE_DATABLOCKMGT_H
#endif // TDENGINE_DATABLOCKMGT_H
source/libs/parser/inc/parInt.h
浏览文件 @
ac874f9e
...
@@ -20,9 +20,9 @@
...
@@ -20,9 +20,9 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#include "parser.h"
#include "parToken.h"
#include "parToken.h"
#include "parUtil.h"
#include "parUtil.h"
#include "parser.h"
int32_t
parseInsertSql
(
SParseContext
*
pContext
,
SQuery
**
pQuery
);
int32_t
parseInsertSql
(
SParseContext
*
pContext
,
SQuery
**
pQuery
);
int32_t
parse
(
SParseContext
*
pParseCxt
,
SQuery
**
pQuery
);
int32_t
parse
(
SParseContext
*
pParseCxt
,
SQuery
**
pQuery
);
...
...
source/libs/parser/inc/parToken.h
浏览文件 @
ac874f9e
...
@@ -20,6 +20,8 @@
...
@@ -20,6 +20,8 @@
extern
"C"
{
extern
"C"
{
#endif
#endif
#include "os.h"
#include "ttokendef.h"
#include "ttokendef.h"
// used to denote the minimum unite in sql parsing
// used to denote the minimum unite in sql parsing
...
@@ -35,7 +37,7 @@ typedef struct SToken {
...
@@ -35,7 +37,7 @@ typedef struct SToken {
* @return
* @return
*/
*/
#define isNumber(tk) \
#define isNumber(tk) \
((tk)->type == TK_NK_INTEGER || (tk)->type == TK_NK_FLOAT || (tk)->type == TK_NK_HEX || (tk)->type == TK_NK_BIN)
((tk)->type == TK_NK_INTEGER || (tk)->type == TK_NK_FLOAT || (tk)->type == TK_NK_HEX || (tk)->type == TK_NK_BIN)
/**
/**
* tokenizer for sql string
* tokenizer for sql string
...
@@ -68,12 +70,12 @@ bool taosIsKeyWordToken(const char *z, int32_t len);
...
@@ -68,12 +70,12 @@ bool taosIsKeyWordToken(const char *z, int32_t len);
* @param pToken
* @param pToken
* @return token type, if it is not a number, TK_NK_ILLEGAL will return
* @return token type, if it is not a number, TK_NK_ILLEGAL will return
*/
*/
static
FORCE_INLINE
int32_t
tGetNumericStringType
(
const
SToken
*
pToken
)
{
static
FORCE_INLINE
int32_t
tGetNumericStringType
(
const
SToken
*
pToken
)
{
const
char
*
z
=
pToken
->
z
;
const
char
*
z
=
pToken
->
z
;
int32_t
type
=
TK_NK_ILLEGAL
;
int32_t
type
=
TK_NK_ILLEGAL
;
uint32_t
i
=
0
;
uint32_t
i
=
0
;
for
(;
i
<
pToken
->
n
;
++
i
)
{
for
(;
i
<
pToken
->
n
;
++
i
)
{
switch
(
z
[
i
])
{
switch
(
z
[
i
])
{
case
'+'
:
case
'+'
:
case
'-'
:
{
case
'-'
:
{
...
@@ -86,7 +88,7 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
...
@@ -86,7 +88,7 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
* .123
* .123
* .123e4
* .123e4
*/
*/
if
(
!
isdigit
(
z
[
i
+
1
]))
{
if
(
!
isdigit
(
z
[
i
+
1
]))
{
return
TK_NK_ILLEGAL
;
return
TK_NK_ILLEGAL
;
}
}
...
@@ -107,13 +109,13 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
...
@@ -107,13 +109,13 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
case
'0'
:
{
case
'0'
:
{
char
next
=
z
[
i
+
1
];
char
next
=
z
[
i
+
1
];
if
(
next
==
'b'
)
{
// bin number
if
(
next
==
'b'
)
{
// bin number
type
=
TK_NK_BIN
;
type
=
TK_NK_BIN
;
for
(
i
+=
2
;
(
z
[
i
]
==
'0'
||
z
[
i
]
==
'1'
);
++
i
)
{
for
(
i
+=
2
;
(
z
[
i
]
==
'0'
||
z
[
i
]
==
'1'
);
++
i
)
{
}
}
goto
_end
;
goto
_end
;
}
else
if
(
next
==
'x'
)
{
//hex number
}
else
if
(
next
==
'x'
)
{
//
hex number
type
=
TK_NK_HEX
;
type
=
TK_NK_HEX
;
for
(
i
+=
2
;
isdigit
(
z
[
i
])
||
(
z
[
i
]
>=
'a'
&&
z
[
i
]
<=
'f'
)
||
(
z
[
i
]
>=
'A'
&&
z
[
i
]
<=
'F'
);
++
i
)
{
for
(
i
+=
2
;
isdigit
(
z
[
i
])
||
(
z
[
i
]
>=
'a'
&&
z
[
i
]
<=
'f'
)
||
(
z
[
i
]
>=
'A'
&&
z
[
i
]
<=
'F'
);
++
i
)
{
}
}
...
@@ -167,15 +169,15 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
...
@@ -167,15 +169,15 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
}
}
}
}
_end:
_end:
return
(
i
<
pToken
->
n
)
?
TK_NK_ILLEGAL
:
type
;
return
(
i
<
pToken
->
n
)
?
TK_NK_ILLEGAL
:
type
;
}
}
void
taosCleanupKeywordsTable
();
void
taosCleanupKeywordsTable
();
SToken
tscReplaceStrToken
(
char
**
str
,
SToken
*
token
,
const
char
*
newToken
);
SToken
tscReplaceStrToken
(
char
**
str
,
SToken
*
token
,
const
char
*
newToken
);
SToken
taosTokenDup
(
SToken
*
pToken
,
char
*
buf
,
int32_t
len
);
SToken
taosTokenDup
(
SToken
*
pToken
,
char
*
buf
,
int32_t
len
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
source/libs/parser/inc/parUtil.h
浏览文件 @
ac874f9e
...
@@ -23,31 +23,31 @@ extern "C" {
...
@@ -23,31 +23,31 @@ extern "C" {
#include "os.h"
#include "os.h"
#include "query.h"
#include "query.h"
#define parserFatal(param, ...)
qFatal("PARSER: " param, __VA_ARGS__)
#define parserFatal(param, ...) qFatal("PARSER: " param, __VA_ARGS__)
#define parserError(param, ...)
qError("PARSER: " param, __VA_ARGS__)
#define parserError(param, ...) qError("PARSER: " param, __VA_ARGS__)
#define parserWarn(param, ...)
qWarn("PARSER: " param, __VA_ARGS__)
#define parserWarn(param, ...) qWarn("PARSER: " param, __VA_ARGS__)
#define parserInfo(param, ...)
qInfo("PARSER: " param, __VA_ARGS__)
#define parserInfo(param, ...) qInfo("PARSER: " param, __VA_ARGS__)
#define parserDebug(param, ...)
qDebug("PARSER: " param, __VA_ARGS__)
#define parserDebug(param, ...) qDebug("PARSER: " param, __VA_ARGS__)
#define parserTrace(param, ...)
qTrace("PARSER: " param, __VA_ARGS__)
#define parserTrace(param, ...) qTrace("PARSER: " param, __VA_ARGS__)
#define PK_TS_COL_INTERNAL_NAME "_rowts"
#define PK_TS_COL_INTERNAL_NAME "_rowts"
typedef
struct
SMsgBuf
{
typedef
struct
SMsgBuf
{
int32_t
len
;
int32_t
len
;
char
*
buf
;
char
*
buf
;
}
SMsgBuf
;
}
SMsgBuf
;
int32_t
generateSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
int32_t
errCode
,
...);
int32_t
generateSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
int32_t
errCode
,
...);
int32_t
buildInvalidOperationMsg
(
SMsgBuf
*
pMsgBuf
,
const
char
*
msg
);
int32_t
buildInvalidOperationMsg
(
SMsgBuf
*
pMsgBuf
,
const
char
*
msg
);
int32_t
buildSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
const
char
*
additionalInfo
,
const
char
*
sourceStr
);
int32_t
buildSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
const
char
*
additionalInfo
,
const
char
*
sourceStr
);
STableMeta
*
tableMetaDup
(
const
STableMeta
*
pTableMeta
);
STableMeta
*
tableMetaDup
(
const
STableMeta
*
pTableMeta
);
SSchema
*
getTableColumnSchema
(
const
STableMeta
*
pTableMeta
);
SSchema
*
getTableColumnSchema
(
const
STableMeta
*
pTableMeta
);
SSchema
*
getTableTagSchema
(
const
STableMeta
*
pTableMeta
);
SSchema
*
getTableTagSchema
(
const
STableMeta
*
pTableMeta
);
int32_t
getNumOfColumns
(
const
STableMeta
*
pTableMeta
);
int32_t
getNumOfColumns
(
const
STableMeta
*
pTableMeta
);
int32_t
getNumOfTags
(
const
STableMeta
*
pTableMeta
);
int32_t
getNumOfTags
(
const
STableMeta
*
pTableMeta
);
STableComInfo
getTableInfo
(
const
STableMeta
*
pTableMeta
);
STableComInfo
getTableInfo
(
const
STableMeta
*
pTableMeta
);
int
parseJsontoTagData
(
const
char
*
json
,
SKVRowBuilder
*
kvRowBuilder
,
SMsgBuf
*
errMsg
,
int16_t
startColId
);
int
parseJsontoTagData
(
const
char
*
json
,
SKVRowBuilder
*
kvRowBuilder
,
SMsgBuf
*
errMsg
,
int16_t
startColId
);
int32_t
trimString
(
const
char
*
src
,
int32_t
len
,
char
*
dst
,
int32_t
dlen
);
int32_t
trimString
(
const
char
*
src
,
int32_t
len
,
char
*
dst
,
int32_t
dlen
);
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
ac874f9e
...
@@ -18,24 +18,24 @@
...
@@ -18,24 +18,24 @@
#include "parUtil.h"
#include "parUtil.h"
#include "ttime.h"
#include "ttime.h"
#define CHECK_OUT_OF_MEM(p) \
#define CHECK_OUT_OF_MEM(p)
\
do { \
do {
\
if (NULL == (p)) { \
if (NULL == (p)) {
\
pCxt->valid = false; \
pCxt->valid = false;
\
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "Out of memory"); \
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "Out of memory"); \
return NULL; \
return NULL;
\
} \
}
\
} while (0)
} while (0)
#define CHECK_RAW_EXPR_NODE(node) \
#define CHECK_RAW_EXPR_NODE(node)
\
do { \
do {
\
if (NULL == (node) || QUERY_NODE_RAW_EXPR != nodeType(node)) { \
if (NULL == (node) || QUERY_NODE_RAW_EXPR != nodeType(node)) { \
pCxt->valid = false; \
pCxt->valid = false;
\
return NULL; \
return NULL;
\
} \
}
\
} while (0)
} while (0)
SToken
nil_token
=
{
.
type
=
TK_NK_NIL
,
.
n
=
0
,
.
z
=
NULL
};
SToken
nil_token
=
{
.
type
=
TK_NK_NIL
,
.
n
=
0
,
.
z
=
NULL
};
void
initAstCreateContext
(
SParseContext
*
pParseCxt
,
SAstCreateContext
*
pCxt
)
{
void
initAstCreateContext
(
SParseContext
*
pParseCxt
,
SAstCreateContext
*
pCxt
)
{
pCxt
->
pQueryCxt
=
pParseCxt
;
pCxt
->
pQueryCxt
=
pParseCxt
;
...
@@ -90,7 +90,7 @@ static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken,
...
@@ -90,7 +90,7 @@ static bool checkPassword(SAstCreateContext* pCxt, const SToken* pPasswordToken,
static
bool
checkAndSplitEndpoint
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pEp
,
char
*
pFqdn
,
int32_t
*
pPort
)
{
static
bool
checkAndSplitEndpoint
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pEp
,
char
*
pFqdn
,
int32_t
*
pPort
)
{
if
(
NULL
==
pEp
)
{
if
(
NULL
==
pEp
)
{
pCxt
->
valid
=
false
;
pCxt
->
valid
=
false
;
}
else
if
(
pEp
->
n
>=
TSDB_FQDN_LEN
+
2
+
6
)
{
// format 'fqdn:port'
}
else
if
(
pEp
->
n
>=
TSDB_FQDN_LEN
+
2
+
6
)
{
// format 'fqdn:port'
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG
);
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_NAME_OR_PASSWD_TOO_LONG
);
pCxt
->
valid
=
false
;
pCxt
->
valid
=
false
;
}
else
{
}
else
{
...
@@ -206,7 +206,7 @@ SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const
...
@@ -206,7 +206,7 @@ SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const
SNode
*
releaseRawExprNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
)
{
SNode
*
releaseRawExprNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
)
{
CHECK_RAW_EXPR_NODE
(
pNode
);
CHECK_RAW_EXPR_NODE
(
pNode
);
SRawExprNode
*
pRawExpr
=
(
SRawExprNode
*
)
pNode
;
SRawExprNode
*
pRawExpr
=
(
SRawExprNode
*
)
pNode
;
SNode
*
pExpr
=
pRawExpr
->
pNode
;
SNode
*
pExpr
=
pRawExpr
->
pNode
;
if
(
nodesIsExprNode
(
pExpr
))
{
if
(
nodesIsExprNode
(
pExpr
))
{
int32_t
len
=
TMIN
(
sizeof
(((
SExprNode
*
)
pExpr
)
->
aliasName
)
-
1
,
pRawExpr
->
n
);
int32_t
len
=
TMIN
(
sizeof
(((
SExprNode
*
)
pExpr
)
->
aliasName
)
-
1
,
pRawExpr
->
n
);
strncpy
(((
SExprNode
*
)
pExpr
)
->
aliasName
,
pRawExpr
->
p
,
len
);
strncpy
(((
SExprNode
*
)
pExpr
)
->
aliasName
,
pRawExpr
->
p
,
len
);
...
@@ -222,7 +222,7 @@ SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
...
@@ -222,7 +222,7 @@ SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
return
nil_token
;
return
nil_token
;
}
}
SRawExprNode
*
target
=
(
SRawExprNode
*
)
pNode
;
SRawExprNode
*
target
=
(
SRawExprNode
*
)
pNode
;
SToken
t
=
{
.
type
=
0
,
.
z
=
target
->
p
,
.
n
=
target
->
n
};
SToken
t
=
{
.
type
=
0
,
.
z
=
target
->
p
,
.
n
=
target
->
n
};
return
t
;
return
t
;
}
}
...
@@ -352,12 +352,13 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL
...
@@ -352,12 +352,13 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL
SNode
*
createBetweenAnd
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
,
SNode
*
pLeft
,
SNode
*
pRight
)
{
SNode
*
createBetweenAnd
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
,
SNode
*
pLeft
,
SNode
*
pRight
)
{
return
createLogicConditionNode
(
pCxt
,
LOGIC_COND_TYPE_AND
,
return
createLogicConditionNode
(
pCxt
,
LOGIC_COND_TYPE_AND
,
createOperatorNode
(
pCxt
,
OP_TYPE_GREATER_EQUAL
,
pExpr
,
pLeft
),
createOperatorNode
(
pCxt
,
OP_TYPE_LOWER_EQUAL
,
nodesCloneNode
(
pExpr
),
pRight
));
createOperatorNode
(
pCxt
,
OP_TYPE_GREATER_EQUAL
,
pExpr
,
pLeft
),
createOperatorNode
(
pCxt
,
OP_TYPE_LOWER_EQUAL
,
nodesCloneNode
(
pExpr
),
pRight
));
}
}
SNode
*
createNotBetweenAnd
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
,
SNode
*
pLeft
,
SNode
*
pRight
)
{
SNode
*
createNotBetweenAnd
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
,
SNode
*
pLeft
,
SNode
*
pRight
)
{
return
createLogicConditionNode
(
pCxt
,
LOGIC_COND_TYPE_OR
,
return
createLogicConditionNode
(
pCxt
,
LOGIC_COND_TYPE_OR
,
createOperatorNode
(
pCxt
,
OP_TYPE_LOWER_THAN
,
pExpr
,
pLeft
),
createOperatorNode
(
pCxt
,
OP_TYPE_LOWER_THAN
,
pExpr
,
pLeft
),
createOperatorNode
(
pCxt
,
OP_TYPE_GREATER_THAN
,
nodesCloneNode
(
pExpr
),
pRight
));
createOperatorNode
(
pCxt
,
OP_TYPE_GREATER_THAN
,
nodesCloneNode
(
pExpr
),
pRight
));
}
}
SNode
*
createFunctionNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFuncName
,
SNodeList
*
pParameterList
)
{
SNode
*
createFunctionNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFuncName
,
SNodeList
*
pParameterList
)
{
...
@@ -410,7 +411,7 @@ SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTa
...
@@ -410,7 +411,7 @@ SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTa
}
else
{
}
else
{
strncpy
(
realTable
->
table
.
tableAlias
,
pTableName
->
z
,
pTableName
->
n
);
strncpy
(
realTable
->
table
.
tableAlias
,
pTableName
->
z
,
pTableName
->
n
);
}
}
strncpy
(
realTable
->
table
.
tableName
,
pTableName
->
z
,
pTableName
->
n
);
strncpy
(
realTable
->
table
.
tableName
,
pTableName
->
z
,
pTableName
->
n
);
return
(
SNode
*
)
realTable
;
return
(
SNode
*
)
realTable
;
}
}
...
@@ -483,7 +484,8 @@ SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr) {
...
@@ -483,7 +484,8 @@ SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr) {
return
(
SNode
*
)
state
;
return
(
SNode
*
)
state
;
}
}
SNode
*
createIntervalWindowNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pInterval
,
SNode
*
pOffset
,
SNode
*
pSliding
,
SNode
*
pFill
)
{
SNode
*
createIntervalWindowNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pInterval
,
SNode
*
pOffset
,
SNode
*
pSliding
,
SNode
*
pFill
)
{
SIntervalWindowNode
*
interval
=
(
SIntervalWindowNode
*
)
nodesMakeNode
(
QUERY_NODE_INTERVAL_WINDOW
);
SIntervalWindowNode
*
interval
=
(
SIntervalWindowNode
*
)
nodesMakeNode
(
QUERY_NODE_INTERVAL_WINDOW
);
CHECK_OUT_OF_MEM
(
interval
);
CHECK_OUT_OF_MEM
(
interval
);
interval
->
pCol
=
nodesMakeNode
(
QUERY_NODE_COLUMN
);
interval
->
pCol
=
nodesMakeNode
(
QUERY_NODE_COLUMN
);
...
@@ -749,17 +751,17 @@ SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType
...
@@ -749,17 +751,17 @@ SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType
}
}
SDataType
createDataType
(
uint8_t
type
)
{
SDataType
createDataType
(
uint8_t
type
)
{
SDataType
dt
=
{
.
type
=
type
,
.
precision
=
0
,
.
scale
=
0
,
.
bytes
=
tDataTypes
[
type
].
bytes
};
SDataType
dt
=
{
.
type
=
type
,
.
precision
=
0
,
.
scale
=
0
,
.
bytes
=
tDataTypes
[
type
].
bytes
};
return
dt
;
return
dt
;
}
}
SDataType
createVarLenDataType
(
uint8_t
type
,
const
SToken
*
pLen
)
{
SDataType
createVarLenDataType
(
uint8_t
type
,
const
SToken
*
pLen
)
{
SDataType
dt
=
{
.
type
=
type
,
.
precision
=
0
,
.
scale
=
0
,
.
bytes
=
strtol
(
pLen
->
z
,
NULL
,
10
)
};
SDataType
dt
=
{
.
type
=
type
,
.
precision
=
0
,
.
scale
=
0
,
.
bytes
=
strtol
(
pLen
->
z
,
NULL
,
10
)
};
return
dt
;
return
dt
;
}
}
SNode
*
createCreateTableStmt
(
SAstCreateContext
*
pCxt
,
SNode
*
createCreateTableStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNodeList
*
pCols
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNodeList
*
pCols
,
SNodeList
*
pTags
,
SNode
*
pOptions
)
{
SNodeList
*
pTags
,
SNode
*
pOptions
)
{
if
(
NULL
==
pRealTable
)
{
if
(
NULL
==
pRealTable
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -775,8 +777,8 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt,
...
@@ -775,8 +777,8 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt,
return
(
SNode
*
)
pStmt
;
return
(
SNode
*
)
pStmt
;
}
}
SNode
*
createCreateSubTableClause
(
SAstCreateContext
*
pCxt
,
SNode
*
createCreateSubTableClause
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNode
*
pUseRealTable
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNode
*
pUseRealTable
,
SNodeList
*
pSpecificTags
,
SNodeList
*
pValsOfTags
)
{
SNodeList
*
pSpecificTags
,
SNodeList
*
pValsOfTags
)
{
if
(
NULL
==
pRealTable
)
{
if
(
NULL
==
pRealTable
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -842,7 +844,8 @@ SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode*
...
@@ -842,7 +844,8 @@ SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode*
return
(
SNode
*
)
pStmt
;
return
(
SNode
*
)
pStmt
;
}
}
SNode
*
createAlterTableAddModifyCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pColName
,
SDataType
dataType
)
{
SNode
*
createAlterTableAddModifyCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pColName
,
SDataType
dataType
)
{
if
(
NULL
==
pRealTable
)
{
if
(
NULL
==
pRealTable
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -865,7 +868,8 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_
...
@@ -865,7 +868,8 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_
return
(
SNode
*
)
pStmt
;
return
(
SNode
*
)
pStmt
;
}
}
SNode
*
createAlterTableRenameCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pOldColName
,
const
SToken
*
pNewColName
)
{
SNode
*
createAlterTableRenameCol
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
,
int8_t
alterType
,
const
SToken
*
pOldColName
,
const
SToken
*
pNewColName
)
{
if
(
NULL
==
pRealTable
)
{
if
(
NULL
==
pRealTable
)
{
return
NULL
;
return
NULL
;
}
}
...
@@ -900,7 +904,8 @@ SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) {
...
@@ -900,7 +904,8 @@ SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) {
}
}
static
bool
needDbShowStmt
(
ENodeType
type
)
{
static
bool
needDbShowStmt
(
ENodeType
type
)
{
return
QUERY_NODE_SHOW_TABLES_STMT
==
type
||
QUERY_NODE_SHOW_STABLES_STMT
==
type
||
QUERY_NODE_SHOW_VGROUPS_STMT
==
type
;
return
QUERY_NODE_SHOW_TABLES_STMT
==
type
||
QUERY_NODE_SHOW_STABLES_STMT
==
type
||
QUERY_NODE_SHOW_VGROUPS_STMT
==
type
;
}
}
SNode
*
createShowStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
SNode
*
pDbName
,
SNode
*
pTbNamePattern
)
{
SNode
*
createShowStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
SNode
*
pDbName
,
SNode
*
pTbNamePattern
)
{
...
@@ -909,7 +914,8 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, S
...
@@ -909,7 +914,8 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, S
pCxt
->
valid
=
false
;
pCxt
->
valid
=
false
;
return
NULL
;
return
NULL
;
}
}
SShowStmt
*
pStmt
=
nodesMakeNode
(
type
);;
SShowStmt
*
pStmt
=
nodesMakeNode
(
type
);
;
CHECK_OUT_OF_MEM
(
pStmt
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
pDbName
=
pDbName
;
pStmt
->
pDbName
=
pDbName
;
pStmt
->
pTbNamePattern
=
pTbNamePattern
;
pStmt
->
pTbNamePattern
=
pTbNamePattern
;
...
@@ -971,7 +977,7 @@ SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName) {
...
@@ -971,7 +977,7 @@ SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName) {
SNode
*
createCreateDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFqdn
,
const
SToken
*
pPort
)
{
SNode
*
createCreateDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFqdn
,
const
SToken
*
pPort
)
{
int32_t
port
=
0
;
int32_t
port
=
0
;
char
fqdn
[
TSDB_FQDN_LEN
]
=
{
0
};
char
fqdn
[
TSDB_FQDN_LEN
]
=
{
0
};
if
(
NULL
==
pPort
)
{
if
(
NULL
==
pPort
)
{
if
(
!
checkAndSplitEndpoint
(
pCxt
,
pFqdn
,
fqdn
,
&
port
))
{
if
(
!
checkAndSplitEndpoint
(
pCxt
,
pFqdn
,
fqdn
,
&
port
))
{
return
NULL
;
return
NULL
;
...
@@ -1004,7 +1010,8 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) {
...
@@ -1004,7 +1010,8 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) {
return
(
SNode
*
)
pStmt
;
return
(
SNode
*
)
pStmt
;
}
}
SNode
*
createAlterDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDnode
,
const
SToken
*
pConfig
,
const
SToken
*
pValue
)
{
SNode
*
createAlterDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDnode
,
const
SToken
*
pConfig
,
const
SToken
*
pValue
)
{
SAlterDnodeStmt
*
pStmt
=
nodesMakeNode
(
QUERY_NODE_ALTER_DNODE_STMT
);
SAlterDnodeStmt
*
pStmt
=
nodesMakeNode
(
QUERY_NODE_ALTER_DNODE_STMT
);
CHECK_OUT_OF_MEM
(
pStmt
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
dnodeId
=
strtol
(
pDnode
->
z
,
NULL
,
10
);
pStmt
->
dnodeId
=
strtol
(
pDnode
->
z
,
NULL
,
10
);
...
@@ -1015,7 +1022,8 @@ SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const
...
@@ -1015,7 +1022,8 @@ SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const
return
(
SNode
*
)
pStmt
;
return
(
SNode
*
)
pStmt
;
}
}
SNode
*
createCreateIndexStmt
(
SAstCreateContext
*
pCxt
,
EIndexType
type
,
bool
ignoreExists
,
SToken
*
pIndexName
,
SToken
*
pTableName
,
SNodeList
*
pCols
,
SNode
*
pOptions
)
{
SNode
*
createCreateIndexStmt
(
SAstCreateContext
*
pCxt
,
EIndexType
type
,
bool
ignoreExists
,
SToken
*
pIndexName
,
SToken
*
pTableName
,
SNodeList
*
pCols
,
SNode
*
pOptions
)
{
if
(
!
checkIndexName
(
pCxt
,
pIndexName
)
||
!
checkTableName
(
pCxt
,
pTableName
))
{
if
(
!
checkIndexName
(
pCxt
,
pIndexName
)
||
!
checkTableName
(
pCxt
,
pTableName
))
{
return
NULL
;
return
NULL
;
}
}
...
@@ -1030,7 +1038,8 @@ SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool igno
...
@@ -1030,7 +1038,8 @@ SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool igno
return
(
SNode
*
)
pStmt
;
return
(
SNode
*
)
pStmt
;
}
}
SNode
*
createIndexOption
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pFuncs
,
SNode
*
pInterval
,
SNode
*
pOffset
,
SNode
*
pSliding
)
{
SNode
*
createIndexOption
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pFuncs
,
SNode
*
pInterval
,
SNode
*
pOffset
,
SNode
*
pSliding
)
{
SIndexOptions
*
pOptions
=
nodesMakeNode
(
QUERY_NODE_INDEX_OPTIONS
);
SIndexOptions
*
pOptions
=
nodesMakeNode
(
QUERY_NODE_INDEX_OPTIONS
);
CHECK_OUT_OF_MEM
(
pOptions
);
CHECK_OUT_OF_MEM
(
pOptions
);
pOptions
->
pFuncs
=
pFuncs
;
pOptions
->
pFuncs
=
pFuncs
;
...
@@ -1055,14 +1064,16 @@ SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken
...
@@ -1055,14 +1064,16 @@ SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken
SNode
*
createCreateComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
)
{
SNode
*
createCreateComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
)
{
SCreateComponentNodeStmt
*
pStmt
=
nodesMakeNode
(
type
);
SCreateComponentNodeStmt
*
pStmt
=
nodesMakeNode
(
type
);
CHECK_OUT_OF_MEM
(
pStmt
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
dnodeId
=
strtol
(
pDnodeId
->
z
,
NULL
,
10
);;
pStmt
->
dnodeId
=
strtol
(
pDnodeId
->
z
,
NULL
,
10
);
;
return
(
SNode
*
)
pStmt
;
return
(
SNode
*
)
pStmt
;
}
}
SNode
*
createDropComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
)
{
SNode
*
createDropComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
)
{
SDropComponentNodeStmt
*
pStmt
=
nodesMakeNode
(
type
);
SDropComponentNodeStmt
*
pStmt
=
nodesMakeNode
(
type
);
CHECK_OUT_OF_MEM
(
pStmt
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
dnodeId
=
strtol
(
pDnodeId
->
z
,
NULL
,
10
);;
pStmt
->
dnodeId
=
strtol
(
pDnodeId
->
z
,
NULL
,
10
);
;
return
(
SNode
*
)
pStmt
;
return
(
SNode
*
)
pStmt
;
}
}
...
@@ -1075,8 +1086,8 @@ SNode* createTopicOptions(SAstCreateContext* pCxt) {
...
@@ -1075,8 +1086,8 @@ SNode* createTopicOptions(SAstCreateContext* pCxt) {
return
(
SNode
*
)
pOptions
;
return
(
SNode
*
)
pOptions
;
}
}
SNode
*
createCreateTopicStmt
(
SAstCreateContext
*
pCxt
,
SNode
*
createCreateTopicStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
const
SToken
*
pTopicName
,
SNode
*
pQuery
,
bool
ignoreExists
,
const
SToken
*
pTopicName
,
SNode
*
pQuery
,
const
SToken
*
pSubscribeDbName
,
SNode
*
pOptions
)
{
const
SToken
*
pSubscribeDbName
,
SNode
*
pOptions
)
{
SCreateTopicStmt
*
pStmt
=
nodesMakeNode
(
QUERY_NODE_CREATE_TOPIC_STMT
);
SCreateTopicStmt
*
pStmt
=
nodesMakeNode
(
QUERY_NODE_CREATE_TOPIC_STMT
);
CHECK_OUT_OF_MEM
(
pStmt
);
CHECK_OUT_OF_MEM
(
pStmt
);
strncpy
(
pStmt
->
topicName
,
pTopicName
->
z
,
pTopicName
->
n
);
strncpy
(
pStmt
->
topicName
,
pTopicName
->
z
,
pTopicName
->
n
);
...
@@ -1158,8 +1169,8 @@ SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups) {
...
@@ -1158,8 +1169,8 @@ SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups) {
return
pStmt
;
return
pStmt
;
}
}
SNode
*
createCreateFunctionStmt
(
SAstCreateContext
*
pCxt
,
SNode
*
createCreateFunctionStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
bool
aggFunc
,
const
SToken
*
pFuncName
,
bool
ignoreExists
,
bool
aggFunc
,
const
SToken
*
pFuncName
,
const
SToken
*
pLibPath
,
SDataType
dataType
,
int32_t
bufSize
)
{
const
SToken
*
pLibPath
,
SDataType
dataType
,
int32_t
bufSize
)
{
if
(
pLibPath
->
n
<=
2
)
{
if
(
pLibPath
->
n
<=
2
)
{
pCxt
->
valid
=
false
;
pCxt
->
valid
=
false
;
return
NULL
;
return
NULL
;
...
@@ -1188,7 +1199,8 @@ SNode* createStreamOptions(SAstCreateContext* pCxt) {
...
@@ -1188,7 +1199,8 @@ SNode* createStreamOptions(SAstCreateContext* pCxt) {
return
(
SNode
*
)
pOptions
;
return
(
SNode
*
)
pOptions
;
}
}
SNode
*
createCreateStreamStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
const
SToken
*
pStreamName
,
SNode
*
pRealTable
,
SNode
*
pOptions
,
SNode
*
pQuery
)
{
SNode
*
createCreateStreamStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
const
SToken
*
pStreamName
,
SNode
*
pRealTable
,
SNode
*
pOptions
,
SNode
*
pQuery
)
{
SCreateStreamStmt
*
pStmt
=
nodesMakeNode
(
QUERY_NODE_CREATE_STREAM_STMT
);
SCreateStreamStmt
*
pStmt
=
nodesMakeNode
(
QUERY_NODE_CREATE_STREAM_STMT
);
CHECK_OUT_OF_MEM
(
pStmt
);
CHECK_OUT_OF_MEM
(
pStmt
);
strncpy
(
pStmt
->
streamName
,
pStreamName
->
z
,
pStreamName
->
n
);
strncpy
(
pStmt
->
streamName
,
pStreamName
->
z
,
pStreamName
->
n
);
...
...
source/libs/parser/src/parAstParser.c
浏览文件 @
ac874f9e
...
@@ -23,14 +23,14 @@ typedef void* (*FMalloc)(size_t);
...
@@ -23,14 +23,14 @@ typedef void* (*FMalloc)(size_t);
typedef
void
(
*
FFree
)(
void
*
);
typedef
void
(
*
FFree
)(
void
*
);
extern
void
*
ParseAlloc
(
FMalloc
);
extern
void
*
ParseAlloc
(
FMalloc
);
extern
void
Parse
(
void
*
,
int
,
SToken
,
void
*
);
extern
void
Parse
(
void
*
,
int
,
SToken
,
void
*
);
extern
void
ParseFree
(
void
*
,
FFree
);
extern
void
ParseFree
(
void
*
,
FFree
);
extern
void
ParseTrace
(
FILE
*
,
char
*
);
extern
void
ParseTrace
(
FILE
*
,
char
*
);
int32_t
parse
(
SParseContext
*
pParseCxt
,
SQuery
**
pQuery
)
{
int32_t
parse
(
SParseContext
*
pParseCxt
,
SQuery
**
pQuery
)
{
SAstCreateContext
cxt
;
SAstCreateContext
cxt
;
initAstCreateContext
(
pParseCxt
,
&
cxt
);
initAstCreateContext
(
pParseCxt
,
&
cxt
);
void
*
pParser
=
ParseAlloc
((
FMalloc
)
taosMemoryMalloc
);
void
*
pParser
=
ParseAlloc
((
FMalloc
)
taosMemoryMalloc
);
int32_t
i
=
0
;
int32_t
i
=
0
;
while
(
1
)
{
while
(
1
)
{
SToken
t0
=
{
0
};
SToken
t0
=
{
0
};
...
@@ -38,8 +38,8 @@ int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) {
...
@@ -38,8 +38,8 @@ int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) {
Parse
(
pParser
,
0
,
t0
,
&
cxt
);
Parse
(
pParser
,
0
,
t0
,
&
cxt
);
goto
abort_parse
;
goto
abort_parse
;
}
}
t0
.
n
=
tGetToken
((
char
*
)
&
cxt
.
pQueryCxt
->
pSql
[
i
],
&
t0
.
type
);
t0
.
n
=
tGetToken
((
char
*
)
&
cxt
.
pQueryCxt
->
pSql
[
i
],
&
t0
.
type
);
t0
.
z
=
(
char
*
)(
cxt
.
pQueryCxt
->
pSql
+
i
);
t0
.
z
=
(
char
*
)(
cxt
.
pQueryCxt
->
pSql
+
i
);
i
+=
t0
.
n
;
i
+=
t0
.
n
;
switch
(
t0
.
type
)
{
switch
(
t0
.
type
)
{
...
...
source/libs/parser/src/parCalcConst.c
浏览文件 @
ac874f9e
...
@@ -20,8 +20,8 @@
...
@@ -20,8 +20,8 @@
typedef
struct
SCalcConstContext
{
typedef
struct
SCalcConstContext
{
SParseContext
*
pParseCxt
;
SParseContext
*
pParseCxt
;
SMsgBuf
msgBuf
;
SMsgBuf
msgBuf
;
int32_t
code
;
int32_t
code
;
}
SCalcConstContext
;
}
SCalcConstContext
;
static
int32_t
calcConstQuery
(
SCalcConstContext
*
pCxt
,
SNode
*
pStmt
,
bool
subquery
);
static
int32_t
calcConstQuery
(
SCalcConstContext
*
pCxt
,
SNode
*
pStmt
,
bool
subquery
);
...
@@ -35,7 +35,7 @@ static int32_t calcConstNode(SNode** pNode) {
...
@@ -35,7 +35,7 @@ static int32_t calcConstNode(SNode** pNode) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
SNode
*
pNew
=
NULL
;
SNode
*
pNew
=
NULL
;
int32_t
code
=
scalarCalculateConstants
(
*
pNode
,
&
pNew
);
int32_t
code
=
scalarCalculateConstants
(
*
pNode
,
&
pNew
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pNode
=
pNew
;
*
pNode
=
pNew
;
...
@@ -46,7 +46,7 @@ static int32_t calcConstNode(SNode** pNode) {
...
@@ -46,7 +46,7 @@ static int32_t calcConstNode(SNode** pNode) {
static
int32_t
calcConstList
(
SNodeList
*
pList
)
{
static
int32_t
calcConstList
(
SNodeList
*
pList
)
{
SNode
*
pNode
=
NULL
;
SNode
*
pNode
=
NULL
;
FOREACH
(
pNode
,
pList
)
{
FOREACH
(
pNode
,
pList
)
{
SNode
*
pNew
=
NULL
;
SNode
*
pNew
=
NULL
;
int32_t
code
=
scalarCalculateConstants
(
pNode
,
&
pNew
);
int32_t
code
=
scalarCalculateConstants
(
pNode
,
&
pNew
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
REPLACE_NODE
(
pNew
);
REPLACE_NODE
(
pNew
);
...
@@ -128,7 +128,7 @@ static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTab
...
@@ -128,7 +128,7 @@ static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTab
}
}
// todo empty table
// todo empty table
break
;
break
;
}
}
default:
default:
break
;
break
;
}
}
...
@@ -196,7 +196,7 @@ static int32_t calcConstProjections(SCalcConstContext* pCxt, SNodeList* pProject
...
@@ -196,7 +196,7 @@ static int32_t calcConstProjections(SCalcConstContext* pCxt, SNodeList* pProject
ERASE_NODE
(
pProjections
);
ERASE_NODE
(
pProjections
);
continue
;
continue
;
}
}
SNode
*
pNew
=
NULL
;
SNode
*
pNew
=
NULL
;
int32_t
code
=
calcConstProject
(
pProj
,
&
pNew
);
int32_t
code
=
calcConstProject
(
pProj
,
&
pNew
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
REPLACE_NODE
(
pNew
);
REPLACE_NODE
(
pNew
);
...
@@ -281,13 +281,11 @@ static bool isEmptyResultQuery(SNode* pStmt) {
...
@@ -281,13 +281,11 @@ static bool isEmptyResultQuery(SNode* pStmt) {
}
}
int32_t
calculateConstant
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
)
{
int32_t
calculateConstant
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
)
{
SCalcConstContext
cxt
=
{
SCalcConstContext
cxt
=
{.
pParseCxt
=
pParseCxt
,
.
pParseCxt
=
pParseCxt
,
.
msgBuf
.
buf
=
pParseCxt
->
pMsg
,
.
msgBuf
.
buf
=
pParseCxt
->
pMsg
,
.
msgBuf
.
len
=
pParseCxt
->
msgLen
,
.
msgBuf
.
len
=
pParseCxt
->
msgLen
,
.
code
=
TSDB_CODE_SUCCESS
};
.
code
=
TSDB_CODE_SUCCESS
int32_t
code
=
calcConstQuery
(
&
cxt
,
pQuery
->
pRoot
,
false
);
};
int32_t
code
=
calcConstQuery
(
&
cxt
,
pQuery
->
pRoot
,
false
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
isEmptyResultQuery
(
pQuery
->
pRoot
))
{
if
(
TSDB_CODE_SUCCESS
==
code
&&
isEmptyResultQuery
(
pQuery
->
pRoot
))
{
pQuery
->
execMode
=
QUERY_EXEC_MODE_EMPTY_RESULT
;
pQuery
->
execMode
=
QUERY_EXEC_MODE_EMPTY_RESULT
;
}
}
...
...
source/libs/parser/src/parInsert.c
浏览文件 @
ac874f9e
此差异已折叠。
点击以展开。
source/libs/parser/src/parInsertData.c
浏览文件 @
ac874f9e
...
@@ -16,9 +16,9 @@
...
@@ -16,9 +16,9 @@
#include "parInsertData.h"
#include "parInsertData.h"
#include "catalog.h"
#include "catalog.h"
#include "parInt.h"
#include "parUtil.h"
#include "parUtil.h"
#include "querynodes.h"
#include "querynodes.h"
#include "parInt.h"
#define IS_RAW_PAYLOAD(t) \
#define IS_RAW_PAYLOAD(t) \
(((int)(t)) == PAYLOAD_TYPE_RAW) // 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
(((int)(t)) == PAYLOAD_TYPE_RAW) // 0: K-V payload for non-prepare insert, 1: rawPayload for prepare insert
...
@@ -33,9 +33,9 @@ typedef struct SBlockKeyInfo {
...
@@ -33,9 +33,9 @@ typedef struct SBlockKeyInfo {
SBlockKeyTuple
*
pKeyTuple
;
SBlockKeyTuple
*
pKeyTuple
;
}
SBlockKeyInfo
;
}
SBlockKeyInfo
;
static
int32_t
rowDataCompar
(
const
void
*
lhs
,
const
void
*
rhs
)
{
static
int32_t
rowDataCompar
(
const
void
*
lhs
,
const
void
*
rhs
)
{
TSKEY
left
=
*
(
TSKEY
*
)
lhs
;
TSKEY
left
=
*
(
TSKEY
*
)
lhs
;
TSKEY
right
=
*
(
TSKEY
*
)
rhs
;
TSKEY
right
=
*
(
TSKEY
*
)
rhs
;
if
(
left
==
right
)
{
if
(
left
==
right
)
{
return
0
;
return
0
;
...
@@ -81,9 +81,9 @@ void setBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, col_id_t
...
@@ -81,9 +81,9 @@ void setBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, col_id_t
pColList
->
extendedVarLen
=
(
uint16_t
)(
nVar
*
sizeof
(
VarDataOffsetT
));
pColList
->
extendedVarLen
=
(
uint16_t
)(
nVar
*
sizeof
(
VarDataOffsetT
));
}
}
int32_t
schemaIdxCompar
(
const
void
*
lhs
,
const
void
*
rhs
)
{
int32_t
schemaIdxCompar
(
const
void
*
lhs
,
const
void
*
rhs
)
{
uint16_t
left
=
*
(
uint16_t
*
)
lhs
;
uint16_t
left
=
*
(
uint16_t
*
)
lhs
;
uint16_t
right
=
*
(
uint16_t
*
)
rhs
;
uint16_t
right
=
*
(
uint16_t
*
)
rhs
;
if
(
left
==
right
)
{
if
(
left
==
right
)
{
return
0
;
return
0
;
...
@@ -92,9 +92,9 @@ int32_t schemaIdxCompar(const void *lhs, const void *rhs) {
...
@@ -92,9 +92,9 @@ int32_t schemaIdxCompar(const void *lhs, const void *rhs) {
}
}
}
}
int32_t
boundIdxCompar
(
const
void
*
lhs
,
const
void
*
rhs
)
{
int32_t
boundIdxCompar
(
const
void
*
lhs
,
const
void
*
rhs
)
{
uint16_t
left
=
*
(
uint16_t
*
)
POINTER_SHIFT
(
lhs
,
sizeof
(
uint16_t
));
uint16_t
left
=
*
(
uint16_t
*
)
POINTER_SHIFT
(
lhs
,
sizeof
(
uint16_t
));
uint16_t
right
=
*
(
uint16_t
*
)
POINTER_SHIFT
(
rhs
,
sizeof
(
uint16_t
));
uint16_t
right
=
*
(
uint16_t
*
)
POINTER_SHIFT
(
rhs
,
sizeof
(
uint16_t
));
if
(
left
==
right
)
{
if
(
left
==
right
)
{
return
0
;
return
0
;
...
@@ -109,14 +109,14 @@ void destroyBoundColumnInfo(void* pBoundInfo) {
...
@@ -109,14 +109,14 @@ void destroyBoundColumnInfo(void* pBoundInfo) {
}
}
SParsedDataColInfo
*
pColList
=
(
SParsedDataColInfo
*
)
pBoundInfo
;
SParsedDataColInfo
*
pColList
=
(
SParsedDataColInfo
*
)
pBoundInfo
;
taosMemoryFreeClear
(
pColList
->
boundColumns
);
taosMemoryFreeClear
(
pColList
->
boundColumns
);
taosMemoryFreeClear
(
pColList
->
cols
);
taosMemoryFreeClear
(
pColList
->
cols
);
taosMemoryFreeClear
(
pColList
->
colIdxInfo
);
taosMemoryFreeClear
(
pColList
->
colIdxInfo
);
}
}
static
int32_t
createDataBlock
(
size_t
defaultSize
,
int32_t
rowSize
,
int32_t
startOffset
,
static
int32_t
createDataBlock
(
size_t
defaultSize
,
int32_t
rowSize
,
int32_t
startOffset
,
const
STableMeta
*
pTableMeta
,
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
)
{
STableDataBlocks
**
dataBlocks
)
{
STableDataBlocks
*
dataBuf
=
(
STableDataBlocks
*
)
taosMemoryCalloc
(
1
,
sizeof
(
STableDataBlocks
));
STableDataBlocks
*
dataBuf
=
(
STableDataBlocks
*
)
taosMemoryCalloc
(
1
,
sizeof
(
STableDataBlocks
));
if
(
dataBuf
==
NULL
)
{
if
(
dataBuf
==
NULL
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
...
@@ -137,18 +137,18 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star
...
@@ -137,18 +137,18 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star
}
}
memset
(
dataBuf
->
pData
,
0
,
sizeof
(
SSubmitBlk
));
memset
(
dataBuf
->
pData
,
0
,
sizeof
(
SSubmitBlk
));
//Here we keep the tableMeta to avoid it to be remove by other threads.
//
Here we keep the tableMeta to avoid it to be remove by other threads.
dataBuf
->
pTableMeta
=
tableMetaDup
(
pTableMeta
);
dataBuf
->
pTableMeta
=
tableMetaDup
(
pTableMeta
);
SParsedDataColInfo
*
pColInfo
=
&
dataBuf
->
boundColumnInfo
;
SParsedDataColInfo
*
pColInfo
=
&
dataBuf
->
boundColumnInfo
;
SSchema
*
pSchema
=
getTableColumnSchema
(
dataBuf
->
pTableMeta
);
SSchema
*
pSchema
=
getTableColumnSchema
(
dataBuf
->
pTableMeta
);
setBoundColumnInfo
(
pColInfo
,
pSchema
,
dataBuf
->
pTableMeta
->
tableInfo
.
numOfColumns
);
setBoundColumnInfo
(
pColInfo
,
pSchema
,
dataBuf
->
pTableMeta
->
tableInfo
.
numOfColumns
);
dataBuf
->
ordered
=
true
;
dataBuf
->
ordered
=
true
;
dataBuf
->
prevTS
=
INT64_MIN
;
dataBuf
->
prevTS
=
INT64_MIN
;
dataBuf
->
rowSize
=
rowSize
;
dataBuf
->
rowSize
=
rowSize
;
dataBuf
->
size
=
startOffset
;
dataBuf
->
size
=
startOffset
;
dataBuf
->
vgId
=
dataBuf
->
pTableMeta
->
vgId
;
dataBuf
->
vgId
=
dataBuf
->
pTableMeta
->
vgId
;
assert
(
defaultSize
>
0
&&
pTableMeta
!=
NULL
&&
dataBuf
->
pTableMeta
!=
NULL
);
assert
(
defaultSize
>
0
&&
pTableMeta
!=
NULL
&&
dataBuf
->
pTableMeta
!=
NULL
);
...
@@ -177,7 +177,8 @@ int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq)
...
@@ -177,7 +177,8 @@ int32_t buildCreateTbMsg(STableDataBlocks* pBlocks, SVCreateTbReq* pCreateTbReq)
}
}
int32_t
getDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
int32_t
getDataBlockFromList
(
SHashObj
*
pHashList
,
int64_t
id
,
int32_t
size
,
int32_t
startOffset
,
int32_t
rowSize
,
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
,
SVCreateTbReq
*
pCreateTbReq
)
{
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
,
SVCreateTbReq
*
pCreateTbReq
)
{
*
dataBlocks
=
NULL
;
*
dataBlocks
=
NULL
;
STableDataBlocks
**
t1
=
(
STableDataBlocks
**
)
taosHashGet
(
pHashList
,
(
const
char
*
)
&
id
,
sizeof
(
id
));
STableDataBlocks
**
t1
=
(
STableDataBlocks
**
)
taosHashGet
(
pHashList
,
(
const
char
*
)
&
id
,
sizeof
(
id
));
if
(
t1
!=
NULL
)
{
if
(
t1
!=
NULL
)
{
...
@@ -267,14 +268,14 @@ void destroyBlockHashmap(SHashObj* pDataBlockHash) {
...
@@ -267,14 +268,14 @@ void destroyBlockHashmap(SHashObj* pDataBlockHash) {
}
}
// data block is disordered, sort it in ascending order
// data block is disordered, sort it in ascending order
void
sortRemoveDataBlockDupRowsRaw
(
STableDataBlocks
*
dataBuf
)
{
void
sortRemoveDataBlockDupRowsRaw
(
STableDataBlocks
*
dataBuf
)
{
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
dataBuf
->
pData
;
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
dataBuf
->
pData
;
// size is less than the total size, since duplicated rows may be removed yet.
// size is less than the total size, since duplicated rows may be removed yet.
assert
(
pBlocks
->
numOfRows
*
dataBuf
->
rowSize
+
sizeof
(
SSubmitBlk
)
==
dataBuf
->
size
);
assert
(
pBlocks
->
numOfRows
*
dataBuf
->
rowSize
+
sizeof
(
SSubmitBlk
)
==
dataBuf
->
size
);
if
(
!
dataBuf
->
ordered
)
{
if
(
!
dataBuf
->
ordered
)
{
char
*
pBlockData
=
pBlocks
->
data
;
char
*
pBlockData
=
pBlocks
->
data
;
qsort
(
pBlockData
,
pBlocks
->
numOfRows
,
dataBuf
->
rowSize
,
rowDataCompar
);
qsort
(
pBlockData
,
pBlocks
->
numOfRows
,
dataBuf
->
rowSize
,
rowDataCompar
);
int32_t
i
=
0
;
int32_t
i
=
0
;
...
@@ -282,8 +283,8 @@ void sortRemoveDataBlockDupRowsRaw(STableDataBlocks *dataBuf) {
...
@@ -282,8 +283,8 @@ void sortRemoveDataBlockDupRowsRaw(STableDataBlocks *dataBuf) {
// delete rows with timestamp conflicts
// delete rows with timestamp conflicts
while
(
j
<
pBlocks
->
numOfRows
)
{
while
(
j
<
pBlocks
->
numOfRows
)
{
TSKEY
ti
=
*
(
TSKEY
*
)(
pBlockData
+
dataBuf
->
rowSize
*
i
);
TSKEY
ti
=
*
(
TSKEY
*
)(
pBlockData
+
dataBuf
->
rowSize
*
i
);
TSKEY
tj
=
*
(
TSKEY
*
)(
pBlockData
+
dataBuf
->
rowSize
*
j
);
TSKEY
tj
=
*
(
TSKEY
*
)(
pBlockData
+
dataBuf
->
rowSize
*
j
);
if
(
ti
==
tj
)
{
if
(
ti
==
tj
)
{
++
j
;
++
j
;
...
@@ -308,8 +309,8 @@ void sortRemoveDataBlockDupRowsRaw(STableDataBlocks *dataBuf) {
...
@@ -308,8 +309,8 @@ void sortRemoveDataBlockDupRowsRaw(STableDataBlocks *dataBuf) {
}
}
// data block is disordered, sort it in ascending order
// data block is disordered, sort it in ascending order
int
sortRemoveDataBlockDupRows
(
STableDataBlocks
*
dataBuf
,
SBlockKeyInfo
*
pBlkKeyInfo
)
{
int
sortRemoveDataBlockDupRows
(
STableDataBlocks
*
dataBuf
,
SBlockKeyInfo
*
pBlkKeyInfo
)
{
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
dataBuf
->
pData
;
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
dataBuf
->
pData
;
int16_t
nRows
=
pBlocks
->
numOfRows
;
int16_t
nRows
=
pBlocks
->
numOfRows
;
// size is less than the total size, since duplicated rows may be removed yet.
// size is less than the total size, since duplicated rows may be removed yet.
...
@@ -317,21 +318,21 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey
...
@@ -317,21 +318,21 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey
// allocate memory
// allocate memory
size_t
nAlloc
=
nRows
*
sizeof
(
SBlockKeyTuple
);
size_t
nAlloc
=
nRows
*
sizeof
(
SBlockKeyTuple
);
if
(
pBlkKeyInfo
->
pKeyTuple
==
NULL
||
pBlkKeyInfo
->
maxBytesAlloc
<
nAlloc
)
{
if
(
pBlkKeyInfo
->
pKeyTuple
==
NULL
||
pBlkKeyInfo
->
maxBytesAlloc
<
nAlloc
)
{
char
*
tmp
=
taosMemoryRealloc
(
pBlkKeyInfo
->
pKeyTuple
,
nAlloc
);
char
*
tmp
=
taosMemoryRealloc
(
pBlkKeyInfo
->
pKeyTuple
,
nAlloc
);
if
(
tmp
==
NULL
)
{
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
}
pBlkKeyInfo
->
pKeyTuple
=
(
SBlockKeyTuple
*
)
tmp
;
pBlkKeyInfo
->
pKeyTuple
=
(
SBlockKeyTuple
*
)
tmp
;
pBlkKeyInfo
->
maxBytesAlloc
=
(
int32_t
)
nAlloc
;
pBlkKeyInfo
->
maxBytesAlloc
=
(
int32_t
)
nAlloc
;
}
}
memset
(
pBlkKeyInfo
->
pKeyTuple
,
0
,
nAlloc
);
memset
(
pBlkKeyInfo
->
pKeyTuple
,
0
,
nAlloc
);
int32_t
extendedRowSize
=
getExtendedRowSize
(
dataBuf
);
int32_t
extendedRowSize
=
getExtendedRowSize
(
dataBuf
);
SBlockKeyTuple
*
pBlkKeyTuple
=
pBlkKeyInfo
->
pKeyTuple
;
SBlockKeyTuple
*
pBlkKeyTuple
=
pBlkKeyInfo
->
pKeyTuple
;
char
*
pBlockData
=
pBlocks
->
data
+
pBlocks
->
schemaLen
;
char
*
pBlockData
=
pBlocks
->
data
+
pBlocks
->
schemaLen
;
int
n
=
0
;
int
n
=
0
;
while
(
n
<
nRows
)
{
while
(
n
<
nRows
)
{
pBlkKeyTuple
->
skey
=
TD_ROW_KEY
((
STSRow
*
)
pBlockData
);
pBlkKeyTuple
->
skey
=
TD_ROW_KEY
((
STSRow
*
)
pBlockData
);
pBlkKeyTuple
->
payloadAddr
=
pBlockData
;
pBlkKeyTuple
->
payloadAddr
=
pBlockData
;
// next loop
// next loop
...
@@ -374,13 +375,14 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey
...
@@ -374,13 +375,14 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey
}
}
// Erase the empty space reserved for binary data
// Erase the empty space reserved for binary data
static
int
trimDataBlock
(
void
*
pDataBlock
,
STableDataBlocks
*
pTableDataBlock
,
SBlockKeyTuple
*
blkKeyTuple
,
bool
isRawPayload
)
{
static
int
trimDataBlock
(
void
*
pDataBlock
,
STableDataBlocks
*
pTableDataBlock
,
SBlockKeyTuple
*
blkKeyTuple
,
bool
isRawPayload
)
{
// TODO: optimize this function, handle the case while binary is not presented
// TODO: optimize this function, handle the case while binary is not presented
STableMeta
*
pTableMeta
=
pTableDataBlock
->
pTableMeta
;
STableMeta
*
pTableMeta
=
pTableDataBlock
->
pTableMeta
;
STableComInfo
tinfo
=
getTableInfo
(
pTableMeta
);
STableComInfo
tinfo
=
getTableInfo
(
pTableMeta
);
SSchema
*
pSchema
=
getTableColumnSchema
(
pTableMeta
);
SSchema
*
pSchema
=
getTableColumnSchema
(
pTableMeta
);
int32_t
nonDataLen
=
sizeof
(
SSubmitBlk
)
+
pTableDataBlock
->
createTbReqLen
;
int32_t
nonDataLen
=
sizeof
(
SSubmitBlk
)
+
pTableDataBlock
->
createTbReqLen
;
SSubmitBlk
*
pBlock
=
pDataBlock
;
SSubmitBlk
*
pBlock
=
pDataBlock
;
memcpy
(
pDataBlock
,
pTableDataBlock
->
pData
,
nonDataLen
);
memcpy
(
pDataBlock
,
pTableDataBlock
->
pData
,
nonDataLen
);
pDataBlock
=
(
char
*
)
pDataBlock
+
nonDataLen
;
pDataBlock
=
(
char
*
)
pDataBlock
+
nonDataLen
;
...
@@ -399,7 +401,7 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SB
...
@@ -399,7 +401,7 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SB
if
(
isRawPayload
)
{
if
(
isRawPayload
)
{
SRowBuilder
builder
=
{
0
};
SRowBuilder
builder
=
{
0
};
tdSRowInit
(
&
builder
,
pTableMeta
->
sversion
);
tdSRowInit
(
&
builder
,
pTableMeta
->
sversion
);
tdSRowSetInfo
(
&
builder
,
getNumOfColumns
(
pTableMeta
),
-
1
,
flen
);
tdSRowSetInfo
(
&
builder
,
getNumOfColumns
(
pTableMeta
),
-
1
,
flen
);
...
@@ -419,8 +421,8 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SB
...
@@ -419,8 +421,8 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SB
}
}
}
else
{
}
else
{
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
char
*
payload
=
(
blkKeyTuple
+
i
)
->
payloadAddr
;
char
*
payload
=
(
blkKeyTuple
+
i
)
->
payloadAddr
;
TDRowLenT
rowTLen
=
TD_ROW_LEN
((
STSRow
*
)
payload
);
TDRowLenT
rowTLen
=
TD_ROW_LEN
((
STSRow
*
)
payload
);
memcpy
(
pDataBlock
,
payload
,
rowTLen
);
memcpy
(
pDataBlock
,
payload
,
rowTLen
);
pDataBlock
=
POINTER_SHIFT
(
pDataBlock
,
rowTLen
);
pDataBlock
=
POINTER_SHIFT
(
pDataBlock
,
rowTLen
);
pBlock
->
dataLen
+=
rowTLen
;
pBlock
->
dataLen
+=
rowTLen
;
...
@@ -438,14 +440,15 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
...
@@ -438,14 +440,15 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
SArray
*
pVnodeDataBlockList
=
taosArrayInit
(
8
,
POINTER_BYTES
);
SArray
*
pVnodeDataBlockList
=
taosArrayInit
(
8
,
POINTER_BYTES
);
STableDataBlocks
**
p
=
taosHashIterate
(
pHashObj
,
NULL
);
STableDataBlocks
**
p
=
taosHashIterate
(
pHashObj
,
NULL
);
STableDataBlocks
*
pOneTableBlock
=
*
p
;
STableDataBlocks
*
pOneTableBlock
=
*
p
;
SBlockKeyInfo
blkKeyInfo
=
{
0
};
// share by pOneTableBlock
SBlockKeyInfo
blkKeyInfo
=
{
0
};
// share by pOneTableBlock
while
(
pOneTableBlock
)
{
while
(
pOneTableBlock
)
{
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
pOneTableBlock
->
pData
;
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
pOneTableBlock
->
pData
;
if
(
pBlocks
->
numOfRows
>
0
)
{
if
(
pBlocks
->
numOfRows
>
0
)
{
STableDataBlocks
*
dataBuf
=
NULL
;
STableDataBlocks
*
dataBuf
=
NULL
;
int32_t
ret
=
getDataBlockFromList
(
pVnodeDataBlockHashList
,
pOneTableBlock
->
vgId
,
TSDB_PAYLOAD_SIZE
,
int32_t
ret
=
INSERT_HEAD_SIZE
,
0
,
pOneTableBlock
->
pTableMeta
,
&
dataBuf
,
pVnodeDataBlockList
,
NULL
);
getDataBlockFromList
(
pVnodeDataBlockHashList
,
pOneTableBlock
->
vgId
,
TSDB_PAYLOAD_SIZE
,
INSERT_HEAD_SIZE
,
0
,
pOneTableBlock
->
pTableMeta
,
&
dataBuf
,
pVnodeDataBlockList
,
NULL
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
taosHashCleanup
(
pVnodeDataBlockHashList
);
taosHashCleanup
(
pVnodeDataBlockHashList
);
destroyBlockArrayList
(
pVnodeDataBlockList
);
destroyBlockArrayList
(
pVnodeDataBlockList
);
...
@@ -490,7 +493,8 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
...
@@ -490,7 +493,8 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
sizeof
(
STColumn
)
*
getNumOfColumns
(
pOneTableBlock
->
pTableMeta
);
sizeof
(
STColumn
)
*
getNumOfColumns
(
pOneTableBlock
->
pTableMeta
);
// erase the empty space reserved for binary data
// erase the empty space reserved for binary data
int32_t
finalLen
=
trimDataBlock
(
dataBuf
->
pData
+
dataBuf
->
size
,
pOneTableBlock
,
blkKeyInfo
.
pKeyTuple
,
isRawPayload
);
int32_t
finalLen
=
trimDataBlock
(
dataBuf
->
pData
+
dataBuf
->
size
,
pOneTableBlock
,
blkKeyInfo
.
pKeyTuple
,
isRawPayload
);
assert
(
finalLen
<=
len
);
assert
(
finalLen
<=
len
);
dataBuf
->
size
+=
(
finalLen
+
sizeof
(
SSubmitBlk
));
dataBuf
->
size
+=
(
finalLen
+
sizeof
(
SSubmitBlk
));
...
@@ -513,15 +517,15 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
...
@@ -513,15 +517,15 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
allocateMemForSize
(
STableDataBlocks
*
pDataBlock
,
int32_t
allSize
)
{
int32_t
allocateMemForSize
(
STableDataBlocks
*
pDataBlock
,
int32_t
allSize
)
{
size_t
remain
=
pDataBlock
->
nAllocSize
-
pDataBlock
->
size
;
size_t
remain
=
pDataBlock
->
nAllocSize
-
pDataBlock
->
size
;
uint32_t
nAllocSizeOld
=
pDataBlock
->
nAllocSize
;
uint32_t
nAllocSizeOld
=
pDataBlock
->
nAllocSize
;
// expand the allocated size
// expand the allocated size
if
(
remain
<
allSize
)
{
if
(
remain
<
allSize
)
{
pDataBlock
->
nAllocSize
=
(
pDataBlock
->
size
+
allSize
)
*
1
.
5
;
pDataBlock
->
nAllocSize
=
(
pDataBlock
->
size
+
allSize
)
*
1
.
5
;
char
*
tmp
=
taosMemoryRealloc
(
pDataBlock
->
pData
,
(
size_t
)
pDataBlock
->
nAllocSize
);
char
*
tmp
=
taosMemoryRealloc
(
pDataBlock
->
pData
,
(
size_t
)
pDataBlock
->
nAllocSize
);
if
(
tmp
!=
NULL
)
{
if
(
tmp
!=
NULL
)
{
pDataBlock
->
pData
=
tmp
;
pDataBlock
->
pData
=
tmp
;
memset
(
pDataBlock
->
pData
+
pDataBlock
->
size
,
0
,
pDataBlock
->
nAllocSize
-
pDataBlock
->
size
);
memset
(
pDataBlock
->
pData
+
pDataBlock
->
size
,
0
,
pDataBlock
->
nAllocSize
-
pDataBlock
->
size
);
...
@@ -535,11 +539,11 @@ int32_t allocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize) {
...
@@ -535,11 +539,11 @@ int32_t allocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
allocateMemIfNeed
(
STableDataBlocks
*
pDataBlock
,
int32_t
rowSize
,
int32_t
*
numOfRows
)
{
int32_t
allocateMemIfNeed
(
STableDataBlocks
*
pDataBlock
,
int32_t
rowSize
,
int32_t
*
numOfRows
)
{
size_t
remain
=
pDataBlock
->
nAllocSize
-
pDataBlock
->
size
;
size_t
remain
=
pDataBlock
->
nAllocSize
-
pDataBlock
->
size
;
const
int
factor
=
5
;
const
int
factor
=
5
;
uint32_t
nAllocSizeOld
=
pDataBlock
->
nAllocSize
;
uint32_t
nAllocSizeOld
=
pDataBlock
->
nAllocSize
;
// expand the allocated size
// expand the allocated size
if
(
remain
<
rowSize
*
factor
)
{
if
(
remain
<
rowSize
*
factor
)
{
while
(
remain
<
rowSize
*
factor
)
{
while
(
remain
<
rowSize
*
factor
)
{
...
@@ -547,7 +551,7 @@ int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t
...
@@ -547,7 +551,7 @@ int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t
remain
=
pDataBlock
->
nAllocSize
-
pDataBlock
->
size
;
remain
=
pDataBlock
->
nAllocSize
-
pDataBlock
->
size
;
}
}
char
*
tmp
=
taosMemoryRealloc
(
pDataBlock
->
pData
,
(
size_t
)
pDataBlock
->
nAllocSize
);
char
*
tmp
=
taosMemoryRealloc
(
pDataBlock
->
pData
,
(
size_t
)
pDataBlock
->
nAllocSize
);
if
(
tmp
!=
NULL
)
{
if
(
tmp
!=
NULL
)
{
pDataBlock
->
pData
=
tmp
;
pDataBlock
->
pData
=
tmp
;
memset
(
pDataBlock
->
pData
+
pDataBlock
->
size
,
0
,
pDataBlock
->
nAllocSize
-
pDataBlock
->
size
);
memset
(
pDataBlock
->
pData
+
pDataBlock
->
size
,
0
,
pDataBlock
->
nAllocSize
-
pDataBlock
->
size
);
...
@@ -563,7 +567,7 @@ int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t
...
@@ -563,7 +567,7 @@ int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int
initRowBuilder
(
SRowBuilder
*
pBuilder
,
int16_t
schemaVer
,
SParsedDataColInfo
*
pColInfo
)
{
int
initRowBuilder
(
SRowBuilder
*
pBuilder
,
int16_t
schemaVer
,
SParsedDataColInfo
*
pColInfo
)
{
ASSERT
(
pColInfo
->
numOfCols
>
0
&&
(
pColInfo
->
numOfBound
<=
pColInfo
->
numOfCols
));
ASSERT
(
pColInfo
->
numOfCols
>
0
&&
(
pColInfo
->
numOfBound
<=
pColInfo
->
numOfCols
));
tdSRowInit
(
pBuilder
,
schemaVer
);
tdSRowInit
(
pBuilder
,
schemaVer
);
tdSRowSetExtendedInfo
(
pBuilder
,
pColInfo
->
numOfCols
,
pColInfo
->
numOfBound
,
pColInfo
->
flen
,
pColInfo
->
allNullLen
,
tdSRowSetExtendedInfo
(
pBuilder
,
pColInfo
->
numOfCols
,
pColInfo
->
numOfBound
,
pColInfo
->
flen
,
pColInfo
->
allNullLen
,
...
@@ -571,7 +575,6 @@ int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo
...
@@ -571,7 +575,6 @@ int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
qResetStmtDataBlock
(
void
*
block
,
bool
keepBuf
)
{
int32_t
qResetStmtDataBlock
(
void
*
block
,
bool
keepBuf
)
{
STableDataBlocks
*
pBlock
=
(
STableDataBlocks
*
)
block
;
STableDataBlocks
*
pBlock
=
(
STableDataBlocks
*
)
block
;
...
@@ -583,32 +586,31 @@ int32_t qResetStmtDataBlock(void* block, bool keepBuf) {
...
@@ -583,32 +586,31 @@ int32_t qResetStmtDataBlock(void* block, bool keepBuf) {
}
}
memset
(
pBlock
->
pData
,
0
,
sizeof
(
SSubmitBlk
));
memset
(
pBlock
->
pData
,
0
,
sizeof
(
SSubmitBlk
));
}
else
{
}
else
{
pBlock
->
pData
=
NULL
;
pBlock
->
pData
=
NULL
;
}
}
pBlock
->
ordered
=
true
;
pBlock
->
ordered
=
true
;
pBlock
->
prevTS
=
INT64_MIN
;
pBlock
->
prevTS
=
INT64_MIN
;
pBlock
->
size
=
sizeof
(
SSubmitBlk
);
pBlock
->
size
=
sizeof
(
SSubmitBlk
);
pBlock
->
tsSource
=
-
1
;
pBlock
->
tsSource
=
-
1
;
pBlock
->
numOfTables
=
1
;
pBlock
->
numOfTables
=
1
;
pBlock
->
nAllocSize
=
TSDB_PAYLOAD_SIZE
;
pBlock
->
nAllocSize
=
TSDB_PAYLOAD_SIZE
;
pBlock
->
headerSize
=
pBlock
->
size
;
pBlock
->
headerSize
=
pBlock
->
size
;
memset
(
&
pBlock
->
rowBuilder
,
0
,
sizeof
(
pBlock
->
rowBuilder
));
memset
(
&
pBlock
->
rowBuilder
,
0
,
sizeof
(
pBlock
->
rowBuilder
));
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
qCloneStmtDataBlock
(
void
**
pDst
,
void
*
pSrc
)
{
int32_t
qCloneStmtDataBlock
(
void
**
pDst
,
void
*
pSrc
)
{
*
pDst
=
taosMemoryMalloc
(
sizeof
(
STableDataBlocks
));
*
pDst
=
taosMemoryMalloc
(
sizeof
(
STableDataBlocks
));
if
(
NULL
==
*
pDst
)
{
if
(
NULL
==
*
pDst
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
memcpy
(
*
pDst
,
pSrc
,
sizeof
(
STableDataBlocks
));
memcpy
(
*
pDst
,
pSrc
,
sizeof
(
STableDataBlocks
));
((
STableDataBlocks
*
)(
*
pDst
))
->
cloned
=
true
;
((
STableDataBlocks
*
)(
*
pDst
))
->
cloned
=
true
;
return
qResetStmtDataBlock
(
*
pDst
,
false
);
return
qResetStmtDataBlock
(
*
pDst
,
false
);
}
}
...
@@ -618,7 +620,7 @@ int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc) {
...
@@ -618,7 +620,7 @@ int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc) {
return
code
;
return
code
;
}
}
STableDataBlocks
*
pBlock
=
(
STableDataBlocks
*
)
*
pDst
;
STableDataBlocks
*
pBlock
=
(
STableDataBlocks
*
)
*
pDst
;
pBlock
->
pData
=
taosMemoryMalloc
(
pBlock
->
nAllocSize
);
pBlock
->
pData
=
taosMemoryMalloc
(
pBlock
->
nAllocSize
);
if
(
NULL
==
pBlock
->
pData
)
{
if
(
NULL
==
pBlock
->
pData
)
{
qFreeStmtDataBlock
(
pBlock
);
qFreeStmtDataBlock
(
pBlock
);
...
@@ -630,7 +632,6 @@ int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc) {
...
@@ -630,7 +632,6 @@ int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc) {
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
void
qFreeStmtDataBlock
(
void
*
pDataBlock
)
{
void
qFreeStmtDataBlock
(
void
*
pDataBlock
)
{
if
(
pDataBlock
==
NULL
)
{
if
(
pDataBlock
==
NULL
)
{
return
;
return
;
...
@@ -650,4 +651,3 @@ void qDestroyStmtDataBlock(void* pBlock) {
...
@@ -650,4 +651,3 @@ void qDestroyStmtDataBlock(void* pBlock) {
pDataBlock
->
cloned
=
false
;
pDataBlock
->
cloned
=
false
;
destroyDataBlock
(
pDataBlock
);
destroyDataBlock
(
pDataBlock
);
}
}
source/libs/parser/src/parTokenizer.c
浏览文件 @
ac874f9e
...
@@ -15,8 +15,8 @@
...
@@ -15,8 +15,8 @@
#include "os.h"
#include "os.h"
#include "parToken.h"
#include "parToken.h"
#include "thash.h"
#include "taosdef.h"
#include "taosdef.h"
#include "thash.h"
#include "ttokendef.h"
#include "ttokendef.h"
// All the keywords of the SQL language are stored in a hash table
// All the keywords of the SQL language are stored in a hash table
...
@@ -28,188 +28,188 @@ typedef struct SKeyword {
...
@@ -28,188 +28,188 @@ typedef struct SKeyword {
// keywords in sql string
// keywords in sql string
static
SKeyword
keywordTable
[]
=
{
static
SKeyword
keywordTable
[]
=
{
{
"ACCOUNT"
,
TK_ACCOUNT
},
{
"ACCOUNT"
,
TK_ACCOUNT
},
{
"ACCOUNTS"
,
TK_ACCOUNTS
},
{
"ACCOUNTS"
,
TK_ACCOUNTS
},
{
"ADD"
,
TK_ADD
},
{
"ADD"
,
TK_ADD
},
{
"AGGREGATE"
,
TK_AGGREGATE
},
{
"AGGREGATE"
,
TK_AGGREGATE
},
{
"ALL"
,
TK_ALL
},
{
"ALL"
,
TK_ALL
},
{
"ALTER"
,
TK_ALTER
},
{
"ALTER"
,
TK_ALTER
},
{
"ANALYZE"
,
TK_ANALYZE
},
{
"ANALYZE"
,
TK_ANALYZE
},
{
"AND"
,
TK_AND
},
{
"AND"
,
TK_AND
},
{
"APPS"
,
TK_APPS
},
{
"APPS"
,
TK_APPS
},
{
"AS"
,
TK_AS
},
{
"AS"
,
TK_AS
},
{
"ASC"
,
TK_ASC
},
{
"ASC"
,
TK_ASC
},
{
"AT_ONCE"
,
TK_AT_ONCE
},
{
"AT_ONCE"
,
TK_AT_ONCE
},
{
"BETWEEN"
,
TK_BETWEEN
},
{
"BETWEEN"
,
TK_BETWEEN
},
{
"BINARY"
,
TK_BINARY
},
{
"BINARY"
,
TK_BINARY
},
{
"BIGINT"
,
TK_BIGINT
},
{
"BIGINT"
,
TK_BIGINT
},
{
"BLOCKS"
,
TK_BLOCKS
},
{
"BLOCKS"
,
TK_BLOCKS
},
{
"BNODE"
,
TK_BNODE
},
{
"BNODE"
,
TK_BNODE
},
{
"BNODES"
,
TK_BNODES
},
{
"BNODES"
,
TK_BNODES
},
{
"BOOL"
,
TK_BOOL
},
{
"BOOL"
,
TK_BOOL
},
{
"BUFSIZE"
,
TK_BUFSIZE
},
{
"BUFSIZE"
,
TK_BUFSIZE
},
{
"BY"
,
TK_BY
},
{
"BY"
,
TK_BY
},
{
"CACHE"
,
TK_CACHE
},
{
"CACHE"
,
TK_CACHE
},
{
"CACHELAST"
,
TK_CACHELAST
},
{
"CACHELAST"
,
TK_CACHELAST
},
{
"CAST"
,
TK_CAST
},
{
"CAST"
,
TK_CAST
},
{
"CLUSTER"
,
TK_CLUSTER
},
{
"CLUSTER"
,
TK_CLUSTER
},
{
"COLUMN"
,
TK_COLUMN
},
{
"COLUMN"
,
TK_COLUMN
},
{
"COMMENT"
,
TK_COMMENT
},
{
"COMMENT"
,
TK_COMMENT
},
{
"COMP"
,
TK_COMP
},
{
"COMP"
,
TK_COMP
},
{
"COMPACT"
,
TK_COMPACT
},
{
"COMPACT"
,
TK_COMPACT
},
{
"CONNS"
,
TK_CONNS
},
{
"CONNS"
,
TK_CONNS
},
{
"CONNECTION"
,
TK_CONNECTION
},
{
"CONNECTION"
,
TK_CONNECTION
},
{
"CONNECTIONS"
,
TK_CONNECTIONS
},
{
"CONNECTIONS"
,
TK_CONNECTIONS
},
{
"COUNT"
,
TK_COUNT
},
{
"COUNT"
,
TK_COUNT
},
{
"CREATE"
,
TK_CREATE
},
{
"CREATE"
,
TK_CREATE
},
{
"DATABASE"
,
TK_DATABASE
},
{
"DATABASE"
,
TK_DATABASE
},
{
"DATABASES"
,
TK_DATABASES
},
{
"DATABASES"
,
TK_DATABASES
},
{
"DAYS"
,
TK_DAYS
},
{
"DAYS"
,
TK_DAYS
},
{
"DBS"
,
TK_DBS
},
{
"DBS"
,
TK_DBS
},
{
"DELAY"
,
TK_DELAY
},
{
"DELAY"
,
TK_DELAY
},
{
"DESC"
,
TK_DESC
},
{
"DESC"
,
TK_DESC
},
{
"DESCRIBE"
,
TK_DESCRIBE
},
{
"DESCRIBE"
,
TK_DESCRIBE
},
{
"DISTINCT"
,
TK_DISTINCT
},
{
"DISTINCT"
,
TK_DISTINCT
},
{
"DNODE"
,
TK_DNODE
},
{
"DNODE"
,
TK_DNODE
},
{
"DNODES"
,
TK_DNODES
},
{
"DNODES"
,
TK_DNODES
},
{
"DOUBLE"
,
TK_DOUBLE
},
{
"DOUBLE"
,
TK_DOUBLE
},
{
"DROP"
,
TK_DROP
},
{
"DROP"
,
TK_DROP
},
{
"EXISTS"
,
TK_EXISTS
},
{
"EXISTS"
,
TK_EXISTS
},
{
"EXPLAIN"
,
TK_EXPLAIN
},
{
"EXPLAIN"
,
TK_EXPLAIN
},
{
"FILE_FACTOR"
,
TK_FILE_FACTOR
},
{
"FILE_FACTOR"
,
TK_FILE_FACTOR
},
{
"FILL"
,
TK_FILL
},
{
"FILL"
,
TK_FILL
},
{
"FIRST"
,
TK_FIRST
},
{
"FIRST"
,
TK_FIRST
},
{
"FLOAT"
,
TK_FLOAT
},
{
"FLOAT"
,
TK_FLOAT
},
{
"FROM"
,
TK_FROM
},
{
"FROM"
,
TK_FROM
},
{
"FSYNC"
,
TK_FSYNC
},
{
"FSYNC"
,
TK_FSYNC
},
{
"FUNCTION"
,
TK_FUNCTION
},
{
"FUNCTION"
,
TK_FUNCTION
},
{
"FUNCTIONS"
,
TK_FUNCTIONS
},
{
"FUNCTIONS"
,
TK_FUNCTIONS
},
{
"GRANTS"
,
TK_GRANTS
},
{
"GRANTS"
,
TK_GRANTS
},
{
"GROUP"
,
TK_GROUP
},
{
"GROUP"
,
TK_GROUP
},
{
"HAVING"
,
TK_HAVING
},
{
"HAVING"
,
TK_HAVING
},
{
"IF"
,
TK_IF
},
{
"IF"
,
TK_IF
},
{
"IMPORT"
,
TK_IMPORT
},
{
"IMPORT"
,
TK_IMPORT
},
{
"IN"
,
TK_IN
},
{
"IN"
,
TK_IN
},
{
"INDEX"
,
TK_INDEX
},
{
"INDEX"
,
TK_INDEX
},
{
"INDEXES"
,
TK_INDEXES
},
{
"INDEXES"
,
TK_INDEXES
},
{
"INNER"
,
TK_INNER
},
{
"INNER"
,
TK_INNER
},
{
"INT"
,
TK_INT
},
{
"INT"
,
TK_INT
},
{
"INSERT"
,
TK_INSERT
},
{
"INSERT"
,
TK_INSERT
},
{
"INTEGER"
,
TK_INTEGER
},
{
"INTEGER"
,
TK_INTEGER
},
{
"INTERVAL"
,
TK_INTERVAL
},
{
"INTERVAL"
,
TK_INTERVAL
},
{
"INTO"
,
TK_INTO
},
{
"INTO"
,
TK_INTO
},
{
"IS"
,
TK_IS
},
{
"IS"
,
TK_IS
},
{
"JOIN"
,
TK_JOIN
},
{
"JOIN"
,
TK_JOIN
},
{
"JSON"
,
TK_JSON
},
{
"JSON"
,
TK_JSON
},
{
"KEEP"
,
TK_KEEP
},
{
"KEEP"
,
TK_KEEP
},
{
"KILL"
,
TK_KILL
},
{
"KILL"
,
TK_KILL
},
{
"LAST"
,
TK_LAST
},
{
"LAST"
,
TK_LAST
},
{
"LAST_ROW"
,
TK_LAST_ROW
},
{
"LAST_ROW"
,
TK_LAST_ROW
},
{
"LICENCE"
,
TK_LICENCE
},
{
"LICENCE"
,
TK_LICENCE
},
{
"LIKE"
,
TK_LIKE
},
{
"LIKE"
,
TK_LIKE
},
{
"LIMIT"
,
TK_LIMIT
},
{
"LIMIT"
,
TK_LIMIT
},
{
"LINEAR"
,
TK_LINEAR
},
{
"LINEAR"
,
TK_LINEAR
},
{
"LOCAL"
,
TK_LOCAL
},
{
"LOCAL"
,
TK_LOCAL
},
{
"MATCH"
,
TK_MATCH
},
{
"MATCH"
,
TK_MATCH
},
{
"MAXROWS"
,
TK_MAXROWS
},
{
"MAXROWS"
,
TK_MAXROWS
},
{
"MINROWS"
,
TK_MINROWS
},
{
"MINROWS"
,
TK_MINROWS
},
{
"MINUS"
,
TK_MINUS
},
{
"MINUS"
,
TK_MINUS
},
{
"MNODE"
,
TK_MNODE
},
{
"MNODE"
,
TK_MNODE
},
{
"MNODES"
,
TK_MNODES
},
{
"MNODES"
,
TK_MNODES
},
{
"MODIFY"
,
TK_MODIFY
},
{
"MODIFY"
,
TK_MODIFY
},
{
"MODULES"
,
TK_MODULES
},
{
"MODULES"
,
TK_MODULES
},
{
"NCHAR"
,
TK_NCHAR
},
{
"NCHAR"
,
TK_NCHAR
},
{
"NMATCH"
,
TK_NMATCH
},
{
"NMATCH"
,
TK_NMATCH
},
{
"NONE"
,
TK_NONE
},
{
"NONE"
,
TK_NONE
},
{
"NOT"
,
TK_NOT
},
{
"NOT"
,
TK_NOT
},
{
"NOW"
,
TK_NOW
},
{
"NOW"
,
TK_NOW
},
{
"NULL"
,
TK_NULL
},
{
"NULL"
,
TK_NULL
},
{
"NULLS"
,
TK_NULLS
},
{
"NULLS"
,
TK_NULLS
},
{
"OFFSET"
,
TK_OFFSET
},
{
"OFFSET"
,
TK_OFFSET
},
{
"ON"
,
TK_ON
},
{
"ON"
,
TK_ON
},
{
"OR"
,
TK_OR
},
{
"OR"
,
TK_OR
},
{
"ORDER"
,
TK_ORDER
},
{
"ORDER"
,
TK_ORDER
},
{
"OUTPUTTYPE"
,
TK_OUTPUTTYPE
},
{
"OUTPUTTYPE"
,
TK_OUTPUTTYPE
},
{
"PARTITION"
,
TK_PARTITION
},
{
"PARTITION"
,
TK_PARTITION
},
{
"PASS"
,
TK_PASS
},
{
"PASS"
,
TK_PASS
},
{
"PORT"
,
TK_PORT
},
{
"PORT"
,
TK_PORT
},
{
"PPS"
,
TK_PPS
},
{
"PPS"
,
TK_PPS
},
{
"PRECISION"
,
TK_PRECISION
},
{
"PRECISION"
,
TK_PRECISION
},
{
"PRIVILEGE"
,
TK_PRIVILEGE
},
{
"PRIVILEGE"
,
TK_PRIVILEGE
},
{
"PREV"
,
TK_PREV
},
{
"PREV"
,
TK_PREV
},
{
"QNODE"
,
TK_QNODE
},
{
"QNODE"
,
TK_QNODE
},
{
"QNODES"
,
TK_QNODES
},
{
"QNODES"
,
TK_QNODES
},
{
"QTIME"
,
TK_QTIME
},
{
"QTIME"
,
TK_QTIME
},
{
"QUERIES"
,
TK_QUERIES
},
{
"QUERIES"
,
TK_QUERIES
},
{
"QUERY"
,
TK_QUERY
},
{
"QUERY"
,
TK_QUERY
},
{
"QUORUM"
,
TK_QUORUM
},
{
"QUORUM"
,
TK_QUORUM
},
{
"RATIO"
,
TK_RATIO
},
{
"RATIO"
,
TK_RATIO
},
{
"REPLICA"
,
TK_REPLICA
},
{
"REPLICA"
,
TK_REPLICA
},
{
"RESET"
,
TK_RESET
},
{
"RESET"
,
TK_RESET
},
{
"RETENTIONS"
,
TK_RETENTIONS
},
{
"RETENTIONS"
,
TK_RETENTIONS
},
{
"ROLLUP"
,
TK_ROLLUP
},
{
"ROLLUP"
,
TK_ROLLUP
},
{
"SCHEMA"
,
TK_SCHEMA
},
{
"SCHEMA"
,
TK_SCHEMA
},
{
"SCORES"
,
TK_SCORES
},
{
"SCORES"
,
TK_SCORES
},
{
"SELECT"
,
TK_SELECT
},
{
"SELECT"
,
TK_SELECT
},
{
"SESSION"
,
TK_SESSION
},
{
"SESSION"
,
TK_SESSION
},
{
"SET"
,
TK_SET
},
{
"SET"
,
TK_SET
},
{
"SHOW"
,
TK_SHOW
},
{
"SHOW"
,
TK_SHOW
},
{
"SINGLE_STABLE"
,
TK_SINGLE_STABLE
},
{
"SINGLE_STABLE"
,
TK_SINGLE_STABLE
},
{
"SLIDING"
,
TK_SLIDING
},
{
"SLIDING"
,
TK_SLIDING
},
{
"SLIMIT"
,
TK_SLIMIT
},
{
"SLIMIT"
,
TK_SLIMIT
},
{
"SMA"
,
TK_SMA
},
{
"SMA"
,
TK_SMA
},
{
"SMALLINT"
,
TK_SMALLINT
},
{
"SMALLINT"
,
TK_SMALLINT
},
{
"SNODE"
,
TK_SNODE
},
{
"SNODE"
,
TK_SNODE
},
{
"SNODES"
,
TK_SNODES
},
{
"SNODES"
,
TK_SNODES
},
{
"SOFFSET"
,
TK_SOFFSET
},
{
"SOFFSET"
,
TK_SOFFSET
},
{
"STABLE"
,
TK_STABLE
},
{
"STABLE"
,
TK_STABLE
},
{
"STABLES"
,
TK_STABLES
},
{
"STABLES"
,
TK_STABLES
},
{
"STATE"
,
TK_STATE
},
{
"STATE"
,
TK_STATE
},
{
"STATE_WINDOW"
,
TK_STATE_WINDOW
},
{
"STATE_WINDOW"
,
TK_STATE_WINDOW
},
{
"STORAGE"
,
TK_STORAGE
},
{
"STORAGE"
,
TK_STORAGE
},
{
"STREAM"
,
TK_STREAM
},
{
"STREAM"
,
TK_STREAM
},
{
"STREAMS"
,
TK_STREAMS
},
{
"STREAMS"
,
TK_STREAMS
},
{
"STREAM_MODE"
,
TK_STREAM_MODE
},
{
"STREAM_MODE"
,
TK_STREAM_MODE
},
{
"STRICT"
,
TK_STRICT
},
{
"STRICT"
,
TK_STRICT
},
{
"SYNCDB"
,
TK_SYNCDB
},
{
"SYNCDB"
,
TK_SYNCDB
},
{
"TABLE"
,
TK_TABLE
},
{
"TABLE"
,
TK_TABLE
},
{
"TABLES"
,
TK_TABLES
},
{
"TABLES"
,
TK_TABLES
},
{
"TAG"
,
TK_TAG
},
{
"TAG"
,
TK_TAG
},
{
"TAGS"
,
TK_TAGS
},
{
"TAGS"
,
TK_TAGS
},
{
"TBNAME"
,
TK_TBNAME
},
{
"TBNAME"
,
TK_TBNAME
},
{
"TIMESTAMP"
,
TK_TIMESTAMP
},
{
"TIMESTAMP"
,
TK_TIMESTAMP
},
{
"TIMEZONE"
,
TK_TIMEZONE
},
{
"TIMEZONE"
,
TK_TIMEZONE
},
{
"TINYINT"
,
TK_TINYINT
},
{
"TINYINT"
,
TK_TINYINT
},
{
"TODAY"
,
TK_TODAY
},
{
"TODAY"
,
TK_TODAY
},
{
"TOPIC"
,
TK_TOPIC
},
{
"TOPIC"
,
TK_TOPIC
},
{
"TOPICS"
,
TK_TOPICS
},
{
"TOPICS"
,
TK_TOPICS
},
{
"TRIGGER"
,
TK_TRIGGER
},
{
"TRIGGER"
,
TK_TRIGGER
},
{
"TSERIES"
,
TK_TSERIES
},
{
"TSERIES"
,
TK_TSERIES
},
{
"TTL"
,
TK_TTL
},
{
"TTL"
,
TK_TTL
},
{
"UNION"
,
TK_UNION
},
{
"UNION"
,
TK_UNION
},
{
"UNSIGNED"
,
TK_UNSIGNED
},
{
"UNSIGNED"
,
TK_UNSIGNED
},
{
"USE"
,
TK_USE
},
{
"USE"
,
TK_USE
},
{
"USER"
,
TK_USER
},
{
"USER"
,
TK_USER
},
{
"USERS"
,
TK_USERS
},
{
"USERS"
,
TK_USERS
},
{
"USING"
,
TK_USING
},
{
"USING"
,
TK_USING
},
{
"VALUE"
,
TK_VALUE
},
{
"VALUE"
,
TK_VALUE
},
{
"VALUES"
,
TK_VALUES
},
{
"VALUES"
,
TK_VALUES
},
{
"VARCHAR"
,
TK_VARCHAR
},
{
"VARCHAR"
,
TK_VARCHAR
},
{
"VARIABLES"
,
TK_VARIABLES
},
{
"VARIABLES"
,
TK_VARIABLES
},
{
"VERBOSE"
,
TK_VERBOSE
},
{
"VERBOSE"
,
TK_VERBOSE
},
{
"VGROUPS"
,
TK_VGROUPS
},
{
"VGROUPS"
,
TK_VGROUPS
},
{
"VNODES"
,
TK_VNODES
},
{
"VNODES"
,
TK_VNODES
},
{
"WAL"
,
TK_WAL
},
{
"WAL"
,
TK_WAL
},
{
"WATERMARK"
,
TK_WATERMARK
},
{
"WATERMARK"
,
TK_WATERMARK
},
{
"WHERE"
,
TK_WHERE
},
{
"WHERE"
,
TK_WHERE
},
{
"WINDOW_CLOSE"
,
TK_WINDOW_CLOSE
},
{
"WINDOW_CLOSE"
,
TK_WINDOW_CLOSE
},
{
"WITH"
,
TK_WITH
},
{
"WITH"
,
TK_WITH
},
{
"_QENDTS"
,
TK_QENDTS
},
{
"_QENDTS"
,
TK_QENDTS
},
{
"_QSTARTTS"
,
TK_QSTARTTS
},
{
"_QSTARTTS"
,
TK_QSTARTTS
},
{
"_ROWTS"
,
TK_ROWTS
},
{
"_ROWTS"
,
TK_ROWTS
},
{
"_WDURATION"
,
TK_WDURATION
},
{
"_WDURATION"
,
TK_WDURATION
},
{
"_WENDTS"
,
TK_WENDTS
},
{
"_WENDTS"
,
TK_WENDTS
},
{
"_WSTARTTS"
,
TK_WSTARTTS
},
{
"_WSTARTTS"
,
TK_WSTARTTS
},
// {"ID", TK_ID},
// {"ID", TK_ID},
// {"STRING", TK_STRING},
// {"STRING", TK_STRING},
// {"EQ", TK_EQ},
// {"EQ", TK_EQ},
...
@@ -293,7 +293,7 @@ static void* keywordHashTable = NULL;
...
@@ -293,7 +293,7 @@ static void* keywordHashTable = NULL;
static
void
doInitKeywordsTable
(
void
)
{
static
void
doInitKeywordsTable
(
void
)
{
int
numOfEntries
=
tListLen
(
keywordTable
);
int
numOfEntries
=
tListLen
(
keywordTable
);
keywordHashTable
=
taosHashInit
(
numOfEntries
,
MurmurHash3_32
,
true
,
false
);
keywordHashTable
=
taosHashInit
(
numOfEntries
,
MurmurHash3_32
,
true
,
false
);
for
(
int32_t
i
=
0
;
i
<
numOfEntries
;
i
++
)
{
for
(
int32_t
i
=
0
;
i
<
numOfEntries
;
i
++
)
{
keywordTable
[
i
].
len
=
(
uint8_t
)
strlen
(
keywordTable
[
i
].
name
);
keywordTable
[
i
].
len
=
(
uint8_t
)
strlen
(
keywordTable
[
i
].
name
);
...
@@ -306,12 +306,12 @@ static TdThreadOnce keywordsHashTableInit = PTHREAD_ONCE_INIT;
...
@@ -306,12 +306,12 @@ static TdThreadOnce keywordsHashTableInit = PTHREAD_ONCE_INIT;
static
int32_t
tKeywordCode
(
const
char
*
z
,
int
n
)
{
static
int32_t
tKeywordCode
(
const
char
*
z
,
int
n
)
{
taosThreadOnce
(
&
keywordsHashTableInit
,
doInitKeywordsTable
);
taosThreadOnce
(
&
keywordsHashTableInit
,
doInitKeywordsTable
);
char
key
[
512
]
=
{
0
};
char
key
[
512
]
=
{
0
};
if
(
n
>
tListLen
(
key
))
{
// too long token, can not be any other token type
if
(
n
>
tListLen
(
key
))
{
// too long token, can not be any other token type
return
TK_NK_ID
;
return
TK_NK_ID
;
}
}
for
(
int32_t
j
=
0
;
j
<
n
;
++
j
)
{
for
(
int32_t
j
=
0
;
j
<
n
;
++
j
)
{
if
(
z
[
j
]
>=
'a'
&&
z
[
j
]
<=
'z'
)
{
if
(
z
[
j
]
>=
'a'
&&
z
[
j
]
<=
'z'
)
{
key
[
j
]
=
(
char
)(
z
[
j
]
&
0xDF
);
// to uppercase and set the null-terminated
key
[
j
]
=
(
char
)(
z
[
j
]
&
0xDF
);
// to uppercase and set the null-terminated
...
@@ -325,7 +325,7 @@ static int32_t tKeywordCode(const char* z, int n) {
...
@@ -325,7 +325,7 @@ static int32_t tKeywordCode(const char* z, int n) {
}
}
SKeyword
**
pKey
=
(
SKeyword
**
)
taosHashGet
(
keywordHashTable
,
key
,
n
);
SKeyword
**
pKey
=
(
SKeyword
**
)
taosHashGet
(
keywordHashTable
,
key
,
n
);
return
(
pKey
!=
NULL
)
?
(
*
pKey
)
->
type
:
TK_NK_ID
;
return
(
pKey
!=
NULL
)
?
(
*
pKey
)
->
type
:
TK_NK_ID
;
}
}
/*
/*
...
@@ -468,11 +468,11 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
...
@@ -468,11 +468,11 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
int
delim
=
z
[
0
];
int
delim
=
z
[
0
];
bool
strEnd
=
false
;
bool
strEnd
=
false
;
for
(
i
=
1
;
z
[
i
];
i
++
)
{
for
(
i
=
1
;
z
[
i
];
i
++
)
{
if
(
z
[
i
]
==
'\\'
)
{
// ignore the escaped character that follows this backslash
if
(
z
[
i
]
==
'\\'
)
{
// ignore the escaped character that follows this backslash
i
++
;
i
++
;
continue
;
continue
;
}
}
if
(
z
[
i
]
==
delim
)
{
if
(
z
[
i
]
==
delim
)
{
if
(
z
[
i
+
1
]
==
delim
)
{
if
(
z
[
i
+
1
]
==
delim
)
{
i
++
;
i
++
;
...
@@ -482,11 +482,11 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
...
@@ -482,11 +482,11 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
}
}
}
}
}
}
if
(
z
[
i
])
i
++
;
if
(
z
[
i
])
i
++
;
if
(
strEnd
)
{
if
(
strEnd
)
{
*
tokenId
=
(
delim
==
'`'
)
?
TK_NK_ID
:
TK_NK_STRING
;
*
tokenId
=
(
delim
==
'`'
)
?
TK_NK_ID
:
TK_NK_STRING
;
return
i
;
return
i
;
}
}
...
@@ -521,7 +521,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
...
@@ -521,7 +521,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
case
'0'
:
{
case
'0'
:
{
char
next
=
z
[
1
];
char
next
=
z
[
1
];
if
(
next
==
'b'
)
{
// bin number
if
(
next
==
'b'
)
{
// bin number
*
tokenId
=
TK_NK_BIN
;
*
tokenId
=
TK_NK_BIN
;
for
(
i
=
2
;
(
z
[
i
]
==
'0'
||
z
[
i
]
==
'1'
);
++
i
)
{
for
(
i
=
2
;
(
z
[
i
]
==
'0'
||
z
[
i
]
==
'1'
);
++
i
)
{
}
}
...
@@ -531,7 +531,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
...
@@ -531,7 +531,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
}
}
return
i
;
return
i
;
}
else
if
(
next
==
'x'
)
{
//hex number
}
else
if
(
next
==
'x'
)
{
//
hex number
*
tokenId
=
TK_NK_HEX
;
*
tokenId
=
TK_NK_HEX
;
for
(
i
=
2
;
isdigit
(
z
[
i
])
||
(
z
[
i
]
>=
'a'
&&
z
[
i
]
<=
'f'
)
||
(
z
[
i
]
>=
'A'
&&
z
[
i
]
<=
'F'
);
++
i
)
{
for
(
i
=
2
;
isdigit
(
z
[
i
])
||
(
z
[
i
]
>=
'a'
&&
z
[
i
]
<=
'f'
)
||
(
z
[
i
]
>=
'A'
&&
z
[
i
]
<=
'F'
);
++
i
)
{
}
}
...
@@ -557,10 +557,9 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
...
@@ -557,10 +557,9 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
}
}
/* here is the 1u/1a/2s/3m/9y */
/* here is the 1u/1a/2s/3m/9y */
if
((
z
[
i
]
==
'b'
||
z
[
i
]
==
'u'
||
z
[
i
]
==
'a'
||
z
[
i
]
==
's'
||
z
[
i
]
==
'm'
||
z
[
i
]
==
'h'
||
z
[
i
]
==
'd'
||
z
[
i
]
==
'n'
||
if
((
z
[
i
]
==
'b'
||
z
[
i
]
==
'u'
||
z
[
i
]
==
'a'
||
z
[
i
]
==
's'
||
z
[
i
]
==
'm'
||
z
[
i
]
==
'h'
||
z
[
i
]
==
'd'
||
z
[
i
]
==
'y'
||
z
[
i
]
==
'w'
||
z
[
i
]
==
'n'
||
z
[
i
]
==
'y'
||
z
[
i
]
==
'w'
||
z
[
i
]
==
'B'
||
z
[
i
]
==
'U'
||
z
[
i
]
==
'A'
||
z
[
i
]
==
'S'
||
z
[
i
]
==
'B'
||
z
[
i
]
==
'U'
||
z
[
i
]
==
'A'
||
z
[
i
]
==
'S'
||
z
[
i
]
==
'M'
||
z
[
i
]
==
'H'
||
z
[
i
]
==
'D'
||
z
[
i
]
==
'N'
||
z
[
i
]
==
'M'
||
z
[
i
]
==
'H'
||
z
[
i
]
==
'D'
||
z
[
i
]
==
'N'
||
z
[
i
]
==
'Y'
||
z
[
i
]
==
'W'
)
&&
z
[
i
]
==
'Y'
||
z
[
i
]
==
'W'
)
&&
(
isIdChar
[(
uint8_t
)
z
[
i
+
1
]]
==
0
))
{
(
isIdChar
[(
uint8_t
)
z
[
i
+
1
]]
==
0
))
{
*
tokenId
=
TK_NK_VARIABLE
;
*
tokenId
=
TK_NK_VARIABLE
;
i
+=
1
;
i
+=
1
;
...
@@ -602,7 +601,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
...
@@ -602,7 +601,7 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
case
't'
:
case
't'
:
case
'F'
:
case
'F'
:
case
'f'
:
{
case
'f'
:
{
for
(
i
=
1
;
((
z
[
i
]
&
0x80
)
==
0
)
&&
isIdChar
[(
uint8_t
)
z
[
i
]];
i
++
)
{
for
(
i
=
1
;
((
z
[
i
]
&
0x80
)
==
0
)
&&
isIdChar
[(
uint8_t
)
z
[
i
]];
i
++
)
{
}
}
if
((
i
==
4
&&
strncasecmp
(
z
,
"true"
,
4
)
==
0
)
||
(
i
==
5
&&
strncasecmp
(
z
,
"false"
,
5
)
==
0
))
{
if
((
i
==
4
&&
strncasecmp
(
z
,
"true"
,
4
)
==
0
)
||
(
i
==
5
&&
strncasecmp
(
z
,
"false"
,
5
)
==
0
))
{
...
@@ -611,10 +610,10 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
...
@@ -611,10 +610,10 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
}
}
}
}
default:
{
default:
{
if
(((
*
z
&
0x80
)
!=
0
)
||
!
isIdChar
[(
uint8_t
)
*
z
])
{
if
(((
*
z
&
0x80
)
!=
0
)
||
!
isIdChar
[(
uint8_t
)
*
z
])
{
break
;
break
;
}
}
for
(
i
=
1
;
((
z
[
i
]
&
0x80
)
==
0
)
&&
isIdChar
[(
uint8_t
)
z
[
i
]];
i
++
)
{
for
(
i
=
1
;
((
z
[
i
]
&
0x80
)
==
0
)
&&
isIdChar
[(
uint8_t
)
z
[
i
]];
i
++
)
{
}
}
*
tokenId
=
tKeywordCode
(
z
,
i
);
*
tokenId
=
tKeywordCode
(
z
,
i
);
return
i
;
return
i
;
...
@@ -625,12 +624,12 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
...
@@ -625,12 +624,12 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
return
0
;
return
0
;
}
}
SToken
tscReplaceStrToken
(
char
**
str
,
SToken
*
token
,
const
char
*
newToken
)
{
SToken
tscReplaceStrToken
(
char
**
str
,
SToken
*
token
,
const
char
*
newToken
)
{
char
*
src
=
*
str
;
char
*
src
=
*
str
;
size_t
nsize
=
strlen
(
newToken
);
size_t
nsize
=
strlen
(
newToken
);
int32_t
size
=
(
int32_t
)
strlen
(
*
str
)
-
token
->
n
+
(
int32_t
)
nsize
+
1
;
int32_t
size
=
(
int32_t
)
strlen
(
*
str
)
-
token
->
n
+
(
int32_t
)
nsize
+
1
;
int32_t
bsize
=
(
int32_t
)((
uint64_t
)
token
->
z
-
(
uint64_t
)
src
);
int32_t
bsize
=
(
int32_t
)((
uint64_t
)
token
->
z
-
(
uint64_t
)
src
);
SToken
ntoken
;
SToken
ntoken
;
*
str
=
taosMemoryCalloc
(
1
,
size
);
*
str
=
taosMemoryCalloc
(
1
,
size
);
...
@@ -660,13 +659,13 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) {
...
@@ -660,13 +659,13 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) {
*
i
+=
t0
.
n
;
*
i
+=
t0
.
n
;
int32_t
numOfComma
=
0
;
int32_t
numOfComma
=
0
;
char
t
=
str
[
*
i
];
char
t
=
str
[
*
i
];
while
(
t
==
' '
||
t
==
'\n'
||
t
==
'\r'
||
t
==
'\t'
||
t
==
'\f'
||
t
==
','
)
{
while
(
t
==
' '
||
t
==
'\n'
||
t
==
'\r'
||
t
==
'\t'
||
t
==
'\f'
||
t
==
','
)
{
if
(
t
==
','
&&
(
++
numOfComma
>
1
))
{
// comma only allowed once
if
(
t
==
','
&&
(
++
numOfComma
>
1
))
{
// comma only allowed once
t0
.
n
=
0
;
t0
.
n
=
0
;
return
t0
;
return
t0
;
}
}
t
=
str
[
++
(
*
i
)];
t
=
str
[
++
(
*
i
)];
}
}
...
@@ -722,15 +721,13 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) {
...
@@ -722,15 +721,13 @@ SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr) {
}
}
}
}
t0
.
z
=
(
char
*
)
str
+
(
*
i
);
t0
.
z
=
(
char
*
)
str
+
(
*
i
);
*
i
+=
t0
.
n
;
*
i
+=
t0
.
n
;
return
t0
;
return
t0
;
}
}
bool
taosIsKeyWordToken
(
const
char
*
z
,
int32_t
len
)
{
bool
taosIsKeyWordToken
(
const
char
*
z
,
int32_t
len
)
{
return
(
tKeywordCode
((
char
*
)
z
,
len
)
!=
TK_NK_ID
);
}
return
(
tKeywordCode
((
char
*
)
z
,
len
)
!=
TK_NK_ID
);
}
void
taosCleanupKeywordsTable
()
{
void
taosCleanupKeywordsTable
()
{
void
*
m
=
keywordHashTable
;
void
*
m
=
keywordHashTable
;
...
@@ -741,7 +738,7 @@ void taosCleanupKeywordsTable() {
...
@@ -741,7 +738,7 @@ void taosCleanupKeywordsTable() {
SToken
taosTokenDup
(
SToken
*
pToken
,
char
*
buf
,
int32_t
len
)
{
SToken
taosTokenDup
(
SToken
*
pToken
,
char
*
buf
,
int32_t
len
)
{
assert
(
pToken
!=
NULL
&&
buf
!=
NULL
&&
len
>
pToken
->
n
);
assert
(
pToken
!=
NULL
&&
buf
!=
NULL
&&
len
>
pToken
->
n
);
strncpy
(
buf
,
pToken
->
z
,
pToken
->
n
);
strncpy
(
buf
,
pToken
->
z
,
pToken
->
n
);
buf
[
pToken
->
n
]
=
0
;
buf
[
pToken
->
n
]
=
0
;
...
...
source/libs/parser/src/parTranslater.c
浏览文件 @
ac874f9e
...
@@ -591,25 +591,27 @@ static EDealRes haveAggFunction(SNode* pNode, void* pContext) {
...
@@ -591,25 +591,27 @@ static EDealRes haveAggFunction(SNode* pNode, void* pContext) {
}
}
static
EDealRes
translateFunction
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
static
EDealRes
translateFunction
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
SFmGetFuncInfoParam
param
=
{
SFmGetFuncInfoParam
param
=
{.
pCtg
=
pCxt
->
pParseCxt
->
pCatalog
,
.
pCtg
=
pCxt
->
pParseCxt
->
pCatalog
,
.
pRpc
=
pCxt
->
pParseCxt
->
pTransporter
,
.
pRpc
=
pCxt
->
pParseCxt
->
pTransporter
,
.
pMgmtEps
=
&
pCxt
->
pParseCxt
->
mgmtEpSet
,
.
pMgmtEps
=
&
pCxt
->
pParseCxt
->
mgmtEpSet
,
.
pErrBuf
=
pCxt
->
msgBuf
.
buf
,
.
pErrBuf
=
pCxt
->
msgBuf
.
buf
,
.
errBufLen
=
pCxt
->
msgBuf
.
len
};
.
errBufLen
=
pCxt
->
msgBuf
.
len
};
pCxt
->
errCode
=
fmGetFuncInfo
(
&
param
,
pFunc
);
pCxt
->
errCode
=
fmGetFuncInfo
(
&
param
,
pFunc
);
if
(
TSDB_CODE_SUCCESS
!=
pCxt
->
errCode
)
{
if
(
TSDB_CODE_SUCCESS
!=
pCxt
->
errCode
)
{
return
DEAL_RES_ERROR
;
return
DEAL_RES_ERROR
;
}
}
if
(
fmIsAggFunc
(
pFunc
->
funcId
)
&&
beforeHaving
(
pCxt
->
currClause
))
{
if
(
fmIsAggFunc
(
pFunc
->
funcId
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
);
if
(
beforeHaving
(
pCxt
->
currClause
))
{
}
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
);
bool
haveAggFunc
=
false
;
}
nodesWalkExprs
(
pFunc
->
pParameterList
,
haveAggFunction
,
&
haveAggFunc
);
bool
haveAggFunc
=
false
;
if
(
haveAggFunc
)
{
nodesWalkExprs
(
pFunc
->
pParameterList
,
haveAggFunction
,
&
haveAggFunc
);
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_AGG_FUNC_NESTING
);
if
(
haveAggFunc
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_AGG_FUNC_NESTING
);
}
pCxt
->
pCurrStmt
->
hasAggFuncs
=
true
;
}
}
return
DEAL_RES_CONTINUE
;
return
DEAL_RES_CONTINUE
;
}
}
...
@@ -771,7 +773,7 @@ static int32_t addMnodeToVgroupList(const SEpSet* pEpSet, SArray** pVgroupList)
...
@@ -771,7 +773,7 @@ static int32_t addMnodeToVgroupList(const SEpSet* pEpSet, SArray** pVgroupList)
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
}
}
SVgroupInfo
vg
=
{
.
vgId
=
MNODE_HANDLE
};
SVgroupInfo
vg
=
{
.
vgId
=
MNODE_HANDLE
};
memcpy
(
&
vg
.
epSet
,
pEpSet
,
sizeof
(
SEpSet
));
memcpy
(
&
vg
.
epSet
,
pEpSet
,
sizeof
(
SEpSet
));
taosArrayPush
(
*
pVgroupList
,
&
vg
);
taosArrayPush
(
*
pVgroupList
,
&
vg
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
...
@@ -787,7 +789,7 @@ static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRea
...
@@ -787,7 +789,7 @@ static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRea
if
(
'\0'
!=
pRealTable
->
qualDbName
[
0
])
{
if
(
'\0'
!=
pRealTable
->
qualDbName
[
0
])
{
// todo release after mnode can be processed
// todo release after mnode can be processed
// if (0 != strcmp(pRealTable->qualDbName, TSDB_INFORMATION_SCHEMA_DB)) {
// if (0 != strcmp(pRealTable->qualDbName, TSDB_INFORMATION_SCHEMA_DB)) {
code
=
getDBVgInfo
(
pCxt
,
pRealTable
->
qualDbName
,
&
vgroupList
);
code
=
getDBVgInfo
(
pCxt
,
pRealTable
->
qualDbName
,
&
vgroupList
);
// }
// }
}
else
{
}
else
{
code
=
getDBVgInfoImpl
(
pCxt
,
pName
,
&
vgroupList
);
code
=
getDBVgInfoImpl
(
pCxt
,
pName
,
&
vgroupList
);
...
@@ -3481,7 +3483,7 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
...
@@ -3481,7 +3483,7 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TAG_NAME
,
pCol
->
colName
);
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TAG_NAME
,
pCol
->
colName
);
}
}
SValueNode
*
pVal
=
NULL
;
SValueNode
*
pVal
=
NULL
;
int32_t
code
=
translateTagVal
(
pCxt
,
pNode
,
&
pVal
);
int32_t
code
=
translateTagVal
(
pCxt
,
pNode
,
&
pVal
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
NULL
==
pVal
)
{
if
(
NULL
==
pVal
)
{
pVal
=
(
SValueNode
*
)
pNode
;
pVal
=
(
SValueNode
*
)
pNode
;
...
@@ -3511,7 +3513,7 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
...
@@ -3511,7 +3513,7 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
int32_t
index
=
0
;
int32_t
index
=
0
;
FOREACH
(
pNode
,
pStmt
->
pValsOfTags
)
{
FOREACH
(
pNode
,
pStmt
->
pValsOfTags
)
{
SValueNode
*
pVal
=
NULL
;
SValueNode
*
pVal
=
NULL
;
int32_t
code
=
translateTagVal
(
pCxt
,
pNode
,
&
pVal
);
int32_t
code
=
translateTagVal
(
pCxt
,
pNode
,
&
pVal
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
NULL
==
pVal
)
{
if
(
NULL
==
pVal
)
{
pVal
=
(
SValueNode
*
)
pNode
;
pVal
=
(
SValueNode
*
)
pNode
;
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
ac874f9e
...
@@ -63,13 +63,13 @@ static char* getSyntaxErrFormat(int32_t errCode) {
...
@@ -63,13 +63,13 @@ static char* getSyntaxErrFormat(int32_t errCode) {
case
TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR
:
case
TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR
:
return
"Corresponding super table not in this db"
;
return
"Corresponding super table not in this db"
;
case
TSDB_CODE_PAR_INVALID_RANGE_OPTION
:
case
TSDB_CODE_PAR_INVALID_RANGE_OPTION
:
return
"Invalid option %s: %"
PRId64
" valid range: [%d, %d]"
;
return
"Invalid option %s: %"
PRId64
" valid range: [%d, %d]"
;
case
TSDB_CODE_PAR_INVALID_STR_OPTION
:
case
TSDB_CODE_PAR_INVALID_STR_OPTION
:
return
"Invalid option %s: %s"
;
return
"Invalid option %s: %s"
;
case
TSDB_CODE_PAR_INVALID_ENUM_OPTION
:
case
TSDB_CODE_PAR_INVALID_ENUM_OPTION
:
return
"Invalid option %s: %"
PRId64
", only %d, %d allowed"
;
return
"Invalid option %s: %"
PRId64
", only %d, %d allowed"
;
case
TSDB_CODE_PAR_INVALID_TTL_OPTION
:
case
TSDB_CODE_PAR_INVALID_TTL_OPTION
:
return
"Invalid option ttl: %"
PRId64
", should be greater than or equal to %d"
;
return
"Invalid option ttl: %"
PRId64
", should be greater than or equal to %d"
;
case
TSDB_CODE_PAR_INVALID_KEEP_NUM
:
case
TSDB_CODE_PAR_INVALID_KEEP_NUM
:
return
"Invalid number of keep options"
;
return
"Invalid number of keep options"
;
case
TSDB_CODE_PAR_INVALID_KEEP_ORDER
:
case
TSDB_CODE_PAR_INVALID_KEEP_ORDER
:
...
@@ -194,20 +194,22 @@ STableMeta* tableMetaDup(const STableMeta* pTableMeta) {
...
@@ -194,20 +194,22 @@ STableMeta* tableMetaDup(const STableMeta* pTableMeta) {
return
p
;
return
p
;
}
}
SSchema
*
getTableColumnSchema
(
const
STableMeta
*
pTableMeta
)
{
SSchema
*
getTableColumnSchema
(
const
STableMeta
*
pTableMeta
)
{
assert
(
pTableMeta
!=
NULL
);
assert
(
pTableMeta
!=
NULL
);
return
(
SSchema
*
)
pTableMeta
->
schema
;
return
(
SSchema
*
)
pTableMeta
->
schema
;
}
}
static
SSchema
*
getOneColumnSchema
(
const
STableMeta
*
pTableMeta
,
int32_t
colIndex
)
{
static
SSchema
*
getOneColumnSchema
(
const
STableMeta
*
pTableMeta
,
int32_t
colIndex
)
{
assert
(
pTableMeta
!=
NULL
&&
pTableMeta
->
schema
!=
NULL
&&
colIndex
>=
0
&&
colIndex
<
(
getNumOfColumns
(
pTableMeta
)
+
getNumOfTags
(
pTableMeta
)));
assert
(
pTableMeta
!=
NULL
&&
pTableMeta
->
schema
!=
NULL
&&
colIndex
>=
0
&&
colIndex
<
(
getNumOfColumns
(
pTableMeta
)
+
getNumOfTags
(
pTableMeta
)));
SSchema
*
pSchema
=
(
SSchema
*
)
pTableMeta
->
schema
;
SSchema
*
pSchema
=
(
SSchema
*
)
pTableMeta
->
schema
;
return
&
pSchema
[
colIndex
];
return
&
pSchema
[
colIndex
];
}
}
SSchema
*
getTableTagSchema
(
const
STableMeta
*
pTableMeta
)
{
SSchema
*
getTableTagSchema
(
const
STableMeta
*
pTableMeta
)
{
assert
(
pTableMeta
!=
NULL
&&
(
pTableMeta
->
tableType
==
TSDB_SUPER_TABLE
||
pTableMeta
->
tableType
==
TSDB_CHILD_TABLE
));
assert
(
pTableMeta
!=
NULL
&&
(
pTableMeta
->
tableType
==
TSDB_SUPER_TABLE
||
pTableMeta
->
tableType
==
TSDB_CHILD_TABLE
));
return
getOneColumnSchema
(
pTableMeta
,
getTableInfo
(
pTableMeta
).
numOfColumns
);
return
getOneColumnSchema
(
pTableMeta
,
getTableInfo
(
pTableMeta
).
numOfColumns
);
}
}
...
@@ -228,40 +230,40 @@ STableComInfo getTableInfo(const STableMeta* pTableMeta) {
...
@@ -228,40 +230,40 @@ STableComInfo getTableInfo(const STableMeta* pTableMeta) {
}
}
int32_t
trimString
(
const
char
*
src
,
int32_t
len
,
char
*
dst
,
int32_t
dlen
)
{
int32_t
trimString
(
const
char
*
src
,
int32_t
len
,
char
*
dst
,
int32_t
dlen
)
{
if
(
len
<=
0
||
dlen
<=
0
)
return
0
;
if
(
len
<=
0
||
dlen
<=
0
)
return
0
;
char
delim
=
src
[
0
];
char
delim
=
src
[
0
];
int32_t
j
=
0
;
int32_t
j
=
0
;
for
(
uint32_t
k
=
1
;
k
<
len
-
1
;
++
k
)
{
for
(
uint32_t
k
=
1
;
k
<
len
-
1
;
++
k
)
{
if
(
j
>=
dlen
)
{
if
(
j
>=
dlen
)
{
dst
[
j
-
1
]
=
'\0'
;
dst
[
j
-
1
]
=
'\0'
;
return
j
;
return
j
;
}
}
if
(
src
[
k
]
==
delim
&&
src
[
k
+
1
]
==
delim
)
{
// deal with "", ''
if
(
src
[
k
]
==
delim
&&
src
[
k
+
1
]
==
delim
)
{
// deal with "", ''
dst
[
j
]
=
src
[
k
+
1
];
dst
[
j
]
=
src
[
k
+
1
];
j
++
;
j
++
;
k
++
;
k
++
;
continue
;
continue
;
}
}
if
(
src
[
k
]
==
'\\'
)
{
// deal with escape character
if
(
src
[
k
]
==
'\\'
)
{
// deal with escape character
if
(
src
[
k
+
1
]
==
'n'
)
{
if
(
src
[
k
+
1
]
==
'n'
)
{
dst
[
j
]
=
'\n'
;
dst
[
j
]
=
'\n'
;
}
else
if
(
src
[
k
+
1
]
==
'r'
)
{
}
else
if
(
src
[
k
+
1
]
==
'r'
)
{
dst
[
j
]
=
'\r'
;
dst
[
j
]
=
'\r'
;
}
else
if
(
src
[
k
+
1
]
==
't'
)
{
}
else
if
(
src
[
k
+
1
]
==
't'
)
{
dst
[
j
]
=
'\t'
;
dst
[
j
]
=
'\t'
;
}
else
if
(
src
[
k
+
1
]
==
'\\'
)
{
}
else
if
(
src
[
k
+
1
]
==
'\\'
)
{
dst
[
j
]
=
'\\'
;
dst
[
j
]
=
'\\'
;
}
else
if
(
src
[
k
+
1
]
==
'\''
)
{
}
else
if
(
src
[
k
+
1
]
==
'\''
)
{
dst
[
j
]
=
'\''
;
dst
[
j
]
=
'\''
;
}
else
if
(
src
[
k
+
1
]
==
'"'
)
{
}
else
if
(
src
[
k
+
1
]
==
'"'
)
{
dst
[
j
]
=
'"'
;
dst
[
j
]
=
'"'
;
}
else
if
(
src
[
k
+
1
]
==
'%'
||
src
[
k
+
1
]
==
'_'
)
{
}
else
if
(
src
[
k
+
1
]
==
'%'
||
src
[
k
+
1
]
==
'_'
)
{
dst
[
j
++
]
=
src
[
k
];
dst
[
j
++
]
=
src
[
k
];
dst
[
j
]
=
src
[
k
+
1
];
dst
[
j
]
=
src
[
k
+
1
];
}
else
{
}
else
{
dst
[
j
]
=
src
[
k
+
1
];
dst
[
j
]
=
src
[
k
+
1
];
}
}
j
++
;
j
++
;
k
++
;
k
++
;
...
@@ -275,7 +277,7 @@ int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen) {
...
@@ -275,7 +277,7 @@ int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen) {
return
j
;
return
j
;
}
}
static
bool
isValidateTag
(
char
*
input
)
{
static
bool
isValidateTag
(
char
*
input
)
{
if
(
!
input
)
return
false
;
if
(
!
input
)
return
false
;
for
(
size_t
i
=
0
;
i
<
strlen
(
input
);
++
i
)
{
for
(
size_t
i
=
0
;
i
<
strlen
(
input
);
++
i
)
{
if
(
isprint
(
input
[
i
])
==
0
)
return
false
;
if
(
isprint
(
input
[
i
])
==
0
)
return
false
;
...
@@ -283,30 +285,30 @@ static bool isValidateTag(char *input) {
...
@@ -283,30 +285,30 @@ static bool isValidateTag(char *input) {
return
true
;
return
true
;
}
}
int
parseJsontoTagData
(
const
char
*
json
,
SKVRowBuilder
*
kvRowBuilder
,
SMsgBuf
*
pMsgBuf
,
int16_t
startColId
){
int
parseJsontoTagData
(
const
char
*
json
,
SKVRowBuilder
*
kvRowBuilder
,
SMsgBuf
*
pMsgBuf
,
int16_t
startColId
)
{
// set json NULL data
// set json NULL data
uint8_t
jsonNULL
=
TSDB_DATA_TYPE_NULL
;
uint8_t
jsonNULL
=
TSDB_DATA_TYPE_NULL
;
int
jsonIndex
=
startColId
+
1
;
int
jsonIndex
=
startColId
+
1
;
if
(
!
json
||
strcasecmp
(
json
,
TSDB_DATA_NULL_STR_L
)
==
0
){
if
(
!
json
||
strcasecmp
(
json
,
TSDB_DATA_NULL_STR_L
)
==
0
)
{
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
,
&
jsonNULL
,
CHAR_BYTES
);
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
,
&
jsonNULL
,
CHAR_BYTES
);
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
// set json real data
// set json real data
cJSON
*
root
=
cJSON_Parse
(
json
);
cJSON
*
root
=
cJSON_Parse
(
json
);
if
(
root
==
NULL
){
if
(
root
==
NULL
)
{
return
buildSyntaxErrMsg
(
pMsgBuf
,
"json parse error"
,
json
);
return
buildSyntaxErrMsg
(
pMsgBuf
,
"json parse error"
,
json
);
}
}
int
size
=
cJSON_GetArraySize
(
root
);
int
size
=
cJSON_GetArraySize
(
root
);
if
(
!
cJSON_IsObject
(
root
))
{
if
(
!
cJSON_IsObject
(
root
))
{
return
buildSyntaxErrMsg
(
pMsgBuf
,
"json error invalide value"
,
json
);
return
buildSyntaxErrMsg
(
pMsgBuf
,
"json error invalide value"
,
json
);
}
}
int
retCode
=
0
;
int
retCode
=
0
;
char
*
tagKV
=
NULL
;
char
*
tagKV
=
NULL
;
SHashObj
*
keyHash
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
false
);
SHashObj
*
keyHash
=
taosHashInit
(
8
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
false
,
false
);
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
for
(
int
i
=
0
;
i
<
size
;
i
++
)
{
cJSON
*
item
=
cJSON_GetArrayItem
(
root
,
i
);
cJSON
*
item
=
cJSON_GetArrayItem
(
root
,
i
);
if
(
!
item
)
{
if
(
!
item
)
{
qError
(
"json inner error:%d"
,
i
);
qError
(
"json inner error:%d"
,
i
);
...
@@ -314,40 +316,41 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
...
@@ -314,40 +316,41 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
goto
end
;
goto
end
;
}
}
char
*
jsonKey
=
item
->
string
;
char
*
jsonKey
=
item
->
string
;
if
(
!
isValidateTag
(
jsonKey
))
{
if
(
!
isValidateTag
(
jsonKey
))
{
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json key not validate"
,
jsonKey
);
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json key not validate"
,
jsonKey
);
goto
end
;
goto
end
;
}
}
// if(strlen(jsonKey) > TSDB_MAX_JSON_KEY_LEN){
// if(strlen(jsonKey) > TSDB_MAX_JSON_KEY_LEN){
// tscError("json key too long error");
// tscError("json key too long error");
// retCode = tscSQLSyntaxErrMsg(errMsg, "json key too long, more than 256", NULL);
// retCode = tscSQLSyntaxErrMsg(errMsg, "json key too long, more than 256", NULL);
// goto end;
// goto end;
// }
// }
size_t
keyLen
=
strlen
(
jsonKey
);
size_t
keyLen
=
strlen
(
jsonKey
);
if
(
keyLen
==
0
||
taosHashGet
(
keyHash
,
jsonKey
,
keyLen
)
!=
NULL
)
{
if
(
keyLen
==
0
||
taosHashGet
(
keyHash
,
jsonKey
,
keyLen
)
!=
NULL
)
{
continue
;
continue
;
}
}
// key: keyLen + VARSTR_HEADER_SIZE, value type: CHAR_BYTES, value reserved: LONG_BYTES
// key: keyLen + VARSTR_HEADER_SIZE, value type: CHAR_BYTES, value reserved: LONG_BYTES
tagKV
=
taosMemoryCalloc
(
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
LONG_BYTES
,
1
);
tagKV
=
taosMemoryCalloc
(
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
LONG_BYTES
,
1
);
if
(
!
tagKV
)
{
if
(
!
tagKV
)
{
retCode
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
retCode
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
goto
end
;
}
}
strncpy
(
varDataVal
(
tagKV
),
jsonKey
,
keyLen
);
strncpy
(
varDataVal
(
tagKV
),
jsonKey
,
keyLen
);
varDataSetLen
(
tagKV
,
keyLen
);
varDataSetLen
(
tagKV
,
keyLen
);
if
(
taosHashGetSize
(
keyHash
)
==
0
)
{
if
(
taosHashGetSize
(
keyHash
)
==
0
)
{
uint8_t
jsonNotNULL
=
TSDB_DATA_TYPE_JSON
;
uint8_t
jsonNotNULL
=
TSDB_DATA_TYPE_JSON
;
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
&
jsonNotNULL
,
CHAR_BYTES
);
// add json type
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
&
jsonNotNULL
,
CHAR_BYTES
);
// add json type
}
}
taosHashPut
(
keyHash
,
jsonKey
,
keyLen
,
&
keyLen
,
CHAR_BYTES
);
// add key to hash to remove dumplicate, value is useless
taosHashPut
(
keyHash
,
jsonKey
,
keyLen
,
&
keyLen
,
CHAR_BYTES
);
// add key to hash to remove dumplicate, value is useless
if
(
item
->
type
==
cJSON_String
){
// add json value format: type|data
if
(
item
->
type
==
cJSON_String
)
{
// add json value format: type|data
char
*
jsonValue
=
item
->
valuestring
;
char
*
jsonValue
=
item
->
valuestring
;
int32_t
valLen
=
(
int32_t
)
strlen
(
jsonValue
);
int32_t
valLen
=
(
int32_t
)
strlen
(
jsonValue
);
int32_t
totalLen
=
keyLen
+
VARSTR_HEADER_SIZE
+
valLen
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
;
int32_t
totalLen
=
keyLen
+
VARSTR_HEADER_SIZE
+
valLen
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
;
char
*
tmp
=
taosMemoryRealloc
(
tagKV
,
totalLen
);
char
*
tmp
=
taosMemoryRealloc
(
tagKV
,
totalLen
);
if
(
!
tmp
)
{
if
(
!
tmp
)
{
retCode
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
retCode
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
goto
end
;
}
}
...
@@ -356,44 +359,47 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
...
@@ -356,44 +359,47 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
*
valueType
=
TSDB_DATA_TYPE_NCHAR
;
*
valueType
=
TSDB_DATA_TYPE_NCHAR
;
if
(
valLen
>
0
&&
!
taosMbsToUcs4
(
jsonValue
,
valLen
,
(
TdUcs4
*
)
varDataVal
(
valueData
),
if
(
valLen
>
0
&&
!
taosMbsToUcs4
(
jsonValue
,
valLen
,
(
TdUcs4
*
)
varDataVal
(
valueData
),
(
int32_t
)(
valLen
*
TSDB_NCHAR_SIZE
),
&
valLen
))
{
(
int32_t
)(
valLen
*
TSDB_NCHAR_SIZE
),
&
valLen
))
{
qError
(
"charset:%s to %s. val:%s, errno:%s, convert failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
jsonValue
,
strerror
(
errno
));
qError
(
"charset:%s to %s. val:%s, errno:%s, convert failed."
,
DEFAULT_UNICODE_ENCODEC
,
tsCharset
,
jsonValue
,
strerror
(
errno
));
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"charset convert json error"
,
jsonValue
);
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"charset convert json error"
,
jsonValue
);
goto
end
;
goto
end
;
}
}
varDataSetLen
(
valueData
,
valLen
);
varDataSetLen
(
valueData
,
valLen
);
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
totalLen
);
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
totalLen
);
}
else
if
(
item
->
type
==
cJSON_Number
)
{
}
else
if
(
item
->
type
==
cJSON_Number
)
{
if
(
!
isfinite
(
item
->
valuedouble
))
{
if
(
!
isfinite
(
item
->
valuedouble
))
{
qError
(
"json value is invalidate"
);
qError
(
"json value is invalidate"
);
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json value number is illegal"
,
json
);
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json value number is illegal"
,
json
);
goto
end
;
goto
end
;
}
}
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
*
valueType
=
(
item
->
valuedouble
-
(
int64_t
)(
item
->
valuedouble
)
==
0
)
?
TSDB_DATA_TYPE_BIGINT
:
TSDB_DATA_TYPE_DOUBLE
;
*
valueType
=
if
(
*
valueType
==
TSDB_DATA_TYPE_DOUBLE
)
*
((
double
*
)
valueData
)
=
item
->
valuedouble
;
(
item
->
valuedouble
-
(
int64_t
)(
item
->
valuedouble
)
==
0
)
?
TSDB_DATA_TYPE_BIGINT
:
TSDB_DATA_TYPE_DOUBLE
;
else
if
(
*
valueType
==
TSDB_DATA_TYPE_BIGINT
)
*
((
int64_t
*
)
valueData
)
=
item
->
valueint
;
if
(
*
valueType
==
TSDB_DATA_TYPE_DOUBLE
)
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
LONG_BYTES
);
*
((
double
*
)
valueData
)
=
item
->
valuedouble
;
}
else
if
(
item
->
type
==
cJSON_True
||
item
->
type
==
cJSON_False
){
else
if
(
*
valueType
==
TSDB_DATA_TYPE_BIGINT
)
*
((
int64_t
*
)
valueData
)
=
item
->
valueint
;
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
LONG_BYTES
);
}
else
if
(
item
->
type
==
cJSON_True
||
item
->
type
==
cJSON_False
)
{
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
*
valueType
=
TSDB_DATA_TYPE_BOOL
;
*
valueType
=
TSDB_DATA_TYPE_BOOL
;
*
valueData
=
(
char
)(
item
->
valueint
);
*
valueData
=
(
char
)(
item
->
valueint
);
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
CHAR_BYTES
);
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
CHAR_BYTES
);
}
else
if
(
item
->
type
==
cJSON_NULL
)
{
}
else
if
(
item
->
type
==
cJSON_NULL
)
{
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
*
valueType
=
TSDB_DATA_TYPE_NULL
;
*
valueType
=
TSDB_DATA_TYPE_NULL
;
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
}
}
else
{
else
{
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"invalidate json value"
,
json
);
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"invalidate json value"
,
json
);
goto
end
;
goto
end
;
}
}
}
}
if
(
taosHashGetSize
(
keyHash
)
==
0
)
{
// set json NULL true
if
(
taosHashGetSize
(
keyHash
)
==
0
)
{
// set json NULL true
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
,
&
jsonNULL
,
CHAR_BYTES
);
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
,
&
jsonNULL
,
CHAR_BYTES
);
}
}
...
...
source/libs/parser/src/parser.c
浏览文件 @
ac874f9e
...
@@ -13,8 +13,8 @@
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "os.h"
#include "parser.h"
#include "parser.h"
#include "os.h"
#include "parInt.h"
#include "parInt.h"
#include "parToken.h"
#include "parToken.h"
...
@@ -23,11 +23,11 @@ bool isInsertSql(const char* pStr, size_t length) {
...
@@ -23,11 +23,11 @@ bool isInsertSql(const char* pStr, size_t length) {
if
(
NULL
==
pStr
)
{
if
(
NULL
==
pStr
)
{
return
false
;
return
false
;
}
}
int32_t
index
=
0
;
int32_t
index
=
0
;
do
{
do
{
SToken
t0
=
tStrGetToken
((
char
*
)
pStr
,
&
index
,
false
);
SToken
t0
=
tStrGetToken
((
char
*
)
pStr
,
&
index
,
false
);
if
(
t0
.
type
!=
TK_NK_LP
)
{
if
(
t0
.
type
!=
TK_NK_LP
)
{
return
t0
.
type
==
TK_INSERT
||
t0
.
type
==
TK_IMPORT
;
return
t0
.
type
==
TK_INSERT
||
t0
.
type
==
TK_IMPORT
;
}
}
...
...
source/libs/parser/test/mockCatalog.cpp
浏览文件 @
ac874f9e
...
@@ -30,103 +30,128 @@ namespace {
...
@@ -30,103 +30,128 @@ namespace {
void
generateInformationSchema
(
MockCatalogService
*
mcs
)
{
void
generateInformationSchema
(
MockCatalogService
*
mcs
)
{
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"dnodes"
,
TSDB_SYSTEM_TABLE
,
1
).
addColumn
(
"id"
,
TSDB_DATA_TYPE_INT
);
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"dnodes"
,
TSDB_SYSTEM_TABLE
,
1
)
.
addColumn
(
"id"
,
TSDB_DATA_TYPE_INT
);
builder
.
done
();
builder
.
done
();
}
}
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"mnodes"
,
TSDB_SYSTEM_TABLE
,
1
).
addColumn
(
"id"
,
TSDB_DATA_TYPE_INT
);
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"mnodes"
,
TSDB_SYSTEM_TABLE
,
1
)
.
addColumn
(
"id"
,
TSDB_DATA_TYPE_INT
);
builder
.
done
();
builder
.
done
();
}
}
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"modules"
,
TSDB_SYSTEM_TABLE
,
1
).
addColumn
(
"id"
,
TSDB_DATA_TYPE_INT
);
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"modules"
,
TSDB_SYSTEM_TABLE
,
1
)
.
addColumn
(
"id"
,
TSDB_DATA_TYPE_INT
);
builder
.
done
();
builder
.
done
();
}
}
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"qnodes"
,
TSDB_SYSTEM_TABLE
,
1
).
addColumn
(
"id"
,
TSDB_DATA_TYPE_INT
);
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"qnodes"
,
TSDB_SYSTEM_TABLE
,
1
)
.
addColumn
(
"id"
,
TSDB_DATA_TYPE_INT
);
builder
.
done
();
builder
.
done
();
}
}
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_databases"
,
TSDB_SYSTEM_TABLE
,
1
).
addColumn
(
"name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
);
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_databases"
,
TSDB_SYSTEM_TABLE
,
1
)
.
addColumn
(
"name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
);
builder
.
done
();
builder
.
done
();
}
}
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_functions"
,
TSDB_SYSTEM_TABLE
,
1
).
addColumn
(
"name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_FUNC_NAME_LEN
);
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_functions"
,
TSDB_SYSTEM_TABLE
,
1
)
.
addColumn
(
"name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_FUNC_NAME_LEN
);
builder
.
done
();
builder
.
done
();
}
}
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_indexes"
,
TSDB_SYSTEM_TABLE
,
2
)
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_indexes"
,
TSDB_SYSTEM_TABLE
,
2
)
.
addColumn
(
"db_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
).
addColumn
(
"table_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_TABLE_NAME_LEN
);
.
addColumn
(
"db_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
)
.
addColumn
(
"table_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_TABLE_NAME_LEN
);
builder
.
done
();
builder
.
done
();
}
}
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_stables"
,
TSDB_SYSTEM_TABLE
,
2
)
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_stables"
,
TSDB_SYSTEM_TABLE
,
2
)
.
addColumn
(
"db_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
).
addColumn
(
"stable_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_TABLE_NAME_LEN
);
.
addColumn
(
"db_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
)
.
addColumn
(
"stable_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_TABLE_NAME_LEN
);
builder
.
done
();
builder
.
done
();
}
}
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_streams"
,
TSDB_SYSTEM_TABLE
,
1
).
addColumn
(
"stream_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_TABLE_NAME_LEN
);
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_streams"
,
TSDB_SYSTEM_TABLE
,
1
)
.
addColumn
(
"stream_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_TABLE_NAME_LEN
);
builder
.
done
();
builder
.
done
();
}
}
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_tables"
,
TSDB_SYSTEM_TABLE
,
2
)
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_tables"
,
TSDB_SYSTEM_TABLE
,
2
)
.
addColumn
(
"db_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
).
addColumn
(
"table_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_TABLE_NAME_LEN
);
.
addColumn
(
"db_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
)
.
addColumn
(
"table_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_TABLE_NAME_LEN
);
builder
.
done
();
builder
.
done
();
}
}
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_table_distributed"
,
TSDB_SYSTEM_TABLE
,
1
).
addColumn
(
"db_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
);
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_table_distributed"
,
TSDB_SYSTEM_TABLE
,
1
)
.
addColumn
(
"db_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
);
builder
.
done
();
builder
.
done
();
}
}
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_users"
,
TSDB_SYSTEM_TABLE
,
1
).
addColumn
(
"user_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_USER_LEN
);
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"user_users"
,
TSDB_SYSTEM_TABLE
,
1
)
.
addColumn
(
"user_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_USER_LEN
);
builder
.
done
();
builder
.
done
();
}
}
{
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"vgroups"
,
TSDB_SYSTEM_TABLE
,
1
).
addColumn
(
"db_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
);
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"information_schema"
,
"vgroups"
,
TSDB_SYSTEM_TABLE
,
1
)
.
addColumn
(
"db_name"
,
TSDB_DATA_TYPE_BINARY
,
TSDB_DB_NAME_LEN
);
builder
.
done
();
builder
.
done
();
}
}
}
}
void
generateTestT1
(
MockCatalogService
*
mcs
)
{
void
generateTestT1
(
MockCatalogService
*
mcs
)
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"test"
,
"t1"
,
TSDB_NORMAL_TABLE
,
6
)
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"test"
,
"t1"
,
TSDB_NORMAL_TABLE
,
6
)
.
setPrecision
(
TSDB_TIME_PRECISION_MILLI
).
setVgid
(
1
).
addColumn
(
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
)
.
setPrecision
(
TSDB_TIME_PRECISION_MILLI
)
.
addColumn
(
"c1"
,
TSDB_DATA_TYPE_INT
).
addColumn
(
"c2"
,
TSDB_DATA_TYPE_BINARY
,
20
).
addColumn
(
"c3"
,
TSDB_DATA_TYPE_BIGINT
)
.
setVgid
(
1
)
.
addColumn
(
"c4"
,
TSDB_DATA_TYPE_DOUBLE
).
addColumn
(
"c5"
,
TSDB_DATA_TYPE_DOUBLE
);
.
addColumn
(
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
)
.
addColumn
(
"c1"
,
TSDB_DATA_TYPE_INT
)
.
addColumn
(
"c2"
,
TSDB_DATA_TYPE_BINARY
,
20
)
.
addColumn
(
"c3"
,
TSDB_DATA_TYPE_BIGINT
)
.
addColumn
(
"c4"
,
TSDB_DATA_TYPE_DOUBLE
)
.
addColumn
(
"c5"
,
TSDB_DATA_TYPE_DOUBLE
);
builder
.
done
();
builder
.
done
();
}
}
void
generateTestST1
(
MockCatalogService
*
mcs
)
{
void
generateTestST1
(
MockCatalogService
*
mcs
)
{
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"test"
,
"st1"
,
TSDB_SUPER_TABLE
,
3
,
2
)
ITableBuilder
&
builder
=
mcs
->
createTableBuilder
(
"test"
,
"st1"
,
TSDB_SUPER_TABLE
,
3
,
2
)
.
setPrecision
(
TSDB_TIME_PRECISION_MILLI
).
addColumn
(
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
)
.
setPrecision
(
TSDB_TIME_PRECISION_MILLI
)
.
addColumn
(
"c1"
,
TSDB_DATA_TYPE_INT
).
addColumn
(
"c2"
,
TSDB_DATA_TYPE_BINARY
,
20
)
.
addColumn
(
"ts"
,
TSDB_DATA_TYPE_TIMESTAMP
)
.
addTag
(
"tag1"
,
TSDB_DATA_TYPE_INT
).
addTag
(
"tag2"
,
TSDB_DATA_TYPE_BINARY
,
20
);
.
addColumn
(
"c1"
,
TSDB_DATA_TYPE_INT
)
.
addColumn
(
"c2"
,
TSDB_DATA_TYPE_BINARY
,
20
)
.
addTag
(
"tag1"
,
TSDB_DATA_TYPE_INT
)
.
addTag
(
"tag2"
,
TSDB_DATA_TYPE_BINARY
,
20
);
builder
.
done
();
builder
.
done
();
mcs
->
createSubTable
(
"test"
,
"st1"
,
"st1s1"
,
1
);
mcs
->
createSubTable
(
"test"
,
"st1"
,
"st1s1"
,
1
);
mcs
->
createSubTable
(
"test"
,
"st1"
,
"st1s2"
,
2
);
mcs
->
createSubTable
(
"test"
,
"st1"
,
"st1s2"
,
2
);
}
}
}
}
// namespace
int32_t
__catalogGetHandle
(
const
char
*
clusterId
,
struct
SCatalog
**
catalogHandle
)
{
int32_t
__catalogGetHandle
(
const
char
*
clusterId
,
struct
SCatalog
**
catalogHandle
)
{
return
0
;
}
return
0
;
}
int32_t
__catalogGetTableMeta
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
SName
*
pTableName
,
STableMeta
**
pTableMeta
)
{
int32_t
__catalogGetTableMeta
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
SName
*
pTableName
,
STableMeta
**
pTableMeta
)
{
return
mockCatalogService
->
catalogGetTableMeta
(
pTableName
,
pTableMeta
);
return
mockCatalogService
->
catalogGetTableMeta
(
pTableName
,
pTableMeta
);
}
}
int32_t
__catalogGetTableHashVgroup
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
SName
*
pTableName
,
SVgroupInfo
*
vgInfo
)
{
int32_t
__catalogGetTableHashVgroup
(
struct
SCatalog
*
pCatalog
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
SName
*
pTableName
,
SVgroupInfo
*
vgInfo
)
{
return
mockCatalogService
->
catalogGetTableHashVgroup
(
pTableName
,
vgInfo
);
return
mockCatalogService
->
catalogGetTableHashVgroup
(
pTableName
,
vgInfo
);
}
}
int32_t
__catalogGetTableDistVgInfo
(
SCatalog
*
pCtg
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
SName
*
pTableName
,
SArray
**
pVgList
)
{
int32_t
__catalogGetTableDistVgInfo
(
SCatalog
*
pCtg
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
SName
*
pTableName
,
SArray
**
pVgList
)
{
return
mockCatalogService
->
catalogGetTableDistVgInfo
(
pTableName
,
pVgList
);
return
mockCatalogService
->
catalogGetTableDistVgInfo
(
pTableName
,
pVgList
);
}
}
int32_t
__catalogGetDBVgVersion
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
int32_t
*
version
,
int64_t
*
dbId
,
int32_t
*
tableNum
)
{
int32_t
__catalogGetDBVgVersion
(
SCatalog
*
pCtg
,
const
char
*
dbFName
,
int32_t
*
version
,
int64_t
*
dbId
,
int32_t
*
tableNum
)
{
return
0
;
return
0
;
}
}
int32_t
__catalogGetDBVgInfo
(
SCatalog
*
pCtg
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
char
*
dbFName
,
SArray
**
vgroupList
)
{
int32_t
__catalogGetDBVgInfo
(
SCatalog
*
pCtg
,
void
*
pRpc
,
const
SEpSet
*
pMgmtEps
,
const
char
*
dbFName
,
SArray
**
vgroupList
)
{
return
0
;
return
0
;
}
}
...
@@ -189,6 +214,4 @@ void generateMetaData() {
...
@@ -189,6 +214,4 @@ void generateMetaData() {
mockCatalogService
->
showTables
();
mockCatalogService
->
showTables
();
}
}
void
destroyMetaDataEnv
()
{
void
destroyMetaDataEnv
()
{
mockCatalogService
.
reset
();
}
mockCatalogService
.
reset
();
}
source/libs/parser/test/mockCatalogService.cpp
浏览文件 @
ac874f9e
...
@@ -13,19 +13,20 @@
...
@@ -13,19 +13,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include "mockCatalogService.h"
#include <iomanip>
#include <iomanip>
#include <iostream>
#include <iostream>
#include <map>
#include <map>
#include "mockCatalogService.h"
#include "tdatablock.h"
#include "tdatablock.h"
#include "tname.h"
#include "tname.h"
#include "ttypes.h"
#include "ttypes.h"
std
::
unique_ptr
<
MockCatalogService
>
mockCatalogService
;
std
::
unique_ptr
<
MockCatalogService
>
mockCatalogService
;
class
TableBuilder
:
public
ITableBuilder
{
class
TableBuilder
:
public
ITableBuilder
{
public:
public:
virtual
TableBuilder
&
addColumn
(
const
std
::
string
&
name
,
int8_t
type
,
int32_t
bytes
)
{
virtual
TableBuilder
&
addColumn
(
const
std
::
string
&
name
,
int8_t
type
,
int32_t
bytes
)
{
assert
(
colId_
<=
schema
()
->
tableInfo
.
numOfTags
+
schema
()
->
tableInfo
.
numOfColumns
);
assert
(
colId_
<=
schema
()
->
tableInfo
.
numOfTags
+
schema
()
->
tableInfo
.
numOfColumns
);
SSchema
*
col
=
schema
()
->
schema
+
(
colId_
-
1
);
SSchema
*
col
=
schema
()
->
schema
+
(
colId_
-
1
);
...
@@ -40,7 +41,7 @@ public:
...
@@ -40,7 +41,7 @@ public:
virtual
TableBuilder
&
setVgid
(
int16_t
vgid
)
{
virtual
TableBuilder
&
setVgid
(
int16_t
vgid
)
{
schema
()
->
vgId
=
vgid
;
schema
()
->
vgId
=
vgid
;
SVgroupInfo
vgroup
=
{
vgid
,
0
,
0
,
{
0
},
0
};
SVgroupInfo
vgroup
=
{
vgid
,
0
,
0
,
{
0
},
0
};
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_1"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_1"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_2"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_2"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_3"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_3"
,
6030
);
...
@@ -55,15 +56,14 @@ public:
...
@@ -55,15 +56,14 @@ public:
return
*
this
;
return
*
this
;
}
}
virtual
void
done
()
{
virtual
void
done
()
{
schema
()
->
tableInfo
.
rowSize
=
rowsize_
;
}
schema
()
->
tableInfo
.
rowSize
=
rowsize_
;
}
private:
private:
friend
class
MockCatalogServiceImpl
;
friend
class
MockCatalogServiceImpl
;
static
std
::
unique_ptr
<
TableBuilder
>
createTableBuilder
(
int8_t
tableType
,
int32_t
numOfColumns
,
int32_t
numOfTags
)
{
static
std
::
unique_ptr
<
TableBuilder
>
createTableBuilder
(
int8_t
tableType
,
int32_t
numOfColumns
,
int32_t
numOfTags
)
{
STableMeta
*
meta
=
(
STableMeta
*
)
taosMemoryCalloc
(
1
,
sizeof
(
STableMeta
)
+
sizeof
(
SSchema
)
*
(
numOfColumns
+
numOfTags
));
STableMeta
*
meta
=
(
STableMeta
*
)
taosMemoryCalloc
(
1
,
sizeof
(
STableMeta
)
+
sizeof
(
SSchema
)
*
(
numOfColumns
+
numOfTags
));
if
(
nullptr
==
meta
)
{
if
(
nullptr
==
meta
)
{
throw
std
::
bad_alloc
();
throw
std
::
bad_alloc
();
}
}
...
@@ -77,29 +77,22 @@ private:
...
@@ -77,29 +77,22 @@ private:
meta_
->
schema
=
schemaMeta
;
meta_
->
schema
=
schemaMeta
;
}
}
STableMeta
*
schema
()
{
STableMeta
*
schema
()
{
return
meta_
->
schema
;
}
return
meta_
->
schema
;
}
std
::
shared_ptr
<
MockTableMeta
>
table
()
{
std
::
shared_ptr
<
MockTableMeta
>
table
()
{
return
meta_
;
}
return
meta_
;
}
col_id_t
colId_
;
col_id_t
colId_
;
int32_t
rowsize_
;
int32_t
rowsize_
;
std
::
shared_ptr
<
MockTableMeta
>
meta_
;
std
::
shared_ptr
<
MockTableMeta
>
meta_
;
};
};
class
MockCatalogServiceImpl
{
class
MockCatalogServiceImpl
{
public:
public:
static
const
int32_t
numOfDataTypes
=
sizeof
(
tDataTypes
)
/
sizeof
(
tDataTypes
[
0
]);
static
const
int32_t
numOfDataTypes
=
sizeof
(
tDataTypes
)
/
sizeof
(
tDataTypes
[
0
]);
MockCatalogServiceImpl
()
:
id_
(
1
)
{
MockCatalogServiceImpl
()
:
id_
(
1
)
{}
}
int32_t
catalogGetHandle
()
const
{
int32_t
catalogGetHandle
()
const
{
return
0
;
}
return
0
;
}
int32_t
catalogGetTableMeta
(
const
SName
*
pTableName
,
STableMeta
**
pTableMeta
)
const
{
int32_t
catalogGetTableMeta
(
const
SName
*
pTableName
,
STableMeta
**
pTableMeta
)
const
{
std
::
unique_ptr
<
STableMeta
>
table
;
std
::
unique_ptr
<
STableMeta
>
table
;
...
@@ -108,7 +101,7 @@ public:
...
@@ -108,7 +101,7 @@ public:
tNameGetDbName
(
pTableName
,
db
);
tNameGetDbName
(
pTableName
,
db
);
const
char
*
tname
=
tNameGetTableName
(
pTableName
);
const
char
*
tname
=
tNameGetTableName
(
pTableName
);
int32_t
code
=
copyTableSchemaMeta
(
db
,
tname
,
&
table
);
int32_t
code
=
copyTableSchemaMeta
(
db
,
tname
,
&
table
);
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
if
(
TSDB_CODE_SUCCESS
!=
code
)
{
std
::
cout
<<
"db : "
<<
db
<<
", table :"
<<
tname
<<
std
::
endl
;
std
::
cout
<<
"db : "
<<
db
<<
", table :"
<<
tname
<<
std
::
endl
;
return
code
;
return
code
;
...
@@ -129,7 +122,8 @@ public:
...
@@ -129,7 +122,8 @@ public:
return
copyTableVgroup
(
db
,
tNameGetTableName
(
pTableName
),
vgList
);
return
copyTableVgroup
(
db
,
tNameGetTableName
(
pTableName
),
vgList
);
}
}
TableBuilder
&
createTableBuilder
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
,
int8_t
tableType
,
int32_t
numOfColumns
,
int32_t
numOfTags
)
{
TableBuilder
&
createTableBuilder
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
,
int8_t
tableType
,
int32_t
numOfColumns
,
int32_t
numOfTags
)
{
builder_
=
TableBuilder
::
createTableBuilder
(
tableType
,
numOfColumns
,
numOfTags
);
builder_
=
TableBuilder
::
createTableBuilder
(
tableType
,
numOfColumns
,
numOfTags
);
meta_
[
db
][
tbname
]
=
builder_
->
table
();
meta_
[
db
][
tbname
]
=
builder_
->
table
();
meta_
[
db
][
tbname
]
->
schema
->
uid
=
id_
++
;
meta_
[
db
][
tbname
]
->
schema
->
uid
=
id_
++
;
...
@@ -146,7 +140,7 @@ public:
...
@@ -146,7 +140,7 @@ public:
meta_
[
db
][
tbname
]
->
schema
->
uid
=
id_
++
;
meta_
[
db
][
tbname
]
->
schema
->
uid
=
id_
++
;
meta_
[
db
][
tbname
]
->
schema
->
tableType
=
TSDB_CHILD_TABLE
;
meta_
[
db
][
tbname
]
->
schema
->
tableType
=
TSDB_CHILD_TABLE
;
SVgroupInfo
vgroup
=
{
vgid
,
0
,
0
,
{
0
},
0
};
SVgroupInfo
vgroup
=
{
vgid
,
0
,
0
,
{
0
},
0
};
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_1"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_1"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_2"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_2"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_3"
,
6030
);
addEpIntoEpSet
(
&
vgroup
.
epSet
,
"dnode_3"
,
6030
);
...
@@ -158,26 +152,28 @@ public:
...
@@ -158,26 +152,28 @@ public:
}
}
void
showTables
()
const
{
void
showTables
()
const
{
// number of forward fills
// number of forward fills
#define NOF(n) ((n) / 2)
#define NOF(n) ((n) / 2)
// number of backward fills
// number of backward fills
#define NOB(n) ((n) % 2 ? (n) / 2 + 1 : (n) / 2)
#define NOB(n) ((n) % 2 ? (n) / 2 + 1 : (n) / 2)
// center aligned
// center aligned
#define CA(n, s) std::setw(NOF((n) - (s).length())) << "" << (s) << std::setw(NOB((n) - (s).length())) << "" << "|"
#define CA(n, s) \
// string field length
std::setw(NOF((n) - (s).length())) << "" << (s) << std::setw(NOB((n) - (s).length())) << "" \
#define SFL 20
<< "|"
// string field header
// string field length
#define SH(h) CA(SFL, std::string(h))
#define SFL 20
// string field
// string field header
#define SF(n) CA(SFL, n)
#define SH(h) CA(SFL, std::string(h))
// integer field length
// string field
#define IFL 10
#define SF(n) CA(SFL, n)
// integer field header
// integer field length
#define IH(i) CA(IFL, std::string(i))
#define IFL 10
// integer field
// integer field header
#define IF(i) CA(IFL, std::to_string(i))
#define IH(i) CA(IFL, std::string(i))
// split line
// integer field
#define SL(sn, in) std::setfill('=') << std::setw((sn) * (SFL + 1) + (in) * (IFL + 1)) << "" << std::setfill(' ')
#define IF(i) CA(IFL, std::to_string(i))
// split line
#define SL(sn, in) std::setfill('=') << std::setw((sn) * (SFL + 1) + (in) * (IFL + 1)) << "" << std::setfill(' ')
for
(
const
auto
&
db
:
meta_
)
{
for
(
const
auto
&
db
:
meta_
)
{
std
::
cout
<<
"Databse:"
<<
db
.
first
<<
std
::
endl
;
std
::
cout
<<
"Databse:"
<<
db
.
first
<<
std
::
endl
;
...
@@ -185,7 +181,8 @@ public:
...
@@ -185,7 +181,8 @@ public:
std
::
cout
<<
SL
(
3
,
1
)
<<
std
::
endl
;
std
::
cout
<<
SL
(
3
,
1
)
<<
std
::
endl
;
for
(
const
auto
&
table
:
db
.
second
)
{
for
(
const
auto
&
table
:
db
.
second
)
{
const
auto
&
schema
=
table
.
second
->
schema
;
const
auto
&
schema
=
table
.
second
->
schema
;
std
::
cout
<<
SF
(
table
.
first
)
<<
SF
(
ttToString
(
schema
->
tableType
))
<<
SF
(
pToString
(
schema
->
tableInfo
.
precision
))
<<
IF
(
schema
->
vgId
)
<<
IF
(
schema
->
tableInfo
.
rowSize
)
<<
std
::
endl
;
std
::
cout
<<
SF
(
table
.
first
)
<<
SF
(
ttToString
(
schema
->
tableType
))
<<
SF
(
pToString
(
schema
->
tableInfo
.
precision
))
<<
IF
(
schema
->
vgId
)
<<
IF
(
schema
->
tableInfo
.
rowSize
)
<<
std
::
endl
;
}
}
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
}
}
...
@@ -200,7 +197,8 @@ public:
...
@@ -200,7 +197,8 @@ public:
int16_t
numOfFields
=
numOfColumns
+
schema
->
tableInfo
.
numOfTags
;
int16_t
numOfFields
=
numOfColumns
+
schema
->
tableInfo
.
numOfTags
;
for
(
int16_t
i
=
0
;
i
<
numOfFields
;
++
i
)
{
for
(
int16_t
i
=
0
;
i
<
numOfFields
;
++
i
)
{
const
SSchema
*
col
=
schema
->
schema
+
i
;
const
SSchema
*
col
=
schema
->
schema
+
i
;
std
::
cout
<<
SF
(
std
::
string
(
col
->
name
))
<<
SH
(
ftToString
(
i
,
numOfColumns
))
<<
SH
(
dtToString
(
col
->
type
))
<<
IF
(
col
->
bytes
)
<<
std
::
endl
;
std
::
cout
<<
SF
(
std
::
string
(
col
->
name
))
<<
SH
(
ftToString
(
i
,
numOfColumns
))
<<
SH
(
dtToString
(
col
->
type
))
<<
IF
(
col
->
bytes
)
<<
std
::
endl
;
}
}
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
}
}
...
@@ -219,9 +217,9 @@ public:
...
@@ -219,9 +217,9 @@ public:
return
tit
->
second
;
return
tit
->
second
;
}
}
private:
private:
typedef
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
MockTableMeta
>>
TableMetaCache
;
typedef
std
::
map
<
std
::
string
,
std
::
shared_ptr
<
MockTableMeta
>>
TableMetaCache
;
typedef
std
::
map
<
std
::
string
,
TableMetaCache
>
DbMetaCache
;
typedef
std
::
map
<
std
::
string
,
TableMetaCache
>
DbMetaCache
;
std
::
string
toDbname
(
const
std
::
string
&
dbFullName
)
const
{
std
::
string
toDbname
(
const
std
::
string
&
dbFullName
)
const
{
std
::
string
::
size_type
n
=
dbFullName
.
find
(
"."
);
std
::
string
::
size_type
n
=
dbFullName
.
find
(
"."
);
...
@@ -257,9 +255,7 @@ private:
...
@@ -257,9 +255,7 @@ private:
}
}
}
}
std
::
string
dtToString
(
int8_t
type
)
const
{
std
::
string
dtToString
(
int8_t
type
)
const
{
return
tDataTypes
[
type
].
name
;
}
return
tDataTypes
[
type
].
name
;
}
std
::
string
ftToString
(
int16_t
colid
,
int16_t
numOfColumns
)
const
{
std
::
string
ftToString
(
int16_t
colid
,
int16_t
numOfColumns
)
const
{
return
(
0
==
colid
?
"column"
:
(
colid
<
numOfColumns
?
"column"
:
"tag"
));
return
(
0
==
colid
?
"column"
:
(
colid
<
numOfColumns
?
"column"
:
"tag"
));
...
@@ -270,7 +266,8 @@ private:
...
@@ -270,7 +266,8 @@ private:
return
table
?
table
->
schema
:
nullptr
;
return
table
?
table
->
schema
:
nullptr
;
}
}
int32_t
copyTableSchemaMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
,
std
::
unique_ptr
<
STableMeta
>*
dst
)
const
{
int32_t
copyTableSchemaMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
,
std
::
unique_ptr
<
STableMeta
>*
dst
)
const
{
STableMeta
*
src
=
getTableSchemaMeta
(
db
,
tbname
);
STableMeta
*
src
=
getTableSchemaMeta
(
db
,
tbname
);
if
(
nullptr
==
src
)
{
if
(
nullptr
==
src
)
{
return
TSDB_CODE_TSC_INVALID_TABLE_NAME
;
return
TSDB_CODE_TSC_INVALID_TABLE_NAME
;
...
@@ -305,30 +302,29 @@ private:
...
@@ -305,30 +302,29 @@ private:
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
uint64_t
id_
;
uint64_t
id_
;
std
::
unique_ptr
<
TableBuilder
>
builder_
;
std
::
unique_ptr
<
TableBuilder
>
builder_
;
DbMetaCache
meta_
;
DbMetaCache
meta_
;
};
};
MockCatalogService
::
MockCatalogService
()
:
impl_
(
new
MockCatalogServiceImpl
())
{
MockCatalogService
::
MockCatalogService
()
:
impl_
(
new
MockCatalogServiceImpl
())
{}
}
MockCatalogService
::~
MockCatalogService
()
{
MockCatalogService
::~
MockCatalogService
()
{}
}
ITableBuilder
&
MockCatalogService
::
createTableBuilder
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
,
int8_t
tableType
,
int32_t
numOfColumns
,
int32_t
numOfTags
)
{
ITableBuilder
&
MockCatalogService
::
createTableBuilder
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
,
int8_t
tableType
,
int32_t
numOfColumns
,
int32_t
numOfTags
)
{
return
impl_
->
createTableBuilder
(
db
,
tbname
,
tableType
,
numOfColumns
,
numOfTags
);
return
impl_
->
createTableBuilder
(
db
,
tbname
,
tableType
,
numOfColumns
,
numOfTags
);
}
}
void
MockCatalogService
::
createSubTable
(
const
std
::
string
&
db
,
const
std
::
string
&
stbname
,
const
std
::
string
&
tbname
,
int16_t
vgid
)
{
void
MockCatalogService
::
createSubTable
(
const
std
::
string
&
db
,
const
std
::
string
&
stbname
,
const
std
::
string
&
tbname
,
int16_t
vgid
)
{
impl_
->
createSubTable
(
db
,
stbname
,
tbname
,
vgid
);
impl_
->
createSubTable
(
db
,
stbname
,
tbname
,
vgid
);
}
}
void
MockCatalogService
::
showTables
()
const
{
void
MockCatalogService
::
showTables
()
const
{
impl_
->
showTables
();
}
impl_
->
showTables
();
}
std
::
shared_ptr
<
MockTableMeta
>
MockCatalogService
::
getTableMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
)
const
{
std
::
shared_ptr
<
MockTableMeta
>
MockCatalogService
::
getTableMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
)
const
{
return
impl_
->
getTableMeta
(
db
,
tbname
);
return
impl_
->
getTableMeta
(
db
,
tbname
);
}
}
...
...
source/libs/parser/test/mockCatalogService.h
浏览文件 @
ac874f9e
...
@@ -20,17 +20,15 @@
...
@@ -20,17 +20,15 @@
#include <string>
#include <string>
#include <vector>
#include <vector>
#define ALLOW_FORBID_FUNC
#include "catalog.h"
#include "catalog.h"
class
ITableBuilder
{
class
ITableBuilder
{
public:
public:
ITableBuilder
&
addTag
(
const
std
::
string
&
name
,
int8_t
type
)
{
ITableBuilder
&
addTag
(
const
std
::
string
&
name
,
int8_t
type
)
{
return
addColumn
(
name
,
type
,
tDataTypes
[
type
].
bytes
);
}
return
addColumn
(
name
,
type
,
tDataTypes
[
type
].
bytes
);
}
ITableBuilder
&
addTag
(
const
std
::
string
&
name
,
int8_t
type
,
int32_t
bytes
)
{
ITableBuilder
&
addTag
(
const
std
::
string
&
name
,
int8_t
type
,
int32_t
bytes
)
{
return
addColumn
(
name
,
type
,
bytes
);
}
return
addColumn
(
name
,
type
,
bytes
);
}
ITableBuilder
&
addColumn
(
const
std
::
string
&
name
,
int8_t
type
)
{
ITableBuilder
&
addColumn
(
const
std
::
string
&
name
,
int8_t
type
)
{
return
addColumn
(
name
,
type
,
tDataTypes
[
type
].
bytes
);
return
addColumn
(
name
,
type
,
tDataTypes
[
type
].
bytes
);
...
@@ -39,24 +37,23 @@ public:
...
@@ -39,24 +37,23 @@ public:
virtual
ITableBuilder
&
addColumn
(
const
std
::
string
&
name
,
int8_t
type
,
int32_t
bytes
)
=
0
;
virtual
ITableBuilder
&
addColumn
(
const
std
::
string
&
name
,
int8_t
type
,
int32_t
bytes
)
=
0
;
virtual
ITableBuilder
&
setVgid
(
int16_t
vgid
)
=
0
;
virtual
ITableBuilder
&
setVgid
(
int16_t
vgid
)
=
0
;
virtual
ITableBuilder
&
setPrecision
(
uint8_t
precision
)
=
0
;
virtual
ITableBuilder
&
setPrecision
(
uint8_t
precision
)
=
0
;
virtual
void
done
()
=
0
;
virtual
void
done
()
=
0
;
};
};
struct
MockTableMeta
{
struct
MockTableMeta
{
~
MockTableMeta
()
{
~
MockTableMeta
()
{
taosMemoryFree
(
schema
);
}
taosMemoryFree
(
schema
);
}
STableMeta
*
schema
;
STableMeta
*
schema
;
std
::
vector
<
SVgroupInfo
>
vgs
;
std
::
vector
<
SVgroupInfo
>
vgs
;
};
};
class
MockCatalogServiceImpl
;
class
MockCatalogServiceImpl
;
class
MockCatalogService
{
class
MockCatalogService
{
public:
public:
MockCatalogService
();
MockCatalogService
();
~
MockCatalogService
();
~
MockCatalogService
();
ITableBuilder
&
createTableBuilder
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
,
int8_t
tableType
,
int32_t
numOfColumns
,
int32_t
numOfTags
=
0
);
ITableBuilder
&
createTableBuilder
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
,
int8_t
tableType
,
int32_t
numOfColumns
,
int32_t
numOfTags
=
0
);
void
createSubTable
(
const
std
::
string
&
db
,
const
std
::
string
&
stbname
,
const
std
::
string
&
tbname
,
int16_t
vgid
);
void
createSubTable
(
const
std
::
string
&
db
,
const
std
::
string
&
stbname
,
const
std
::
string
&
tbname
,
int16_t
vgid
);
void
showTables
()
const
;
void
showTables
()
const
;
std
::
shared_ptr
<
MockTableMeta
>
getTableMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
)
const
;
std
::
shared_ptr
<
MockTableMeta
>
getTableMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
)
const
;
...
@@ -65,7 +62,7 @@ public:
...
@@ -65,7 +62,7 @@ public:
int32_t
catalogGetTableHashVgroup
(
const
SName
*
pTableName
,
SVgroupInfo
*
vgInfo
)
const
;
int32_t
catalogGetTableHashVgroup
(
const
SName
*
pTableName
,
SVgroupInfo
*
vgInfo
)
const
;
int32_t
catalogGetTableDistVgInfo
(
const
SName
*
pTableName
,
SArray
**
pVgList
)
const
;
int32_t
catalogGetTableDistVgInfo
(
const
SName
*
pTableName
,
SArray
**
pVgList
)
const
;
private:
private:
std
::
unique_ptr
<
MockCatalogServiceImpl
>
impl_
;
std
::
unique_ptr
<
MockCatalogServiceImpl
>
impl_
;
};
};
...
...
source/libs/parser/test/parserAstTest.cpp
浏览文件 @
ac874f9e
...
@@ -18,14 +18,14 @@
...
@@ -18,14 +18,14 @@
#include <gtest/gtest.h>
#include <gtest/gtest.h>
#include "parserTestUtil.h"
#include "parInt.h"
#include "parInt.h"
#include "parserTestUtil.h"
using
namespace
std
;
using
namespace
std
;
using
namespace
testing
;
using
namespace
testing
;
class
ParserTest
:
public
Test
{
class
ParserTest
:
public
Test
{
protected:
protected:
void
setDatabase
(
const
string
&
acctId
,
const
string
&
db
)
{
void
setDatabase
(
const
string
&
acctId
,
const
string
&
db
)
{
acctId_
=
acctId
;
acctId_
=
acctId
;
db_
=
db
;
db_
=
db
;
...
@@ -51,7 +51,7 @@ protected:
...
@@ -51,7 +51,7 @@ protected:
return
res
;
return
res
;
}
}
private:
private:
static
const
int
max_err_len
=
1024
;
static
const
int
max_err_len
=
1024
;
bool
runImpl
(
int32_t
parseCode
,
int32_t
translateCode
)
{
bool
runImpl
(
int32_t
parseCode
,
int32_t
translateCode
)
{
...
@@ -105,7 +105,7 @@ private:
...
@@ -105,7 +105,7 @@ private:
}
}
string
toString
(
const
SNode
*
pRoot
,
bool
format
=
false
)
{
string
toString
(
const
SNode
*
pRoot
,
bool
format
=
false
)
{
char
*
pStr
=
NULL
;
char
*
pStr
=
NULL
;
int32_t
len
=
0
;
int32_t
len
=
0
;
int32_t
code
=
nodesNodeToString
(
pRoot
,
format
,
&
pStr
,
&
len
);
int32_t
code
=
nodesNodeToString
(
pRoot
,
format
,
&
pStr
,
&
len
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
@@ -130,18 +130,18 @@ private:
...
@@ -130,18 +130,18 @@ private:
calcConstAstStr_
.
clear
();
calcConstAstStr_
.
clear
();
}
}
string
acctId_
;
string
acctId_
;
string
db_
;
string
db_
;
char
errMagBuf_
[
max_err_len
];
char
errMagBuf_
[
max_err_len
];
string
sqlBuf_
;
string
sqlBuf_
;
SParseContext
cxt_
;
SParseContext
cxt_
;
SQuery
*
query_
;
SQuery
*
query_
;
string
parseErrStr_
;
string
parseErrStr_
;
string
parsedAstStr_
;
string
parsedAstStr_
;
string
translateErrStr_
;
string
translateErrStr_
;
string
translatedAstStr_
;
string
translatedAstStr_
;
string
calcConstErrStr_
;
string
calcConstErrStr_
;
string
calcConstAstStr_
;
string
calcConstAstStr_
;
};
};
TEST_F
(
ParserTest
,
createAccount
)
{
TEST_F
(
ParserTest
,
createAccount
)
{
...
@@ -207,7 +207,9 @@ TEST_F(ParserTest, selectConstant) {
...
@@ -207,7 +207,9 @@ TEST_F(ParserTest, selectConstant) {
bind
(
"SELECT 123, 20.4, 'abc',
\"
wxy
\"
, TIMESTAMP '2022-02-09 17:30:20', true, false, 10s FROM t1"
);
bind
(
"SELECT 123, 20.4, 'abc',
\"
wxy
\"
, TIMESTAMP '2022-02-09 17:30:20', true, false, 10s FROM t1"
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
bind
(
"SELECT 1234567890123456789012345678901234567890, 20.1234567890123456789012345678901234567890, 'abc',
\"
wxy
\"
, TIMESTAMP '2022-02-09 17:30:20', true, false, 15s FROM t1"
);
bind
(
"SELECT 1234567890123456789012345678901234567890, 20.1234567890123456789012345678901234567890, 'abc',
\"
wxy
\"
, "
"TIMESTAMP '2022-02-09 17:30:20', true, false, 15s FROM t1"
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
bind
(
"SELECT 123 + 45 FROM t1 where 2 - 1"
);
bind
(
"SELECT 123 + 45 FROM t1 where 2 - 1"
);
...
@@ -449,32 +451,32 @@ TEST_F(ParserTest, createDatabase) {
...
@@ -449,32 +451,32 @@ TEST_F(ParserTest, createDatabase) {
bind
(
"create database wxy_db"
);
bind
(
"create database wxy_db"
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
bind
(
"create database if not exists wxy_db "
bind
(
"BLOCKS 100
"
"create database if not exists wxy_db
"
"CACHE
100 "
"BLOCKS
100 "
"CACHELAST 2
"
"CACHE 100
"
"COMP 1
"
"CACHELAST 2
"
"DAYS 100
"
"COMP 1
"
"FSYNC
100 "
"DAYS
100 "
"MAXROWS 10
00 "
"FSYNC 1
00 "
"MINROWS 1
00 "
"MAXROWS 10
00 "
"KEEP
100 "
"MINROWS
100 "
"PRECISION 'ms'
"
"KEEP 100
"
"QUORUM 1
"
"PRECISION 'ms'
"
"REPLICA 3
"
"QUORUM 1
"
"TTL 100
"
"REPLICA 3
"
"WAL 2
"
"TTL 100
"
"VGROUPS 100
"
"WAL 2
"
"SINGLE_STABLE
0 "
"VGROUPS 10
0 "
"STREAM_MODE 1
"
"SINGLE_STABLE 0
"
"RETENTIONS '15s:7d,1m:21d,15m:5y'
"
"STREAM_MODE 1
"
);
"RETENTIONS '15s:7d,1m:21d,15m:5y'"
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
bind
(
"create database if not exists wxy_db "
bind
(
"DAYS 100m
"
"create database if not exists wxy_db
"
"KEEP 200m,300h,400d
"
"DAYS 100m
"
);
"KEEP 200m,300h,400d "
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
}
}
...
@@ -484,14 +486,14 @@ TEST_F(ParserTest, alterDatabase) {
...
@@ -484,14 +486,14 @@ TEST_F(ParserTest, alterDatabase) {
bind
(
"alter database wxy_db BLOCKS 200"
);
bind
(
"alter database wxy_db BLOCKS 200"
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
bind
(
"alter database wxy_db "
bind
(
"BLOCKS 200
"
"alter database wxy_db
"
"CACHELAST 1
"
"BLOCKS 200
"
"FSYNC 200
"
"CACHELAST 1
"
"KEEP
200 "
"FSYNC
200 "
"QUORUM 2
"
"KEEP 200
"
"WAL 1
"
"QUORUM 2
"
);
"WAL 1 "
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
}
}
...
@@ -515,45 +517,55 @@ TEST_F(ParserTest, createTable) {
...
@@ -515,45 +517,55 @@ TEST_F(ParserTest, createTable) {
bind
(
"create table t1(ts timestamp, c1 int)"
);
bind
(
"create table t1(ts timestamp, c1 int)"
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
bind
(
"create table if not exists test.t1("
bind
(
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 SMALLINT, "
"create table if not exists test.t1("
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) "
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 "
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)"
"SMALLINT, "
);
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), "
"c14 JSON, c15 VARCHAR(50)) "
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3)"
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
bind
(
"create table if not exists test.t1("
bind
(
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 SMALLINT, "
"create table if not exists test.t1("
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) "
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 "
"TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 BINARY(20), a8 SMALLINT, "
"SMALLINT, "
"a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), a14 JSON, a15 VARCHAR(50)) "
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), "
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2"
"c14 JSON, c15 VARCHAR(50)) "
);
"TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 "
"BINARY(20), a8 SMALLINT, "
"a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), "
"a14 JSON, a15 VARCHAR(50)) "
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2"
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
bind
(
"create table if not exists t1 using st1 tags(1, 'wxy')"
);
bind
(
"create table if not exists t1 using st1 tags(1, 'wxy')"
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
bind
(
"create table "
bind
(
"if not exists test.t1 using test.st1 (tag1, tag2) tags(1, 'abc')
"
"create table
"
"if not exists test.t2 using test.st1 (tag1, tag2) tags(2
, 'abc') "
"if not exists test.t1 using test.st1 (tag1, tag2) tags(1
, 'abc') "
"if not exists test.t3 using test.st1 (tag1, tag2) tags(3
, 'abc') "
"if not exists test.t2 using test.st1 (tag1, tag2) tags(2
, 'abc') "
"if not exists test.t4 using test.st1 (tag1, tag2) tags(3, null
) "
"if not exists test.t3 using test.st1 (tag1, tag2) tags(3, 'abc'
) "
"if not exists test.t5 using test.st1 (tag1, tag2) tags(null, 'abc'
) "
"if not exists test.t4 using test.st1 (tag1, tag2) tags(3, null
) "
"if not exists test.t6 using test.st1 (tag1, tag2) tags(null, null)
"
"if not exists test.t5 using test.st1 (tag1, tag2) tags(null, 'abc')
"
);
"if not exists test.t6 using test.st1 (tag1, tag2) tags(null, null)"
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
bind
(
"create stable t1(ts timestamp, c1 int) TAGS(id int)"
);
bind
(
"create stable t1(ts timestamp, c1 int) TAGS(id int)"
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
bind
(
"create stable if not exists test.t1("
bind
(
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 SMALLINT, "
"create stable if not exists test.t1("
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), c14 JSON, c15 VARCHAR(50)) "
"ts TIMESTAMP, c1 INT, c2 INT UNSIGNED, c3 BIGINT, c4 BIGINT UNSIGNED, c5 FLOAT, c6 DOUBLE, c7 BINARY(20), c8 "
"TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 BINARY(20), a8 SMALLINT, "
"SMALLINT, "
"a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), a14 JSON, a15 VARCHAR(50)) "
"c9 SMALLINT UNSIGNED COMMENT 'test column comment', c10 TINYINT, c11 TINYINT UNSIGNED, c12 BOOL, c13 NCHAR(30), "
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2"
"c14 JSON, c15 VARCHAR(50)) "
);
"TAGS (tsa TIMESTAMP, a1 INT, a2 INT UNSIGNED, a3 BIGINT, a4 BIGINT UNSIGNED, a5 FLOAT, a6 DOUBLE, a7 "
"BINARY(20), a8 SMALLINT, "
"a9 SMALLINT UNSIGNED COMMENT 'test column comment', a10 TINYINT, a11 TINYINT UNSIGNED, a12 BOOL, a13 NCHAR(30), "
"a14 JSON, a15 VARCHAR(50)) "
"KEEP 100 TTL 100 COMMENT 'test create table' SMA(c1, c2, c3) ROLLUP (min) FILE_FACTOR 0.1 DELAY 2"
);
ASSERT_TRUE
(
run
());
ASSERT_TRUE
(
run
());
}
}
...
...
source/libs/parser/test/parserInsertTest.cpp
浏览文件 @
ac874f9e
...
@@ -22,10 +22,8 @@ using namespace std;
...
@@ -22,10 +22,8 @@ using namespace std;
using
namespace
testing
;
using
namespace
testing
;
namespace
{
namespace
{
string
toString
(
int32_t
code
)
{
string
toString
(
int32_t
code
)
{
return
tstrerror
(
code
);
}
return
tstrerror
(
code
);
}
// namespace
}
}
// syntax:
// syntax:
// INSERT INTO
// INSERT INTO
...
@@ -35,7 +33,7 @@ namespace {
...
@@ -35,7 +33,7 @@ namespace {
// VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path
// VALUES (field1_value, ...) [(field1_value2, ...) ...] | FILE csv_file_path
// [...];
// [...];
class
InsertTest
:
public
Test
{
class
InsertTest
:
public
Test
{
protected:
protected:
void
setDatabase
(
const
string
&
acctId
,
const
string
&
db
)
{
void
setDatabase
(
const
string
&
acctId
,
const
string
&
db
)
{
acctId_
=
acctId
;
acctId_
=
acctId
;
db_
=
db
;
db_
=
db
;
...
@@ -44,12 +42,11 @@ protected:
...
@@ -44,12 +42,11 @@ protected:
void
bind
(
const
char
*
sql
)
{
void
bind
(
const
char
*
sql
)
{
reset
();
reset
();
cxt_
.
acctId
=
atoi
(
acctId_
.
c_str
());
cxt_
.
acctId
=
atoi
(
acctId_
.
c_str
());
cxt_
.
db
=
(
char
*
)
db_
.
c_str
();
cxt_
.
db
=
(
char
*
)
db_
.
c_str
();
strcpy
(
sqlBuf_
,
sql
);
strcpy
(
sqlBuf_
,
sql
);
cxt_
.
sqlLen
=
strlen
(
sql
);
cxt_
.
sqlLen
=
strlen
(
sql
);
sqlBuf_
[
cxt_
.
sqlLen
]
=
'\0'
;
sqlBuf_
[
cxt_
.
sqlLen
]
=
'\0'
;
cxt_
.
pSql
=
sqlBuf_
;
cxt_
.
pSql
=
sqlBuf_
;
}
}
int32_t
run
()
{
int32_t
run
()
{
...
@@ -62,19 +59,21 @@ protected:
...
@@ -62,19 +59,21 @@ protected:
void
dumpReslut
()
{
void
dumpReslut
()
{
SVnodeModifOpStmt
*
pStmt
=
getVnodeModifStmt
(
res_
);
SVnodeModifOpStmt
*
pStmt
=
getVnodeModifStmt
(
res_
);
size_t
num
=
taosArrayGetSize
(
pStmt
->
pDataBlocks
);
size_t
num
=
taosArrayGetSize
(
pStmt
->
pDataBlocks
);
cout
<<
"payloadType:"
<<
(
int32_t
)
pStmt
->
payloadType
<<
", insertType:"
<<
pStmt
->
insertType
<<
", numOfVgs:"
<<
num
<<
endl
;
cout
<<
"payloadType:"
<<
(
int32_t
)
pStmt
->
payloadType
<<
", insertType:"
<<
pStmt
->
insertType
<<
", numOfVgs:"
<<
num
<<
endl
;
for
(
size_t
i
=
0
;
i
<
num
;
++
i
)
{
for
(
size_t
i
=
0
;
i
<
num
;
++
i
)
{
SVgDataBlocks
*
vg
=
(
SVgDataBlocks
*
)
taosArrayGetP
(
pStmt
->
pDataBlocks
,
i
);
SVgDataBlocks
*
vg
=
(
SVgDataBlocks
*
)
taosArrayGetP
(
pStmt
->
pDataBlocks
,
i
);
cout
<<
"vgId:"
<<
vg
->
vg
.
vgId
<<
", numOfTables:"
<<
vg
->
numOfTables
<<
", dataSize:"
<<
vg
->
size
<<
endl
;
cout
<<
"vgId:"
<<
vg
->
vg
.
vgId
<<
", numOfTables:"
<<
vg
->
numOfTables
<<
", dataSize:"
<<
vg
->
size
<<
endl
;
SSubmitReq
*
submit
=
(
SSubmitReq
*
)
vg
->
pData
;
SSubmitReq
*
submit
=
(
SSubmitReq
*
)
vg
->
pData
;
cout
<<
"length:"
<<
ntohl
(
submit
->
length
)
<<
", numOfBlocks:"
<<
ntohl
(
submit
->
numOfBlocks
)
<<
endl
;
cout
<<
"length:"
<<
ntohl
(
submit
->
length
)
<<
", numOfBlocks:"
<<
ntohl
(
submit
->
numOfBlocks
)
<<
endl
;
int32_t
numOfBlocks
=
ntohl
(
submit
->
numOfBlocks
);
int32_t
numOfBlocks
=
ntohl
(
submit
->
numOfBlocks
);
SSubmitBlk
*
blk
=
(
SSubmitBlk
*
)(
submit
+
1
);
SSubmitBlk
*
blk
=
(
SSubmitBlk
*
)(
submit
+
1
);
for
(
int32_t
i
=
0
;
i
<
numOfBlocks
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfBlocks
;
++
i
)
{
cout
<<
"Block:"
<<
i
<<
endl
;
cout
<<
"Block:"
<<
i
<<
endl
;
cout
<<
"
\t
uid:"
<<
be64toh
(
blk
->
uid
)
<<
", tid:"
<<
be64toh
(
blk
->
suid
)
<<
", padding:"
<<
ntohl
(
blk
->
padding
)
<<
", sversion:"
<<
ntohl
(
blk
->
sversion
)
cout
<<
"
\t
uid:"
<<
be64toh
(
blk
->
uid
)
<<
", tid:"
<<
be64toh
(
blk
->
suid
)
<<
", padding:"
<<
ntohl
(
blk
->
padding
)
<<
", dataLen:"
<<
ntohl
(
blk
->
dataLen
)
<<
", schemaLen:"
<<
ntohl
(
blk
->
schemaLen
)
<<
", numOfRows:"
<<
ntohs
(
blk
->
numOfRows
)
<<
endl
;
<<
", sversion:"
<<
ntohl
(
blk
->
sversion
)
<<
", dataLen:"
<<
ntohl
(
blk
->
dataLen
)
<<
", schemaLen:"
<<
ntohl
(
blk
->
schemaLen
)
<<
", numOfRows:"
<<
ntohs
(
blk
->
numOfRows
)
<<
endl
;
blk
=
(
SSubmitBlk
*
)(
blk
->
data
+
ntohl
(
blk
->
dataLen
));
blk
=
(
SSubmitBlk
*
)(
blk
->
data
+
ntohl
(
blk
->
dataLen
));
}
}
}
}
...
@@ -93,7 +92,7 @@ protected:
...
@@ -93,7 +92,7 @@ protected:
SSubmitReq
*
submit
=
(
SSubmitReq
*
)
vg
->
pData
;
SSubmitReq
*
submit
=
(
SSubmitReq
*
)
vg
->
pData
;
ASSERT_GE
(
ntohl
(
submit
->
length
),
0
);
ASSERT_GE
(
ntohl
(
submit
->
length
),
0
);
ASSERT_GE
(
ntohl
(
submit
->
numOfBlocks
),
0
);
ASSERT_GE
(
ntohl
(
submit
->
numOfBlocks
),
0
);
int32_t
numOfBlocks
=
ntohl
(
submit
->
numOfBlocks
);
int32_t
numOfBlocks
=
ntohl
(
submit
->
numOfBlocks
);
SSubmitBlk
*
blk
=
(
SSubmitBlk
*
)(
submit
+
1
);
SSubmitBlk
*
blk
=
(
SSubmitBlk
*
)(
submit
+
1
);
for
(
int32_t
i
=
0
;
i
<
numOfBlocks
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfBlocks
;
++
i
)
{
ASSERT_EQ
(
ntohs
(
blk
->
numOfRows
),
(
0
==
i
?
numOfRows1
:
(
numOfRows2
>
0
?
numOfRows2
:
numOfRows1
)));
ASSERT_EQ
(
ntohs
(
blk
->
numOfRows
),
(
0
==
i
?
numOfRows1
:
(
numOfRows2
>
0
?
numOfRows2
:
numOfRows1
)));
...
@@ -102,7 +101,7 @@ protected:
...
@@ -102,7 +101,7 @@ protected:
}
}
}
}
private:
private:
static
const
int
max_err_len
=
1024
;
static
const
int
max_err_len
=
1024
;
static
const
int
max_sql_len
=
1024
*
1024
;
static
const
int
max_sql_len
=
1024
*
1024
;
...
@@ -114,17 +113,15 @@ private:
...
@@ -114,17 +113,15 @@ private:
code_
=
TSDB_CODE_SUCCESS
;
code_
=
TSDB_CODE_SUCCESS
;
}
}
SVnodeModifOpStmt
*
getVnodeModifStmt
(
SQuery
*
pQuery
)
{
SVnodeModifOpStmt
*
getVnodeModifStmt
(
SQuery
*
pQuery
)
{
return
(
SVnodeModifOpStmt
*
)
pQuery
->
pRoot
;
}
return
(
SVnodeModifOpStmt
*
)
pQuery
->
pRoot
;
}
string
acctId_
;
string
acctId_
;
string
db_
;
string
db_
;
char
errMagBuf_
[
max_err_len
];
char
errMagBuf_
[
max_err_len
];
char
sqlBuf_
[
max_sql_len
];
char
sqlBuf_
[
max_sql_len
];
SParseContext
cxt_
;
SParseContext
cxt_
;
int32_t
code_
;
int32_t
code_
;
SQuery
*
res_
;
SQuery
*
res_
;
};
};
// INSERT INTO tb_name VALUES (field1_value, ...)
// INSERT INTO tb_name VALUES (field1_value, ...)
...
@@ -141,7 +138,9 @@ TEST_F(InsertTest, singleTableSingleRowTest) {
...
@@ -141,7 +138,9 @@ TEST_F(InsertTest, singleTableSingleRowTest) {
TEST_F
(
InsertTest
,
singleTableMultiRowTest
)
{
TEST_F
(
InsertTest
,
singleTableMultiRowTest
)
{
setDatabase
(
"root"
,
"test"
);
setDatabase
(
"root"
,
"test"
);
bind
(
"insert into t1 values (now, 1, 'beijing', 3, 4, 5)(now+1s, 2, 'shanghai', 6, 7, 8)(now+2s, 3, 'guangzhou', 9, 10, 11)"
);
bind
(
"insert into t1 values (now, 1, 'beijing', 3, 4, 5)(now+1s, 2, 'shanghai', 6, 7, 8)(now+2s, 3, 'guangzhou', 9, "
"10, 11)"
);
ASSERT_EQ
(
run
(),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
run
(),
TSDB_CODE_SUCCESS
);
dumpReslut
();
dumpReslut
();
checkReslut
(
1
,
3
);
checkReslut
(
1
,
3
);
...
@@ -161,20 +160,23 @@ TEST_F(InsertTest, multiTableSingleRowTest) {
...
@@ -161,20 +160,23 @@ TEST_F(InsertTest, multiTableSingleRowTest) {
TEST_F
(
InsertTest
,
multiTableMultiRowTest
)
{
TEST_F
(
InsertTest
,
multiTableMultiRowTest
)
{
setDatabase
(
"root"
,
"test"
);
setDatabase
(
"root"
,
"test"
);
bind
(
"insert into st1s1 values (now, 1,
\"
beijing
\"
)(now+1s, 2,
\"
shanghai
\"
)(now+2s, 3,
\"
guangzhou
\"
)"
bind
(
" st1s2 values (now, 10,
\"
131028
\"
)(now+1s, 20,
\"
132028
\"
)"
);
"insert into st1s1 values (now, 1,
\"
beijing
\"
)(now+1s, 2,
\"
shanghai
\"
)(now+2s, 3,
\"
guangzhou
\"
)"
" st1s2 values (now, 10,
\"
131028
\"
)(now+1s, 20,
\"
132028
\"
)"
);
ASSERT_EQ
(
run
(),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
run
(),
TSDB_CODE_SUCCESS
);
dumpReslut
();
dumpReslut
();
checkReslut
(
2
,
3
,
2
);
checkReslut
(
2
,
3
,
2
);
}
}
// INSERT INTO
// INSERT INTO
// tb1_name USING st1_name [(tag1_name, ...)] TAGS (tag1_value, ...) VALUES (field1_value, ...)
// tb1_name USING st1_name [(tag1_name, ...)] TAGS (tag1_value, ...) VALUES (field1_value, ...)
// tb2_name USING st2_name [(tag1_name, ...)] TAGS (tag1_value, ...) VALUES (field1_value, ...)
// tb2_name USING st2_name [(tag1_name, ...)] TAGS (tag1_value, ...) VALUES (field1_value, ...)
TEST_F
(
InsertTest
,
autoCreateTableTest
)
{
TEST_F
(
InsertTest
,
autoCreateTableTest
)
{
setDatabase
(
"root"
,
"test"
);
setDatabase
(
"root"
,
"test"
);
bind
(
"insert into st1s1 using st1 tags(1, 'wxy') values (now, 1,
\"
beijing
\"
)(now+1s, 2,
\"
shanghai
\"
)(now+2s, 3,
\"
guangzhou
\"
)"
);
bind
(
"insert into st1s1 using st1 tags(1, 'wxy') values (now, 1,
\"
beijing
\"
)(now+1s, 2,
\"
shanghai
\"
)(now+2s, 3, "
"
\"
guangzhou
\"
)"
);
ASSERT_EQ
(
run
(),
TSDB_CODE_SUCCESS
);
ASSERT_EQ
(
run
(),
TSDB_CODE_SUCCESS
);
dumpReslut
();
dumpReslut
();
checkReslut
(
1
,
3
);
checkReslut
(
1
,
3
);
...
...
source/libs/parser/test/parserTestMain.cpp
浏览文件 @
ac874f9e
...
@@ -13,9 +13,9 @@
...
@@ -13,9 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
*/
#include <string>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string>
#include <getopt.h>
#include <getopt.h>
#include <gtest/gtest.h>
#include <gtest/gtest.h>
...
@@ -23,16 +23,16 @@
...
@@ -23,16 +23,16 @@
#ifdef WINDOWS
#ifdef WINDOWS
#define TD_USE_WINSOCK
#define TD_USE_WINSOCK
#endif
#endif
#include "os.h"
#include "parserTestUtil.h"
#include "parToken.h"
#include "functionMgt.h"
#include "functionMgt.h"
#include "mockCatalog.h"
#include "mockCatalog.h"
#include "os.h"
#include "parToken.h"
#include "parserTestUtil.h"
bool
g_isDump
=
false
;
bool
g_isDump
=
false
;
class
ParserEnv
:
public
testing
::
Environment
{
class
ParserEnv
:
public
testing
::
Environment
{
public:
public:
virtual
void
SetUp
()
{
virtual
void
SetUp
()
{
initMetaDataEnv
();
initMetaDataEnv
();
generateMetaData
();
generateMetaData
();
...
@@ -49,12 +49,9 @@ public:
...
@@ -49,12 +49,9 @@ public:
};
};
static
void
parseArg
(
int
argc
,
char
*
argv
[])
{
static
void
parseArg
(
int
argc
,
char
*
argv
[])
{
int
opt
=
0
;
int
opt
=
0
;
const
char
*
optstring
=
""
;
const
char
*
optstring
=
""
;
static
struct
option
long_options
[]
=
{
static
struct
option
long_options
[]
=
{{
"dump"
,
no_argument
,
NULL
,
'd'
},
{
0
,
0
,
0
,
0
}};
{
"dump"
,
no_argument
,
NULL
,
'd'
},
{
0
,
0
,
0
,
0
}
};
while
((
opt
=
getopt_long
(
argc
,
argv
,
optstring
,
long_options
,
NULL
))
!=
-
1
)
{
while
((
opt
=
getopt_long
(
argc
,
argv
,
optstring
,
long_options
,
NULL
))
!=
-
1
)
{
switch
(
opt
)
{
switch
(
opt
)
{
case
'd'
:
case
'd'
:
...
@@ -67,8 +64,8 @@ static void parseArg(int argc, char* argv[]) {
...
@@ -67,8 +64,8 @@ static void parseArg(int argc, char* argv[]) {
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
int
main
(
int
argc
,
char
*
argv
[])
{
testing
::
AddGlobalTestEnvironment
(
new
ParserEnv
());
testing
::
AddGlobalTestEnvironment
(
new
ParserEnv
());
testing
::
InitGoogleTest
(
&
argc
,
argv
);
testing
::
InitGoogleTest
(
&
argc
,
argv
);
parseArg
(
argc
,
argv
);
parseArg
(
argc
,
argv
);
return
RUN_ALL_TESTS
();
return
RUN_ALL_TESTS
();
}
}
source/libs/planner/inc/planInt.h
浏览文件 @
ac874f9e
...
@@ -26,12 +26,12 @@ extern "C" {
...
@@ -26,12 +26,12 @@ extern "C" {
#define QUERY_POLICY_HYBRID 2
#define QUERY_POLICY_HYBRID 2
#define QUERY_POLICY_QNODE 3
#define QUERY_POLICY_QNODE 3
#define planFatal(param, ...)
qFatal("PLAN: " param, __VA_ARGS__)
#define planFatal(param, ...) qFatal("PLAN: " param, __VA_ARGS__)
#define planError(param, ...)
qError("PLAN: " param, __VA_ARGS__)
#define planError(param, ...) qError("PLAN: " param, __VA_ARGS__)
#define planWarn(param, ...)
qWarn("PLAN: " param, __VA_ARGS__)
#define planWarn(param, ...) qWarn("PLAN: " param, __VA_ARGS__)
#define planInfo(param, ...)
qInfo("PLAN: " param, __VA_ARGS__)
#define planInfo(param, ...) qInfo("PLAN: " param, __VA_ARGS__)
#define planDebug(param, ...)
qDebug("PLAN: " param, __VA_ARGS__)
#define planDebug(param, ...) qDebug("PLAN: " param, __VA_ARGS__)
#define planTrace(param, ...)
qTrace("PLAN: " param, __VA_ARGS__)
#define planTrace(param, ...) qTrace("PLAN: " param, __VA_ARGS__)
int32_t
createLogicPlan
(
SPlanContext
*
pCxt
,
SLogicNode
**
pLogicNode
);
int32_t
createLogicPlan
(
SPlanContext
*
pCxt
,
SLogicNode
**
pLogicNode
);
int32_t
optimizeLogicPlan
(
SPlanContext
*
pCxt
,
SLogicNode
*
pLogicNode
);
int32_t
optimizeLogicPlan
(
SPlanContext
*
pCxt
,
SLogicNode
*
pLogicNode
);
...
...
source/libs/planner/src/planLogicCreater.c
浏览文件 @
ac874f9e
此差异已折叠。
点击以展开。
source/libs/planner/src/planOptimizer.c
浏览文件 @
ac874f9e
此差异已折叠。
点击以展开。
source/libs/planner/src/planPhysiCreater.c
浏览文件 @
ac874f9e
此差异已折叠。
点击以展开。
source/libs/planner/src/planScaleOut.c
浏览文件 @
ac874f9e
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
typedef
struct
SScaleOutContext
{
typedef
struct
SScaleOutContext
{
SPlanContext
*
pPlanCxt
;
SPlanContext
*
pPlanCxt
;
int32_t
subplanId
;
int32_t
subplanId
;
}
SScaleOutContext
;
}
SScaleOutContext
;
static
SLogicSubplan
*
singleCloneSubLogicPlan
(
SScaleOutContext
*
pCxt
,
SLogicSubplan
*
pSrc
,
int32_t
level
)
{
static
SLogicSubplan
*
singleCloneSubLogicPlan
(
SScaleOutContext
*
pCxt
,
SLogicSubplan
*
pSrc
,
int32_t
level
)
{
...
@@ -40,7 +40,7 @@ static SLogicSubplan* singleCloneSubLogicPlan(SScaleOutContext* pCxt, SLogicSubp
...
@@ -40,7 +40,7 @@ static SLogicSubplan* singleCloneSubLogicPlan(SScaleOutContext* pCxt, SLogicSubp
static
int32_t
scaleOutForModify
(
SScaleOutContext
*
pCxt
,
SLogicSubplan
*
pSubplan
,
int32_t
level
,
SNodeList
*
pGroup
)
{
static
int32_t
scaleOutForModify
(
SScaleOutContext
*
pCxt
,
SLogicSubplan
*
pSubplan
,
int32_t
level
,
SNodeList
*
pGroup
)
{
SVnodeModifLogicNode
*
pNode
=
(
SVnodeModifLogicNode
*
)
pSubplan
->
pNode
;
SVnodeModifLogicNode
*
pNode
=
(
SVnodeModifLogicNode
*
)
pSubplan
->
pNode
;
size_t
numOfVgroups
=
taosArrayGetSize
(
pNode
->
pDataBlocks
);
size_t
numOfVgroups
=
taosArrayGetSize
(
pNode
->
pDataBlocks
);
for
(
int32_t
i
=
0
;
i
<
numOfVgroups
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
numOfVgroups
;
++
i
)
{
SLogicSubplan
*
pNewSubplan
=
singleCloneSubLogicPlan
(
pCxt
,
pSubplan
,
level
);
SLogicSubplan
*
pNewSubplan
=
singleCloneSubLogicPlan
(
pCxt
,
pSubplan
,
level
);
if
(
NULL
==
pNewSubplan
)
{
if
(
NULL
==
pNewSubplan
)
{
...
@@ -108,8 +108,8 @@ static int32_t scaleOutForScan(SScaleOutContext* pCxt, SLogicSubplan* pSubplan,
...
@@ -108,8 +108,8 @@ static int32_t scaleOutForScan(SScaleOutContext* pCxt, SLogicSubplan* pSubplan,
static
int32_t
pushHierarchicalPlan
(
SNodeList
*
pParentsGroup
,
SNodeList
*
pCurrentGroup
)
{
static
int32_t
pushHierarchicalPlan
(
SNodeList
*
pParentsGroup
,
SNodeList
*
pCurrentGroup
)
{
int32_t
code
=
TSDB_CODE_SUCCESS
;
int32_t
code
=
TSDB_CODE_SUCCESS
;
bool
topLevel
=
(
0
==
LIST_LENGTH
(
pParentsGroup
));
bool
topLevel
=
(
0
==
LIST_LENGTH
(
pParentsGroup
));
SNode
*
pChild
=
NULL
;
SNode
*
pChild
=
NULL
;
FOREACH
(
pChild
,
pCurrentGroup
)
{
FOREACH
(
pChild
,
pCurrentGroup
)
{
if
(
topLevel
)
{
if
(
topLevel
)
{
code
=
nodesListAppend
(
pParentsGroup
,
pChild
);
code
=
nodesListAppend
(
pParentsGroup
,
pChild
);
...
@@ -192,8 +192,8 @@ int32_t scaleOutLogicPlan(SPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SQue
...
@@ -192,8 +192,8 @@ int32_t scaleOutLogicPlan(SPlanContext* pCxt, SLogicSubplan* pLogicSubplan, SQue
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
SScaleOutContext
cxt
=
{
.
pPlanCxt
=
pCxt
,
.
subplanId
=
1
};
SScaleOutContext
cxt
=
{
.
pPlanCxt
=
pCxt
,
.
subplanId
=
1
};
int32_t
code
=
doScaleOut
(
&
cxt
,
pLogicSubplan
,
0
,
pPlan
->
pTopSubplans
);
int32_t
code
=
doScaleOut
(
&
cxt
,
pLogicSubplan
,
0
,
pPlan
->
pTopSubplans
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pLogicPlan
=
pPlan
;
*
pLogicPlan
=
pPlan
;
}
else
{
}
else
{
...
...
source/libs/planner/src/planSpliter.c
浏览文件 @
ac874f9e
...
@@ -15,39 +15,39 @@
...
@@ -15,39 +15,39 @@
#include "planInt.h"
#include "planInt.h"
#define SPLIT_FLAG_MASK(n)
(1 << n)
#define SPLIT_FLAG_MASK(n) (1 << n)
#define SPLIT_FLAG_STS SPLIT_FLAG_MASK(0)
#define SPLIT_FLAG_STS SPLIT_FLAG_MASK(0)
#define SPLIT_FLAG_CTJ SPLIT_FLAG_MASK(1)
#define SPLIT_FLAG_CTJ SPLIT_FLAG_MASK(1)
#define SPLIT_FLAG_SET_MASK(val, mask) (val) |= (mask)
#define SPLIT_FLAG_SET_MASK(val, mask)
(val) |= (mask)
#define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0)
#define SPLIT_FLAG_TEST_MASK(val, mask) (((val) & (mask)) != 0)
typedef
struct
SSplitContext
{
typedef
struct
SSplitContext
{
int32_t
groupId
;
int32_t
groupId
;
bool
split
;
bool
split
;
}
SSplitContext
;
}
SSplitContext
;
typedef
int32_t
(
*
FSplit
)(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
);
typedef
int32_t
(
*
FSplit
)(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
);
typedef
struct
SSplitRule
{
typedef
struct
SSplitRule
{
char
*
pName
;
char
*
pName
;
FSplit
splitFunc
;
FSplit
splitFunc
;
}
SSplitRule
;
}
SSplitRule
;
typedef
struct
SStsInfo
{
typedef
struct
SStsInfo
{
SScanLogicNode
*
pScan
;
SScanLogicNode
*
pScan
;
SLogicSubplan
*
pSubplan
;
SLogicSubplan
*
pSubplan
;
}
SStsInfo
;
}
SStsInfo
;
typedef
struct
SCtjInfo
{
typedef
struct
SCtjInfo
{
SScanLogicNode
*
pScan
;
SScanLogicNode
*
pScan
;
SLogicSubplan
*
pSubplan
;
SLogicSubplan
*
pSubplan
;
}
SCtjInfo
;
}
SCtjInfo
;
typedef
struct
SUaInfo
{
typedef
struct
SUaInfo
{
SProjectLogicNode
*
pProject
;
SProjectLogicNode
*
pProject
;
SLogicSubplan
*
pSubplan
;
SLogicSubplan
*
pSubplan
;
}
SUaInfo
;
}
SUaInfo
;
typedef
struct
SUnInfo
{
typedef
struct
SUnInfo
{
...
@@ -70,7 +70,8 @@ static SLogicSubplan* splCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode*
...
@@ -70,7 +70,8 @@ static SLogicSubplan* splCreateScanSubplan(SSplitContext* pCxt, SScanLogicNode*
return
pSubplan
;
return
pSubplan
;
}
}
static
int32_t
splCreateExchangeNode
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
,
SScanLogicNode
*
pScan
,
ESubplanType
subplanType
)
{
static
int32_t
splCreateExchangeNode
(
SSplitContext
*
pCxt
,
SLogicSubplan
*
pSubplan
,
SScanLogicNode
*
pScan
,
ESubplanType
subplanType
)
{
SExchangeLogicNode
*
pExchange
=
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_EXCHANGE
);
SExchangeLogicNode
*
pExchange
=
nodesMakeNode
(
QUERY_NODE_LOGIC_PLAN_EXCHANGE
);
if
(
NULL
==
pExchange
)
{
if
(
NULL
==
pExchange
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_OUT_OF_MEMORY
;
...
@@ -117,8 +118,8 @@ static bool splMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan, int32_t flag,
...
@@ -117,8 +118,8 @@ static bool splMatch(SSplitContext* pCxt, SLogicSubplan* pSubplan, int32_t flag,
}
}
static
SLogicNode
*
stsMatchByNode
(
SLogicNode
*
pNode
)
{
static
SLogicNode
*
stsMatchByNode
(
SLogicNode
*
pNode
)
{
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pNode
)
&&
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pNode
)
&&
NULL
!=
((
SScanLogicNode
*
)
pNode
)
->
pVgroupList
&&
NULL
!=
((
SScanLogicNode
*
)
pNode
)
->
pVgroupList
&&
((
SScanLogicNode
*
)
pNode
)
->
pVgroupList
->
numOfVgroups
>
1
)
{
((
SScanLogicNode
*
)
pNode
)
->
pVgroupList
->
numOfVgroups
>
1
)
{
return
pNode
;
return
pNode
;
}
}
SNode
*
pChild
;
SNode
*
pChild
;
...
@@ -145,7 +146,8 @@ static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
...
@@ -145,7 +146,8 @@ static int32_t stsSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
if
(
!
splMatch
(
pCxt
,
pSubplan
,
SPLIT_FLAG_STS
,
(
FSplFindSplitNode
)
stsFindSplitNode
,
&
info
))
{
if
(
!
splMatch
(
pCxt
,
pSubplan
,
SPLIT_FLAG_STS
,
(
FSplFindSplitNode
)
stsFindSplitNode
,
&
info
))
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
code
=
nodesListMakeStrictAppend
(
&
info
.
pSubplan
->
pChildren
,
splCreateScanSubplan
(
pCxt
,
info
.
pScan
,
SPLIT_FLAG_STS
));
int32_t
code
=
nodesListMakeStrictAppend
(
&
info
.
pSubplan
->
pChildren
,
splCreateScanSubplan
(
pCxt
,
info
.
pScan
,
SPLIT_FLAG_STS
));
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
splCreateExchangeNode
(
pCxt
,
info
.
pSubplan
,
info
.
pScan
,
SUBPLAN_TYPE_MERGE
);
code
=
splCreateExchangeNode
(
pCxt
,
info
.
pSubplan
,
info
.
pScan
,
SUBPLAN_TYPE_MERGE
);
}
}
...
@@ -163,7 +165,8 @@ static SLogicNode* ctjMatchByNode(SLogicNode* pNode) {
...
@@ -163,7 +165,8 @@ static SLogicNode* ctjMatchByNode(SLogicNode* pNode) {
SLogicNode
*
pLeft
=
(
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
);
SLogicNode
*
pLeft
=
(
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
0
);
SLogicNode
*
pRight
=
(
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
1
);
SLogicNode
*
pRight
=
(
SLogicNode
*
)
nodesListGetNode
(
pNode
->
pChildren
,
1
);
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pLeft
)
&&
ctjIsSingleTable
(((
SScanLogicNode
*
)
pLeft
)
->
pMeta
->
tableType
)
&&
if
(
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pLeft
)
&&
ctjIsSingleTable
(((
SScanLogicNode
*
)
pLeft
)
->
pMeta
->
tableType
)
&&
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pRight
)
&&
ctjIsSingleTable
(((
SScanLogicNode
*
)
pRight
)
->
pMeta
->
tableType
))
{
QUERY_NODE_LOGIC_PLAN_SCAN
==
nodeType
(
pRight
)
&&
ctjIsSingleTable
(((
SScanLogicNode
*
)
pRight
)
->
pMeta
->
tableType
))
{
return
pRight
;
return
pRight
;
}
}
}
}
...
@@ -191,7 +194,8 @@ static int32_t ctjSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
...
@@ -191,7 +194,8 @@ static int32_t ctjSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
if
(
!
splMatch
(
pCxt
,
pSubplan
,
SPLIT_FLAG_CTJ
,
(
FSplFindSplitNode
)
ctjFindSplitNode
,
&
info
))
{
if
(
!
splMatch
(
pCxt
,
pSubplan
,
SPLIT_FLAG_CTJ
,
(
FSplFindSplitNode
)
ctjFindSplitNode
,
&
info
))
{
return
TSDB_CODE_SUCCESS
;
return
TSDB_CODE_SUCCESS
;
}
}
int32_t
code
=
nodesListMakeStrictAppend
(
&
info
.
pSubplan
->
pChildren
,
splCreateScanSubplan
(
pCxt
,
info
.
pScan
,
SPLIT_FLAG_CTJ
));
int32_t
code
=
nodesListMakeStrictAppend
(
&
info
.
pSubplan
->
pChildren
,
splCreateScanSubplan
(
pCxt
,
info
.
pScan
,
SPLIT_FLAG_CTJ
));
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
splCreateExchangeNode
(
pCxt
,
info
.
pSubplan
,
info
.
pScan
,
info
.
pSubplan
->
subplanType
);
code
=
splCreateExchangeNode
(
pCxt
,
info
.
pSubplan
,
info
.
pScan
,
info
.
pSubplan
->
subplanType
);
}
}
...
@@ -360,17 +364,15 @@ static int32_t unSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
...
@@ -360,17 +364,15 @@ static int32_t unSplit(SSplitContext* pCxt, SLogicSubplan* pSubplan) {
return
code
;
return
code
;
}
}
static
const
SSplitRule
splitRuleSet
[]
=
{
static
const
SSplitRule
splitRuleSet
[]
=
{{.
pName
=
"SuperTableScan"
,
.
splitFunc
=
stsSplit
},
{
.
pName
=
"SuperTableScan"
,
.
splitFunc
=
stsSplit
},
{.
pName
=
"ChildTableJoin"
,
.
splitFunc
=
ctjSplit
},
{
.
pName
=
"ChildTableJoin"
,
.
splitFunc
=
ctjSplit
},
{.
pName
=
"UnionAll"
,
.
splitFunc
=
uaSplit
},
{
.
pName
=
"UnionAll"
,
.
splitFunc
=
uaSplit
},
{.
pName
=
"Union"
,
.
splitFunc
=
unSplit
}};
{
.
pName
=
"Union"
,
.
splitFunc
=
unSplit
}
};
static
const
int32_t
splitRuleNum
=
(
sizeof
(
splitRuleSet
)
/
sizeof
(
SSplitRule
));
static
const
int32_t
splitRuleNum
=
(
sizeof
(
splitRuleSet
)
/
sizeof
(
SSplitRule
));
static
int32_t
applySplitRule
(
SLogicSubplan
*
pSubplan
)
{
static
int32_t
applySplitRule
(
SLogicSubplan
*
pSubplan
)
{
SSplitContext
cxt
=
{
.
groupId
=
pSubplan
->
id
.
groupId
+
1
,
.
split
=
false
};
SSplitContext
cxt
=
{
.
groupId
=
pSubplan
->
id
.
groupId
+
1
,
.
split
=
false
};
do
{
do
{
cxt
.
split
=
false
;
cxt
.
split
=
false
;
for
(
int32_t
i
=
0
;
i
<
splitRuleNum
;
++
i
)
{
for
(
int32_t
i
=
0
;
i
<
splitRuleNum
;
++
i
)
{
...
@@ -386,14 +388,10 @@ static int32_t applySplitRule(SLogicSubplan* pSubplan) {
...
@@ -386,14 +388,10 @@ static int32_t applySplitRule(SLogicSubplan* pSubplan) {
static
void
doSetLogicNodeParent
(
SLogicNode
*
pNode
,
SLogicNode
*
pParent
)
{
static
void
doSetLogicNodeParent
(
SLogicNode
*
pNode
,
SLogicNode
*
pParent
)
{
pNode
->
pParent
=
pParent
;
pNode
->
pParent
=
pParent
;
SNode
*
pChild
;
SNode
*
pChild
;
FOREACH
(
pChild
,
pNode
->
pChildren
)
{
FOREACH
(
pChild
,
pNode
->
pChildren
)
{
doSetLogicNodeParent
((
SLogicNode
*
)
pChild
,
pNode
);
}
doSetLogicNodeParent
((
SLogicNode
*
)
pChild
,
pNode
);
}
}
}
static
void
setLogicNodeParent
(
SLogicNode
*
pNode
)
{
static
void
setLogicNodeParent
(
SLogicNode
*
pNode
)
{
doSetLogicNodeParent
(
pNode
,
NULL
);
}
doSetLogicNodeParent
(
pNode
,
NULL
);
}
int32_t
splitLogicPlan
(
SPlanContext
*
pCxt
,
SLogicNode
*
pLogicNode
,
SLogicSubplan
**
pLogicSubplan
)
{
int32_t
splitLogicPlan
(
SPlanContext
*
pCxt
,
SLogicNode
*
pLogicNode
,
SLogicSubplan
**
pLogicSubplan
)
{
SLogicSubplan
*
pSubplan
=
(
SLogicSubplan
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_SUBPLAN
);
SLogicSubplan
*
pSubplan
=
(
SLogicSubplan
*
)
nodesMakeNode
(
QUERY_NODE_LOGIC_SUBPLAN
);
...
@@ -408,7 +406,8 @@ int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan
...
@@ -408,7 +406,8 @@ int32_t splitLogicPlan(SPlanContext* pCxt, SLogicNode* pLogicNode, SLogicSubplan
}
}
if
(
QUERY_NODE_LOGIC_PLAN_VNODE_MODIF
==
nodeType
(
pLogicNode
))
{
if
(
QUERY_NODE_LOGIC_PLAN_VNODE_MODIF
==
nodeType
(
pLogicNode
))
{
pSubplan
->
subplanType
=
SUBPLAN_TYPE_MODIFY
;
pSubplan
->
subplanType
=
SUBPLAN_TYPE_MODIFY
;
TSWAP
(((
SVnodeModifLogicNode
*
)
pLogicNode
)
->
pDataBlocks
,
((
SVnodeModifLogicNode
*
)
pSubplan
->
pNode
)
->
pDataBlocks
,
SArray
*
);
TSWAP
(((
SVnodeModifLogicNode
*
)
pLogicNode
)
->
pDataBlocks
,
((
SVnodeModifLogicNode
*
)
pSubplan
->
pNode
)
->
pDataBlocks
,
SArray
*
);
}
else
{
}
else
{
pSubplan
->
subplanType
=
SUBPLAN_TYPE_SCAN
;
pSubplan
->
subplanType
=
SUBPLAN_TYPE_SCAN
;
}
}
...
...
source/libs/planner/src/planner.c
浏览文件 @
ac874f9e
此差异已折叠。
点击以展开。
source/libs/planner/test/planOptTest.cpp
浏览文件 @
ac874f9e
此差异已折叠。
点击以展开。
source/libs/planner/test/planSTableTest.cpp
0 → 100644
浏览文件 @
ac874f9e
此差异已折叠。
点击以展开。
source/libs/planner/test/planSetOpTest.cpp
浏览文件 @
ac874f9e
此差异已折叠。
点击以展开。
source/libs/planner/test/planStmtTest.cpp
浏览文件 @
ac874f9e
此差异已折叠。
点击以展开。
source/libs/planner/test/planTestMain.cpp
浏览文件 @
ac874f9e
此差异已折叠。
点击以展开。
source/libs/planner/test/planTestUtil.cpp
浏览文件 @
ac874f9e
此差异已折叠。
点击以展开。
source/libs/planner/test/planTestUtil.h
浏览文件 @
ac874f9e
此差异已折叠。
点击以展开。
source/libs/planner/test/plannerTest.cpp
浏览文件 @
ac874f9e
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录