Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
34a219b5
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看板
提交
34a219b5
编写于
5月 14, 2022
作者:
H
Hongze Cheng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: impl tsrow read
上级
f9bcea8d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
140 addition
and
55 deletion
+140
-55
include/common/tdataformat.h
include/common/tdataformat.h
+40
-12
source/common/src/tdataformat.c
source/common/src/tdataformat.c
+100
-43
未找到文件。
include/common/tdataformat.h
浏览文件 @
34a219b5
...
...
@@ -29,20 +29,41 @@ extern "C" {
typedef
struct
SSchema
SSchema
;
typedef
struct
STColumn
STColumn
;
typedef
struct
STSchema
STSchema
;
typedef
struct
SColVal
SColVal
;
typedef
struct
STSRow2
STSRow2
;
typedef
struct
STSRowBuilder
STSRowBuilder
;
typedef
struct
SKVIdx
SKVIdx
;
// STSRow2
int32_t
tEncodeTSRow
(
SEncoder
*
pEncoder
,
const
STSRow2
*
pRow
);
int32_t
tDecodeTSRow
(
SDecoder
*
pDecoder
,
STSRow2
*
pRow
);
int32_t
tTSRowGet
(
const
STSRow2
*
pRow
,
STSchema
*
pTSchema
,
int32_t
cid
,
const
uint8_t
**
ppData
,
uint32_t
*
nData
,
int8_t
*
flags
);
// STSchema
int32_t
tTSchemaCreate
(
int32_t
sver
,
SSchema
*
pSchema
,
int32_t
nCols
,
STSchema
**
ppTSchema
);
void
tTSchemaDestroy
(
STSchema
*
pTSchema
);
// SColVal
#define COL_VAL_SET_NONE(CV) \
do { \
(CV)->type = COL_NONE; \
(CV)->nData = 0; \
(CV)->pData = NULL; \
} while (0)
#define COL_VAL_SET_NULL(CV) \
do { \
(CV)->type = COL_NULL; \
(CV)->nData = 0; \
(CV)->pData = NULL; \
} while (0)
#define COL_VAL_SET_VAL(CV, PDATA, NDATA) \
do { \
(CV)->type = COL_VAL; \
(CV)->nData = (NDATA); \
(CV)->pData = (PDATA); \
} while (0)
// STSRow2
int32_t
tEncodeTSRow
(
SEncoder
*
pEncoder
,
const
STSRow2
*
pRow
);
int32_t
tDecodeTSRow
(
SDecoder
*
pDecoder
,
STSRow2
*
pRow
);
int32_t
tTSRowGet
(
const
STSRow2
*
pRow
,
STSchema
*
pTSchema
,
int32_t
iCol
,
SColVal
*
pColVal
);
// STSRowBuilder
int32_t
tTSRowBuilderInit
(
STSRowBuilder
*
pBuilder
,
int32_t
sver
,
SSchema
*
pSchema
,
int32_t
nCols
);
void
tTSRowBuilderClear
(
STSRowBuilder
*
pBuilder
);
...
...
@@ -73,11 +94,11 @@ struct STSchema {
#define TSROW_HAS_VAL ((uint8_t)0x4U)
#define TSROW_KV_ROW ((uint8_t)0x10U)
struct
STSRow2
{
TSKEY
ts
;
uint8_t
flags
;
int32_t
sver
;
uint32_t
nData
;
const
uint8_t
*
pData
;
TSKEY
ts
;
uint8_t
flags
;
int32_t
sver
;
uint32_t
nData
;
uint8_t
*
pData
;
};
struct
STSRowBuilder
{
...
...
@@ -94,6 +115,13 @@ struct STSRowBuilder {
STSRow2
row
;
};
typedef
enum
{
COL_VAL
=
0
,
COL_NONE
=
1
,
COL_NULL
=
2
}
EColValT
;
struct
SColVal
{
EColValT
type
;
uint32_t
nData
;
uint8_t
*
pData
;
};
#if 1 //====================================
// Imported since 3.0 and use bitmap to demonstrate None/Null/Norm, while use Null/Norm below 3.0 without of bitmap.
#define TD_SUPPORT_BITMAP
...
...
source/common/src/tdataformat.c
浏览文件 @
34a219b5
...
...
@@ -19,10 +19,10 @@
#include "tdatablock.h"
#include "tlog.h"
struct
SKVIdx
{
typedef
struct
SKVIdx
{
int32_t
cid
;
int32_t
offset
;
};
}
SKVIdx
;
#pragma pack(push, 1)
typedef
struct
{
...
...
@@ -34,6 +34,8 @@ typedef struct {
#define TSROW_IS_KV_ROW(r) ((r)->flags & TSROW_KV_ROW)
#define SET_BIT1(p, i, v) ((p)[(i) / 8] = (p)[(i) / 8] & (~(((uint8_t)1) << ((i) % 8))) | ((v) << ((i) % 8)))
#define SET_BIT2(p, i, v) ((p)[(i) / 4] = (p)[(i) / 4] & (~(((uint8_t)3) << ((i) % 4))) | ((v) << ((i) % 4)))
#define GET_BIT1(p, i) (((p)[(i) / 8] >> ((i) % 8)) & ((uint8_t)1))
#define GET_BIT2(p, i) (((p)[(i) / 4] >> ((i) % 4)) & ((uint8_t)3))
// STSRow2
int32_t
tEncodeTSRow
(
SEncoder
*
pEncoder
,
const
STSRow2
*
pRow
)
{
...
...
@@ -81,57 +83,112 @@ int32_t tDecodeTSRow(SDecoder *pDecoder, STSRow2 *pRow) {
return
0
;
}
int32_t
tTSRowGet
(
const
STSRow2
*
pRow
,
STSchema
*
pTSchema
,
int32_t
cid
,
const
uint8_t
**
ppData
,
uint32_t
*
nData
,
int8_t
*
flags
)
{
#if 0
if (cid == 0) {
*ppData = (uint8_t *)&pRow->ts;
*nData = sizeof(TSKEY);
*flags = 0;
} else {
uint32_t tflags = pRow->flags & 0xf;
*ppData = NULL;
*nData = 0;
static
FORCE_INLINE
int
kvRowCmprFn
(
const
void
*
p1
,
const
void
*
p2
)
{
col_id_t
cid
=
*
(
col_id_t
*
)
p1
;
SKVIdx
*
pKVIdx
=
(
SKVIdx
*
)
p2
;
switch (tflags) {
case TSROW_HAS_NONE:
*flags = -1;
break;
case TSROW_HAS_NULL:
*flags = 1;
break;
case TSROW_HAS_VAL:
*flags = 0;
// find the row
break;
if
(
cid
<
pKVIdx
->
cid
)
{
return
-
1
;
}
else
if
(
cid
>
pKVIdx
->
cid
)
{
return
1
;
}
return
0
;
}
int32_t
tTSRowGet
(
const
STSRow2
*
pRow
,
STSchema
*
pTSchema
,
int32_t
iCol
,
SColVal
*
pColVal
)
{
uint32_t
n
;
uint8_t
*
p
;
uint8_t
v
;
int32_t
bidx
=
iCol
-
1
;
STColumn
*
pTColumn
=
&
pTSchema
->
columns
[
iCol
];
STSKVRow
*
pTSKVRow
;
SKVIdx
*
pKVIdx
;
ASSERT
(
pTColumn
->
colId
!=
0
);
ASSERT
(
pRow
->
flags
&
0xf
!=
0
);
switch
(
pRow
->
flags
&
0xf
)
{
case
TSROW_HAS_NONE
:
COL_VAL_SET_NONE
(
pColVal
);
return
0
;
case
TSROW_HAS_NULL
:
COL_VAL_SET_NULL
(
pColVal
);
return
0
;
}
if
(
TSROW_IS_KV_ROW
(
pRow
))
{
ASSERT
((
pRow
->
flags
&
0xf
)
!=
TSROW_HAS_VAL
);
pTSKVRow
=
(
STSKVRow
*
)
pRow
->
pData
;
pKVIdx
=
bsearch
(
&
pTColumn
->
colId
,
pTSKVRow
->
idx
,
pTSKVRow
->
nCols
,
sizeof
(
SKVIdx
),
kvRowCmprFn
);
if
(
pKVIdx
==
NULL
)
{
COL_VAL_SET_NONE
(
pColVal
);
}
else
if
(
pKVIdx
->
offset
<
0
)
{
COL_VAL_SET_NULL
(
pColVal
);
}
else
{
p
=
pRow
->
pData
+
sizeof
(
STSKVRow
)
+
sizeof
(
SKVIdx
)
*
pTSKVRow
->
nCols
+
pKVIdx
->
offset
;
tGetBinary
(
p
,
&
p
,
&
n
);
COL_VAL_SET_VAL
(
pColVal
,
p
,
n
);
}
}
else
{
// get bitmap
switch
(
pRow
->
flags
&
0xf
)
{
p
=
pRow
->
pData
;
case
TSROW_HAS_NULL
|
TSROW_HAS_NONE
:
// read bit map (todo)
if (0) {
*flags = 1
;
v
=
GET_BIT1
(
p
,
bidx
);
if
(
v
==
0
)
{
COL_VAL_SET_NONE
(
pColVal
)
;
}
else
{
*flags = -1
;
COL_VAL_SET_NULL
(
pColVal
)
;
}
break
;
return
0
;
case
TSROW_HAS_VAL
|
TSROW_HAS_NONE
:
v
=
GET_BIT1
(
p
,
bidx
);
if
(
v
==
1
)
{
p
=
p
+
(
pTSchema
->
numOfCols
-
2
)
/
8
+
1
;
break
;
}
else
{
COL_VAL_SET_NONE
(
pColVal
);
return
0
;
}
case
TSROW_HAS_VAL
|
TSROW_HAS_NULL
:
// read bitmap (todo)
if (0) {
if (tflags & TSROW_HAS_NONE) {
*flags = -1;
} else {
*flags = 1;
}
v
=
GET_BIT1
(
p
,
bidx
);
if
(
v
==
1
)
{
p
=
p
+
(
pTSchema
->
numOfCols
-
2
)
/
8
+
1
;
break
;
}
else
{
// get value (todo)
COL_VAL_SET_NULL
(
pColVal
);
return
0
;
}
break;
case
TSROW_HAS_VAL
|
TSROW_HAS_NULL
|
TSROW_HAS_NONE
:
break;
v
=
GET_BIT2
(
p
,
bidx
);
if
(
v
==
0
)
{
COL_VAL_SET_NONE
(
pColVal
);
return
0
;
}
else
if
(
v
==
1
)
{
COL_VAL_SET_NULL
(
pColVal
);
return
0
;
}
else
if
(
v
==
2
)
{
p
=
p
+
(
pTSchema
->
numOfCols
-
2
)
/
4
+
1
;
break
;
}
else
{
ASSERT
(
0
);
}
default:
return -1
;
break
;
}
// get real value
p
=
p
+
pTColumn
->
offset
;
if
(
IS_VAR_DATA_TYPE
(
pTColumn
->
type
))
{
p
=
pTSchema
->
flen
+
*
(
int32_t
*
)
p
;
tGetBinary
(
p
,
&
p
,
&
n
);
}
else
{
n
=
pTColumn
->
bytes
;
}
COL_VAL_SET_VAL
(
pColVal
,
p
,
n
);
}
#endif
return
0
;
}
...
...
@@ -445,8 +502,8 @@ int tdAllocMemForCol(SDataCol *pCol, int maxPoints) {
spaceNeeded
+=
(
int
)
nBitmapBytes
;
// TODO: Currently, the compression of bitmap parts is affiliated to the column data parts, thus allocate 1 more
// TYPE_BYTES as to comprise complete TYPE_BYTES. Otherwise, invalid read/write would be triggered.
// spaceNeeded += TYPE_BYTES[pCol->type]; // the bitmap part is append as a single part since 2022.04.03, thus
remove
// the additional space
// spaceNeeded += TYPE_BYTES[pCol->type]; // the bitmap part is append as a single part since 2022.04.03, thus
//
remove
the additional space
#endif
if
(
pCol
->
spaceSize
<
spaceNeeded
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录