Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
5070bb3a
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看板
提交
5070bb3a
编写于
6月 02, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
more
上级
6a204ca4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
61 addition
and
211 deletion
+61
-211
include/common/tdataformat.h
include/common/tdataformat.h
+13
-14
source/common/src/tdataformat.c
source/common/src/tdataformat.c
+48
-197
未找到文件。
include/common/tdataformat.h
浏览文件 @
5070bb3a
...
...
@@ -46,7 +46,7 @@ void tTSchemaDestroy(STSchema *pTSchema);
#define COL_VAL_NULL(CID) ((SColVal){.cid = (CID), .isNull = 1})
#define COL_VAL_VALUE(CID, V) ((SColVal){.cid = (CID), .value = (V)})
int32_t
tTSRowNew
(
SArray
*
pArray
,
STSchema
*
pTSchema
,
STSRow2
**
ppRow
);
int32_t
tTSRowNew
(
S
TSRowBuilder
*
pBuilder
,
S
Array
*
pArray
,
STSchema
*
pTSchema
,
STSRow2
**
ppRow
);
int32_t
tTSRowClone
(
const
STSRow2
*
pRow
,
STSRow2
**
ppRow
);
void
tTSRowFree
(
STSRow2
*
pRow
);
void
tTSRowGet
(
STSRow2
*
pRow
,
STSchema
*
pTSchema
,
int32_t
iCol
,
SColVal
*
pColVal
);
...
...
@@ -55,6 +55,13 @@ int32_t tPutTSRow(uint8_t *p, STSRow2 *pRow);
int32_t
tGetTSRow
(
uint8_t
*
p
,
STSRow2
*
pRow
);
// STSRowBuilder
#define tsRowBuilderInit() ((STSRowBuilder){0})
#define tsRowBuilderClear(B) \
do { \
if ((B)->pBuf) { \
taosMemoryFree((B)->pBuf); \
} \
} while (0)
// STag
int32_t
tTagNew
(
SArray
*
pArray
,
int32_t
version
,
int8_t
isJson
,
STag
**
ppTag
);
...
...
@@ -64,8 +71,8 @@ char *tTagValToData(const STagVal *pTagVal, bool isJson);
int32_t
tEncodeTag
(
SEncoder
*
pEncoder
,
const
STag
*
pTag
);
int32_t
tDecodeTag
(
SDecoder
*
pDecoder
,
STag
**
ppTag
);
int32_t
tTagToValArray
(
const
STag
*
pTag
,
SArray
**
ppArray
);
void
debugPrintSTag
(
STag
*
pTag
,
const
char
*
tag
,
int32_t
ln
);
// TODO: remove
void
debugCheckTags
(
STag
*
pTag
);
// TODO: remove
void
debugPrintSTag
(
STag
*
pTag
,
const
char
*
tag
,
int32_t
ln
);
// TODO: remove
void
debugCheckTags
(
STag
*
pTag
);
// TODO: remove
// STRUCT =================
struct
STColumn
{
...
...
@@ -100,17 +107,9 @@ struct STSRow2 {
};
struct
STSRowBuilder
{
STSchema
*
pTSchema
;
int32_t
szBitMap1
;
int32_t
szBitMap2
;
int32_t
szKVBuf
;
uint8_t
*
pKVBuf
;
int32_t
szTPBuf
;
uint8_t
*
pTPBuf
;
int32_t
iCol
;
int32_t
vlenKV
;
int32_t
vlenTP
;
STSRow2
row
;
STSRow2
tsRow
;
int32_t
szBuf
;
uint8_t
*
pBuf
;
};
struct
SValue
{
...
...
source/common/src/tdataformat.c
浏览文件 @
5070bb3a
...
...
@@ -142,191 +142,6 @@ static FORCE_INLINE int32_t tGetValue(uint8_t *p, SValue *pValue, int8_t type) {
}
// STSRow2 ========================================================================
static
void
tTupleTSRowNew
(
SArray
*
pArray
,
STSchema
*
pTSchema
,
STSRow2
*
pRow
)
{
int32_t
nColVal
=
taosArrayGetSize
(
pArray
);
STColumn
*
pTColumn
;
SColVal
*
pColVal
;
ASSERT
(
nColVal
>
0
);
pRow
->
sver
=
pTSchema
->
version
;
// ts
pTColumn
=
&
pTSchema
->
columns
[
0
];
pColVal
=
(
SColVal
*
)
taosArrayGet
(
pArray
,
0
);
ASSERT
(
pTColumn
->
colId
==
0
&&
pColVal
->
cid
==
0
);
ASSERT
(
pTColumn
->
type
==
TSDB_DATA_TYPE_TIMESTAMP
);
pRow
->
ts
=
pColVal
->
value
.
ts
;
// other fields
int32_t
iColVal
=
1
;
int32_t
bidx
;
uint32_t
nv
=
0
;
uint8_t
*
pb
=
NULL
;
uint8_t
*
pf
=
NULL
;
uint8_t
*
pv
=
NULL
;
uint8_t
flags
=
0
;
for
(
int32_t
iColumn
=
1
;
iColumn
<
pTSchema
->
numOfCols
;
iColumn
++
)
{
bidx
=
iColumn
-
1
;
pTColumn
=
&
pTSchema
->
columns
[
iColumn
];
if
(
iColVal
<
nColVal
)
{
pColVal
=
(
SColVal
*
)
taosArrayGet
(
pArray
,
iColVal
);
}
else
{
pColVal
=
NULL
;
}
if
(
pColVal
)
{
if
(
pColVal
->
cid
==
pTColumn
->
colId
)
{
iColVal
++
;
if
(
pColVal
->
isNone
)
{
goto
_set_none
;
}
else
if
(
pColVal
->
isNull
)
{
goto
_set_null
;
}
else
{
goto
_set_value
;
}
}
else
if
(
pColVal
->
cid
>
pTColumn
->
colId
)
{
goto
_set_none
;
}
else
{
ASSERT
(
0
);
}
}
else
{
goto
_set_none
;
}
_set_none:
flags
|=
TSROW_HAS_NONE
;
// SET_BIT2(pb, bidx, 0); (todo)
continue
;
_set_null:
flags
!=
TSROW_HAS_NULL
;
// SET_BIT2(pb, bidx, 1); (todo)
continue
;
_set_value:
flags
!=
TSROW_HAS_VAL
;
// SET_BIT2(pb, bidx, 2); (todo)
if
(
IS_VAR_DATA_TYPE
(
pTColumn
->
type
))
{
// nv += tPutColVal(pv ? pv + nv : pv, pColVal, pTColumn->type, 1);
}
else
{
// tPutColVal(pf ? pf + pTColumn->offset : pf, pColVal, pTColumn->type, 1);
}
continue
;
}
ASSERT
(
flags
);
switch
(
flags
&
0xf
)
{
case
TSROW_HAS_NONE
:
case
TSROW_HAS_NULL
:
pRow
->
nData
=
0
;
break
;
case
TSROW_HAS_VAL
:
pRow
->
nData
=
pTSchema
->
flen
+
nv
;
break
;
case
TSROW_HAS_NULL
|
TSROW_HAS_NONE
:
pRow
->
nData
=
BIT1_SIZE
(
pTSchema
->
numOfCols
-
1
);
break
;
case
TSROW_HAS_VAL
|
TSROW_HAS_NONE
:
case
TSROW_HAS_VAL
|
TSROW_HAS_NULL
:
pRow
->
nData
=
BIT1_SIZE
(
pTSchema
->
numOfCols
-
1
)
+
pTSchema
->
flen
+
nv
;
break
;
case
TSROW_HAS_VAL
|
TSROW_HAS_NULL
|
TSROW_HAS_NONE
:
pRow
->
nData
=
BIT2_SIZE
(
pTSchema
->
numOfCols
-
1
)
+
pTSchema
->
flen
+
nv
;
break
;
default:
break
;
}
}
static
void
tMapTSRowNew
(
SArray
*
pArray
,
STSchema
*
pTSchema
,
STSRow2
*
pRow
,
uint8_t
flags
)
{
int32_t
nColVal
=
taosArrayGetSize
(
pArray
);
STColumn
*
pTColumn
;
SColVal
*
pColVal
;
ASSERT
(
nColVal
>
0
);
pRow
->
sver
=
pTSchema
->
version
;
pRow
->
flags
=
0
;
// ts
pTColumn
=
&
pTSchema
->
columns
[
0
];
pColVal
=
(
SColVal
*
)
taosArrayGet
(
pArray
,
0
);
ASSERT
(
pTColumn
->
colId
==
0
&&
pColVal
->
cid
==
0
);
ASSERT
(
pTColumn
->
type
==
TSDB_DATA_TYPE_TIMESTAMP
);
pRow
->
ts
=
pColVal
->
value
.
ts
;
// other fields
int32_t
iColVal
=
1
;
uint32_t
nv
=
0
;
uint8_t
*
pv
=
NULL
;
uint8_t
*
pidx
=
NULL
;
int16_t
nCol
=
0
;
for
(
int32_t
iColumn
=
1
;
iColumn
<
pTSchema
->
numOfCols
;
iColumn
++
)
{
pTColumn
=
&
pTSchema
->
columns
[
iColumn
];
if
(
iColVal
<
nColVal
)
{
pColVal
=
(
SColVal
*
)
taosArrayGet
(
pArray
,
iColVal
);
}
else
{
pColVal
=
NULL
;
}
if
(
pColVal
)
{
if
(
pColVal
->
cid
==
pTColumn
->
colId
)
{
iColVal
++
;
if
(
pColVal
->
isNone
)
{
goto
_set_none
;
}
else
if
(
pColVal
->
isNull
)
{
goto
_set_null
;
}
else
{
goto
_set_value
;
}
}
else
if
(
pColVal
->
cid
>
pTColumn
->
colId
)
{
goto
_set_none
;
}
else
{
ASSERT
(
0
);
}
}
else
{
goto
_set_none
;
}
_set_none:
pRow
->
flags
|=
TSROW_HAS_NONE
;
continue
;
_set_null:
pRow
->
flags
|=
TSROW_HAS_NULL
;
if
(
pidx
)
pidx
[
nCol
++
]
=
nv
;
nv
+=
tPutI16v
(
pv
?
pv
+
nv
:
pv
,
-
pTColumn
->
colId
);
continue
;
_set_value:
pRow
->
flags
!=
TSROW_HAS_VAL
;
if
(
pidx
)
pidx
[
nCol
++
]
=
nv
;
nv
+=
tPutI16v
(
pv
?
pv
+
nv
:
pv
,
pTColumn
->
colId
);
nv
+=
tPutValue
(
pv
?
pv
+
nv
:
pv
,
&
pColVal
->
value
,
pTColumn
->
type
);
continue
;
}
if
(
nv
<=
UINT8_MAX
)
{
pRow
->
flags
|=
TSROW_KV_SMALL
;
// small
}
else
if
(
nv
<=
UINT16_MAX
)
{
pRow
->
flags
|=
TSROW_KV_MID
;
// mid
}
else
{
pRow
->
flags
|=
TSROW_KV_BIG
;
// large
}
ASSERT
(
flags
==
0
||
pRow
->
flags
==
flags
);
}
static
void
tTSRowNewImpl
(
SArray
*
pArray
,
STSchema
*
pTSchema
,
STSRow2
*
pRowT
,
STSRow2
*
pRowK
)
{
int32_t
nColVal
=
taosArrayGetSize
(
pArray
);
STColumn
*
pTColumn
;
...
...
@@ -476,7 +291,7 @@ static void tTSRowNewImpl(SArray *pArray, STSchema *pTSchema, STSRow2 *pRowT, ST
continue
;
}
// finalize
(todo)
// finalize
if
(
pRowT
)
{
}
if
(
pRowK
)
{
...
...
@@ -501,7 +316,7 @@ static void tTSRowNewImpl(SArray *pArray, STSchema *pTSchema, STSRow2 *pRowT, ST
}
// try-decide-build
int32_t
tTSRowNew
(
SArray
*
pArray
,
STSchema
*
pTSchema
,
STSRow2
**
ppRow
)
{
int32_t
tTSRowNew
(
S
TSRowBuilder
*
pBuilder
,
S
Array
*
pArray
,
STSchema
*
pTSchema
,
STSRow2
**
ppRow
)
{
int32_t
code
=
0
;
STSRow2
rowT
=
{
0
};
STSRow2
rowK
=
{
0
};
...
...
@@ -510,29 +325,65 @@ int32_t tTSRowNew(SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow) {
// try
tTSRowNewImpl
(
pArray
,
pTSchema
,
&
rowT
,
&
rowK
);
ASSERT
(
rowT
.
flags
&&
rowK
.
flags
);
// alloc
nData
=
TMIN
(
rowT
.
nData
,
rowK
.
nData
);
*
ppRow
=
(
STSRow2
*
)
taosMemoryMalloc
(
sizeof
(
STSRow2
));
if
(
*
ppRow
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
(
*
ppRow
)
->
nData
=
0
;
(
*
ppRow
)
->
pData
=
NULL
;
if
(
nData
)
{
(
*
ppRow
)
->
pData
=
taosMemoryMalloc
(
nData
);
if
((
*
ppRow
)
->
pData
==
NULL
)
{
if
(
pBuilder
)
{
// create from a builder
if
(
nData
==
0
)
{
ASSERT
((
rowT
.
flags
&
0xf
)
==
TSROW_HAS_NONE
||
(
rowT
.
flags
&
0xf
)
==
TSROW_HAS_NULL
);
pBuilder
->
tsRow
.
nData
=
0
;
pBuilder
->
tsRow
.
pData
=
NULL
;
}
else
{
if
(
pBuilder
->
szBuf
<
nData
)
{
uint8_t
*
p
=
taosMemoryRealloc
(
pBuilder
->
pBuf
,
nData
);
if
(
p
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
pBuilder
->
pBuf
=
p
;
pBuilder
->
szBuf
=
nData
;
}
pBuilder
->
tsRow
.
nData
=
0
;
pBuilder
->
tsRow
.
pData
=
pBuilder
->
pBuf
;
}
*
ppRow
=
&
pBuilder
->
tsRow
;
}
else
{
// create a new one
*
ppRow
=
(
STSRow2
*
)
taosMemoryMalloc
(
sizeof
(
STSRow2
));
if
(
*
ppRow
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
(
*
ppRow
)
->
nData
=
0
;
(
*
ppRow
)
->
pData
=
NULL
;
if
(
nData
)
{
(
*
ppRow
)
->
pData
=
taosMemoryMalloc
(
nData
);
if
((
*
ppRow
)
->
pData
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
goto
_exit
;
}
}
}
// decide and build
if
(
rowT
.
nData
<=
rowK
.
nData
)
{
(
*
ppRow
)
->
flags
=
rowT
.
flags
;
tTSRowNewImpl
(
pArray
,
pTSchema
,
*
ppRow
,
NULL
);
ASSERT
((
*
ppRow
)
->
flags
==
rowT
.
flags
);
ASSERT
((
*
ppRow
)
->
nData
==
rowT
.
nData
);
}
else
{
(
*
ppRow
)
->
flags
=
rowK
.
flags
;
tTSRowNewImpl
(
pArray
,
pTSchema
,
NULL
,
*
ppRow
);
ASSERT
((
*
ppRow
)
->
flags
==
rowK
.
flags
);
ASSERT
((
*
ppRow
)
->
nData
==
rowK
.
nData
);
}
_exit:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录