Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
db3999ea
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看板
提交
db3999ea
编写于
2月 28, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
minor changes
上级
5891779f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
27 addition
and
31 deletion
+27
-31
source/common/src/tdataformat.c
source/common/src/tdataformat.c
+27
-31
未找到文件。
source/common/src/tdataformat.c
浏览文件 @
db3999ea
...
...
@@ -15,7 +15,7 @@
#define _DEFAULT_SOURCE
#include "tdataformat.h"
#include "tcoding.h"
#include "tcoding.h"
#include "tlog.h"
static
void
dataColSetNEleNull
(
SDataCol
*
pCol
,
int
nEle
);
...
...
@@ -25,7 +25,7 @@ static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, i
#endif
int
tdAllocMemForCol
(
SDataCol
*
pCol
,
int
maxPoints
)
{
int
spaceNeeded
=
pCol
->
bytes
*
maxPoints
;
if
(
IS_VAR_DATA_TYPE
(
pCol
->
type
))
{
if
(
IS_VAR_DATA_TYPE
(
pCol
->
type
))
{
spaceNeeded
+=
sizeof
(
VarDataOffsetT
)
*
maxPoints
;
}
#ifdef TD_SUPPORT_BITMAP
...
...
@@ -36,11 +36,10 @@ int tdAllocMemForCol(SDataCol *pCol, int maxPoints) {
spaceNeeded
+=
TYPE_BYTES
[
pCol
->
type
];
#endif
if
(
pCol
->
spaceSize
<
spaceNeeded
)
{
void
*
ptr
=
realloc
(
pCol
->
pData
,
spaceNeeded
);
if
(
ptr
==
NULL
)
{
uDebug
(
"malloc failure, size:%"
PRId64
" failed, reason:%s"
,
(
int64_t
)
spaceNeeded
,
strerror
(
errno
));
if
(
pCol
->
spaceSize
<
spaceNeeded
)
{
void
*
ptr
=
realloc
(
pCol
->
pData
,
spaceNeeded
);
if
(
ptr
==
NULL
)
{
uDebug
(
"malloc failure, size:%"
PRId64
" failed, reason:%s"
,
(
int64_t
)
spaceNeeded
,
strerror
(
errno
));
return
-
1
;
}
else
{
pCol
->
pData
=
ptr
;
...
...
@@ -66,8 +65,7 @@ int tdAllocMemForCol(SDataCol *pCol, int maxPoints) {
* Duplicate the schema and return a new object
*/
STSchema
*
tdDupSchema
(
const
STSchema
*
pSchema
)
{
int
tlen
=
sizeof
(
STSchema
)
+
sizeof
(
STColumn
)
*
schemaNCols
(
pSchema
);
int
tlen
=
sizeof
(
STSchema
)
+
sizeof
(
STColumn
)
*
schemaNCols
(
pSchema
);
STSchema
*
tSchema
=
(
STSchema
*
)
malloc
(
tlen
);
if
(
tSchema
==
NULL
)
return
NULL
;
...
...
@@ -98,8 +96,8 @@ int tdEncodeSchema(void **buf, STSchema *pSchema) {
* Decode a schema from a binary.
*/
void
*
tdDecodeSchema
(
void
*
buf
,
STSchema
**
pRSchema
)
{
int
version
=
0
;
int
numOfCols
=
0
;
int
version
=
0
;
int
numOfCols
=
0
;
STSchemaBuilder
schemaBuilder
;
buf
=
taosDecodeFixedI32
(
buf
,
&
version
);
...
...
@@ -155,7 +153,7 @@ int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int1
if
(
pBuilder
->
nCols
>=
pBuilder
->
tCols
)
{
pBuilder
->
tCols
*=
2
;
STColumn
*
columns
=
(
STColumn
*
)
realloc
(
pBuilder
->
columns
,
sizeof
(
STColumn
)
*
pBuilder
->
tCols
);
STColumn
*
columns
=
(
STColumn
*
)
realloc
(
pBuilder
->
columns
,
sizeof
(
STColumn
)
*
pBuilder
->
tCols
);
if
(
columns
==
NULL
)
return
-
1
;
pBuilder
->
columns
=
columns
;
}
...
...
@@ -166,7 +164,7 @@ int tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int16_t colId, int1
if
(
pBuilder
->
nCols
==
0
)
{
colSetOffset
(
pCol
,
0
);
}
else
{
STColumn
*
pTCol
=
&
(
pBuilder
->
columns
[
pBuilder
->
nCols
-
1
]);
STColumn
*
pTCol
=
&
(
pBuilder
->
columns
[
pBuilder
->
nCols
-
1
]);
colSetOffset
(
pCol
,
pTCol
->
offset
+
TYPE_BYTES
[
pTCol
->
type
]);
}
...
...
@@ -258,7 +256,7 @@ void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints) {
pDataCol
->
type
=
colType
(
pCol
);
pDataCol
->
colId
=
colColId
(
pCol
);
pDataCol
->
bytes
=
colBytes
(
pCol
);
pDataCol
->
offset
=
colOffset
(
pCol
)
+
0
;
//
TD_DATA_ROW_HEAD_SIZE;
pDataCol
->
offset
=
colOffset
(
pCol
)
+
0
;
//
TD_DATA_ROW_HEAD_SIZE;
pDataCol
->
len
=
0
;
}
...
...
@@ -272,7 +270,7 @@ int dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPo
return
0
;
}
if
(
tdAllocMemForCol
(
pCol
,
maxPoints
)
<
0
)
return
-
1
;
if
(
tdAllocMemForCol
(
pCol
,
maxPoints
)
<
0
)
return
-
1
;
if
(
numOfRows
>
0
)
{
// Find the first not null value, fill all previouse values as NULL
dataColSetNEleNull
(
pCol
,
numOfRows
);
...
...
@@ -303,7 +301,7 @@ static FORCE_INLINE const void *tdGetColDataOfRowUnsafe(SDataCol *pCol, int row)
}
bool
isNEleNull
(
SDataCol
*
pCol
,
int
nEle
)
{
if
(
isAllRowsNull
(
pCol
))
return
true
;
if
(
isAllRowsNull
(
pCol
))
return
true
;
for
(
int
i
=
0
;
i
<
nEle
;
i
++
)
{
if
(
!
isNull
(
tdGetColDataOfRowUnsafe
(
pCol
,
i
),
pCol
->
type
))
return
false
;
}
...
...
@@ -370,7 +368,7 @@ SDataCols *tdNewDataCols(int maxCols, int maxRows) {
return
NULL
;
}
int
i
;
for
(
i
=
0
;
i
<
maxCols
;
i
++
)
{
for
(
i
=
0
;
i
<
maxCols
;
i
++
)
{
pCols
->
cols
[
i
].
spaceSize
=
0
;
pCols
->
cols
[
i
].
len
=
0
;
pCols
->
cols
[
i
].
pData
=
NULL
;
...
...
@@ -386,10 +384,10 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) {
int
oldMaxCols
=
pCols
->
maxCols
;
if
(
schemaNCols
(
pSchema
)
>
oldMaxCols
)
{
pCols
->
maxCols
=
schemaNCols
(
pSchema
);
void
*
ptr
=
(
SDataCol
*
)
realloc
(
pCols
->
cols
,
sizeof
(
SDataCol
)
*
pCols
->
maxCols
);
void
*
ptr
=
(
SDataCol
*
)
realloc
(
pCols
->
cols
,
sizeof
(
SDataCol
)
*
pCols
->
maxCols
);
if
(
ptr
==
NULL
)
return
-
1
;
pCols
->
cols
=
ptr
;
for
(
i
=
oldMaxCols
;
i
<
pCols
->
maxCols
;
i
++
)
{
for
(
i
=
oldMaxCols
;
i
<
pCols
->
maxCols
;
i
++
)
{
pCols
->
cols
[
i
].
pData
=
NULL
;
pCols
->
cols
[
i
].
dataOff
=
NULL
;
pCols
->
cols
[
i
].
spaceSize
=
0
;
...
...
@@ -402,16 +400,16 @@ int tdInitDataCols(SDataCols *pCols, STSchema *pSchema) {
for
(
i
=
0
;
i
<
schemaNCols
(
pSchema
);
i
++
)
{
dataColInit
(
pCols
->
cols
+
i
,
schemaColAt
(
pSchema
,
i
),
pCols
->
maxPoints
);
}
return
0
;
}
SDataCols
*
tdFreeDataCols
(
SDataCols
*
pCols
)
{
int
i
;
if
(
pCols
)
{
if
(
pCols
->
cols
)
{
if
(
pCols
->
cols
)
{
int
maxCols
=
pCols
->
maxCols
;
for
(
i
=
0
;
i
<
maxCols
;
i
++
)
{
for
(
i
=
0
;
i
<
maxCols
;
i
++
)
{
SDataCol
*
pCol
=
&
pCols
->
cols
[
i
];
tfree
(
pCol
->
pData
);
}
...
...
@@ -439,7 +437,7 @@ SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) {
if
(
keepData
)
{
if
(
pDataCols
->
cols
[
i
].
len
>
0
)
{
if
(
tdAllocMemForCol
(
&
pRet
->
cols
[
i
],
pRet
->
maxPoints
)
<
0
)
{
if
(
tdAllocMemForCol
(
&
pRet
->
cols
[
i
],
pRet
->
maxPoints
)
<
0
)
{
tdFreeDataCols
(
pRet
);
return
NULL
;
}
...
...
@@ -647,9 +645,9 @@ SKVRow tdKVRowDup(SKVRow row) {
return
trow
;
}
static
int
compareColIdx
(
const
void
*
a
,
const
void
*
b
)
{
const
SColIdx
*
x
=
(
const
SColIdx
*
)
a
;
const
SColIdx
*
y
=
(
const
SColIdx
*
)
b
;
static
int
compareColIdx
(
const
void
*
a
,
const
void
*
b
)
{
const
SColIdx
*
x
=
(
const
SColIdx
*
)
a
;
const
SColIdx
*
y
=
(
const
SColIdx
*
)
b
;
if
(
x
->
colId
>
y
->
colId
)
{
return
1
;
}
...
...
@@ -659,15 +657,13 @@ static int compareColIdx(const void* a, const void* b) {
return
0
;
}
void
tdSortKVRowByColIdx
(
SKVRow
row
)
{
qsort
(
kvRowColIdx
(
row
),
kvRowNCols
(
row
),
sizeof
(
SColIdx
),
compareColIdx
);
}
void
tdSortKVRowByColIdx
(
SKVRow
row
)
{
qsort
(
kvRowColIdx
(
row
),
kvRowNCols
(
row
),
sizeof
(
SColIdx
),
compareColIdx
);
}
int
tdSetKVRowDataOfCol
(
SKVRow
*
orow
,
int16_t
colId
,
int8_t
type
,
void
*
value
)
{
SColIdx
*
pColIdx
=
NULL
;
SKVRow
row
=
*
orow
;
SKVRow
nrow
=
NULL
;
void
*
ptr
=
taosbsearch
(
&
colId
,
kvRowColIdx
(
row
),
kvRowNCols
(
row
),
sizeof
(
SColIdx
),
comparTagId
,
TD_GE
);
void
*
ptr
=
taosbsearch
(
&
colId
,
kvRowColIdx
(
row
),
kvRowNCols
(
row
),
sizeof
(
SColIdx
),
comparTagId
,
TD_GE
);
if
(
ptr
==
NULL
||
((
SColIdx
*
)
ptr
)
->
colId
>
colId
)
{
// need to add a column value to the row
int
diff
=
IS_VAR_DATA_TYPE
(
type
)
?
varDataTLen
(
value
)
:
TYPE_BYTES
[
type
];
...
...
@@ -699,7 +695,7 @@ int tdSetKVRowDataOfCol(SKVRow *orow, int16_t colId, int8_t type, void *value) {
if
(
IS_VAR_DATA_TYPE
(
type
))
{
void
*
pOldVal
=
kvRowColVal
(
row
,
(
SColIdx
*
)
ptr
);
if
(
varDataTLen
(
value
)
==
varDataTLen
(
pOldVal
))
{
// just update the column value in place
if
(
varDataTLen
(
value
)
==
varDataTLen
(
pOldVal
))
{
// just update the column value in place
memcpy
(
pOldVal
,
value
,
varDataTLen
(
value
));
}
else
{
// need to reallocate the memory
int16_t
nlen
=
kvRowLen
(
row
)
+
(
varDataTLen
(
value
)
-
varDataTLen
(
pOldVal
));
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录