Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
慢慢CG
TDengine
提交
9ed5a42c
T
TDengine
项目概览
慢慢CG
/
TDengine
与 Fork 源项目一致
Fork自
taosdata / TDengine
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
9ed5a42c
编写于
7月 07, 2021
作者:
C
Cary Xu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
tsc raw data combination restructure
上级
e94bb935
变更
10
展开全部
隐藏空白更改
内联
并排
Showing
10 changed file
with
774 addition
and
168 deletion
+774
-168
src/client/inc/tscUtil.h
src/client/inc/tscUtil.h
+13
-18
src/client/inc/tsclient.h
src/client/inc/tsclient.h
+42
-4
src/client/src/tscParseInsert.c
src/client/src/tscParseInsert.c
+489
-48
src/client/src/tscUtil.c
src/client/src/tscUtil.c
+94
-81
src/common/inc/tdataformat.h
src/common/inc/tdataformat.h
+105
-1
src/common/src/tdataformat.c
src/common/src/tdataformat.c
+15
-0
src/cq/src/cqMain.c
src/cq/src/cqMain.c
+1
-1
src/tsdb/src/tsdbCommit.c
src/tsdb/src/tsdbCommit.c
+10
-10
src/tsdb/src/tsdbMain.c
src/tsdb/src/tsdbMain.c
+3
-3
src/tsdb/tests/tsdbTests.cpp
src/tsdb/tests/tsdbTests.cpp
+2
-2
未找到文件。
src/client/inc/tscUtil.h
浏览文件 @
9ed5a42c
...
...
@@ -40,7 +40,8 @@ extern "C" {
#define UTIL_TABLE_IS_TMP_TABLE(metaInfo) \
(((metaInfo)->pTableMeta != NULL) && ((metaInfo)->pTableMeta->tableType == TSDB_TEMP_TABLE))
#define KvRowNColsThresh 1 // default 1200. TODO: only for test, restore to default value after test finished
#define KvRowNColsThresh 1 // default 1200
#define KVRowRatio 0.85 // for NonVarType, we get value from SDataRow directly, while needs readdressing for SKVRow
#pragma pack(push,1)
// this struct is transfered as binary, padding two bytes to avoid
...
...
@@ -96,11 +97,21 @@ typedef struct SVgroupTableInfo {
SArray
*
itemList
;
// SArray<STableIdInfo>
}
SVgroupTableInfo
;
typedef
struct
SBlockKeyTuple
{
TSKEY
skey
;
void
*
payloadAddr
;
}
SBlockKeyTuple
;
typedef
struct
SBlockKeyInfo
{
int32_t
nBytesAlloc
;
SBlockKeyTuple
*
pKeyTuple
;
}
SBlockKeyInfo
;
int32_t
converToStr
(
char
*
str
,
int
type
,
void
*
buf
,
int32_t
bufSize
,
int32_t
*
len
);
int32_t
tscCreateDataBlock
(
size_t
initialSize
,
int32_t
rowSize
,
int32_t
startOffset
,
SName
*
name
,
STableMeta
*
pTableMeta
,
STableDataBlocks
**
dataBlocks
);
void
tscDestroyDataBlock
(
STableDataBlocks
*
pDataBlock
,
bool
removeMeta
);
void
tscSortRemoveDataBlockDupRows
(
STableDataBlocks
*
dataBuf
);
int
tscSortRemoveDataBlockDupRows
(
STableDataBlocks
*
dataBuf
,
SBlockKeyInfo
*
pBlkKeyInfo
);
void
tscDestroyBoundColumnInfo
(
SParsedDataColInfo
*
pColInfo
);
void
doRetrieveSubqueryData
(
SSchedMsg
*
pMsg
);
...
...
@@ -343,22 +354,6 @@ char* strdup_throw(const char* str);
bool
vgroupInfoIdentical
(
SNewVgroupInfo
*
pExisted
,
SVgroupMsg
*
src
);
SNewVgroupInfo
createNewVgroupInfo
(
SVgroupMsg
*
pVgroupMsg
);
typedef
struct
{
// for SDataRow
SSchema
*
pSchema
;
int16_t
sversion
;
int32_t
flen
;
// for SKVRow
uint16_t
nCols
;
uint16_t
size
;
void
*
buf
;
void
*
pDataBlock
;
SSubmitBlk
*
pSubmitBlk
;
}
SMemRowBuilder
;
SMemRow
tdGenMemRowFromBuilder
(
SMemRowBuilder
*
pBuilder
);
#ifdef __cplusplus
}
#endif
...
...
src/client/inc/tsclient.h
浏览文件 @
9ed5a42c
...
...
@@ -95,6 +95,43 @@ typedef struct SParsedDataColInfo {
SBoundColumn
*
cols
;
}
SParsedDataColInfo
;
typedef
struct
{
// for SDataRow
SSchema
*
pSchema
;
int16_t
sversion
;
int32_t
flen
;
// for SKVRow
uint16_t
nCols
;
uint16_t
size
;
void
*
buf
;
void
*
pDataBlock
;
SSubmitBlk
*
pSubmitBlk
;
uint16_t
allNullLen
;
}
SMemRowBuilder
;
int
FORCE_INLINE
initSMemRowBuilder
(
SMemRowBuilder
*
pBuilder
,
SSchema
*
pSSchema
,
uint16_t
nCols
,
uint16_t
allNullColsLen
)
{
ASSERT
(
nCols
>
0
);
pBuilder
->
pSchema
=
pSSchema
;
pBuilder
->
allNullLen
=
allNullColsLen
;
// TODO: get allNullColsLen when creating or altering table meta
if
(
pBuilder
->
allNullLen
==
0
)
{
for
(
uint16_t
i
=
0
;
i
<
nCols
;
++
i
)
{
uint8_t
type
=
pSSchema
[
i
].
type
;
int32_t
typeLen
=
TYPE_BYTES
[
type
];
ASSERT
(
typeLen
>
0
);
pBuilder
->
allNullLen
+=
typeLen
;
if
(
TSDB_DATA_TYPE_BINARY
==
type
)
{
pBuilder
->
allNullLen
+=
(
sizeof
(
VarDataLenT
)
+
CHAR_BYTES
);
}
else
if
(
TSDB_DATA_TYPE_NCHAR
==
type
)
{
int
len
=
sizeof
(
VarDataLenT
)
+
TSDB_NCHAR_SIZE
;
pBuilder
->
allNullLen
+=
len
;
}
}
}
return
0
;
}
typedef
struct
STableDataBlocks
{
SName
tableName
;
int8_t
tsSource
;
// where does the UNIX timestamp come from, server or client
...
...
@@ -109,12 +146,13 @@ typedef struct STableDataBlocks {
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
;
SParsedDataColInfo
boundColumnInfo
;
SParsedDataColInfo
boundColumnInfo
;
// for parameter ('?') binding
uint32_t
numOfAllocedParams
;
uint32_t
numOfParams
;
SParamInfo
*
params
;
uint32_t
numOfAllocedParams
;
uint32_t
numOfParams
;
SParamInfo
*
params
;
SMemRowBuilder
rowBuilder
;
}
STableDataBlocks
;
typedef
struct
{
...
...
src/client/src/tscParseInsert.c
浏览文件 @
9ed5a42c
此差异已折叠。
点击以展开。
src/client/src/tscUtil.c
浏览文件 @
9ed5a42c
...
...
@@ -1639,61 +1639,29 @@ int32_t tscGetDataBlockFromList(SHashObj* pHashList, int64_t id, int32_t size, i
return
TSDB_CODE_SUCCESS
;
}
static
FORCE_INLINE
uint8_t
checkTdRowType
(
SSchema
*
pSchema
,
void
*
pData
,
int32_t
nCols
,
int32_t
flen
,
uint16_t
*
nColsNotNull
)
{
ASSERT
(
pData
!=
NULL
);
if
(
nCols
<
KvRowNColsThresh
)
{
return
SMEM_ROW_DATA
;
}
int32_t
dataRowLength
=
flen
;
int32_t
kvRowLength
=
TD_MEM_ROW_KV_VER_SIZE
;
uint16_t
nColsNull
=
0
;
char
*
p
=
(
char
*
)
pData
;
for
(
int
i
=
0
;
i
<
nCols
;
++
i
)
{
if
(
IS_VAR_DATA_TYPE
(
pSchema
[
i
].
type
))
{
dataRowLength
+=
varDataTLen
(
p
);
if
(
!
isNull
(
p
,
pSchema
[
i
].
type
))
{
kvRowLength
+=
(
sizeof
(
SColIdx
)
+
varDataTLen
(
p
));
}
else
{
++
nColsNull
;
}
}
else
{
if
(
!
isNull
(
p
,
pSchema
[
i
].
type
))
{
kvRowLength
+=
(
sizeof
(
SColIdx
)
+
TYPE_BYTES
[
pSchema
[
i
].
type
]);
}
else
{
++
nColsNull
;
}
}
// next column
p
+=
pSchema
[
i
].
bytes
;
}
tscDebug
(
"nColsNull %d, nCols: %d, kvRowLen: %d, dataRowLen: %d"
,
(
int32_t
)
nColsNull
,
nCols
,
kvRowLength
,
dataRowLength
);
if
(
kvRowLength
<
dataRowLength
)
{
if
(
nColsNotNull
)
{
*
nColsNotNull
=
nCols
-
nColsNull
;
}
return
SMEM_ROW_KV
;
}
return
SMEM_ROW_DATA
;
}
SMemRow
tdGenMemRowFromBuilder
(
SMemRowBuilder
*
pBuilder
)
{
static
SMemRow
tdGenMemRowFromBuilder
(
SMemRowBuilder
*
pBuilder
)
{
SSchema
*
pSchema
=
pBuilder
->
pSchema
;
char
*
p
=
(
char
*
)
pBuilder
->
buf
;
int
toffset
=
0
;
if
(
pBuilder
->
nCols
<=
0
){
uint16_t
nCols
=
pBuilder
->
nCols
;
// RawRow payload structure:
// |<---------- header ------------->|<------- column data array ------->|
// |SMemRowType| dataLen | nCols | colId | colType | value |...|...|
// +-----------+----------+----------+---------------------------------->|
// | uint8_t | uint16_t | uint16_t | int16_t | uint8_t | ??? |...|...|
// +-----------+----------+----------+---------------------------------->|
uint8_t
memRowType
=
payloadType
(
p
);
uint16_t
nColsNotNull
=
payloadNCols
(
p
);
if
(
pBuilder
->
nCols
<=
0
||
nColsNotNull
<=
0
)
{
return
NULL
;
}
ASSERT
(
nColsNotNull
<=
nCols
);
uint16_t
nColsNotNull
=
0
;
uint8_t
memRowType
=
checkTdRowType
(
pSchema
,
p
,
pBuilder
->
nCols
,
pBuilder
->
flen
,
&
nColsNotNull
);
// nColsNotNull = pBuilder->nCols;
SMemRow
*
memRow
=
(
SMemRow
)
pBuilder
->
pDataBlock
;
memRowSetType
(
memRow
,
memRowType
);
...
...
@@ -1702,14 +1670,41 @@ SMemRow tdGenMemRowFromBuilder(SMemRowBuilder* pBuilder) {
dataRowSetLen
(
trow
,
(
uint16_t
)(
TD_DATA_ROW_HEAD_SIZE
+
pBuilder
->
flen
));
dataRowSetVersion
(
trow
,
pBuilder
->
sversion
);
p
=
(
char
*
)
pBuilder
->
buf
;
for
(
int32_t
j
=
0
;
j
<
pBuilder
->
nCols
;
++
j
)
{
tdAppendColVal
(
trow
,
p
,
pSchema
[
j
].
type
,
pSchema
[
j
].
bytes
,
toffset
);
p
=
(
char
*
)
payloadBody
(
pBuilder
->
buf
);
uint16_t
i
=
0
,
j
=
0
;
while
(
j
<
pBuilder
->
nCols
)
{
if
(
i
>=
nColsNotNull
)
{
break
;
}
int16_t
colId
=
*
(
int16_t
*
)
p
;
if
(
colId
==
pSchema
[
j
].
colId
)
{
tdAppendColVal
(
trow
,
payloadColValue
(
p
),
pSchema
[
j
].
type
,
toffset
);
toffset
+=
TYPE_BYTES
[
pSchema
[
j
].
type
];
p
=
skipToNextEles
(
p
);
++
i
;
++
j
;
}
else
if
(
colId
<
pSchema
[
j
].
colId
)
{
p
=
skipToNextEles
(
p
);
++
i
;
}
else
{
tdAppendColVal
(
trow
,
tdGetNullVal
(
pSchema
[
j
].
type
),
pSchema
[
j
].
type
,
toffset
);
toffset
+=
TYPE_BYTES
[
pSchema
[
j
].
type
];
++
j
;
}
}
while
(
j
<
pBuilder
->
nCols
)
{
tdAppendColVal
(
trow
,
tdGetNullVal
(
pSchema
[
j
].
type
),
pSchema
[
j
].
type
,
toffset
);
toffset
+=
TYPE_BYTES
[
pSchema
[
j
].
type
];
p
+=
pSchema
[
j
].
bytes
;
++
j
;
}
while
(
i
<
nColsNotNull
)
{
p
=
skipToNextEles
(
p
);
++
i
;
}
pBuilder
->
buf
=
p
;
}
else
if
(
memRowType
==
SMEM_ROW_KV
)
{
}
else
if
(
memRowType
==
SMEM_ROW_KV
)
{
ASSERT
(
nColsNotNull
<=
pBuilder
->
nCols
);
SKVRow
kvRow
=
(
SKVRow
)
memRowKvBody
(
memRow
);
uint16_t
tlen
=
TD_KV_ROW_HEAD_SIZE
+
sizeof
(
SColIdx
)
*
nColsNotNull
;
...
...
@@ -1717,14 +1712,17 @@ SMemRow tdGenMemRowFromBuilder(SMemRowBuilder* pBuilder) {
kvRowSetNCols
(
kvRow
,
nColsNotNull
);
memRowKvSetVersion
(
memRow
,
pBuilder
->
sversion
);
p
=
(
char
*
)
pBuilder
->
buf
;
for
(
int32_t
j
=
0
;
j
<
pBuilder
->
nCols
;
++
j
)
{
if
(
!
isNull
(
p
,
pSchema
[
j
].
type
))
{
tdAppendKvColVal
(
kvRow
,
p
,
pSchema
[
j
].
colId
,
pSchema
[
j
].
type
,
toffset
);
toffset
+=
sizeof
(
SColIdx
);
}
p
+=
pSchema
[
j
].
bytes
;
p
=
(
char
*
)
payloadBody
(
pBuilder
->
buf
);
int
i
=
0
;
while
(
i
<
nColsNotNull
)
{
int16_t
colId
=
payloadColId
(
p
);
uint8_t
colType
=
payloadColType
(
p
);
tdAppendKvColVal
(
kvRow
,
payloadColValue
(
p
),
colId
,
colType
,
toffset
);
toffset
+=
sizeof
(
SColIdx
);
p
=
skipToNextEles
(
p
);
++
i
;
}
pBuilder
->
buf
=
p
;
}
else
{
...
...
@@ -1738,11 +1736,12 @@ SMemRow tdGenMemRowFromBuilder(SMemRowBuilder* pBuilder) {
}
// Erase the empty space reserved for binary data
static
int
trimDataBlock
(
void
*
pDataBlock
,
STableDataBlocks
*
pTableDataBlock
,
bool
includeSchema
)
{
static
int
trimDataBlock
(
void
*
pDataBlock
,
STableDataBlocks
*
pTableDataBlock
,
bool
includeSchema
,
SBlockKeyTuple
*
blkKeyTuple
)
{
// TODO: optimize this function, handle the case while binary is not presented
STableMeta
*
pTableMeta
=
pTableDataBlock
->
pTableMeta
;
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMeta
);
SSchema
*
pSchema
=
tscGetTableSchema
(
pTableMeta
);
STableMeta
*
pTableMeta
=
pTableDataBlock
->
pTableMeta
;
STableComInfo
tinfo
=
tscGetTableInfo
(
pTableMeta
);
SSchema
*
pSchema
=
tscGetTableSchema
(
pTableMeta
);
SMemRowBuilder
*
pBuilder
=
&
pTableDataBlock
->
rowBuilder
;
SSubmitBlk
*
pBlock
=
pDataBlock
;
memcpy
(
pDataBlock
,
pTableDataBlock
->
pData
,
sizeof
(
SSubmitBlk
));
...
...
@@ -1778,18 +1777,18 @@ static int trimDataBlock(void* pDataBlock, STableDataBlocks* pTableDataBlock, bo
pBlock
->
dataLen
=
0
;
int32_t
numOfRows
=
htons
(
pBlock
->
numOfRows
);
SMemRowBuilder
mRowBuilder
;
mRowBuilder
.
pSchema
=
pSchema
;
mRowBuilder
.
sversion
=
pTableMeta
->
sversion
;
mRowBuilder
.
flen
=
flen
;
mRowBuilder
.
nCols
=
tinfo
.
numOfColumns
;
mRowBuilder
.
pDataBlock
=
pDataBlock
;
mRowBuilder
.
pSubmitBlk
=
pBlock
;
mRowBuilder
.
buf
=
p
;
mRowBuilder
.
size
=
0
;
pBuilder
->
pSchema
=
pSchema
;
pBuilder
->
sversion
=
pTableMeta
->
sversion
;
pBuilder
->
flen
=
flen
;
pBuilder
->
nCols
=
tinfo
.
numOfColumns
;
pBuilder
->
pDataBlock
=
pDataBlock
;
pBuilder
->
pSubmitBlk
=
pBlock
;
pBuilder
->
buf
=
p
;
pBuilder
->
size
=
0
;
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
tdGenMemRowFromBuilder
(
&
mRowBuilder
);
pBuilder
->
buf
=
(
blkKeyTuple
+
i
)
->
payloadAddr
;
tdGenMemRowFromBuilder
(
pBuilder
);
}
int32_t
len
=
pBlock
->
dataLen
+
pBlock
->
schemaLen
;
...
...
@@ -1807,9 +1806,8 @@ static int32_t getRowExpandSize(STableMeta* pTableMeta) {
if
(
IS_VAR_DATA_TYPE
((
pSchema
+
i
)
->
type
))
{
result
+=
TYPE_BYTES
[
TSDB_DATA_TYPE_BINARY
];
}
result
+=
sizeof
(
SColIdx
);
}
result
+=
TD_MEM_ROW_
TYPE_SIZE
;
// add len of SMemRow flag
result
+=
TD_MEM_ROW_
KV_TYPE_VER_SIZE
;
// add prefix len of KV type SMemRow(we may use SDataRow or SKVRow)
return
result
;
}
...
...
@@ -1837,14 +1835,17 @@ static void extractTableNameList(SInsertStatementParam *pInsertParam, bool freeB
}
int32_t
tscMergeTableDataBlocks
(
SInsertStatementParam
*
pInsertParam
,
bool
freeBlockMap
)
{
const
int
INSERT_HEAD_SIZE
=
sizeof
(
SMsgDesc
)
+
sizeof
(
SSubmitMsg
);
void
*
pVnodeDataBlockHashList
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
false
);
const
int
INSERT_HEAD_SIZE
=
sizeof
(
SMsgDesc
)
+
sizeof
(
SSubmitMsg
);
int
code
=
0
;
void
*
pVnodeDataBlockHashList
=
taosHashInit
(
128
,
taosGetDefaultHashFunction
(
TSDB_DATA_TYPE_BIGINT
),
true
,
false
);
SArray
*
pVnodeDataBlockList
=
taosArrayInit
(
8
,
POINTER_BYTES
);
STableDataBlocks
**
p
=
taosHashIterate
(
pInsertParam
->
pTableBlockHashList
,
NULL
);
STableDataBlocks
*
pOneTableBlock
=
*
p
;
SBlockKeyInfo
blkKeyInfo
=
{
0
};
// share by pOneTableBlock
while
(
pOneTableBlock
)
{
SSubmitBlk
*
pBlocks
=
(
SSubmitBlk
*
)
pOneTableBlock
->
pData
;
if
(
pBlocks
->
numOfRows
>
0
)
{
...
...
@@ -1858,6 +1859,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
tscError
(
"0x%"
PRIx64
" failed to prepare the data block buffer for merging table data, code:%d"
,
pInsertParam
->
objectId
,
ret
);
taosHashCleanup
(
pVnodeDataBlockHashList
);
tscDestroyBlockArrayList
(
pVnodeDataBlockList
);
tfree
(
blkKeyInfo
.
pKeyTuple
);
return
ret
;
}
...
...
@@ -1878,16 +1880,26 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
taosHashCleanup
(
pVnodeDataBlockHashList
);
tscDestroyBlockArrayList
(
pVnodeDataBlockList
);
tfree
(
dataBuf
->
pData
);
tfree
(
blkKeyInfo
.
pKeyTuple
);
return
TSDB_CODE_TSC_OUT_OF_MEMORY
;
}
}
tscSortRemoveDataBlockDupRows
(
pOneTableBlock
);
char
*
ekey
=
(
char
*
)
pBlocks
->
data
+
pOneTableBlock
->
rowSize
*
(
pBlocks
->
numOfRows
-
1
);
if
((
code
=
tscSortRemoveDataBlockDupRows
(
pOneTableBlock
,
&
blkKeyInfo
))
!=
0
){
taosHashCleanup
(
pVnodeDataBlockHashList
);
tscDestroyBlockArrayList
(
pVnodeDataBlockList
);
tfree
(
dataBuf
->
pData
);
tfree
(
blkKeyInfo
.
pKeyTuple
);
return
code
;
}
ASSERT
(
blkKeyInfo
.
pKeyTuple
!=
NULL
&&
pBlocks
->
numOfRows
>
0
);
tscDebug
(
"0x%"
PRIx64
" name:%s, tid:%d rows:%d sversion:%d skey:%"
PRId64
", ekey:%"
PRId64
,
pInsertParam
->
objectId
,
tNameGetTableName
(
&
pOneTableBlock
->
tableName
),
pBlocks
->
tid
,
pBlocks
->
numOfRows
,
pBlocks
->
sversion
,
GET_INT64_VAL
(
pBlocks
->
data
),
GET_INT64_VAL
(
ekey
));
SBlockKeyTuple
*
pLastKeyTuple
=
blkKeyInfo
.
pKeyTuple
+
pBlocks
->
numOfRows
-
1
;
tscDebug
(
"0x%"
PRIx64
" name:%s, tid:%d rows:%d sversion:%d skey:%"
PRId64
", ekey:%"
PRId64
,
pInsertParam
->
objectId
,
tNameGetTableName
(
&
pOneTableBlock
->
tableName
),
pBlocks
->
tid
,
pBlocks
->
numOfRows
,
pBlocks
->
sversion
,
blkKeyInfo
.
pKeyTuple
->
skey
,
pLastKeyTuple
->
skey
);
int32_t
len
=
pBlocks
->
numOfRows
*
(
pOneTableBlock
->
rowSize
+
expandSize
)
+
sizeof
(
STColumn
)
*
tscGetNumOfColumns
(
pOneTableBlock
->
pTableMeta
);
...
...
@@ -1898,7 +1910,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
pBlocks
->
schemaLen
=
0
;
// erase the empty space reserved for binary data
int32_t
finalLen
=
trimDataBlock
(
dataBuf
->
pData
+
dataBuf
->
size
,
pOneTableBlock
,
pInsertParam
->
schemaAttached
);
int32_t
finalLen
=
trimDataBlock
(
dataBuf
->
pData
+
dataBuf
->
size
,
pOneTableBlock
,
pInsertParam
->
schemaAttached
,
blkKeyInfo
.
pKeyTuple
);
assert
(
finalLen
<=
len
);
dataBuf
->
size
+=
(
finalLen
+
sizeof
(
SSubmitBlk
));
...
...
@@ -1926,6 +1938,7 @@ int32_t tscMergeTableDataBlocks(SInsertStatementParam *pInsertParam, bool freeBl
// free the table data blocks;
pInsertParam
->
pDataBlocks
=
pVnodeDataBlockList
;
taosHashCleanup
(
pVnodeDataBlockHashList
);
tfree
(
blkKeyInfo
.
pKeyTuple
);
return
TSDB_CODE_SUCCESS
;
}
...
...
src/common/inc/tdataformat.h
浏览文件 @
9ed5a42c
...
...
@@ -24,6 +24,33 @@
extern
"C"
{
#endif
#pragma pack(push, 1)
typedef
struct
{
VarDataLenT
len
;
uint8_t
data
;
}
SBinaryNullT
;
typedef
struct
{
VarDataLenT
len
;
uint32_t
data
;
}
SNCharNullT
;
#pragma pack(pop)
extern
const
uint8_t
BoolNull
;
extern
const
uint8_t
TinyintNull
;
extern
const
uint16_t
SmallintNull
;
extern
const
uint32_t
IntNull
;
extern
const
uint64_t
BigintNull
;
extern
const
uint64_t
TimestampNull
;
extern
const
uint8_t
UTinyintNull
;
extern
const
uint16_t
USmallintNull
;
extern
const
uint32_t
UIntNull
;
extern
const
uint64_t
UBigintNull
;
extern
const
uint32_t
FloatNull
;
extern
const
uint64_t
DoubleNull
;
extern
const
SBinaryNullT
BinaryNull
;
extern
const
SNCharNullT
NcharNull
;
#define STR_TO_VARSTR(x, str) \
do { \
VarDataLenT __len = (VarDataLenT)strlen(str); \
...
...
@@ -207,7 +234,7 @@ SDataRow tdDataRowDup(SDataRow row);
SMemRow
tdMemRowDup
(
SMemRow
row
);
// offset here not include dataRow header length
static
FORCE_INLINE
int
tdAppendColVal
(
SDataRow
row
,
void
*
value
,
int8_t
type
,
int32_t
bytes
,
int32_t
offset
)
{
static
FORCE_INLINE
int
tdAppendColVal
(
SDataRow
row
,
const
void
*
value
,
int8_t
type
,
int32_t
offset
)
{
ASSERT
(
value
!=
NULL
);
int32_t
toffset
=
offset
+
TD_DATA_ROW_HEAD_SIZE
;
char
*
ptr
=
(
char
*
)
POINTER_SHIFT
(
row
,
dataRowLen
(
row
));
...
...
@@ -260,6 +287,42 @@ void dataColSetOffset(SDataCol *pCol, int nEle);
bool
isNEleNull
(
SDataCol
*
pCol
,
int
nEle
);
void
dataColSetNEleNull
(
SDataCol
*
pCol
,
int
nEle
,
int
maxPoints
);
static
FORCE_INLINE
const
void
*
tdGetNullVal
(
int8_t
type
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
return
&
BoolNull
;
case
TSDB_DATA_TYPE_TINYINT
:
return
&
TinyintNull
;
case
TSDB_DATA_TYPE_SMALLINT
:
return
&
SmallintNull
;
case
TSDB_DATA_TYPE_INT
:
return
&
IntNull
;
case
TSDB_DATA_TYPE_BIGINT
:
return
&
BigintNull
;
case
TSDB_DATA_TYPE_FLOAT
:
return
&
FloatNull
;
case
TSDB_DATA_TYPE_DOUBLE
:
return
&
DoubleNull
;
case
TSDB_DATA_TYPE_BINARY
:
return
&
BinaryNull
;
case
TSDB_DATA_TYPE_TIMESTAMP
:
return
&
TimestampNull
;
case
TSDB_DATA_TYPE_NCHAR
:
return
&
NcharNull
;
case
TSDB_DATA_TYPE_UTINYINT
:
return
&
UTinyintNull
;
case
TSDB_DATA_TYPE_USMALLINT
:
return
&
USmallintNull
;
case
TSDB_DATA_TYPE_UINT
:
return
&
UIntNull
;
case
TSDB_DATA_TYPE_UBIGINT
:
return
&
UBigintNull
;
default:
ASSERT
(
0
);
return
NULL
;
}
}
// Get the data pointer from a column-wised data
static
FORCE_INLINE
void
*
tdGetColDataOfRow
(
SDataCol
*
pCol
,
int
row
)
{
if
(
IS_VAR_DATA_TYPE
(
pCol
->
type
))
{
...
...
@@ -545,6 +608,47 @@ static FORCE_INLINE void *tdGetMemRowDataOfCol(void *row, int8_t type, int32_t o
return
NULL
;
}
// RawRow payload structure:
// |<---------- header ------------->|<---- body: column data tuple ---->|
// |SMemRowType| dataLen | nCols | colId | colType | value |...|...|
// +-----------+----------+----------+---------------------------------->|
// | uint8_t | uint16_t | uint16_t | int16_t | uint8_t | ??? |...|...|
// +-----------+----------+----------+---------------------------------->|
#define PAYLOAD_NCOLS_LEN sizeof(uint16_t)
#define PAYLOAD_NCOLS_OFFSET (sizeof(uint8_t) + sizeof(TDRowLenT))
#define PAYLOAD_HEADER_LEN (PAYLOAD_NCOLS_OFFSET + PAYLOAD_NCOLS_LEN)
#define PAYLOAD_ID_LEN sizeof(int16_t)
#define PAYLOAD_ID_TYPE_LEN (sizeof(int16_t) + sizeof(uint8_t))
#define payloadBody(r) POINTER_SHIFT(r, PAYLOAD_HEADER_LEN)
#define payloadType(r) (*(uint8_t *)(r))
#define payloadSetType(r, t) (payloadType(r) = (t))
#define payloadTLen(r) (*(TDRowLenT *)POINTER_SHIFT(r, TD_MEM_ROW_TYPE_SIZE)) // including total header
#define payloadSetTLen(r, l) (payloadTLen(r) = (l))
#define payloadNCols(r) (*(TDRowLenT *)POINTER_SHIFT(r, PAYLOAD_NCOLS_OFFSET))
#define payloadSetNCols(r, n) (payloadNCols(r) = (n))
#define payloadColId(r) (*(int16_t *)(r))
#define payloadColType(r) (*(uint8_t *)POINTER_SHIFT(r, PAYLOAD_ID_LEN))
#define payloadColValue(r) POINTER_SHIFT(r, PAYLOAD_ID_TYPE_LEN)
#define payloadColSetId(r, i) (payloadColId(r) = (i))
#define payloadColSetType(r, t) (payloadColType(r) = (t))
#define payloadKeyAddr(r) POINTER_SHIFT(r, PAYLOAD_HEADER_LEN + PAYLOAD_ID_TYPE_LEN)
#define payloadTKey(r) (*(TKEY *)(payloadKeyAddr(r)))
#define payloadKey(r) tdGetKey(payloadTKey(r))
static
FORCE_INLINE
char
*
skipToNextEles
(
char
*
p
)
{
uint8_t
colType
=
payloadColType
(
p
);
if
(
IS_VAR_DATA_TYPE
(
colType
))
{
return
POINTER_SHIFT
(
p
,
PAYLOAD_ID_TYPE_LEN
+
varDataTLen
(
payloadColValue
(
p
)));
}
else
{
return
POINTER_SHIFT
(
p
,
PAYLOAD_ID_TYPE_LEN
+
TYPE_BYTES
[
colType
]);
}
}
#ifdef __cplusplus
}
#endif
...
...
src/common/src/tdataformat.c
浏览文件 @
9ed5a42c
...
...
@@ -18,6 +18,21 @@
#include "tcoding.h"
#include "wchar.h"
const
uint8_t
BoolNull
=
TSDB_DATA_BOOL_NULL
;
const
uint8_t
TinyintNull
=
TSDB_DATA_TINYINT_NULL
;
const
uint16_t
SmallintNull
=
TSDB_DATA_SMALLINT_NULL
;
const
uint32_t
IntNull
=
TSDB_DATA_INT_NULL
;
const
uint64_t
BigintNull
=
TSDB_DATA_BIGINT_NULL
;
const
uint64_t
TimestampNull
=
TSDB_DATA_BIGINT_NULL
;
const
uint8_t
UTinyintNull
=
TSDB_DATA_UTINYINT_NULL
;
const
uint16_t
USmallintNull
=
TSDB_DATA_USMALLINT_NULL
;
const
uint32_t
UIntNull
=
TSDB_DATA_UINT_NULL
;
const
uint64_t
UBigintNull
=
TSDB_DATA_UBIGINT_NULL
;
const
uint32_t
FloatNull
=
TSDB_DATA_FLOAT_NULL
;
const
uint64_t
DoubleNull
=
TSDB_DATA_DOUBLE_NULL
;
const
SBinaryNullT
BinaryNull
=
{
1
,
TSDB_DATA_BINARY_NULL
};
const
SNCharNullT
NcharNull
=
{
4
,
TSDB_DATA_NCHAR_NULL
};
static
void
tdMergeTwoDataCols
(
SDataCols
*
target
,
SDataCols
*
src1
,
int
*
iter1
,
int
limit1
,
SDataCols
*
src2
,
int
*
iter2
,
int
limit2
,
int
tRows
);
...
...
src/cq/src/cqMain.c
浏览文件 @
9ed5a42c
...
...
@@ -502,7 +502,7 @@ static void cqProcessStreamRes(void *param, TAOS_RES *tres, TAOS_ROW row) {
memcpy
((
char
*
)
val
+
sizeof
(
VarDataLenT
),
buf
,
len
);
varDataLen
(
val
)
=
len
;
}
tdAppendColVal
(
dataRow
,
val
,
c
->
type
,
c
->
bytes
,
c
->
offset
);
tdAppendColVal
(
dataRow
,
val
,
c
->
type
,
c
->
offset
);
}
pBlk
->
dataLen
=
htonl
(
memRowDataTLen
(
trow
));
pBlk
->
schemaLen
=
0
;
...
...
src/tsdb/src/tsdbCommit.c
浏览文件 @
9ed5a42c
...
...
@@ -924,17 +924,17 @@ int tsdbWriteBlockImpl(STsdbRepo *pRepo, STable *pTable, SDFile *pDFile, SDataCo
continue
;
}
memset
(
pBlockCol
,
0
,
sizeof
(
*
pBlockCol
));
pBlockCol
->
colId
=
pDataCol
->
colId
;
pBlockCol
->
type
=
pDataCol
->
type
;
if
(
tDataTypes
[
pDataCol
->
type
].
statisFunc
)
{
(
*
tDataTypes
[
pDataCol
->
type
].
statisFunc
)(
pDataCol
->
pData
,
rowsToWrite
,
&
(
pBlockCol
->
min
),
&
(
pBlockCol
->
max
),
&
(
pBlockCol
->
sum
),
&
(
pBlockCol
->
minIndex
),
&
(
pBlockCol
->
maxIndex
),
&
(
pBlockCol
->
numOfNull
));
}
nColsNotAllNull
++
;
memset
(
pBlockCol
,
0
,
sizeof
(
*
pBlockCol
));
pBlockCol
->
colId
=
pDataCol
->
colId
;
pBlockCol
->
type
=
pDataCol
->
type
;
if
(
tDataTypes
[
pDataCol
->
type
].
statisFunc
)
{
(
*
tDataTypes
[
pDataCol
->
type
].
statisFunc
)(
pDataCol
->
pData
,
rowsToWrite
,
&
(
pBlockCol
->
min
),
&
(
pBlockCol
->
max
),
&
(
pBlockCol
->
sum
),
&
(
pBlockCol
->
minIndex
),
&
(
pBlockCol
->
maxIndex
),
&
(
pBlockCol
->
numOfNull
));
}
nColsNotAllNull
++
;
}
ASSERT
(
nColsNotAllNull
>=
0
&&
nColsNotAllNull
<=
pDataCols
->
numOfCols
);
...
...
src/tsdb/src/tsdbMain.c
浏览文件 @
9ed5a42c
...
...
@@ -720,7 +720,7 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea
// OK,let's load row from backward to get not-null column
for
(
int32_t
rowId
=
pBlock
->
numOfRows
-
1
;
rowId
>=
0
;
rowId
--
)
{
SDataCol
*
pDataCol
=
pReadh
->
pDCols
[
0
]
->
cols
+
i
;
tdAppendColVal
(
memRowDataBody
(
row
),
tdGetColDataOfRow
(
pDataCol
,
rowId
),
pCol
->
type
,
pCol
->
bytes
,
pCol
->
offset
);
tdAppendColVal
(
memRowDataBody
(
row
),
tdGetColDataOfRow
(
pDataCol
,
rowId
),
pCol
->
type
,
pCol
->
offset
);
//SDataCol *pDataCol = readh.pDCols[0]->cols + j;
void
*
value
=
tdGetRowDataOfCol
(
memRowDataBody
(
row
),
(
int8_t
)
pCol
->
type
,
TD_DATA_ROW_HEAD_SIZE
+
pCol
->
offset
);
if
(
isNull
(
value
,
pCol
->
type
))
{
...
...
@@ -742,7 +742,7 @@ static int tsdbRestoreLastColumns(STsdbRepo *pRepo, STable *pTable, SReadH* pRea
// save row ts(in column 0)
pDataCol
=
pReadh
->
pDCols
[
0
]
->
cols
+
0
;
pCol
=
schemaColAt
(
pSchema
,
0
);
tdAppendColVal
(
memRowDataBody
(
row
),
tdGetColDataOfRow
(
pDataCol
,
rowId
),
pCol
->
type
,
pCol
->
bytes
,
pCol
->
offset
);
tdAppendColVal
(
memRowDataBody
(
row
),
tdGetColDataOfRow
(
pDataCol
,
rowId
),
pCol
->
type
,
pCol
->
offset
);
pLastCol
->
ts
=
memRowKey
(
row
);
pTable
->
restoreColumnNum
+=
1
;
...
...
@@ -790,7 +790,7 @@ static int tsdbRestoreLastRow(STsdbRepo *pRepo, STable *pTable, SReadH* pReadh,
STColumn
*
pCol
=
schemaColAt
(
pSchema
,
icol
);
SDataCol
*
pDataCol
=
pReadh
->
pDCols
[
0
]
->
cols
+
icol
;
tdAppendColVal
(
memRowDataBody
(
pTable
->
lastRow
),
tdGetColDataOfRow
(
pDataCol
,
pBlock
->
numOfRows
-
1
),
pCol
->
type
,
pCol
->
bytes
,
pCol
->
offset
);
pCol
->
offset
);
}
return
0
;
...
...
src/tsdb/tests/tsdbTests.cpp
浏览文件 @
9ed5a42c
...
...
@@ -55,10 +55,10 @@ static int insertData(SInsertInfo *pInfo) {
for
(
int
j
=
0
;
j
<
schemaNCols
(
pInfo
->
pSchema
);
j
++
)
{
STColumn
*
pTCol
=
schemaColAt
(
pInfo
->
pSchema
,
j
);
if
(
j
==
0
)
{
// Just for timestamp
tdAppendColVal
(
row
,
(
void
*
)(
&
start_time
),
pTCol
->
type
,
pTCol
->
bytes
,
pTCol
->
offset
);
tdAppendColVal
(
row
,
(
void
*
)(
&
start_time
),
pTCol
->
type
,
pTCol
->
offset
);
}
else
{
// For int
int
val
=
10
;
tdAppendColVal
(
row
,
(
void
*
)(
&
val
),
pTCol
->
type
,
pTCol
->
bytes
,
pTCol
->
offset
);
tdAppendColVal
(
row
,
(
void
*
)(
&
val
),
pTCol
->
type
,
pTCol
->
offset
);
}
}
pBlock
->
dataLen
+=
dataRowLen
(
row
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录