Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a68e6345
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a68e6345
编写于
4月 26, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/3.0' into feature/dnode
上级
9f2d788d
b08ad78d
变更
52
展开全部
隐藏空白更改
内联
并排
Showing
52 changed file
with
2277 addition
and
2238 deletion
+2277
-2238
include/common/tmsg.h
include/common/tmsg.h
+10
-10
include/libs/nodes/querynodes.h
include/libs/nodes/querynodes.h
+124
-140
source/common/src/tmsg.c
source/common/src/tmsg.c
+2
-2
source/dnode/vnode/src/inc/tsdb.h
source/dnode/vnode/src/inc/tsdb.h
+0
-1
source/dnode/vnode/src/tq/tq.c
source/dnode/vnode/src/tq/tq.c
+3
-4
source/dnode/vnode/src/tq/tqRead.c
source/dnode/vnode/src/tq/tqRead.c
+22
-20
source/dnode/vnode/src/tsdb/tsdbSma.c
source/dnode/vnode/src/tsdb/tsdbSma.c
+18
-15
source/dnode/vnode/src/vnd/vnodeSvr.c
source/dnode/vnode/src/vnd/vnodeSvr.c
+1
-1
source/libs/function/src/builtins.c
source/libs/function/src/builtins.c
+466
-565
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
+28
-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
+69
-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/common/tmsg.h
浏览文件 @
a68e6345
...
...
@@ -230,12 +230,12 @@ typedef struct {
int32_t
totalLen
;
int32_t
len
;
// head of SSubmitBlk
//
int64_t uid; // table unique id
//
int64_t suid; // stable id
//
int32_t sversion; // data schema version
//
int32_t dataLen; // data part length, not including the SSubmitBlk head
//
int32_t schemaLen; // schema length, if length is 0, no schema exists
//
int16_t numOfRows; // total number of rows in current submit block
int64_t
uid
;
// table unique id
int64_t
suid
;
// stable id
int32_t
sversion
;
// data schema version
int32_t
dataLen
;
// data part length, not including the SSubmitBlk head
int32_t
schemaLen
;
// schema length, if length is 0, no schema exists
int16_t
numOfRows
;
// total number of rows in current submit block
// head of SSubmitBlk
const
void
*
pMsg
;
}
SSubmitMsgIter
;
...
...
@@ -249,10 +249,10 @@ STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
// 1) use tInitSubmitMsgIterEx firstly as not decrease the merge conflicts
// 2) replace tInitSubmitMsgIterEx with tInitSubmitMsgIter later
// 3) finally, rename tInitSubmitMsgIterEx to tInitSubmitMsgIter
//
int32_t tInitSubmitMsgIterEx(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
//
int32_t tGetSubmitMsgNextEx(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
//
int32_t tInitSubmitBlkIterEx(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
//
STSRow* tGetSubmitBlkNextEx(SSubmitBlkIter* pIter);
int32_t
tInitSubmitMsgIterEx
(
const
SSubmitReq
*
pMsg
,
SSubmitMsgIter
*
pIter
);
int32_t
tGetSubmitMsgNextEx
(
SSubmitMsgIter
*
pIter
,
SSubmitBlk
**
pPBlock
);
int32_t
tInitSubmitBlkIterEx
(
SSubmitMsgIter
*
pMsgIter
,
SSubmitBlk
*
pBlock
,
SSubmitBlkIter
*
pIter
);
STSRow
*
tGetSubmitBlkNextEx
(
SSubmitBlkIter
*
pIter
);
typedef
struct
{
int32_t
index
;
// index of failed block in submit blocks
...
...
include/libs/nodes/querynodes.h
浏览文件 @
a68e6345
...
...
@@ -25,14 +25,16 @@ extern "C" {
#include "tvariant.h"
#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 VGROUPS_INFO_SIZE(pInfo) (NULL == (pInfo) ? 0 : (sizeof(SVgroupsInfo) + (pInfo)->numOfVgroups * sizeof(SVgroupInfo)))
#define TABLE_META_SIZE(pMeta) \
(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
{
ENodeType
nodeType
;
char
*
p
;
uint32_t
n
;
SNode
*
pNode
;
char
*
p
;
uint32_t
n
;
SNode
*
pNode
;
}
SRawExprNode
;
typedef
struct
SDataType
{
...
...
@@ -45,170 +47,155 @@ typedef struct SDataType {
typedef
struct
SExprNode
{
ENodeType
type
;
SDataType
resType
;
char
aliasName
[
TSDB_COL_NAME_LEN
];
SArray
*
pAssociation
;
char
aliasName
[
TSDB_COL_NAME_LEN
];
SArray
*
pAssociation
;
}
SExprNode
;
typedef
enum
EColumnType
{
COLUMN_TYPE_COLUMN
=
1
,
COLUMN_TYPE_TAG
}
EColumnType
;
typedef
enum
EColumnType
{
COLUMN_TYPE_COLUMN
=
1
,
COLUMN_TYPE_TAG
}
EColumnType
;
typedef
struct
SColumnNode
{
SExprNode
node
;
// QUERY_NODE_COLUMN
uint64_t
tableId
;
int8_t
tableType
;
col_id_t
colId
;
EColumnType
colType
;
// column or tag
char
dbName
[
TSDB_DB_NAME_LEN
];
char
tableName
[
TSDB_TABLE_NAME_LEN
];
char
tableAlias
[
TSDB_TABLE_NAME_LEN
];
char
colName
[
TSDB_COL_NAME_LEN
];
SNode
*
pProjectRef
;
int16_t
dataBlockId
;
int16_t
slotId
;
SExprNode
node
;
// QUERY_NODE_COLUMN
uint64_t
tableId
;
int8_t
tableType
;
col_id_t
colId
;
EColumnType
colType
;
// column or tag
char
dbName
[
TSDB_DB_NAME_LEN
];
char
tableName
[
TSDB_TABLE_NAME_LEN
];
char
tableAlias
[
TSDB_TABLE_NAME_LEN
];
char
colName
[
TSDB_COL_NAME_LEN
];
SNode
*
pProjectRef
;
int16_t
dataBlockId
;
int16_t
slotId
;
}
SColumnNode
;
typedef
struct
STargetNode
{
ENodeType
type
;
int16_t
dataBlockId
;
int16_t
slotId
;
SNode
*
pExpr
;
int16_t
dataBlockId
;
int16_t
slotId
;
SNode
*
pExpr
;
}
STargetNode
;
typedef
struct
SValueNode
{
SExprNode
node
;
// QUERY_NODE_VALUE
char
*
literal
;
bool
isDuration
;
bool
translate
;
int16_t
placeholderNo
;
SExprNode
node
;
// QUERY_NODE_VALUE
char
*
literal
;
bool
isDuration
;
bool
translate
;
int16_t
placeholderNo
;
union
{
bool
b
;
int64_t
i
;
bool
b
;
int64_t
i
;
uint64_t
u
;
double
d
;
char
*
p
;
double
d
;
char
*
p
;
}
datum
;
char
unit
;
}
SValueNode
;
typedef
struct
SOperatorNode
{
SExprNode
node
;
// QUERY_NODE_OPERATOR
SExprNode
node
;
// QUERY_NODE_OPERATOR
EOperatorType
opType
;
SNode
*
pLeft
;
SNode
*
pRight
;
SNode
*
pLeft
;
SNode
*
pRight
;
}
SOperatorNode
;
typedef
struct
SLogicConditionNode
{
SExprNode
node
;
// QUERY_NODE_LOGIC_CONDITION
SExprNode
node
;
// QUERY_NODE_LOGIC_CONDITION
ELogicConditionType
condType
;
SNodeList
*
pParameterList
;
SNodeList
*
pParameterList
;
}
SLogicConditionNode
;
typedef
struct
SNodeListNode
{
ENodeType
type
;
// QUERY_NODE_NODE_LIST
SDataType
dataType
;
ENodeType
type
;
// QUERY_NODE_NODE_LIST
SDataType
dataType
;
SNodeList
*
pNodeList
;
}
SNodeListNode
;
typedef
struct
SFunctionNode
{
SExprNode
node
;
// QUERY_NODE_FUNCTION
char
functionName
[
TSDB_FUNC_NAME_LEN
];
int32_t
funcId
;
int32_t
funcType
;
SExprNode
node
;
// QUERY_NODE_FUNCTION
char
functionName
[
TSDB_FUNC_NAME_LEN
];
int32_t
funcId
;
int32_t
funcType
;
SNodeList
*
pParameterList
;
int32_t
udfBufSize
;
int32_t
udfBufSize
;
}
SFunctionNode
;
typedef
struct
STableNode
{
SExprNode
node
;
char
dbName
[
TSDB_DB_NAME_LEN
];
char
tableName
[
TSDB_TABLE_NAME_LEN
];
char
tableAlias
[
TSDB_TABLE_NAME_LEN
];
uint8_t
precision
;
char
dbName
[
TSDB_DB_NAME_LEN
];
char
tableName
[
TSDB_TABLE_NAME_LEN
];
char
tableAlias
[
TSDB_TABLE_NAME_LEN
];
uint8_t
precision
;
}
STableNode
;
struct
STableMeta
;
typedef
struct
SRealTableNode
{
STableNode
table
;
// QUERY_NODE_REAL_TABLE
STableNode
table
;
// QUERY_NODE_REAL_TABLE
struct
STableMeta
*
pMeta
;
SVgroupsInfo
*
pVgroupList
;
char
qualDbName
[
TSDB_DB_NAME_LEN
];
// SHOW qualDbName.TABLES
double
ratio
;
SVgroupsInfo
*
pVgroupList
;
char
qualDbName
[
TSDB_DB_NAME_LEN
];
// SHOW qualDbName.TABLES
double
ratio
;
}
SRealTableNode
;
typedef
struct
STempTableNode
{
STableNode
table
;
// QUERY_NODE_TEMP_TABLE
SNode
*
pSubquery
;
STableNode
table
;
// QUERY_NODE_TEMP_TABLE
SNode
*
pSubquery
;
}
STempTableNode
;
typedef
enum
EJoinType
{
JOIN_TYPE_INNER
=
1
}
EJoinType
;
typedef
enum
EJoinType
{
JOIN_TYPE_INNER
=
1
}
EJoinType
;
typedef
struct
SJoinTableNode
{
STableNode
table
;
// QUERY_NODE_JOIN_TABLE
EJoinType
joinType
;
SNode
*
pLeft
;
SNode
*
pRight
;
SNode
*
pOnCond
;
STableNode
table
;
// QUERY_NODE_JOIN_TABLE
EJoinType
joinType
;
SNode
*
pLeft
;
SNode
*
pRight
;
SNode
*
pOnCond
;
}
SJoinTableNode
;
typedef
enum
EGroupingSetType
{
GP_TYPE_NORMAL
=
1
}
EGroupingSetType
;
typedef
enum
EGroupingSetType
{
GP_TYPE_NORMAL
=
1
}
EGroupingSetType
;
typedef
struct
SGroupingSetNode
{
ENodeType
type
;
// QUERY_NODE_GROUPING_SET
ENodeType
type
;
// QUERY_NODE_GROUPING_SET
EGroupingSetType
groupingSetType
;
SNodeList
*
pParameterList
;
SNodeList
*
pParameterList
;
}
SGroupingSetNode
;
typedef
enum
EOrder
{
ORDER_ASC
=
1
,
ORDER_DESC
}
EOrder
;
typedef
enum
EOrder
{
ORDER_ASC
=
1
,
ORDER_DESC
}
EOrder
;
typedef
enum
ENullOrder
{
NULL_ORDER_DEFAULT
=
1
,
NULL_ORDER_FIRST
,
NULL_ORDER_LAST
}
ENullOrder
;
typedef
enum
ENullOrder
{
NULL_ORDER_DEFAULT
=
1
,
NULL_ORDER_FIRST
,
NULL_ORDER_LAST
}
ENullOrder
;
typedef
struct
SOrderByExprNode
{
ENodeType
type
;
// QUERY_NODE_ORDER_BY_EXPR
SNode
*
pExpr
;
EOrder
order
;
ENodeType
type
;
// QUERY_NODE_ORDER_BY_EXPR
SNode
*
pExpr
;
EOrder
order
;
ENullOrder
nullOrder
;
}
SOrderByExprNode
;
typedef
struct
SLimitNode
{
ENodeType
type
;
// QUERY_NODE_LIMIT
int64_t
limit
;
int64_t
offset
;
ENodeType
type
;
// QUERY_NODE_LIMIT
int64_t
limit
;
int64_t
offset
;
}
SLimitNode
;
typedef
struct
SStateWindowNode
{
ENodeType
type
;
// QUERY_NODE_STATE_WINDOW
SNode
*
pCol
;
// timestamp primary key
SNode
*
pExpr
;
ENodeType
type
;
// QUERY_NODE_STATE_WINDOW
SNode
*
pCol
;
// timestamp primary key
SNode
*
pExpr
;
}
SStateWindowNode
;
typedef
struct
SSessionWindowNode
{
ENodeType
type
;
// QUERY_NODE_SESSION_WINDOW
SColumnNode
*
pCol
;
// timestamp primary key
SValueNode
*
pGap
;
// gap between two session window(in microseconds)
ENodeType
type
;
// QUERY_NODE_SESSION_WINDOW
SColumnNode
*
pCol
;
// timestamp primary key
SValueNode
*
pGap
;
// gap between two session window(in microseconds)
}
SSessionWindowNode
;
typedef
struct
SIntervalWindowNode
{
ENodeType
type
;
// QUERY_NODE_INTERVAL_WINDOW
SNode
*
pCol
;
// timestamp primary key
SNode
*
pInterval
;
// SValueNode
SNode
*
pOffset
;
// SValueNode
SNode
*
pSliding
;
// SValueNode
SNode
*
pFill
;
ENodeType
type
;
// QUERY_NODE_INTERVAL_WINDOW
SNode
*
pCol
;
// timestamp primary key
SNode
*
pInterval
;
// SValueNode
SNode
*
pOffset
;
// SValueNode
SNode
*
pSliding
;
// SValueNode
SNode
*
pFill
;
}
SIntervalWindowNode
;
typedef
enum
EFillMode
{
...
...
@@ -221,42 +208,40 @@ typedef enum EFillMode {
}
EFillMode
;
typedef
struct
SFillNode
{
ENodeType
type
;
// QUERY_NODE_FILL
ENodeType
type
;
// QUERY_NODE_FILL
EFillMode
mode
;
SNode
*
pValues
;
// SNodeListNode
SNode
*
pValues
;
// SNodeListNode
}
SFillNode
;
typedef
struct
SSelectStmt
{
ENodeType
type
;
// QUERY_NODE_SELECT_STMT
bool
isDistinct
;
SNodeList
*
pProjectionList
;
SNode
*
pFromTable
;
SNode
*
pWhere
;
SNodeList
*
pPartitionByList
;
SNode
*
pWindow
;
SNodeList
*
pGroupByList
;
// SGroupingSetNode
SNode
*
pHaving
;
SNodeList
*
pOrderByList
;
// SOrderByExprNode
ENodeType
type
;
// QUERY_NODE_SELECT_STMT
bool
isDistinct
;
SNodeList
*
pProjectionList
;
SNode
*
pFromTable
;
SNode
*
pWhere
;
SNodeList
*
pPartitionByList
;
SNode
*
pWindow
;
SNodeList
*
pGroupByList
;
// SGroupingSetNode
SNode
*
pHaving
;
SNodeList
*
pOrderByList
;
// SOrderByExprNode
SLimitNode
*
pLimit
;
SLimitNode
*
pSlimit
;
char
stmtName
[
TSDB_TABLE_NAME_LEN
];
uint8_t
precision
;
bool
isEmptyResult
;
char
stmtName
[
TSDB_TABLE_NAME_LEN
];
uint8_t
precision
;
bool
isEmptyResult
;
bool
hasAggFuncs
;
}
SSelectStmt
;
typedef
enum
ESetOperatorType
{
SET_OP_TYPE_UNION_ALL
=
1
,
SET_OP_TYPE_UNION
}
ESetOperatorType
;
typedef
enum
ESetOperatorType
{
SET_OP_TYPE_UNION_ALL
=
1
,
SET_OP_TYPE_UNION
}
ESetOperatorType
;
typedef
struct
SSetOperator
{
ENodeType
type
;
// QUERY_NODE_SET_OPERATOR
ENodeType
type
;
// QUERY_NODE_SET_OPERATOR
ESetOperatorType
opType
;
SNodeList
*
pProjectionList
;
SNode
*
pLeft
;
SNode
*
pRight
;
SNodeList
*
pOrderByList
;
// SOrderByExprNode
SNode
*
pLimit
;
SNodeList
*
pProjectionList
;
SNode
*
pLeft
;
SNode
*
pRight
;
SNodeList
*
pOrderByList
;
// SOrderByExprNode
SNode
*
pLimit
;
}
SSetOperator
;
typedef
enum
ESqlClause
{
...
...
@@ -271,7 +256,6 @@ typedef enum ESqlClause {
SQL_CLAUSE_ORDER_BY
}
ESqlClause
;
typedef
enum
{
PAYLOAD_TYPE_KV
=
0
,
PAYLOAD_TYPE_RAW
=
1
,
...
...
@@ -281,29 +265,29 @@ typedef struct SVgDataBlocks {
SVgroupInfo
vg
;
int32_t
numOfTables
;
// number of tables in current submit block
uint32_t
size
;
char
*
pData
;
// SMsgDesc + SSubmitReq + SSubmitBlk + ...
char
*
pData
;
// SMsgDesc + SSubmitReq + SSubmitBlk + ...
}
SVgDataBlocks
;
typedef
struct
SVnodeModifOpStmt
{
ENodeType
nodeType
;
ENodeType
sqlNodeType
;
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
uint32_t
insertType
;
// insert data from [file|sql statement| bound statement]
const
char
*
sql
;
// current sql statement position
ENodeType
nodeType
;
ENodeType
sqlNodeType
;
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
uint32_t
insertType
;
// insert data from [file|sql statement| bound statement]
const
char
*
sql
;
// current sql statement position
}
SVnodeModifOpStmt
;
typedef
struct
SExplainOptions
{
ENodeType
type
;
bool
verbose
;
double
ratio
;
bool
verbose
;
double
ratio
;
}
SExplainOptions
;
typedef
struct
SExplainStmt
{
ENodeType
type
;
bool
analyze
;
ENodeType
type
;
bool
analyze
;
SExplainOptions
*
pOptions
;
SNode
*
pQuery
;
SNode
*
pQuery
;
}
SExplainStmt
;
void
nodesWalkSelectStmt
(
SSelectStmt
*
pSelect
,
ESqlClause
clause
,
FNodeWalker
walker
,
void
*
pContext
);
...
...
@@ -324,10 +308,10 @@ bool nodesIsJsonOp(const SOperatorNode* pOp);
bool
nodesIsTimeorderQuery
(
const
SNode
*
pQuery
);
bool
nodesIsTimelineQuery
(
const
SNode
*
pQuery
);
void
*
nodesGetValueFromNode
(
SValueNode
*
pNode
);
char
*
nodesGetStrValueFromNode
(
SValueNode
*
pNode
);
char
*
getFillModeString
(
EFillMode
mode
);
void
valueNodeToVariant
(
const
SValueNode
*
pNode
,
SVariant
*
pVal
);
void
*
nodesGetValueFromNode
(
SValueNode
*
pNode
);
char
*
nodesGetStrValueFromNode
(
SValueNode
*
pNode
);
char
*
getFillModeString
(
EFillMode
mode
);
void
valueNodeToVariant
(
const
SValueNode
*
pNode
,
SVariant
*
pVal
);
#ifdef __cplusplus
}
...
...
source/common/src/tmsg.c
浏览文件 @
a68e6345
...
...
@@ -93,7 +93,7 @@ STSRow *tGetSubmitBlkNext(SSubmitBlkIter *pIter) {
return
row
;
}
}
#if 0
// TODO: KEEP one suite of iterator API finally.
// 1) use tInitSubmitMsgIterEx firstly as not decrease the merge conflicts
// 2) replace tInitSubmitMsgIterEx with tInitSubmitMsgIter later
...
...
@@ -173,7 +173,7 @@ STSRow *tGetSubmitBlkNextEx(SSubmitBlkIter *pIter) {
return
row
;
}
}
#endif
int32_t
tEncodeSEpSet
(
SCoder
*
pEncoder
,
const
SEpSet
*
pEp
)
{
if
(
tEncodeI8
(
pEncoder
,
pEp
->
inUse
)
<
0
)
return
-
1
;
if
(
tEncodeI8
(
pEncoder
,
pEp
->
numOfEps
)
<
0
)
return
-
1
;
...
...
source/dnode/vnode/src/inc/tsdb.h
浏览文件 @
a68e6345
...
...
@@ -56,7 +56,6 @@ int32_t tsdbInsertTSmaData(STsdb *pTsdb, int64_t indexUid, const char *msg);
int32_t
tsdbDropTSmaData
(
STsdb
*
pTsdb
,
int64_t
indexUid
);
int32_t
tsdbInsertRSmaData
(
STsdb
*
pTsdb
,
char
*
msg
);
void
tsdbCleanupReadHandle
(
tsdbReaderT
queryHandle
);
int32_t
tdScanAndConvertSubmitMsg
(
SSubmitReq
*
pMsg
);
typedef
enum
{
TSDB_FILE_HEAD
=
0
,
// .head
TSDB_FILE_DATA
,
// .data
...
...
source/dnode/vnode/src/tq/tq.c
浏览文件 @
a68e6345
...
...
@@ -197,10 +197,9 @@ int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver)
}
memcpy
(
data
,
msg
,
msgLen
);
if
(
msgType
==
TDMT_VND_SUBMIT
)
{
if
(
tsdbUpdateSmaWindow
(
pTq
->
pVnode
->
pTsdb
,
msg
,
ver
)
!=
0
)
{
return
-
1
;
}
// make sure msgType == TDMT_VND_SUBMIT
if
(
tsdbUpdateSmaWindow
(
pTq
->
pVnode
->
pTsdb
,
msg
,
ver
)
!=
0
)
{
return
-
1
;
}
SRpcMsg
req
=
{
...
...
source/dnode/vnode/src/tq/tqRead.c
浏览文件 @
a68e6345
...
...
@@ -33,24 +33,24 @@ STqReadHandle* tqInitSubmitMsgScanner(SMeta* pMeta) {
int32_t
tqReadHandleSetMsg
(
STqReadHandle
*
pReadHandle
,
SSubmitReq
*
pMsg
,
int64_t
ver
)
{
pReadHandle
->
pMsg
=
pMsg
;
pMsg
->
length
=
htonl
(
pMsg
->
length
);
pMsg
->
numOfBlocks
=
htonl
(
pMsg
->
numOfBlocks
);
//
pMsg->length = htonl(pMsg->length);
//
pMsg->numOfBlocks = htonl(pMsg->numOfBlocks);
// iterate and convert
if
(
tInitSubmitMsgIter
(
pMsg
,
&
pReadHandle
->
msgIter
)
<
0
)
return
-
1
;
if
(
tInitSubmitMsgIter
Ex
(
pMsg
,
&
pReadHandle
->
msgIter
)
<
0
)
return
-
1
;
while
(
true
)
{
if
(
tGetSubmitMsgNext
(
&
pReadHandle
->
msgIter
,
&
pReadHandle
->
pBlock
)
<
0
)
return
-
1
;
if
(
tGetSubmitMsgNext
Ex
(
&
pReadHandle
->
msgIter
,
&
pReadHandle
->
pBlock
)
<
0
)
return
-
1
;
if
(
pReadHandle
->
pBlock
==
NULL
)
break
;
pReadHandle
->
pBlock
->
uid
=
htobe64
(
pReadHandle
->
pBlock
->
uid
);
pReadHandle
->
pBlock
->
suid
=
htobe64
(
pReadHandle
->
pBlock
->
suid
);
pReadHandle
->
pBlock
->
sversion
=
htonl
(
pReadHandle
->
pBlock
->
sversion
);
pReadHandle
->
pBlock
->
dataLen
=
htonl
(
pReadHandle
->
pBlock
->
dataLen
);
pReadHandle
->
pBlock
->
schemaLen
=
htonl
(
pReadHandle
->
pBlock
->
schemaLen
);
pReadHandle
->
pBlock
->
numOfRows
=
htons
(
pReadHandle
->
pBlock
->
numOfRows
);
//
pReadHandle->pBlock->uid = htobe64(pReadHandle->pBlock->uid);
//
pReadHandle->pBlock->suid = htobe64(pReadHandle->pBlock->suid);
//
pReadHandle->pBlock->sversion = htonl(pReadHandle->pBlock->sversion);
//
pReadHandle->pBlock->dataLen = htonl(pReadHandle->pBlock->dataLen);
//
pReadHandle->pBlock->schemaLen = htonl(pReadHandle->pBlock->schemaLen);
//
pReadHandle->pBlock->numOfRows = htons(pReadHandle->pBlock->numOfRows);
}
if
(
tInitSubmitMsgIter
(
pMsg
,
&
pReadHandle
->
msgIter
)
<
0
)
return
-
1
;
if
(
tInitSubmitMsgIter
Ex
(
pMsg
,
&
pReadHandle
->
msgIter
)
<
0
)
return
-
1
;
pReadHandle
->
ver
=
ver
;
memset
(
&
pReadHandle
->
blkIter
,
0
,
sizeof
(
SSubmitBlkIter
));
return
0
;
...
...
@@ -58,7 +58,7 @@ int32_t tqReadHandleSetMsg(STqReadHandle* pReadHandle, SSubmitReq* pMsg, int64_t
bool
tqNextDataBlock
(
STqReadHandle
*
pHandle
)
{
while
(
1
)
{
if
(
tGetSubmitMsgNext
(
&
pHandle
->
msgIter
,
&
pHandle
->
pBlock
)
<
0
)
{
if
(
tGetSubmitMsgNext
Ex
(
&
pHandle
->
msgIter
,
&
pHandle
->
pBlock
)
<
0
)
{
return
false
;
}
if
(
pHandle
->
pBlock
==
NULL
)
return
false
;
...
...
@@ -68,7 +68,7 @@ bool tqNextDataBlock(STqReadHandle* pHandle) {
if
(
pHandle
->
tbIdHash
==
NULL
)
{
return
true
;
}
void
*
ret
=
taosHashGet
(
pHandle
->
tbIdHash
,
&
pHandle
->
pBlock
->
uid
,
sizeof
(
int64_t
));
void
*
ret
=
taosHashGet
(
pHandle
->
tbIdHash
,
&
pHandle
->
msgIter
.
uid
,
sizeof
(
int64_t
));
if
(
ret
!=
NULL
)
{
/*printf("retrieve one tb %ld\n", pHandle->pBlock->uid);*/
/*pHandle->pBlock->tid = htonl(pHandle->pBlock->tid);*/
...
...
@@ -90,23 +90,25 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
// TODO set to real sversion
int32_t
sversion
=
0
;
if
(
pHandle
->
sver
!=
sversion
)
{
pHandle
->
pSchema
=
metaGetTbTSchema
(
pHandle
->
pVnodeMeta
,
pHandle
->
pBlock
->
uid
,
sversion
);
pHandle
->
pSchema
=
metaGetTbTSchema
(
pHandle
->
pVnodeMeta
,
pHandle
->
msgIter
.
uid
,
sversion
);
#if 0
tb_uid_t quid;
STbCfg
*
pTbCfg
=
metaGetTbInfoByUid
(
pHandle
->
pVnodeMeta
,
pHandle
->
pBlock
->
uid
);
STbCfg* pTbCfg = metaGetTbInfoByUid(pHandle->pVnodeMeta, pHandle->
msgIter.
uid);
if (pTbCfg->type == META_CHILD_TABLE) {
quid = pTbCfg->ctbCfg.suid;
} else {
quid
=
pHandle
->
pBlock
->
uid
;
quid = pHandle->
msgIter.
uid;
}
pHandle->pSchemaWrapper = metaGetTableSchema(pHandle->pVnodeMeta, quid, sversion, true);
#endif
pHandle
->
pSchemaWrapper
=
metaGetTableSchema
(
pHandle
->
pVnodeMeta
,
pHandle
->
msgIter
.
suid
,
sversion
,
true
);
pHandle
->
sver
=
sversion
;
}
STSchema
*
pTschema
=
pHandle
->
pSchema
;
SSchemaWrapper
*
pSchemaWrapper
=
pHandle
->
pSchemaWrapper
;
*
pNumOfRows
=
pHandle
->
pBlock
->
numOfRows
;
*
pNumOfRows
=
pHandle
->
msgIter
.
numOfRows
;
int32_t
colNumNeed
=
taosArrayGetSize
(
pHandle
->
pColIdList
);
if
(
colNumNeed
==
0
)
{
...
...
@@ -175,8 +177,8 @@ int32_t tqRetrieveDataBlock(SArray** ppCols, STqReadHandle* pHandle, uint64_t* p
tdSTSRowIterInit
(
&
iter
,
pTschema
);
STSRow
*
row
;
int32_t
curRow
=
0
;
tInitSubmitBlkIter
(
pHandle
->
pBlock
,
&
pHandle
->
blkIter
);
while
((
row
=
tGetSubmitBlkNext
(
&
pHandle
->
blkIter
))
!=
NULL
)
{
tInitSubmitBlkIter
Ex
(
&
pHandle
->
msgIter
,
pHandle
->
pBlock
,
&
pHandle
->
blkIter
);
while
((
row
=
tGetSubmitBlkNext
Ex
(
&
pHandle
->
blkIter
))
!=
NULL
)
{
tdSTSRowIterReset
(
&
iter
,
row
);
// get all wanted col of that block
for
(
int32_t
i
=
0
;
i
<
colActual
;
i
++
)
{
...
...
source/dnode/vnode/src/tsdb/tsdbSma.c
浏览文件 @
a68e6345
...
...
@@ -678,9 +678,6 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
return
TSDB_CODE_FAILED
;
}
if
(
tdScanAndConvertSubmitMsg
(
pMsg
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_FAILED
;
}
if
(
tsdbCheckAndInitSmaEnv
(
pTsdb
,
TSDB_SMA_TYPE_TIME_RANGE
)
!=
TSDB_CODE_SUCCESS
)
{
terrno
=
TSDB_CODE_TDB_INIT_FAILED
;
...
...
@@ -705,25 +702,25 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
SInterval
interval
=
{
0
};
TSKEY
lastWinSKey
=
INT64_MIN
;
if
(
tInitSubmitMsgIter
(
pMsg
,
&
msgIter
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tInitSubmitMsgIter
Ex
(
pMsg
,
&
msgIter
)
!=
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_FAILED
;
}
while
(
true
)
{
tGetSubmitMsgNext
(
&
msgIter
,
&
pBlock
);
tGetSubmitMsgNext
Ex
(
&
msgIter
,
&
pBlock
);
if
(
!
pBlock
)
break
;
STSmaWrapper
*
pSW
=
NULL
;
STSma
*
pTSma
=
NULL
;
SSubmitBlkIter
blkIter
=
{
0
};
if
(
tInitSubmitBlkIter
(
pBlock
,
&
blkIter
)
!=
TSDB_CODE_SUCCESS
)
{
if
(
tInitSubmitBlkIter
Ex
(
&
msgIter
,
pBlock
,
&
blkIter
)
!=
TSDB_CODE_SUCCESS
)
{
pSW
=
tdFreeTSmaWrapper
(
pSW
);
break
;
}
while
(
true
)
{
STSRow
*
row
=
tGetSubmitBlkNext
(
&
blkIter
);
STSRow
*
row
=
tGetSubmitBlkNext
Ex
(
&
blkIter
);
if
(
!
row
)
{
tdFreeTSmaWrapper
(
pSW
);
break
;
...
...
@@ -1764,7 +1761,7 @@ int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateTbReq *pReq) {
TSDB_CODE_SUCCESS
)
{
return
TSDB_CODE_FAILED
;
}
else
{
tsdbDebug
(
"vgId:%d register rsma info succeed for suid:%"
PRIi64
,
REPO_ID
(
pTsdb
),
pReq
->
stbCfg
.
suid
);
tsdbDebug
(
"vgId:%d register rsma info succeed for suid:%"
PRIi64
,
REPO_ID
(
pTsdb
),
pReq
->
stbCfg
.
suid
);
}
return
TSDB_CODE_SUCCESS
;
...
...
@@ -1791,7 +1788,7 @@ int32_t tsdbUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid) {
return
TSDB_CODE_FAILED
;
}
}
if
(
!
taosArrayPush
(
pStore
->
tbUids
,
&
uid
))
{
if
(
!
taosArrayPush
(
pStore
->
tbUids
,
uid
))
{
return
TSDB_CODE_FAILED
;
}
}
...
...
@@ -1806,14 +1803,14 @@ int32_t tsdbUidStorePut(STbUidStore *pStore, tb_uid_t suid, tb_uid_t *uid) {
if
(
uid
)
{
SArray
*
uidArray
=
taosHashGet
(
pStore
->
uidHash
,
&
suid
,
sizeof
(
tb_uid_t
));
if
(
uidArray
&&
((
uidArray
=
*
(
SArray
**
)
uidArray
)))
{
taosArrayPush
(
uidArray
,
&
uid
);
taosArrayPush
(
uidArray
,
uid
);
}
else
{
SArray
*
pUidArray
=
taosArrayInit
(
1
,
sizeof
(
tb_uid_t
));
if
(
!
pUidArray
)
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
}
if
(
!
taosArrayPush
(
pUidArray
,
&
uid
))
{
if
(
!
taosArrayPush
(
pUidArray
,
uid
))
{
terrno
=
TSDB_CODE_OUT_OF_MEMORY
;
return
TSDB_CODE_FAILED
;
}
...
...
@@ -1975,12 +1972,12 @@ static int32_t tsdbFetchSubmitReqSuids(SSubmitReq *pMsg, STbUidStore *pStore) {
// pMsg->length = htonl(pMsg->length);
// pMsg->numOfBlocks = htonl(pMsg->numOfBlocks);
if
(
tInitSubmitMsgIter
(
pMsg
,
&
msgIter
)
<
0
)
return
-
1
;
if
(
tInitSubmitMsgIter
Ex
(
pMsg
,
&
msgIter
)
<
0
)
return
-
1
;
while
(
true
)
{
if
(
tGetSubmitMsgNext
(
&
msgIter
,
&
pBlock
)
<
0
)
return
-
1
;
if
(
tGetSubmitMsgNext
Ex
(
&
msgIter
,
&
pBlock
)
<
0
)
return
-
1
;
if
(
!
pBlock
)
break
;
tsdbUidStorePut
(
pStore
,
pBlock
->
suid
,
NULL
);
tsdbUidStorePut
(
pStore
,
msgIter
.
suid
,
NULL
);
}
if
(
terrno
!=
TSDB_CODE_SUCCESS
)
return
-
1
;
...
...
@@ -2014,6 +2011,8 @@ int32_t tsdbExecuteRSma(STsdb *pTsdb, SMeta *pMeta, const void *pMsg, int32_t in
if
(
inputType
==
STREAM_DATA_TYPE_SUBMIT_BLOCK
)
{
if
(
pRSmaInfo
->
taskInfo
[
0
])
{
tsdbDebug
(
"vgId:%d execute rsma task for qTaskInfo:%p suid:%"
PRIu64
,
REPO_ID
(
pTsdb
),
pRSmaInfo
->
taskInfo
[
0
],
*
suid
);
qSetStreamInput
(
pRSmaInfo
->
taskInfo
[
0
],
pMsg
,
inputType
);
while
(
1
)
{
SSDataBlock
*
output
;
...
...
@@ -2026,7 +2025,11 @@ int32_t tsdbExecuteRSma(STsdb *pTsdb, SMeta *pMeta, const void *pMsg, int32_t in
}
taosArrayPush
(
pResult
,
output
);
}
blockDebugShowData
(
pResult
);
if
(
taosArrayGetSize
(
pResult
)
>
0
)
{
blockDebugShowData
(
pResult
);
}
else
{
tsdbWarn
(
"vgId:%d no sma data generated since %s"
,
REPO_ID
(
pTsdb
),
tstrerror
(
terrno
));
}
}
// if (pRSmaInfo->taskInfo[1]) {
...
...
source/dnode/vnode/src/vnd/vnodeSvr.c
浏览文件 @
a68e6345
...
...
@@ -81,9 +81,9 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, int64_t version, SRpcMsg
case
TDMT_VND_DROP_TABLE
:
break
;
case
TDMT_VND_SUBMIT
:
tsdbTriggerRSma
(
pVnode
->
pTsdb
,
pVnode
->
pMeta
,
ptr
,
STREAM_DATA_TYPE_SUBMIT_BLOCK
);
pRsp
->
msgType
=
TDMT_VND_SUBMIT_RSP
;
vnodeProcessSubmitReq
(
pVnode
,
ptr
,
pRsp
);
tsdbTriggerRSma
(
pVnode
->
pTsdb
,
pVnode
->
pMeta
,
ptr
,
STREAM_DATA_TYPE_SUBMIT_BLOCK
);
break
;
case
TDMT_VND_MQ_VG_CHANGE
:
if
(
tqProcessVgChangeReq
(
pVnode
->
pTq
,
POINTER_SHIFT
(
pMsg
->
pCont
,
sizeof
(
SMsgHead
)),
...
...
source/libs/function/src/builtins.c
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/nodes/inc/nodesUtil.h
浏览文件 @
a68e6345
...
...
@@ -20,17 +20,39 @@
extern
"C"
{
#endif
#define nodesFatal(...)
qFatal("NODES: " __VA_ARGS__)
#define nodesError(...)
qError("NODES: " __VA_ARGS__)
#define nodesWarn(...)
qWarn("NODES: " __VA_ARGS__)
#define nodesInfo(...)
qInfo("NODES: " __VA_ARGS__)
#define nodesDebug(...)
qDebug("NODES: " __VA_ARGS__)
#define nodesTrace(...)
qTrace("NODES: " __VA_ARGS__)
#define nodesFatal(...) qFatal("NODES: " __VA_ARGS__)
#define nodesError(...) qError("NODES: " __VA_ARGS__)
#define nodesWarn(...) qWarn("NODES: " __VA_ARGS__)
#define nodesInfo(...) qInfo("NODES: " __VA_ARGS__)
#define nodesDebug(...) qDebug("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_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)
#define NODES_ERR_RET(c) \
do { \
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
}
...
...
source/libs/nodes/src/nodesCloneFuncs.c
浏览文件 @
a68e6345
...
...
@@ -19,71 +19,71 @@
#include "taos.h"
#include "taoserror.h"
#define COPY_ALL_SCALAR_FIELDS \
do {
\
#define COPY_ALL_SCALAR_FIELDS
\
do {
\
memcpy((pDst), (pSrc), sizeof(*pSrc)); \
} while (0)
} while (0)
#define COPY_SCALAR_FIELD(fldname) \
do {
\
#define COPY_SCALAR_FIELD(fldname)
\
do {
\
(pDst)->fldname = (pSrc)->fldname; \
} while (0)
} while (0)
#define COPY_CHAR_ARRAY_FIELD(fldname) \
do {
\
#define COPY_CHAR_ARRAY_FIELD(fldname)
\
do {
\
strcpy((pDst)->fldname, (pSrc)->fldname); \
} while (0)
} while (0)
#define COPY_CHAR_POINT_FIELD(fldname) \
do {
\
if (NULL == (pSrc)->fldname) { \
break; \
} \
#define COPY_CHAR_POINT_FIELD(fldname)
\
do {
\
if (NULL == (pSrc)->fldname) {
\
break;
\
}
\
(pDst)->fldname = strdup((pSrc)->fldname); \
} while (0)
} while (0)
#define CLONE_NODE_FIELD(fldname) \
do {
\
if (NULL == (pSrc)->fldname) { \
break; \
} \
#define CLONE_NODE_FIELD(fldname)
\
do {
\
if (NULL == (pSrc)->fldname) {
\
break;
\
}
\
(pDst)->fldname = nodesCloneNode((pSrc)->fldname); \
if (NULL == (pDst)->fldname) { \
nodesDestroyNode((SNode*)(pDst)); \
return NULL; \
} \
} while (0)
#define CLONE_NODE_LIST_FIELD(fldname) \
do {
\
if (NULL == (pSrc)->fldname) { \
break; \
} \
if (NULL == (pDst)->fldname) {
\
nodesDestroyNode((SNode*)(pDst));
\
return NULL;
\
}
\
} while (0)
#define CLONE_NODE_LIST_FIELD(fldname)
\
do {
\
if (NULL == (pSrc)->fldname) {
\
break;
\
}
\
(pDst)->fldname = nodesCloneList((pSrc)->fldname); \
if (NULL == (pDst)->fldname) { \
nodesDestroyNode((SNode*)(pDst)); \
return NULL; \
} \
} while (0)
#define CLONE_OBJECT_FIELD(fldname, cloneFunc) \
do {
\
if (NULL == (pSrc)->fldname) { \
break; \
} \
if (NULL == (pDst)->fldname) {
\
nodesDestroyNode((SNode*)(pDst));
\
return NULL;
\
}
\
} while (0)
#define CLONE_OBJECT_FIELD(fldname, cloneFunc)
\
do {
\
if (NULL == (pSrc)->fldname) {
\
break;
\
}
\
(pDst)->fldname = cloneFunc((pSrc)->fldname); \
if (NULL == (pDst)->fldname) { \
nodesDestroyNode((SNode*)(pDst)); \
return NULL; \
} \
} while (0)
#define COPY_BASE_OBJECT_FIELD(fldname, copyFunc) \
do {
\
if (NULL == (pDst)->fldname) {
\
nodesDestroyNode((SNode*)(pDst));
\
return NULL;
\
}
\
} while (0)
#define COPY_BASE_OBJECT_FIELD(fldname, copyFunc)
\
do {
\
if (NULL == copyFunc(&((pSrc)->fldname), &((pDst)->fldname))) { \
return NULL; \
} \
} while (0)
return NULL;
\
}
\
} while (0)
static
void
dataTypeCopy
(
const
SDataType
*
pSrc
,
SDataType
*
pDst
)
{
COPY_SCALAR_FIELD
(
type
);
...
...
@@ -201,7 +201,7 @@ static SNode* logicNodeCopy(const SLogicNode* pSrc, SLogicNode* pDst) {
}
static
STableMeta
*
tableMetaClone
(
const
STableMeta
*
pSrc
)
{
int32_t
len
=
TABLE_META_SIZE
(
pSrc
);
int32_t
len
=
TABLE_META_SIZE
(
pSrc
);
STableMeta
*
pDst
=
taosMemoryMalloc
(
len
);
if
(
NULL
==
pDst
)
{
return
NULL
;
...
...
@@ -211,7 +211,7 @@ static STableMeta* tableMetaClone(const STableMeta* 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
);
if
(
NULL
==
pDst
)
{
return
NULL
;
...
...
source/libs/nodes/src/nodesCodeFuncs.c
浏览文件 @
a68e6345
...
...
@@ -16,8 +16,8 @@
#include "cmdnodes.h"
#include "nodesUtil.h"
#include "plannodes.h"
#include "querynodes.h"
#include "query.h"
#include "querynodes.h"
#include "taoserror.h"
#include "tjson.h"
...
...
@@ -29,7 +29,7 @@ static int32_t makeNodeByJson(const SJson* pJson, SNode** pNode);
const
char
*
nodesNodeName
(
ENodeType
type
)
{
switch
(
type
)
{
case
QUERY_NODE_COLUMN
:
return
"Column"
;
return
"Column"
;
case
QUERY_NODE_VALUE
:
return
"Value"
;
case
QUERY_NODE_OPERATOR
:
...
...
@@ -306,7 +306,7 @@ static int32_t tableComInfoToJson(const void* pObj, SJson* pJson) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddIntegerToObject
(
pJson
,
jkTableComInfoRowSize
,
pNode
->
rowSize
);
}
return
code
;
}
...
...
@@ -323,7 +323,7 @@ static int32_t jsonToTableComInfo(const SJson* pJson, void* pObj) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetNumberValue
(
pJson
,
jkTableComInfoRowSize
,
pNode
->
rowSize
);
}
return
code
;
}
...
...
@@ -345,7 +345,7 @@ static int32_t schemaToJson(const void* pObj, SJson* pJson) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddStringToObject
(
pJson
,
jkSchemaName
,
pNode
->
name
);
}
return
code
;
}
...
...
@@ -362,7 +362,7 @@ static int32_t jsonToSchema(const SJson* pJson, void* pObj) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetStringValue
(
pJson
,
jkSchemaName
,
pNode
->
name
);
}
return
code
;
}
...
...
@@ -398,7 +398,8 @@ static int32_t tableMetaToJson(const void* pObj, SJson* pJson) {
code
=
tjsonAddObject
(
pJson
,
jkTableMetaComInfo
,
tableComInfoToJson
,
&
pNode
->
tableInfo
);
}
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
;
...
...
@@ -713,13 +714,9 @@ static int32_t jsonToPhysiScanNode(const SJson* pJson, void* pObj) {
return
code
;
}
static
int32_t
physiTagScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
return
physiScanNodeToJson
(
pObj
,
pJson
);
}
static
int32_t
physiTagScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
return
physiScanNodeToJson
(
pObj
,
pJson
);
}
static
int32_t
jsonToPhysiTagScanNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
return
jsonToPhysiScanNode
(
pJson
,
pObj
);
}
static
int32_t
jsonToPhysiTagScanNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
return
jsonToPhysiScanNode
(
pJson
,
pObj
);
}
static
const
char
*
jkTableScanPhysiPlanScanCount
=
"ScanCount"
;
static
const
char
*
jkTableScanPhysiPlanReverseScanCount
=
"ReverseScanCount"
;
...
...
@@ -732,7 +729,7 @@ static const char* jkTableScanPhysiPlanInterval = "Interval";
static
const
char
*
jkTableScanPhysiPlanOffset
=
"Offset"
;
static
const
char
*
jkTableScanPhysiPlanSliding
=
"Sliding"
;
static
const
char
*
jkTableScanPhysiPlanIntervalUnit
=
"intervalUnit"
;
static
const
char
*
jkTableScanPhysiPlanSlidingUnit
=
"slidingUnit"
;
static
const
char
*
jkTableScanPhysiPlanSlidingUnit
=
"slidingUnit"
;
static
int32_t
physiTableScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
STableScanPhysiNode
*
pNode
=
(
const
STableScanPhysiNode
*
)
pObj
;
...
...
@@ -822,13 +819,9 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
return
code
;
}
static
int32_t
physiStreamScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
return
physiScanNodeToJson
(
pObj
,
pJson
);
}
static
int32_t
physiStreamScanNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
return
physiScanNodeToJson
(
pObj
,
pJson
);
}
static
int32_t
jsonToPhysiStreamScanNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
return
jsonToPhysiScanNode
(
pJson
,
pObj
);
}
static
int32_t
jsonToPhysiStreamScanNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
return
jsonToPhysiScanNode
(
pJson
,
pObj
);
}
static
const
char
*
jkEndPointFqdn
=
"Fqdn"
;
static
const
char
*
jkEndPointPort
=
"Port"
;
...
...
@@ -1178,7 +1171,7 @@ static const char* jkIntervalPhysiPlanInterval = "Interval";
static
const
char
*
jkIntervalPhysiPlanOffset
=
"Offset"
;
static
const
char
*
jkIntervalPhysiPlanSliding
=
"Sliding"
;
static
const
char
*
jkIntervalPhysiPlanIntervalUnit
=
"intervalUnit"
;
static
const
char
*
jkIntervalPhysiPlanSlidingUnit
=
"slidingUnit"
;
static
const
char
*
jkIntervalPhysiPlanSlidingUnit
=
"slidingUnit"
;
static
const
char
*
jkIntervalPhysiPlanFill
=
"Fill"
;
static
int32_t
physiIntervalNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
...
...
@@ -1331,13 +1324,9 @@ static int32_t jsonToPhysicDataSinkNode(const SJson* pJson, void* pObj) {
return
jsonToNodeObject
(
pJson
,
jkDataSinkInputDataBlockDesc
,
(
SNode
**
)
&
pNode
->
pInputDataBlockDesc
);
}
static
int32_t
physiDispatchNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
return
physicDataSinkNodeToJson
(
pObj
,
pJson
);
}
static
int32_t
physiDispatchNodeToJson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
return
physicDataSinkNodeToJson
(
pObj
,
pJson
);
}
static
int32_t
jsonToPhysiDispatchNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
return
jsonToPhysicDataSinkNode
(
pJson
,
pObj
);
}
static
int32_t
jsonToPhysiDispatchNode
(
const
SJson
*
pJson
,
void
*
pObj
)
{
return
jsonToPhysicDataSinkNode
(
pJson
,
pObj
);
}
static
const
char
*
jkSubplanIdQueryId
=
"QueryId"
;
static
const
char
*
jkSubplanIdGroupId
=
"GroupId"
;
...
...
@@ -1709,7 +1698,7 @@ static int32_t datumToJson(const void* pObj, SJson* pJson) {
break
;
}
return
code
;
return
code
;
}
static
int32_t
valueNodeToJson
(
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
);
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
;
...
...
@@ -2381,6 +2371,7 @@ static const char* jkSelectStmtOrderBy = "OrderBy";
static
const
char
*
jkSelectStmtLimit
=
"Limit"
;
static
const
char
*
jkSelectStmtSlimit
=
"Slimit"
;
static
const
char
*
jkSelectStmtStmtName
=
"StmtName"
;
static
const
char
*
jkSelectStmtHasAggFuncs
=
"HasAggFuncs"
;
static
int32_t
selectStmtTojson
(
const
void
*
pObj
,
SJson
*
pJson
)
{
const
SSelectStmt
*
pNode
=
(
const
SSelectStmt
*
)
pObj
;
...
...
@@ -2419,6 +2410,9 @@ static int32_t selectStmtTojson(const void* pObj, SJson* pJson) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddStringToObject
(
pJson
,
jkSelectStmtStmtName
,
pNode
->
stmtName
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonAddBoolToObject
(
pJson
,
jkSelectStmtHasAggFuncs
,
pNode
->
hasAggFuncs
);
}
return
code
;
}
...
...
@@ -2460,6 +2454,9 @@ static int32_t jsonToSelectStmt(const SJson* pJson, void* pObj) {
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetStringValue
(
pJson
,
jkSelectStmtStmtName
,
pNode
->
stmtName
);
}
if
(
TSDB_CODE_SUCCESS
==
code
)
{
code
=
tjsonGetBoolValue
(
pJson
,
jkSelectStmtHasAggFuncs
,
&
pNode
->
hasAggFuncs
);
}
return
code
;
}
...
...
@@ -2660,10 +2657,10 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
return
jsonToPhysiTagScanNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN
:
return
jsonToPhysiTableScanNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
:
case
QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN
:
return
jsonToPhysiStreamScanNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_SYSTABLE_SCAN
:
return
jsonToPhysiSysTableScanNode
(
pJson
,
pObj
);
return
jsonToPhysiSysTableScanNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_PROJECT
:
return
jsonToPhysiProjectNode
(
pJson
,
pObj
);
case
QUERY_NODE_PHYSICAL_PLAN_JOIN
:
...
...
source/libs/nodes/src/nodesEqualFuncs.c
浏览文件 @
a68e6345
...
...
@@ -15,32 +15,27 @@
#include "querynodes.h"
#define COMPARE_SCALAR_FIELD(fldname) \
do { \
if (a->fldname != b->fldname) \
return false; \
} while (0)
#define COMPARE_STRING(a, b) \
(((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
#define COMPARE_STRING_FIELD(fldname) \
do { \
if (!COMPARE_STRING(a->fldname, b->fldname)) \
return false; \
} while (0)
#define COMPARE_NODE_FIELD(fldname) \
do { \
if (!nodesEqualNode(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)
#define COMPARE_SCALAR_FIELD(fldname) \
do { \
if (a->fldname != b->fldname) return false; \
} while (0)
#define COMPARE_STRING(a, b) (((a) != NULL && (b) != NULL) ? (strcmp(a, b) == 0) : (a) == (b))
#define COMPARE_STRING_FIELD(fldname) \
do { \
if (!COMPARE_STRING(a->fldname, b->fldname)) return false; \
} while (0)
#define COMPARE_NODE_FIELD(fldname) \
do { \
if (!nodesEqualNode(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
)
{
if
(
a
==
b
)
{
...
...
@@ -55,7 +50,7 @@ static bool nodeNodeListEqual(const SNodeList* a, const SNodeList* b) {
return
false
;
}
SNode
*
na
,
*
nb
;
SNode
*
na
,
*
nb
;
FORBOTH
(
na
,
a
,
nb
,
b
)
{
if
(
!
nodesEqualNode
(
na
,
nb
))
{
return
false
;
...
...
@@ -125,7 +120,7 @@ bool nodesEqualNode(const SNodeptr a, const SNodeptr b) {
case
QUERY_NODE_GROUPING_SET
:
case
QUERY_NODE_ORDER_BY_EXPR
:
case
QUERY_NODE_LIMIT
:
return
false
;
// todo
return
false
;
// todo
default:
break
;
}
...
...
source/libs/nodes/src/nodesToSQLFuncs.c
浏览文件 @
a68e6345
...
...
@@ -21,9 +21,35 @@
#include "taoserror.h"
#include "thash.h"
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"
};
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"
};
char
*
gLogicConditionStr
[]
=
{
"AND"
,
"OR"
,
"NOT"
};
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
])
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"`%s`."
,
colNode
->
dbName
);
}
if
(
colNode
->
tableAlias
[
0
])
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"`%s`."
,
colNode
->
tableAlias
);
}
else
if
(
colNode
->
tableName
[
0
])
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"`%s`."
,
colNode
->
tableName
);
}
if
(
colNode
->
tableAlias
[
0
])
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"`%s`"
,
colNode
->
colName
);
}
else
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"%s"
,
colNode
->
colName
);
}
return
TSDB_CODE_SUCCESS
;
}
case
QUERY_NODE_VALUE
:{
case
QUERY_NODE_VALUE
:
{
SValueNode
*
colNode
=
(
SValueNode
*
)
pNode
;
char
*
t
=
nodesGetStrValueFromNode
(
colNode
);
char
*
t
=
nodesGetStrValueFromNode
(
colNode
);
if
(
NULL
==
t
)
{
nodesError
(
"fail to get str value from valueNode"
);
NODES_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"%s"
,
t
);
taosMemoryFree
(
t
);
return
TSDB_CODE_SUCCESS
;
}
case
QUERY_NODE_OPERATOR
:
{
SOperatorNode
*
pOpNode
=
(
SOperatorNode
*
)
pNode
;
SOperatorNode
*
pOpNode
=
(
SOperatorNode
*
)
pNode
;
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"("
);
if
(
pOpNode
->
pLeft
)
{
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) {
nodesError
(
"unknown operation type:%d"
,
pOpNode
->
opType
);
NODES_ERR_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
" %s "
,
gOperatorStr
[
pOpNode
->
opType
]);
if
(
pOpNode
->
pRight
)
{
NODES_ERR_RET
(
nodesNodeToSQL
(
pOpNode
->
pRight
,
buf
,
bufSize
,
len
));
}
}
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
")"
);
return
TSDB_CODE_SUCCESS
;
}
case
QUERY_NODE_LOGIC_CONDITION
:{
SLogicConditionNode
*
pLogicNode
=
(
SLogicConditionNode
*
)
pNode
;
SNode
*
node
=
NULL
;
bool
first
=
true
;
case
QUERY_NODE_LOGIC_CONDITION
:
{
SLogicConditionNode
*
pLogicNode
=
(
SLogicConditionNode
*
)
pNode
;
SNode
*
node
=
NULL
;
bool
first
=
true
;
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"("
);
FOREACH
(
node
,
pLogicNode
->
pParameterList
)
{
if
(
!
first
)
{
*
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) {
return
TSDB_CODE_SUCCESS
;
}
case
QUERY_NODE_FUNCTION
:{
SFunctionNode
*
pFuncNode
=
(
SFunctionNode
*
)
pNode
;
SNode
*
node
=
NULL
;
bool
first
=
true
;
case
QUERY_NODE_FUNCTION
:
{
SFunctionNode
*
pFuncNode
=
(
SFunctionNode
*
)
pNode
;
SNode
*
node
=
NULL
;
bool
first
=
true
;
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"%s("
,
pFuncNode
->
functionName
);
FOREACH
(
node
,
pFuncNode
->
pParameterList
)
{
if
(
!
first
)
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
", "
);
...
...
@@ -121,13 +147,13 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
return
TSDB_CODE_SUCCESS
;
}
case
QUERY_NODE_NODE_LIST
:{
SNodeListNode
*
pListNode
=
(
SNodeListNode
*
)
pNode
;
SNode
*
node
=
NULL
;
bool
first
=
true
;
case
QUERY_NODE_NODE_LIST
:
{
SNodeListNode
*
pListNode
=
(
SNodeListNode
*
)
pNode
;
SNode
*
node
=
NULL
;
bool
first
=
true
;
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
"("
);
FOREACH
(
node
,
pListNode
->
pNodeList
)
{
if
(
!
first
)
{
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
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
));
first
=
false
;
}
*
len
+=
snprintf
(
buf
+
*
len
,
bufSize
-
*
len
,
")"
);
return
TSDB_CODE_SUCCESS
;
...
...
@@ -143,7 +169,7 @@ int32_t nodesNodeToSQL(SNode *pNode, char *buf, int32_t bufSize, int32_t *len) {
default:
break
;
}
nodesError
(
"nodesNodeToSQL unknown node = %s"
,
nodesNodeName
(
pNode
->
type
));
NODES_RET
(
TSDB_CODE_QRY_APP_ERROR
);
}
source/libs/nodes/src/nodesTraverseFuncs.c
浏览文件 @
a68e6345
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "querynodes.h"
#include "plannodes.h"
#include "querynodes.h"
typedef
enum
ETraversalOrder
{
TRAVERSAL_PREORDER
=
1
,
...
...
@@ -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
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
)
{
return
DEAL_RES_CONTINUE
;
}
...
...
@@ -77,7 +78,7 @@ static EDealRes dispatchExpr(SNode* pNode, ETraversalOrder order, FNodeWalker wa
break
;
case
QUERY_NODE_REAL_TABLE
:
case
QUERY_NODE_TEMP_TABLE
:
break
;
// todo
break
;
// todo
case
QUERY_NODE_JOIN_TABLE
:
{
SJoinTableNode
*
pJoinTableNode
=
(
SJoinTableNode
*
)
pNode
;
res
=
walkExpr
(
pJoinTableNode
->
pLeft
,
order
,
walker
,
pContext
);
...
...
@@ -217,7 +218,7 @@ static EDealRes rewriteExpr(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
break
;
case
QUERY_NODE_REAL_TABLE
:
case
QUERY_NODE_TEMP_TABLE
:
break
;
// todo
break
;
// todo
case
QUERY_NODE_JOIN_TABLE
:
{
SJoinTableNode
*
pJoinTableNode
=
(
SJoinTableNode
*
)
pNode
;
res
=
rewriteExpr
(
&
(
pJoinTableNode
->
pLeft
),
order
,
rewriter
,
pContext
);
...
...
@@ -339,7 +340,7 @@ void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker wa
case
SQL_CLAUSE_DISTINCT
:
nodesWalkExprs
(
pSelect
->
pOrderByList
,
walker
,
pContext
);
case
SQL_CLAUSE_ORDER_BY
:
nodesWalkExprs
(
pSelect
->
pProjectionList
,
walker
,
pContext
);
nodesWalkExprs
(
pSelect
->
pProjectionList
,
walker
,
pContext
);
default:
break
;
}
...
...
@@ -368,7 +369,7 @@ void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewrit
case
SQL_CLAUSE_DISTINCT
:
nodesRewriteExprs
(
pSelect
->
pOrderByList
,
rewriter
,
pContext
);
case
SQL_CLAUSE_ORDER_BY
:
nodesRewriteExprs
(
pSelect
->
pProjectionList
,
rewriter
,
pContext
);
nodesRewriteExprs
(
pSelect
->
pProjectionList
,
rewriter
,
pContext
);
default:
break
;
}
...
...
@@ -395,7 +396,8 @@ static EDealRes walkScanPhysi(SScanPhysiNode* pScan, ETraversalOrder order, FNod
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
);
if
(
DEAL_RES_ERROR
!=
res
&&
DEAL_RES_END
!=
res
)
{
res
=
walkPhysiPlans
(
pScan
->
pDynamicScanFuncs
,
order
,
walker
,
pContext
);
...
...
source/libs/nodes/src/nodesUtilFuncs.c
浏览文件 @
a68e6345
...
...
@@ -97,7 +97,7 @@ SNodeptr nodesMakeNode(ENodeType type) {
case
QUERY_NODE_CREATE_DATABASE_STMT
:
return
makeNode
(
type
,
sizeof
(
SCreateDatabaseStmt
));
case
QUERY_NODE_DROP_DATABASE_STMT
:
return
makeNode
(
type
,
sizeof
(
SDropDatabaseStmt
));
return
makeNode
(
type
,
sizeof
(
SDropDatabaseStmt
));
case
QUERY_NODE_ALTER_DATABASE_STMT
:
return
makeNode
(
type
,
sizeof
(
SAlterDatabaseStmt
));
case
QUERY_NODE_CREATE_TABLE_STMT
:
...
...
@@ -298,9 +298,7 @@ static void destroyScanPhysiNode(SScanPhysiNode* pNode) {
nodesDestroyList
(
pNode
->
pScanCols
);
}
static
void
destroyDataSinkNode
(
SDataSinkNode
*
pNode
)
{
nodesDestroyNode
(
pNode
->
pInputDataBlockDesc
);
}
static
void
destroyDataSinkNode
(
SDataSinkNode
*
pNode
)
{
nodesDestroyNode
(
pNode
->
pInputDataBlockDesc
);
}
void
nodesDestroyNode
(
SNodeptr
pNode
)
{
if
(
NULL
==
pNode
)
{
...
...
@@ -308,7 +306,7 @@ void nodesDestroyNode(SNodeptr 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
;
case
QUERY_NODE_VALUE
:
{
SValueNode
*
pValue
=
(
SValueNode
*
)
pNode
;
...
...
@@ -352,7 +350,7 @@ void nodesDestroyNode(SNodeptr pNode) {
case
QUERY_NODE_ORDER_BY_EXPR
:
nodesDestroyNode
(((
SOrderByExprNode
*
)
pNode
)
->
pExpr
);
break
;
case
QUERY_NODE_LIMIT
:
// no pointer field
case
QUERY_NODE_LIMIT
:
// no pointer field
break
;
case
QUERY_NODE_STATE_WINDOW
:
nodesDestroyNode
(((
SStateWindowNode
*
)
pNode
)
->
pExpr
);
...
...
@@ -387,9 +385,9 @@ void nodesDestroyNode(SNodeptr pNode) {
case
QUERY_NODE_DATABLOCK_DESC
:
nodesDestroyList
(((
SDataBlockDescNode
*
)
pNode
)
->
pSlots
);
break
;
case
QUERY_NODE_SLOT_DESC
:
// no pointer field
case
QUERY_NODE_COLUMN_DEF
:
// no pointer field
case
QUERY_NODE_DOWNSTREAM_SOURCE
:
// no pointer field
case
QUERY_NODE_SLOT_DESC
:
// no pointer field
case
QUERY_NODE_COLUMN_DEF
:
// no pointer field
case
QUERY_NODE_DOWNSTREAM_SOURCE
:
// no pointer field
break
;
case
QUERY_NODE_DATABASE_OPTIONS
:
nodesDestroyList
(((
SDatabaseOptions
*
)
pNode
)
->
pRetentions
);
...
...
@@ -436,7 +434,7 @@ void nodesDestroyNode(SNodeptr pNode) {
case
QUERY_NODE_CREATE_DATABASE_STMT
:
nodesDestroyNode
(((
SCreateDatabaseStmt
*
)
pNode
)
->
pOptions
);
break
;
case
QUERY_NODE_DROP_DATABASE_STMT
:
// no pointer field
case
QUERY_NODE_DROP_DATABASE_STMT
:
// no pointer field
break
;
case
QUERY_NODE_ALTER_DATABASE_STMT
:
nodesDestroyNode
(((
SAlterDatabaseStmt
*
)
pNode
)
->
pOptions
);
...
...
@@ -457,12 +455,12 @@ void nodesDestroyNode(SNodeptr pNode) {
case
QUERY_NODE_CREATE_MULTI_TABLE_STMT
:
nodesDestroyList
(((
SCreateMultiTableStmt
*
)
pNode
)
->
pSubTables
);
break
;
case
QUERY_NODE_DROP_TABLE_CLAUSE
:
// no pointer field
case
QUERY_NODE_DROP_TABLE_CLAUSE
:
// no pointer field
break
;
case
QUERY_NODE_DROP_TABLE_STMT
:
nodesDestroyNode
(((
SDropTableStmt
*
)
pNode
)
->
pTables
);
break
;
case
QUERY_NODE_DROP_SUPER_TABLE_STMT
:
// no pointer field
case
QUERY_NODE_DROP_SUPER_TABLE_STMT
:
// no pointer field
break
;
case
QUERY_NODE_ALTER_TABLE_STMT
:
{
SAlterTableStmt
*
pStmt
=
(
SAlterTableStmt
*
)
pNode
;
...
...
@@ -470,13 +468,13 @@ void nodesDestroyNode(SNodeptr pNode) {
nodesDestroyNode
(
pStmt
->
pVal
);
break
;
}
case
QUERY_NODE_CREATE_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_USE_DATABASE_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_ALTER_DNODE_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_DROP_USER_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_DROP_DNODE_STMT
:
// no pointer field
case
QUERY_NODE_ALTER_DNODE_STMT
:
// no pointer field
break
;
case
QUERY_NODE_CREATE_INDEX_STMT
:
{
SCreateIndexStmt
*
pStmt
=
(
SCreateIndexStmt
*
)
pNode
;
...
...
@@ -484,15 +482,15 @@ void nodesDestroyNode(SNodeptr pNode) {
nodesDestroyList
(
pStmt
->
pCols
);
break
;
}
case
QUERY_NODE_DROP_INDEX_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_INDEX_STMT
:
// no pointer field
case
QUERY_NODE_CREATE_QNODE_STMT
:
// no pointer field
case
QUERY_NODE_DROP_QNODE_STMT
:
// no pointer field
break
;
case
QUERY_NODE_CREATE_TOPIC_STMT
:
nodesDestroyNode
(((
SCreateTopicStmt
*
)
pNode
)
->
pQuery
);
break
;
case
QUERY_NODE_DROP_TOPIC_STMT
:
// no pointer field
case
QUERY_NODE_ALTER_LOCAL_STMT
:
// no pointer field
case
QUERY_NODE_DROP_TOPIC_STMT
:
// no pointer field
case
QUERY_NODE_ALTER_LOCAL_STMT
:
// no pointer field
break
;
case
QUERY_NODE_SHOW_DATABASES_STMT
:
case
QUERY_NODE_SHOW_TABLES_STMT
:
...
...
@@ -658,7 +656,7 @@ void nodesDestroyNode(SNodeptr pNode) {
SQueryPlan
*
pPlan
=
(
SQueryPlan
*
)
pNode
;
if
(
NULL
!=
pPlan
->
pSubplans
)
{
// 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
;
FOREACH
(
pElement
,
pPlan
->
pSubplans
)
{
if
(
first
)
{
...
...
@@ -866,7 +864,7 @@ void nodesClearList(SNodeList* pList) {
taosMemoryFreeClear
(
pList
);
}
void
*
nodesGetValueFromNode
(
SValueNode
*
pNode
)
{
void
*
nodesGetValueFromNode
(
SValueNode
*
pNode
)
{
switch
(
pNode
->
node
.
resType
.
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
return
(
void
*
)
&
pNode
->
datum
.
b
;
...
...
@@ -895,10 +893,10 @@ void* nodesGetValueFromNode(SValueNode *pNode) {
return
NULL
;
}
char
*
nodesGetStrValueFromNode
(
SValueNode
*
pNode
)
{
char
*
nodesGetStrValueFromNode
(
SValueNode
*
pNode
)
{
switch
(
pNode
->
node
.
resType
.
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
{
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
if
(
NULL
==
buf
)
{
return
NULL
;
}
...
...
@@ -911,7 +909,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
if
(
NULL
==
buf
)
{
return
NULL
;
}
...
...
@@ -923,7 +921,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
case
TSDB_DATA_TYPE_USMALLINT
:
case
TSDB_DATA_TYPE_UINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
{
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
if
(
NULL
==
buf
)
{
return
NULL
;
}
...
...
@@ -933,7 +931,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
}
case
TSDB_DATA_TYPE_FLOAT
:
case
TSDB_DATA_TYPE_DOUBLE
:
{
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
void
*
buf
=
taosMemoryMalloc
(
MAX_NUM_STR_SIZE
);
if
(
NULL
==
buf
)
{
return
NULL
;
}
...
...
@@ -945,7 +943,7 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
case
TSDB_DATA_TYPE_VARCHAR
:
case
TSDB_DATA_TYPE_VARBINARY
:
{
int32_t
bufSize
=
varDataLen
(
pNode
->
datum
.
p
)
+
2
+
1
;
void
*
buf
=
taosMemoryMalloc
(
bufSize
);
void
*
buf
=
taosMemoryMalloc
(
bufSize
);
if
(
NULL
==
buf
)
{
return
NULL
;
}
...
...
@@ -962,7 +960,8 @@ char* nodesGetStrValueFromNode(SValueNode *pNode) {
bool
nodesIsExprNode
(
const
SNode
*
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
)
{
...
...
@@ -1037,23 +1036,19 @@ bool nodesIsJsonOp(const SOperatorNode* pOp) {
return
false
;
}
bool
nodesIsTimeorderQuery
(
const
SNode
*
pQuery
)
{
return
false
;
}
bool
nodesIsTimeorderQuery
(
const
SNode
*
pQuery
)
{
return
false
;
}
bool
nodesIsTimelineQuery
(
const
SNode
*
pQuery
)
{
return
false
;
}
bool
nodesIsTimelineQuery
(
const
SNode
*
pQuery
)
{
return
false
;
}
typedef
struct
SCollectColumnsCxt
{
int32_t
errCode
;
int32_t
errCode
;
const
char
*
pTableAlias
;
SNodeList
*
pCols
;
SHashObj
*
pColHash
;
SNodeList
*
pCols
;
SHashObj
*
pColHash
;
}
SCollectColumnsCxt
;
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
;
if
(
'\0'
==
pCol
->
tableAlias
[
0
])
{
len
=
sprintf
(
name
,
"%s"
,
pCol
->
colName
);
...
...
@@ -1086,11 +1081,10 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char*
}
SCollectColumnsCxt
cxt
=
{
.
errCode
=
TSDB_CODE_SUCCESS
,
.
pTableAlias
=
pTableAlias
,
.
pCols
=
nodesMakeList
(),
.
pColHash
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
)
};
.
errCode
=
TSDB_CODE_SUCCESS
,
.
pTableAlias
=
pTableAlias
,
.
pCols
=
nodesMakeList
(),
.
pColHash
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BINARY
),
true
,
HASH_NO_LOCK
)};
if
(
NULL
==
cxt
.
pCols
||
NULL
==
cxt
.
pColHash
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
...
...
@@ -1110,9 +1104,9 @@ int32_t nodesCollectColumns(SSelectStmt* pSelect, ESqlClause clause, const char*
}
typedef
struct
SCollectFuncsCxt
{
int32_t
errCode
;
int32_t
errCode
;
FFuncClassifier
classifier
;
SNodeList
*
pFuncs
;
SNodeList
*
pFuncs
;
}
SCollectFuncsCxt
;
static
EDealRes
collectFuncs
(
SNode
*
pNode
,
void
*
pContext
)
{
...
...
@@ -1129,11 +1123,7 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod
return
TSDB_CODE_SUCCESS
;
}
SCollectFuncsCxt
cxt
=
{
.
errCode
=
TSDB_CODE_SUCCESS
,
.
classifier
=
classifier
,
.
pFuncs
=
nodesMakeList
()
};
SCollectFuncsCxt
cxt
=
{.
errCode
=
TSDB_CODE_SUCCESS
,
.
classifier
=
classifier
,
.
pFuncs
=
nodesMakeList
()};
if
(
NULL
==
cxt
.
pFuncs
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
...
...
@@ -1148,12 +1138,11 @@ int32_t nodesCollectFuncs(SSelectStmt* pSelect, FFuncClassifier classifier, SNod
nodesDestroyList
(
cxt
.
pFuncs
);
*
pFuncs
=
NULL
;
}
return
TSDB_CODE_SUCCESS
;
}
char
*
getFillModeString
(
EFillMode
mode
)
{
char
*
getFillModeString
(
EFillMode
mode
)
{
switch
(
mode
)
{
case
FILL_MODE_NONE
:
return
"none"
;
...
...
@@ -1172,12 +1161,12 @@ char *getFillModeString(EFillMode mode) {
}
}
char
*
nodesGetNameFromColumnNode
(
SNode
*
pNode
)
{
char
*
nodesGetNameFromColumnNode
(
SNode
*
pNode
)
{
if
(
NULL
==
pNode
||
QUERY_NODE_COLUMN
!=
pNode
->
type
)
{
return
"NULL"
;
}
return
((
SColumnNode
*
)
pNode
)
->
colName
;
return
((
SColumnNode
*
)
pNode
)
->
colName
;
}
int32_t
nodesGetOutputNumFromSlotList
(
SNodeList
*
pSlots
)
{
...
...
@@ -1185,14 +1174,14 @@ int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) {
return
0
;
}
SNode
*
pNode
=
NULL
;
SNode
*
pNode
=
NULL
;
int32_t
num
=
0
;
FOREACH
(
pNode
,
pSlots
)
{
if
(
QUERY_NODE_SLOT_DESC
!=
pNode
->
type
)
{
continue
;
}
SSlotDescNode
*
descNode
=
(
SSlotDescNode
*
)
pNode
;
SSlotDescNode
*
descNode
=
(
SSlotDescNode
*
)
pNode
;
if
(
descNode
->
output
)
{
++
num
;
}
...
...
@@ -1201,13 +1190,12 @@ int32_t nodesGetOutputNumFromSlotList(SNodeList* pSlots) {
return
num
;
}
void
valueNodeToVariant
(
const
SValueNode
*
pNode
,
SVariant
*
pVal
)
{
pVal
->
nType
=
pNode
->
node
.
resType
.
type
;
pVal
->
nLen
=
pNode
->
node
.
resType
.
bytes
;
switch
(
pNode
->
node
.
resType
.
type
)
{
case
TSDB_DATA_TYPE_NULL
:
break
;
break
;
case
TSDB_DATA_TYPE_BOOL
:
pVal
->
i
=
pNode
->
datum
.
b
;
break
;
...
...
@@ -1241,6 +1229,3 @@ void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
break
;
}
}
source/libs/nodes/test/nodesTest.cpp
浏览文件 @
a68e6345
...
...
@@ -20,42 +20,42 @@
using
namespace
std
;
static
EDealRes
rewriterTest
(
SNode
**
pNode
,
void
*
pContext
)
{
EDealRes
*
pRes
=
(
EDealRes
*
)
pContext
;
if
(
QUERY_NODE_OPERATOR
==
nodeType
(
*
pNode
))
{
SOperatorNode
*
pOp
=
(
SOperatorNode
*
)(
*
pNode
);
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pOp
->
pLeft
)
||
QUERY_NODE_VALUE
!=
nodeType
(
pOp
->
pRight
))
{
*
pRes
=
DEAL_RES_ERROR
;
}
SValueNode
*
pVal
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
string
tmp
=
to_string
(
stoi
(((
SValueNode
*
)(
pOp
->
pLeft
))
->
literal
)
+
stoi
(((
SValueNode
*
)(
pOp
->
pRight
))
->
literal
));
pVal
->
literal
=
strdup
(
tmp
.
c_str
());
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
pVal
;
}
return
DEAL_RES_CONTINUE
;
EDealRes
*
pRes
=
(
EDealRes
*
)
pContext
;
if
(
QUERY_NODE_OPERATOR
==
nodeType
(
*
pNode
))
{
SOperatorNode
*
pOp
=
(
SOperatorNode
*
)(
*
pNode
);
if
(
QUERY_NODE_VALUE
!=
nodeType
(
pOp
->
pLeft
)
||
QUERY_NODE_VALUE
!=
nodeType
(
pOp
->
pRight
))
{
*
pRes
=
DEAL_RES_ERROR
;
}
SValueNode
*
pVal
=
(
SValueNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
string
tmp
=
to_string
(
stoi
(((
SValueNode
*
)(
pOp
->
pLeft
))
->
literal
)
+
stoi
(((
SValueNode
*
)(
pOp
->
pRight
))
->
literal
));
pVal
->
literal
=
strdup
(
tmp
.
c_str
());
nodesDestroyNode
(
*
pNode
);
*
pNode
=
(
SNode
*
)
pVal
;
}
return
DEAL_RES_CONTINUE
;
}
TEST
(
NodesTest
,
traverseTest
)
{
SNode
*
pRoot
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_OPERATOR
);
SOperatorNode
*
pOp
=
(
SOperatorNode
*
)
pRoot
;
SOperatorNode
*
pLeft
=
(
SOperatorNode
*
)
nodesMakeNode
(
QUERY_NODE_OPERATOR
);
pLeft
->
pLeft
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
((
SValueNode
*
)(
pLeft
->
pLeft
))
->
literal
=
strdup
(
"10"
);
pLeft
->
pRight
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
((
SValueNode
*
)(
pLeft
->
pRight
))
->
literal
=
strdup
(
"5"
);
pOp
->
pLeft
=
(
SNode
*
)
pLeft
;
pOp
->
pRight
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
((
SValueNode
*
)(
pOp
->
pRight
))
->
literal
=
strdup
(
"3"
);
SNode
*
pRoot
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_OPERATOR
);
SOperatorNode
*
pOp
=
(
SOperatorNode
*
)
pRoot
;
SOperatorNode
*
pLeft
=
(
SOperatorNode
*
)
nodesMakeNode
(
QUERY_NODE_OPERATOR
);
pLeft
->
pLeft
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
((
SValueNode
*
)(
pLeft
->
pLeft
))
->
literal
=
strdup
(
"10"
);
pLeft
->
pRight
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
((
SValueNode
*
)(
pLeft
->
pRight
))
->
literal
=
strdup
(
"5"
);
pOp
->
pLeft
=
(
SNode
*
)
pLeft
;
pOp
->
pRight
=
(
SNode
*
)
nodesMakeNode
(
QUERY_NODE_VALUE
);
((
SValueNode
*
)(
pOp
->
pRight
))
->
literal
=
strdup
(
"3"
);
EXPECT_EQ
(
nodeType
(
pRoot
),
QUERY_NODE_OPERATOR
);
EDealRes
res
=
DEAL_RES_CONTINUE
;
nodesRewriteExprPostOrder
(
&
pRoot
,
rewriterTest
,
&
res
);
EXPECT_EQ
(
res
,
DEAL_RES_CONTINUE
);
EXPECT_EQ
(
nodeType
(
pRoot
),
QUERY_NODE_VALUE
);
EXPECT_EQ
(
string
(((
SValueNode
*
)
pRoot
)
->
literal
),
"18"
);
EXPECT_EQ
(
nodeType
(
pRoot
),
QUERY_NODE_OPERATOR
);
EDealRes
res
=
DEAL_RES_CONTINUE
;
nodesRewriteExprPostOrder
(
&
pRoot
,
rewriterTest
,
&
res
);
EXPECT_EQ
(
res
,
DEAL_RES_CONTINUE
);
EXPECT_EQ
(
nodeType
(
pRoot
),
QUERY_NODE_VALUE
);
EXPECT_EQ
(
string
(((
SValueNode
*
)
pRoot
)
->
literal
),
"18"
);
}
int
main
(
int
argc
,
char
*
argv
[])
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
testing
::
InitGoogleTest
(
&
argc
,
argv
);
return
RUN_ALL_TESTS
();
}
source/libs/parser/inc/parAst.h
浏览文件 @
a68e6345
...
...
@@ -21,18 +21,18 @@ extern "C" {
#endif
#include "cmdnodes.h"
#include "parser.h"
#include "parToken.h"
#include "parUtil.h"
#include "parser.h"
#include "querynodes.h"
typedef
struct
SAstCreateContext
{
SParseContext
*
pQueryCxt
;
SMsgBuf
msgBuf
;
bool
notSupport
;
bool
valid
;
SNode
*
pRootNode
;
int16_t
placeholderNo
;
SMsgBuf
msgBuf
;
bool
notSupport
;
bool
valid
;
SNode
*
pRootNode
;
int16_t
placeholderNo
;
}
SAstCreateContext
;
typedef
enum
EDatabaseOptionType
{
...
...
@@ -67,9 +67,9 @@ typedef enum ETableOptionType {
}
ETableOptionType
;
typedef
struct
SAlterOption
{
int32_t
type
;
int32_t
type
;
SValueNode
*
pVal
;
SNodeList
*
pList
;
SNodeList
*
pList
;
}
SAlterOption
;
extern
SToken
nil_token
;
...
...
@@ -105,7 +105,8 @@ SNode* createLimitNode(SAstCreateContext* pCxt, const SToken* pLimit, const STok
SNode
*
createOrderByExprNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
,
EOrder
order
,
ENullOrder
nullOrder
);
SNode
*
createSessionWindowNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pCol
,
SNode
*
pGap
);
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
*
createGroupingSetNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
);
...
...
@@ -120,26 +121,30 @@ SNode* addLimitClause(SAstCreateContext* pCxt, SNode* pStmt, SNode* pLimit);
SNode
*
createSelectStmt
(
SAstCreateContext
*
pCxt
,
bool
isDistinct
,
SNodeList
*
pProjectionList
,
SNode
*
pTable
);
SNode
*
createSetOperator
(
SAstCreateContext
*
pCxt
,
ESetOperatorType
type
,
SNode
*
pLeft
,
SNode
*
pRight
);
SNode
*
createDatabaseOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
setDatabaseAlterOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SAlterOption
*
pAlterOption
);
SNode
*
createCreateDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SToken
*
pDbName
,
SNode
*
pOptions
);
SNode
*
createDropDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SToken
*
pDbName
);
SNode
*
createAlterDatabaseStmt
(
SAstCreateContext
*
pCxt
,
SToken
*
pDbName
,
SNode
*
pOptions
);
SNode
*
createTableOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
setTableAlterOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SAlterOption
*
pAlterOption
);
SNode
*
createColumnDefNode
(
SAstCreateContext
*
pCxt
,
SToken
*
pColName
,
SDataType
dataType
,
const
SToken
*
pComment
);
SNode
*
createDatabaseOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
setDatabaseAlterOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SAlterOption
*
pAlterOption
);
SNode
*
createCreateDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SToken
*
pDbName
,
SNode
*
pOptions
);
SNode
*
createDropDatabaseStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SToken
*
pDbName
);
SNode
*
createAlterDatabaseStmt
(
SAstCreateContext
*
pCxt
,
SToken
*
pDbName
,
SNode
*
pOptions
);
SNode
*
createTableOptions
(
SAstCreateContext
*
pCxt
);
SNode
*
setTableAlterOption
(
SAstCreateContext
*
pCxt
,
SNode
*
pOptions
,
SAlterOption
*
pAlterOption
);
SNode
*
createColumnDefNode
(
SAstCreateContext
*
pCxt
,
SToken
*
pColName
,
SDataType
dataType
,
const
SToken
*
pComment
);
SDataType
createDataType
(
uint8_t
type
);
SDataType
createVarLenDataType
(
uint8_t
type
,
const
SToken
*
pLen
);
SNode
*
createCreateTableStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNodeList
*
pCols
,
SNodeList
*
pTags
,
SNode
*
pOptions
);
SNode
*
createCreateSubTableClause
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNode
*
pUseRealTable
,
SNodeList
*
pSpecificTags
,
SNodeList
*
pValsOfTags
);
SNode
*
createCreateTableStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNodeList
*
pCols
,
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
*
createDropTableClause
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SNode
*
pRealTable
);
SNode
*
createDropTableStmt
(
SAstCreateContext
*
pCxt
,
SNodeList
*
pTables
);
SNode
*
createDropSuperTableStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SNode
*
pRealTable
);
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
*
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
*
createUseDatabaseStmt
(
SAstCreateContext
*
pCxt
,
SToken
*
pDbName
);
SNode
*
createShowStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
SNode
*
pDbName
,
SNode
*
pTbNamePattern
);
...
...
@@ -151,13 +156,15 @@ SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName);
SNode
*
createCreateDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFqdn
,
const
SToken
*
pPort
);
SNode
*
createDropDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pDnode
);
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
*
createDropIndexStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreNotExists
,
SToken
*
pIndexName
,
SToken
*
pTableName
);
SNode
*
createCreateComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
);
SNode
*
createDropComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
);
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
*
createAlterLocalStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pConfig
,
const
SToken
*
pValue
);
SNode
*
createDefaultExplainOptions
(
SAstCreateContext
*
pCxt
);
...
...
@@ -167,10 +174,12 @@ SNode* createExplainStmt(SAstCreateContext* pCxt, bool analyze, SNode* pOptions,
SNode
*
createDescribeStmt
(
SAstCreateContext
*
pCxt
,
SNode
*
pRealTable
);
SNode
*
createResetQueryCacheStmt
(
SAstCreateContext
*
pCxt
);
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
*
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
*
createKillStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pId
);
SNode
*
createMergeVgroupStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pVgId1
,
const
SToken
*
pVgId2
);
...
...
source/libs/parser/inc/parInsertData.h
浏览文件 @
a68e6345
...
...
@@ -18,8 +18,8 @@
#include "catalog.h"
#include "os.h"
#include "ttypes.h"
#include "tname.h"
#include "ttypes.h"
#define IS_DATA_COL_ORDERED(spd) ((spd->orderStatus) == (int8_t)ORDER_STATUS_ORDERED)
...
...
@@ -52,8 +52,8 @@ typedef struct SParsedDataColInfo {
uint16_t
flen
;
// TODO: get from STSchema
uint16_t
allNullLen
;
// TODO: get from STSchema(base on SDataRow)
uint16_t
extendedVarLen
;
uint16_t
boundNullLen
;
// bound column len with all NULL value(without VarDataOffsetT/SColIdx part)
col_id_t
*
boundColumns
;
// bound column idx according to schema
uint16_t
boundNullLen
;
// bound column len with all NULL value(without VarDataOffsetT/SColIdx part)
col_id_t
*
boundColumns
;
// bound column idx according to schema
SBoundColumn
*
cols
;
SBoundIdxInfo
*
colIdxInfo
;
int8_t
orderStatus
;
// bound columns
...
...
@@ -72,12 +72,13 @@ typedef struct STableDataBlocks {
int32_t
numOfTables
;
// number of tables in current submit block
int32_t
rowSize
;
// row size for current table
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
;
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
char
*
pData
;
bool
cloned
;
int32_t
createTbReqLen
;
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
char
*
pData
;
bool
cloned
;
int32_t
createTbReqLen
;
SParsedDataColInfo
boundColumnInfo
;
SRowBuilder
rowBuilder
;
}
STableDataBlocks
;
...
...
@@ -89,8 +90,8 @@ static FORCE_INLINE int32_t getExtendedRowSize(STableDataBlocks *pBlock) {
(
int32_t
)
TD_BITMAP_BYTES
(
pTableInfo
->
numOfColumns
-
1
);
}
static
FORCE_INLINE
void
getSTSRowAppendInfo
(
uint8_t
rowType
,
SParsedDataColInfo
*
spd
,
col_id_t
idx
,
int32_t
*
toffset
,
col_id_t
*
colIdx
)
{
static
FORCE_INLINE
void
getSTSRowAppendInfo
(
uint8_t
rowType
,
SParsedDataColInfo
*
spd
,
col_id_t
idx
,
int32_t
*
toffset
,
col_id_t
*
colIdx
)
{
col_id_t
schemaIdx
=
0
;
if
(
IS_DATA_COL_ORDERED
(
spd
))
{
schemaIdx
=
spd
->
boundColumns
[
idx
]
-
PRIMARYKEY_TIMESTAMP_COL_ID
;
...
...
@@ -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
)
{
pBlocks
->
suid
=
(
TSDB_NORMAL_TABLE
==
dataBuf
->
pTableMeta
->
tableType
?
dataBuf
->
pTableMeta
->
uid
:
dataBuf
->
pTableMeta
->
suid
);
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
->
uid
=
dataBuf
->
pTableMeta
->
uid
;
pBlocks
->
sversion
=
dataBuf
->
pTableMeta
->
sversion
;
pBlocks
->
schemaLen
=
dataBuf
->
createTbReqLen
;
...
...
@@ -131,14 +133,15 @@ static FORCE_INLINE int32_t setBlockInfo(SSubmitBlk *pBlocks, STableDataBlocks*
int32_t
schemaIdxCompar
(
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
destroyBlockArrayList
(
SArray
*
pDataBlockList
);
void
destroyBlockHashmap
(
SHashObj
*
pDataBlockHash
);
int
initRowBuilder
(
SRowBuilder
*
pBuilder
,
int16_t
schemaVer
,
SParsedDataColInfo
*
pColInfo
);
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
,
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
,
SVCreateTbReq
*
pCreateTbReq
);
int32_t
mergeTableDataBlocks
(
SHashObj
*
pHashObj
,
uint8_t
payloadType
,
SArray
**
pVgDataBlocks
);
int32_t
buildCreateTbMsg
(
STableDataBlocks
*
pBlocks
,
SVCreateTbReq
*
pCreateTbReq
);
void
destroyBlockArrayList
(
SArray
*
pDataBlockList
);
void
destroyBlockHashmap
(
SHashObj
*
pDataBlockHash
);
int
initRowBuilder
(
SRowBuilder
*
pBuilder
,
int16_t
schemaVer
,
SParsedDataColInfo
*
pColInfo
);
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
,
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
,
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
);
#endif // TDENGINE_DATABLOCKMGT_H
source/libs/parser/inc/parInt.h
浏览文件 @
a68e6345
...
...
@@ -20,9 +20,9 @@
extern
"C"
{
#endif
#include "parser.h"
#include "parToken.h"
#include "parUtil.h"
#include "parser.h"
int32_t
parseInsertSql
(
SParseContext
*
pContext
,
SQuery
**
pQuery
);
int32_t
parse
(
SParseContext
*
pParseCxt
,
SQuery
**
pQuery
);
...
...
source/libs/parser/inc/parToken.h
浏览文件 @
a68e6345
...
...
@@ -20,6 +20,8 @@
extern
"C"
{
#endif
#include "os.h"
#include "ttokendef.h"
// used to denote the minimum unite in sql parsing
...
...
@@ -35,7 +37,7 @@ typedef struct SToken {
* @return
*/
#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
...
...
@@ -68,12 +70,12 @@ bool taosIsKeyWordToken(const char *z, int32_t len);
* @param pToken
* @return token type, if it is not a number, TK_NK_ILLEGAL will return
*/
static
FORCE_INLINE
int32_t
tGetNumericStringType
(
const
SToken
*
pToken
)
{
const
char
*
z
=
pToken
->
z
;
int32_t
type
=
TK_NK_ILLEGAL
;
static
FORCE_INLINE
int32_t
tGetNumericStringType
(
const
SToken
*
pToken
)
{
const
char
*
z
=
pToken
->
z
;
int32_t
type
=
TK_NK_ILLEGAL
;
uint32_t
i
=
0
;
for
(;
i
<
pToken
->
n
;
++
i
)
{
for
(;
i
<
pToken
->
n
;
++
i
)
{
switch
(
z
[
i
])
{
case
'+'
:
case
'-'
:
{
...
...
@@ -86,7 +88,7 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
* .123
* .123e4
*/
if
(
!
isdigit
(
z
[
i
+
1
]))
{
if
(
!
isdigit
(
z
[
i
+
1
]))
{
return
TK_NK_ILLEGAL
;
}
...
...
@@ -107,13 +109,13 @@ static FORCE_INLINE int32_t tGetNumericStringType(const SToken* pToken) {
case
'0'
:
{
char
next
=
z
[
i
+
1
];
if
(
next
==
'b'
)
{
// bin number
if
(
next
==
'b'
)
{
// bin number
type
=
TK_NK_BIN
;
for
(
i
+=
2
;
(
z
[
i
]
==
'0'
||
z
[
i
]
==
'1'
);
++
i
)
{
}
goto
_end
;
}
else
if
(
next
==
'x'
)
{
//hex number
}
else
if
(
next
==
'x'
)
{
//
hex number
type
=
TK_NK_HEX
;
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) {
}
}
_end:
return
(
i
<
pToken
->
n
)
?
TK_NK_ILLEGAL
:
type
;
_end:
return
(
i
<
pToken
->
n
)
?
TK_NK_ILLEGAL
:
type
;
}
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
}
...
...
source/libs/parser/inc/parUtil.h
浏览文件 @
a68e6345
...
...
@@ -23,31 +23,31 @@ extern "C" {
#include "os.h"
#include "query.h"
#define parserFatal(param, ...)
qFatal("PARSER: " param, __VA_ARGS__)
#define parserError(param, ...)
qError("PARSER: " param, __VA_ARGS__)
#define parserWarn(param, ...)
qWarn("PARSER: " param, __VA_ARGS__)
#define parserInfo(param, ...)
qInfo("PARSER: " param, __VA_ARGS__)
#define parserDebug(param, ...)
qDebug("PARSER: " param, __VA_ARGS__)
#define parserTrace(param, ...)
qTrace("PARSER: " param, __VA_ARGS__)
#define parserFatal(param, ...) qFatal("PARSER: " param, __VA_ARGS__)
#define parserError(param, ...) qError("PARSER: " param, __VA_ARGS__)
#define parserWarn(param, ...) qWarn("PARSER: " param, __VA_ARGS__)
#define parserInfo(param, ...) qInfo("PARSER: " param, __VA_ARGS__)
#define parserDebug(param, ...) qDebug("PARSER: " param, __VA_ARGS__)
#define parserTrace(param, ...) qTrace("PARSER: " param, __VA_ARGS__)
#define PK_TS_COL_INTERNAL_NAME "_rowts"
typedef
struct
SMsgBuf
{
int32_t
len
;
char
*
buf
;
char
*
buf
;
}
SMsgBuf
;
int32_t
generateSyntaxErrMsg
(
SMsgBuf
*
pBuf
,
int32_t
errCode
,
...);
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
);
SSchema
*
getTableColumnSchema
(
const
STableMeta
*
pTableMeta
);
SSchema
*
getTableTagSchema
(
const
STableMeta
*
pTableMeta
);
int32_t
getNumOfColumns
(
const
STableMeta
*
pTableMeta
);
int32_t
getNumOfTags
(
const
STableMeta
*
pTableMeta
);
STableMeta
*
tableMetaDup
(
const
STableMeta
*
pTableMeta
);
SSchema
*
getTableColumnSchema
(
const
STableMeta
*
pTableMeta
);
SSchema
*
getTableTagSchema
(
const
STableMeta
*
pTableMeta
);
int32_t
getNumOfColumns
(
const
STableMeta
*
pTableMeta
);
int32_t
getNumOfTags
(
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
);
...
...
source/libs/parser/src/parAstCreater.c
浏览文件 @
a68e6345
...
...
@@ -18,24 +18,24 @@
#include "parUtil.h"
#include "ttime.h"
#define CHECK_OUT_OF_MEM(p) \
do { \
if (NULL == (p)) { \
pCxt->valid = false; \
#define CHECK_OUT_OF_MEM(p)
\
do {
\
if (NULL == (p)) {
\
pCxt->valid = false;
\
snprintf(pCxt->pQueryCxt->pMsg, pCxt->pQueryCxt->msgLen, "Out of memory"); \
return NULL; \
} \
return NULL;
\
}
\
} while (0)
#define CHECK_RAW_EXPR_NODE(node) \
do { \
#define CHECK_RAW_EXPR_NODE(node)
\
do {
\
if (NULL == (node) || QUERY_NODE_RAW_EXPR != nodeType(node)) { \
pCxt->valid = false; \
return NULL; \
} \
pCxt->valid = false;
\
return NULL;
\
}
\
} 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
)
{
pCxt
->
pQueryCxt
=
pParseCxt
;
...
...
@@ -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
)
{
if
(
NULL
==
pEp
)
{
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
);
pCxt
->
valid
=
false
;
}
else
{
...
...
@@ -206,7 +206,7 @@ SNode* createRawExprNodeExt(SAstCreateContext* pCxt, const SToken* pStart, const
SNode
*
releaseRawExprNode
(
SAstCreateContext
*
pCxt
,
SNode
*
pNode
)
{
CHECK_RAW_EXPR_NODE
(
pNode
);
SRawExprNode
*
pRawExpr
=
(
SRawExprNode
*
)
pNode
;
SNode
*
pExpr
=
pRawExpr
->
pNode
;
SNode
*
pExpr
=
pRawExpr
->
pNode
;
if
(
nodesIsExprNode
(
pExpr
))
{
int32_t
len
=
TMIN
(
sizeof
(((
SExprNode
*
)
pExpr
)
->
aliasName
)
-
1
,
pRawExpr
->
n
);
strncpy
(((
SExprNode
*
)
pExpr
)
->
aliasName
,
pRawExpr
->
p
,
len
);
...
...
@@ -222,7 +222,7 @@ SToken getTokenFromRawExprNode(SAstCreateContext* pCxt, SNode* pNode) {
return
nil_token
;
}
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
;
}
...
...
@@ -352,12 +352,13 @@ SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pL
SNode
*
createBetweenAnd
(
SAstCreateContext
*
pCxt
,
SNode
*
pExpr
,
SNode
*
pLeft
,
SNode
*
pRight
)
{
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
)
{
return
createLogicConditionNode
(
pCxt
,
LOGIC_COND_TYPE_OR
,
createOperatorNode
(
pCxt
,
OP_TYPE_LOWER_THAN
,
pExpr
,
pLeft
),
createOperatorNode
(
pCxt
,
OP_TYPE_GREATER_THAN
,
nodesCloneNode
(
pExpr
),
pRight
));
return
createLogicConditionNode
(
pCxt
,
LOGIC_COND_TYPE_OR
,
createOperatorNode
(
pCxt
,
OP_TYPE_LOWER_THAN
,
pExpr
,
pLeft
),
createOperatorNode
(
pCxt
,
OP_TYPE_GREATER_THAN
,
nodesCloneNode
(
pExpr
),
pRight
));
}
SNode
*
createFunctionNode
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFuncName
,
SNodeList
*
pParameterList
)
{
...
...
@@ -410,7 +411,7 @@ SNode* createRealTableNode(SAstCreateContext* pCxt, SToken* pDbName, SToken* pTa
}
else
{
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
;
}
...
...
@@ -483,7 +484,8 @@ SNode* createStateWindowNode(SAstCreateContext* pCxt, SNode* pExpr) {
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
);
CHECK_OUT_OF_MEM
(
interval
);
interval
->
pCol
=
nodesMakeNode
(
QUERY_NODE_COLUMN
);
...
...
@@ -749,17 +751,17 @@ SNode* createColumnDefNode(SAstCreateContext* pCxt, SToken* pColName, SDataType
}
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
;
}
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
;
}
SNode
*
createCreateTableStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNodeList
*
pCols
,
SNodeList
*
pTags
,
SNode
*
pOptions
)
{
SNode
*
createCreateTableStmt
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNodeList
*
pCols
,
SNodeList
*
pTags
,
SNode
*
pOptions
)
{
if
(
NULL
==
pRealTable
)
{
return
NULL
;
}
...
...
@@ -775,8 +777,8 @@ SNode* createCreateTableStmt(SAstCreateContext* pCxt,
return
(
SNode
*
)
pStmt
;
}
SNode
*
createCreateSubTableClause
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNode
*
pUseRealTable
,
SNodeList
*
pSpecificTags
,
SNodeList
*
pValsOfTags
)
{
SNode
*
createCreateSubTableClause
(
SAstCreateContext
*
pCxt
,
bool
ignoreExists
,
SNode
*
pRealTable
,
SNode
*
pUseRealTable
,
SNodeList
*
pSpecificTags
,
SNodeList
*
pValsOfTags
)
{
if
(
NULL
==
pRealTable
)
{
return
NULL
;
}
...
...
@@ -842,7 +844,8 @@ SNode* createAlterTableOption(SAstCreateContext* pCxt, SNode* pRealTable, SNode*
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
)
{
return
NULL
;
}
...
...
@@ -865,7 +868,8 @@ SNode* createAlterTableDropCol(SAstCreateContext* pCxt, SNode* pRealTable, int8_
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
)
{
return
NULL
;
}
...
...
@@ -900,7 +904,8 @@ SNode* createUseDatabaseStmt(SAstCreateContext* pCxt, SToken* pDbName) {
}
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
)
{
...
...
@@ -909,7 +914,8 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, S
pCxt
->
valid
=
false
;
return
NULL
;
}
SShowStmt
*
pStmt
=
nodesMakeNode
(
type
);;
SShowStmt
*
pStmt
=
nodesMakeNode
(
type
);
;
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
pDbName
=
pDbName
;
pStmt
->
pTbNamePattern
=
pTbNamePattern
;
...
...
@@ -971,7 +977,7 @@ SNode* createDropUserStmt(SAstCreateContext* pCxt, SToken* pUserName) {
SNode
*
createCreateDnodeStmt
(
SAstCreateContext
*
pCxt
,
const
SToken
*
pFqdn
,
const
SToken
*
pPort
)
{
int32_t
port
=
0
;
char
fqdn
[
TSDB_FQDN_LEN
]
=
{
0
};
char
fqdn
[
TSDB_FQDN_LEN
]
=
{
0
};
if
(
NULL
==
pPort
)
{
if
(
!
checkAndSplitEndpoint
(
pCxt
,
pFqdn
,
fqdn
,
&
port
))
{
return
NULL
;
...
...
@@ -1004,7 +1010,8 @@ SNode* createDropDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode) {
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
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
dnodeId
=
strtol
(
pDnode
->
z
,
NULL
,
10
);
...
...
@@ -1015,7 +1022,8 @@ SNode* createAlterDnodeStmt(SAstCreateContext* pCxt, const SToken* pDnode, const
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
))
{
return
NULL
;
}
...
...
@@ -1030,7 +1038,8 @@ SNode* createCreateIndexStmt(SAstCreateContext* pCxt, EIndexType type, bool igno
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
);
CHECK_OUT_OF_MEM
(
pOptions
);
pOptions
->
pFuncs
=
pFuncs
;
...
...
@@ -1055,14 +1064,16 @@ SNode* createDropIndexStmt(SAstCreateContext* pCxt, bool ignoreNotExists, SToken
SNode
*
createCreateComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
)
{
SCreateComponentNodeStmt
*
pStmt
=
nodesMakeNode
(
type
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
dnodeId
=
strtol
(
pDnodeId
->
z
,
NULL
,
10
);;
pStmt
->
dnodeId
=
strtol
(
pDnodeId
->
z
,
NULL
,
10
);
;
return
(
SNode
*
)
pStmt
;
}
SNode
*
createDropComponentNodeStmt
(
SAstCreateContext
*
pCxt
,
ENodeType
type
,
const
SToken
*
pDnodeId
)
{
SDropComponentNodeStmt
*
pStmt
=
nodesMakeNode
(
type
);
CHECK_OUT_OF_MEM
(
pStmt
);
pStmt
->
dnodeId
=
strtol
(
pDnodeId
->
z
,
NULL
,
10
);;
pStmt
->
dnodeId
=
strtol
(
pDnodeId
->
z
,
NULL
,
10
);
;
return
(
SNode
*
)
pStmt
;
}
...
...
@@ -1075,8 +1086,8 @@ SNode* createTopicOptions(SAstCreateContext* pCxt) {
return
(
SNode
*
)
pOptions
;
}
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
)
{
SCreateTopicStmt
*
pStmt
=
nodesMakeNode
(
QUERY_NODE_CREATE_TOPIC_STMT
);
CHECK_OUT_OF_MEM
(
pStmt
);
strncpy
(
pStmt
->
topicName
,
pTopicName
->
z
,
pTopicName
->
n
);
...
...
@@ -1158,8 +1169,8 @@ SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups) {
return
pStmt
;
}
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
)
{
if
(
pLibPath
->
n
<=
2
)
{
pCxt
->
valid
=
false
;
return
NULL
;
...
...
@@ -1188,7 +1199,8 @@ SNode* createStreamOptions(SAstCreateContext* pCxt) {
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
);
CHECK_OUT_OF_MEM
(
pStmt
);
strncpy
(
pStmt
->
streamName
,
pStreamName
->
z
,
pStreamName
->
n
);
...
...
source/libs/parser/src/parAstParser.c
浏览文件 @
a68e6345
...
...
@@ -23,14 +23,14 @@ typedef void* (*FMalloc)(size_t);
typedef
void
(
*
FFree
)(
void
*
);
extern
void
*
ParseAlloc
(
FMalloc
);
extern
void
Parse
(
void
*
,
int
,
SToken
,
void
*
);
extern
void
ParseFree
(
void
*
,
FFree
);
extern
void
ParseTrace
(
FILE
*
,
char
*
);
extern
void
Parse
(
void
*
,
int
,
SToken
,
void
*
);
extern
void
ParseFree
(
void
*
,
FFree
);
extern
void
ParseTrace
(
FILE
*
,
char
*
);
int32_t
parse
(
SParseContext
*
pParseCxt
,
SQuery
**
pQuery
)
{
SAstCreateContext
cxt
;
initAstCreateContext
(
pParseCxt
,
&
cxt
);
void
*
pParser
=
ParseAlloc
((
FMalloc
)
taosMemoryMalloc
);
void
*
pParser
=
ParseAlloc
((
FMalloc
)
taosMemoryMalloc
);
int32_t
i
=
0
;
while
(
1
)
{
SToken
t0
=
{
0
};
...
...
@@ -38,8 +38,8 @@ int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) {
Parse
(
pParser
,
0
,
t0
,
&
cxt
);
goto
abort_parse
;
}
t0
.
n
=
tGetToken
((
char
*
)
&
cxt
.
pQueryCxt
->
pSql
[
i
],
&
t0
.
type
);
t0
.
z
=
(
char
*
)(
cxt
.
pQueryCxt
->
pSql
+
i
);
t0
.
n
=
tGetToken
((
char
*
)
&
cxt
.
pQueryCxt
->
pSql
[
i
],
&
t0
.
type
);
t0
.
z
=
(
char
*
)(
cxt
.
pQueryCxt
->
pSql
+
i
);
i
+=
t0
.
n
;
switch
(
t0
.
type
)
{
...
...
source/libs/parser/src/parCalcConst.c
浏览文件 @
a68e6345
...
...
@@ -20,8 +20,8 @@
typedef
struct
SCalcConstContext
{
SParseContext
*
pParseCxt
;
SMsgBuf
msgBuf
;
int32_t
code
;
SMsgBuf
msgBuf
;
int32_t
code
;
}
SCalcConstContext
;
static
int32_t
calcConstQuery
(
SCalcConstContext
*
pCxt
,
SNode
*
pStmt
,
bool
subquery
);
...
...
@@ -35,7 +35,7 @@ static int32_t calcConstNode(SNode** pNode) {
return
TSDB_CODE_SUCCESS
;
}
SNode
*
pNew
=
NULL
;
SNode
*
pNew
=
NULL
;
int32_t
code
=
scalarCalculateConstants
(
*
pNode
,
&
pNew
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
*
pNode
=
pNew
;
...
...
@@ -46,7 +46,7 @@ static int32_t calcConstNode(SNode** pNode) {
static
int32_t
calcConstList
(
SNodeList
*
pList
)
{
SNode
*
pNode
=
NULL
;
FOREACH
(
pNode
,
pList
)
{
SNode
*
pNew
=
NULL
;
SNode
*
pNew
=
NULL
;
int32_t
code
=
scalarCalculateConstants
(
pNode
,
&
pNew
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
REPLACE_NODE
(
pNew
);
...
...
@@ -128,7 +128,7 @@ static int32_t rewriteConditionForFromTable(SCalcConstContext* pCxt, SNode* pTab
}
// todo empty table
break
;
}
}
default:
break
;
}
...
...
@@ -196,7 +196,7 @@ static int32_t calcConstProjections(SCalcConstContext* pCxt, SNodeList* pProject
ERASE_NODE
(
pProjections
);
continue
;
}
SNode
*
pNew
=
NULL
;
SNode
*
pNew
=
NULL
;
int32_t
code
=
calcConstProject
(
pProj
,
&
pNew
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
REPLACE_NODE
(
pNew
);
...
...
@@ -281,13 +281,11 @@ static bool isEmptyResultQuery(SNode* pStmt) {
}
int32_t
calculateConstant
(
SParseContext
*
pParseCxt
,
SQuery
*
pQuery
)
{
SCalcConstContext
cxt
=
{
.
pParseCxt
=
pParseCxt
,
.
msgBuf
.
buf
=
pParseCxt
->
pMsg
,
.
msgBuf
.
len
=
pParseCxt
->
msgLen
,
.
code
=
TSDB_CODE_SUCCESS
};
int32_t
code
=
calcConstQuery
(
&
cxt
,
pQuery
->
pRoot
,
false
);
SCalcConstContext
cxt
=
{.
pParseCxt
=
pParseCxt
,
.
msgBuf
.
buf
=
pParseCxt
->
pMsg
,
.
msgBuf
.
len
=
pParseCxt
->
msgLen
,
.
code
=
TSDB_CODE_SUCCESS
};
int32_t
code
=
calcConstQuery
(
&
cxt
,
pQuery
->
pRoot
,
false
);
if
(
TSDB_CODE_SUCCESS
==
code
&&
isEmptyResultQuery
(
pQuery
->
pRoot
))
{
pQuery
->
execMode
=
QUERY_EXEC_MODE_EMPTY_RESULT
;
}
...
...
source/libs/parser/src/parInsert.c
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/parser/src/parInsertData.c
浏览文件 @
a68e6345
...
...
@@ -16,9 +16,9 @@
#include "parInsertData.h"
#include "catalog.h"
#include "parInt.h"
#include "parUtil.h"
#include "querynodes.h"
#include "parInt.h"
#define IS_RAW_PAYLOAD(t) \
(((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 {
SBlockKeyTuple
*
pKeyTuple
;
}
SBlockKeyInfo
;
static
int32_t
rowDataCompar
(
const
void
*
lhs
,
const
void
*
rhs
)
{
TSKEY
left
=
*
(
TSKEY
*
)
lhs
;
TSKEY
right
=
*
(
TSKEY
*
)
rhs
;
static
int32_t
rowDataCompar
(
const
void
*
lhs
,
const
void
*
rhs
)
{
TSKEY
left
=
*
(
TSKEY
*
)
lhs
;
TSKEY
right
=
*
(
TSKEY
*
)
rhs
;
if
(
left
==
right
)
{
return
0
;
...
...
@@ -81,9 +81,9 @@ void setBoundColumnInfo(SParsedDataColInfo* pColList, SSchema* pSchema, col_id_t
pColList
->
extendedVarLen
=
(
uint16_t
)(
nVar
*
sizeof
(
VarDataOffsetT
));
}
int32_t
schemaIdxCompar
(
const
void
*
lhs
,
const
void
*
rhs
)
{
uint16_t
left
=
*
(
uint16_t
*
)
lhs
;
uint16_t
right
=
*
(
uint16_t
*
)
rhs
;
int32_t
schemaIdxCompar
(
const
void
*
lhs
,
const
void
*
rhs
)
{
uint16_t
left
=
*
(
uint16_t
*
)
lhs
;
uint16_t
right
=
*
(
uint16_t
*
)
rhs
;
if
(
left
==
right
)
{
return
0
;
...
...
@@ -92,9 +92,9 @@ int32_t schemaIdxCompar(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
right
=
*
(
uint16_t
*
)
POINTER_SHIFT
(
rhs
,
sizeof
(
uint16_t
));
int32_t
boundIdxCompar
(
const
void
*
lhs
,
const
void
*
rhs
)
{
uint16_t
left
=
*
(
uint16_t
*
)
POINTER_SHIFT
(
lhs
,
sizeof
(
uint16_t
));
uint16_t
right
=
*
(
uint16_t
*
)
POINTER_SHIFT
(
rhs
,
sizeof
(
uint16_t
));
if
(
left
==
right
)
{
return
0
;
...
...
@@ -109,14 +109,14 @@ void destroyBoundColumnInfo(void* pBoundInfo) {
}
SParsedDataColInfo
*
pColList
=
(
SParsedDataColInfo
*
)
pBoundInfo
;
taosMemoryFreeClear
(
pColList
->
boundColumns
);
taosMemoryFreeClear
(
pColList
->
cols
);
taosMemoryFreeClear
(
pColList
->
colIdxInfo
);
}
static
int32_t
createDataBlock
(
size_t
defaultSize
,
int32_t
rowSize
,
int32_t
startOffset
,
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
)
{
static
int32_t
createDataBlock
(
size_t
defaultSize
,
int32_t
rowSize
,
int32_t
startOffset
,
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
)
{
STableDataBlocks
*
dataBuf
=
(
STableDataBlocks
*
)
taosMemoryCalloc
(
1
,
sizeof
(
STableDataBlocks
));
if
(
dataBuf
==
NULL
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
...
...
@@ -137,18 +137,18 @@ static int32_t createDataBlock(size_t defaultSize, int32_t rowSize, int32_t star
}
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
);
SParsedDataColInfo
*
pColInfo
=
&
dataBuf
->
boundColumnInfo
;
SSchema
*
pSchema
=
getTableColumnSchema
(
dataBuf
->
pTableMeta
);
SSchema
*
pSchema
=
getTableColumnSchema
(
dataBuf
->
pTableMeta
);
setBoundColumnInfo
(
pColInfo
,
pSchema
,
dataBuf
->
pTableMeta
->
tableInfo
.
numOfColumns
);
dataBuf
->
ordered
=
true
;
dataBuf
->
prevTS
=
INT64_MIN
;
dataBuf
->
rowSize
=
rowSize
;
dataBuf
->
size
=
startOffset
;
dataBuf
->
vgId
=
dataBuf
->
pTableMeta
->
vgId
;
dataBuf
->
ordered
=
true
;
dataBuf
->
prevTS
=
INT64_MIN
;
dataBuf
->
rowSize
=
rowSize
;
dataBuf
->
size
=
startOffset
;
dataBuf
->
vgId
=
dataBuf
->
pTableMeta
->
vgId
;
assert
(
defaultSize
>
0
&&
pTableMeta
!=
NULL
&&
dataBuf
->
pTableMeta
!=
NULL
);
...
...
@@ -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
,
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
,
SVCreateTbReq
*
pCreateTbReq
)
{
const
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
,
SArray
*
pBlockList
,
SVCreateTbReq
*
pCreateTbReq
)
{
*
dataBlocks
=
NULL
;
STableDataBlocks
**
t1
=
(
STableDataBlocks
**
)
taosHashGet
(
pHashList
,
(
const
char
*
)
&
id
,
sizeof
(
id
));
if
(
t1
!=
NULL
)
{
...
...
@@ -267,14 +268,14 @@ void destroyBlockHashmap(SHashObj* pDataBlockHash) {
}
// data block is disordered, sort it in ascending order
void
sortRemoveDataBlockDupRowsRaw
(
STableDataBlocks
*
dataBuf
)
{
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
dataBuf
->
pData
;
void
sortRemoveDataBlockDupRowsRaw
(
STableDataBlocks
*
dataBuf
)
{
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
dataBuf
->
pData
;
// size is less than the total size, since duplicated rows may be removed yet.
assert
(
pBlocks
->
numOfRows
*
dataBuf
->
rowSize
+
sizeof
(
SSubmitBlk
)
==
dataBuf
->
size
);
if
(
!
dataBuf
->
ordered
)
{
char
*
pBlockData
=
pBlocks
->
data
;
char
*
pBlockData
=
pBlocks
->
data
;
qsort
(
pBlockData
,
pBlocks
->
numOfRows
,
dataBuf
->
rowSize
,
rowDataCompar
);
int32_t
i
=
0
;
...
...
@@ -282,8 +283,8 @@ void sortRemoveDataBlockDupRowsRaw(STableDataBlocks *dataBuf) {
// delete rows with timestamp conflicts
while
(
j
<
pBlocks
->
numOfRows
)
{
TSKEY
ti
=
*
(
TSKEY
*
)(
pBlockData
+
dataBuf
->
rowSize
*
i
);
TSKEY
tj
=
*
(
TSKEY
*
)(
pBlockData
+
dataBuf
->
rowSize
*
j
);
TSKEY
ti
=
*
(
TSKEY
*
)(
pBlockData
+
dataBuf
->
rowSize
*
i
);
TSKEY
tj
=
*
(
TSKEY
*
)(
pBlockData
+
dataBuf
->
rowSize
*
j
);
if
(
ti
==
tj
)
{
++
j
;
...
...
@@ -308,8 +309,8 @@ void sortRemoveDataBlockDupRowsRaw(STableDataBlocks *dataBuf) {
}
// data block is disordered, sort it in ascending order
int
sortRemoveDataBlockDupRows
(
STableDataBlocks
*
dataBuf
,
SBlockKeyInfo
*
pBlkKeyInfo
)
{
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
dataBuf
->
pData
;
int
sortRemoveDataBlockDupRows
(
STableDataBlocks
*
dataBuf
,
SBlockKeyInfo
*
pBlkKeyInfo
)
{
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
dataBuf
->
pData
;
int16_t
nRows
=
pBlocks
->
numOfRows
;
// size is less than the total size, since duplicated rows may be removed yet.
...
...
@@ -317,21 +318,21 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey
// allocate memory
size_t
nAlloc
=
nRows
*
sizeof
(
SBlockKeyTuple
);
if
(
pBlkKeyInfo
->
pKeyTuple
==
NULL
||
pBlkKeyInfo
->
maxBytesAlloc
<
nAlloc
)
{
char
*
tmp
=
taosMemoryRealloc
(
pBlkKeyInfo
->
pKeyTuple
,
nAlloc
);
char
*
tmp
=
taosMemoryRealloc
(
pBlkKeyInfo
->
pKeyTuple
,
nAlloc
);
if
(
tmp
==
NULL
)
{
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
pBlkKeyInfo
->
pKeyTuple
=
(
SBlockKeyTuple
*
)
tmp
;
pBlkKeyInfo
->
pKeyTuple
=
(
SBlockKeyTuple
*
)
tmp
;
pBlkKeyInfo
->
maxBytesAlloc
=
(
int32_t
)
nAlloc
;
}
memset
(
pBlkKeyInfo
->
pKeyTuple
,
0
,
nAlloc
);
int32_t
extendedRowSize
=
getExtendedRowSize
(
dataBuf
);
SBlockKeyTuple
*
pBlkKeyTuple
=
pBlkKeyInfo
->
pKeyTuple
;
char
*
pBlockData
=
pBlocks
->
data
+
pBlocks
->
schemaLen
;
SBlockKeyTuple
*
pBlkKeyTuple
=
pBlkKeyInfo
->
pKeyTuple
;
char
*
pBlockData
=
pBlocks
->
data
+
pBlocks
->
schemaLen
;
int
n
=
0
;
while
(
n
<
nRows
)
{
pBlkKeyTuple
->
skey
=
TD_ROW_KEY
((
STSRow
*
)
pBlockData
);
pBlkKeyTuple
->
skey
=
TD_ROW_KEY
((
STSRow
*
)
pBlockData
);
pBlkKeyTuple
->
payloadAddr
=
pBlockData
;
// next loop
...
...
@@ -374,13 +375,14 @@ int sortRemoveDataBlockDupRows(STableDataBlocks *dataBuf, SBlockKeyInfo *pBlkKey
}
// 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
STableMeta
*
pTableMeta
=
pTableDataBlock
->
pTableMeta
;
STableComInfo
tinfo
=
getTableInfo
(
pTableMeta
);
SSchema
*
pSchema
=
getTableColumnSchema
(
pTableMeta
);
STableMeta
*
pTableMeta
=
pTableDataBlock
->
pTableMeta
;
STableComInfo
tinfo
=
getTableInfo
(
pTableMeta
);
SSchema
*
pSchema
=
getTableColumnSchema
(
pTableMeta
);
int32_t
nonDataLen
=
sizeof
(
SSubmitBlk
)
+
pTableDataBlock
->
createTbReqLen
;
int32_t
nonDataLen
=
sizeof
(
SSubmitBlk
)
+
pTableDataBlock
->
createTbReqLen
;
SSubmitBlk
*
pBlock
=
pDataBlock
;
memcpy
(
pDataBlock
,
pTableDataBlock
->
pData
,
nonDataLen
);
pDataBlock
=
(
char
*
)
pDataBlock
+
nonDataLen
;
...
...
@@ -399,7 +401,7 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SB
if
(
isRawPayload
)
{
SRowBuilder
builder
=
{
0
};
tdSRowInit
(
&
builder
,
pTableMeta
->
sversion
);
tdSRowSetInfo
(
&
builder
,
getNumOfColumns
(
pTableMeta
),
-
1
,
flen
);
...
...
@@ -419,8 +421,8 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, SB
}
}
else
{
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
char
*
payload
=
(
blkKeyTuple
+
i
)
->
payloadAddr
;
TDRowLenT
rowTLen
=
TD_ROW_LEN
((
STSRow
*
)
payload
);
char
*
payload
=
(
blkKeyTuple
+
i
)
->
payloadAddr
;
TDRowLenT
rowTLen
=
TD_ROW_LEN
((
STSRow
*
)
payload
);
memcpy
(
pDataBlock
,
payload
,
rowTLen
);
pDataBlock
=
POINTER_SHIFT
(
pDataBlock
,
rowTLen
);
pBlock
->
dataLen
+=
rowTLen
;
...
...
@@ -438,14 +440,15 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
SArray
*
pVnodeDataBlockList
=
taosArrayInit
(
8
,
POINTER_BYTES
);
STableDataBlocks
**
p
=
taosHashIterate
(
pHashObj
,
NULL
);
STableDataBlocks
*
pOneTableBlock
=
*
p
;
SBlockKeyInfo
blkKeyInfo
=
{
0
};
// share by pOneTableBlock
STableDataBlocks
*
pOneTableBlock
=
*
p
;
SBlockKeyInfo
blkKeyInfo
=
{
0
};
// share by pOneTableBlock
while
(
pOneTableBlock
)
{
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
pOneTableBlock
->
pData
;
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
pOneTableBlock
->
pData
;
if
(
pBlocks
->
numOfRows
>
0
)
{
STableDataBlocks
*
dataBuf
=
NULL
;
int32_t
ret
=
getDataBlockFromList
(
pVnodeDataBlockHashList
,
pOneTableBlock
->
vgId
,
TSDB_PAYLOAD_SIZE
,
INSERT_HEAD_SIZE
,
0
,
pOneTableBlock
->
pTableMeta
,
&
dataBuf
,
pVnodeDataBlockList
,
NULL
);
int32_t
ret
=
getDataBlockFromList
(
pVnodeDataBlockHashList
,
pOneTableBlock
->
vgId
,
TSDB_PAYLOAD_SIZE
,
INSERT_HEAD_SIZE
,
0
,
pOneTableBlock
->
pTableMeta
,
&
dataBuf
,
pVnodeDataBlockList
,
NULL
);
if
(
ret
!=
TSDB_CODE_SUCCESS
)
{
taosHashCleanup
(
pVnodeDataBlockHashList
);
destroyBlockArrayList
(
pVnodeDataBlockList
);
...
...
@@ -490,7 +493,8 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
sizeof
(
STColumn
)
*
getNumOfColumns
(
pOneTableBlock
->
pTableMeta
);
// 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
);
dataBuf
->
size
+=
(
finalLen
+
sizeof
(
SSubmitBlk
));
...
...
@@ -513,15 +517,15 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
return
TSDB_CODE_SUCCESS
;
}
int32_t
allocateMemForSize
(
STableDataBlocks
*
pDataBlock
,
int32_t
allSize
)
{
size_t
remain
=
pDataBlock
->
nAllocSize
-
pDataBlock
->
size
;
int32_t
allocateMemForSize
(
STableDataBlocks
*
pDataBlock
,
int32_t
allSize
)
{
size_t
remain
=
pDataBlock
->
nAllocSize
-
pDataBlock
->
size
;
uint32_t
nAllocSizeOld
=
pDataBlock
->
nAllocSize
;
// expand the allocated size
if
(
remain
<
allSize
)
{
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
)
{
pDataBlock
->
pData
=
tmp
;
memset
(
pDataBlock
->
pData
+
pDataBlock
->
size
,
0
,
pDataBlock
->
nAllocSize
-
pDataBlock
->
size
);
...
...
@@ -535,11 +539,11 @@ int32_t allocateMemForSize(STableDataBlocks *pDataBlock, int32_t allSize) {
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
;
const
int
factor
=
5
;
uint32_t
nAllocSizeOld
=
pDataBlock
->
nAllocSize
;
uint32_t
nAllocSizeOld
=
pDataBlock
->
nAllocSize
;
// expand the allocated size
if
(
remain
<
rowSize
*
factor
)
{
while
(
remain
<
rowSize
*
factor
)
{
...
...
@@ -547,7 +551,7 @@ int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t
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
)
{
pDataBlock
->
pData
=
tmp
;
memset
(
pDataBlock
->
pData
+
pDataBlock
->
size
,
0
,
pDataBlock
->
nAllocSize
-
pDataBlock
->
size
);
...
...
@@ -563,7 +567,7 @@ int32_t allocateMemIfNeed(STableDataBlocks *pDataBlock, int32_t rowSize, int32_t
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
));
tdSRowInit
(
pBuilder
,
schemaVer
);
tdSRowSetExtendedInfo
(
pBuilder
,
pColInfo
->
numOfCols
,
pColInfo
->
numOfBound
,
pColInfo
->
flen
,
pColInfo
->
allNullLen
,
...
...
@@ -571,7 +575,6 @@ int initRowBuilder(SRowBuilder *pBuilder, int16_t schemaVer, SParsedDataColInfo
return
TSDB_CODE_SUCCESS
;
}
int32_t
qResetStmtDataBlock
(
void
*
block
,
bool
keepBuf
)
{
STableDataBlocks
*
pBlock
=
(
STableDataBlocks
*
)
block
;
...
...
@@ -583,32 +586,31 @@ int32_t qResetStmtDataBlock(void* block, bool keepBuf) {
}
memset
(
pBlock
->
pData
,
0
,
sizeof
(
SSubmitBlk
));
}
else
{
pBlock
->
pData
=
NULL
;
pBlock
->
pData
=
NULL
;
}
pBlock
->
ordered
=
true
;
pBlock
->
prevTS
=
INT64_MIN
;
pBlock
->
size
=
sizeof
(
SSubmitBlk
);
pBlock
->
ordered
=
true
;
pBlock
->
prevTS
=
INT64_MIN
;
pBlock
->
size
=
sizeof
(
SSubmitBlk
);
pBlock
->
tsSource
=
-
1
;
pBlock
->
numOfTables
=
1
;
pBlock
->
nAllocSize
=
TSDB_PAYLOAD_SIZE
;
pBlock
->
headerSize
=
pBlock
->
size
;
memset
(
&
pBlock
->
rowBuilder
,
0
,
sizeof
(
pBlock
->
rowBuilder
));
return
TSDB_CODE_SUCCESS
;
}
int32_t
qCloneStmtDataBlock
(
void
**
pDst
,
void
*
pSrc
)
{
*
pDst
=
taosMemoryMalloc
(
sizeof
(
STableDataBlocks
));
if
(
NULL
==
*
pDst
)
{
return
TSDB_CODE_OUT_OF_MEMORY
;
}
memcpy
(
*
pDst
,
pSrc
,
sizeof
(
STableDataBlocks
));
((
STableDataBlocks
*
)(
*
pDst
))
->
cloned
=
true
;
return
qResetStmtDataBlock
(
*
pDst
,
false
);
}
...
...
@@ -618,7 +620,7 @@ int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc) {
return
code
;
}
STableDataBlocks
*
pBlock
=
(
STableDataBlocks
*
)
*
pDst
;
STableDataBlocks
*
pBlock
=
(
STableDataBlocks
*
)
*
pDst
;
pBlock
->
pData
=
taosMemoryMalloc
(
pBlock
->
nAllocSize
);
if
(
NULL
==
pBlock
->
pData
)
{
qFreeStmtDataBlock
(
pBlock
);
...
...
@@ -630,7 +632,6 @@ int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc) {
return
TSDB_CODE_SUCCESS
;
}
void
qFreeStmtDataBlock
(
void
*
pDataBlock
)
{
if
(
pDataBlock
==
NULL
)
{
return
;
...
...
@@ -650,4 +651,3 @@ void qDestroyStmtDataBlock(void* pBlock) {
pDataBlock
->
cloned
=
false
;
destroyDataBlock
(
pDataBlock
);
}
source/libs/parser/src/parTokenizer.c
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/parser/src/parTranslater.c
浏览文件 @
a68e6345
...
...
@@ -591,25 +591,27 @@ static EDealRes haveAggFunction(SNode* pNode, void* pContext) {
}
static
EDealRes
translateFunction
(
STranslateContext
*
pCxt
,
SFunctionNode
*
pFunc
)
{
SFmGetFuncInfoParam
param
=
{
.
pCtg
=
pCxt
->
pParseCxt
->
pCatalog
,
.
pRpc
=
pCxt
->
pParseCxt
->
pTransporter
,
.
pMgmtEps
=
&
pCxt
->
pParseCxt
->
mgmtEpSet
,
.
pErrBuf
=
pCxt
->
msgBuf
.
buf
,
.
errBufLen
=
pCxt
->
msgBuf
.
len
};
SFmGetFuncInfoParam
param
=
{.
pCtg
=
pCxt
->
pParseCxt
->
pCatalog
,
.
pRpc
=
pCxt
->
pParseCxt
->
pTransporter
,
.
pMgmtEps
=
&
pCxt
->
pParseCxt
->
mgmtEpSet
,
.
pErrBuf
=
pCxt
->
msgBuf
.
buf
,
.
errBufLen
=
pCxt
->
msgBuf
.
len
};
pCxt
->
errCode
=
fmGetFuncInfo
(
&
param
,
pFunc
);
if
(
TSDB_CODE_SUCCESS
!=
pCxt
->
errCode
)
{
return
DEAL_RES_ERROR
;
}
if
(
fmIsAggFunc
(
pFunc
->
funcId
)
&&
beforeHaving
(
pCxt
->
currClause
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
);
}
bool
haveAggFunc
=
false
;
nodesWalkExprs
(
pFunc
->
pParameterList
,
haveAggFunction
,
&
haveAggFunc
);
if
(
haveAggFunc
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_AGG_FUNC_NESTING
);
if
(
fmIsAggFunc
(
pFunc
->
funcId
))
{
if
(
beforeHaving
(
pCxt
->
currClause
))
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION
);
}
bool
haveAggFunc
=
false
;
nodesWalkExprs
(
pFunc
->
pParameterList
,
haveAggFunction
,
&
haveAggFunc
);
if
(
haveAggFunc
)
{
return
generateDealNodeErrMsg
(
pCxt
,
TSDB_CODE_PAR_AGG_FUNC_NESTING
);
}
pCxt
->
pCurrStmt
->
hasAggFuncs
=
true
;
}
return
DEAL_RES_CONTINUE
;
}
...
...
@@ -771,7 +773,7 @@ static int32_t addMnodeToVgroupList(const SEpSet* pEpSet, SArray** pVgroupList)
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
SVgroupInfo
vg
=
{
.
vgId
=
MNODE_HANDLE
};
SVgroupInfo
vg
=
{
.
vgId
=
MNODE_HANDLE
};
memcpy
(
&
vg
.
epSet
,
pEpSet
,
sizeof
(
SEpSet
));
taosArrayPush
(
*
pVgroupList
,
&
vg
);
return
TSDB_CODE_SUCCESS
;
...
...
@@ -787,7 +789,7 @@ static int32_t setSysTableVgroupList(STranslateContext* pCxt, SName* pName, SRea
if
(
'\0'
!=
pRealTable
->
qualDbName
[
0
])
{
// todo release after mnode can be processed
// if (0 != strcmp(pRealTable->qualDbName, TSDB_INFORMATION_SCHEMA_DB)) {
code
=
getDBVgInfo
(
pCxt
,
pRealTable
->
qualDbName
,
&
vgroupList
);
code
=
getDBVgInfo
(
pCxt
,
pRealTable
->
qualDbName
,
&
vgroupList
);
// }
}
else
{
code
=
getDBVgInfoImpl
(
pCxt
,
pName
,
&
vgroupList
);
...
...
@@ -3481,7 +3483,7 @@ static int32_t buildKVRowForBindTags(STranslateContext* pCxt, SCreateSubTableCla
return
generateSyntaxErrMsg
(
&
pCxt
->
msgBuf
,
TSDB_CODE_PAR_INVALID_TAG_NAME
,
pCol
->
colName
);
}
SValueNode
*
pVal
=
NULL
;
int32_t
code
=
translateTagVal
(
pCxt
,
pNode
,
&
pVal
);
int32_t
code
=
translateTagVal
(
pCxt
,
pNode
,
&
pVal
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
NULL
==
pVal
)
{
pVal
=
(
SValueNode
*
)
pNode
;
...
...
@@ -3511,7 +3513,7 @@ static int32_t buildKVRowForAllTags(STranslateContext* pCxt, SCreateSubTableClau
int32_t
index
=
0
;
FOREACH
(
pNode
,
pStmt
->
pValsOfTags
)
{
SValueNode
*
pVal
=
NULL
;
int32_t
code
=
translateTagVal
(
pCxt
,
pNode
,
&
pVal
);
int32_t
code
=
translateTagVal
(
pCxt
,
pNode
,
&
pVal
);
if
(
TSDB_CODE_SUCCESS
==
code
)
{
if
(
NULL
==
pVal
)
{
pVal
=
(
SValueNode
*
)
pNode
;
...
...
source/libs/parser/src/parUtil.c
浏览文件 @
a68e6345
...
...
@@ -63,13 +63,13 @@ static char* getSyntaxErrFormat(int32_t errCode) {
case
TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR
:
return
"Corresponding super table not in this db"
;
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
:
return
"Invalid option %s: %s"
;
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
:
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
:
return
"Invalid number of keep options"
;
case
TSDB_CODE_PAR_INVALID_KEEP_ORDER
:
...
...
@@ -194,20 +194,22 @@ STableMeta* tableMetaDup(const STableMeta* pTableMeta) {
return
p
;
}
SSchema
*
getTableColumnSchema
(
const
STableMeta
*
pTableMeta
)
{
SSchema
*
getTableColumnSchema
(
const
STableMeta
*
pTableMeta
)
{
assert
(
pTableMeta
!=
NULL
);
return
(
SSchema
*
)
pTableMeta
->
schema
;
return
(
SSchema
*
)
pTableMeta
->
schema
;
}
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
];
}
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
);
}
...
...
@@ -228,40 +230,40 @@ STableComInfo getTableInfo(const STableMeta* pTableMeta) {
}
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
;
for
(
uint32_t
k
=
1
;
k
<
len
-
1
;
++
k
)
{
if
(
j
>=
dlen
)
{
dst
[
j
-
1
]
=
'\0'
;
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
];
j
++
;
k
++
;
continue
;
}
if
(
src
[
k
]
==
'\\'
)
{
// deal with escape character
if
(
src
[
k
+
1
]
==
'n'
)
{
if
(
src
[
k
]
==
'\\'
)
{
// deal with escape character
if
(
src
[
k
+
1
]
==
'n'
)
{
dst
[
j
]
=
'\n'
;
}
else
if
(
src
[
k
+
1
]
==
'r'
)
{
}
else
if
(
src
[
k
+
1
]
==
'r'
)
{
dst
[
j
]
=
'\r'
;
}
else
if
(
src
[
k
+
1
]
==
't'
)
{
}
else
if
(
src
[
k
+
1
]
==
't'
)
{
dst
[
j
]
=
'\t'
;
}
else
if
(
src
[
k
+
1
]
==
'\\'
)
{
}
else
if
(
src
[
k
+
1
]
==
'\\'
)
{
dst
[
j
]
=
'\\'
;
}
else
if
(
src
[
k
+
1
]
==
'\''
)
{
}
else
if
(
src
[
k
+
1
]
==
'\''
)
{
dst
[
j
]
=
'\''
;
}
else
if
(
src
[
k
+
1
]
==
'"'
)
{
}
else
if
(
src
[
k
+
1
]
==
'"'
)
{
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
+
1
];
}
else
{
dst
[
j
]
=
src
[
k
+
1
];
dst
[
j
]
=
src
[
k
+
1
];
}
else
{
dst
[
j
]
=
src
[
k
+
1
];
}
j
++
;
k
++
;
...
...
@@ -275,7 +277,7 @@ int32_t trimString(const char* src, int32_t len, char* dst, int32_t dlen) {
return
j
;
}
static
bool
isValidateTag
(
char
*
input
)
{
static
bool
isValidateTag
(
char
*
input
)
{
if
(
!
input
)
return
false
;
for
(
size_t
i
=
0
;
i
<
strlen
(
input
);
++
i
)
{
if
(
isprint
(
input
[
i
])
==
0
)
return
false
;
...
...
@@ -283,30 +285,30 @@ static bool isValidateTag(char *input) {
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
uint8_t
jsonNULL
=
TSDB_DATA_TYPE_NULL
;
int
jsonIndex
=
startColId
+
1
;
if
(
!
json
||
strcasecmp
(
json
,
TSDB_DATA_NULL_STR_L
)
==
0
){
int
jsonIndex
=
startColId
+
1
;
if
(
!
json
||
strcasecmp
(
json
,
TSDB_DATA_NULL_STR_L
)
==
0
)
{
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
,
&
jsonNULL
,
CHAR_BYTES
);
return
TSDB_CODE_SUCCESS
;
}
// set json real data
cJSON
*
root
=
cJSON_Parse
(
json
);
if
(
root
==
NULL
){
cJSON
*
root
=
cJSON_Parse
(
json
);
if
(
root
==
NULL
)
{
return
buildSyntaxErrMsg
(
pMsgBuf
,
"json parse error"
,
json
);
}
int
size
=
cJSON_GetArraySize
(
root
);
if
(
!
cJSON_IsObject
(
root
))
{
if
(
!
cJSON_IsObject
(
root
))
{
return
buildSyntaxErrMsg
(
pMsgBuf
,
"json error invalide value"
,
json
);
}
int
retCode
=
0
;
char
*
tagKV
=
NULL
;
int
retCode
=
0
;
char
*
tagKV
=
NULL
;
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
);
if
(
!
item
)
{
qError
(
"json inner error:%d"
,
i
);
...
...
@@ -314,40 +316,41 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
goto
end
;
}
char
*
jsonKey
=
item
->
string
;
if
(
!
isValidateTag
(
jsonKey
))
{
char
*
jsonKey
=
item
->
string
;
if
(
!
isValidateTag
(
jsonKey
))
{
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"json key not validate"
,
jsonKey
);
goto
end
;
}
// if(strlen(jsonKey) > TSDB_MAX_JSON_KEY_LEN){
// tscError("json key too long error");
// retCode = tscSQLSyntaxErrMsg(errMsg, "json key too long, more than 256", NULL);
// goto end;
// }
// if(strlen(jsonKey) > TSDB_MAX_JSON_KEY_LEN){
// tscError("json key too long error");
// retCode = tscSQLSyntaxErrMsg(errMsg, "json key too long, more than 256", NULL);
// goto end;
// }
size_t
keyLen
=
strlen
(
jsonKey
);
if
(
keyLen
==
0
||
taosHashGet
(
keyHash
,
jsonKey
,
keyLen
)
!=
NULL
)
{
if
(
keyLen
==
0
||
taosHashGet
(
keyHash
,
jsonKey
,
keyLen
)
!=
NULL
)
{
continue
;
}
// key: keyLen + VARSTR_HEADER_SIZE, value type: CHAR_BYTES, value reserved: LONG_BYTES
tagKV
=
taosMemoryCalloc
(
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
+
LONG_BYTES
,
1
);
if
(
!
tagKV
)
{
if
(
!
tagKV
)
{
retCode
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
}
strncpy
(
varDataVal
(
tagKV
),
jsonKey
,
keyLen
);
varDataSetLen
(
tagKV
,
keyLen
);
if
(
taosHashGetSize
(
keyHash
)
==
0
)
{
if
(
taosHashGetSize
(
keyHash
)
==
0
)
{
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
char
*
jsonValue
=
item
->
valuestring
;
if
(
item
->
type
==
cJSON_String
)
{
// add json value format: type|data
char
*
jsonValue
=
item
->
valuestring
;
int32_t
valLen
=
(
int32_t
)
strlen
(
jsonValue
);
int32_t
totalLen
=
keyLen
+
VARSTR_HEADER_SIZE
+
valLen
*
TSDB_NCHAR_SIZE
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
;
char
*
tmp
=
taosMemoryRealloc
(
tagKV
,
totalLen
);
if
(
!
tmp
)
{
char
*
tmp
=
taosMemoryRealloc
(
tagKV
,
totalLen
);
if
(
!
tmp
)
{
retCode
=
TSDB_CODE_TSC_OUT_OF_MEMORY
;
goto
end
;
}
...
...
@@ -356,44 +359,47 @@ int parseJsontoTagData(const char* json, SKVRowBuilder* kvRowBuilder, SMsgBuf* p
char
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
*
valueType
=
TSDB_DATA_TYPE_NCHAR
;
if
(
valLen
>
0
&&
!
taosMbsToUcs4
(
jsonValue
,
valLen
,
(
TdUcs4
*
)
varDataVal
(
valueData
),
(
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
));
(
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
));
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"charset convert json error"
,
jsonValue
);
goto
end
;
}
varDataSetLen
(
valueData
,
valLen
);
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
totalLen
);
}
else
if
(
item
->
type
==
cJSON_Number
)
{
if
(
!
isfinite
(
item
->
valuedouble
))
{
}
else
if
(
item
->
type
==
cJSON_Number
)
{
if
(
!
isfinite
(
item
->
valuedouble
))
{
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
;
}
char
*
valueType
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
);
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
;
if
(
*
valueType
==
TSDB_DATA_TYPE_DOUBLE
)
*
((
double
*
)
valueData
)
=
item
->
valuedouble
;
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
){
*
valueType
=
(
item
->
valuedouble
-
(
int64_t
)(
item
->
valuedouble
)
==
0
)
?
TSDB_DATA_TYPE_BIGINT
:
TSDB_DATA_TYPE_DOUBLE
;
if
(
*
valueType
==
TSDB_DATA_TYPE_DOUBLE
)
*
((
double
*
)
valueData
)
=
item
->
valuedouble
;
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
*
valueData
=
POINTER_SHIFT
(
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
*
valueType
=
TSDB_DATA_TYPE_BOOL
;
*
valueData
=
(
char
)(
item
->
valueint
);
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
);
*
valueType
=
TSDB_DATA_TYPE_NULL
;
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
++
,
tagKV
,
keyLen
+
VARSTR_HEADER_SIZE
+
CHAR_BYTES
);
}
else
{
}
else
{
retCode
=
buildSyntaxErrMsg
(
pMsgBuf
,
"invalidate json value"
,
json
);
goto
end
;
}
}
if
(
taosHashGetSize
(
keyHash
)
==
0
)
{
// set json NULL true
if
(
taosHashGetSize
(
keyHash
)
==
0
)
{
// set json NULL true
tdAddColToKVRow
(
kvRowBuilder
,
jsonIndex
,
&
jsonNULL
,
CHAR_BYTES
);
}
...
...
source/libs/parser/src/parser.c
浏览文件 @
a68e6345
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
#include "parser.h"
#include "os.h"
#include "parInt.h"
#include "parToken.h"
...
...
@@ -23,11 +23,11 @@ bool isInsertSql(const char* pStr, size_t length) {
if
(
NULL
==
pStr
)
{
return
false
;
}
int32_t
index
=
0
;
do
{
SToken
t0
=
tStrGetToken
((
char
*
)
pStr
,
&
index
,
false
);
SToken
t0
=
tStrGetToken
((
char
*
)
pStr
,
&
index
,
false
);
if
(
t0
.
type
!=
TK_NK_LP
)
{
return
t0
.
type
==
TK_INSERT
||
t0
.
type
==
TK_IMPORT
;
}
...
...
source/libs/parser/test/mockCatalog.cpp
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/parser/test/mockCatalogService.cpp
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/parser/test/mockCatalogService.h
浏览文件 @
a68e6345
...
...
@@ -20,17 +20,15 @@
#include <string>
#include <vector>
#define ALLOW_FORBID_FUNC
#include "catalog.h"
class
ITableBuilder
{
public:
ITableBuilder
&
addTag
(
const
std
::
string
&
name
,
int8_t
type
)
{
return
addColumn
(
name
,
type
,
tDataTypes
[
type
].
bytes
);
}
public:
ITableBuilder
&
addTag
(
const
std
::
string
&
name
,
int8_t
type
)
{
return
addColumn
(
name
,
type
,
tDataTypes
[
type
].
bytes
);
}
ITableBuilder
&
addTag
(
const
std
::
string
&
name
,
int8_t
type
,
int32_t
bytes
)
{
return
addColumn
(
name
,
type
,
bytes
);
}
ITableBuilder
&
addTag
(
const
std
::
string
&
name
,
int8_t
type
,
int32_t
bytes
)
{
return
addColumn
(
name
,
type
,
bytes
);
}
ITableBuilder
&
addColumn
(
const
std
::
string
&
name
,
int8_t
type
)
{
return
addColumn
(
name
,
type
,
tDataTypes
[
type
].
bytes
);
...
...
@@ -39,24 +37,23 @@ public:
virtual
ITableBuilder
&
addColumn
(
const
std
::
string
&
name
,
int8_t
type
,
int32_t
bytes
)
=
0
;
virtual
ITableBuilder
&
setVgid
(
int16_t
vgid
)
=
0
;
virtual
ITableBuilder
&
setPrecision
(
uint8_t
precision
)
=
0
;
virtual
void
done
()
=
0
;
virtual
void
done
()
=
0
;
};
struct
MockTableMeta
{
~
MockTableMeta
()
{
taosMemoryFree
(
schema
);
}
~
MockTableMeta
()
{
taosMemoryFree
(
schema
);
}
STableMeta
*
schema
;
STableMeta
*
schema
;
std
::
vector
<
SVgroupInfo
>
vgs
;
};
class
MockCatalogServiceImpl
;
class
MockCatalogService
{
public:
public:
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
showTables
()
const
;
std
::
shared_ptr
<
MockTableMeta
>
getTableMeta
(
const
std
::
string
&
db
,
const
std
::
string
&
tbname
)
const
;
...
...
@@ -65,7 +62,7 @@ public:
int32_t
catalogGetTableHashVgroup
(
const
SName
*
pTableName
,
SVgroupInfo
*
vgInfo
)
const
;
int32_t
catalogGetTableDistVgInfo
(
const
SName
*
pTableName
,
SArray
**
pVgList
)
const
;
private:
private:
std
::
unique_ptr
<
MockCatalogServiceImpl
>
impl_
;
};
...
...
source/libs/parser/test/parserAstTest.cpp
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/parser/test/parserInsertTest.cpp
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/parser/test/parserTestMain.cpp
浏览文件 @
a68e6345
...
...
@@ -13,9 +13,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <getopt.h>
#include <gtest/gtest.h>
...
...
@@ -23,16 +23,16 @@
#ifdef WINDOWS
#define TD_USE_WINSOCK
#endif
#include "os.h"
#include "parserTestUtil.h"
#include "parToken.h"
#include "functionMgt.h"
#include "mockCatalog.h"
#include "os.h"
#include "parToken.h"
#include "parserTestUtil.h"
bool
g_isDump
=
false
;
class
ParserEnv
:
public
testing
::
Environment
{
public:
public:
virtual
void
SetUp
()
{
initMetaDataEnv
();
generateMetaData
();
...
...
@@ -49,12 +49,9 @@ public:
};
static
void
parseArg
(
int
argc
,
char
*
argv
[])
{
int
opt
=
0
;
const
char
*
optstring
=
""
;
static
struct
option
long_options
[]
=
{
{
"dump"
,
no_argument
,
NULL
,
'd'
},
{
0
,
0
,
0
,
0
}
};
int
opt
=
0
;
const
char
*
optstring
=
""
;
static
struct
option
long_options
[]
=
{{
"dump"
,
no_argument
,
NULL
,
'd'
},
{
0
,
0
,
0
,
0
}};
while
((
opt
=
getopt_long
(
argc
,
argv
,
optstring
,
long_options
,
NULL
))
!=
-
1
)
{
switch
(
opt
)
{
case
'd'
:
...
...
@@ -67,8 +64,8 @@ static void parseArg(int argc, char* argv[]) {
}
int
main
(
int
argc
,
char
*
argv
[])
{
testing
::
AddGlobalTestEnvironment
(
new
ParserEnv
());
testing
::
InitGoogleTest
(
&
argc
,
argv
);
testing
::
AddGlobalTestEnvironment
(
new
ParserEnv
());
testing
::
InitGoogleTest
(
&
argc
,
argv
);
parseArg
(
argc
,
argv
);
return
RUN_ALL_TESTS
();
return
RUN_ALL_TESTS
();
}
source/libs/planner/inc/planInt.h
浏览文件 @
a68e6345
...
...
@@ -26,12 +26,12 @@ extern "C" {
#define QUERY_POLICY_HYBRID 2
#define QUERY_POLICY_QNODE 3
#define planFatal(param, ...)
qFatal("PLAN: " param, __VA_ARGS__)
#define planError(param, ...)
qError("PLAN: " param, __VA_ARGS__)
#define planWarn(param, ...)
qWarn("PLAN: " param, __VA_ARGS__)
#define planInfo(param, ...)
qInfo("PLAN: " param, __VA_ARGS__)
#define planDebug(param, ...)
qDebug("PLAN: " param, __VA_ARGS__)
#define planTrace(param, ...)
qTrace("PLAN: " param, __VA_ARGS__)
#define planFatal(param, ...) qFatal("PLAN: " param, __VA_ARGS__)
#define planError(param, ...) qError("PLAN: " param, __VA_ARGS__)
#define planWarn(param, ...) qWarn("PLAN: " param, __VA_ARGS__)
#define planInfo(param, ...) qInfo("PLAN: " param, __VA_ARGS__)
#define planDebug(param, ...) qDebug("PLAN: " param, __VA_ARGS__)
#define planTrace(param, ...) qTrace("PLAN: " param, __VA_ARGS__)
int32_t
createLogicPlan
(
SPlanContext
*
pCxt
,
SLogicNode
**
pLogicNode
);
int32_t
optimizeLogicPlan
(
SPlanContext
*
pCxt
,
SLogicNode
*
pLogicNode
);
...
...
source/libs/planner/src/planLogicCreater.c
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/planner/src/planOptimizer.c
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/planner/src/planPhysiCreater.c
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/planner/src/planScaleOut.c
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/planner/src/planSpliter.c
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/planner/src/planner.c
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/planner/test/planOptTest.cpp
浏览文件 @
a68e6345
...
...
@@ -18,9 +18,7 @@
using
namespace
std
;
class
PlanOptimizeTest
:
public
PlannerTestBase
{
};
class
PlanOptimizeTest
:
public
PlannerTestBase
{};
TEST_F
(
PlanOptimizeTest
,
orderByPrimaryKey
)
{
useDb
(
"root"
,
"test"
);
...
...
source/libs/planner/test/planSTableTest.cpp
0 → 100644
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/planner/test/planSetOpTest.cpp
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/planner/test/planStmtTest.cpp
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/planner/test/planTestMain.cpp
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/planner/test/planTestUtil.cpp
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/planner/test/planTestUtil.h
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
source/libs/planner/test/plannerTest.cpp
浏览文件 @
a68e6345
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录