Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
097a047b
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
097a047b
编写于
10月 19, 2022
作者:
S
Shengliang Guan
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'origin/3.0' into FIX/TD-19593-3.0
上级
985e6f53
308dd565
变更
17
隐藏空白更改
内联
并排
Showing
17 changed file
with
86 addition
and
1665 deletion
+86
-1665
include/common/ttypes.h
include/common/ttypes.h
+3
-8
include/common/tvariant.h
include/common/tvariant.h
+0
-11
source/common/src/tdataformat.c
source/common/src/tdataformat.c
+3
-6
source/common/src/trow.c
source/common/src/trow.c
+0
-280
source/common/src/ttypes.c
source/common/src/ttypes.c
+18
-526
source/common/src/tvariant.c
source/common/src/tvariant.c
+2
-719
source/dnode/vnode/src/meta/metaQuery.c
source/dnode/vnode/src/meta/metaQuery.c
+5
-0
source/dnode/vnode/src/tsdb/tsdbCacheRead.c
source/dnode/vnode/src/tsdb/tsdbCacheRead.c
+1
-0
source/dnode/vnode/src/tsdb/tsdbRead.c
source/dnode/vnode/src/tsdb/tsdbRead.c
+6
-0
source/libs/executor/src/executor.c
source/libs/executor/src/executor.c
+3
-2
source/libs/executor/src/executorimpl.c
source/libs/executor/src/executorimpl.c
+1
-0
source/libs/executor/src/groupoperator.c
source/libs/executor/src/groupoperator.c
+7
-2
source/libs/executor/src/scanoperator.c
source/libs/executor/src/scanoperator.c
+22
-9
source/libs/executor/src/tfill.c
source/libs/executor/src/tfill.c
+3
-1
source/libs/executor/src/timewindowoperator.c
source/libs/executor/src/timewindowoperator.c
+10
-7
source/libs/executor/src/tsort.c
source/libs/executor/src/tsort.c
+2
-1
source/libs/function/src/builtinsimpl.c
source/libs/function/src/builtinsimpl.c
+0
-93
未找到文件。
include/common/ttypes.h
浏览文件 @
097a047b
...
...
@@ -337,21 +337,16 @@ typedef struct tDataTypeDescriptor {
int32_t
nBuf
);
int32_t
(
*
decompFunc
)(
void
*
pIn
,
int32_t
nIn
,
int32_t
nEle
,
void
*
pOut
,
int32_t
nOut
,
uint8_t
cmprAlg
,
void
*
pBuf
,
int32_t
nBuf
);
void
(
*
statisFunc
)(
int8_t
bitmapMode
,
const
void
*
pBitmap
,
const
void
*
pData
,
int32_t
numofrow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minindex
,
int16_t
*
maxindex
,
int16_t
*
numofnull
);
}
tDataTypeDescriptor
;
extern
tDataTypeDescriptor
tDataTypes
[
TSDB_DATA_TYPE_MAX
];
bool
isValidDataType
(
int32_t
type
);
void
setVardataNull
(
void
*
val
,
int32_t
type
);
void
setNull
(
void
*
val
,
int32_t
type
,
int32_t
bytes
);
void
setNullN
(
void
*
val
,
int32_t
type
,
int32_t
bytes
,
int32_t
numOfElems
);
const
void
*
getNullValue
(
int32_t
type
);
void
setVardataNull
(
void
*
val
,
int32_t
type
);
//void setNull(void *val, int32_t type, int32_t bytes);
//void setNullN(void *val, int32_t type, int32_t bytes, int32_t numOfElems);
void
assignVal
(
char
*
val
,
const
char
*
src
,
int32_t
len
,
int32_t
type
);
void
tsDataSwap
(
void
*
pLeft
,
void
*
pRight
,
int32_t
type
,
int32_t
size
,
void
*
buf
);
void
operateVal
(
void
*
dst
,
void
*
s1
,
void
*
s2
,
int32_t
optr
,
int32_t
type
);
void
*
getDataMin
(
int32_t
type
);
void
*
getDataMax
(
int32_t
type
);
...
...
include/common/tvariant.h
浏览文件 @
097a047b
...
...
@@ -39,8 +39,6 @@ typedef struct SVariant {
int32_t
toInteger
(
const
char
*
z
,
int32_t
n
,
int32_t
base
,
int64_t
*
value
);
int32_t
toUInteger
(
const
char
*
z
,
int32_t
n
,
int32_t
base
,
uint64_t
*
value
);
bool
taosVariantIsValid
(
SVariant
*
pVar
);
void
taosVariantCreateFromBinary
(
SVariant
*
pVar
,
const
char
*
pz
,
size_t
len
,
uint32_t
type
);
void
taosVariantDestroy
(
SVariant
*
pV
);
...
...
@@ -49,15 +47,6 @@ void taosVariantAssign(SVariant *pDst, const SVariant *pSrc);
int32_t
taosVariantCompare
(
const
SVariant
*
p1
,
const
SVariant
*
p2
);
int32_t
taosVariantToString
(
SVariant
*
pVar
,
char
*
dst
);
int32_t
taosVariantDump
(
SVariant
*
pVariant
,
char
*
payload
,
int16_t
type
,
bool
includeLengthPrefix
);
#if 0
int32_t taosVariantDumpEx(SVariant *pVariant, char *payload, int16_t type, bool includeLengthPrefix, bool *converted, char *extInfo);
#endif
int32_t
taosVariantTypeSetType
(
SVariant
*
pVariant
,
char
type
);
char
*
taosVariantGet
(
SVariant
*
pVar
,
int32_t
type
);
#ifdef __cplusplus
...
...
source/common/src/tdataformat.c
浏览文件 @
097a047b
...
...
@@ -114,7 +114,7 @@ static void setBitMap(uint8_t *pb, uint8_t v, int32_t idx, uint8_t flags) {
((uint32_t *)(p))[i] = (n); \
} \
} while (0)
#if 0
int32_t tTSRowNew(STSRowBuilder *pBuilder, SArray *pArray, STSchema *pTSchema, STSRow2 **ppRow) {
int32_t code = 0;
#if 0
...
...
@@ -432,7 +432,6 @@ void tTSRowFree(STSRow2 *pRow) {
}
void tTSRowGet(STSRow2 *pRow, STSchema *pTSchema, int32_t iCol, SColVal *pColVal) {
#if 0
uint8_t isTuple = ((pRow->flags & 0xf0) == 0) ? 1 : 0;
STColumn *pTColumn = &pTSchema->columns[iCol];
uint8_t flags = pRow->flags & (uint8_t)0xf;
...
...
@@ -577,12 +576,10 @@ _return_null:
_return_value:
*pColVal = COL_VAL_VALUE(pTColumn->colId, pTColumn->type, value);
return;
#endif
}
int32_t tTSRowToArray(STSRow2 *pRow, STSchema *pTSchema, SArray **ppArray) {
int32_t code = 0;
#if 0
SColVal cv;
(*ppArray) = taosArrayInit(pTSchema->numOfCols, sizeof(SColVal));
...
...
@@ -596,11 +593,11 @@ int32_t tTSRowToArray(STSRow2 *pRow, STSchema *pTSchema, SArray **ppArray) {
taosArrayPush(*ppArray, &cv);
}
#endif
_exit:
return code;
}
#endif
int32_t
tPutTSRow
(
uint8_t
*
p
,
STSRow2
*
pRow
)
{
int32_t
n
=
0
;
...
...
source/common/src/trow.c
浏览文件 @
097a047b
...
...
@@ -41,286 +41,6 @@ static bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, col_id_t colIdx, SCe
static
void
tdSCellValPrint
(
SCellVal
*
pVal
,
int8_t
colType
);
// implementation
/**
* @brief Compress bitmap bytes comprised of 2-bits to counterpart of 1-bit.
* e.g.
* TD_VTYPE_NORM 0x00U(00000000) to 00000000 Normal
* TD_VTYPE_NULL 0x01U(00000001) to 00000001 Null
* TD_VTYPE_NONE 0x02U(00000010) to 00000001 Null
*
* 00000000 0x00 0x00
* 01000000 0x40 0x08
* 10000000 0x80 0x08
* ...
* @param byte
* @return uint8_t
*/
static
uint8_t
tdGetMergedBitmapByte
(
uint8_t
byte
)
{
switch
(
byte
)
{
case
0x00
:
return
0x00
;
case
0x40
:
return
0x08
;
case
0x80
:
return
0x08
;
case
0x10
:
return
0x04
;
case
0x50
:
return
0x0c
;
case
0x90
:
return
0x0c
;
case
0x20
:
return
0x04
;
case
0x60
:
return
0x0c
;
case
0xa0
:
return
0x0c
;
case
0x04
:
return
0x02
;
case
0x44
:
return
0x0a
;
case
0x84
:
return
0x0a
;
case
0x14
:
return
0x06
;
case
0x54
:
return
0x0e
;
case
0x94
:
return
0x0e
;
case
0x24
:
return
0x06
;
case
0x64
:
return
0x0e
;
case
0xa4
:
return
0x0e
;
case
0x08
:
return
0x02
;
case
0x48
:
return
0x0a
;
case
0x88
:
return
0x0a
;
case
0x18
:
return
0x06
;
case
0x58
:
return
0x0e
;
case
0x98
:
return
0x0e
;
case
0x28
:
return
0x06
;
case
0x68
:
return
0x0e
;
case
0xa8
:
return
0x0e
;
case
0x01
:
return
0x01
;
case
0x41
:
return
0x09
;
case
0x81
:
return
0x09
;
case
0x11
:
return
0x05
;
case
0x51
:
return
0x0d
;
case
0x91
:
return
0x0d
;
case
0x21
:
return
0x05
;
case
0x61
:
return
0x0d
;
case
0xa1
:
return
0x0d
;
case
0x05
:
return
0x03
;
case
0x45
:
return
0x0b
;
case
0x85
:
return
0x0b
;
case
0x15
:
return
0x07
;
case
0x55
:
return
0x0f
;
case
0x95
:
return
0x0f
;
case
0x25
:
return
0x07
;
case
0x65
:
return
0x0f
;
case
0xa5
:
return
0x0f
;
case
0x09
:
return
0x03
;
case
0x49
:
return
0x0b
;
case
0x89
:
return
0x0b
;
case
0x19
:
return
0x07
;
case
0x59
:
return
0x0f
;
case
0x99
:
return
0x0f
;
case
0x29
:
return
0x07
;
case
0x69
:
return
0x0f
;
case
0xa9
:
return
0x0f
;
case
0x02
:
return
0x01
;
case
0x42
:
return
0x09
;
case
0x82
:
return
0x09
;
case
0x12
:
return
0x05
;
case
0x52
:
return
0x0d
;
case
0x92
:
return
0x0d
;
case
0x22
:
return
0x05
;
case
0x62
:
return
0x0d
;
case
0xa2
:
return
0x0d
;
case
0x06
:
return
0x03
;
case
0x46
:
return
0x0b
;
case
0x86
:
return
0x0b
;
case
0x16
:
return
0x07
;
case
0x56
:
return
0x0f
;
case
0x96
:
return
0x0f
;
case
0x26
:
return
0x07
;
case
0x66
:
return
0x0f
;
case
0xa6
:
return
0x0f
;
case
0x0a
:
return
0x03
;
case
0x4a
:
return
0x0b
;
case
0x8a
:
return
0x0b
;
case
0x1a
:
return
0x07
;
case
0x5a
:
return
0x0f
;
case
0x9a
:
return
0x0f
;
case
0x2a
:
return
0x07
;
case
0x6a
:
return
0x0f
;
case
0xaa
:
return
0x0f
;
default:
// make sure the bitmap area is set to 0 firstly
ASSERT
(
0
);
return
0x0f
;
// return NULL bitmap for exception
}
}
/**
* @brief Merge bitmap from 2 bits to 1 bit, and the memory buffer should be guaranteed by the invoker.
*
* @param srcBitmap
* @param nBits
* @param dstBitmap
*/
void
tdMergeBitmap
(
uint8_t
*
srcBitmap
,
int32_t
nBits
,
uint8_t
*
dstBitmap
)
{
int32_t
i
=
0
,
j
=
0
;
int32_t
nBytes
=
TD_BITMAP_BYTES
(
nBits
);
int32_t
nRoundBytes
=
nBits
/
4
;
int32_t
nRemainderBits
=
nBits
-
nRoundBytes
*
4
;
switch
(
nRemainderBits
)
{
case
0
:
// NOTHING TODO
break
;
case
1
:
{
void
*
lastByte
=
POINTER_SHIFT
(
srcBitmap
,
nRoundBytes
);
*
(
uint8_t
*
)
lastByte
&=
0xC0
;
}
break
;
case
2
:
{
void
*
lastByte
=
POINTER_SHIFT
(
srcBitmap
,
nRoundBytes
);
*
(
uint8_t
*
)
lastByte
&=
0xF0
;
}
break
;
case
3
:
{
void
*
lastByte
=
POINTER_SHIFT
(
srcBitmap
,
nRoundBytes
);
*
(
uint8_t
*
)
lastByte
&=
0xFC
;
}
break
;
default:
ASSERT
(
0
);
}
if
(
nBytes
>
0
)
{
dstBitmap
[
j
]
=
(
tdGetMergedBitmapByte
(
srcBitmap
[
i
])
<<
4
);
}
while
((
++
i
)
<
nBytes
)
{
if
((
i
&
1
)
==
0
)
{
dstBitmap
[
j
]
=
(
tdGetMergedBitmapByte
(
srcBitmap
[
i
])
<<
4
);
}
else
{
dstBitmap
[
j
]
|=
tdGetMergedBitmapByte
(
srcBitmap
[
i
]);
++
j
;
}
}
}
/**
* @brief Set bitmap area by byte preferentially and then by bit.
*
* @param pBitmap
* @param nEle
* @param valType
* @param bitmapMode 0 for 2 bits, 1 for 1 bit
* @return int32_t
*/
int32_t
tdSetBitmapValTypeN
(
void
*
pBitmap
,
int16_t
nEle
,
TDRowValT
valType
,
int8_t
bitmapMode
)
{
TASSERT
(
valType
<
TD_VTYPE_MAX
);
int32_t
nBytes
=
(
bitmapMode
==
0
?
nEle
/
TD_VTYPE_PARTS
:
nEle
/
TD_VTYPE_PARTS_I
);
uint8_t
vTypeByte
=
tdVTypeByte
[
bitmapMode
][
valType
];
for
(
int
i
=
0
;
i
<
nBytes
;
++
i
)
{
*
(
uint8_t
*
)
pBitmap
=
vTypeByte
;
pBitmap
=
POINTER_SHIFT
(
pBitmap
,
1
);
}
int32_t
nLeft
=
nEle
-
nBytes
*
(
bitmapMode
==
0
?
TD_VTYPE_BITS
:
TD_VTYPE_BITS_I
);
for
(
int
j
=
0
;
j
<
nLeft
;
++
j
)
{
tdSetBitmapValType
(
pBitmap
,
j
,
valType
,
bitmapMode
);
}
return
TSDB_CODE_SUCCESS
;
}
bool
tdIsBitmapBlkNorm
(
const
void
*
pBitmap
,
int32_t
numOfBits
,
int8_t
bitmapMode
)
{
int32_t
nBytes
=
(
bitmapMode
==
0
?
numOfBits
/
TD_VTYPE_PARTS
:
numOfBits
/
TD_VTYPE_PARTS_I
);
uint8_t
vTypeByte
=
tdVTypeByte
[
bitmapMode
][
TD_VTYPE_NORM
];
uint8_t
*
qBitmap
=
(
uint8_t
*
)
pBitmap
;
for
(
int
i
=
0
;
i
<
nBytes
;
++
i
)
{
if
(
*
qBitmap
!=
vTypeByte
)
{
return
false
;
}
qBitmap
=
(
uint8_t
*
)
POINTER_SHIFT
(
pBitmap
,
i
);
}
int32_t
nLeft
=
numOfBits
-
nBytes
*
(
bitmapMode
==
0
?
TD_VTYPE_BITS
:
TD_VTYPE_BITS_I
);
for
(
int
j
=
0
;
j
<
nLeft
;
++
j
)
{
uint8_t
vType
;
tdGetBitmapValType
(
qBitmap
,
j
,
&
vType
,
bitmapMode
);
if
(
vType
!=
TD_VTYPE_NORM
)
{
return
false
;
}
}
return
true
;
}
STSRow
*
tdRowDup
(
STSRow
*
row
)
{
STSRow
*
trow
=
taosMemoryMalloc
(
TD_ROW_LEN
(
row
));
if
(
trow
==
NULL
)
return
NULL
;
...
...
source/common/src/ttypes.c
浏览文件 @
097a047b
...
...
@@ -37,394 +37,30 @@ const int32_t TYPE_BYTES[16] = {
TSDB_MAX_JSON_TAG_LEN
,
// TSDB_DATA_TYPE_JSON
};
#define DO_STATICS(__sum, __min, __max, __minIndex, __maxIndex, _list, _index) \
do { \
(__sum) += (_list)[(_index)]; \
if ((__min) > (_list)[(_index)]) { \
(__min) = (_list)[(_index)]; \
(__minIndex) = (_index); \
} \
\
if ((__max) < (_list)[(_index)]) { \
(__max) = (_list)[(_index)]; \
(__maxIndex) = (_index); \
} \
} while (0)
static
void
getStatics_bool
(
int8_t
bitmapMode
,
const
void
*
pBitmap
,
const
void
*
pData
,
int32_t
numOfRow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minIndex
,
int16_t
*
maxIndex
,
int16_t
*
numOfNull
)
{
int8_t
*
data
=
(
int8_t
*
)
pData
;
*
min
=
INT64_MAX
;
*
max
=
INT64_MIN
;
*
minIndex
=
0
;
*
maxIndex
=
0
;
assert
(
numOfRow
<=
INT16_MAX
);
for
(
int32_t
i
=
0
;
i
<
numOfRow
;
++
i
)
{
// if (data[i] == TSDB_DATA_BOOL_NULL) {
if
(
!
tdIsBitmapValTypeNorm
(
pBitmap
,
i
,
bitmapMode
))
{
(
*
numOfNull
)
+=
1
;
continue
;
}
DO_STATICS
(
*
sum
,
*
min
,
*
max
,
*
minIndex
,
*
maxIndex
,
data
,
i
);
}
}
static
void
getStatics_i8
(
int8_t
bitmapMode
,
const
void
*
pBitmap
,
const
void
*
pData
,
int32_t
numOfRow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minIndex
,
int16_t
*
maxIndex
,
int16_t
*
numOfNull
)
{
int8_t
*
data
=
(
int8_t
*
)
pData
;
*
min
=
INT64_MAX
;
*
max
=
INT64_MIN
;
*
minIndex
=
0
;
*
maxIndex
=
0
;
assert
(
numOfRow
<=
INT16_MAX
);
for
(
int32_t
i
=
0
;
i
<
numOfRow
;
++
i
)
{
// if (((uint8_t)data[i]) == TSDB_DATA_TINYINT_NULL) {
if
(
!
tdIsBitmapValTypeNorm
(
pBitmap
,
i
,
bitmapMode
))
{
(
*
numOfNull
)
+=
1
;
continue
;
}
DO_STATICS
(
*
sum
,
*
min
,
*
max
,
*
minIndex
,
*
maxIndex
,
data
,
i
);
}
}
static
void
getStatics_u8
(
int8_t
bitmapMode
,
const
void
*
pBitmap
,
const
void
*
pData
,
int32_t
numOfRow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minIndex
,
int16_t
*
maxIndex
,
int16_t
*
numOfNull
)
{
uint8_t
*
data
=
(
uint8_t
*
)
pData
;
uint64_t
_min
=
UINT64_MAX
;
uint64_t
_max
=
0
;
uint64_t
_sum
=
0
;
*
minIndex
=
0
;
*
maxIndex
=
0
;
assert
(
numOfRow
<=
INT16_MAX
);
for
(
int32_t
i
=
0
;
i
<
numOfRow
;
++
i
)
{
// if (((uint8_t)data[i]) == TSDB_DATA_UTINYINT_NULL) {
if
(
!
tdIsBitmapValTypeNorm
(
pBitmap
,
i
,
bitmapMode
))
{
(
*
numOfNull
)
+=
1
;
continue
;
}
DO_STATICS
(
_sum
,
_min
,
_max
,
*
minIndex
,
*
maxIndex
,
data
,
i
);
}
*
min
=
_min
;
*
max
=
_max
;
*
sum
=
_sum
;
}
static
void
getStatics_i16
(
int8_t
bitmapMode
,
const
void
*
pBitmap
,
const
void
*
pData
,
int32_t
numOfRow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minIndex
,
int16_t
*
maxIndex
,
int16_t
*
numOfNull
)
{
int16_t
*
data
=
(
int16_t
*
)
pData
;
*
min
=
INT64_MAX
;
*
max
=
INT64_MIN
;
*
minIndex
=
0
;
*
maxIndex
=
0
;
assert
(
numOfRow
<=
INT16_MAX
);
for
(
int32_t
i
=
0
;
i
<
numOfRow
;
++
i
)
{
// if (((uint16_t)data[i]) == TSDB_DATA_SMALLINT_NULL) {
if
(
!
tdIsBitmapValTypeNorm
(
pBitmap
,
i
,
bitmapMode
))
{
(
*
numOfNull
)
+=
1
;
continue
;
}
DO_STATICS
(
*
sum
,
*
min
,
*
max
,
*
minIndex
,
*
maxIndex
,
data
,
i
);
}
}
static
void
getStatics_u16
(
int8_t
bitmapMode
,
const
void
*
pBitmap
,
const
void
*
pData
,
int32_t
numOfRow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minIndex
,
int16_t
*
maxIndex
,
int16_t
*
numOfNull
)
{
uint16_t
*
data
=
(
uint16_t
*
)
pData
;
uint64_t
_min
=
UINT64_MAX
;
uint64_t
_max
=
0
;
uint64_t
_sum
=
0
;
*
minIndex
=
0
;
*
maxIndex
=
0
;
assert
(
numOfRow
<=
INT16_MAX
);
for
(
int32_t
i
=
0
;
i
<
numOfRow
;
++
i
)
{
// if (((uint16_t)data[i]) == TSDB_DATA_USMALLINT_NULL) {
if
(
!
tdIsBitmapValTypeNorm
(
pBitmap
,
i
,
bitmapMode
))
{
(
*
numOfNull
)
+=
1
;
continue
;
}
DO_STATICS
(
_sum
,
_min
,
_max
,
*
minIndex
,
*
maxIndex
,
data
,
i
);
}
*
min
=
_min
;
*
max
=
_max
;
*
sum
=
_sum
;
}
static
void
getStatics_i32
(
int8_t
bitmapMode
,
const
void
*
pBitmap
,
const
void
*
pData
,
int32_t
numOfRow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minIndex
,
int16_t
*
maxIndex
,
int16_t
*
numOfNull
)
{
int32_t
*
data
=
(
int32_t
*
)
pData
;
*
min
=
INT64_MAX
;
*
max
=
INT64_MIN
;
*
minIndex
=
0
;
*
maxIndex
=
0
;
assert
(
numOfRow
<=
INT16_MAX
);
for
(
int32_t
i
=
0
;
i
<
numOfRow
;
++
i
)
{
// if (((uint32_t)data[i]) == TSDB_DATA_INT_NULL) {
if
(
!
tdIsBitmapValTypeNorm
(
pBitmap
,
i
,
bitmapMode
))
{
(
*
numOfNull
)
+=
1
;
continue
;
}
DO_STATICS
(
*
sum
,
*
min
,
*
max
,
*
minIndex
,
*
maxIndex
,
data
,
i
);
}
}
static
void
getStatics_u32
(
int8_t
bitmapMode
,
const
void
*
pBitmap
,
const
void
*
pData
,
int32_t
numOfRow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minIndex
,
int16_t
*
maxIndex
,
int16_t
*
numOfNull
)
{
uint32_t
*
data
=
(
uint32_t
*
)
pData
;
uint64_t
_min
=
UINT64_MAX
;
uint64_t
_max
=
0
;
uint64_t
_sum
=
0
;
*
minIndex
=
0
;
*
maxIndex
=
0
;
assert
(
numOfRow
<=
INT16_MAX
);
for
(
int32_t
i
=
0
;
i
<
numOfRow
;
++
i
)
{
// if (((uint32_t)data[i]) == TSDB_DATA_UINT_NULL) {
if
(
!
tdIsBitmapValTypeNorm
(
pBitmap
,
i
,
bitmapMode
))
{
(
*
numOfNull
)
+=
1
;
continue
;
}
DO_STATICS
(
_sum
,
_min
,
_max
,
*
minIndex
,
*
maxIndex
,
data
,
i
);
}
*
min
=
_min
;
*
max
=
_max
;
*
sum
=
_sum
;
}
static
void
getStatics_i64
(
int8_t
bitmapMode
,
const
void
*
pBitmap
,
const
void
*
pData
,
int32_t
numOfRow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minIndex
,
int16_t
*
maxIndex
,
int16_t
*
numOfNull
)
{
int64_t
*
data
=
(
int64_t
*
)
pData
;
*
min
=
INT64_MAX
;
*
max
=
INT64_MIN
;
*
minIndex
=
0
;
*
maxIndex
=
0
;
assert
(
numOfRow
<=
INT16_MAX
);
for
(
int32_t
i
=
0
;
i
<
numOfRow
;
++
i
)
{
// if (((uint64_t)data[i]) == TSDB_DATA_BIGINT_NULL) {
if
(
!
tdIsBitmapValTypeNorm
(
pBitmap
,
i
,
bitmapMode
))
{
(
*
numOfNull
)
+=
1
;
continue
;
}
DO_STATICS
(
*
sum
,
*
min
,
*
max
,
*
minIndex
,
*
maxIndex
,
data
,
i
);
}
}
static
void
getStatics_u64
(
int8_t
bitmapMode
,
const
void
*
pBitmap
,
const
void
*
pData
,
int32_t
numOfRow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minIndex
,
int16_t
*
maxIndex
,
int16_t
*
numOfNull
)
{
uint64_t
*
data
=
(
uint64_t
*
)
pData
;
uint64_t
_min
=
UINT64_MAX
;
uint64_t
_max
=
0
;
uint64_t
_sum
=
0
;
*
minIndex
=
0
;
*
maxIndex
=
0
;
assert
(
numOfRow
<=
INT16_MAX
);
for
(
int32_t
i
=
0
;
i
<
numOfRow
;
++
i
)
{
// if (((uint64_t)data[i]) == TSDB_DATA_UBIGINT_NULL) {
if
(
!
tdIsBitmapValTypeNorm
(
pBitmap
,
i
,
bitmapMode
))
{
(
*
numOfNull
)
+=
1
;
continue
;
}
DO_STATICS
(
_sum
,
_min
,
_max
,
*
minIndex
,
*
maxIndex
,
data
,
i
);
}
*
min
=
_min
;
*
max
=
_max
;
*
sum
=
_sum
;
}
static
void
getStatics_f
(
int8_t
bitmapMode
,
const
void
*
pBitmap
,
const
void
*
pData
,
int32_t
numOfRow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minIndex
,
int16_t
*
maxIndex
,
int16_t
*
numOfNull
)
{
float
*
data
=
(
float
*
)
pData
;
float
fmin
=
FLT_MAX
;
float
fmax
=
-
FLT_MAX
;
double
dsum
=
0
;
*
minIndex
=
0
;
*
maxIndex
=
0
;
assert
(
numOfRow
<=
INT16_MAX
);
for
(
int32_t
i
=
0
;
i
<
numOfRow
;
++
i
)
{
// if ((*(uint32_t *)&(data[i])) == TSDB_DATA_FLOAT_NULL) {
if
(
!
tdIsBitmapValTypeNorm
(
pBitmap
,
i
,
bitmapMode
))
{
(
*
numOfNull
)
+=
1
;
continue
;
}
float
fv
=
GET_FLOAT_VAL
((
const
char
*
)
&
(
data
[
i
]));
dsum
+=
fv
;
if
(
fmin
>
fv
)
{
fmin
=
fv
;
*
minIndex
=
i
;
}
if
(
fmax
<
fv
)
{
fmax
=
fv
;
*
maxIndex
=
i
;
}
}
SET_DOUBLE_VAL
(
sum
,
dsum
);
SET_DOUBLE_VAL
(
max
,
fmax
);
SET_DOUBLE_VAL
(
min
,
fmin
);
}
static
void
getStatics_d
(
int8_t
bitmapMode
,
const
void
*
pBitmap
,
const
void
*
pData
,
int32_t
numOfRow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minIndex
,
int16_t
*
maxIndex
,
int16_t
*
numOfNull
)
{
double
*
data
=
(
double
*
)
pData
;
double
dmin
=
DBL_MAX
;
double
dmax
=
-
DBL_MAX
;
double
dsum
=
0
;
*
minIndex
=
0
;
*
maxIndex
=
0
;
assert
(
numOfRow
<=
INT16_MAX
);
for
(
int32_t
i
=
0
;
i
<
numOfRow
;
++
i
)
{
// if ((*(uint64_t *)&(data[i])) == TSDB_DATA_DOUBLE_NULL) {
if
(
!
tdIsBitmapValTypeNorm
(
pBitmap
,
i
,
bitmapMode
))
{
(
*
numOfNull
)
+=
1
;
continue
;
}
double
dv
=
0
;
dv
=
GET_DOUBLE_VAL
((
const
char
*
)
&
(
data
[
i
]));
dsum
+=
dv
;
if
(
dmin
>
dv
)
{
dmin
=
dv
;
*
minIndex
=
i
;
}
if
(
dmax
<
dv
)
{
dmax
=
dv
;
*
maxIndex
=
i
;
}
}
SET_DOUBLE_PTR
(
sum
,
&
dsum
);
SET_DOUBLE_PTR
(
max
,
&
dmax
);
SET_DOUBLE_PTR
(
min
,
&
dmin
);
}
static
void
getStatics_bin
(
int8_t
bitmapMode
,
const
void
*
pBitmap
,
const
void
*
pData
,
int32_t
numOfRow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minIndex
,
int16_t
*
maxIndex
,
int16_t
*
numOfNull
)
{
const
char
*
data
=
pData
;
assert
(
numOfRow
<=
INT16_MAX
);
for
(
int32_t
i
=
0
;
i
<
numOfRow
;
++
i
)
{
// if (isNull(data, TSDB_DATA_TYPE_BINARY)) {
if
(
!
tdIsBitmapValTypeNorm
(
pBitmap
,
i
,
bitmapMode
))
{
(
*
numOfNull
)
+=
1
;
}
data
+=
varDataTLen
(
data
);
}
*
sum
=
0
;
*
max
=
0
;
*
min
=
0
;
*
minIndex
=
0
;
*
maxIndex
=
0
;
}
static
void
getStatics_nchr
(
int8_t
bitmapMode
,
const
void
*
pBitmap
,
const
void
*
pData
,
int32_t
numOfRow
,
int64_t
*
min
,
int64_t
*
max
,
int64_t
*
sum
,
int16_t
*
minIndex
,
int16_t
*
maxIndex
,
int16_t
*
numOfNull
)
{
const
char
*
data
=
pData
;
assert
(
numOfRow
<=
INT16_MAX
);
for
(
int32_t
i
=
0
;
i
<
numOfRow
;
++
i
)
{
// if (isNull(data, TSDB_DATA_TYPE_NCHAR)) {
if
(
!
tdIsBitmapValTypeNorm
(
pBitmap
,
i
,
bitmapMode
))
{
(
*
numOfNull
)
+=
1
;
}
data
+=
varDataTLen
(
data
);
}
*
sum
=
0
;
*
max
=
0
;
*
min
=
0
;
*
minIndex
=
0
;
*
maxIndex
=
0
;
}
tDataTypeDescriptor
tDataTypes
[
TSDB_DATA_TYPE_MAX
]
=
{
{
TSDB_DATA_TYPE_NULL
,
6
,
1
,
"NOTYPE"
,
0
,
0
,
NULL
,
NULL
,
NULL
},
{
TSDB_DATA_TYPE_BOOL
,
4
,
CHAR_BYTES
,
"BOOL"
,
false
,
true
,
tsCompressBool
,
tsDecompressBool
,
getStatics_bool
},
{
TSDB_DATA_TYPE_TINYINT
,
7
,
CHAR_BYTES
,
"TINYINT"
,
INT8_MIN
,
INT8_MAX
,
tsCompressTinyint
,
tsDecompressTinyint
,
getStatics_i8
},
{
TSDB_DATA_TYPE_NULL
,
6
,
1
,
"NOTYPE"
,
0
,
0
,
NULL
,
NULL
},
{
TSDB_DATA_TYPE_BOOL
,
4
,
CHAR_BYTES
,
"BOOL"
,
false
,
true
,
tsCompressBool
,
tsDecompressBool
},
{
TSDB_DATA_TYPE_TINYINT
,
7
,
CHAR_BYTES
,
"TINYINT"
,
INT8_MIN
,
INT8_MAX
,
tsCompressTinyint
,
tsDecompressTinyint
},
{
TSDB_DATA_TYPE_SMALLINT
,
8
,
SHORT_BYTES
,
"SMALLINT"
,
INT16_MIN
,
INT16_MAX
,
tsCompressSmallint
,
tsDecompressSmallint
,
getStatics_i16
},
{
TSDB_DATA_TYPE_INT
,
3
,
INT_BYTES
,
"INT"
,
INT32_MIN
,
INT32_MAX
,
tsCompressInt
,
tsDecompressInt
,
getStatics_i32
},
{
TSDB_DATA_TYPE_BIGINT
,
6
,
LONG_BYTES
,
"BIGINT"
,
INT64_MIN
,
INT64_MAX
,
tsCompressBigint
,
tsDecompressBigint
,
getStatics_i64
},
{
TSDB_DATA_TYPE_FLOAT
,
5
,
FLOAT_BYTES
,
"FLOAT"
,
0
,
0
,
tsCompressFloat
,
tsDecompressFloat
,
getStatics_f
},
{
TSDB_DATA_TYPE_DOUBLE
,
6
,
DOUBLE_BYTES
,
"DOUBLE"
,
0
,
0
,
tsCompressDouble
,
tsDecompressDouble
,
getStatics_d
},
{
TSDB_DATA_TYPE_VARCHAR
,
6
,
1
,
"VARCHAR"
,
0
,
0
,
tsCompressString
,
tsDecompressString
,
getStatics_bin
},
tsDecompressSmallint
},
{
TSDB_DATA_TYPE_INT
,
3
,
INT_BYTES
,
"INT"
,
INT32_MIN
,
INT32_MAX
,
tsCompressInt
,
tsDecompressInt
},
{
TSDB_DATA_TYPE_BIGINT
,
6
,
LONG_BYTES
,
"BIGINT"
,
INT64_MIN
,
INT64_MAX
,
tsCompressBigint
,
tsDecompressBigint
},
{
TSDB_DATA_TYPE_FLOAT
,
5
,
FLOAT_BYTES
,
"FLOAT"
,
0
,
0
,
tsCompressFloat
,
tsDecompressFloat
},
{
TSDB_DATA_TYPE_DOUBLE
,
6
,
DOUBLE_BYTES
,
"DOUBLE"
,
0
,
0
,
tsCompressDouble
,
tsDecompressDouble
},
{
TSDB_DATA_TYPE_VARCHAR
,
6
,
1
,
"VARCHAR"
,
0
,
0
,
tsCompressString
,
tsDecompressString
},
{
TSDB_DATA_TYPE_TIMESTAMP
,
9
,
LONG_BYTES
,
"TIMESTAMP"
,
INT64_MIN
,
INT64_MAX
,
tsCompressTimestamp
,
tsDecompressTimestamp
,
getStatics_i64
},
{
TSDB_DATA_TYPE_NCHAR
,
5
,
1
,
"NCHAR"
,
0
,
0
,
tsCompressString
,
tsDecompressString
,
getStatics_nchr
},
{
TSDB_DATA_TYPE_UTINYINT
,
16
,
CHAR_BYTES
,
"TINYINT UNSIGNED"
,
0
,
UINT8_MAX
,
tsCompressTinyint
,
tsDecompressTinyint
,
getStatics_u8
},
tsDecompressTimestamp
},
{
TSDB_DATA_TYPE_NCHAR
,
5
,
1
,
"NCHAR"
,
0
,
0
,
tsCompressString
,
tsDecompressString
},
{
TSDB_DATA_TYPE_UTINYINT
,
16
,
CHAR_BYTES
,
"TINYINT UNSIGNED"
,
0
,
UINT8_MAX
,
tsCompressTinyint
,
tsDecompressTinyint
},
{
TSDB_DATA_TYPE_USMALLINT
,
17
,
SHORT_BYTES
,
"SMALLINT UNSIGNED"
,
0
,
UINT16_MAX
,
tsCompressSmallint
,
tsDecompressSmallint
,
getStatics_u16
},
{
TSDB_DATA_TYPE_UINT
,
12
,
INT_BYTES
,
"INT UNSIGNED"
,
0
,
UINT32_MAX
,
tsCompressInt
,
tsDecompressInt
,
getStatics_u32
},
{
TSDB_DATA_TYPE_UBIGINT
,
15
,
LONG_BYTES
,
"BIGINT UNSIGNED"
,
0
,
UINT64_MAX
,
tsCompressBigint
,
tsDecompressBigint
,
getStatics_u64
},
{
TSDB_DATA_TYPE_JSON
,
4
,
TSDB_MAX_JSON_TAG_LEN
,
"JSON"
,
0
,
0
,
tsCompressString
,
tsDecompressString
,
getStatics_nchr
},
};
char
tTokenTypeSwitcher
[
13
]
=
{
TSDB_DATA_TYPE_NULL
,
// no type
TSDB_DATA_TYPE_BINARY
,
// TK_ID
TSDB_DATA_TYPE_BOOL
,
// TK_BOOL
TSDB_DATA_TYPE_BIGINT
,
// TK_TINYINT
TSDB_DATA_TYPE_BIGINT
,
// TK_SMALLINT
TSDB_DATA_TYPE_BIGINT
,
// TK_INTEGER
TSDB_DATA_TYPE_BIGINT
,
// TK_BIGINT
TSDB_DATA_TYPE_DOUBLE
,
// TK_FLOAT
TSDB_DATA_TYPE_DOUBLE
,
// TK_DOUBLE
TSDB_DATA_TYPE_BINARY
,
// TK_STRING
TSDB_DATA_TYPE_BIGINT
,
// TK_TIMESTAMP
TSDB_DATA_TYPE_VARCHAR
,
// TK_BINARY
TSDB_DATA_TYPE_NCHAR
,
// TK_NCHAR
tsDecompressSmallint
},
{
TSDB_DATA_TYPE_UINT
,
12
,
INT_BYTES
,
"INT UNSIGNED"
,
0
,
UINT32_MAX
,
tsCompressInt
,
tsDecompressInt
},
{
TSDB_DATA_TYPE_UBIGINT
,
15
,
LONG_BYTES
,
"BIGINT UNSIGNED"
,
0
,
UINT64_MAX
,
tsCompressBigint
,
tsDecompressBigint
},
{
TSDB_DATA_TYPE_JSON
,
4
,
TSDB_MAX_JSON_TAG_LEN
,
"JSON"
,
0
,
0
,
tsCompressString
,
tsDecompressString
},
};
float
floatMin
=
-
FLT_MAX
,
floatMax
=
FLT_MAX
;
double
doubleMin
=
-
DBL_MAX
,
doubleMax
=
DBL_MAX
;
static
float
floatMin
=
-
FLT_MAX
,
floatMax
=
FLT_MAX
;
static
double
doubleMin
=
-
DBL_MAX
,
doubleMax
=
DBL_MAX
;
FORCE_INLINE
void
*
getDataMin
(
int32_t
type
)
{
switch
(
type
)
{
...
...
@@ -462,107 +98,8 @@ void setVardataNull(void *val, int32_t type) {
}
}
void
setNull
(
void
*
val
,
int32_t
type
,
int32_t
bytes
)
{
setNullN
(
val
,
type
,
bytes
,
1
);
}
#define POINTER_SHIFT(p, b) ((void *)((char *)(p) + (b)))
void
setNullN
(
void
*
val
,
int32_t
type
,
int32_t
bytes
,
int32_t
numOfElems
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint8_t
*
)(
POINTER_SHIFT
(
val
,
i
*
tDataTypes
[
type
].
bytes
))
=
TSDB_DATA_BOOL_NULL
;
}
break
;
case
TSDB_DATA_TYPE_TINYINT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint8_t
*
)(
POINTER_SHIFT
(
val
,
i
*
tDataTypes
[
type
].
bytes
))
=
TSDB_DATA_TINYINT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_SMALLINT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint16_t
*
)(
POINTER_SHIFT
(
val
,
i
*
tDataTypes
[
type
].
bytes
))
=
TSDB_DATA_SMALLINT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_INT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint32_t
*
)(
POINTER_SHIFT
(
val
,
i
*
tDataTypes
[
type
].
bytes
))
=
TSDB_DATA_INT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint64_t
*
)(
POINTER_SHIFT
(
val
,
i
*
tDataTypes
[
type
].
bytes
))
=
TSDB_DATA_BIGINT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_UTINYINT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint8_t
*
)(
POINTER_SHIFT
(
val
,
i
*
tDataTypes
[
type
].
bytes
))
=
TSDB_DATA_UTINYINT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_USMALLINT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint16_t
*
)(
POINTER_SHIFT
(
val
,
i
*
tDataTypes
[
type
].
bytes
))
=
TSDB_DATA_USMALLINT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_UINT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint32_t
*
)(
POINTER_SHIFT
(
val
,
i
*
tDataTypes
[
type
].
bytes
))
=
TSDB_DATA_UINT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_UBIGINT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint64_t
*
)(
POINTER_SHIFT
(
val
,
i
*
tDataTypes
[
type
].
bytes
))
=
TSDB_DATA_UBIGINT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_FLOAT
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint32_t
*
)(
POINTER_SHIFT
(
val
,
i
*
tDataTypes
[
type
].
bytes
))
=
TSDB_DATA_FLOAT_NULL
;
}
break
;
case
TSDB_DATA_TYPE_DOUBLE
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint64_t
*
)(
POINTER_SHIFT
(
val
,
i
*
tDataTypes
[
type
].
bytes
))
=
TSDB_DATA_DOUBLE_NULL
;
}
break
;
case
TSDB_DATA_TYPE_NCHAR
:
case
TSDB_DATA_TYPE_BINARY
:
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
setVardataNull
(
POINTER_SHIFT
(
val
,
i
*
bytes
),
type
);
}
break
;
default:
{
for
(
int32_t
i
=
0
;
i
<
numOfElems
;
++
i
)
{
*
(
uint32_t
*
)(
POINTER_SHIFT
(
val
,
i
*
tDataTypes
[
TSDB_DATA_TYPE_INT
].
bytes
))
=
TSDB_DATA_INT_NULL
;
}
break
;
}
}
}
static
uint8_t
nullBool
=
TSDB_DATA_BOOL_NULL
;
static
uint8_t
nullTinyInt
=
TSDB_DATA_TINYINT_NULL
;
static
uint16_t
nullSmallInt
=
TSDB_DATA_SMALLINT_NULL
;
static
uint32_t
nullInt
=
TSDB_DATA_INT_NULL
;
static
uint64_t
nullBigInt
=
TSDB_DATA_BIGINT_NULL
;
static
uint32_t
nullFloat
=
TSDB_DATA_FLOAT_NULL
;
static
uint64_t
nullDouble
=
TSDB_DATA_DOUBLE_NULL
;
static
uint8_t
nullTinyIntu
=
TSDB_DATA_UTINYINT_NULL
;
static
uint16_t
nullSmallIntu
=
TSDB_DATA_USMALLINT_NULL
;
static
uint32_t
nullIntu
=
TSDB_DATA_UINT_NULL
;
static
uint64_t
nullBigIntu
=
TSDB_DATA_UBIGINT_NULL
;
static
SBinaryNullT
nullBinary
=
{
1
,
TSDB_DATA_BINARY_NULL
};
static
SNCharNullT
nullNchar
=
{
4
,
TSDB_DATA_NCHAR_NULL
};
static
const
void
*
nullValues
[]
=
{
&
nullBool
,
&
nullTinyInt
,
&
nullSmallInt
,
&
nullInt
,
&
nullBigInt
,
&
nullFloat
,
&
nullDouble
,
&
nullBinary
,
&
nullBigInt
,
&
nullNchar
,
&
nullTinyIntu
,
&
nullSmallIntu
,
&
nullIntu
,
&
nullBigIntu
,
};
const
void
*
getNullValue
(
int32_t
type
)
{
assert
(
type
>=
TSDB_DATA_TYPE_BOOL
&&
type
<=
TSDB_DATA_TYPE_UBIGINT
);
// TODO: extend the types
return
nullValues
[
type
-
1
];
}
void
assignVal
(
char
*
val
,
const
char
*
src
,
int32_t
len
,
int32_t
type
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
...
...
@@ -648,48 +185,3 @@ void operateVal(void *dst, void *s1, void *s2, int32_t optr, int32_t type) {
assert
(
0
);
}
}
void
tsDataSwap
(
void
*
pLeft
,
void
*
pRight
,
int32_t
type
,
int32_t
size
,
void
*
buf
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UINT
:
{
TSWAP
(
*
(
int32_t
*
)(
pLeft
),
*
(
int32_t
*
)(
pRight
));
break
;
}
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_UBIGINT
:
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
TSWAP
(
*
(
int64_t
*
)(
pLeft
),
*
(
int64_t
*
)(
pRight
));
break
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
TSWAP
(
*
(
double
*
)(
pLeft
),
*
(
double
*
)(
pRight
));
break
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
{
TSWAP
(
*
(
int16_t
*
)(
pLeft
),
*
(
int16_t
*
)(
pRight
));
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
TSWAP
(
*
(
float
*
)(
pLeft
),
*
(
float
*
)(
pRight
));
break
;
}
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_UTINYINT
:
{
TSWAP
(
*
(
int8_t
*
)(
pLeft
),
*
(
int8_t
*
)(
pRight
));
break
;
}
default:
{
memcpy
(
buf
,
pLeft
,
size
);
memcpy
(
pLeft
,
pRight
,
size
);
memcpy
(
pRight
,
buf
,
size
);
break
;
}
}
}
source/common/src/tvariant.c
浏览文件 @
097a047b
...
...
@@ -19,22 +19,6 @@
#include "ttokendef.h"
#include "tvariant.h"
#define SET_EXT_INFO(converted, res, minv, maxv, exti) \
do { \
if (converted == NULL || exti == NULL || *converted == false) { \
break; \
} \
if ((res) < (minv)) { \
*exti = -1; \
break; \
} \
if ((res) > (maxv)) { \
*exti = 1; \
break; \
} \
assert(0); \
} while (0)
int32_t
toInteger
(
const
char
*
z
,
int32_t
n
,
int32_t
base
,
int64_t
*
value
)
{
errno
=
0
;
char
*
endPtr
=
NULL
;
...
...
@@ -53,8 +37,8 @@ int32_t toUInteger(const char *z, int32_t n, int32_t base, uint64_t *value) {
char
*
endPtr
=
NULL
;
const
char
*
p
=
z
;
while
(
*
p
!=
0
&&
*
p
==
' '
)
p
++
;
if
(
*
p
!=
0
&&
*
p
==
'-'
)
{
while
(
*
p
==
' '
)
p
++
;
if
(
*
p
==
'-'
)
{
return
-
1
;
}
...
...
@@ -176,11 +160,6 @@ void taosVariantDestroy(SVariant *pVar) {
}
}
bool
taosVariantIsValid
(
SVariant
*
pVar
)
{
assert
(
pVar
!=
NULL
);
return
isValidDataType
(
pVar
->
nType
);
}
void
taosVariantAssign
(
SVariant
*
pDst
,
const
SVariant
*
pSrc
)
{
if
(
pSrc
==
NULL
||
pDst
==
NULL
)
return
;
...
...
@@ -265,702 +244,6 @@ int32_t taosVariantCompare(const SVariant *p1, const SVariant *p2) {
}
}
int32_t
taosVariantToString
(
SVariant
*
pVar
,
char
*
dst
)
{
if
(
pVar
==
NULL
||
dst
==
NULL
)
return
0
;
switch
(
pVar
->
nType
)
{
case
TSDB_DATA_TYPE_BINARY
:
{
int32_t
len
=
sprintf
(
dst
,
"
\'
%s
\'
"
,
pVar
->
pz
);
assert
(
len
<=
pVar
->
nLen
+
sizeof
(
"
\'
"
)
*
2
);
// two more chars
return
len
;
}
case
TSDB_DATA_TYPE_NCHAR
:
{
dst
[
0
]
=
'\''
;
taosUcs4ToMbs
(
pVar
->
ucs4
,
(
taosUcs4len
(
pVar
->
ucs4
)
+
1
)
*
TSDB_NCHAR_SIZE
,
dst
+
1
);
int32_t
len
=
(
int32_t
)
strlen
(
dst
);
dst
[
len
]
=
'\''
;
dst
[
len
+
1
]
=
0
;
return
len
+
1
;
}
case
TSDB_DATA_TYPE_BOOL
:
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_SMALLINT
:
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_UTINYINT
:
case
TSDB_DATA_TYPE_USMALLINT
:
case
TSDB_DATA_TYPE_UINT
:
return
sprintf
(
dst
,
"%d"
,
(
int32_t
)
pVar
->
i
);
case
TSDB_DATA_TYPE_BIGINT
:
return
sprintf
(
dst
,
"%"
PRId64
,
pVar
->
i
);
case
TSDB_DATA_TYPE_UBIGINT
:
return
sprintf
(
dst
,
"%"
PRIu64
,
pVar
->
u
);
case
TSDB_DATA_TYPE_FLOAT
:
case
TSDB_DATA_TYPE_DOUBLE
:
return
sprintf
(
dst
,
"%.9lf"
,
pVar
->
d
);
default:
return
0
;
}
}
static
FORCE_INLINE
int32_t
convertToBoolImpl
(
char
*
pStr
,
int32_t
len
)
{
if
((
strncasecmp
(
pStr
,
"true"
,
len
)
==
0
)
&&
(
len
==
4
))
{
return
TSDB_TRUE
;
}
else
if
((
strncasecmp
(
pStr
,
"false"
,
len
)
==
0
)
&&
(
len
==
5
))
{
return
TSDB_FALSE
;
}
else
if
(
strcasecmp
(
pStr
,
TSDB_DATA_NULL_STR_L
)
==
0
)
{
return
TSDB_DATA_BOOL_NULL
;
}
else
{
return
-
1
;
}
}
static
FORCE_INLINE
int32_t
wcsconvertToBoolImpl
(
TdUcs4
*
pstr
,
int32_t
len
)
{
if
((
wcsncasecmp
(
pstr
,
L"true"
,
len
)
==
0
)
&&
(
len
==
4
))
{
return
TSDB_TRUE
;
}
else
if
(
wcsncasecmp
(
pstr
,
L"false"
,
len
)
==
0
&&
(
len
==
5
))
{
return
TSDB_FALSE
;
}
else
if
(
memcmp
(
pstr
,
L"null"
,
wcslen
(
L"null"
))
==
0
)
{
return
TSDB_DATA_BOOL_NULL
;
}
else
{
return
-
1
;
}
}
static
int32_t
toBinary
(
SVariant
*
pVariant
,
char
**
pDest
,
int32_t
*
pDestSize
)
{
const
int32_t
INITIAL_ALLOC_SIZE
=
40
;
char
*
pBuf
=
NULL
;
// it is a in-place convert type for SVariant, local buffer is needed
if
(
*
pDest
==
pVariant
->
pz
)
{
pBuf
=
taosMemoryCalloc
(
1
,
INITIAL_ALLOC_SIZE
);
}
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NCHAR
)
{
size_t
newSize
=
pVariant
->
nLen
*
TSDB_NCHAR_SIZE
;
if
(
pBuf
!=
NULL
)
{
if
(
newSize
>=
INITIAL_ALLOC_SIZE
)
{
pBuf
=
taosMemoryRealloc
(
pBuf
,
newSize
+
1
);
}
taosUcs4ToMbs
(
pVariant
->
ucs4
,
(
int32_t
)
newSize
,
pBuf
);
taosMemoryFree
(
pVariant
->
ucs4
);
pBuf
[
newSize
]
=
0
;
}
else
{
taosUcs4ToMbs
(
pVariant
->
ucs4
,
(
int32_t
)
newSize
,
*
pDest
);
}
}
else
{
if
(
IS_SIGNED_NUMERIC_TYPE
(
pVariant
->
nType
))
{
sprintf
(
pBuf
==
NULL
?
*
pDest
:
pBuf
,
"%"
PRId64
,
pVariant
->
i
);
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_DOUBLE
||
pVariant
->
nType
==
TSDB_DATA_TYPE_FLOAT
)
{
sprintf
(
pBuf
==
NULL
?
*
pDest
:
pBuf
,
"%lf"
,
pVariant
->
d
);
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BOOL
)
{
sprintf
(
pBuf
==
NULL
?
*
pDest
:
pBuf
,
"%s"
,
(
pVariant
->
i
==
TSDB_TRUE
)
?
"TRUE"
:
"FALSE"
);
}
else
if
(
pVariant
->
nType
==
0
)
{
// null data
setNull
(
pBuf
==
NULL
?
*
pDest
:
pBuf
,
TSDB_DATA_TYPE_BINARY
,
0
);
}
}
if
(
pBuf
!=
NULL
)
{
taosMemoryFree
(
pVariant
->
pz
);
*
pDest
=
pBuf
;
}
*
pDestSize
=
(
int32_t
)
strlen
(
*
pDest
);
return
0
;
}
static
int32_t
toNchar
(
SVariant
*
pVariant
,
char
**
pDest
,
int32_t
*
pDestSize
)
{
char
tmpBuf
[
40
]
=
{
0
};
char
*
pDst
=
tmpBuf
;
int32_t
nLen
=
0
;
// convert the number to string, than convert it to wchar string.
if
(
IS_SIGNED_NUMERIC_TYPE
(
pVariant
->
nType
))
{
nLen
=
sprintf
(
pDst
,
"%"
PRId64
,
pVariant
->
i
);
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
pVariant
->
nType
))
{
nLen
=
sprintf
(
pDst
,
"%"
PRIu64
,
pVariant
->
u
);
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_DOUBLE
||
pVariant
->
nType
==
TSDB_DATA_TYPE_FLOAT
)
{
nLen
=
sprintf
(
pDst
,
"%lf"
,
pVariant
->
d
);
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BINARY
)
{
pDst
=
pVariant
->
pz
;
nLen
=
pVariant
->
nLen
;
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BOOL
)
{
nLen
=
sprintf
(
pDst
,
"%s"
,
(
pVariant
->
i
==
TSDB_TRUE
)
?
"TRUE"
:
"FALSE"
);
}
if
(
*
pDest
==
pVariant
->
pz
)
{
TdUcs4
*
pWStr
=
taosMemoryCalloc
(
1
,
(
nLen
+
1
)
*
TSDB_NCHAR_SIZE
);
bool
ret
=
taosMbsToUcs4
(
pDst
,
nLen
,
pWStr
,
(
nLen
+
1
)
*
TSDB_NCHAR_SIZE
,
NULL
);
if
(
!
ret
)
{
taosMemoryFreeClear
(
pWStr
);
return
-
1
;
}
// free the binary buffer in the first place
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BINARY
)
{
taosMemoryFree
(
pVariant
->
ucs4
);
}
pVariant
->
ucs4
=
pWStr
;
*
pDestSize
=
taosUcs4len
(
pVariant
->
ucs4
);
// shrink the allocate memory, no need to check here.
char
*
tmp
=
taosMemoryRealloc
(
pVariant
->
ucs4
,
(
*
pDestSize
+
1
)
*
TSDB_NCHAR_SIZE
);
assert
(
tmp
!=
NULL
);
pVariant
->
ucs4
=
(
TdUcs4
*
)
tmp
;
}
else
{
int32_t
output
=
0
;
bool
ret
=
taosMbsToUcs4
(
pDst
,
nLen
,
(
TdUcs4
*
)
*
pDest
,
(
nLen
+
1
)
*
TSDB_NCHAR_SIZE
,
&
output
);
if
(
!
ret
)
{
return
-
1
;
}
if
(
pDestSize
!=
NULL
)
{
*
pDestSize
=
output
;
}
}
return
0
;
}
static
FORCE_INLINE
int32_t
convertToDouble
(
char
*
pStr
,
int32_t
len
,
double
*
value
)
{
// SToken stoken = {.z = pStr, .n = len};
// if (TK_ILLEGAL == tGetNumericStringType(&stoken)) {
// return -1;
// }
//
// *value = taosStr2Double(pStr, NULL);
return
0
;
}
static
FORCE_INLINE
int32_t
convertToInteger
(
SVariant
*
pVariant
,
int64_t
*
result
,
int32_t
type
,
bool
issigned
,
bool
releaseVariantPtr
,
bool
*
converted
)
{
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NULL
)
{
setNull
((
char
*
)
result
,
type
,
tDataTypes
[
type
].
bytes
);
return
0
;
}
if
(
IS_SIGNED_NUMERIC_TYPE
(
pVariant
->
nType
)
||
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BOOL
))
{
*
result
=
pVariant
->
i
;
}
else
if
(
IS_UNSIGNED_NUMERIC_TYPE
(
pVariant
->
nType
))
{
*
result
=
pVariant
->
u
;
}
else
if
(
IS_FLOAT_TYPE
(
pVariant
->
nType
))
{
*
result
=
(
int64_t
)
pVariant
->
d
;
}
else
{
// TODO: handling var types
}
#if 0
errno = 0;
if (IS_SIGNED_NUMERIC_TYPE(pVariant->nType) || (pVariant->nType == TSDB_DATA_TYPE_BOOL)) {
*result = pVariant->i;
} else if (IS_UNSIGNED_NUMERIC_TYPE(pVariant->nType)) {
*result = pVariant->u;
} else if (IS_FLOAT_TYPE(pVariant->nType)) {
*result = (int64_t) pVariant->d;
} else if (pVariant->nType == TSDB_DATA_TYPE_BINARY) {
SToken token = {.z = pVariant->pz, .n = pVariant->nLen};
/*int32_t n = */tGetToken(pVariant->pz, &token.type);
if (token.type == TK_NULL) {
if (releaseVariantPtr) {
taosMemoryFree(pVariant->pz);
pVariant->nLen = 0;
}
setNull((char *)result, type, tDataTypes[type].bytes);
return 0;
}
// decide if it is a valid number
token.type = tGetNumericStringType(&token);
if (token.type == TK_ILLEGAL) {
return -1;
}
int64_t res = 0;
int32_t t = tStrToInteger(token.z, token.type, token.n, &res, issigned);
if (t != 0) {
return -1;
}
if (releaseVariantPtr) {
taosMemoryFree(pVariant->pz);
pVariant->nLen = 0;
}
*result = res;
} else if (pVariant->nType == TSDB_DATA_TYPE_NCHAR) {
errno = 0;
TdUcs4 *endPtr = NULL;
SToken token = {0};
token.n = tGetToken(pVariant->pz, &token.type);
if (token.type == TK_MINUS || token.type == TK_PLUS) {
token.n = tGetToken(pVariant->pz + token.n, &token.type);
}
if (token.type == TK_FLOAT) {
double v = wcstod(pVariant->ucs4, &endPtr);
if (releaseVariantPtr) {
taosMemoryFree(pVariant->pz);
pVariant->nLen = 0;
}
if ((errno == ERANGE && v == -1) || (isinf(v) || isnan(v))) {
return -1;
}
*result = (int64_t)v;
} else if (token.type == TK_NULL) {
if (releaseVariantPtr) {
taosMemoryFree(pVariant->pz);
pVariant->nLen = 0;
}
setNull((char *)result, type, tDataTypes[type].bytes);
return 0;
} else {
int64_t val = wcstoll(pVariant->ucs4, &endPtr, 10);
if (releaseVariantPtr) {
taosMemoryFree(pVariant->pz);
pVariant->nLen = 0;
}
if (errno == ERANGE) {
return -1; // data overflow
}
*result = val;
}
}
if (converted) {
*converted = true;
}
bool code = false;
uint64_t ui = 0;
switch(type) {
case TSDB_DATA_TYPE_TINYINT:
code = IS_VALID_TINYINT(*result); break;
case TSDB_DATA_TYPE_SMALLINT:
code = IS_VALID_SMALLINT(*result); break;
case TSDB_DATA_TYPE_INT:
code = IS_VALID_INT(*result); break;
case TSDB_DATA_TYPE_BIGINT:
code = IS_VALID_BIGINT(*result); break;
case TSDB_DATA_TYPE_UTINYINT:
ui = *result;
code = IS_VALID_UTINYINT(ui); break;
case TSDB_DATA_TYPE_USMALLINT:
ui = *result;
code = IS_VALID_USMALLINT(ui); break;
case TSDB_DATA_TYPE_UINT:
ui = *result;
code = IS_VALID_UINT(ui); break;
case TSDB_DATA_TYPE_UBIGINT:
ui = *result;
code = IS_VALID_UBIGINT(ui); break;
}
return code? 0:-1;
#endif
return
0
;
}
static
int32_t
convertToBool
(
SVariant
*
pVariant
,
int64_t
*
pDest
)
{
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BOOL
)
{
*
pDest
=
pVariant
->
i
;
// in order to be compatible to null of bool
}
else
if
(
IS_NUMERIC_TYPE
(
pVariant
->
nType
))
{
*
pDest
=
((
pVariant
->
i
!=
0
)
?
TSDB_TRUE
:
TSDB_FALSE
);
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_FLOAT
||
pVariant
->
nType
==
TSDB_DATA_TYPE_DOUBLE
)
{
*
pDest
=
((
pVariant
->
d
!=
0
)
?
TSDB_TRUE
:
TSDB_FALSE
);
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BINARY
)
{
int32_t
ret
=
0
;
if
((
ret
=
convertToBoolImpl
(
pVariant
->
pz
,
pVariant
->
nLen
))
<
0
)
{
return
ret
;
}
*
pDest
=
ret
;
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NCHAR
)
{
int32_t
ret
=
0
;
if
((
ret
=
wcsconvertToBoolImpl
(
pVariant
->
ucs4
,
pVariant
->
nLen
))
<
0
)
{
return
ret
;
}
*
pDest
=
ret
;
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NULL
)
{
*
pDest
=
TSDB_DATA_BOOL_NULL
;
}
assert
(
*
pDest
==
TSDB_TRUE
||
*
pDest
==
TSDB_FALSE
||
*
pDest
==
TSDB_DATA_BOOL_NULL
);
return
0
;
}
/*
* transfer data from variant serve as the implicit data conversion: from input sql string pVariant->nType
* to column type defined in schema
*/
int32_t
tVariantDumpEx
(
SVariant
*
pVariant
,
char
*
payload
,
int16_t
type
,
bool
includeLengthPrefix
,
bool
*
converted
,
char
*
extInfo
)
{
if
(
converted
)
{
*
converted
=
false
;
}
if
(
pVariant
==
NULL
||
(
pVariant
->
nType
!=
0
&&
!
isValidDataType
(
pVariant
->
nType
)))
{
return
-
1
;
}
errno
=
0
;
// reset global error code
int64_t
result
=
0
;
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
{
if
(
convertToBool
(
pVariant
,
&
result
)
<
0
)
{
return
-
1
;
}
*
(
int8_t
*
)
payload
=
(
int8_t
)
result
;
break
;
}
case
TSDB_DATA_TYPE_TINYINT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
true
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
result
,
INT8_MIN
+
1
,
INT8_MAX
,
extInfo
);
return
-
1
;
}
*
((
int8_t
*
)
payload
)
=
(
int8_t
)
result
;
break
;
}
case
TSDB_DATA_TYPE_UTINYINT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
false
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
result
,
0
,
UINT8_MAX
-
1
,
extInfo
);
return
-
1
;
}
*
((
uint8_t
*
)
payload
)
=
(
uint8_t
)
result
;
break
;
}
case
TSDB_DATA_TYPE_SMALLINT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
true
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
result
,
INT16_MIN
+
1
,
INT16_MAX
,
extInfo
);
return
-
1
;
}
*
((
int16_t
*
)
payload
)
=
(
int16_t
)
result
;
break
;
}
case
TSDB_DATA_TYPE_USMALLINT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
false
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
result
,
0
,
UINT16_MAX
-
1
,
extInfo
);
return
-
1
;
}
*
((
uint16_t
*
)
payload
)
=
(
uint16_t
)
result
;
break
;
}
case
TSDB_DATA_TYPE_INT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
true
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
result
,
INT32_MIN
+
1
,
INT32_MAX
,
extInfo
);
return
-
1
;
}
*
((
int32_t
*
)
payload
)
=
(
int32_t
)
result
;
break
;
}
case
TSDB_DATA_TYPE_UINT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
false
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
result
,
0
,
UINT32_MAX
-
1
,
extInfo
);
return
-
1
;
}
*
((
uint32_t
*
)
payload
)
=
(
uint32_t
)
result
;
break
;
}
case
TSDB_DATA_TYPE_BIGINT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
true
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
result
,
INT64_MIN
+
1
,
INT64_MAX
,
extInfo
);
return
-
1
;
}
*
((
int64_t
*
)
payload
)
=
(
int64_t
)
result
;
break
;
}
case
TSDB_DATA_TYPE_UBIGINT
:
{
if
(
convertToInteger
(
pVariant
,
&
result
,
type
,
false
,
false
,
converted
)
<
0
)
{
SET_EXT_INFO
(
converted
,
result
,
0
,
UINT64_MAX
-
1
,
extInfo
);
return
-
1
;
}
*
((
uint64_t
*
)
payload
)
=
(
uint64_t
)
result
;
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
{
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
strncasecmp
(
TSDB_DATA_NULL_STR_L
,
pVariant
->
pz
,
pVariant
->
nLen
)
==
0
&&
strlen
(
TSDB_DATA_NULL_STR_L
)
==
pVariant
->
nLen
)
{
*
((
int32_t
*
)
payload
)
=
TSDB_DATA_FLOAT_NULL
;
return
0
;
}
else
{
double
value
=
-
1
;
int32_t
ret
=
convertToDouble
(
pVariant
->
pz
,
pVariant
->
nLen
,
&
value
);
if
((
errno
==
ERANGE
&&
(
float
)
value
==
-
1
)
||
(
ret
!=
0
))
{
return
-
1
;
}
if
(
converted
)
{
*
converted
=
true
;
}
if
(
value
>
FLT_MAX
||
value
<
-
FLT_MAX
)
{
SET_EXT_INFO
(
converted
,
value
,
-
FLT_MAX
,
FLT_MAX
,
extInfo
);
return
-
1
;
}
SET_FLOAT_VAL
(
payload
,
value
);
}
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BOOL
||
IS_SIGNED_NUMERIC_TYPE
(
pVariant
->
nType
)
||
IS_UNSIGNED_NUMERIC_TYPE
(
pVariant
->
nType
))
{
if
(
converted
)
{
*
converted
=
true
;
}
if
(
pVariant
->
i
>
FLT_MAX
||
pVariant
->
i
<
-
FLT_MAX
)
{
SET_EXT_INFO
(
converted
,
pVariant
->
i
,
-
FLT_MAX
,
FLT_MAX
,
extInfo
);
return
-
1
;
}
SET_FLOAT_VAL
(
payload
,
pVariant
->
i
);
}
else
if
(
IS_FLOAT_TYPE
(
pVariant
->
nType
))
{
if
(
converted
)
{
*
converted
=
true
;
}
if
(
pVariant
->
d
>
FLT_MAX
||
pVariant
->
d
<
-
FLT_MAX
)
{
SET_EXT_INFO
(
converted
,
pVariant
->
d
,
-
FLT_MAX
,
FLT_MAX
,
extInfo
);
return
-
1
;
}
SET_FLOAT_VAL
(
payload
,
pVariant
->
d
);
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NULL
)
{
*
((
uint32_t
*
)
payload
)
=
TSDB_DATA_FLOAT_NULL
;
return
0
;
}
float
fv
=
GET_FLOAT_VAL
(
payload
);
if
(
isinf
(
fv
)
||
isnan
(
fv
)
||
fv
>
FLT_MAX
||
fv
<
-
FLT_MAX
)
{
return
-
1
;
}
break
;
}
case
TSDB_DATA_TYPE_DOUBLE
:
{
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BINARY
)
{
if
(
strncasecmp
(
TSDB_DATA_NULL_STR_L
,
pVariant
->
pz
,
pVariant
->
nLen
)
==
0
&&
strlen
(
TSDB_DATA_NULL_STR_L
)
==
pVariant
->
nLen
)
{
*
((
int64_t
*
)
payload
)
=
TSDB_DATA_DOUBLE_NULL
;
return
0
;
}
else
{
double
value
=
0
;
int32_t
ret
;
ret
=
convertToDouble
(
pVariant
->
pz
,
pVariant
->
nLen
,
&
value
);
if
((
errno
==
ERANGE
&&
value
==
-
1
)
||
(
ret
!=
0
))
{
return
-
1
;
}
SET_DOUBLE_VAL
(
payload
,
value
);
}
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BOOL
||
IS_SIGNED_NUMERIC_TYPE
(
pVariant
->
nType
)
||
IS_UNSIGNED_NUMERIC_TYPE
(
pVariant
->
nType
))
{
SET_DOUBLE_VAL
(
payload
,
pVariant
->
i
);
}
else
if
(
IS_FLOAT_TYPE
(
pVariant
->
nType
))
{
SET_DOUBLE_VAL
(
payload
,
pVariant
->
d
);
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NULL
)
{
*
((
int64_t
*
)
payload
)
=
TSDB_DATA_DOUBLE_NULL
;
return
0
;
}
double
dv
=
GET_DOUBLE_VAL
(
payload
);
if
(
errno
==
ERANGE
||
isinf
(
dv
)
||
isnan
(
dv
))
{
return
-
1
;
}
break
;
}
case
TSDB_DATA_TYPE_BINARY
:
{
if
(
!
includeLengthPrefix
)
{
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NULL
)
{
*
(
uint8_t
*
)
payload
=
TSDB_DATA_BINARY_NULL
;
}
else
{
if
(
pVariant
->
nType
!=
TSDB_DATA_TYPE_BINARY
)
{
toBinary
(
pVariant
,
&
payload
,
&
pVariant
->
nLen
);
}
else
{
strncpy
(
payload
,
pVariant
->
pz
,
pVariant
->
nLen
);
}
}
}
else
{
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NULL
)
{
setVardataNull
(
payload
,
TSDB_DATA_TYPE_BINARY
);
}
else
{
char
*
p
=
varDataVal
(
payload
);
if
(
pVariant
->
nType
!=
TSDB_DATA_TYPE_BINARY
)
{
toBinary
(
pVariant
,
&
p
,
&
pVariant
->
nLen
);
}
else
{
strncpy
(
p
,
pVariant
->
pz
,
pVariant
->
nLen
);
}
varDataSetLen
(
payload
,
pVariant
->
nLen
);
assert
(
p
==
varDataVal
(
payload
));
}
}
break
;
}
case
TSDB_DATA_TYPE_TIMESTAMP
:
{
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NULL
)
{
*
((
int64_t
*
)
payload
)
=
TSDB_DATA_BIGINT_NULL
;
}
else
{
*
((
int64_t
*
)
payload
)
=
pVariant
->
i
;
}
break
;
}
case
TSDB_DATA_TYPE_NCHAR
:
{
int32_t
newlen
=
0
;
if
(
!
includeLengthPrefix
)
{
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NULL
)
{
*
(
uint32_t
*
)
payload
=
TSDB_DATA_NCHAR_NULL
;
}
else
{
if
(
pVariant
->
nType
!=
TSDB_DATA_TYPE_NCHAR
)
{
if
(
toNchar
(
pVariant
,
&
payload
,
&
newlen
)
!=
0
)
{
return
-
1
;
}
}
else
{
tasoUcs4Copy
((
TdUcs4
*
)
payload
,
pVariant
->
ucs4
,
pVariant
->
nLen
);
}
}
}
else
{
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NULL
)
{
setVardataNull
(
payload
,
TSDB_DATA_TYPE_NCHAR
);
}
else
{
char
*
p
=
varDataVal
(
payload
);
if
(
pVariant
->
nType
!=
TSDB_DATA_TYPE_NCHAR
)
{
if
(
toNchar
(
pVariant
,
&
p
,
&
newlen
)
!=
0
)
{
return
-
1
;
}
}
else
{
memcpy
(
p
,
pVariant
->
ucs4
,
pVariant
->
nLen
);
newlen
=
pVariant
->
nLen
;
}
varDataSetLen
(
payload
,
newlen
);
// the length may be changed after toNchar function called
assert
(
p
==
varDataVal
(
payload
));
}
}
break
;
}
}
return
0
;
}
/*
* transfer data from variant serve as the implicit data conversion: from input sql string pVariant->nType
* to column type defined in schema
*/
int32_t
taosVariantDump
(
SVariant
*
pVariant
,
char
*
payload
,
int16_t
type
,
bool
includeLengthPrefix
)
{
return
tVariantDumpEx
(
pVariant
,
payload
,
type
,
includeLengthPrefix
,
NULL
,
NULL
);
}
/*
* In variant, bool/smallint/tinyint/int/bigint share the same attribution of
* structure, also ignore the convert the type required
*
* It is actually the bigint/binary/bool/nchar type transfer
*/
int32_t
taosVariantTypeSetType
(
SVariant
*
pVariant
,
char
type
)
{
if
(
pVariant
==
NULL
||
pVariant
->
nType
==
0
)
{
// value is not set
return
0
;
}
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
{
// bool
if
(
convertToBool
(
pVariant
,
&
pVariant
->
i
)
<
0
)
{
return
-
1
;
}
pVariant
->
nType
=
type
;
break
;
}
case
TSDB_DATA_TYPE_INT
:
case
TSDB_DATA_TYPE_BIGINT
:
case
TSDB_DATA_TYPE_TINYINT
:
case
TSDB_DATA_TYPE_SMALLINT
:
{
convertToInteger
(
pVariant
,
&
(
pVariant
->
i
),
type
,
true
,
true
,
NULL
);
pVariant
->
nType
=
TSDB_DATA_TYPE_BIGINT
;
break
;
}
case
TSDB_DATA_TYPE_FLOAT
:
case
TSDB_DATA_TYPE_DOUBLE
:
{
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_BINARY
)
{
errno
=
0
;
double
v
=
taosStr2Double
(
pVariant
->
pz
,
NULL
);
if
((
errno
==
ERANGE
&&
v
==
-
1
)
||
(
isinf
(
v
)
||
isnan
(
v
)))
{
taosMemoryFree
(
pVariant
->
pz
);
return
-
1
;
}
taosMemoryFree
(
pVariant
->
pz
);
pVariant
->
d
=
v
;
}
else
if
(
pVariant
->
nType
==
TSDB_DATA_TYPE_NCHAR
)
{
errno
=
0
;
double
v
=
wcstod
(
pVariant
->
ucs4
,
NULL
);
if
((
errno
==
ERANGE
&&
v
==
-
1
)
||
(
isinf
(
v
)
||
isnan
(
v
)))
{
taosMemoryFree
(
pVariant
->
pz
);
return
-
1
;
}
taosMemoryFree
(
pVariant
->
pz
);
pVariant
->
d
=
v
;
}
else
if
(
pVariant
->
nType
>=
TSDB_DATA_TYPE_BOOL
&&
pVariant
->
nType
<=
TSDB_DATA_TYPE_BIGINT
)
{
double
tmp
=
(
double
)
pVariant
->
i
;
pVariant
->
d
=
tmp
;
}
pVariant
->
nType
=
TSDB_DATA_TYPE_DOUBLE
;
break
;
}
case
TSDB_DATA_TYPE_BINARY
:
{
if
(
pVariant
->
nType
!=
TSDB_DATA_TYPE_BINARY
)
{
toBinary
(
pVariant
,
&
pVariant
->
pz
,
&
pVariant
->
nLen
);
}
pVariant
->
nType
=
type
;
break
;
}
case
TSDB_DATA_TYPE_NCHAR
:
{
if
(
pVariant
->
nType
!=
TSDB_DATA_TYPE_NCHAR
)
{
if
(
toNchar
(
pVariant
,
&
pVariant
->
pz
,
&
pVariant
->
nLen
)
!=
0
)
{
return
-
1
;
}
}
pVariant
->
nType
=
type
;
break
;
}
}
return
0
;
}
char
*
taosVariantGet
(
SVariant
*
pVar
,
int32_t
type
)
{
switch
(
type
)
{
case
TSDB_DATA_TYPE_BOOL
:
...
...
source/dnode/vnode/src/meta/metaQuery.c
浏览文件 @
097a047b
...
...
@@ -687,7 +687,12 @@ int32_t metaGetTbTSchemaEx(SMeta *pMeta, tb_uid_t suid, tb_uid_t uid, int32_t sv
SSchema
*
pSchema
=
pSchemaWrapper
->
pSchema
+
i
;
tdAddColToSchema
(
&
sb
,
pSchema
->
type
,
pSchema
->
flags
,
pSchema
->
colId
,
pSchema
->
bytes
);
}
STSchema
*
pTSchema
=
tdGetSchemaFromBuilder
(
&
sb
);
if
(
pTSchema
==
NULL
)
{
code
=
TSDB_CODE_OUT_OF_MEMORY
;
}
tdDestroyTSchemaBuilder
(
&
sb
);
*
ppTSchema
=
pTSchema
;
...
...
source/dnode/vnode/src/tsdb/tsdbCacheRead.c
浏览文件 @
097a047b
...
...
@@ -84,6 +84,7 @@ int32_t tsdbCacherowsReaderOpen(void* pVnode, int32_t type, SArray* pTableIdList
p
->
transferBuf
=
taosMemoryCalloc
(
p
->
pSchema
->
numOfCols
,
POINTER_BYTES
);
if
(
p
->
transferBuf
==
NULL
)
{
tsdbCacherowsReaderClose
(
p
);
return
TSDB_CODE_OUT_OF_MEMORY
;
}
...
...
source/dnode/vnode/src/tsdb/tsdbRead.c
浏览文件 @
097a047b
...
...
@@ -2554,6 +2554,12 @@ static int32_t doBuildDataBlock(STsdbReader* pReader) {
pScanInfo
=
pReader
->
status
.
pTableIter
;
}
if
(
pScanInfo
==
NULL
)
{
tsdbError
(
"failed to get table, uid:"
PRIu64
", %s"
,
pBlockInfo
->
uid
,
pReader
->
idStr
);
code
=
TSDB_CODE_INVALID_PARA
;
return
code
;
}
if
(
pBlockInfo
!=
NULL
)
{
pBlock
=
getCurrentBlock
(
pBlockIter
);
}
...
...
source/libs/executor/src/executor.c
浏览文件 @
097a047b
...
...
@@ -250,6 +250,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo
qDebug
(
" %d qualified child tables added into stream scanner"
,
(
int32_t
)
taosArrayGetSize
(
qa
));
code
=
tqReaderAddTbUidList
(
pScanInfo
->
tqReader
,
qa
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
taosArrayDestroy
(
qa
);
return
code
;
}
...
...
@@ -261,6 +262,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo
assignUid
=
groupbyTbname
(
pScanInfo
->
pGroupTags
);
keyBuf
=
taosMemoryMalloc
(
bufLen
);
if
(
keyBuf
==
NULL
)
{
taosArrayDestroy
(
qa
);
return
TSDB_CODE_OUT_OF_MEMORY
;
}
}
...
...
@@ -277,6 +279,7 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo
&
keyInfo
.
groupId
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
taosMemoryFree
(
keyBuf
);
taosArrayDestroy
(
qa
);
return
code
;
}
}
...
...
@@ -298,8 +301,6 @@ int32_t qUpdateQualifiedTableId(qTaskInfo_t tinfo, const SArray* tableIdList, bo
taosHashPut
(
pTaskInfo
->
tableqinfoList
.
map
,
uid
,
sizeof
(
*
uid
),
&
keyInfo
.
groupId
,
sizeof
(
keyInfo
.
groupId
));
}
/*}*/
if
(
keyBuf
!=
NULL
)
{
taosMemoryFree
(
keyBuf
);
}
...
...
source/libs/executor/src/executorimpl.c
浏览文件 @
097a047b
...
...
@@ -462,6 +462,7 @@ static int32_t doCreateConstantValColumnInfo(SInputColumnInfoData* pInput, SFunc
for
(
int32_t
i
=
0
;
i
<
numOfRows
;
++
i
)
{
colDataAppend
(
pColInfo
,
i
,
tmp
,
false
);
}
taosMemoryFree
(
tmp
);
}
return
TSDB_CODE_SUCCESS
;
...
...
source/libs/executor/src/groupoperator.c
浏览文件 @
097a047b
...
...
@@ -757,7 +757,6 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
goto
_error
;
}
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pPartNode
->
node
.
pOutputDataBlockDesc
);
int32_t
numOfCols
=
0
;
SExprInfo
*
pExprInfo
=
createExprInfo
(
pPartNode
->
pTargets
,
NULL
,
&
numOfCols
);
...
...
@@ -781,14 +780,18 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
uint32_t
defaultPgsz
=
0
;
uint32_t
defaultBufsz
=
0
;
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pPartNode
->
node
.
pOutputDataBlockDesc
);
getBufferPgSize
(
pResBlock
->
info
.
rowSize
,
&
defaultPgsz
,
&
defaultBufsz
);
if
(
!
osTempSpaceAvailable
())
{
terrno
=
TSDB_CODE_NO_AVAIL_DISK
;
pTaskInfo
->
code
=
terrno
;
qError
(
"Create partition operator info failed since %s"
,
terrstr
(
terrno
));
blockDataDestroy
(
pResBlock
);
goto
_error
;
}
int32_t
code
=
createDiskbasedBuf
(
&
pInfo
->
pBuf
,
defaultPgsz
,
defaultBufsz
,
pTaskInfo
->
id
.
str
,
tsTempDir
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
...
...
@@ -819,7 +822,9 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SPartition
_error:
pTaskInfo
->
code
=
TSDB_CODE_OUT_OF_MEMORY
;
taosMemoryFreeClear
(
pInfo
);
if
(
pInfo
!=
NULL
)
{
destroyPartitionOperatorInfo
(
pInfo
);
}
taosMemoryFreeClear
(
pOperator
);
return
NULL
;
}
...
...
source/libs/executor/src/scanoperator.c
浏览文件 @
097a047b
...
...
@@ -737,7 +737,7 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
SDataBlockDescNode
*
pDescNode
=
pTableScanNode
->
scan
.
node
.
pOutputDataBlockDesc
;
int32_t
numOfCols
=
0
;
SArray
*
pColList
=
extractColMatchInfo
(
pTableScanNode
->
scan
.
pScanCols
,
pDescNode
,
&
numOfCols
,
COL_MATCH_FROM_COL_ID
);
pInfo
->
pColMatchInfo
=
extractColMatchInfo
(
pTableScanNode
->
scan
.
pScanCols
,
pDescNode
,
&
numOfCols
,
COL_MATCH_FROM_COL_ID
);
int32_t
code
=
initQueryTableDataCond
(
&
pInfo
->
cond
,
pTableScanNode
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
...
...
@@ -765,7 +765,6 @@ SOperatorInfo* createTableScanOperatorInfo(STableScanPhysiNode* pTableScanNode,
}
pInfo
->
scanFlag
=
MAIN_SCAN
;
pInfo
->
pColMatchInfo
=
pColList
;
pInfo
->
currentGroupId
=
-
1
;
pInfo
->
assignBlockUid
=
pTableScanNode
->
assignBlockUid
;
...
...
@@ -1768,8 +1767,9 @@ FETCH_NEXT_BLOCK:
generateDeleteResultBlock
(
pInfo
,
pDelBlock
,
pInfo
->
pDeleteDataRes
);
pInfo
->
pDeleteDataRes
->
info
.
type
=
STREAM_DELETE_RESULT
;
printDataBlock
(
pDelBlock
,
"stream scan delete result"
);
blockDataDestroy
(
pDelBlock
);
if
(
pInfo
->
pDeleteDataRes
->
info
.
rows
>
0
)
{
blockDataDestroy
(
pDelBlock
);
return
pInfo
->
pDeleteDataRes
;
}
else
{
goto
FETCH_NEXT_BLOCK
;
...
...
@@ -2090,24 +2090,30 @@ SOperatorInfo* createRawScanOperatorInfo(SReadHandle* pHandle, SExecTaskInfo* pT
// create meta reader
// create tq reader
int32_t
code
=
TSDB_CODE_SUCCESS
;
SStreamRawScanInfo
*
pInfo
=
taosMemoryCalloc
(
1
,
sizeof
(
SStreamRawScanInfo
));
SOperatorInfo
*
pOperator
=
taosMemoryCalloc
(
1
,
sizeof
(
SOperatorInfo
));
if
(
pInfo
==
NULL
||
pOperator
==
NULL
)
{
terrno
=
TSDB_CODE_QRY
_OUT_OF_MEMORY
;
return
NULL
;
code
=
TSDB_CODE
_OUT_OF_MEMORY
;
goto
_end
;
}
pInfo
->
vnode
=
pHandle
->
vnode
;
pInfo
->
sContext
=
pHandle
->
sContext
;
pOperator
->
name
=
"RawStreamScanOperator"
;
// pOperator->blocking = false;
// pOperator->status = OP_NOT_OPENED;
pOperator
->
info
=
pInfo
;
pOperator
->
pTaskInfo
=
pTaskInfo
;
pOperator
->
fpSet
=
createOperatorFpSet
(
NULL
,
doRawScan
,
NULL
,
NULL
,
destroyRawScanOperatorInfo
,
NULL
,
NULL
,
NULL
);
return
pOperator
;
_end:
taosMemoryFree
(
pInfo
);
taosMemoryFree
(
pOperator
);
pTaskInfo
->
code
=
code
;
return
NULL
;
}
static
void
destroyStreamScanOperatorInfo
(
void
*
param
)
{
...
...
@@ -2285,7 +2291,14 @@ SOperatorInfo* createStreamScanOperatorInfo(SReadHandle* pHandle, STableScanPhys
return
pOperator
;
_error:
taosMemoryFreeClear
(
pInfo
);
if
(
pColIds
!=
NULL
)
{
taosArrayDestroy
(
pColIds
);
}
if
(
pInfo
!=
NULL
)
{
destroyStreamScanOperatorInfo
(
pInfo
);
}
taosMemoryFreeClear
(
pOperator
);
return
NULL
;
}
...
...
@@ -3333,7 +3346,7 @@ int32_t createScanTableListInfo(SScanPhysiNode* pScanNode, SNodeList* pGroupTags
int64_t
st
=
taosGetTimestampUs
();
if
(
pHandle
==
NULL
)
{
qError
(
"invalid handle, in creating operator tree
:
%s"
,
idStr
);
qError
(
"invalid handle, in creating operator tree
,
%s"
,
idStr
);
return
TSDB_CODE_INVALID_PARA
;
}
...
...
source/libs/executor/src/tfill.c
浏览文件 @
097a047b
...
...
@@ -467,9 +467,11 @@ struct SFillInfo* taosCreateFillInfo(TSKEY skey, int32_t numOfFillCols, int32_t
case
FILL_MODE_VALUE
:
pFillInfo
->
type
=
TSDB_FILL_SET_VALUE
;
break
;
default:
default:
{
taosMemoryFree
(
pFillInfo
);
terrno
=
TSDB_CODE_INVALID_PARA
;
return
NULL
;
}
}
pFillInfo
->
type
=
fillType
;
...
...
source/libs/executor/src/timewindowoperator.c
浏览文件 @
097a047b
...
...
@@ -2669,14 +2669,13 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWi
int32_t
num
=
0
;
SExprInfo
*
pExprInfo
=
createExprInfo
(
pStateNode
->
window
.
pFuncs
,
NULL
,
&
num
);
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pStateNode
->
window
.
node
.
pOutputDataBlockDesc
);
initResultSizeInfo
(
&
pOperator
->
resultInfo
,
4096
);
int32_t
code
=
initAggInfo
(
&
pOperator
->
exprSupp
,
&
pInfo
->
aggSup
,
pExprInfo
,
num
,
keyBufSize
,
pTaskInfo
->
id
.
str
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pStateNode
->
window
.
node
.
pOutputDataBlockDesc
);
initBasicInfo
(
&
pInfo
->
binfo
,
pResBlock
);
initResultRowInfo
(
&
pInfo
->
binfo
.
resultRowInfo
);
...
...
@@ -2704,7 +2703,10 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SStateWi
return
pOperator
;
_error:
destroyStateWindowOperatorInfo
(
pInfo
);
if
(
pInfo
!=
NULL
)
{
destroyStateWindowOperatorInfo
(
pInfo
);
}
taosMemoryFreeClear
(
pOperator
);
pTaskInfo
->
code
=
code
;
return
NULL
;
...
...
@@ -4973,9 +4975,7 @@ SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream,
goto
_error
;
}
int32_t
num
=
0
;
SExprInfo
*
pExprInfo
=
createExprInfo
(
pNode
->
window
.
pFuncs
,
NULL
,
&
num
);
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pNode
->
window
.
node
.
pOutputDataBlockDesc
);
SInterval
interval
=
{.
interval
=
pNode
->
interval
,
.
sliding
=
pNode
->
sliding
,
...
...
@@ -4999,11 +4999,14 @@ SOperatorInfo* createMergeAlignedIntervalOperatorInfo(SOperatorInfo* downstream,
size_t
keyBufSize
=
sizeof
(
int64_t
)
+
sizeof
(
int64_t
)
+
POINTER_BYTES
;
initResultSizeInfo
(
&
pOperator
->
resultInfo
,
4096
);
int32_t
code
=
initAggInfo
(
&
pOperator
->
exprSupp
,
&
iaInfo
->
aggSup
,
pExprInfo
,
num
,
keyBufSize
,
pTaskInfo
->
id
.
str
);
int32_t
num
=
0
;
SExprInfo
*
pExprInfo
=
createExprInfo
(
pNode
->
window
.
pFuncs
,
NULL
,
&
num
);
int32_t
code
=
initAggInfo
(
&
pOperator
->
exprSupp
,
&
iaInfo
->
aggSup
,
pExprInfo
,
num
,
keyBufSize
,
pTaskInfo
->
id
.
str
);
if
(
code
!=
TSDB_CODE_SUCCESS
)
{
goto
_error
;
}
SSDataBlock
*
pResBlock
=
createResDataBlock
(
pNode
->
window
.
node
.
pOutputDataBlockDesc
);
initBasicInfo
(
&
iaInfo
->
binfo
,
pResBlock
);
initExecTimeWindowInfo
(
&
iaInfo
->
twAggSup
.
timeWindowData
,
&
iaInfo
->
win
);
...
...
source/libs/executor/src/tsort.c
浏览文件 @
097a047b
...
...
@@ -181,6 +181,7 @@ static int32_t doAddToBuf(SSDataBlock* pDataBlock, SSortHandle* pHandle) {
blockDataSplitRows
(
pDataBlock
,
pDataBlock
->
info
.
hasVarCol
,
start
,
&
stop
,
pHandle
->
pageSize
);
SSDataBlock
*
p
=
blockDataExtractBlock
(
pDataBlock
,
start
,
stop
-
start
+
1
);
if
(
p
==
NULL
)
{
taosArrayDestroy
(
pPageIdList
);
return
terrno
;
}
...
...
@@ -422,7 +423,7 @@ int32_t msortComparFn(const void* pLeft, const void* pRight, void* param) {
SColumnInfoData
*
pRightColInfoData
=
TARRAY_GET_ELEM
(
pRightBlock
->
pDataBlock
,
pOrder
->
slotId
);
bool
rightNull
=
false
;
if
(
pRightColInfoData
->
hasNull
)
{
if
(
p
Lef
tBlock
->
pBlockAgg
==
NULL
)
{
if
(
p
Righ
tBlock
->
pBlockAgg
==
NULL
)
{
rightNull
=
colDataIsNull_s
(
pRightColInfoData
,
pRightSource
->
src
.
rowIndex
);
}
else
{
rightNull
=
colDataIsNull
(
pRightColInfoData
,
pRightBlock
->
info
.
rows
,
pRightSource
->
src
.
rowIndex
,
...
...
source/libs/function/src/builtinsimpl.c
浏览文件 @
097a047b
...
...
@@ -6187,99 +6187,6 @@ int32_t groupKeyFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
return
pResInfo
->
numOfRes
;
}
int32_t
interpFunction
(
SqlFunctionCtx
*
pCtx
)
{
#if 0
int32_t fillType = (int32_t) pCtx->param[2].i64;
//bool ascQuery = (pCtx->order == TSDB_ORDER_ASC);
if (pCtx->start.key == pCtx->startTs) {
assert(pCtx->start.key != INT64_MIN);
COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->start.val);
goto interp_success_exit;
} else if (pCtx->end.key == pCtx->startTs && pCtx->end.key != INT64_MIN && fillType == TSDB_FILL_NEXT) {
COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->end.val);
goto interp_success_exit;
}
switch (fillType) {
case TSDB_FILL_NULL:
setNull(pCtx->pOutput, pCtx->outputType, pCtx->outputBytes);
break;
case TSDB_FILL_SET_VALUE:
tVariantDump(&pCtx->param[1], pCtx->pOutput, pCtx->inputType, true);
break;
case TSDB_FILL_LINEAR:
if (pCtx->start.key == INT64_MIN || pCtx->start.key > pCtx->startTs
|| pCtx->end.key == INT64_MIN || pCtx->end.key < pCtx->startTs) {
goto interp_exit;
}
double v1 = -1, v2 = -1;
GET_TYPED_DATA(v1, double, pCtx->inputType, &pCtx->start.val);
GET_TYPED_DATA(v2, double, pCtx->inputType, &pCtx->end.val);
SPoint point1 = {.key = pCtx->start.key, .val = &v1};
SPoint point2 = {.key = pCtx->end.key, .val = &v2};
SPoint point = {.key = pCtx->startTs, .val = pCtx->pOutput};
int32_t srcType = pCtx->inputType;
if (isNull((char *)&pCtx->start.val, srcType) || isNull((char *)&pCtx->end.val, srcType)) {
setNull(pCtx->pOutput, srcType, pCtx->inputBytes);
} else {
bool exceedMax = false, exceedMin = false;
taosGetLinearInterpolationVal(&point, pCtx->outputType, &point1, &point2, TSDB_DATA_TYPE_DOUBLE, &exceedMax, &exceedMin);
if (exceedMax || exceedMin) {
__compar_fn_t func = getComparFunc((int32_t)pCtx->inputType, 0);
if (func(&pCtx->start.val, &pCtx->end.val) <= 0) {
COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, exceedMax ? &pCtx->start.val : &pCtx->end.val);
} else {
COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, exceedMax ? &pCtx->end.val : &pCtx->start.val);
}
}
}
break;
case TSDB_FILL_PREV:
if (pCtx->start.key == INT64_MIN || pCtx->start.key > pCtx->startTs) {
goto interp_exit;
}
COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->start.val);
break;
case TSDB_FILL_NEXT:
if (pCtx->end.key == INT64_MIN || pCtx->end.key < pCtx->startTs) {
goto interp_exit;
}
COPY_TYPED_DATA(pCtx->pOutput, pCtx->inputType, &pCtx->end.val);
break;
case TSDB_FILL_NONE:
// do nothing
default:
goto interp_exit;
}
interp_success_exit:
*(TSKEY*)pCtx->ptsOutputBuf = pCtx->startTs;
INC_INIT_VAL(pCtx, 1);
interp_exit:
pCtx->start.key = INT64_MIN;
pCtx->end.key = INT64_MIN;
pCtx->endTs = pCtx->startTs;
#endif
return
TSDB_CODE_SUCCESS
;
}
int32_t
cachedLastRowFunction
(
SqlFunctionCtx
*
pCtx
)
{
int32_t
numOfElems
=
0
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录