Merge remote-tracking branch 'origin/3.0' into feature/qnode
This commit is contained in:
commit
84e8939513
103
Jenkinsfile2
103
Jenkinsfile2
|
@ -33,7 +33,7 @@ def abort_previous(){
|
|||
milestone(buildNumber)
|
||||
}
|
||||
def pre_test(){
|
||||
sh'hostname'
|
||||
sh 'hostname'
|
||||
sh '''
|
||||
date
|
||||
sudo rmtaos || echo "taosd has not installed"
|
||||
|
@ -50,35 +50,32 @@ def pre_test(){
|
|||
cd ${WKC}
|
||||
git checkout master
|
||||
'''
|
||||
}
|
||||
else if(env.CHANGE_TARGET == '2.0'){
|
||||
} else if(env.CHANGE_TARGET == '2.0') {
|
||||
sh '''
|
||||
cd ${WKC}
|
||||
git checkout 2.0
|
||||
'''
|
||||
}
|
||||
else if(env.CHANGE_TARGET == '3.0'){
|
||||
} else if(env.CHANGE_TARGET == '3.0') {
|
||||
sh '''
|
||||
cd ${WKC}
|
||||
git checkout 3.0
|
||||
[ -d contrib/bdb ] && cd contrib/bdb && git clean -fxd && cd ../..
|
||||
'''
|
||||
}
|
||||
else{
|
||||
} else {
|
||||
sh '''
|
||||
cd ${WKC}
|
||||
git checkout develop
|
||||
'''
|
||||
}
|
||||
}
|
||||
sh'''
|
||||
sh '''
|
||||
cd ${WKC}
|
||||
git pull >/dev/null
|
||||
git fetch origin +refs/pull/${CHANGE_ID}/merge
|
||||
git checkout -qf FETCH_HEAD
|
||||
git submodule update --init --recursive
|
||||
'''
|
||||
sh'''
|
||||
sh '''
|
||||
cd ${WKC}
|
||||
export TZ=Asia/Harbin
|
||||
date
|
||||
|
@ -88,7 +85,7 @@ def pre_test(){
|
|||
cmake .. > /dev/null
|
||||
make -j4> /dev/null
|
||||
'''
|
||||
sh'''
|
||||
sh '''
|
||||
cd ${WKPY}
|
||||
git reset --hard
|
||||
git pull
|
||||
|
@ -96,6 +93,69 @@ def pre_test(){
|
|||
'''
|
||||
return 1
|
||||
}
|
||||
def pre_test_win(){
|
||||
bat '''
|
||||
hostname
|
||||
date /t
|
||||
time /t
|
||||
taskkill /f /t /im python.exe
|
||||
taskkill /f /t /im bash.exe
|
||||
cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
|
||||
rd /s /Q C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine\\debug
|
||||
exit 0
|
||||
'''
|
||||
bat '''
|
||||
cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
|
||||
git reset --hard
|
||||
git fetch || git fetch
|
||||
git checkout -f
|
||||
'''
|
||||
script {
|
||||
if (env.CHANGE_TARGET == 'master') {
|
||||
bat '''
|
||||
cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
|
||||
git checkout master
|
||||
'''
|
||||
} else if(env.CHANGE_TARGET == '2.0') {
|
||||
bat '''
|
||||
cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
|
||||
git checkout 2.0
|
||||
'''
|
||||
} else if(env.CHANGE_TARGET == '3.0') {
|
||||
bat '''
|
||||
cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
|
||||
git checkout 3.0
|
||||
'''
|
||||
} else {
|
||||
bat '''
|
||||
cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
|
||||
git checkout develop
|
||||
'''
|
||||
}
|
||||
}
|
||||
bat '''
|
||||
cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
|
||||
git branch
|
||||
git pull || git pull
|
||||
git fetch origin +refs/pull/%CHANGE_ID%/merge
|
||||
git checkout -qf FETCH_HEAD
|
||||
'''
|
||||
}
|
||||
def pre_test_build_win() {
|
||||
bat '''
|
||||
echo "building ..."
|
||||
time /t
|
||||
cd C:\\workspace\\%EXECUTOR_NUMBER%\\TDengine
|
||||
mkdir debug
|
||||
cd debug
|
||||
call "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Auxiliary\\Build\\vcvarsall.bat" x64
|
||||
set CL=/MP8
|
||||
cmake .. -G "NMake Makefiles JOM"
|
||||
jom -j 4 || exit 8
|
||||
time /t
|
||||
'''
|
||||
return 1
|
||||
}
|
||||
|
||||
pipeline {
|
||||
agent none
|
||||
|
@ -106,29 +166,34 @@ pipeline {
|
|||
WKPY= '/var/lib/jenkins/workspace/taos-connector-python'
|
||||
}
|
||||
stages {
|
||||
stage('pre_build'){
|
||||
stage('run test') {
|
||||
parallel {
|
||||
stage('windows test') {
|
||||
agent {label " windows11 "}
|
||||
steps {
|
||||
pre_test_win()
|
||||
pre_test_build_win()
|
||||
}
|
||||
}
|
||||
stage('linux test') {
|
||||
agent{label " slave3_0 || slave15 || slave16 || slave17 "}
|
||||
options { skipDefaultCheckout() }
|
||||
when {
|
||||
changeRequest()
|
||||
}
|
||||
steps {
|
||||
script{
|
||||
abort_previous()
|
||||
abortPreviousBuilds()
|
||||
}
|
||||
timeout(time: 45, unit: 'MINUTES'){
|
||||
pre_test()
|
||||
sh'''
|
||||
sh '''
|
||||
cd ${WKC}/debug
|
||||
ctest -VV
|
||||
'''
|
||||
sh'''
|
||||
sh '''
|
||||
export LD_LIBRARY_PATH=${WKC}/debug/build/lib
|
||||
cd ${WKC}/tests/system-test
|
||||
./fulltest.sh
|
||||
'''
|
||||
sh'''
|
||||
sh '''
|
||||
cd ${WKC}/tests
|
||||
./test-all.sh b1fq
|
||||
'''
|
||||
|
@ -136,6 +201,8 @@ pipeline {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
post {
|
||||
success {
|
||||
emailext (
|
||||
|
|
|
@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.16)
|
|||
|
||||
set(CMAKE_VERBOSE_MAKEFILE OFF)
|
||||
|
||||
SET(BUILD_SHARED_LIBS "OFF")
|
||||
|
||||
#set output directory
|
||||
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/lib)
|
||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/bin)
|
||||
|
@ -67,7 +69,13 @@ ELSE ()
|
|||
IF (${CMAKE_SYSTEM_PROCESSOR} MATCHES "arm64" OR ${CMAKE_SYSTEM_PROCESSOR} MATCHES "aarch64")
|
||||
ADD_DEFINITIONS("-D_TD_ARM_")
|
||||
ELSE ()
|
||||
ADD_DEFINITIONS("-msse4.2 -mfma")
|
||||
ADD_DEFINITIONS("-msse4.2")
|
||||
IF("${FMA_SUPPORT}" MATCHES "true")
|
||||
MESSAGE(STATUS "turn fma function support on")
|
||||
ADD_DEFINITIONS("-mfma")
|
||||
ELSE ()
|
||||
MESSAGE(STATUS "turn fma function support off")
|
||||
ENDIF()
|
||||
ENDIF ()
|
||||
|
||||
ENDIF ()
|
||||
|
|
|
@ -81,9 +81,10 @@ int32_t create_stream() {
|
|||
/*const char* sql = "select min(k), max(k), sum(k) as sum_of_k from st1";*/
|
||||
/*const char* sql = "select sum(k) from tu1 interval(10m)";*/
|
||||
/*pRes = tmq_create_stream(pConn, "stream1", "out1", sql);*/
|
||||
pRes = taos_query(
|
||||
pConn,
|
||||
"create stream stream1 trigger window_close as select min(k), max(k), sum(k) as sum_of_k from tu1 interval(10m)");
|
||||
pRes =
|
||||
taos_query(pConn,
|
||||
"create stream stream1 trigger window_close as select _wstartts, min(k), max(k), sum(k) as sum_of_k "
|
||||
"from tu1 interval(10m)");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to create stream stream1, reason:%s\n", taos_errstr(pRes));
|
||||
return -1;
|
||||
|
|
|
@ -54,6 +54,11 @@ SEpSet getEpSet_s(SCorEpSet* pEpSet);
|
|||
BMCharPos(bm_, r_) |= (1u << (7u - BitPos(r_))); \
|
||||
} while (0)
|
||||
|
||||
#define colDataSetNotNull_f(bm_, r_) \
|
||||
do { \
|
||||
BMCharPos(bm_, r_) &= ~(1u << (7u - BitPos(r_))); \
|
||||
} while (0)
|
||||
|
||||
#define colDataIsNull_var(pColumnInfoData, row) (pColumnInfoData->varmeta.offset[row] == -1)
|
||||
#define colDataSetNull_var(pColumnInfoData, row) (pColumnInfoData->varmeta.offset[row] = -1)
|
||||
|
||||
|
@ -64,15 +69,14 @@ SEpSet getEpSet_s(SCorEpSet* pEpSet);
|
|||
#define colDataGetNumData(p1_, r_) ((p1_)->pData + ((r_) * (p1_)->info.bytes))
|
||||
// SColumnInfoData, rowNumber
|
||||
#define colDataGetData(p1_, r_) \
|
||||
((IS_VAR_DATA_TYPE((p1_)->info.type)) ? colDataGetVarData(p1_, r_) \
|
||||
: colDataGetNumData(p1_, r_))
|
||||
((IS_VAR_DATA_TYPE((p1_)->info.type)) ? colDataGetVarData(p1_, r_) : colDataGetNumData(p1_, r_))
|
||||
|
||||
static FORCE_INLINE bool colDataIsNull_s(const SColumnInfoData* pColumnInfoData, uint32_t row) {
|
||||
if (pColumnInfoData->info.type == TSDB_DATA_TYPE_JSON){
|
||||
if(colDataIsNull_var(pColumnInfoData, row)){
|
||||
if (pColumnInfoData->info.type == TSDB_DATA_TYPE_JSON) {
|
||||
if (colDataIsNull_var(pColumnInfoData, row)) {
|
||||
return true;
|
||||
}
|
||||
char *data = colDataGetVarData(pColumnInfoData, row);
|
||||
char* data = colDataGetVarData(pColumnInfoData, row);
|
||||
return (*data == TSDB_DATA_TYPE_NULL);
|
||||
}
|
||||
|
||||
|
@ -80,7 +84,7 @@ static FORCE_INLINE bool colDataIsNull_s(const SColumnInfoData* pColumnInfoData,
|
|||
return false;
|
||||
}
|
||||
|
||||
if (pColumnInfoData->info.type== TSDB_DATA_TYPE_VARCHAR || pColumnInfoData->info.type == TSDB_DATA_TYPE_NCHAR) {
|
||||
if (pColumnInfoData->info.type == TSDB_DATA_TYPE_VARCHAR || pColumnInfoData->info.type == TSDB_DATA_TYPE_NCHAR) {
|
||||
return colDataIsNull_var(pColumnInfoData, row);
|
||||
} else {
|
||||
if (pColumnInfoData->nullbitmap == NULL) {
|
||||
|
@ -132,7 +136,7 @@ static FORCE_INLINE void colDataAppendNULL(SColumnInfoData* pColumnInfoData, uin
|
|||
static FORCE_INLINE void colDataAppendNNULL(SColumnInfoData* pColumnInfoData, uint32_t start, size_t nRows) {
|
||||
if (IS_VAR_DATA_TYPE(pColumnInfoData->info.type)) {
|
||||
for (int32_t i = start; i < start + nRows; ++i) {
|
||||
colDataSetNull_var(pColumnInfoData,i); // it is a null value of VAR type.
|
||||
colDataSetNull_var(pColumnInfoData, i); // it is a null value of VAR type.
|
||||
}
|
||||
} else {
|
||||
for (int32_t i = start; i < start + nRows; ++i) {
|
||||
|
@ -228,6 +232,8 @@ void blockDebugShowData(const SArray* dataBlocks);
|
|||
int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks, STSchema* pTSchema, int32_t vgId,
|
||||
tb_uid_t uid, tb_uid_t suid);
|
||||
|
||||
SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pSchema);
|
||||
|
||||
static FORCE_INLINE int32_t blockGetEncodeSize(const SSDataBlock* pBlock) {
|
||||
return blockDataGetSerialMetaSize(pBlock) + blockDataGetSize(pBlock);
|
||||
}
|
||||
|
@ -241,10 +247,10 @@ static FORCE_INLINE int32_t blockCompressColData(SColumnInfoData* pColRes, int32
|
|||
|
||||
static FORCE_INLINE void blockCompressEncode(const SSDataBlock* pBlock, char* data, int32_t* dataLen, int32_t numOfCols,
|
||||
int8_t needCompress) {
|
||||
int32_t* actualLen = (int32_t*) data;
|
||||
int32_t* actualLen = (int32_t*)data;
|
||||
data += sizeof(int32_t);
|
||||
|
||||
uint64_t* groupId = (uint64_t*) data;
|
||||
uint64_t* groupId = (uint64_t*)data;
|
||||
data += sizeof(uint64_t);
|
||||
|
||||
int32_t* colSizes = (int32_t*)data;
|
||||
|
|
|
@ -62,10 +62,10 @@ extern "C" {
|
|||
#pragma pack(push, 1)
|
||||
typedef struct {
|
||||
col_id_t colId; // column ID(start from PRIMARYKEY_TIMESTAMP_COL_ID(1))
|
||||
int32_t type : 8; // column type
|
||||
int32_t bytes : 24; // column bytes (0~16M)
|
||||
int32_t flags : 8; // flags: 0 no index, 1 SCHEMA_SMA_ON, 2 SCHEMA_IDX_ON
|
||||
int32_t offset : 24; // point offset in STpRow after the header part.
|
||||
int8_t type; // column type
|
||||
int8_t flags; // flags: 0 no index, 1 SCHEMA_SMA_ON, 2 SCHEMA_IDX_ON
|
||||
int32_t bytes; // column bytes (0~16M)
|
||||
int32_t offset; // point offset in STpRow after the header part.
|
||||
} STColumn;
|
||||
#pragma pack(pop)
|
||||
|
||||
|
|
|
@ -246,6 +246,8 @@ int32_t tInitSubmitMsgIter(const SSubmitReq* pMsg, SSubmitMsgIter* pIter);
|
|||
int32_t tGetSubmitMsgNext(SSubmitMsgIter* pIter, SSubmitBlk** pPBlock);
|
||||
int32_t tInitSubmitBlkIter(SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, SSubmitBlkIter* pIter);
|
||||
STSRow* tGetSubmitBlkNext(SSubmitBlkIter* pIter);
|
||||
// for debug
|
||||
int32_t tPrintFixedSchemaSubmitReq(const SSubmitReq* pReq, STSchema* pSchema);
|
||||
|
||||
typedef struct {
|
||||
int32_t index; // index of failed block in submit blocks
|
||||
|
@ -2143,7 +2145,7 @@ static FORCE_INLINE int32_t tDecodeSSchemaWrapper(SCoder* pDecoder, SSchemaWrapp
|
|||
if (tDecodeI32v(pDecoder, &pSW->nCols) < 0) return -1;
|
||||
if (tDecodeI32v(pDecoder, &pSW->sver) < 0) return -1;
|
||||
|
||||
pSW->pSchema = (SSchema*)tCoderMalloc(pDecoder, sizeof(SSchema) * pSW->nCols);
|
||||
pSW->pSchema = (SSchema*)taosMemoryCalloc(pSW->nCols, sizeof(SSchema));
|
||||
if (pSW->pSchema == NULL) return -1;
|
||||
for (int32_t i = 0; i < pSW->nCols; i++) {
|
||||
if (tDecodeSSchema(pDecoder, &pSW->pSchema[i]) < 0) return -1;
|
||||
|
@ -2589,6 +2591,28 @@ static FORCE_INLINE void tDeleteSMqAskEpRsp(SMqAskEpRsp* pRsp) {
|
|||
taosArrayDestroyEx(pRsp->topics, (void (*)(void*))tDeleteSMqSubTopicEp);
|
||||
}
|
||||
|
||||
#define TD_AUTO_CREATE_TABLE 0x1
|
||||
typedef struct {
|
||||
int64_t suid;
|
||||
int64_t uid;
|
||||
int32_t sver;
|
||||
uint64_t nData;
|
||||
const void* pData;
|
||||
SVCreateTbReq cTbReq;
|
||||
} SVSubmitBlk;
|
||||
|
||||
typedef struct {
|
||||
int32_t flags;
|
||||
int32_t nBlocks;
|
||||
union {
|
||||
SArray* pArray;
|
||||
SVSubmitBlk* pBlocks;
|
||||
};
|
||||
} SVSubmitReq;
|
||||
|
||||
int32_t tEncodeSVSubmitReq(SCoder* pCoder, const SVSubmitReq* pReq);
|
||||
int32_t tDecodeSVSubmitReq(SCoder* pCoder, SVSubmitReq* pReq);
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -622,7 +622,6 @@ static FORCE_INLINE int32_t tdSRowSetTpInfo(SRowBuilder *pBuilder, int32_t nCols
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief To judge row type: STpRow/SKvRow
|
||||
*
|
||||
|
@ -758,7 +757,6 @@ static int32_t tdSRowGetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 由调用方管理存储空间的分配及释放,一次输入多个参数
|
||||
*
|
||||
|
@ -1397,14 +1395,14 @@ static void tdSCellValPrint(SCellVal *pVal, int8_t colType) {
|
|||
}
|
||||
}
|
||||
|
||||
static void tdSRowPrint(STSRow *row, STSchema *pSchema, const char* tag) {
|
||||
static void tdSRowPrint(STSRow *row, STSchema *pSchema, const char *tag) {
|
||||
STSRowIter iter = {0};
|
||||
tdSTSRowIterInit(&iter, pSchema);
|
||||
tdSTSRowIterReset(&iter, row);
|
||||
printf("%s >>>", tag);
|
||||
for (int i = 0; i < pSchema->numOfCols; ++i) {
|
||||
STColumn *stCol = pSchema->columns + i;
|
||||
SCellVal sVal = { 255, NULL};
|
||||
SCellVal sVal = {255, NULL};
|
||||
if (!tdSTSRowIterNext(&iter, stCol->colId, stCol->type, &sVal)) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include "tmsg.h"
|
||||
#include "tcommon.h"
|
||||
#include "function.h"
|
||||
#include "tdatablock.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -54,14 +55,14 @@ int32_t setupUdf(char udfName[], UdfcFuncHandle *handle);
|
|||
|
||||
typedef struct SUdfColumnMeta {
|
||||
int16_t type;
|
||||
int32_t bytes; // <0 var length, others fixed length bytes
|
||||
int32_t bytes;
|
||||
uint8_t precision;
|
||||
uint8_t scale;
|
||||
} SUdfColumnMeta;
|
||||
|
||||
typedef struct SUdfColumnData {
|
||||
int32_t numOfRows;
|
||||
bool varLengthColumn;
|
||||
int32_t rowsAlloc;
|
||||
union {
|
||||
struct {
|
||||
int32_t nullBitmapLen;
|
||||
|
@ -72,9 +73,10 @@ typedef struct SUdfColumnData {
|
|||
|
||||
struct {
|
||||
int32_t varOffsetsLen;
|
||||
char *varOffsets;
|
||||
int32_t *varOffsets;
|
||||
int32_t payloadLen;
|
||||
char *payload;
|
||||
int32_t payloadAllocLen;
|
||||
} varLenCol;
|
||||
};
|
||||
} SUdfColumnData;
|
||||
|
@ -131,10 +133,114 @@ typedef int32_t (*TUdfSetupFunc)();
|
|||
typedef int32_t (*TUdfTeardownFunc)();
|
||||
|
||||
//TODO: add API to check function arguments type, number etc.
|
||||
//TODO: another way to manage memory is provide api for UDF to add data to SUdfColumnData and UDF framework will allocate memory.
|
||||
// then UDF framework will free the memory
|
||||
//typedef int32_t addFixedLengthColumnData(SColumnData *columnData, int rowIndex, bool isNull, int32_t colBytes, char* data);
|
||||
//typedef int32_t addVariableLengthColumnData(SColumnData *columnData, int rowIndex, bool isNull, int32_t dataLen, char * data);
|
||||
|
||||
#define UDF_MEMORY_EXP_GROWTH 1.5
|
||||
|
||||
static FORCE_INLINE int32_t udfColEnsureCapacity(SUdfColumn* pColumn, int32_t newCapacity) {
|
||||
SUdfColumnMeta *meta = &pColumn->colMeta;
|
||||
SUdfColumnData *data = &pColumn->colData;
|
||||
|
||||
if (newCapacity== 0 || newCapacity <= data->rowsAlloc) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int allocCapacity = TMAX(data->rowsAlloc, 8);
|
||||
while (allocCapacity < newCapacity) {
|
||||
allocCapacity *= UDF_MEMORY_EXP_GROWTH;
|
||||
}
|
||||
|
||||
if (IS_VAR_DATA_TYPE(meta->type)) {
|
||||
char* tmp = taosMemoryRealloc(data->varLenCol.varOffsets, sizeof(int32_t) * allocCapacity);
|
||||
if (tmp == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
data->varLenCol.varOffsets = (int32_t*)tmp;
|
||||
data->varLenCol.varOffsetsLen = sizeof(int32_t) * allocCapacity;
|
||||
// for payload, add data in udfColDataAppend
|
||||
} else {
|
||||
char* tmp = taosMemoryRealloc(data->fixLenCol.nullBitmap, BitmapLen(allocCapacity));
|
||||
if (tmp == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
data->fixLenCol.nullBitmap = tmp;
|
||||
data->fixLenCol.nullBitmapLen = BitmapLen(allocCapacity);
|
||||
if (meta->type == TSDB_DATA_TYPE_NULL) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
tmp = taosMemoryRealloc(data->fixLenCol.data, allocCapacity* meta->bytes);
|
||||
if (tmp == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
data->fixLenCol.data = tmp;
|
||||
data->fixLenCol.dataLen = allocCapacity* meta->bytes;
|
||||
}
|
||||
|
||||
data->rowsAlloc = allocCapacity;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t udfColSetRow(SUdfColumn* pColumn, uint32_t currentRow, const char* pData, bool isNull) {
|
||||
SUdfColumnMeta *meta = &pColumn->colMeta;
|
||||
SUdfColumnData *data = &pColumn->colData;
|
||||
udfColEnsureCapacity(pColumn, currentRow+1);
|
||||
bool isVarCol = IS_VAR_DATA_TYPE(meta->type);
|
||||
if (isNull) {
|
||||
if (isVarCol) {
|
||||
data->varLenCol.varOffsets[currentRow] = -1;
|
||||
} else {
|
||||
colDataSetNull_f(data->fixLenCol.nullBitmap, currentRow);
|
||||
}
|
||||
} else {
|
||||
if (!isVarCol) {
|
||||
colDataSetNotNull_f(data->fixLenCol.nullBitmap, currentRow);
|
||||
memcpy(data->fixLenCol.data + meta->bytes * currentRow, pData, meta->bytes);
|
||||
} else {
|
||||
int32_t dataLen = varDataTLen(pData);
|
||||
if (meta->type == TSDB_DATA_TYPE_JSON) {
|
||||
if (*pData == TSDB_DATA_TYPE_NULL) {
|
||||
dataLen = 0;
|
||||
} else if (*pData == TSDB_DATA_TYPE_NCHAR) {
|
||||
dataLen = varDataTLen(pData + CHAR_BYTES);
|
||||
} else if (*pData == TSDB_DATA_TYPE_BIGINT || *pData == TSDB_DATA_TYPE_DOUBLE) {
|
||||
dataLen = LONG_BYTES;
|
||||
} else if (*pData == TSDB_DATA_TYPE_BOOL) {
|
||||
dataLen = CHAR_BYTES;
|
||||
}
|
||||
dataLen += CHAR_BYTES;
|
||||
}
|
||||
|
||||
if (data->varLenCol.payloadAllocLen < data->varLenCol.payloadLen + dataLen) {
|
||||
uint32_t newSize = data->varLenCol.payloadAllocLen;
|
||||
if (newSize <= 1) {
|
||||
newSize = 8;
|
||||
}
|
||||
|
||||
while (newSize < data->varLenCol.payloadLen + dataLen) {
|
||||
newSize = newSize * UDF_MEMORY_EXP_GROWTH;
|
||||
}
|
||||
|
||||
char *buf = taosMemoryRealloc(data->varLenCol.payload, newSize);
|
||||
if (buf == NULL) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
data->varLenCol.payload = buf;
|
||||
data->varLenCol.payloadAllocLen = newSize;
|
||||
}
|
||||
|
||||
uint32_t len = data->varLenCol.payloadLen;
|
||||
data->varLenCol.varOffsets[currentRow] = len;
|
||||
|
||||
memcpy(data->varLenCol.payload + len, pData, dataLen);
|
||||
data->varLenCol.payloadLen += dataLen;
|
||||
}
|
||||
}
|
||||
data->numOfRows = TMAX(currentRow + 1, data->numOfRows);
|
||||
return 0;
|
||||
}
|
||||
|
||||
typedef int32_t (*TUdfFreeUdfColumnFunc)(SUdfColumn* column);
|
||||
typedef int32_t (*TUdfScalarProcFunc)(SUdfDataBlock* block, SUdfColumn *resultCol);
|
||||
|
|
|
@ -47,7 +47,17 @@ typedef enum {
|
|||
} SIndexOperOnColumn;
|
||||
|
||||
typedef enum { MUST = 0, SHOULD, NOT } EIndexOperatorType;
|
||||
typedef enum { QUERY_TERM = 0, QUERY_PREFIX, QUERY_SUFFIX, QUERY_REGEX, QUERY_RANGE } EIndexQueryType;
|
||||
typedef enum {
|
||||
QUERY_TERM = 0,
|
||||
QUERY_PREFIX,
|
||||
QUERY_SUFFIX,
|
||||
QUERY_REGEX,
|
||||
QUERY_LESS_THAN,
|
||||
QUERY_LESS_EQUAL,
|
||||
QUERY_GREATER_THAN,
|
||||
QUERY_GREATER_EQUAL,
|
||||
QUERY_RANGE
|
||||
} EIndexQueryType;
|
||||
|
||||
/*
|
||||
* create multi query
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "querynodes.h"
|
||||
#include "query.h"
|
||||
#include "querynodes.h"
|
||||
|
||||
typedef struct SStmtCallback {
|
||||
TAOS_STMT* pStmt;
|
||||
|
@ -34,16 +34,18 @@ typedef struct SStmtCallback {
|
|||
typedef struct SParseContext {
|
||||
uint64_t requestId;
|
||||
int32_t acctId;
|
||||
const char *db;
|
||||
const char* db;
|
||||
bool topicQuery;
|
||||
void *pTransporter;
|
||||
void* pTransporter;
|
||||
SEpSet mgmtEpSet;
|
||||
const char *pSql; // sql string
|
||||
const char* pSql; // sql string
|
||||
size_t sqlLen; // length of the sql string
|
||||
char *pMsg; // extended error message if exists to help identifying the problem in sql statement.
|
||||
char* pMsg; // extended error message if exists to help identifying the problem in sql statement.
|
||||
int32_t msgLen; // max length of the msg
|
||||
struct SCatalog *pCatalog;
|
||||
SStmtCallback *pStmtCb;
|
||||
struct SCatalog* pCatalog;
|
||||
SStmtCallback* pStmtCb;
|
||||
const char* pUser;
|
||||
bool isSuperUser;
|
||||
} SParseContext;
|
||||
|
||||
typedef struct SCmdMsgInfo {
|
||||
|
@ -89,14 +91,16 @@ int32_t qCloneStmtDataBlock(void** pDst, void* pSrc);
|
|||
void qFreeStmtDataBlock(void* pDataBlock);
|
||||
int32_t qRebuildStmtDataBlock(void** pDst, void* pSrc);
|
||||
void qDestroyStmtDataBlock(void* pBlock);
|
||||
int32_t qBindStmtColsValue(void *pBlock, TAOS_MULTI_BIND *bind, char *msgBuf, int32_t msgBufLen);
|
||||
int32_t qBindStmtSingleColValue(void *pBlock, TAOS_MULTI_BIND *bind, char *msgBuf, int32_t msgBufLen, int32_t colIdx, int32_t rowNum);
|
||||
int32_t qBuildStmtColFields(void *pDataBlock, int32_t *fieldNum, TAOS_FIELD** fields);
|
||||
int32_t qBuildStmtTagFields(void *pBlock, void *boundTags, int32_t *fieldNum, TAOS_FIELD** fields);
|
||||
int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *pName, TAOS_MULTI_BIND *bind, char *msgBuf, int32_t msgBufLen);
|
||||
int32_t qBindStmtColsValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen);
|
||||
int32_t qBindStmtSingleColValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, int32_t colIdx,
|
||||
int32_t rowNum);
|
||||
int32_t qBuildStmtColFields(void* pDataBlock, int32_t* fieldNum, TAOS_FIELD** fields);
|
||||
int32_t qBuildStmtTagFields(void* pBlock, void* boundTags, int32_t* fieldNum, TAOS_FIELD** fields);
|
||||
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, SName* pName, TAOS_MULTI_BIND* bind,
|
||||
char* msgBuf, int32_t msgBufLen);
|
||||
void destroyBoundColumnInfo(void* pBoundInfo);
|
||||
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char *msgBuf, int32_t msgBufLen);
|
||||
|
||||
int32_t qCreateSName(SName* pName, const char* pTableName, int32_t acctId, char* dbName, char* msgBuf,
|
||||
int32_t msgBufLen);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -71,7 +71,9 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
int8_t reserved;
|
||||
SSchemaWrapper* pSchemaWrapper;
|
||||
// not applicable to encoder and decoder
|
||||
STSchema* pTSchema;
|
||||
SHashObj* pHash; // groupId to tbuid
|
||||
} STaskSinkTb;
|
||||
|
||||
|
|
|
@ -59,6 +59,8 @@ bool taosMbsToUcs4(const char *mbs, size_t mbs_len, TdUcs4 *ucs4, int32_t ucs
|
|||
int32_t tasoUcs4Compare(TdUcs4 *f1_ucs4, TdUcs4 *f2_ucs4, int32_t bytes);
|
||||
TdUcs4* tasoUcs4Copy(TdUcs4 *target_ucs4, TdUcs4 *source_ucs4, int32_t len_ucs4);
|
||||
bool taosValidateEncodec(const char *encodec);
|
||||
int32_t taosHexEncode(const char *src, char *dst, int32_t len);
|
||||
int32_t taosHexDecode(const char *src, char *dst, int32_t len);
|
||||
|
||||
int32_t taosWcharWidth(TdWchar wchar);
|
||||
int32_t taosWcharsWidth(TdWchar *pWchar, int32_t size);
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifndef _TD_UTIL_SKIPLIST2_H_
|
||||
#define _TD_UTIL_SKIPLIST2_H_
|
||||
|
||||
#include "os.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define SL_MAX_LEVEL 15
|
||||
|
||||
typedef struct SSkipList2 SSkipList2;
|
||||
typedef struct SSLCursor SSLCursor;
|
||||
typedef struct SSLCfg SSLCfg;
|
||||
typedef struct SSLNode SSLNode;
|
||||
|
||||
typedef int32_t (*tslCmprFn)(const void *pKey1, int32_t nKey1, const void *pKey2, int32_t nKey2);
|
||||
|
||||
// SSkipList2
|
||||
int32_t slOpen(const SSLCfg *pCfg, SSkipList2 **ppSl);
|
||||
int32_t slClose(SSkipList2 *pSl);
|
||||
int32_t slClear(SSkipList2 *pSl);
|
||||
|
||||
// SSLCursor
|
||||
int32_t slcOpen(SSkipList2 *pSl, SSLCursor *pSlc);
|
||||
int32_t slcClose(SSLCursor *pSlc);
|
||||
int32_t slcMoveTo(SSLCursor *pSlc, const void *pKey, int32_t nKey);
|
||||
int32_t slcMoveToNext(SSLCursor *pSlc);
|
||||
int32_t slcMoveToPrev(SSLCursor *pSlc);
|
||||
int32_t slcMoveToFirst(SSLCursor *pSlc);
|
||||
int32_t slcMoveToLast(SSLCursor *pSlc);
|
||||
int32_t slcPut(SSLCursor *pSlc, const void *pKey, int32_t nKey, const void *pData, int32_t nData);
|
||||
int32_t slcGet(SSLCursor *pSlc, const void **ppKey, int32_t *nKey, const void **ppData, int32_t *nData);
|
||||
int32_t slcDrop(SSLCursor *pSlc);
|
||||
|
||||
// struct
|
||||
struct SSLCfg {
|
||||
int8_t maxLevel;
|
||||
int32_t nKey;
|
||||
int32_t nData;
|
||||
tslCmprFn cmprFn;
|
||||
void *pPool;
|
||||
void *(*xMalloc)(void *, int32_t size);
|
||||
void (*xFree)(void *, void *);
|
||||
};
|
||||
|
||||
struct SSLCursor {
|
||||
SSkipList2 *pSl;
|
||||
SSLNode **forwards[SL_MAX_LEVEL];
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_UTIL_SKIPLIST2_H_*/
|
|
@ -491,7 +491,12 @@ SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int3
|
|||
SColumnInfoData* pDstCol = taosArrayGet(pDst->pDataBlock, i);
|
||||
|
||||
for (int32_t j = startIndex; j < (startIndex + rowCount); ++j) {
|
||||
bool isNull = colDataIsNull(pColData, pBlock->info.rows, j, pBlock->pBlockAgg[i]);
|
||||
bool isNull = false;
|
||||
if (pBlock->pBlockAgg == NULL) {
|
||||
isNull = colDataIsNull(pColData, pBlock->info.rows, j, NULL);
|
||||
} else {
|
||||
isNull = colDataIsNull(pColData, pBlock->info.rows, j, pBlock->pBlockAgg[i]);
|
||||
}
|
||||
char* p = colDataGetData(pColData, j);
|
||||
|
||||
colDataAppend(pDstCol, j - startIndex, p, isNull);
|
||||
|
@ -1589,3 +1594,68 @@ int32_t buildSubmitReqFromDataBlock(SSubmitReq** pReq, const SArray* pDataBlocks
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SSubmitReq* tdBlockToSubmit(const SArray* pBlocks, const STSchema* pTSchema) {
|
||||
SSubmitReq* ret = NULL;
|
||||
|
||||
// cal size
|
||||
int32_t cap = sizeof(SSubmitReq);
|
||||
int32_t sz = taosArrayGetSize(pBlocks);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SSDataBlock* pDataBlock = taosArrayGet(pBlocks, i);
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
// TODO min
|
||||
int32_t rowSize = pDataBlock->info.rowSize;
|
||||
int32_t maxLen = TD_ROW_MAX_BYTES_FROM_SCHEMA(pTSchema);
|
||||
cap += sizeof(SSubmitBlk) + rows * maxLen;
|
||||
}
|
||||
|
||||
// assign data
|
||||
ret = taosMemoryCalloc(1, cap);
|
||||
ret->version = htonl(1);
|
||||
ret->length = htonl(cap - sizeof(SSubmitReq));
|
||||
ret->numOfBlocks = htonl(sz);
|
||||
|
||||
void* submitBlk = POINTER_SHIFT(ret, sizeof(SSubmitReq));
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SSDataBlock* pDataBlock = taosArrayGet(pBlocks, i);
|
||||
|
||||
SSubmitBlk* blkHead = submitBlk;
|
||||
blkHead->numOfRows = htons(pDataBlock->info.rows);
|
||||
blkHead->schemaLen = 0;
|
||||
blkHead->sversion = htonl(pTSchema->version);
|
||||
// TODO
|
||||
blkHead->suid = 0;
|
||||
blkHead->uid = htobe64(pDataBlock->info.uid);
|
||||
|
||||
int32_t rows = pDataBlock->info.rows;
|
||||
int32_t maxLen = TD_ROW_MAX_BYTES_FROM_SCHEMA(pTSchema);
|
||||
/*blkHead->dataLen = htonl(rows * maxLen);*/
|
||||
blkHead->dataLen = 0;
|
||||
|
||||
void* blockData = POINTER_SHIFT(submitBlk, sizeof(SSubmitBlk));
|
||||
STSRow* rowData = blockData;
|
||||
|
||||
for (int32_t j = 0; j < pDataBlock->info.rows; j++) {
|
||||
SRowBuilder rb = {0};
|
||||
tdSRowInit(&rb, pTSchema->version);
|
||||
tdSRowSetTpInfo(&rb, pTSchema->numOfCols, pTSchema->flen);
|
||||
tdSRowResetBuf(&rb, rowData);
|
||||
|
||||
for (int32_t k = 0; k < pTSchema->numOfCols; k++) {
|
||||
const STColumn* pColumn = &pTSchema->columns[k];
|
||||
SColumnInfoData* pColData = taosArrayGet(pDataBlock->pDataBlock, k);
|
||||
void* data = colDataGetData(pColData, j);
|
||||
tdAppendColValToRow(&rb, pColumn->colId, pColumn->type, TD_VTYPE_NORM, data, true, pColumn->offset, k);
|
||||
}
|
||||
int32_t rowLen = TD_ROW_LEN(rowData);
|
||||
rowData = POINTER_SHIFT(rowData, rowLen);
|
||||
blkHead->dataLen += rowLen;
|
||||
}
|
||||
int32_t len = blkHead->dataLen;
|
||||
blkHead->dataLen = htonl(len);
|
||||
blkHead = POINTER_SHIFT(blkHead, len);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "tdataformat.h"
|
||||
#include "tcoding.h"
|
||||
#include "tdatablock.h"
|
||||
#include "tlog.h"
|
||||
|
||||
static void dataColSetNEleNull(SDataCol *pCol, int nEle);
|
||||
|
@ -128,6 +129,50 @@ void *tdDecodeSchema(void *buf, STSchema **pRSchema) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
#if 0
|
||||
int32_t tEncodeSTColumn(SCoder *pEncoder, const STColumn *pCol) {
|
||||
if (tEncodeI16(pEncoder, pCol->colId) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pCol->type) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pCol->sma) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pCol->bytes) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pCol->offset) < 0) return -1;
|
||||
return pEncoder->pos;
|
||||
}
|
||||
|
||||
int32_t tDecodeSTColumn(SCoder *pDecoder, STColumn *pCol) {
|
||||
if (tDecodeI16(pDecoder, &pCol->colId) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pCol->type) < 0) return -1;
|
||||
if (tDecodeI8(pDecoder, &pCol->sma) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pCol->bytes) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pCol->offset) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSchema(SCoder *pEncoder, const STSchema *pSchema) {
|
||||
if (tEncodeI32(pEncoder, pSchema->numOfCols) < 0) return -1;
|
||||
if (tEncodeI16(pEncoder, pSchema->version) < 0) return -1;
|
||||
if (tEncodeU16(pEncoder, pSchema->flen) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pSchema->vlen) < 0) return -1;
|
||||
if (tEncodeI32(pEncoder, pSchema->tlen) < 0) return -1;
|
||||
|
||||
for (int32_t i = 0; i < schemaNCols(pSchema); i++) {
|
||||
const STColumn *pCol = schemaColAt(pSchema, i);
|
||||
if (tEncodeSTColumn(pEncoder, pCol) < 0) return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSchema(SCoder *pDecoder, STSchema *pSchema) {
|
||||
if (tDecodeI32(pDecoder, &pSchema->numOfCols) < 0) return -1;
|
||||
if (tDecodeI16(pDecoder, &pSchema->version) < 0) return -1;
|
||||
if (tDecodeU16(pDecoder, &pSchema->flen) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pSchema->vlen) < 0) return -1;
|
||||
if (tDecodeI32(pDecoder, &pSchema->tlen) < 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
int tdInitTSchemaBuilder(STSchemaBuilder *pBuilder, schema_ver_t version) {
|
||||
if (pBuilder == NULL) return -1;
|
||||
|
||||
|
|
|
@ -224,7 +224,8 @@ struct SConfig *taosGetCfg() {
|
|||
return tsCfg;
|
||||
}
|
||||
|
||||
static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile, char *apolloUrl) {
|
||||
static int32_t taosLoadCfg(SConfig *pCfg, const char **envCmd, const char *inputCfgDir, const char *envFile,
|
||||
char *apolloUrl) {
|
||||
char cfgDir[PATH_MAX] = {0};
|
||||
char cfgFile[PATH_MAX + 100] = {0};
|
||||
|
||||
|
@ -300,15 +301,10 @@ static int32_t taosAddServerLogCfg(SConfig *pCfg) {
|
|||
static int32_t taosAddClientCfg(SConfig *pCfg) {
|
||||
char defaultFqdn[TSDB_FQDN_LEN] = {0};
|
||||
int32_t defaultServerPort = 6030;
|
||||
char defaultFirstEp[TSDB_EP_LEN] = {0};
|
||||
char defaultSecondEp[TSDB_EP_LEN] = {0};
|
||||
|
||||
if (taosGetFqdn(defaultFqdn) != 0) return -1;
|
||||
snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%d", defaultFqdn, defaultServerPort);
|
||||
snprintf(defaultSecondEp, TSDB_EP_LEN, "%s:%d", defaultFqdn, defaultServerPort);
|
||||
|
||||
if (cfgAddString(pCfg, "firstEp", defaultFirstEp, 1) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "secondEp", defaultSecondEp, 1) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "firstEp", "", 1) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "secondEp", "", 1) != 0) return -1;
|
||||
if (cfgAddString(pCfg, "fqdn", defaultFqdn, 1) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "serverPort", defaultServerPort, 1, 65056, 1) != 0) return -1;
|
||||
if (cfgAddDir(pCfg, "tempDir", tsTempDir, 1) != 0) return -1;
|
||||
|
@ -478,15 +474,18 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
|
|||
tsServerPort = (uint16_t)cfgGetItem(pCfg, "serverPort")->i32;
|
||||
snprintf(tsLocalEp, sizeof(tsLocalEp), "%s:%u", tsLocalFqdn, tsServerPort);
|
||||
|
||||
char defaultFirstEp[TSDB_EP_LEN] = {0};
|
||||
snprintf(defaultFirstEp, TSDB_EP_LEN, "%s:%u", tsLocalFqdn, tsServerPort);
|
||||
|
||||
SConfigItem *pFirstEpItem = cfgGetItem(pCfg, "firstEp");
|
||||
SEp firstEp = {0};
|
||||
taosGetFqdnPortFromEp(pFirstEpItem->str, &firstEp);
|
||||
taosGetFqdnPortFromEp(strlen(pFirstEpItem->str) == 0 ? defaultFirstEp : pFirstEpItem->str, &firstEp);
|
||||
snprintf(tsFirst, sizeof(tsFirst), "%s:%u", firstEp.fqdn, firstEp.port);
|
||||
cfgSetItem(pCfg, "firstEp", tsFirst, pFirstEpItem->stype);
|
||||
|
||||
SConfigItem *pSecondpItem = cfgGetItem(pCfg, "secondEp");
|
||||
SEp secondEp = {0};
|
||||
taosGetFqdnPortFromEp(pSecondpItem->str, &secondEp);
|
||||
taosGetFqdnPortFromEp(strlen(pSecondpItem->str) == 0 ? defaultFirstEp : pSecondpItem->str, &secondEp);
|
||||
snprintf(tsSecond, sizeof(tsSecond), "%s:%u", secondEp.fqdn, secondEp.port);
|
||||
cfgSetItem(pCfg, "secondEp", tsSecond, pSecondpItem->stype);
|
||||
|
||||
|
@ -583,8 +582,8 @@ static int32_t taosSetServerCfg(SConfig *pCfg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd, const char *envFile,
|
||||
char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||
int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDir, const char **envCmd,
|
||||
const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||
osDefaultInit();
|
||||
|
||||
SConfig *pCfg = cfgInit();
|
||||
|
@ -636,7 +635,24 @@ int32_t taosCreateLog(const char *logname, int32_t logFileNum, const char *cfgDi
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs, bool tsc) {
|
||||
static int32_t taosCheckGlobalCfg() {
|
||||
uint32_t ipv4 = taosGetIpv4FromFqdn(tsLocalFqdn);
|
||||
if (ipv4 == 0xffffffff) {
|
||||
terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
uError("failed to get ip from fqdn:%s since %s, dnode can not be initialized", tsLocalFqdn, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tsServerPort <= 0) {
|
||||
uError("invalid server port:%u, dnode can not be initialized", tsServerPort);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile, char *apolloUrl, SArray *pArgs,
|
||||
bool tsc) {
|
||||
if (tsCfg != NULL) return 0;
|
||||
tsCfg = cfgInit();
|
||||
|
||||
|
@ -674,6 +690,11 @@ int32_t taosInitCfg(const char *cfgDir, const char **envCmd, const char *envFile
|
|||
taosSetSystemCfg(tsCfg);
|
||||
|
||||
cfgDumpCfg(tsCfg, tsc, false);
|
||||
|
||||
if (taosCheckGlobalCfg() != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,6 +103,25 @@ STSRow *tGetSubmitBlkNext(SSubmitBlkIter *pIter) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t tPrintFixedSchemaSubmitReq(const SSubmitReq *pReq, STSchema *pTschema) {
|
||||
SSubmitMsgIter msgIter = {0};
|
||||
if (tInitSubmitMsgIter(pReq, &msgIter) < 0) return -1;
|
||||
while (true) {
|
||||
SSubmitBlk *pBlock = NULL;
|
||||
if (tGetSubmitMsgNext(&msgIter, &pBlock) < 0) return -1;
|
||||
if (pBlock == NULL) break;
|
||||
SSubmitBlkIter blkIter = {0};
|
||||
tInitSubmitBlkIter(&msgIter, pBlock, &blkIter);
|
||||
STSRowIter rowIter = {0};
|
||||
tdSTSRowIterInit(&rowIter, pTschema);
|
||||
STSRow *row;
|
||||
while ((row = tGetSubmitBlkNext(&blkIter)) != NULL) {
|
||||
tdSRowPrint(row, pTschema, "stream");
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSEpSet(SCoder *pEncoder, const SEpSet *pEp) {
|
||||
if (tEncodeI8(pEncoder, pEp->inUse) < 0) return -1;
|
||||
if (tEncodeI8(pEncoder, pEp->numOfEps) < 0) return -1;
|
||||
|
@ -3933,3 +3952,65 @@ int32_t tDecodeSVDropStbReq(SCoder *pCoder, SVDropStbReq *pReq) {
|
|||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tEncodeSVSubmitBlk(SCoder *pCoder, const SVSubmitBlk *pBlock, int32_t flags) {
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI64(pCoder, pBlock->suid) < 0) return -1;
|
||||
if (tEncodeI64(pCoder, pBlock->uid) < 0) return -1;
|
||||
if (tEncodeI32v(pCoder, pBlock->sver) < 0) return -1;
|
||||
if (tEncodeBinary(pCoder, pBlock->pData, pBlock->nData) < 0) return -1;
|
||||
|
||||
if (flags & TD_AUTO_CREATE_TABLE) {
|
||||
if (tEncodeSVCreateTbReq(pCoder, &pBlock->cTbReq) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tDecodeSVSubmitBlk(SCoder *pCoder, SVSubmitBlk *pBlock, int32_t flags) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI64(pCoder, &pBlock->suid) < 0) return -1;
|
||||
if (tDecodeI64(pCoder, &pBlock->uid) < 0) return -1;
|
||||
if (tDecodeI32v(pCoder, &pBlock->sver) < 0) return -1;
|
||||
if (tDecodeBinary(pCoder, &pBlock->pData, &pBlock->nData) < 0) return -1;
|
||||
|
||||
if (flags & TD_AUTO_CREATE_TABLE) {
|
||||
if (tDecodeSVCreateTbReq(pCoder, &pBlock->cTbReq) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tEncodeSVSubmitReq(SCoder *pCoder, const SVSubmitReq *pReq) {
|
||||
int32_t nBlocks = taosArrayGetSize(pReq->pArray);
|
||||
|
||||
if (tStartEncode(pCoder) < 0) return -1;
|
||||
|
||||
if (tEncodeI32v(pCoder, pReq->flags) < 0) return -1;
|
||||
if (tEncodeI32v(pCoder, nBlocks) < 0) return -1;
|
||||
for (int32_t iBlock = 0; iBlock < nBlocks; iBlock++) {
|
||||
if (tEncodeSVSubmitBlk(pCoder, (SVSubmitBlk *)taosArrayGet(pReq->pArray, iBlock), pReq->flags) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndEncode(pCoder);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tDecodeSVSubmitReq(SCoder *pCoder, SVSubmitReq *pReq) {
|
||||
if (tStartDecode(pCoder) < 0) return -1;
|
||||
|
||||
if (tDecodeI32v(pCoder, &pReq->flags) < 0) return -1;
|
||||
if (tDecodeI32v(pCoder, &pReq->nBlocks) < 0) return -1;
|
||||
pReq->pBlocks = tCoderMalloc(pCoder, sizeof(SVSubmitBlk) * pReq->nBlocks);
|
||||
if (pReq->pBlocks == NULL) return -1;
|
||||
for (int32_t iBlock = 0; iBlock < pReq->nBlocks; iBlock++) {
|
||||
if (tDecodeSVSubmitBlk(pCoder, pReq->pBlocks + iBlock, pReq->flags) < 0) return -1;
|
||||
}
|
||||
|
||||
tEndDecode(pCoder);
|
||||
return 0;
|
||||
}
|
|
@ -420,6 +420,7 @@ typedef struct {
|
|||
|
||||
typedef struct {
|
||||
char key[TSDB_PARTITION_KEY_LEN];
|
||||
int64_t dbUid;
|
||||
int64_t offset;
|
||||
} SMqOffsetObj;
|
||||
|
||||
|
|
|
@ -37,6 +37,8 @@ static FORCE_INLINE int32_t mndMakePartitionKey(char *key, const char *cgroup, c
|
|||
return snprintf(key, TSDB_PARTITION_KEY_LEN, "%d:%s:%s", vgId, cgroup, topicName);
|
||||
}
|
||||
|
||||
int32_t mndDropOffsetByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -31,6 +31,8 @@ void mndReleaseSubscribe(SMnode *pMnode, SMqSubscribeObj *pSub);
|
|||
|
||||
int32_t mndMakeSubscribeKey(char *key, const char *cgroup, const char *topicName);
|
||||
|
||||
int32_t mndDropSubByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -44,6 +44,8 @@ typedef void (*TransCbFp)(SMnode *pMnode, void *param, int32_t paramLen);
|
|||
|
||||
int32_t mndInitTrans(SMnode *pMnode);
|
||||
void mndCleanupTrans(SMnode *pMnode);
|
||||
STrans *mndAcquireTrans(SMnode *pMnode, int32_t transId);
|
||||
void mndReleaseTrans(SMnode *pMnode, STrans *pTrans);
|
||||
|
||||
STrans *mndTransCreate(SMnode *pMnode, ETrnPolicy policy, ETrnType type, const SRpcMsg *pReq);
|
||||
void mndTransDrop(STrans *pTrans);
|
||||
|
@ -59,6 +61,7 @@ void mndTransSetDbInfo(STrans *pTrans, SDbObj *pDb);
|
|||
int32_t mndTransPrepare(SMnode *pMnode, STrans *pTrans);
|
||||
void mndTransProcessRsp(SNodeMsg *pRsp);
|
||||
void mndTransPullup(SMnode *pMnode);
|
||||
int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -17,9 +17,12 @@
|
|||
#include "mndDb.h"
|
||||
#include "mndAuth.h"
|
||||
#include "mndDnode.h"
|
||||
#include "mndOffset.h"
|
||||
#include "mndShow.h"
|
||||
#include "mndSma.h"
|
||||
#include "mndStb.h"
|
||||
#include "mndSubscribe.h"
|
||||
#include "mndTopic.h"
|
||||
#include "mndTrans.h"
|
||||
#include "mndUser.h"
|
||||
#include "mndVgroup.h"
|
||||
|
@ -1027,6 +1030,9 @@ static int32_t mndDropDb(SMnode *pMnode, SNodeMsg *pReq, SDbObj *pDb) {
|
|||
|
||||
if (mndSetDropDbRedoLogs(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||
if (mndSetDropDbCommitLogs(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||
/*if (mndDropOffsetByDB(pMnode, pTrans, pDb) != 0) goto _OVER;*/
|
||||
/*if (mndDropSubByDB(pMnode, pTrans, pDb) != 0) goto _OVER;*/
|
||||
/*if (mndDropTopicByDB(pMnode, pTrans, pDb) != 0) goto _OVER;*/
|
||||
if (mndSetDropDbRedoActions(pMnode, pTrans, pDb) != 0) goto _OVER;
|
||||
|
||||
int32_t rspLen = 0;
|
||||
|
|
|
@ -231,3 +231,36 @@ static void mndCancelGetNextOffset(SMnode *pMnode, void *pIter) {
|
|||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
}
|
||||
|
||||
static int32_t mndSetDropOffsetCommitLogs(SMnode *pMnode, STrans *pTrans, SMqOffsetObj *pOffset) {
|
||||
SSdbRaw *pCommitRaw = mndOffsetActionEncode(pOffset);
|
||||
if (pCommitRaw == NULL) return -1;
|
||||
if (mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) return -1;
|
||||
if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t mndDropOffsetByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
||||
int32_t code = -1;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
|
||||
void *pIter = NULL;
|
||||
SMqOffsetObj *pOffset = NULL;
|
||||
while (1) {
|
||||
pIter = sdbFetch(pSdb, SDB_SUBSCRIBE, pIter, (void **)&pOffset);
|
||||
if (pIter == NULL) break;
|
||||
|
||||
if (pOffset->dbUid != pDb->uid) {
|
||||
sdbRelease(pSdb, pOffset);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mndSetDropOffsetCommitLogs(pMnode, pTrans, pOffset) < 0) {
|
||||
goto END;
|
||||
}
|
||||
}
|
||||
|
||||
code = 0;
|
||||
END:
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -204,6 +204,8 @@ int32_t mndAddShuffledSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* p
|
|||
pTask->smaSink.smaId = pStream->smaId;
|
||||
} else {
|
||||
pTask->sinkType = TASK_SINK__TABLE;
|
||||
pTask->tbSink.pSchemaWrapper = tCloneSSchemaWrapper(&pStream->outputSchema);
|
||||
ASSERT(pTask->tbSink.pSchemaWrapper);
|
||||
}
|
||||
|
||||
// dispatch
|
||||
|
@ -242,6 +244,7 @@ int32_t mndAddFixedSinkToStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStr
|
|||
pTask->smaSink.smaId = pStream->smaId;
|
||||
} else {
|
||||
pTask->sinkType = TASK_SINK__TABLE;
|
||||
pTask->tbSink.pSchemaWrapper = tCloneSSchemaWrapper(&pStream->outputSchema);
|
||||
}
|
||||
//
|
||||
// dispatch
|
||||
|
@ -316,6 +319,7 @@ int32_t mndScheduleStream(SMnode* pMnode, STrans* pTrans, SStreamObj* pStream) {
|
|||
pTask->smaSink.smaId = pStream->smaId;
|
||||
} else {
|
||||
pTask->sinkType = TASK_SINK__TABLE;
|
||||
pTask->tbSink.pSchemaWrapper = tCloneSSchemaWrapper(&pStream->outputSchema);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
@ -537,7 +537,7 @@ static int32_t mndTransActionUpdate(SSdb *pSdb, STrans *pOld, STrans *pNew) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static STrans *mndAcquireTrans(SMnode *pMnode, int32_t transId) {
|
||||
STrans *mndAcquireTrans(SMnode *pMnode, int32_t transId) {
|
||||
STrans *pTrans = sdbAcquire(pMnode->pSdb, SDB_TRANS, &transId);
|
||||
if (pTrans == NULL) {
|
||||
terrno = TSDB_CODE_MND_TRANS_NOT_EXIST;
|
||||
|
@ -545,7 +545,7 @@ static STrans *mndAcquireTrans(SMnode *pMnode, int32_t transId) {
|
|||
return pTrans;
|
||||
}
|
||||
|
||||
static void mndReleaseTrans(SMnode *pMnode, STrans *pTrans) {
|
||||
void mndReleaseTrans(SMnode *pMnode, STrans *pTrans) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbRelease(pSdb, pTrans);
|
||||
}
|
||||
|
@ -919,27 +919,41 @@ static int32_t mndTransExecuteLogs(SMnode *pMnode, SArray *pArray) {
|
|||
|
||||
if (arraySize == 0) return 0;
|
||||
|
||||
int32_t code = 0;
|
||||
for (int32_t i = 0; i < arraySize; ++i) {
|
||||
SSdbRaw *pRaw = taosArrayGetP(pArray, i);
|
||||
int32_t code = sdbWriteWithoutFree(pSdb, pRaw);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
if (sdbWriteWithoutFree(pSdb, pRaw) != 0) {
|
||||
code = ((terrno != 0) ? terrno : -1);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteRedoLogs(SMnode *pMnode, STrans *pTrans) {
|
||||
return mndTransExecuteLogs(pMnode, pTrans->redoLogs);
|
||||
int32_t code = mndTransExecuteLogs(pMnode, pTrans->redoLogs);
|
||||
if (code != 0) {
|
||||
mError("failed to execute redoLogs since %s", terrstr());
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteUndoLogs(SMnode *pMnode, STrans *pTrans) {
|
||||
return mndTransExecuteLogs(pMnode, pTrans->undoLogs);
|
||||
int32_t code = mndTransExecuteLogs(pMnode, pTrans->undoLogs);
|
||||
if (code != 0) {
|
||||
mError("failed to execute undoLogs since %s, return success", terrstr());
|
||||
}
|
||||
|
||||
return 0; // return success in any case
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteCommitLogs(SMnode *pMnode, STrans *pTrans) {
|
||||
return mndTransExecuteLogs(pMnode, pTrans->commitLogs);
|
||||
int32_t code = mndTransExecuteLogs(pMnode, pTrans->commitLogs);
|
||||
if (code != 0) {
|
||||
mError("failed to execute commitLogs since %s", terrstr());
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static void mndTransResetActions(SMnode *pMnode, STrans *pTrans, SArray *pArray) {
|
||||
|
@ -983,6 +997,12 @@ static int32_t mndTransSendActionMsg(SMnode *pMnode, STrans *pTrans, SArray *pAr
|
|||
pAction->msgReceived = 0;
|
||||
pAction->errCode = 0;
|
||||
} else {
|
||||
pAction->msgSent = 0;
|
||||
pAction->msgReceived = 0;
|
||||
pAction->errCode = terrno;
|
||||
if (terrno == TSDB_CODE_INVALID_PTR || terrno == TSDB_CODE_NODE_OFFLINE) {
|
||||
rpcFreeCont(rpcMsg.pCont);
|
||||
}
|
||||
mError("trans:%d, action:%d not send since %s", pTrans->id, action, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -1029,11 +1049,19 @@ static int32_t mndTransExecuteActions(SMnode *pMnode, STrans *pTrans, SArray *pA
|
|||
}
|
||||
|
||||
static int32_t mndTransExecuteRedoActions(SMnode *pMnode, STrans *pTrans) {
|
||||
return mndTransExecuteActions(pMnode, pTrans, pTrans->redoActions);
|
||||
int32_t code = mndTransExecuteActions(pMnode, pTrans, pTrans->redoActions);
|
||||
if (code != 0) {
|
||||
mError("failed to execute redoActions since %s", terrstr());
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndTransExecuteUndoActions(SMnode *pMnode, STrans *pTrans) {
|
||||
return mndTransExecuteActions(pMnode, pTrans, pTrans->undoActions);
|
||||
int32_t code = mndTransExecuteActions(pMnode, pTrans, pTrans->undoActions);
|
||||
if (code != 0) {
|
||||
mError("failed to execute undoActions since %s", terrstr());
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool mndTransPerformPrepareStage(SMnode *pMnode, STrans *pTrans) {
|
||||
|
@ -1252,7 +1280,7 @@ static int32_t mndProcessTransReq(SNodeMsg *pReq) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) {
|
||||
int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) {
|
||||
SArray *pArray = NULL;
|
||||
if (pTrans->stage == TRN_STAGE_REDO_ACTION) {
|
||||
pArray = pTrans->redoActions;
|
||||
|
@ -1270,14 +1298,14 @@ static int32_t mndKillTrans(SMnode *pMnode, STrans *pTrans) {
|
|||
if (pAction == NULL) continue;
|
||||
|
||||
if (pAction->msgReceived == 0) {
|
||||
mInfo("trans:%d, action:%d set processed", pTrans->id, i);
|
||||
mInfo("trans:%d, action:%d set processed for kill msg received", pTrans->id, i);
|
||||
pAction->msgSent = 1;
|
||||
pAction->msgReceived = 1;
|
||||
pAction->errCode = 0;
|
||||
}
|
||||
|
||||
if (pAction->errCode != 0) {
|
||||
mInfo("trans:%d, action:%d set processed, errCode from %s to success", pTrans->id, i,
|
||||
mInfo("trans:%d, action:%d set processed for kill msg received, errCode from %s to success", pTrans->id, i,
|
||||
tstrerror(pAction->errCode));
|
||||
pAction->msgSent = 1;
|
||||
pAction->msgReceived = 1;
|
||||
|
|
|
@ -86,7 +86,112 @@ class MndTestTrans2 : public ::testing::Test {
|
|||
void SetUp() override {}
|
||||
void TearDown() override {}
|
||||
|
||||
int32_t CreateUser(const char *acct, const char *user) {
|
||||
int32_t CreateUserLog(const char *acct, const char *user, ETrnType type, SDbObj *pDb) {
|
||||
SUserObj userObj = {0};
|
||||
taosEncryptPass_c((uint8_t *)"taosdata", strlen("taosdata"), userObj.pass);
|
||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
|
||||
userObj.createdTime = taosGetTimestampMs();
|
||||
userObj.updateTime = userObj.createdTime;
|
||||
userObj.superUser = 1;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, type, &rpcMsg);
|
||||
SSdbRaw *pRedoRaw = mndUserActionEncode(&userObj);
|
||||
mndTransAppendRedolog(pTrans, pRedoRaw);
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY);
|
||||
|
||||
SSdbRaw *pUndoRaw = mndUserActionEncode(&userObj);
|
||||
mndTransAppendUndolog(pTrans, pUndoRaw);
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
char *param = strdup("====> test log <=====");
|
||||
mndTransSetCb(pTrans, TEST_TRANS_START_FUNC, TEST_TRANS_STOP_FUNC, param, strlen(param) + 1);
|
||||
|
||||
if (pDb != NULL) {
|
||||
mndTransSetDbInfo(pTrans, pDb);
|
||||
}
|
||||
|
||||
int32_t code = mndTransPrepare(pMnode, pTrans);
|
||||
mndTransDrop(pTrans);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t CreateUserAction(const char *acct, const char *user, bool hasUndoAction, ETrnPolicy policy, ETrnType type,
|
||||
SDbObj *pDb) {
|
||||
SUserObj userObj = {0};
|
||||
taosEncryptPass_c((uint8_t *)"taosdata", strlen("taosdata"), userObj.pass);
|
||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||
tstrncpy(userObj.acct, acct, TSDB_USER_LEN);
|
||||
userObj.createdTime = taosGetTimestampMs();
|
||||
userObj.updateTime = userObj.createdTime;
|
||||
userObj.superUser = 1;
|
||||
|
||||
SRpcMsg rpcMsg = {0};
|
||||
STrans *pTrans = mndTransCreate(pMnode, policy, type, &rpcMsg);
|
||||
SSdbRaw *pRedoRaw = mndUserActionEncode(&userObj);
|
||||
mndTransAppendRedolog(pTrans, pRedoRaw);
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY);
|
||||
|
||||
SSdbRaw *pUndoRaw = mndUserActionEncode(&userObj);
|
||||
mndTransAppendUndolog(pTrans, pUndoRaw);
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
char *param = strdup("====> test action <=====");
|
||||
mndTransSetCb(pTrans, TEST_TRANS_START_FUNC, TEST_TRANS_STOP_FUNC, param, strlen(param) + 1);
|
||||
|
||||
{
|
||||
STransAction action = {0};
|
||||
action.epSet.inUse = 0;
|
||||
action.epSet.numOfEps = 1;
|
||||
action.epSet.eps[0].port = 9040;
|
||||
strcpy(action.epSet.eps[0].fqdn, "localhost");
|
||||
|
||||
int32_t contLen = 1024;
|
||||
void *pReq = taosMemoryCalloc(1, contLen);
|
||||
strcpy((char *)pReq, "hello world redo");
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_CREATE_MNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED;
|
||||
mndTransAppendRedoAction(pTrans, &action);
|
||||
}
|
||||
|
||||
if (hasUndoAction) {
|
||||
STransAction action = {0};
|
||||
action.epSet.inUse = 0;
|
||||
action.epSet.numOfEps = 1;
|
||||
action.epSet.eps[0].port = 9040;
|
||||
strcpy(action.epSet.eps[0].fqdn, "localhost");
|
||||
|
||||
int32_t contLen = 1024;
|
||||
void *pReq = taosMemoryCalloc(1, contLen);
|
||||
strcpy((char *)pReq, "hello world undo");
|
||||
action.pCont = pReq;
|
||||
action.contLen = contLen;
|
||||
action.msgType = TDMT_DND_CREATE_MNODE;
|
||||
action.acceptableCode = TSDB_CODE_NODE_ALREADY_DEPLOYED;
|
||||
mndTransAppendUndoAction(pTrans, &action);
|
||||
}
|
||||
|
||||
{
|
||||
void *pRsp = taosMemoryCalloc(1, 256);
|
||||
strcpy((char *)pRsp, "simple rsponse");
|
||||
mndTransSetRpcRsp(pTrans, pRsp, 256);
|
||||
}
|
||||
|
||||
if (pDb != NULL) {
|
||||
mndTransSetDbInfo(pTrans, pDb);
|
||||
}
|
||||
|
||||
int32_t code = mndTransPrepare(pMnode, pTrans);
|
||||
mndTransDrop(pTrans);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
int32_t CreateUserGlobal(const char *acct, const char *user) {
|
||||
SUserObj userObj = {0};
|
||||
taosEncryptPass_c((uint8_t *)"taosdata", strlen("taosdata"), userObj.pass);
|
||||
tstrncpy(userObj.user, user, TSDB_USER_LEN);
|
||||
|
@ -101,7 +206,11 @@ class MndTestTrans2 : public ::testing::Test {
|
|||
mndTransAppendRedolog(pTrans, pRedoRaw);
|
||||
sdbSetRawStatus(pRedoRaw, SDB_STATUS_READY);
|
||||
|
||||
char *param = strdup("====> test param <=====");
|
||||
SSdbRaw *pUndoRaw = mndUserActionEncode(&userObj);
|
||||
mndTransAppendUndolog(pTrans, pUndoRaw);
|
||||
sdbSetRawStatus(pUndoRaw, SDB_STATUS_DROPPED);
|
||||
|
||||
char *param = strdup("====> test log <=====");
|
||||
mndTransSetCb(pTrans, TEST_TRANS_START_FUNC, TEST_TRANS_STOP_FUNC, param, strlen(param) + 1);
|
||||
|
||||
int32_t code = mndTransPrepare(pMnode, pTrans);
|
||||
|
@ -113,25 +222,292 @@ class MndTestTrans2 : public ::testing::Test {
|
|||
|
||||
SMnode *MndTestTrans2::pMnode;
|
||||
|
||||
TEST_F(MndTestTrans2, 01_CbFunc) {
|
||||
TEST_F(MndTestTrans2, 01_Log) {
|
||||
const char *acct = "root";
|
||||
const char *acct_invalid = "root1";
|
||||
const char *user1 = "test1";
|
||||
const char *user2 = "test2";
|
||||
const char *user1 = "log1";
|
||||
const char *user2 = "log2";
|
||||
SUserObj *pUser1 = NULL;
|
||||
SUserObj *pUser2 = NULL;
|
||||
|
||||
ASSERT_NE(pMnode, nullptr);
|
||||
|
||||
// create user success
|
||||
EXPECT_EQ(CreateUser(acct, user1), 0);
|
||||
EXPECT_EQ(CreateUserLog(acct, user1, TRN_TYPE_CREATE_USER, NULL), 0);
|
||||
pUser1 = mndAcquireUser(pMnode, user1);
|
||||
ASSERT_NE(pUser1, nullptr);
|
||||
|
||||
// failed to create user and rollback
|
||||
EXPECT_EQ(CreateUser(acct_invalid, user2), 0);
|
||||
EXPECT_EQ(CreateUserLog(acct_invalid, user2, TRN_TYPE_CREATE_USER, NULL), 0);
|
||||
pUser2 = mndAcquireUser(pMnode, user2);
|
||||
ASSERT_EQ(pUser2, nullptr);
|
||||
|
||||
mndTransPullup(pMnode);
|
||||
}
|
||||
|
||||
TEST_F(MndTestTrans2, 02_Action) {
|
||||
const char *acct = "root";
|
||||
const char *acct_invalid = "root1";
|
||||
const char *user1 = "action1";
|
||||
const char *user2 = "action2";
|
||||
SUserObj *pUser1 = NULL;
|
||||
SUserObj *pUser2 = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
int32_t transId = 0;
|
||||
int32_t action = 0;
|
||||
|
||||
ASSERT_NE(pMnode, nullptr);
|
||||
|
||||
{
|
||||
// failed to create user and rollback
|
||||
EXPECT_EQ(CreateUserAction(acct, user1, false, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_USER, NULL), 0);
|
||||
pUser1 = mndAcquireUser(pMnode, user1);
|
||||
ASSERT_EQ(pUser1, nullptr);
|
||||
mndReleaseUser(pMnode, pUser1);
|
||||
|
||||
// create user, and fake a response
|
||||
{
|
||||
EXPECT_EQ(CreateUserAction(acct, user1, true, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_USER, NULL), 0);
|
||||
pUser1 = mndAcquireUser(pMnode, user1);
|
||||
ASSERT_NE(pUser1, nullptr);
|
||||
mndReleaseUser(pMnode, pUser1);
|
||||
|
||||
transId = 4;
|
||||
pTrans = mndAcquireTrans(pMnode, transId);
|
||||
EXPECT_EQ(pTrans->code, TSDB_CODE_INVALID_PTR);
|
||||
EXPECT_EQ(pTrans->stage, TRN_STAGE_UNDO_ACTION);
|
||||
EXPECT_EQ(pTrans->failedTimes, 1);
|
||||
|
||||
STransAction *pAction = (STransAction *)taosArrayGet(pTrans->undoActions, action);
|
||||
pAction->msgSent = 1;
|
||||
|
||||
SNodeMsg rspMsg = {0};
|
||||
rspMsg.pNode = pMnode;
|
||||
int64_t signature = transId;
|
||||
signature = (signature << 32);
|
||||
signature += action;
|
||||
rspMsg.rpcMsg.ahandle = (void *)signature;
|
||||
mndTransProcessRsp(&rspMsg);
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
|
||||
pUser1 = mndAcquireUser(pMnode, user1);
|
||||
ASSERT_EQ(pUser1, nullptr);
|
||||
mndReleaseUser(pMnode, pUser1);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
EXPECT_EQ(CreateUserAction(acct, user1, false, TRN_POLICY_RETRY, TRN_TYPE_CREATE_USER, NULL), 0);
|
||||
pUser1 = mndAcquireUser(pMnode, user1);
|
||||
ASSERT_NE(pUser1, nullptr);
|
||||
mndReleaseUser(pMnode, pUser1);
|
||||
|
||||
{
|
||||
transId = 5;
|
||||
pTrans = mndAcquireTrans(pMnode, transId);
|
||||
EXPECT_EQ(pTrans->code, TSDB_CODE_INVALID_PTR);
|
||||
EXPECT_EQ(pTrans->stage, TRN_STAGE_REDO_ACTION);
|
||||
EXPECT_EQ(pTrans->failedTimes, 1);
|
||||
|
||||
STransAction *pAction = (STransAction *)taosArrayGet(pTrans->redoActions, action);
|
||||
pAction->msgSent = 1;
|
||||
|
||||
SNodeMsg rspMsg = {0};
|
||||
rspMsg.pNode = pMnode;
|
||||
int64_t signature = transId;
|
||||
signature = (signature << 32);
|
||||
signature += action;
|
||||
rspMsg.rpcMsg.ahandle = (void *)signature;
|
||||
rspMsg.rpcMsg.code = TSDB_CODE_RPC_NETWORK_UNAVAIL;
|
||||
mndTransProcessRsp(&rspMsg);
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
|
||||
pUser1 = mndAcquireUser(pMnode, user1);
|
||||
ASSERT_NE(pUser1, nullptr);
|
||||
mndReleaseUser(pMnode, pUser1);
|
||||
}
|
||||
|
||||
{
|
||||
transId = 5;
|
||||
pTrans = mndAcquireTrans(pMnode, transId);
|
||||
EXPECT_EQ(pTrans->code, TSDB_CODE_RPC_NETWORK_UNAVAIL);
|
||||
EXPECT_EQ(pTrans->stage, TRN_STAGE_REDO_ACTION);
|
||||
EXPECT_EQ(pTrans->failedTimes, 2);
|
||||
|
||||
STransAction *pAction = (STransAction *)taosArrayGet(pTrans->redoActions, action);
|
||||
pAction->msgSent = 1;
|
||||
|
||||
SNodeMsg rspMsg = {0};
|
||||
rspMsg.pNode = pMnode;
|
||||
int64_t signature = transId;
|
||||
signature = (signature << 32);
|
||||
signature += action;
|
||||
rspMsg.rpcMsg.ahandle = (void *)signature;
|
||||
mndTransProcessRsp(&rspMsg);
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
|
||||
pUser1 = mndAcquireUser(pMnode, user1);
|
||||
ASSERT_NE(pUser1, nullptr);
|
||||
mndReleaseUser(pMnode, pUser1);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
EXPECT_EQ(CreateUserAction(acct, user2, true, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_USER, NULL), 0);
|
||||
SUserObj *pUser2 = (SUserObj *)sdbAcquire(pMnode->pSdb, SDB_USER, user2);
|
||||
ASSERT_NE(pUser2, nullptr);
|
||||
mndReleaseUser(pMnode, pUser2);
|
||||
|
||||
{
|
||||
transId = 6;
|
||||
pTrans = mndAcquireTrans(pMnode, transId);
|
||||
EXPECT_EQ(pTrans->code, TSDB_CODE_INVALID_PTR);
|
||||
EXPECT_EQ(pTrans->stage, TRN_STAGE_UNDO_ACTION);
|
||||
EXPECT_EQ(pTrans->failedTimes, 1);
|
||||
|
||||
SNodeMsg rspMsg = {0};
|
||||
rspMsg.pNode = pMnode;
|
||||
int64_t signature = transId;
|
||||
signature = (signature << 32);
|
||||
signature += action;
|
||||
rspMsg.rpcMsg.ahandle = (void *)signature;
|
||||
rspMsg.rpcMsg.code = 0;
|
||||
mndTransProcessRsp(&rspMsg);
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
|
||||
pUser2 = mndAcquireUser(pMnode, user2);
|
||||
ASSERT_NE(pUser2, nullptr);
|
||||
mndReleaseUser(pMnode, pUser2);
|
||||
}
|
||||
|
||||
{
|
||||
transId = 6;
|
||||
pTrans = mndAcquireTrans(pMnode, transId);
|
||||
EXPECT_EQ(pTrans->code, TSDB_CODE_INVALID_PTR);
|
||||
EXPECT_EQ(pTrans->stage, TRN_STAGE_UNDO_ACTION);
|
||||
EXPECT_EQ(pTrans->failedTimes, 2);
|
||||
|
||||
STransAction *pAction = (STransAction *)taosArrayGet(pTrans->undoActions, action);
|
||||
pAction->msgSent = 1;
|
||||
|
||||
SNodeMsg rspMsg = {0};
|
||||
rspMsg.pNode = pMnode;
|
||||
int64_t signature = transId;
|
||||
signature = (signature << 32);
|
||||
signature += action;
|
||||
rspMsg.rpcMsg.ahandle = (void *)signature;
|
||||
mndTransProcessRsp(&rspMsg);
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
|
||||
pUser2 = mndAcquireUser(pMnode, user2);
|
||||
ASSERT_EQ(pUser2, nullptr);
|
||||
mndReleaseUser(pMnode, pUser2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestTrans2, 03_Kill) {
|
||||
const char *acct = "root";
|
||||
const char *user1 = "kill1";
|
||||
const char *user2 = "kill2";
|
||||
SUserObj *pUser1 = NULL;
|
||||
SUserObj *pUser2 = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
int32_t transId = 0;
|
||||
int32_t action = 0;
|
||||
|
||||
ASSERT_NE(pMnode, nullptr);
|
||||
|
||||
{
|
||||
EXPECT_EQ(CreateUserAction(acct, user1, true, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_USER, NULL), 0);
|
||||
pUser1 = mndAcquireUser(pMnode, user1);
|
||||
ASSERT_NE(pUser1, nullptr);
|
||||
mndReleaseUser(pMnode, pUser1);
|
||||
|
||||
transId = 7;
|
||||
pTrans = mndAcquireTrans(pMnode, transId);
|
||||
EXPECT_EQ(pTrans->code, TSDB_CODE_INVALID_PTR);
|
||||
EXPECT_EQ(pTrans->stage, TRN_STAGE_UNDO_ACTION);
|
||||
EXPECT_EQ(pTrans->failedTimes, 1);
|
||||
|
||||
mndKillTrans(pMnode, pTrans);
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
|
||||
pUser1 = mndAcquireUser(pMnode, user1);
|
||||
ASSERT_EQ(pUser1, nullptr);
|
||||
mndReleaseUser(pMnode, pUser1);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_F(MndTestTrans2, 04_Conflict) {
|
||||
const char *acct = "root";
|
||||
const char *user1 = "conflict1";
|
||||
const char *user2 = "conflict2";
|
||||
const char *user3 = "conflict3";
|
||||
const char *user4 = "conflict4";
|
||||
const char *user5 = "conflict5";
|
||||
const char *user6 = "conflict6";
|
||||
const char *user7 = "conflict7";
|
||||
const char *user8 = "conflict8";
|
||||
SUserObj *pUser = NULL;
|
||||
STrans *pTrans = NULL;
|
||||
int32_t transId = 0;
|
||||
int32_t code = 0;
|
||||
|
||||
ASSERT_NE(pMnode, nullptr);
|
||||
|
||||
{
|
||||
SDbObj dbObj1 = {0};
|
||||
dbObj1.uid = 9521;
|
||||
strcpy(dbObj1.name, "db");
|
||||
SDbObj dbObj2 = {0};
|
||||
dbObj2.uid = 9522;
|
||||
strcpy(dbObj2.name, "conflict db");
|
||||
|
||||
EXPECT_EQ(CreateUserAction(acct, user1, true, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_STB, &dbObj1), 0);
|
||||
pUser = mndAcquireUser(pMnode, user1);
|
||||
ASSERT_NE(pUser, nullptr);
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
|
||||
transId = 8;
|
||||
pTrans = mndAcquireTrans(pMnode, transId);
|
||||
EXPECT_EQ(pTrans->code, TSDB_CODE_INVALID_PTR);
|
||||
EXPECT_EQ(pTrans->stage, TRN_STAGE_UNDO_ACTION);
|
||||
|
||||
// stb scope
|
||||
EXPECT_EQ(CreateUserLog(acct, user2, TRN_TYPE_CREATE_DNODE, NULL), -1);
|
||||
code = terrno;
|
||||
EXPECT_EQ(code, TSDB_CODE_MND_TRANS_CONFLICT);
|
||||
|
||||
EXPECT_EQ(CreateUserLog(acct, user2, TRN_TYPE_CREATE_DB, &dbObj1), -1);
|
||||
EXPECT_EQ(CreateUserLog(acct, user2, TRN_TYPE_CREATE_DB, &dbObj2), 0);
|
||||
EXPECT_EQ(CreateUserLog(acct, user3, TRN_TYPE_CREATE_STB, &dbObj1), 0);
|
||||
|
||||
// db scope
|
||||
pTrans->type = TRN_TYPE_CREATE_DB;
|
||||
EXPECT_EQ(CreateUserLog(acct, user4, TRN_TYPE_CREATE_DNODE, NULL), -1);
|
||||
EXPECT_EQ(CreateUserLog(acct, user4, TRN_TYPE_CREATE_DB, &dbObj1), -1);
|
||||
EXPECT_EQ(CreateUserLog(acct, user4, TRN_TYPE_CREATE_DB, &dbObj2), 0);
|
||||
EXPECT_EQ(CreateUserLog(acct, user5, TRN_TYPE_CREATE_STB, &dbObj1), -1);
|
||||
EXPECT_EQ(CreateUserLog(acct, user5, TRN_TYPE_CREATE_STB, &dbObj2), 0);
|
||||
|
||||
// global scope
|
||||
pTrans->type = TRN_TYPE_CREATE_DNODE;
|
||||
EXPECT_EQ(CreateUserLog(acct, user6, TRN_TYPE_CREATE_DNODE, NULL), 0);
|
||||
EXPECT_EQ(CreateUserLog(acct, user7, TRN_TYPE_CREATE_DB, &dbObj1), -1);
|
||||
EXPECT_EQ(CreateUserLog(acct, user7, TRN_TYPE_CREATE_DB, &dbObj2), -1);
|
||||
EXPECT_EQ(CreateUserLog(acct, user7, TRN_TYPE_CREATE_STB, &dbObj1), -1);
|
||||
EXPECT_EQ(CreateUserLog(acct, user7, TRN_TYPE_CREATE_STB, &dbObj2), -1);
|
||||
|
||||
// global scope
|
||||
pTrans->type = TRN_TYPE_CREATE_USER;
|
||||
EXPECT_EQ(CreateUserLog(acct, user7, TRN_TYPE_CREATE_DB, &dbObj1), 0);
|
||||
EXPECT_EQ(CreateUserLog(acct, user8, TRN_TYPE_CREATE_DB, &dbObj2), 0);
|
||||
|
||||
mndKillTrans(pMnode, pTrans);
|
||||
mndReleaseTrans(pMnode, pTrans);
|
||||
|
||||
pUser = mndAcquireUser(pMnode, user1);
|
||||
ASSERT_EQ(pUser, nullptr);
|
||||
mndReleaseUser(pMnode, pUser);
|
||||
}
|
||||
}
|
|
@ -30,6 +30,7 @@ target_sources(
|
|||
"src/tsdb/tsdbFS.c"
|
||||
"src/tsdb/tsdbOpen.c"
|
||||
"src/tsdb/tsdbMemTable.c"
|
||||
"src/tsdb/tsdbMemTable2.c"
|
||||
"src/tsdb/tsdbRead.c"
|
||||
"src/tsdb/tsdbReadImpl.c"
|
||||
"src/tsdb/tsdbSma.c"
|
||||
|
|
|
@ -103,8 +103,6 @@ typedef struct {
|
|||
|
||||
#if 1
|
||||
|
||||
// int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg, STbDdlH* pHandle);
|
||||
int metaDropTable(SMeta* pMeta, tb_uid_t uid);
|
||||
SMSmaCursor* metaOpenSmaCursor(SMeta* pMeta, tb_uid_t uid);
|
||||
void metaCloseSmaCursor(SMSmaCursor* pSmaCur);
|
||||
int64_t metaSmaCursorNext(SMSmaCursor* pSmaCur);
|
||||
|
|
|
@ -40,7 +40,6 @@ typedef struct STable STable;
|
|||
|
||||
int tsdbMemTableCreate(STsdb *pTsdb, STsdbMemTable **ppMemTable);
|
||||
void tsdbMemTableDestroy(STsdb *pTsdb, STsdbMemTable *pMemTable);
|
||||
int tsdbInsertTableData(STsdb *pTsdb, SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, int32_t *pAffectedRows);
|
||||
int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey, int maxRowsToRead, SDataCols *pCols,
|
||||
TKEY *filterKeys, int nFilterKeys, bool keepDup, SMergeInfo *pMergeInfo);
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ int metaCommit(SMeta* pMeta);
|
|||
int metaCreateSTable(SMeta* pMeta, int64_t version, SVCreateStbReq* pReq);
|
||||
int metaDropSTable(SMeta* pMeta, int64_t verison, SVDropStbReq* pReq);
|
||||
int metaCreateTable(SMeta* pMeta, int64_t version, SVCreateTbReq* pReq);
|
||||
int metaDropTable(SMeta* pMeta, int64_t version, SVDropTbReq* pReq);
|
||||
SSchemaWrapper* metaGetTableSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver, bool isinline);
|
||||
STSchema* metaGetTbTSchema(SMeta* pMeta, tb_uid_t uid, int32_t sver);
|
||||
int metaGetTableEntryByName(SMetaReader* pReader, const char* name);
|
||||
|
@ -99,6 +100,7 @@ int32_t tsdbUpdateSmaWindow(STsdb* pTsdb, SSubmitReq* pMsg, int64_t version
|
|||
int32_t tsdbCreateTSma(STsdb* pTsdb, char* pMsg);
|
||||
int32_t tsdbInsertTSmaData(STsdb* pTsdb, int64_t indexUid, const char* msg);
|
||||
int tsdbInsertData(STsdb* pTsdb, int64_t version, SSubmitReq* pMsg, SSubmitRsp* pRsp);
|
||||
int tsdbInsertTableData(STsdb* pTsdb, SSubmitMsgIter* pMsgIter, SSubmitBlk* pBlock, int32_t* pAffectedRows);
|
||||
tsdbReaderT* tsdbQueryTables(SVnode* pVnode, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId,
|
||||
uint64_t taskId);
|
||||
tsdbReaderT tsdbQueryCacheLastT(STsdb* tsdb, SQueryTableDataCond* pCond, STableGroupInfo* groupList, uint64_t qId,
|
||||
|
@ -124,7 +126,6 @@ int32_t tsdbUpdateTbUidList(STsdb* pTsdb, STbUidStore* pUidStore);
|
|||
void tsdbUidStoreDestory(STbUidStore* pStore);
|
||||
void* tsdbUidStoreFree(STbUidStore* pStore);
|
||||
int32_t tsdbTriggerRSma(STsdb* pTsdb, void* pMsg, int32_t inputType);
|
||||
int32_t tsdbProcessSubmitReq(STsdb* pTsdb, int64_t version, void* pReq);
|
||||
|
||||
typedef struct {
|
||||
int8_t streamType; // sma or other
|
||||
|
@ -189,7 +190,6 @@ struct STbUidStore {
|
|||
|
||||
#define TD_VID(PVNODE) (PVNODE)->config.vgId
|
||||
|
||||
|
||||
static FORCE_INLINE bool vnodeIsRollup(SVnode* pVnode) {
|
||||
SRetention* pRetention = &(pVnode->config.tsdbCfg.retentions[0]);
|
||||
return (pRetention->freq > 0 && pRetention->keep > 0);
|
||||
|
|
|
@ -289,7 +289,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
|||
pVal = pBuf = buf;
|
||||
metaEncodeTbInfo(&pBuf, pTbCfg);
|
||||
vLen = POINTER_DISTANCE(pBuf, buf);
|
||||
ret = tdbDbPut(pMetaDb->pTbDB, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
ret = tdbDbInsert(pMetaDb->pTbDB, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
|||
pVal = pBuf = buf;
|
||||
metaEncodeSchemaEx(&pBuf, &schemaWrapper);
|
||||
vLen = POINTER_DISTANCE(pBuf, buf);
|
||||
ret = tdbDbPut(pMetaDb->pSchemaDB, pKey, kLen, pVal, vLen, &pMeta->pDB->txn);
|
||||
ret = tdbDbInsert(pMetaDb->pSchemaDB, pKey, kLen, pVal, vLen, &pMeta->pDB->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -325,7 +325,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
|||
kLen = nameLen + 1 + sizeof(uid);
|
||||
pVal = NULL;
|
||||
vLen = 0;
|
||||
ret = tdbDbPut(pMetaDb->pNameIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
ret = tdbDbInsert(pMetaDb->pNameIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -336,7 +336,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
|||
kLen = sizeof(uid);
|
||||
pVal = NULL;
|
||||
vLen = 0;
|
||||
ret = tdbDbPut(pMetaDb->pStbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
ret = tdbDbInsert(pMetaDb->pStbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -347,7 +347,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
|||
kLen = sizeof(ctbIdxKey);
|
||||
pVal = NULL;
|
||||
vLen = 0;
|
||||
ret = tdbDbPut(pMetaDb->pCtbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
ret = tdbDbInsert(pMetaDb->pCtbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -362,7 +362,7 @@ int metaSaveTableToDB(SMeta *pMeta, STbCfg *pTbCfg, STbDdlH *pHandle) {
|
|||
kLen = sizeof(uid);
|
||||
pVal = NULL;
|
||||
vLen = 0;
|
||||
ret = tdbDbPut(pMetaDb->pNtbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
ret = tdbDbInsert(pMetaDb->pNtbIdx, pKey, kLen, pVal, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
@ -530,7 +530,7 @@ int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) {
|
|||
int32_t kLen = sizeof(pSmaCfg->indexUid);
|
||||
int32_t vLen = POINTER_DISTANCE(qBuf, pBuf);
|
||||
|
||||
ret = tdbDbPut(pMeta->pDB->pSmaDB, key, kLen, val, vLen, &pMetaDb->txn);
|
||||
ret = tdbDbInsert(pMeta->pDB->pSmaDB, key, kLen, val, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
taosMemoryFreeClear(pBuf);
|
||||
return -1;
|
||||
|
@ -545,7 +545,7 @@ int metaSaveSmaToDB(SMeta *pMeta, STSma *pSmaCfg) {
|
|||
val = NULL;
|
||||
vLen = 0;
|
||||
|
||||
ret = tdbDbPut(pMeta->pDB->pSmaIdx, key, kLen, val, vLen, &pMetaDb->txn);
|
||||
ret = tdbDbInsert(pMeta->pDB->pSmaIdx, key, kLen, val, vLen, &pMetaDb->txn);
|
||||
if (ret < 0) {
|
||||
taosMemoryFreeClear(pBuf);
|
||||
return -1;
|
||||
|
|
|
@ -72,44 +72,61 @@ _err:
|
|||
}
|
||||
|
||||
int metaDropSTable(SMeta *pMeta, int64_t verison, SVDropStbReq *pReq) {
|
||||
SMetaReader mr = {0};
|
||||
TDBC *pNameIdxc = NULL;
|
||||
TDBC *pUidIdxc = NULL;
|
||||
TDBC *pCtbIdxc = NULL;
|
||||
SCtbIdxKey *pCtbIdxKey;
|
||||
const void *pKey = NULL;
|
||||
int nKey;
|
||||
const void *pData = NULL;
|
||||
int nData;
|
||||
int c, ret;
|
||||
|
||||
// validate req
|
||||
metaReaderInit(&mr, pMeta, 0);
|
||||
if (metaGetTableEntryByUid(&mr, pReq->suid) < 0) {
|
||||
terrno = TSDB_CODE_VND_TABLE_NOT_EXIST;
|
||||
// prepare uid idx cursor
|
||||
tdbDbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn);
|
||||
ret = tdbDbcMoveTo(pUidIdxc, &pReq->suid, sizeof(tb_uid_t), &c);
|
||||
if (ret < 0 || c != 0) {
|
||||
terrno = TSDB_CODE_VND_TB_NOT_EXIST;
|
||||
tdbDbcClose(pUidIdxc);
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// do drop
|
||||
// drop from pTbDb
|
||||
// drop from pSkmDb
|
||||
// drop from pUidIdx
|
||||
// drop from pNameIdx
|
||||
// {
|
||||
// TDBC *pDbc1 = NULL;
|
||||
// void *pKey = NULL;
|
||||
// void *pVal = NULL;
|
||||
// int kLen = 0;
|
||||
// int vLen = 0;
|
||||
// int ret = 0;
|
||||
// prepare name idx cursor
|
||||
tdbDbcOpen(pMeta->pNameIdx, &pNameIdxc, &pMeta->txn);
|
||||
ret = tdbDbcMoveTo(pNameIdxc, pReq->name, strlen(pReq->name) + 1, &c);
|
||||
if (ret < 0 || c != 0) {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
// // drop from pCtbIdx
|
||||
// ret = tdbDbcOpen(pMeta->pCtbIdx, &pDbc1);
|
||||
// tdbDbcMoveTo(pDbc1, &pReq->suid, sizeof(pReq->suid), NULL /*cmpr*/, 0 /*TDB_FORWARD_SEARCH*/);
|
||||
// tdbDbcGet(pDbc1, &pKey, &kLen, &pVal, vLen);
|
||||
// tdbDbcDrop(pDbc1);
|
||||
// // drop from pTagIdx
|
||||
// // drop from pTtlIdx
|
||||
// }
|
||||
tdbDbcDelete(pUidIdxc);
|
||||
tdbDbcDelete(pNameIdxc);
|
||||
tdbDbcClose(pUidIdxc);
|
||||
tdbDbcClose(pNameIdxc);
|
||||
|
||||
// clear and return
|
||||
metaReaderClear(&mr);
|
||||
metaError("vgId:%d super table %s uid:%" PRId64 " is dropped", TD_VID(pMeta->pVnode), pReq->name, pReq->suid);
|
||||
// loop to drop each child table
|
||||
tdbDbcOpen(pMeta->pCtbIdx, &pCtbIdxc, &pMeta->txn);
|
||||
ret = tdbDbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = pReq->suid, .uid = INT64_MIN}, sizeof(SCtbIdxKey), &c);
|
||||
if (ret < 0 || (c < 0 && tdbDbcMoveToNext(pCtbIdxc) < 0)) {
|
||||
tdbDbcClose(pCtbIdxc);
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
tdbDbcGet(pCtbIdxc, &pKey, &nKey, NULL, NULL);
|
||||
pCtbIdxKey = (SCtbIdxKey *)pKey;
|
||||
|
||||
if (pCtbIdxKey->suid > pReq->suid) break;
|
||||
|
||||
// drop the child table (TODO)
|
||||
|
||||
if (tdbDbcMoveToNext(pCtbIdxc) < 0) break;
|
||||
}
|
||||
|
||||
_exit:
|
||||
metaDebug("vgId:%d super table %s uid:%" PRId64 " is dropped", TD_VID(pMeta->pVnode), pReq->name, pReq->suid);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
metaReaderClear(&mr);
|
||||
metaError("vgId:%d failed to drop super table %s uid:%" PRId64 " since %s", TD_VID(pMeta->pVnode), pReq->name,
|
||||
pReq->suid, tstrerror(terrno));
|
||||
return -1;
|
||||
|
@ -166,18 +183,122 @@ _err:
|
|||
return -1;
|
||||
}
|
||||
|
||||
int metaDropTable(SMeta *pMeta, tb_uid_t uid) {
|
||||
#if 0
|
||||
if (metaRemoveTableFromIdx(pMeta, uid) < 0) {
|
||||
// TODO: handle error
|
||||
int metaDropTable(SMeta *pMeta, int64_t version, SVDropTbReq *pReq) {
|
||||
TDBC *pTbDbc = NULL;
|
||||
TDBC *pUidIdxc = NULL;
|
||||
TDBC *pNameIdxc = NULL;
|
||||
const void *pData;
|
||||
int nData;
|
||||
tb_uid_t uid;
|
||||
int64_t tver;
|
||||
SMetaEntry me = {0};
|
||||
SCoder coder = {0};
|
||||
int8_t type;
|
||||
int64_t ctime;
|
||||
tb_uid_t suid;
|
||||
int c, ret;
|
||||
|
||||
// search & delete the name idx
|
||||
tdbDbcOpen(pMeta->pNameIdx, &pNameIdxc, &pMeta->txn);
|
||||
ret = tdbDbcMoveTo(pNameIdxc, pReq->name, strlen(pReq->name) + 1, &c);
|
||||
if (ret < 0 || c) {
|
||||
tdbDbcClose(pNameIdxc);
|
||||
terrno = TSDB_CODE_VND_TABLE_NOT_EXIST;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (metaRemoveTableFromIdx(pMeta, uid) < 0) {
|
||||
// TODO
|
||||
ret = tdbDbcGet(pNameIdxc, NULL, NULL, &pData, &nData);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
uid = *(tb_uid_t *)pData;
|
||||
|
||||
tdbDbcDelete(pNameIdxc);
|
||||
tdbDbcClose(pNameIdxc);
|
||||
|
||||
// search & delete uid idx
|
||||
tdbDbcOpen(pMeta->pUidIdx, &pUidIdxc, &pMeta->txn);
|
||||
ret = tdbDbcMoveTo(pUidIdxc, &uid, sizeof(uid), &c);
|
||||
if (ret < 0 || c != 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = tdbDbcGet(pUidIdxc, NULL, NULL, &pData, &nData);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tver = *(int64_t *)pData;
|
||||
tdbDbcDelete(pUidIdxc);
|
||||
tdbDbcClose(pUidIdxc);
|
||||
|
||||
// search and get meta entry
|
||||
tdbDbcOpen(pMeta->pTbDb, &pTbDbc, &pMeta->txn);
|
||||
ret = tdbDbcMoveTo(pTbDbc, &(STbDbKey){.uid = uid, .version = tver}, sizeof(STbDbKey), &c);
|
||||
if (ret < 0 || c != 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = tdbDbcGet(pTbDbc, NULL, NULL, &pData, &nData);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// decode entry
|
||||
void *pDataCopy = taosMemoryMalloc(nData); // remove the copy (todo)
|
||||
memcpy(pDataCopy, pData, nData);
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pDataCopy, nData, TD_DECODER);
|
||||
ret = metaDecodeEntry(&coder, &me);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
type = me.type;
|
||||
if (type == TSDB_CHILD_TABLE) {
|
||||
ctime = me.ctbEntry.ctime;
|
||||
suid = me.ctbEntry.suid;
|
||||
} else if (type == TSDB_NORMAL_TABLE) {
|
||||
ctime = me.ntbEntry.ctime;
|
||||
suid = 0;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
taosMemoryFree(pDataCopy);
|
||||
tCoderClear(&coder);
|
||||
tdbDbcClose(pTbDbc);
|
||||
|
||||
if (type == TSDB_CHILD_TABLE) {
|
||||
// remove the pCtbIdx
|
||||
TDBC *pCtbIdxc = NULL;
|
||||
tdbDbcOpen(pMeta->pCtbIdx, &pCtbIdxc, &pMeta->txn);
|
||||
|
||||
ret = tdbDbcMoveTo(pCtbIdxc, &(SCtbIdxKey){.suid = suid, .uid = uid}, sizeof(SCtbIdxKey), &c);
|
||||
if (ret < 0 || c != 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdbDbcDelete(pCtbIdxc);
|
||||
tdbDbcClose(pCtbIdxc);
|
||||
|
||||
// remove tags from pTagIdx (todo)
|
||||
} else if (type == TSDB_NORMAL_TABLE) {
|
||||
// remove from pSkmDb
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
// remove from ttl (todo)
|
||||
if (ctime > 0) {
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -218,7 +339,7 @@ static int metaSaveToTbDb(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
tCoderClear(&coder);
|
||||
|
||||
// write to table.db
|
||||
if (tdbDbPut(pMeta->pTbDb, pKey, kLen, pVal, vLen, &pMeta->txn) < 0) {
|
||||
if (tdbDbInsert(pMeta->pTbDb, pKey, kLen, pVal, vLen, &pMeta->txn) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
|
@ -231,11 +352,11 @@ _err:
|
|||
}
|
||||
|
||||
static int metaUpdateUidIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
return tdbDbPut(pMeta->pUidIdx, &pME->uid, sizeof(tb_uid_t), &pME->version, sizeof(int64_t), &pMeta->txn);
|
||||
return tdbDbInsert(pMeta->pUidIdx, &pME->uid, sizeof(tb_uid_t), &pME->version, sizeof(int64_t), &pMeta->txn);
|
||||
}
|
||||
|
||||
static int metaUpdateNameIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
return tdbDbPut(pMeta->pNameIdx, pME->name, strlen(pME->name) + 1, &pME->uid, sizeof(tb_uid_t), &pMeta->txn);
|
||||
return tdbDbInsert(pMeta->pNameIdx, pME->name, strlen(pME->name) + 1, &pME->uid, sizeof(tb_uid_t), &pMeta->txn);
|
||||
}
|
||||
|
||||
static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
|
@ -258,12 +379,12 @@ static int metaUpdateTtlIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
ttlKey.dtime = ctime + ttlDays * 24 * 60 * 60;
|
||||
ttlKey.uid = pME->uid;
|
||||
|
||||
return tdbDbPut(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, &pMeta->txn);
|
||||
return tdbDbInsert(pMeta->pTtlIdx, &ttlKey, sizeof(ttlKey), NULL, 0, &pMeta->txn);
|
||||
}
|
||||
|
||||
static int metaUpdateCtbIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
SCtbIdxKey ctbIdxKey = {.suid = pME->ctbEntry.suid, .uid = pME->uid};
|
||||
return tdbDbPut(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), NULL, 0, &pMeta->txn);
|
||||
return tdbDbInsert(pMeta->pCtbIdx, &ctbIdxKey, sizeof(ctbIdxKey), NULL, 0, &pMeta->txn);
|
||||
}
|
||||
|
||||
static int metaUpdateTagIdx(SMeta *pMeta, const SMetaEntry *pME) {
|
||||
|
@ -304,7 +425,7 @@ static int metaSaveToSkmDb(SMeta *pMeta, const SMetaEntry *pME) {
|
|||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pVal, vLen, TD_ENCODER);
|
||||
tEncodeSSchemaWrapper(&coder, pSW);
|
||||
|
||||
if (tdbDbPut(pMeta->pSkmDb, &skmDbKey, sizeof(skmDbKey), pVal, vLen, &pMeta->txn) < 0) {
|
||||
if (tdbDbInsert(pMeta->pSkmDb, &skmDbKey, sizeof(skmDbKey), pVal, vLen, &pMeta->txn) < 0) {
|
||||
rcode = -1;
|
||||
goto _exit;
|
||||
}
|
||||
|
|
|
@ -926,6 +926,12 @@ int32_t tqProcessTaskDeploy(STQ* pTq, char* msg, int32_t msgLen) {
|
|||
pTask->ahandle = pTq->pVnode;
|
||||
if (pTask->sinkType == TASK_SINK__SMA) {
|
||||
pTask->smaSink.smaHandle = smaHandleRes;
|
||||
} else if (pTask->sinkType == TASK_SINK__TABLE) {
|
||||
ASSERT(pTask->tbSink.pSchemaWrapper);
|
||||
ASSERT(pTask->tbSink.pSchemaWrapper->pSchema);
|
||||
pTask->tbSink.pTSchema =
|
||||
tdGetSTSChemaFromSSChema(&pTask->tbSink.pSchemaWrapper->pSchema, pTask->tbSink.pSchemaWrapper->nCols);
|
||||
ASSERT(pTask->tbSink.pTSchema);
|
||||
}
|
||||
|
||||
taosHashPut(pTq->pStreamTasks, &pTask->taskId, sizeof(int32_t), pTask, sizeof(SStreamTask));
|
||||
|
|
|
@ -69,10 +69,6 @@ static void tsdbDestroyCommitIters(SCommitH *pCommith);
|
|||
static int tsdbCommitToFile(SCommitH *pCommith, SDFileSet *pSet, int fid);
|
||||
static void tsdbResetCommitFile(SCommitH *pCommith);
|
||||
static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid);
|
||||
// static int tsdbCommitMeta(STsdbRepo *pRepo);
|
||||
// static int tsdbUpdateMetaRecord(STsdbFS *pfs, SMFile *pMFile, uint64_t uid, void *cont, int contLen, bool compact);
|
||||
// static int tsdbDropMetaRecord(STsdbFS *pfs, SMFile *pMFile, uint64_t uid);
|
||||
// static int tsdbCompactMetaFile(STsdbRepo *pRepo, STsdbFS *pfs, SMFile *pMFile);
|
||||
static int tsdbCommitToTable(SCommitH *pCommith, int tid);
|
||||
static int tsdbSetCommitTable(SCommitH *pCommith, STable *pTable);
|
||||
static int tsdbComparKeyBlock(const void *arg1, const void *arg2);
|
||||
|
|
|
@ -191,9 +191,6 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey
|
|||
}
|
||||
|
||||
int tsdbInsertTableData(STsdb *pTsdb, SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlock, int32_t *pAffectedRows) {
|
||||
// STsdbMeta *pMeta = pRepo->tsdbMeta;
|
||||
// int32_t points = 0;
|
||||
// STable *pTable = NULL;
|
||||
SSubmitBlkIter blkIter = {0};
|
||||
STsdbMemTable *pMemTable = pTsdb->mem;
|
||||
void *tptr;
|
||||
|
@ -221,8 +218,9 @@ int tsdbInsertTableData(STsdb *pTsdb, SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlo
|
|||
}
|
||||
|
||||
// copy data to buffer pool
|
||||
pBlkCopy = (SSubmitBlk *)vnodeBufPoolMalloc(pTsdb->mem->pPool, pMsgIter->dataLen + sizeof(*pBlock));
|
||||
memcpy(pBlkCopy, pBlock, pMsgIter->dataLen + sizeof(*pBlock));
|
||||
int32_t tlen = pMsgIter->dataLen + pMsgIter->schemaLen + sizeof(*pBlock);
|
||||
pBlkCopy = (SSubmitBlk *)vnodeBufPoolMalloc(pTsdb->mem->pPool, tlen);
|
||||
memcpy(pBlkCopy, pBlock, tlen);
|
||||
|
||||
tInitSubmitBlkIter(pMsgIter, pBlkCopy, &blkIter);
|
||||
if (blkIter.row == NULL) return 0;
|
||||
|
@ -241,7 +239,7 @@ int tsdbInsertTableData(STsdb *pTsdb, SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlo
|
|||
if (pMemTable->keyMin > keyMin) pMemTable->keyMin = keyMin;
|
||||
if (pMemTable->keyMax < keyMax) pMemTable->keyMax = keyMax;
|
||||
|
||||
(*pAffectedRows) += pMsgIter->numOfRows;
|
||||
(*pAffectedRows) = pMsgIter->numOfRows;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,93 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tsdb.h"
|
||||
|
||||
typedef struct SMemTable SMemTable;
|
||||
typedef struct SMemData SMemData;
|
||||
typedef struct SMemSkipList SMemSkipList;
|
||||
typedef struct SMemSkipListCfg SMemSkipListCfg;
|
||||
|
||||
struct SMemTable {
|
||||
STsdb *pTsdb;
|
||||
TSKEY minKey;
|
||||
TSKEY maxKey;
|
||||
int64_t minVer;
|
||||
int64_t maxVer;
|
||||
int64_t nRows;
|
||||
int32_t nHash;
|
||||
int32_t nBucket;
|
||||
SMemData **pBuckets;
|
||||
};
|
||||
|
||||
struct SMemSkipListCfg {
|
||||
int8_t maxLevel;
|
||||
int32_t nKey;
|
||||
int32_t nData;
|
||||
};
|
||||
|
||||
struct SMemSkipList {
|
||||
int8_t level;
|
||||
uint32_t seed;
|
||||
};
|
||||
|
||||
struct SMemData {
|
||||
SMemData *pHashNext;
|
||||
tb_uid_t suid;
|
||||
tb_uid_t uid;
|
||||
TSKEY minKey;
|
||||
TSKEY maxKey;
|
||||
int64_t minVer;
|
||||
int64_t maxVer;
|
||||
int64_t nRows;
|
||||
SMemSkipList sl;
|
||||
};
|
||||
|
||||
// SMemTable
|
||||
int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTb) {
|
||||
SMemTable *pMemTb = NULL;
|
||||
|
||||
pMemTb = taosMemoryCalloc(1, sizeof(*pMemTb));
|
||||
if (pMemTb == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pMemTb->pTsdb = pTsdb;
|
||||
pMemTb->minKey = TSKEY_MAX;
|
||||
pMemTb->maxKey = TSKEY_MIN;
|
||||
pMemTb->minVer = -1;
|
||||
pMemTb->maxVer = -1;
|
||||
pMemTb->nRows = 0;
|
||||
pMemTb->nHash = 0;
|
||||
pMemTb->nBucket = 1024;
|
||||
pMemTb->pBuckets = taosMemoryCalloc(pMemTb->nBucket, sizeof(*pMemTb->pBuckets));
|
||||
if (pMemTb->pBuckets == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
*ppMemTb = pMemTb;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tsdbMemTableDestroy2(STsdb *pTsdb, SMemTable *pMT) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
// SMemData
|
||||
|
||||
// SMemSkipList
|
|
@ -3308,7 +3308,7 @@ void tsdbRetrieveDataBlockInfo(tsdbReaderT* pTsdbReadHandle, SDataBlockInfo* pDa
|
|||
|
||||
pDataBlockInfo->rows = cur->rows;
|
||||
pDataBlockInfo->window = cur->win;
|
||||
pDataBlockInfo->numOfCols = (int32_t)(QH_GET_NUM_OF_COLS(pHandle));
|
||||
// ASSERT(pDataBlockInfo->numOfCols >= (int32_t)(QH_GET_NUM_OF_COLS(pHandle));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1962,6 +1962,21 @@ int32_t tsdbUpdateTbUidList(STsdb *pTsdb, STbUidStore *pStore) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t tsdbProcessSubmitReq(STsdb *pTsdb, int64_t version, void *pReq) {
|
||||
if (!pReq) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SSubmitReq *pSubmitReq = (SSubmitReq *)pReq;
|
||||
|
||||
if (tsdbInsertData(pTsdb, version, pSubmitReq, NULL) < 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t tsdbFetchSubmitReqSuids(SSubmitReq *pMsg, STbUidStore *pStore) {
|
||||
ASSERT(pMsg != NULL);
|
||||
SSubmitMsgIter msgIter = {0};
|
||||
|
|
|
@ -97,7 +97,7 @@ int32_t tsdbCloseDBF(SDBFile *pDBF) {
|
|||
int32_t tsdbSaveSmaToDB(SDBFile *pDBF, void *pKey, int32_t keyLen, void *pVal, int32_t valLen, TXN *txn) {
|
||||
int32_t ret;
|
||||
|
||||
ret = tdbDbPut(pDBF->pDB, pKey, keyLen, pVal, valLen, txn);
|
||||
ret = tdbDbInsert(pDBF->pDB, pKey, keyLen, pVal, valLen, txn);
|
||||
if (ret < 0) {
|
||||
tsdbError("Failed to create insert sma data into db, ret = %d", ret);
|
||||
return -1;
|
||||
|
|
|
@ -445,32 +445,102 @@ static int vnodeProcessAlterTbReq(SVnode *pVnode, void *pReq, int32_t len, SRpcM
|
|||
}
|
||||
|
||||
static int vnodeProcessDropTbReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
SVDropTbReq req = {0};
|
||||
SVDropTbReq rsp = {0};
|
||||
SVDropTbBatchReq req = {0};
|
||||
SVDropTbBatchRsp rsp = {0};
|
||||
SCoder coder = {0};
|
||||
int ret;
|
||||
|
||||
pRsp->msgType = TDMT_VND_DROP_TABLE_RSP;
|
||||
pRsp->pCont = NULL;
|
||||
pRsp->contLen = 0;
|
||||
pRsp->code = TSDB_CODE_SUCCESS;
|
||||
|
||||
// decode req
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pReq, len, TD_DECODER);
|
||||
ret = tDecodeSVDropTbBatchReq(&coder, &req);
|
||||
if (ret < 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
pRsp->code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
// process req
|
||||
rsp.pArray = taosArrayInit(sizeof(SVDropTbRsp), req.nReqs);
|
||||
for (int iReq = 0; iReq < req.nReqs; iReq++) {
|
||||
SVDropTbReq *pDropTbReq = req.pReqs + iReq;
|
||||
SVDropTbRsp dropTbRsp = {0};
|
||||
|
||||
// return rsp
|
||||
/* code */
|
||||
ret = metaDropTable(pVnode->pMeta, version, pDropTbReq);
|
||||
if (ret < 0) {
|
||||
if (pDropTbReq->igNotExists && terrno == TSDB_CODE_VND_TABLE_NOT_EXIST) {
|
||||
dropTbRsp.code = TSDB_CODE_SUCCESS;
|
||||
} else {
|
||||
dropTbRsp.code = terrno;
|
||||
}
|
||||
} else {
|
||||
dropTbRsp.code = TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
taosArrayPush(rsp.pArray, &dropTbRsp);
|
||||
}
|
||||
|
||||
_exit:
|
||||
tCoderClear(&coder);
|
||||
// encode rsp (TODO)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
SSubmitReq *pSubmitReq = (SSubmitReq *)pReq;
|
||||
SSubmitMsgIter msgIter = {0};
|
||||
SSubmitBlk *pBlock;
|
||||
SSubmitRsp rsp = {0};
|
||||
SVCreateTbReq createTbReq = {0};
|
||||
SCoder coder = {0};
|
||||
int32_t nRows;
|
||||
|
||||
pRsp->code = 0;
|
||||
|
||||
// handle the request
|
||||
if (tsdbInsertData(pVnode->pTsdb, version, pSubmitReq, &rsp) < 0) {
|
||||
pRsp->code = terrno;
|
||||
return -1;
|
||||
if (tInitSubmitMsgIter(pSubmitReq, &msgIter) < 0) {
|
||||
pRsp->code = TSDB_CODE_INVALID_MSG;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
// pRsp->msgType = TDMT_VND_SUBMIT_RSP;
|
||||
// vnodeProcessSubmitReq(pVnode, ptr, pRsp);
|
||||
for (;;) {
|
||||
tGetSubmitMsgNext(&msgIter, &pBlock);
|
||||
if (pBlock == NULL) break;
|
||||
|
||||
// create table for auto create table mode
|
||||
if (msgIter.schemaLen > 0) {
|
||||
tCoderInit(&coder, TD_LITTLE_ENDIAN, pBlock->data, msgIter.schemaLen, TD_DECODER);
|
||||
if (tDecodeSVCreateTbReq(&coder, &createTbReq) < 0) {
|
||||
pRsp->code = TSDB_CODE_INVALID_MSG;
|
||||
tCoderClear(&coder);
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
if (metaCreateTable(pVnode->pMeta, version, &createTbReq) < 0) {
|
||||
if (terrno != TSDB_CODE_TDB_TABLE_ALREADY_EXIST) {
|
||||
pRsp->code = terrno;
|
||||
tCoderClear(&coder);
|
||||
goto _exit;
|
||||
}
|
||||
}
|
||||
|
||||
tCoderClear(&coder);
|
||||
}
|
||||
|
||||
if (tsdbInsertTableData(pVnode->pTsdb, &msgIter, pBlock, &nRows) < 0) {
|
||||
pRsp->code = terrno;
|
||||
goto _exit;
|
||||
}
|
||||
|
||||
rsp.numOfRows += nRows;
|
||||
}
|
||||
|
||||
_exit:
|
||||
// encode the response (TODO)
|
||||
pRsp->pCont = rpcMallocCont(sizeof(SSubmitRsp));
|
||||
memcpy(pRsp->pCont, &rsp, sizeof(rsp));
|
||||
|
@ -480,18 +550,3 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, in
|
|||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tsdbProcessSubmitReq(STsdb *pTsdb, int64_t version, void *pReq) {
|
||||
if(!pReq) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SSubmitReq *pSubmitReq = (SSubmitReq *)pReq;
|
||||
|
||||
if (tsdbInsertData(pTsdb, version, pSubmitReq, NULL) < 0) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
|
@ -277,7 +277,7 @@ typedef struct SOperatorInfo {
|
|||
uint8_t operatorType;
|
||||
bool blocking; // block operator or not
|
||||
uint8_t status; // denote if current operator is completed
|
||||
int32_t numOfOutput; // number of columns of the current operator results
|
||||
int32_t numOfExprs; // number of columns of the current operator results
|
||||
char* name; // name, used to show the query execution plan
|
||||
void* info; // extension attribution
|
||||
SExprInfo* pExpr;
|
||||
|
@ -415,8 +415,6 @@ typedef struct SOptrBasicInfo {
|
|||
// TODO move the resultrowsiz together with SOptrBasicInfo:rowCellInfoOffset
|
||||
typedef struct SAggSupporter {
|
||||
SHashObj* pResultRowHashTable; // quick locate the window object for each result
|
||||
// SHashObj* pResultRowListSet; // used to check if current ResultRowInfo has ResultRow object or not
|
||||
// SArray* pResultRowArrayList; // The array list that contains the Result rows
|
||||
char* keyBuf; // window key buffer
|
||||
SDiskbasedBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
||||
int32_t resultRowSize; // the result buffer size for each result row, with the meta data size for each row
|
||||
|
@ -577,13 +575,13 @@ typedef struct SSortedMergeOperatorInfo {
|
|||
} SSortedMergeOperatorInfo;
|
||||
|
||||
typedef struct SSortOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
uint32_t sortBufSize; // max buffer size for in-memory sort
|
||||
SSDataBlock* pDataBlock;
|
||||
SArray* pSortInfo;
|
||||
SSortHandle* pSortHandle;
|
||||
SArray* inputSlotMap; // for index map from table scan output
|
||||
int32_t bufPageSize;
|
||||
int32_t numOfRowsInRes;
|
||||
// int32_t numOfRowsInRes;
|
||||
|
||||
// TODO extact struct
|
||||
int64_t startTs; // sort start time
|
||||
|
@ -646,9 +644,12 @@ void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SAr
|
|||
void initExecTimeWindowInfo(SColumnInfoData* pColData, STimeWindow* pQueryWindow);
|
||||
void cleanupAggSup(SAggSupporter* pAggSup);
|
||||
void destroyBasicOperatorInfo(void* param, int32_t numOfOutput);
|
||||
void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle);
|
||||
|
||||
void setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput,
|
||||
int32_t* rowCellInfoOffset);
|
||||
SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity);
|
||||
SSDataBlock* loadNextDataBlock(void* param);
|
||||
|
||||
void setResultRowInitCtx(SResultRow* pResult, SqlFunctionCtx* pCtx, int32_t numOfOutput, int32_t* rowCellInfoOffset);
|
||||
|
||||
SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pResultRowInfo,
|
||||
char* pData, int16_t bytes, bool masterscan, uint64_t groupId,
|
||||
|
@ -663,7 +664,8 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
|||
int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
|
||||
SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t num, SSDataBlock* pResBlock, SLimit* pLimit, SLimit* pSlimit, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo *createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SArray* pIndexMap, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo *createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SArray* pIndexMap, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t num, SArray* pSortInfo, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
|
|
|
@ -89,7 +89,7 @@ int32_t tsortClose(SSortHandle* pHandle);
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
int32_t tsortSetFetchRawDataFp(SSortHandle* pHandle, _sort_fetch_block_fn_t fp);
|
||||
int32_t tsortSetFetchRawDataFp(SSortHandle* pHandle, _sort_fetch_block_fn_t fetchFp, void (*fp)(SSDataBlock*, void*), void* param);
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -202,9 +202,9 @@ SSDataBlock* createResDataBlock(SDataBlockDescNode* pNode) {
|
|||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData idata = {{0}};
|
||||
SSlotDescNode* pDescNode = nodesListGetNode(pNode->pSlots, i);
|
||||
if (!pDescNode->output) {
|
||||
continue;
|
||||
}
|
||||
// if (!pDescNode->output) { // todo disable it temporarily
|
||||
// continue;
|
||||
// }
|
||||
|
||||
idata.info.type = pDescNode->dataType.type;
|
||||
idata.info.bytes = pDescNode->dataType.bytes;
|
||||
|
@ -651,7 +651,7 @@ static int32_t doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCt
|
|||
|
||||
static void doSetInputDataBlockInfo(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock,
|
||||
int32_t order) {
|
||||
for (int32_t i = 0; i < pOperator->numOfOutput; ++i) {
|
||||
for (int32_t i = 0; i < pOperator->numOfExprs; ++i) {
|
||||
pCtx[i].order = order;
|
||||
pCtx[i].size = pBlock->info.rows;
|
||||
setBlockStatisInfo(&pCtx[i], &pOperator->pExpr[i], pBlock);
|
||||
|
@ -713,7 +713,7 @@ static int32_t doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCt
|
|||
bool createDummyCol) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
for (int32_t i = 0; i < pOperator->numOfOutput; ++i) {
|
||||
for (int32_t i = 0; i < pOperator->numOfExprs; ++i) {
|
||||
pCtx[i].order = order;
|
||||
pCtx[i].size = pBlock->info.rows;
|
||||
pCtx[i].pSrcBlock = pBlock;
|
||||
|
@ -798,7 +798,7 @@ static int32_t doSetInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCt
|
|||
}
|
||||
|
||||
static void doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SqlFunctionCtx* pCtx) {
|
||||
for (int32_t k = 0; k < pOperator->numOfOutput; ++k) {
|
||||
for (int32_t k = 0; k < pOperator->numOfExprs; ++k) {
|
||||
if (functionNeedToExecute(&pCtx[k])) {
|
||||
pCtx[k].startTs = startTs; // this can be set during create the struct
|
||||
pCtx[k].fpSet.process(&pCtx[k]);
|
||||
|
@ -2815,7 +2815,6 @@ static int32_t doSendFetchDataRequest(SExchangeInfo* pExchangeInfo, SExecTaskInf
|
|||
// NOTE: sources columns are more than the destination SSDatablock columns.
|
||||
void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray* pCols) {
|
||||
size_t numOfSrcCols = taosArrayGetSize(pCols);
|
||||
ASSERT(numOfSrcCols >= pBlock->info.numOfCols);
|
||||
|
||||
int32_t i = 0, j = 0;
|
||||
while (i < numOfSrcCols && j < taosArrayGetSize(pColMatchInfo)) {
|
||||
|
@ -3287,7 +3286,7 @@ SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock
|
|||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = pBlock->info.numOfCols;
|
||||
pOperator->numOfExprs = pBlock->info.numOfCols;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(prepareLoadRemoteData, doLoadRemoteData, NULL, NULL,
|
||||
|
@ -3345,49 +3344,6 @@ static void destroySortedMergeOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
cleanupAggSup(&pInfo->aggSup);
|
||||
}
|
||||
|
||||
// TODO merge aggregate super table
|
||||
static void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle) {
|
||||
for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i);
|
||||
|
||||
bool isNull = tsortIsNullVal(pTupleHandle, i);
|
||||
if (isNull) {
|
||||
colDataAppend(pColInfo, pBlock->info.rows, NULL, true);
|
||||
} else {
|
||||
char* pData = tsortGetValue(pTupleHandle, i);
|
||||
colDataAppend(pColInfo, pBlock->info.rows, pData, false);
|
||||
}
|
||||
}
|
||||
|
||||
pBlock->info.rows += 1;
|
||||
}
|
||||
|
||||
SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity) {
|
||||
blockDataCleanup(pDataBlock);
|
||||
blockDataEnsureCapacity(pDataBlock, capacity);
|
||||
|
||||
blockDataEnsureCapacity(pDataBlock, capacity);
|
||||
|
||||
while (1) {
|
||||
STupleHandle* pTupleHandle = tsortNextTuple(pHandle);
|
||||
if (pTupleHandle == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
appendOneRowToDataBlock(pDataBlock, pTupleHandle);
|
||||
if (pDataBlock->info.rows >= capacity) {
|
||||
return pDataBlock;
|
||||
}
|
||||
}
|
||||
|
||||
return (pDataBlock->info.rows > 0) ? pDataBlock : NULL;
|
||||
}
|
||||
|
||||
SSDataBlock* loadNextDataBlock(void* param) {
|
||||
SOperatorInfo* pOperator = (SOperatorInfo*)param;
|
||||
return pOperator->fpSet.getNextFn(pOperator);
|
||||
}
|
||||
|
||||
static bool needToMerge(SSDataBlock* pBlock, SArray* groupInfo, char** buf, int32_t rowIndex) {
|
||||
size_t size = taosArrayGetSize(groupInfo);
|
||||
if (size == 0) {
|
||||
|
@ -3490,8 +3446,8 @@ static void doMergeImpl(SOperatorInfo* pOperator, int32_t numOfExpr, SSDataBlock
|
|||
doMergeResultImpl(pInfo, pCtx, numOfExpr, i);
|
||||
} else {
|
||||
doFinalizeResultImpl(pCtx, numOfExpr);
|
||||
int32_t numOfRows = getNumOfResult(pInfo->binfo.pCtx, pOperator->numOfOutput, NULL);
|
||||
// setTagValueForMultipleRows(pCtx, pOperator->numOfOutput, numOfRows);
|
||||
int32_t numOfRows = getNumOfResult(pInfo->binfo.pCtx, pOperator->numOfExprs, NULL);
|
||||
// setTagValueForMultipleRows(pCtx, pOperator->numOfExprs, numOfRows);
|
||||
|
||||
// TODO check for available buffer;
|
||||
|
||||
|
@ -3541,13 +3497,13 @@ static SSDataBlock* doMerge(SOperatorInfo* pOperator) {
|
|||
setInputDataBlock(pOperator, pInfo->binfo.pCtx, pDataBlock, TSDB_ORDER_ASC, true);
|
||||
// updateOutputBuf(&pInfo->binfo, &pAggInfo->bufCapacity, pBlock->info.rows * pAggInfo->resultRowFactor,
|
||||
// pOperator->pRuntimeEnv, true);
|
||||
doMergeImpl(pOperator, pOperator->numOfOutput, pDataBlock);
|
||||
doMergeImpl(pOperator, pOperator->numOfExprs, pDataBlock);
|
||||
// flush to tuple store, and after all data have been handled, return to upstream node or sink node
|
||||
}
|
||||
|
||||
doFinalizeResultImpl(pInfo->binfo.pCtx, pOperator->numOfOutput);
|
||||
int32_t numOfRows = getNumOfResult(pInfo->binfo.pCtx, pOperator->numOfOutput, NULL);
|
||||
// setTagValueForMultipleRows(pCtx, pOperator->numOfOutput, numOfRows);
|
||||
doFinalizeResultImpl(pInfo->binfo.pCtx, pOperator->numOfExprs);
|
||||
int32_t numOfRows = getNumOfResult(pInfo->binfo.pCtx, pOperator->numOfExprs, NULL);
|
||||
// setTagValueForMultipleRows(pCtx, pOperator->numOfExprs, numOfRows);
|
||||
|
||||
// TODO check for available buffer;
|
||||
|
||||
|
@ -3571,7 +3527,7 @@ static SSDataBlock* doSortedMerge(SOperatorInfo* pOperator) {
|
|||
pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, NULL, SORT_MULTISOURCE_MERGE, pInfo->bufPageSize,
|
||||
numOfBufPage, pInfo->binfo.pRes, "GET_TASKID(pTaskInfo)");
|
||||
|
||||
tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock);
|
||||
tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock, NULL, NULL);
|
||||
|
||||
for (int32_t i = 0; i < pOperator->numOfDownstream; ++i) {
|
||||
SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource));
|
||||
|
@ -3678,7 +3634,7 @@ SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t
|
|||
pOperator->blocking = true;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = num;
|
||||
pOperator->numOfExprs = num;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
@ -3703,79 +3659,6 @@ _error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static SSDataBlock* doSort(SOperatorInfo* pOperator) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SSortOperatorInfo* pInfo = pOperator->info;
|
||||
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
return getSortedBlockData(pInfo->pSortHandle, pInfo->pDataBlock, pInfo->numOfRowsInRes);
|
||||
}
|
||||
|
||||
int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize;
|
||||
pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, pInfo->inputSlotMap, SORT_SINGLESOURCE_SORT,
|
||||
pInfo->bufPageSize, numOfBufPage, pInfo->pDataBlock, pTaskInfo->id.str);
|
||||
|
||||
tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock);
|
||||
|
||||
SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource));
|
||||
ps->param = pOperator->pDownstream[0];
|
||||
tsortAddSource(pInfo->pSortHandle, ps);
|
||||
|
||||
int32_t code = tsortOpen(pInfo->pSortHandle);
|
||||
taosMemoryFreeClear(ps);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, terrno);
|
||||
}
|
||||
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
return getSortedBlockData(pInfo->pSortHandle, pInfo->pDataBlock, pInfo->numOfRowsInRes);
|
||||
}
|
||||
|
||||
SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo,
|
||||
SArray* pIndexMap, SExecTaskInfo* pTaskInfo) {
|
||||
SSortOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortOperatorInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
int32_t rowSize = pResBlock->info.rowSize;
|
||||
|
||||
if (pInfo == NULL || pOperator == NULL || rowSize > 100 * 1024 * 1024) {
|
||||
taosMemoryFreeClear(pInfo);
|
||||
taosMemoryFreeClear(pOperator);
|
||||
terrno = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pInfo->bufPageSize = rowSize < 1024 ? 1024 * 2 : rowSize * 2; // there are headers, so pageSize = rowSize + header
|
||||
|
||||
pInfo->sortBufSize = pInfo->bufPageSize * 16; // TODO dynamic set the available sort buffer
|
||||
pInfo->numOfRowsInRes = 1024;
|
||||
pInfo->pDataBlock = pResBlock;
|
||||
pInfo->pSortInfo = pSortInfo;
|
||||
pInfo->inputSlotMap = pIndexMap;
|
||||
|
||||
pOperator->name = "SortOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SORT;
|
||||
pOperator->blocking = true;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doSort, NULL, NULL, destroyOrderOperatorInfo, NULL, NULL, NULL);
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFree(pInfo);
|
||||
taosMemoryFree(pOperator);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t getTableScanOrder(SOperatorInfo* pOperator) {
|
||||
if (pOperator->operatorType != QUERY_NODE_PHYSICAL_PLAN_TABLE_SCAN) {
|
||||
if (pOperator->pDownstream == NULL || pOperator->pDownstream[0] == NULL) {
|
||||
|
@ -3813,7 +3696,7 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) {
|
|||
break;
|
||||
}
|
||||
// if (pAggInfo->current != NULL) {
|
||||
// setTagValue(pOperator, pAggInfo->current->pTable, pInfo->pCtx, pOperator->numOfOutput);
|
||||
// setTagValue(pOperator, pAggInfo->current->pTable, pInfo->pCtx, pOperator->numOfExprs);
|
||||
// }
|
||||
|
||||
// there is an scalar expression that needs to be calculated before apply the group aggregation.
|
||||
|
@ -3827,7 +3710,7 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
// the pDataBlock are always the same one, no need to call this again
|
||||
setExecutionContext(pOperator->numOfOutput, pBlock->info.groupId, pTaskInfo, pAggInfo);
|
||||
setExecutionContext(pOperator->numOfExprs, pBlock->info.groupId, pTaskInfo, pAggInfo);
|
||||
setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order, true);
|
||||
doAggregateImpl(pOperator, 0, pInfo->pCtx);
|
||||
|
||||
|
@ -3848,7 +3731,7 @@ static int32_t doOpenAggregateOptr(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
closeAllResultRows(&pAggInfo->binfo.resultRowInfo);
|
||||
finalizeMultiTupleQueryResult(pAggInfo->binfo.pCtx, pOperator->numOfOutput, pAggInfo->aggSup.pResultBuf,
|
||||
finalizeMultiTupleQueryResult(pAggInfo->binfo.pCtx, pOperator->numOfExprs, pAggInfo->aggSup.pResultBuf,
|
||||
&pAggInfo->binfo.resultRowInfo, pAggInfo->binfo.rowCellInfoOffset);
|
||||
|
||||
initGroupedResultInfo(&pAggInfo->groupResInfo, pAggInfo->aggSup.pResultRowHashTable, false);
|
||||
|
@ -4092,17 +3975,17 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
|
|||
|
||||
// todo dynamic set tags
|
||||
// if (pTableQueryInfo != NULL) {
|
||||
// setTagValue(pOperator, pTableQueryInfo->pTable, pInfo->pCtx, pOperator->numOfOutput);
|
||||
// setTagValue(pOperator, pTableQueryInfo->pTable, pInfo->pCtx, pOperator->numOfExprs);
|
||||
// }
|
||||
|
||||
// the pDataBlock are always the same one, no need to call this again
|
||||
setInputDataBlock(pOperator, pInfo->pCtx, pBlock, TSDB_ORDER_ASC);
|
||||
|
||||
blockDataEnsureCapacity(pInfo->pRes, pBlock->info.rows);
|
||||
projectApplyFunctions(pOperator->pExpr, pInfo->pRes, pBlock, pInfo->pCtx, pOperator->numOfOutput);
|
||||
projectApplyFunctions(pOperator->pExpr, pInfo->pRes, pBlock, pInfo->pCtx, pOperator->numOfExprs);
|
||||
if (pRes->info.rows >= pProjectInfo->binfo.capacity * 0.8) {
|
||||
copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput);
|
||||
resetResultRowEntryResult(pInfo->pCtx, pOperator->numOfOutput);
|
||||
copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfExprs);
|
||||
resetResultRowEntryResult(pInfo->pCtx, pOperator->numOfExprs);
|
||||
return pRes;
|
||||
}
|
||||
}
|
||||
|
@ -4127,14 +4010,14 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
|
|||
pProjectInfo->existDataBlock = pBlock;
|
||||
break;
|
||||
} else { // init output buffer for a new group data
|
||||
initCtxOutputBuffer(pInfo->pCtx, pOperator->numOfOutput);
|
||||
initCtxOutputBuffer(pInfo->pCtx, pOperator->numOfExprs);
|
||||
}
|
||||
}
|
||||
|
||||
// todo dynamic set tags
|
||||
// STableQueryInfo* pTableQueryInfo = pRuntimeEnv->current;
|
||||
// if (pTableQueryInfo != NULL) {
|
||||
// setTagValue(pOperator, pTableQueryInfo->pTable, pInfo->pCtx, pOperator->numOfOutput);
|
||||
// setTagValue(pOperator, pTableQueryInfo->pTable, pInfo->pCtx, pOperator->numOfExprs);
|
||||
// }
|
||||
|
||||
// the pDataBlock are always the same one, no need to call this again
|
||||
|
@ -4143,7 +4026,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
|
|||
setInputDataBlock(pOperator, pInfo->pCtx, pBlock, order, false);
|
||||
blockDataEnsureCapacity(pInfo->pRes, pInfo->pRes->info.rows + pBlock->info.rows);
|
||||
|
||||
projectApplyFunctions(pOperator->pExpr, pInfo->pRes, pBlock, pInfo->pCtx, pOperator->numOfOutput,
|
||||
projectApplyFunctions(pOperator->pExpr, pInfo->pRes, pBlock, pInfo->pCtx, pOperator->numOfExprs,
|
||||
pProjectInfo->pPseudoColInfo);
|
||||
|
||||
int32_t status = handleLimitOffset(pOperator, pBlock);
|
||||
|
@ -4156,7 +4039,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
|
|||
|
||||
pProjectInfo->curOutput += pInfo->pRes->info.rows;
|
||||
|
||||
// copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfOutput);
|
||||
// copyTsColoum(pRes, pInfo->pCtx, pOperator->numOfExprs);
|
||||
return (pInfo->pRes->info.rows > 0) ? pInfo->pRes : NULL;
|
||||
}
|
||||
|
||||
|
@ -4289,7 +4172,7 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
if (pOperator->fpSet.closeFn != NULL) {
|
||||
pOperator->fpSet.closeFn(pOperator->info, pOperator->numOfOutput);
|
||||
pOperator->fpSet.closeFn(pOperator->info, pOperator->numOfExprs);
|
||||
}
|
||||
|
||||
if (pOperator->pDownstream != NULL) {
|
||||
|
@ -4425,7 +4308,7 @@ SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
|||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->numOfOutput = numOfCols;
|
||||
pOperator->numOfExprs = numOfCols;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(doOpenAggregateOptr, getAggregateResult, NULL, NULL, destroyAggOperatorInfo,
|
||||
|
@ -4477,14 +4360,6 @@ static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
doDestroyBasicInfo(&pInfo->binfo, numOfOutput);
|
||||
}
|
||||
|
||||
static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
SSortOperatorInfo* pInfo = (SSortOperatorInfo*)param;
|
||||
pInfo->pDataBlock = blockDataDestroy(pInfo->pDataBlock);
|
||||
|
||||
taosArrayDestroy(pInfo->pSortInfo);
|
||||
taosArrayDestroy(pInfo->inputSlotMap);
|
||||
}
|
||||
|
||||
void destroyExchangeOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
SExchangeInfo* pExInfo = (SExchangeInfo*)param;
|
||||
taosArrayDestroy(pExInfo->pSources);
|
||||
|
@ -4538,7 +4413,7 @@ SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* p
|
|||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->numOfOutput = num;
|
||||
pOperator->numOfExprs = num;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doProjectOperation, NULL, NULL,
|
||||
destroyProjectOperatorInfo, NULL, NULL, NULL);
|
||||
|
@ -4621,7 +4496,7 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExp
|
|||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_FILL;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfCols;
|
||||
pOperator->numOfExprs = numOfCols;
|
||||
pOperator->info = pInfo;
|
||||
|
||||
pOperator->fpSet =
|
||||
|
@ -4830,6 +4705,7 @@ static SArray* createSortInfo(SNodeList* pNodeList, SNodeList* pNodeListTarget);
|
|||
static SArray* createIndexMap(SNodeList* pNodeList);
|
||||
static SArray* extractPartitionColInfo(SNodeList* pNodeList);
|
||||
static int32_t initQueryTableDataCond(SQueryTableDataCond* pCond, const STableScanPhysiNode* pTableScanNode);
|
||||
static void setJoinColumnInfo(SColumnInfo* pInfo, const SColumnNode* pLeftNode);
|
||||
|
||||
static SInterval extractIntervalInfo(const STableScanPhysiNode* pTableScanNode) {
|
||||
SInterval interval = {
|
||||
|
@ -4978,7 +4854,14 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
|
||||
SArray* info = createSortInfo(pSortPhyNode->pSortKeys, pSortPhyNode->pTargets);
|
||||
SArray* slotMap = createIndexMap(pSortPhyNode->pTargets);
|
||||
pOptr = createSortOperatorInfo(ops[0], pResBlock, info, slotMap, pTaskInfo);
|
||||
|
||||
int32_t numOfCols = 0;
|
||||
SExprInfo* pExprInfo = NULL;
|
||||
if (pSortPhyNode->pExprs != NULL) {
|
||||
pExprInfo = createExprInfo(pSortPhyNode->pExprs, NULL, &numOfCols);
|
||||
}
|
||||
|
||||
pOptr = createSortOperatorInfo(ops[0], pResBlock, info, pExprInfo, numOfCols, slotMap, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW == type) {
|
||||
SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode;
|
||||
|
||||
|
@ -5565,7 +5448,7 @@ static SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator) {
|
|||
// only the timestamp match support for ordinary table
|
||||
ASSERT(pLeftCol->info.type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
if (*(int64_t*)pLeftVal == *(int64_t*)pRightVal) {
|
||||
for (int32_t i = 0; i < pOperator->numOfOutput; ++i) {
|
||||
for (int32_t i = 0; i < pOperator->numOfExprs; ++i) {
|
||||
SColumnInfoData* pDst = taosArrayGet(pRes->pDataBlock, i);
|
||||
|
||||
SExprInfo* pExprInfo = &pOperator->pExpr[i];
|
||||
|
@ -5624,25 +5507,29 @@ SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOf
|
|||
goto _error;
|
||||
}
|
||||
|
||||
pOperator->resultInfo.capacity = 4096;
|
||||
pOperator->resultInfo.threshold = 4096 * 0.75;
|
||||
initResultSizeInfo(pOperator, 4096);
|
||||
|
||||
// initResultRowInf
|
||||
// o(&pInfo->binfo.resultRowInfo, 8);
|
||||
pInfo->pRes = pResBlock;
|
||||
|
||||
pOperator->name = "JoinOperator";
|
||||
pOperator->name = "MergeJoinOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_JOIN;
|
||||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->numOfOutput = numOfCols;
|
||||
pOperator->numOfExprs = numOfCols;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
SOperatorNode* pNode = (SOperatorNode*)pOnCondition;
|
||||
setJoinColumnInfo(&pInfo->leftCol, (SColumnNode*)pNode->pLeft);
|
||||
setJoinColumnInfo(&pInfo->rightCol, (SColumnNode*)pNode->pRight);
|
||||
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doMergeJoin, NULL, NULL, destroyBasicOperatorInfo, NULL, NULL, NULL);
|
||||
int32_t code = appendDownstream(pOperator, pDownstream, numOfDownstream);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
|
@ -5651,3 +5538,11 @@ _error:
|
|||
pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void setJoinColumnInfo(SColumnInfo* pColumn, const SColumnNode* pColumnNode) {
|
||||
pColumn->slotId = pColumnNode->slotId;
|
||||
pColumn->type = pColumnNode->node.resType.type;
|
||||
pColumn->bytes = pColumnNode->node.resType.bytes;
|
||||
pColumn->precision = pColumnNode->node.resType.precision;
|
||||
pColumn->scale = pColumnNode->node.resType.scale;
|
||||
}
|
||||
|
|
|
@ -227,16 +227,16 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
|||
}
|
||||
|
||||
len = buildGroupKeys(pInfo->keyBuf, pInfo->pGroupColVals);
|
||||
int32_t ret = setGroupResultOutputBuf(&(pInfo->binfo), pOperator->numOfOutput, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len, 0, pInfo->aggSup.pResultBuf, pTaskInfo, &pInfo->aggSup);
|
||||
int32_t ret = setGroupResultOutputBuf(&(pInfo->binfo), pOperator->numOfExprs, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len, 0, pInfo->aggSup.pResultBuf, pTaskInfo, &pInfo->aggSup);
|
||||
if (ret != TSDB_CODE_SUCCESS) { // null data, too many state code
|
||||
longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
||||
int32_t rowIndex = j - num;
|
||||
doApplyFunctions(pCtx, &w, NULL, rowIndex, num, NULL, pBlock->info.rows, pOperator->numOfOutput, TSDB_ORDER_ASC);
|
||||
doApplyFunctions(pCtx, &w, NULL, rowIndex, num, NULL, pBlock->info.rows, pOperator->numOfExprs, TSDB_ORDER_ASC);
|
||||
|
||||
// assign the group keys or user input constant values if required
|
||||
doAssignGroupKeys(pCtx, pOperator->numOfOutput, pBlock->info.rows, rowIndex);
|
||||
doAssignGroupKeys(pCtx, pOperator->numOfExprs, pBlock->info.rows, rowIndex);
|
||||
recordNewGroupKeys(pInfo->pGroupCols, pInfo->pGroupColVals, pBlock, j, numOfGroupCols);
|
||||
num = 1;
|
||||
}
|
||||
|
@ -244,15 +244,15 @@ static void doHashGroupbyAgg(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
|||
if (num > 0) {
|
||||
len = buildGroupKeys(pInfo->keyBuf, pInfo->pGroupColVals);
|
||||
int32_t ret =
|
||||
setGroupResultOutputBuf(&(pInfo->binfo), pOperator->numOfOutput, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len,
|
||||
setGroupResultOutputBuf(&(pInfo->binfo), pOperator->numOfExprs, pInfo->keyBuf, TSDB_DATA_TYPE_VARCHAR, len,
|
||||
0, pInfo->aggSup.pResultBuf, pTaskInfo, &pInfo->aggSup);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
|
||||
int32_t rowIndex = pBlock->info.rows - num;
|
||||
doApplyFunctions(pCtx, &w, NULL, rowIndex, num, NULL, pBlock->info.rows, pOperator->numOfOutput, TSDB_ORDER_ASC);
|
||||
doAssignGroupKeys(pCtx, pOperator->numOfOutput, pBlock->info.rows, rowIndex);
|
||||
doApplyFunctions(pCtx, &w, NULL, rowIndex, num, NULL, pBlock->info.rows, pOperator->numOfExprs, TSDB_ORDER_ASC);
|
||||
doAssignGroupKeys(pCtx, pOperator->numOfExprs, pBlock->info.rows, rowIndex);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -291,19 +291,19 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
|
|||
projectApplyFunctions(pInfo->pScalarExprInfo, pBlock, pBlock, pInfo->pScalarFuncCtx, pInfo->numOfScalarExpr, NULL);
|
||||
}
|
||||
|
||||
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->binfo.pCtx, pOperator->numOfOutput);
|
||||
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->binfo.pCtx, pOperator->numOfExprs);
|
||||
doHashGroupbyAgg(pOperator, pBlock);
|
||||
}
|
||||
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
closeAllResultRows(&pInfo->binfo.resultRowInfo);
|
||||
|
||||
finalizeMultiTupleQueryResult(pInfo->binfo.pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf,
|
||||
finalizeMultiTupleQueryResult(pInfo->binfo.pCtx, pOperator->numOfExprs, pInfo->aggSup.pResultBuf,
|
||||
&pInfo->binfo.resultRowInfo, pInfo->binfo.rowCellInfoOffset);
|
||||
// if (!stableQuery) { // finalize include the update of result rows
|
||||
// finalizeQueryResult(pInfo->binfo.pCtx, pOperator->numOfOutput);
|
||||
// finalizeQueryResult(pInfo->binfo.pCtx, pOperator->numOfExprs);
|
||||
// } else {
|
||||
// updateNumOfRowsInResultRows(pInfo->binfo.pCtx, pOperator->numOfOutput, &pInfo->binfo.resultRowInfo,
|
||||
// updateNumOfRowsInResultRows(pInfo->binfo.pCtx, pOperator->numOfExprs, &pInfo->binfo.resultRowInfo,
|
||||
// pInfo->binfo.rowCellInfoOffset);
|
||||
// }
|
||||
|
||||
|
@ -357,7 +357,7 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx
|
|||
pOperator->status = OP_NOT_OPENED;
|
||||
// pOperator->operatorType = OP_Groupby;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->numOfOutput = numOfCols;
|
||||
pOperator->numOfExprs = numOfCols;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
|
@ -392,7 +392,7 @@ static void doHashPartition(SOperatorInfo* pOperator, SSDataBlock* pBlock) {
|
|||
|
||||
int32_t* rows = (int32_t*) pPage;
|
||||
|
||||
size_t numOfCols = pOperator->numOfOutput;
|
||||
size_t numOfCols = pOperator->numOfExprs;
|
||||
for(int32_t i = 0; i < numOfCols; ++i) {
|
||||
SExprInfo* pExpr = &pOperator->pExpr[i];
|
||||
int32_t slotId = pExpr->base.pParam[0].pCol->slotId;
|
||||
|
@ -565,7 +565,7 @@ static SSDataBlock* hashPartition(SOperatorInfo* pOperator) {
|
|||
break;
|
||||
}
|
||||
|
||||
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->binfo.pCtx, pOperator->numOfOutput);
|
||||
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->binfo.pCtx, pOperator->numOfExprs);
|
||||
doHashPartition(pOperator, pBlock);
|
||||
}
|
||||
|
||||
|
@ -616,7 +616,7 @@ SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
|||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_PARTITION;
|
||||
pInfo->binfo.pRes = pResultBlock;
|
||||
pOperator->numOfOutput = numOfCols;
|
||||
pOperator->numOfExprs = numOfCols;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->info = pInfo;
|
||||
|
||||
|
|
|
@ -63,9 +63,14 @@ typedef struct SIFParam {
|
|||
} SIFParam;
|
||||
|
||||
static int32_t sifGetFuncFromSql(EOperatorType src, EIndexQueryType *dst) {
|
||||
if (src == OP_TYPE_GREATER_THAN || src == OP_TYPE_GREATER_EQUAL || src == OP_TYPE_LOWER_THAN ||
|
||||
src == OP_TYPE_LOWER_EQUAL) {
|
||||
*dst = QUERY_RANGE;
|
||||
if (src == OP_TYPE_GREATER_THAN) {
|
||||
*dst = QUERY_GREATER_THAN;
|
||||
} else if (src == OP_TYPE_GREATER_EQUAL) {
|
||||
*dst = QUERY_GREATER_EQUAL;
|
||||
} else if (src == OP_TYPE_LOWER_THAN) {
|
||||
*dst = QUERY_LESS_THAN;
|
||||
} else if (src == OP_TYPE_LOWER_EQUAL) {
|
||||
*dst = QUERY_LESS_EQUAL;
|
||||
} else if (src == OP_TYPE_EQUAL) {
|
||||
*dst = QUERY_TERM;
|
||||
} else if (src == OP_TYPE_LIKE || src == OP_TYPE_MATCH || src == OP_TYPE_NMATCH) {
|
||||
|
@ -249,9 +254,6 @@ static int32_t sifExecFunction(SFunctionNode *node, SIFCtx *ctx, SIFParam *outpu
|
|||
static int32_t sifDoIndex(SIFParam *left, SIFParam *right, int8_t operType, SIFParam *output) {
|
||||
SIndexTerm *tm = indexTermCreate(left->suid, DEFAULT, operType, left->colValType, left->colName,
|
||||
strlen(left->colName), right->condValue, strlen(right->condValue));
|
||||
if (operType == OP_TYPE_LOWER_EQUAL || operType == OP_TYPE_GREATER_EQUAL || operType == OP_TYPE_GREATER_THAN ||
|
||||
operType == OP_TYPE_LOWER_THAN) {
|
||||
}
|
||||
if (tm == NULL) {
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -386,7 +386,7 @@ SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, SQueryTableDataCon
|
|||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->numOfExprs = numOfOutput;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doTableScan, NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
|
@ -646,7 +646,7 @@ SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock*
|
|||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = pResBlock->info.numOfCols;
|
||||
pOperator->numOfExprs = pResBlock->info.numOfCols;
|
||||
pOperator->fpSet._openFn = operatorDummyOpenFn;
|
||||
pOperator->fpSet.getNextFn = doStreamBlockScan;
|
||||
pOperator->fpSet.closeFn = operatorDummyCloseFn;
|
||||
|
@ -1020,7 +1020,7 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
|||
|
||||
SRetrieveMetaTableRsp* pTableRsp = pInfo->pRsp;
|
||||
setSDataBlockFromFetchRsp(pInfo->pRes, &pInfo->loadInfo, pTableRsp->numOfRows, pTableRsp->data,
|
||||
pTableRsp->compLen, pOperator->numOfOutput, startTs, NULL, pInfo->scanCols);
|
||||
pTableRsp->compLen, pOperator->numOfExprs, startTs, NULL, pInfo->scanCols);
|
||||
|
||||
// todo log the filter info
|
||||
doFilterResult(pInfo);
|
||||
|
@ -1150,7 +1150,7 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSDataBlock* pRe
|
|||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->numOfOutput = pResBlock->info.numOfCols;
|
||||
pOperator->numOfExprs = pResBlock->info.numOfCols;
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSysTableScan, NULL, NULL, destroySysScanOperator,
|
||||
NULL, NULL, NULL);
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
@ -1247,7 +1247,7 @@ static SSDataBlock* doTagScan(SOperatorInfo* pOperator) {
|
|||
|
||||
char *data = NULL, *dst = NULL;
|
||||
int16_t type = 0, bytes = 0;
|
||||
for(int32_t j = 0; j < pOperator->numOfOutput; ++j) {
|
||||
for(int32_t j = 0; j < pOperator->numOfExprs; ++j) {
|
||||
// not assign value in case of user defined constant output column
|
||||
if (TSDB_COL_IS_UD_COL(pExprInfo[j].base.pColumns->flag)) {
|
||||
continue;
|
||||
|
@ -1308,7 +1308,7 @@ SOperatorInfo* createTagScanOperatorInfo(void* readHandle, SExprInfo* pExpr, int
|
|||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfOutput;
|
||||
pOperator->numOfExprs = numOfOutput;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
pOperator->fpSet =
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
#include "tdatablock.h"
|
||||
#include "executorimpl.h"
|
||||
|
||||
static SSDataBlock* doSort(SOperatorInfo* pOperator);
|
||||
static void destroyOrderOperatorInfo(void* param, int32_t numOfOutput);
|
||||
|
||||
SOperatorInfo* createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SArray* pIndexMap, SExecTaskInfo* pTaskInfo) {
|
||||
SSortOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SSortOperatorInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
int32_t rowSize = pResBlock->info.rowSize;
|
||||
|
||||
if (pInfo == NULL || pOperator == NULL || rowSize > 100 * 1024 * 1024) {
|
||||
goto _error;
|
||||
}
|
||||
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->numOfExprs = numOfCols;
|
||||
pInfo->binfo.pCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pInfo->binfo.rowCellInfoOffset);
|
||||
pInfo->binfo.pRes = pResBlock;
|
||||
|
||||
initResultSizeInfo(pOperator, 1024);
|
||||
pInfo->bufPageSize = rowSize < 1024 ? 1024 * 2 : rowSize * 2; // there are headers, so pageSize = rowSize + header
|
||||
|
||||
pInfo->sortBufSize = pInfo->bufPageSize * 16; // TODO dynamic set the available sort buffer
|
||||
pInfo->pSortInfo = pSortInfo;
|
||||
pInfo->inputSlotMap = pIndexMap;
|
||||
pOperator->name = "SortOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_SORT;
|
||||
pOperator->blocking = true;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->info = pInfo;
|
||||
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->fpSet =
|
||||
createOperatorFpSet(operatorDummyOpenFn, doSort, NULL, NULL, destroyOrderOperatorInfo, NULL, NULL, NULL);
|
||||
|
||||
int32_t code = appendDownstream(pOperator, &downstream, 1);
|
||||
return pOperator;
|
||||
|
||||
_error:
|
||||
pTaskInfo->code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFree(pInfo);
|
||||
taosMemoryFree(pOperator);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// TODO merge aggregate super table
|
||||
void appendOneRowToDataBlock(SSDataBlock* pBlock, STupleHandle* pTupleHandle) {
|
||||
for (int32_t i = 0; i < pBlock->info.numOfCols; ++i) {
|
||||
SColumnInfoData* pColInfo = taosArrayGet(pBlock->pDataBlock, i);
|
||||
|
||||
bool isNull = tsortIsNullVal(pTupleHandle, i);
|
||||
if (isNull) {
|
||||
colDataAppend(pColInfo, pBlock->info.rows, NULL, true);
|
||||
} else {
|
||||
char* pData = tsortGetValue(pTupleHandle, i);
|
||||
colDataAppend(pColInfo, pBlock->info.rows, pData, false);
|
||||
}
|
||||
}
|
||||
|
||||
pBlock->info.rows += 1;
|
||||
}
|
||||
|
||||
SSDataBlock* getSortedBlockData(SSortHandle* pHandle, SSDataBlock* pDataBlock, int32_t capacity) {
|
||||
blockDataCleanup(pDataBlock);
|
||||
blockDataEnsureCapacity(pDataBlock, capacity);
|
||||
|
||||
blockDataEnsureCapacity(pDataBlock, capacity);
|
||||
|
||||
while (1) {
|
||||
STupleHandle* pTupleHandle = tsortNextTuple(pHandle);
|
||||
if (pTupleHandle == NULL) {
|
||||
break;
|
||||
}
|
||||
|
||||
appendOneRowToDataBlock(pDataBlock, pTupleHandle);
|
||||
if (pDataBlock->info.rows >= capacity) {
|
||||
return pDataBlock;
|
||||
}
|
||||
}
|
||||
|
||||
return (pDataBlock->info.rows > 0) ? pDataBlock : NULL;
|
||||
}
|
||||
|
||||
SSDataBlock* loadNextDataBlock(void* param) {
|
||||
SOperatorInfo* pOperator = (SOperatorInfo*)param;
|
||||
return pOperator->fpSet.getNextFn(pOperator);
|
||||
}
|
||||
|
||||
// todo refactor: merged with fetch fp
|
||||
void applyScalarFunction(SSDataBlock* pBlock, void* param) {
|
||||
SOperatorInfo* pOperator = param;
|
||||
SSortOperatorInfo* pSort = pOperator->info;
|
||||
if (pOperator->pExpr != NULL) {
|
||||
projectApplyFunctions(pOperator->pExpr, pBlock, pBlock, pSort->binfo.pCtx, pOperator->numOfExprs, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
SSDataBlock* doSort(SOperatorInfo* pOperator) {
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
SSortOperatorInfo* pInfo = pOperator->info;
|
||||
|
||||
if (pOperator->status == OP_RES_TO_RETURN) {
|
||||
return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
||||
}
|
||||
|
||||
int32_t numOfBufPage = pInfo->sortBufSize / pInfo->bufPageSize;
|
||||
pInfo->pSortHandle = tsortCreateSortHandle(pInfo->pSortInfo, pInfo->inputSlotMap, SORT_SINGLESOURCE_SORT,
|
||||
pInfo->bufPageSize, numOfBufPage, pInfo->binfo.pRes, pTaskInfo->id.str);
|
||||
|
||||
tsortSetFetchRawDataFp(pInfo->pSortHandle, loadNextDataBlock, applyScalarFunction, pOperator);
|
||||
|
||||
|
||||
SSortSource* ps = taosMemoryCalloc(1, sizeof(SSortSource));
|
||||
ps->param = pOperator->pDownstream[0];
|
||||
tsortAddSource(pInfo->pSortHandle, ps);
|
||||
|
||||
int32_t code = tsortOpen(pInfo->pSortHandle);
|
||||
taosMemoryFreeClear(ps);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, terrno);
|
||||
}
|
||||
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
return getSortedBlockData(pInfo->pSortHandle, pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
||||
}
|
||||
|
||||
void destroyOrderOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
SSortOperatorInfo* pInfo = (SSortOperatorInfo*)param;
|
||||
pInfo->binfo.pRes = blockDataDestroy(pInfo->binfo.pRes);
|
||||
|
||||
taosArrayDestroy(pInfo->pSortInfo);
|
||||
taosArrayDestroy(pInfo->inputSlotMap);
|
||||
}
|
|
@ -325,7 +325,7 @@ void doTimeWindowInterpolation(SOperatorInfo* pOperator, SOptrBasicInfo* pInfo,
|
|||
|
||||
SqlFunctionCtx* pCtx = pInfo->pCtx;
|
||||
|
||||
for (int32_t k = 0; k < pOperator->numOfOutput; ++k) {
|
||||
for (int32_t k = 0; k < pOperator->numOfExprs; ++k) {
|
||||
int32_t functionId = pCtx[k].functionId;
|
||||
if (functionId != FUNCTION_TWA && functionId != FUNCTION_INTERP) {
|
||||
pCtx[k].start.key = INT64_MIN;
|
||||
|
@ -406,12 +406,12 @@ static bool setTimeWindowInterpolationStartTs(SOperatorInfo* pOperatorInfo, SqlF
|
|||
// start exactly from this point, no need to do interpolation
|
||||
TSKEY key = ascQuery ? win->skey : win->ekey;
|
||||
if (key == curTs) {
|
||||
setNotInterpoWindowKey(pCtx, pOperatorInfo->numOfOutput, RESULT_ROW_START_INTERP);
|
||||
setNotInterpoWindowKey(pCtx, pOperatorInfo->numOfExprs, RESULT_ROW_START_INTERP);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (lastTs == INT64_MIN && ((pos == 0 && ascQuery) || (pos == (numOfRows - 1) && !ascQuery))) {
|
||||
setNotInterpoWindowKey(pCtx, pOperatorInfo->numOfOutput, RESULT_ROW_START_INTERP);
|
||||
setNotInterpoWindowKey(pCtx, pOperatorInfo->numOfExprs, RESULT_ROW_START_INTERP);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -427,7 +427,7 @@ static bool setTimeWindowInterpolationEndTs(SOperatorInfo* pOperatorInfo, SqlFun
|
|||
SArray* pDataBlock, const TSKEY* tsCols, TSKEY blockEkey,
|
||||
STimeWindow* win) {
|
||||
int32_t order = TSDB_ORDER_ASC;
|
||||
int32_t numOfOutput = pOperatorInfo->numOfOutput;
|
||||
int32_t numOfOutput = pOperatorInfo->numOfExprs;
|
||||
|
||||
TSKEY actualEndKey = tsCols[endRowIndex];
|
||||
TSKEY key = order ? win->ekey : win->skey;
|
||||
|
@ -572,7 +572,7 @@ static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBloc
|
|||
setResultRowInterpo(pResult, RESULT_ROW_START_INTERP);
|
||||
}
|
||||
} else {
|
||||
setNotInterpoWindowKey(pCtx, pOperatorInfo->numOfOutput, RESULT_ROW_START_INTERP);
|
||||
setNotInterpoWindowKey(pCtx, pOperatorInfo->numOfExprs, RESULT_ROW_START_INTERP);
|
||||
}
|
||||
|
||||
// point interpolation does not require the end key time window interpolation.
|
||||
|
@ -592,7 +592,7 @@ static void doWindowBorderInterpolation(SOperatorInfo* pOperatorInfo, SSDataBloc
|
|||
setResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
|
||||
}
|
||||
} else {
|
||||
setNotInterpoWindowKey(pCtx, pOperatorInfo->numOfOutput, RESULT_ROW_END_INTERP);
|
||||
setNotInterpoWindowKey(pCtx, pOperatorInfo->numOfExprs, RESULT_ROW_END_INTERP);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -612,7 +612,7 @@ static SArray* hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe
|
|||
SIntervalAggOperatorInfo* pInfo = (SIntervalAggOperatorInfo*)pOperatorInfo->info;
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperatorInfo->pTaskInfo;
|
||||
int32_t numOfOutput = pOperatorInfo->numOfOutput;
|
||||
int32_t numOfOutput = pOperatorInfo->numOfExprs;
|
||||
|
||||
SArray* pUpdated = NULL;
|
||||
if (pInfo->execModel == OPTR_EXEC_MODEL_STREAM) {
|
||||
|
@ -683,7 +683,7 @@ static SArray* hashIntervalAgg(SOperatorInfo* pOperatorInfo, SResultRowInfo* pRe
|
|||
tsCols[startPos], startPos, w.ekey, RESULT_ROW_END_INTERP);
|
||||
|
||||
setResultRowInterpo(pResult, RESULT_ROW_END_INTERP);
|
||||
setNotInterpoWindowKey(pInfo->binfo.pCtx, pOperatorInfo->numOfOutput, RESULT_ROW_START_INTERP);
|
||||
setNotInterpoWindowKey(pInfo->binfo.pCtx, pOperatorInfo->numOfExprs, RESULT_ROW_START_INTERP);
|
||||
|
||||
doApplyFunctions(pInfo->binfo.pCtx, &w, &pInfo->timeWindowData, startPos, 0, tsCols, pSDataBlock->info.rows, numOfOutput, TSDB_ORDER_ASC);
|
||||
}
|
||||
|
@ -773,7 +773,7 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) {
|
|||
break;
|
||||
}
|
||||
|
||||
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->pCtx, pOperator->numOfOutput);
|
||||
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->pCtx, pOperator->numOfExprs);
|
||||
// the pDataBlock are always the same one, no need to call this again
|
||||
setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order, true);
|
||||
STableQueryInfo* pTableQueryInfo = pInfo->pCurrent;
|
||||
|
@ -798,7 +798,7 @@ static int32_t doOpenIntervalAgg(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
closeAllResultRows(&pInfo->binfo.resultRowInfo);
|
||||
finalizeMultiTupleQueryResult(pInfo->binfo.pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf,
|
||||
finalizeMultiTupleQueryResult(pInfo->binfo.pCtx, pOperator->numOfExprs, pInfo->aggSup.pResultBuf,
|
||||
&pInfo->binfo.resultRowInfo, pInfo->binfo.rowCellInfoOffset);
|
||||
|
||||
initGroupedResultInfo(&pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable, true);
|
||||
|
@ -813,7 +813,7 @@ static void doStateWindowAggImpl(SOperatorInfo* pOperator, SStateWindowOperatorI
|
|||
int64_t gid = pBlock->info.groupId;
|
||||
|
||||
bool masterScan = true;
|
||||
int32_t numOfOutput = pOperator->numOfOutput;
|
||||
int32_t numOfOutput = pOperator->numOfExprs;
|
||||
int16_t bytes = pStateColInfoData->info.bytes;
|
||||
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pInfo->tsSlotId);
|
||||
|
@ -916,7 +916,7 @@ static SSDataBlock* doStateWindowAgg(SOperatorInfo* pOperator) {
|
|||
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
closeAllResultRows(&pBInfo->resultRowInfo);
|
||||
finalizeMultiTupleQueryResult(pBInfo->pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, &pBInfo->resultRowInfo,
|
||||
finalizeMultiTupleQueryResult(pBInfo->pCtx, pOperator->numOfExprs, pInfo->aggSup.pResultBuf, &pBInfo->resultRowInfo,
|
||||
pBInfo->rowCellInfoOffset);
|
||||
|
||||
initGroupedResultInfo(&pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable, true);
|
||||
|
@ -1013,13 +1013,13 @@ static SSDataBlock* doStreamIntervalAgg(SOperatorInfo* pOperator) {
|
|||
// The timewindows that overlaps the timestamps of the input pBlock need to be recalculated and return to the
|
||||
// caller. Note that all the time window are not close till now.
|
||||
|
||||
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->pCtx, pOperator->numOfOutput);
|
||||
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->pCtx, pOperator->numOfExprs);
|
||||
// the pDataBlock are always the same one, no need to call this again
|
||||
setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order, true);
|
||||
pUpdated = hashIntervalAgg(pOperator, &pInfo->binfo.resultRowInfo, pBlock, 0);
|
||||
}
|
||||
|
||||
finalizeUpdatedResult(pOperator->numOfOutput, pInfo->aggSup.pResultBuf, pUpdated, pInfo->binfo.rowCellInfoOffset);
|
||||
finalizeUpdatedResult(pOperator->numOfExprs, pInfo->aggSup.pResultBuf, pUpdated, pInfo->binfo.rowCellInfoOffset);
|
||||
|
||||
initMultiResInfoFromArrayList(&pInfo->groupResInfo, pUpdated);
|
||||
blockDataEnsureCapacity(pInfo->binfo.pRes, pOperator->resultInfo.capacity);
|
||||
|
@ -1082,7 +1082,7 @@ SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
|||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->numOfOutput = numOfCols;
|
||||
pOperator->numOfExprs = numOfCols;
|
||||
pOperator->info = pInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doBuildIntervalResult, doStreamIntervalAgg, NULL,
|
||||
|
@ -1141,7 +1141,7 @@ SOperatorInfo* createStreamIntervalOperatorInfo(SOperatorInfo* downstream, SExpr
|
|||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->numOfOutput = numOfCols;
|
||||
pOperator->numOfExprs = numOfCols;
|
||||
pOperator->info = pInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(doOpenIntervalAgg, doStreamIntervalAgg, doStreamIntervalAgg, NULL,
|
||||
|
@ -1169,7 +1169,7 @@ static void doSessionWindowAggImpl(SOperatorInfo* pOperator, SSessionAggOperator
|
|||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, pInfo->tsSlotId);
|
||||
|
||||
bool masterScan = true;
|
||||
int32_t numOfOutput = pOperator->numOfOutput;
|
||||
int32_t numOfOutput = pOperator->numOfExprs;
|
||||
int64_t gid = pBlock->info.groupId;
|
||||
|
||||
int64_t gap = pInfo->gap;
|
||||
|
@ -1270,7 +1270,7 @@ static SSDataBlock* doSessionWindowAgg(SOperatorInfo* pOperator) {
|
|||
// restore the value
|
||||
pOperator->status = OP_RES_TO_RETURN;
|
||||
closeAllResultRows(&pBInfo->resultRowInfo);
|
||||
finalizeMultiTupleQueryResult(pBInfo->pCtx, pOperator->numOfOutput, pInfo->aggSup.pResultBuf, &pBInfo->resultRowInfo,
|
||||
finalizeMultiTupleQueryResult(pBInfo->pCtx, pOperator->numOfExprs, pInfo->aggSup.pResultBuf, &pBInfo->resultRowInfo,
|
||||
pBInfo->rowCellInfoOffset);
|
||||
|
||||
initGroupedResultInfo(&pInfo->groupResInfo, pInfo->aggSup.pResultRowHashTable, true);
|
||||
|
@ -1309,7 +1309,7 @@ static SSDataBlock* doAllIntervalAgg(SOperatorInfo* pOperator) {
|
|||
break;
|
||||
}
|
||||
|
||||
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pIntervalInfo->pCtx, pOperator->numOfOutput);
|
||||
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pIntervalInfo->pCtx, pOperator->numOfExprs);
|
||||
// the pDataBlock are always the same one, no need to call this again
|
||||
setInputDataBlock(pOperator, pSliceInfo->binfo.pCtx, pBlock, order, true);
|
||||
// hashAllIntervalAgg(pOperator, &pSliceInfo->binfo.resultRowInfo, pBlock, 0);
|
||||
|
@ -1319,7 +1319,7 @@ static SSDataBlock* doAllIntervalAgg(SOperatorInfo* pOperator) {
|
|||
pOperator->status = OP_RES_TO_RETURN;
|
||||
closeAllResultRows(&pSliceInfo->binfo.resultRowInfo);
|
||||
setTaskStatus(pOperator->pTaskInfo, TASK_COMPLETED);
|
||||
// finalizeQueryResult(pSliceInfo->binfo.pCtx, pOperator->numOfOutput);
|
||||
// finalizeQueryResult(pSliceInfo->binfo.pCtx, pOperator->numOfExprs);
|
||||
|
||||
// initGroupedResultInfo(&pSliceInfo->groupResInfo, &pSliceInfo->binfo.resultRowInfo);
|
||||
// doBuildResultDatablock(&pRuntimeEnv->groupResInfo, pRuntimeEnv, pSliceInfo->pRes);
|
||||
|
@ -1346,7 +1346,7 @@ SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo*
|
|||
pOperator->blocking = true;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->numOfOutput = numOfCols;
|
||||
pOperator->numOfExprs = numOfCols;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
|
@ -1388,7 +1388,7 @@ SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInf
|
|||
pOperator->blocking = true;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = pExpr;
|
||||
pOperator->numOfOutput = numOfCols;
|
||||
pOperator->numOfExprs = numOfCols;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
pOperator->info = pInfo;
|
||||
|
||||
|
@ -1440,7 +1440,7 @@ SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo
|
|||
pOperator->blocking = true;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->numOfOutput = numOfCols;
|
||||
pOperator->numOfExprs = numOfCols;
|
||||
pOperator->info = pInfo;
|
||||
|
||||
pOperator->fpSet = createOperatorFpSet(operatorDummyOpenFn, doSessionWindowAgg, NULL, NULL,
|
||||
|
|
|
@ -42,11 +42,7 @@ struct SSortHandle {
|
|||
|
||||
_sort_fetch_block_fn_t fetchfp;
|
||||
_sort_merge_compar_fn_t comparFn;
|
||||
|
||||
void *pParam;
|
||||
SMultiwayMergeTreeInfo *pMergeTree;
|
||||
int32_t numOfCols;
|
||||
|
||||
int64_t startTs;
|
||||
uint64_t sortElapsed;
|
||||
uint64_t totalElapsed;
|
||||
|
@ -61,6 +57,9 @@ struct SSortHandle {
|
|||
bool inMemSort;
|
||||
bool needAdjust;
|
||||
STupleHandle tupleHandle;
|
||||
|
||||
void *param;
|
||||
void (*beforeFp)(SSDataBlock* pBlock, void* param);
|
||||
};
|
||||
|
||||
static int32_t msortComparFn(const void *pLeft, const void *pRight, void *param);
|
||||
|
@ -533,6 +532,13 @@ static int32_t createInitialSortedMultiSources(SSortHandle* pHandle) {
|
|||
pHandle->pDataBlock = createOneDataBlock(pBlock, false);
|
||||
}
|
||||
|
||||
// perform the scalar function calculation before apply the sort
|
||||
if (pHandle->beforeFp != NULL) {
|
||||
pHandle->beforeFp(pBlock, pHandle->param);
|
||||
}
|
||||
|
||||
// todo relocate the columns
|
||||
|
||||
int32_t code = blockDataMerge(pHandle->pDataBlock, pBlock, pHandle->pIndexMap);
|
||||
if (code != 0) {
|
||||
return code;
|
||||
|
@ -623,8 +629,10 @@ int32_t tsortClose(SSortHandle* pHandle) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tsortSetFetchRawDataFp(SSortHandle* pHandle, _sort_fetch_block_fn_t fp) {
|
||||
pHandle->fetchfp = fp;
|
||||
int32_t tsortSetFetchRawDataFp(SSortHandle* pHandle, _sort_fetch_block_fn_t fetchFp, void (*fp)(SSDataBlock*, void*), void* param) {
|
||||
pHandle->fetchfp = fetchFp;
|
||||
pHandle->beforeFp = fp;
|
||||
pHandle->param = param;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
|
|
@ -210,7 +210,7 @@ TEST(testCase, inMem_sort_Test) {
|
|||
taosArrayPush(orderInfo, &oi);
|
||||
|
||||
SSortHandle* phandle = tsortCreateSortHandle(orderInfo, NULL, SORT_SINGLESOURCE_SORT, 1024, 5, NULL, "test_abc");
|
||||
tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock);
|
||||
tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock, NULL, NULL);
|
||||
|
||||
_info* pInfo = (_info*) taosMemoryCalloc(1, sizeof(_info));
|
||||
pInfo->startVal = 0;
|
||||
|
@ -299,7 +299,7 @@ TEST(testCase, external_mem_sort_Test) {
|
|||
taosArrayPush(orderInfo, &oi);
|
||||
|
||||
SSortHandle* phandle = tsortCreateSortHandle(orderInfo, NULL, SORT_SINGLESOURCE_SORT, 128, 3, NULL, "test_abc");
|
||||
tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock);
|
||||
tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock, NULL, NULL);
|
||||
|
||||
SSortSource* ps = static_cast<SSortSource*>(taosMemoryCalloc(1, sizeof(SSortSource)));
|
||||
ps->param = &pInfo[i];
|
||||
|
@ -366,7 +366,7 @@ TEST(testCase, ordered_merge_sort_Test) {
|
|||
}
|
||||
|
||||
SSortHandle* phandle = tsortCreateSortHandle(orderInfo, NULL, SORT_MULTISOURCE_MERGE, 1024, 5, pBlock,"test_abc");
|
||||
tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock);
|
||||
tsortSetFetchRawDataFp(phandle, getSingleColDummyBlock, NULL, NULL);
|
||||
tsortSetComparFp(phandle, docomp);
|
||||
|
||||
SSortSource* p[10] = {0};
|
||||
|
|
|
@ -48,8 +48,7 @@ target_include_directories(
|
|||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
udf1 PUBLIC os
|
||||
)
|
||||
udf1 PUBLIC os)
|
||||
|
||||
add_library(udf2 MODULE test/udf2.c)
|
||||
target_include_directories(
|
||||
|
|
|
@ -19,9 +19,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
//TODO replaces them with fnDebug
|
||||
//#define debugPrint(...) taosPrintLog("Function", DEBUG_INFO, 135, __VA_ARGS__)
|
||||
#define debugPrint(...) {fprintf(stderr, __VA_ARGS__);fprintf(stderr, "\n");}
|
||||
enum {
|
||||
UDF_TASK_SETUP = 0,
|
||||
UDF_TASK_CALL = 1,
|
||||
|
@ -107,7 +104,7 @@ void* decodeUdfRequest(const void *buf, SUdfRequest* request);
|
|||
int32_t encodeUdfResponse(void **buf, const SUdfResponse *response);
|
||||
void* decodeUdfResponse(const void* buf, SUdfResponse *response);
|
||||
|
||||
void freeUdfColumnData(SUdfColumnData *data);
|
||||
void freeUdfColumnData(SUdfColumnData *data, SUdfColumnMeta *meta);
|
||||
void freeUdfColumn(SUdfColumn* col);
|
||||
void freeUdfDataDataBlock(SUdfDataBlock *block);
|
||||
|
||||
|
|
|
@ -913,7 +913,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "tbname",
|
||||
.type = FUNCTION_TYPE_TBNAME,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC,
|
||||
.classification = FUNC_MGT_PSEUDO_COLUMN_FUNC | FUNC_MGT_SCAN_PC_FUNC,
|
||||
.translateFunc = translateTbnameColumn,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
|
|
|
@ -481,8 +481,8 @@ void* decodeUdfResponse(const void* buf, SUdfResponse* rsp) {
|
|||
return (void*)buf;
|
||||
}
|
||||
|
||||
void freeUdfColumnData(SUdfColumnData *data) {
|
||||
if (data->varLengthColumn) {
|
||||
void freeUdfColumnData(SUdfColumnData *data, SUdfColumnMeta *meta) {
|
||||
if (IS_VAR_DATA_TYPE(meta->type)) {
|
||||
taosMemoryFree(data->varLenCol.varOffsets);
|
||||
data->varLenCol.varOffsets = NULL;
|
||||
taosMemoryFree(data->varLenCol.payload);
|
||||
|
@ -496,7 +496,7 @@ void freeUdfColumnData(SUdfColumnData *data) {
|
|||
}
|
||||
|
||||
void freeUdfColumn(SUdfColumn* col) {
|
||||
freeUdfColumnData(&col->colData);
|
||||
freeUdfColumnData(&col->colData, &col->colMeta);
|
||||
}
|
||||
|
||||
void freeUdfDataDataBlock(SUdfDataBlock *block) {
|
||||
|
@ -528,8 +528,7 @@ int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlo
|
|||
udfCol->colMeta.scale = col->info.scale;
|
||||
udfCol->colMeta.precision = col->info.precision;
|
||||
udfCol->colData.numOfRows = udfBlock->numOfRows;
|
||||
udfCol->colData.varLengthColumn = IS_VAR_DATA_TYPE(udfCol->colMeta.type);
|
||||
if (udfCol->colData.varLengthColumn) {
|
||||
if (IS_VAR_DATA_TYPE(udfCol->colMeta.type)) {
|
||||
udfCol->colData.varLenCol.varOffsetsLen = sizeof(int32_t) * udfBlock->numOfRows;
|
||||
udfCol->colData.varLenCol.varOffsets = taosMemoryMalloc(udfCol->colData.varLenCol.varOffsetsLen);
|
||||
memcpy(udfCol->colData.varLenCol.varOffsets, col->varmeta.offset, udfCol->colData.varLenCol.varOffsetsLen);
|
||||
|
@ -555,7 +554,7 @@ int32_t convertDataBlockToUdfDataBlock(SSDataBlock *block, SUdfDataBlock *udfBlo
|
|||
int32_t convertUdfColumnToDataBlock(SUdfColumn *udfCol, SSDataBlock *block) {
|
||||
block->info.numOfCols = 1;
|
||||
block->info.rows = udfCol->colData.numOfRows;
|
||||
block->info.hasVarCol = udfCol->colData.varLengthColumn;
|
||||
block->info.hasVarCol = IS_VAR_DATA_TYPE(udfCol->colMeta.type);
|
||||
|
||||
block->pDataBlock = taosArrayInit(1, sizeof(SColumnInfoData));
|
||||
taosArraySetSize(block->pDataBlock, 1);
|
||||
|
|
|
@ -75,8 +75,8 @@ typedef struct SUdf {
|
|||
char path[PATH_MAX];
|
||||
|
||||
uv_lib_t lib;
|
||||
|
||||
TUdfScalarProcFunc scalarProcFunc;
|
||||
TUdfFreeUdfColumnFunc freeUdfColumn;
|
||||
|
||||
TUdfAggStartFunc aggStartFunc;
|
||||
TUdfAggProcessFunc aggProcFunc;
|
||||
|
@ -106,11 +106,6 @@ int32_t udfdLoadUdf(char *udfName, SUdf *udf) {
|
|||
char processFuncName[TSDB_FUNC_NAME_LEN] = {0};
|
||||
strcpy(processFuncName, udfName);
|
||||
uv_dlsym(&udf->lib, processFuncName, (void **)(&udf->scalarProcFunc));
|
||||
char freeFuncName[TSDB_FUNC_NAME_LEN + 5] = {0};
|
||||
char *freeSuffix = "_free";
|
||||
strncpy(freeFuncName, processFuncName, strlen(processFuncName));
|
||||
strncat(freeFuncName, freeSuffix, strlen(freeSuffix));
|
||||
uv_dlsym(&udf->lib, freeFuncName, (void **)(&udf->freeUdfColumn));
|
||||
} else if (udf->funcType == TSDB_FUNC_TYPE_AGGREGATE) {
|
||||
char processFuncName[TSDB_FUNC_NAME_LEN] = {0};
|
||||
strcpy(processFuncName, udfName);
|
||||
|
@ -215,7 +210,7 @@ void udfdProcessRequest(uv_work_t *req) {
|
|||
udf->scalarProcFunc(&input, &output);
|
||||
|
||||
convertUdfColumnToDataBlock(&output, &response.callRsp.resultData);
|
||||
udf->freeUdfColumn(&output);
|
||||
freeUdfColumn(&output);
|
||||
break;
|
||||
}
|
||||
case TSDB_UDF_CALL_AGG_INIT: {
|
||||
|
|
|
@ -18,52 +18,20 @@ int32_t udf1_destroy() {
|
|||
}
|
||||
|
||||
int32_t udf1(SUdfDataBlock* block, SUdfColumn *resultCol) {
|
||||
SUdfColumnData *resultData = &resultCol->colData;
|
||||
resultData->numOfRows = block->numOfRows;
|
||||
SUdfColumnData *srcData = &block->udfCols[0]->colData;
|
||||
resultData->varLengthColumn = srcData->varLengthColumn;
|
||||
|
||||
if (resultData->varLengthColumn) {
|
||||
resultData->varLenCol.varOffsetsLen = srcData->varLenCol.varOffsetsLen;
|
||||
resultData->varLenCol.varOffsets = malloc(resultData->varLenCol.varOffsetsLen);
|
||||
memcpy(resultData->varLenCol.varOffsets, srcData->varLenCol.varOffsets, srcData->varLenCol.varOffsetsLen);
|
||||
|
||||
resultData->varLenCol.payloadLen = srcData->varLenCol.payloadLen;
|
||||
resultData->varLenCol.payload = malloc(resultData->varLenCol.payloadLen);
|
||||
memcpy(resultData->varLenCol.payload, srcData->varLenCol.payload, srcData->varLenCol.payloadLen);
|
||||
} else {
|
||||
resultData->fixLenCol.nullBitmapLen = srcData->fixLenCol.nullBitmapLen;
|
||||
resultData->fixLenCol.nullBitmap = malloc(resultData->fixLenCol.nullBitmapLen);
|
||||
memcpy(resultData->fixLenCol.nullBitmap, srcData->fixLenCol.nullBitmap, srcData->fixLenCol.nullBitmapLen);
|
||||
|
||||
resultData->fixLenCol.dataLen = srcData->fixLenCol.dataLen;
|
||||
resultData->fixLenCol.data = malloc(resultData->fixLenCol.dataLen);
|
||||
memcpy(resultData->fixLenCol.data, srcData->fixLenCol.data, srcData->fixLenCol.dataLen);
|
||||
for (int32_t i = 0; i < resultData->numOfRows; ++i) {
|
||||
*(resultData->fixLenCol.data + i * sizeof(int32_t)) = 88;
|
||||
}
|
||||
}
|
||||
|
||||
SUdfColumnMeta *meta = &resultCol->colMeta;
|
||||
meta->bytes = 4;
|
||||
meta->type = TSDB_DATA_TYPE_INT;
|
||||
meta->scale = 0;
|
||||
meta->precision = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t udf1_free(SUdfColumn *col) {
|
||||
SUdfColumnData *data = &col->colData;
|
||||
if (data->varLengthColumn) {
|
||||
free(data->varLenCol.varOffsets);
|
||||
data->varLenCol.varOffsets = NULL;
|
||||
free(data->varLenCol.payload);
|
||||
data->varLenCol.payload = NULL;
|
||||
} else {
|
||||
free(data->fixLenCol.nullBitmap);
|
||||
data->fixLenCol.nullBitmap = NULL;
|
||||
free(data->fixLenCol.data);
|
||||
data->fixLenCol.data = NULL;
|
||||
SUdfColumnData *resultData = &resultCol->colData;
|
||||
resultData->numOfRows = block->numOfRows;
|
||||
SUdfColumnData *srcData = &block->udfCols[0]->colData;
|
||||
|
||||
for (int32_t i = 0; i < resultData->numOfRows; ++i) {
|
||||
int32_t luckyNum = 88;
|
||||
udfColSetRow(resultCol, i, (char*)&luckyNum, false);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -52,7 +52,6 @@ typedef struct FstRange {
|
|||
uint64_t end;
|
||||
} FstRange;
|
||||
|
||||
typedef enum { GE, GT, LE, LT } RangeType;
|
||||
typedef enum { OneTransNext, OneTrans, AnyTrans, EmptyFinal } State;
|
||||
typedef enum { Ordered, OutOfOrdered, DuplicateKey } OrderType;
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef enum { LT, LE, GT, GE } RangeType;
|
||||
typedef enum { kTypeValue, kTypeDeletion } STermValueType;
|
||||
|
||||
typedef struct SIndexStat {
|
||||
|
@ -86,7 +87,6 @@ typedef struct SIndexTerm {
|
|||
int32_t nColName;
|
||||
char* colVal;
|
||||
int32_t nColVal;
|
||||
int8_t qType; // just use for range
|
||||
} SIndexTerm;
|
||||
|
||||
typedef struct SIndexTermQuery {
|
||||
|
|
|
@ -262,7 +262,6 @@ SIndexTerm* indexTermCreate(int64_t suid, SIndexOperOnColumn oper, int8_t queryT
|
|||
tm->colVal = (char*)taosMemoryCalloc(1, nColVal + 1);
|
||||
memcpy(tm->colVal, colVal, nColVal);
|
||||
tm->nColVal = nColVal;
|
||||
tm->qType = queryType;
|
||||
|
||||
return tm;
|
||||
}
|
||||
|
|
|
@ -38,10 +38,29 @@ static int32_t cacheSearchTerm(void* cache, CacheTerm* ct, SIdxTempResult* tr, S
|
|||
static int32_t cacheSearchPrefix(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s);
|
||||
static int32_t cacheSearchSuffix(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s);
|
||||
static int32_t cacheSearchRegex(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s);
|
||||
static int32_t cacheSearchLessThan(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s);
|
||||
static int32_t cacheSearchLessEqual(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s);
|
||||
static int32_t cacheSearchGreaterThan(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s);
|
||||
static int32_t cacheSearchGreaterEqual(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s);
|
||||
static int32_t cacheSearchRange(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s);
|
||||
/*comm func of compare, used in (LE/LT/GE/GT compare)*/
|
||||
static int32_t cacheSearchCompareFunc(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s,
|
||||
RangeType type);
|
||||
|
||||
typedef enum { MATCH, CONTINUE, BREAK } TExeCond;
|
||||
typedef TExeCond (*_cache_range_compare)(void* a, void* b, int8_t type);
|
||||
|
||||
static TExeCond tCompareLessThan(void* a, void* b, int8_t type) { return MATCH; }
|
||||
static TExeCond tCompareLessEqual(void* a, void* b, int8_t type) { return MATCH; }
|
||||
static TExeCond tCompareGreaterThan(void* a, void* b, int8_t type) { return MATCH; }
|
||||
static TExeCond tCompareGreaterEqual(void* a, void* b, int8_t type) { return MATCH; }
|
||||
|
||||
static TExeCond (*rangeCompare[])(void* a, void* b, int8_t type) = {tCompareLessThan, tCompareLessEqual,
|
||||
tCompareGreaterThan, tCompareGreaterEqual};
|
||||
|
||||
static int32_t (*cacheSearch[])(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s) = {
|
||||
cacheSearchTerm, cacheSearchPrefix, cacheSearchSuffix, cacheSearchRegex, cacheSearchRange};
|
||||
cacheSearchTerm, cacheSearchPrefix, cacheSearchSuffix, cacheSearchRegex, cacheSearchLessThan,
|
||||
cacheSearchLessEqual, cacheSearchGreaterThan, cacheSearchGreaterEqual, cacheSearchRange};
|
||||
|
||||
static void doMergeWork(SSchedMsg* msg);
|
||||
static bool indexCacheIteratorNext(Iterate* itera);
|
||||
|
@ -88,6 +107,52 @@ static int32_t cacheSearchRegex(void* cache, CacheTerm* ct, SIdxTempResult* tr,
|
|||
// impl later
|
||||
return 0;
|
||||
}
|
||||
static int32_t cacheSearchCompareFunc(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s,
|
||||
RangeType type) {
|
||||
if (cache == NULL) {
|
||||
return 0;
|
||||
}
|
||||
_cache_range_compare cmpFn = rangeCompare[type];
|
||||
|
||||
MemTable* mem = cache;
|
||||
char* key = indexCacheTermGet(ct);
|
||||
|
||||
SSkipListIterator* iter = tSkipListCreateIter(mem->mem);
|
||||
while (tSkipListIterNext(iter)) {
|
||||
SSkipListNode* node = tSkipListIterGet(iter);
|
||||
if (node == NULL) {
|
||||
break;
|
||||
}
|
||||
CacheTerm* c = (CacheTerm*)SL_GET_NODE_DATA(node);
|
||||
TExeCond cond = cmpFn(c->colVal, ct->colVal, ct->colType);
|
||||
if (cond == MATCH) {
|
||||
if (c->operaType == ADD_VALUE) {
|
||||
INDEX_MERGE_ADD_DEL(tr->deled, tr->added, c->uid)
|
||||
// taosArrayPush(result, &c->uid);
|
||||
*s = kTypeValue;
|
||||
} else if (c->operaType == DEL_VALUE) {
|
||||
INDEX_MERGE_ADD_DEL(tr->added, tr->deled, c->uid)
|
||||
}
|
||||
} else if (cond == CONTINUE) {
|
||||
} else if (cond == BREAK) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
tSkipListDestroyIter(iter);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t cacheSearchLessThan(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s) {
|
||||
return cacheSearchCompareFunc(cache, ct, tr, s, LT);
|
||||
}
|
||||
static int32_t cacheSearchLessEqual(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s) {
|
||||
return cacheSearchCompareFunc(cache, ct, tr, s, LE);
|
||||
}
|
||||
static int32_t cacheSearchGreaterThan(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s) {
|
||||
return cacheSearchCompareFunc(cache, ct, tr, s, GT);
|
||||
}
|
||||
static int32_t cacheSearchGreaterEqual(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s) {
|
||||
return cacheSearchCompareFunc(cache, ct, tr, s, GE);
|
||||
}
|
||||
static int32_t cacheSearchRange(void* cache, CacheTerm* ct, SIdxTempResult* tr, STermValueType* s) {
|
||||
// impl later
|
||||
return 0;
|
||||
|
|
|
@ -64,10 +64,17 @@ static int32_t tfSearchTerm(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
|||
static int32_t tfSearchPrefix(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchSuffix(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchRegex(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchLessThan(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchLessEqual(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchGreaterThan(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchGreaterEqual(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchRange(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
|
||||
static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTempResult* tr, RangeType ctype);
|
||||
|
||||
static int32_t (*tfSearch[])(void* reader, SIndexTerm* tem, SIdxTempResult* tr) = {
|
||||
tfSearchTerm, tfSearchPrefix, tfSearchSuffix, tfSearchRegex, tfSearchRange};
|
||||
tfSearchTerm, tfSearchPrefix, tfSearchSuffix, tfSearchRegex, tfSearchLessThan,
|
||||
tfSearchLessEqual, tfSearchGreaterThan, tfSearchGreaterEqual, tfSearchRange};
|
||||
|
||||
TFileCache* tfileCacheCreate(const char* path) {
|
||||
TFileCache* tcache = taosMemoryCalloc(1, sizeof(TFileCache));
|
||||
|
@ -299,6 +306,47 @@ static int32_t tfSearchRegex(void* reader, SIndexTerm* tem, SIdxTempResult* tr)
|
|||
fstSliceDestroy(&key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTempResult* tr, RangeType type) {
|
||||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON);
|
||||
int ret = 0;
|
||||
char* p = tem->colVal;
|
||||
uint64_t sz = tem->nColVal;
|
||||
if (hasJson) {
|
||||
p = indexPackJsonData(tem);
|
||||
sz = strlen(p);
|
||||
}
|
||||
SArray* offsets = taosArrayInit(16, sizeof(uint64_t));
|
||||
|
||||
AutomationCtx* ctx = automCtxCreate((void*)p, AUTOMATION_ALWAYS);
|
||||
FstStreamBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx);
|
||||
|
||||
FstSlice h = fstSliceCreate((uint8_t*)p, sz);
|
||||
fstStreamBuilderSetRange(sb, &h, type);
|
||||
fstSliceDestroy(&h);
|
||||
|
||||
StreamWithState* st = streamBuilderIntoStream(sb);
|
||||
StreamWithStateResult* rt = NULL;
|
||||
while ((rt = streamWithStateNextWith(st, NULL)) != NULL) {
|
||||
taosArrayPush(offsets, &(rt->out.out));
|
||||
swsResultDestroy(rt);
|
||||
}
|
||||
streamWithStateDestroy(st);
|
||||
fstStreamBuilderDestroy(sb);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t tfSearchLessThan(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
return tfSearchCompareFunc(reader, tem, tr, LT);
|
||||
}
|
||||
static int32_t tfSearchLessEqual(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
return tfSearchCompareFunc(reader, tem, tr, LE);
|
||||
}
|
||||
static int32_t tfSearchGreaterThan(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
return tfSearchCompareFunc(reader, tem, tr, GT);
|
||||
}
|
||||
static int32_t tfSearchGreaterEqual(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
return tfSearchCompareFunc(reader, tem, tr, GE);
|
||||
}
|
||||
static int32_t tfSearchRange(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
bool hasJson = INDEX_TYPE_CONTAIN_EXTERN_TYPE(tem->colType, TSDB_DATA_TYPE_JSON);
|
||||
int ret = 0;
|
||||
|
|
|
@ -1971,7 +1971,18 @@ static int32_t datumToJson(const void* pObj, SJson* pJson) {
|
|||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
code = tjsonAddDoubleToObject(pJson, jkValueDatum, pNode->datum.d);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
//cJSON only support utf-8 encoding. Convert memory content to hex string.
|
||||
char *buf = taosMemoryCalloc(varDataLen(pNode->datum.p) * 2 + 1, sizeof(char));
|
||||
code = taosHexEncode(varDataVal(pNode->datum.p), buf, varDataLen(pNode->datum.p));
|
||||
if(code != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFree(buf);
|
||||
return TSDB_CODE_TSC_INVALID_VALUE;
|
||||
}
|
||||
code = tjsonAddStringToObject(pJson, jkValueDatum, buf);
|
||||
taosMemoryFree(buf);
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
code = tjsonAddStringToObject(pJson, jkValueDatum, varDataVal(pNode->datum.p));
|
||||
|
@ -2074,7 +2085,26 @@ static int32_t jsonToDatum(const SJson* pJson, void* pObj) {
|
|||
break;
|
||||
}
|
||||
varDataSetLen(pNode->datum.p, pNode->node.resType.bytes);
|
||||
if (TSDB_DATA_TYPE_NCHAR == pNode->node.resType.type) {
|
||||
char *buf = taosMemoryCalloc(1, pNode->node.resType.bytes * 2 + VARSTR_HEADER_SIZE + 1);
|
||||
if (NULL == buf) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
break;
|
||||
}
|
||||
code = tjsonGetStringValue(pJson, jkValueDatum, buf);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFree(buf);
|
||||
break;
|
||||
}
|
||||
code = taosHexDecode(buf, varDataVal(pNode->datum.p), pNode->node.resType.bytes - VARSTR_HEADER_SIZE);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
taosMemoryFree(buf);
|
||||
break;
|
||||
}
|
||||
taosMemoryFree(buf);
|
||||
} else {
|
||||
code = tjsonGetStringValue(pJson, jkValueDatum, varDataVal(pNode->datum.p));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
|
|
|
@ -363,10 +363,8 @@ SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType d
|
|||
CHECK_OUT_OF_MEM(func);
|
||||
strcpy(func->functionName, "cast");
|
||||
func->node.resType = dt;
|
||||
if (TSDB_DATA_TYPE_BINARY == dt.type) {
|
||||
func->node.resType.bytes += 2;
|
||||
} else if (TSDB_DATA_TYPE_NCHAR == dt.type) {
|
||||
func->node.resType.bytes = func->node.resType.bytes * TSDB_NCHAR_SIZE + 2;
|
||||
if (TSDB_DATA_TYPE_NCHAR == dt.type) {
|
||||
func->node.resType.bytes = func->node.resType.bytes * TSDB_NCHAR_SIZE;
|
||||
}
|
||||
nodesListMakeAppend(&func->pParameterList, pExpr);
|
||||
return (SNode*)func;
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
#include "ttime.h"
|
||||
#include "ttypes.h"
|
||||
|
||||
// clang-format off
|
||||
#define NEXT_TOKEN(pSql, sToken) \
|
||||
do { \
|
||||
int32_t index = 0; \
|
||||
|
@ -248,12 +247,11 @@ static int32_t getTableMetaImpl(SInsertParseContext* pCxt, SToken* pTname, bool
|
|||
} else {
|
||||
CHECK_CODE(catalogGetTableMeta(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name,
|
||||
&pCxt->pTableMeta));
|
||||
}
|
||||
SVgroupInfo vg;
|
||||
CHECK_CODE(
|
||||
catalogGetTableHashVgroup(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name, &vg));
|
||||
CHECK_CODE(taosHashPut(pCxt->pVgroupsHashObj, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg)));
|
||||
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -828,12 +826,21 @@ static int32_t cloneTableMeta(STableMeta* pSrc, STableMeta** pDst) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t storeTableMeta(SHashObj* pHash, const char* pName, int32_t len, STableMeta* pMeta) {
|
||||
static int32_t storeTableMeta(SInsertParseContext* pCxt, SHashObj* pHash, SName* pTableName, const char* pName,
|
||||
int32_t len, STableMeta* pMeta) {
|
||||
SVgroupInfo vg;
|
||||
SParseContext* pBasicCtx = pCxt->pComCxt;
|
||||
CHECK_CODE(
|
||||
catalogGetTableHashVgroup(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, pTableName, &vg));
|
||||
CHECK_CODE(taosHashPut(pCxt->pVgroupsHashObj, (const char*)&vg.vgId, sizeof(vg.vgId), (char*)&vg, sizeof(vg)));
|
||||
|
||||
pMeta->uid = tGenIdPI64();
|
||||
pMeta->vgId = vg.vgId;
|
||||
|
||||
STableMeta* pBackup = NULL;
|
||||
if (TSDB_CODE_SUCCESS != cloneTableMeta(pMeta, &pBackup)) {
|
||||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
pBackup->uid = tGenIdPI64();
|
||||
return taosHashPut(pHash, pName, len, &pBackup, POINTER_BYTES);
|
||||
}
|
||||
|
||||
|
@ -856,7 +863,7 @@ static int32_t parseUsingClause(SInsertParseContext* pCxt, SToken* pTbnameToken)
|
|||
if (TSDB_SUPER_TABLE != pCxt->pTableMeta->tableType) {
|
||||
return buildInvalidOperationMsg(&pCxt->msg, "create table only from super table is allowed");
|
||||
}
|
||||
CHECK_CODE(storeTableMeta(pCxt->pSubTableHashObj, tbFName, len, pCxt->pTableMeta));
|
||||
CHECK_CODE(storeTableMeta(pCxt, pCxt->pSubTableHashObj, &name, tbFName, len, pCxt->pTableMeta));
|
||||
|
||||
SSchema* pTagsSchema = getTableTagSchema(pCxt->pTableMeta);
|
||||
setBoundColumnInfo(&pCxt->tags, pTagsSchema, getNumOfTags(pCxt->pTableMeta));
|
||||
|
@ -1043,6 +1050,7 @@ static void destroyDataBlock(STableDataBlocks* pDataBlock) {
|
|||
static void destroyInsertParseContext(SInsertParseContext* pCxt) {
|
||||
destroyInsertParseContextForTable(pCxt);
|
||||
taosHashCleanup(pCxt->pVgroupsHashObj);
|
||||
taosHashCleanup(pCxt->pSubTableHashObj);
|
||||
|
||||
destroyBlockHashmap(pCxt->pTableBlockHashObj);
|
||||
destroyBlockArrayList(pCxt->pVgDataBlocks);
|
||||
|
@ -1261,8 +1269,9 @@ int32_t qBuildStmtOutput(SQuery* pQuery, SHashObj* pVgHash, SHashObj* pBlockHash
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *pName, TAOS_MULTI_BIND *bind, char *msgBuf, int32_t msgBufLen){
|
||||
STableDataBlocks *pDataBlock = (STableDataBlocks *)pBlock;
|
||||
int32_t qBindStmtTagsValue(void* pBlock, void* boundTags, int64_t suid, SName* pName, TAOS_MULTI_BIND* bind,
|
||||
char* msgBuf, int32_t msgBufLen) {
|
||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||
SMsgBuf pBuf = {.buf = msgBuf, .len = msgBufLen};
|
||||
SParsedDataColInfo* tags = (SParsedDataColInfo*)boundTags;
|
||||
if (NULL == tags) {
|
||||
|
@ -1311,9 +1320,8 @@ int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, SName *p
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int32_t qBindStmtColsValue(void *pBlock, TAOS_MULTI_BIND *bind, char *msgBuf, int32_t msgBufLen) {
|
||||
STableDataBlocks *pDataBlock = (STableDataBlocks *)pBlock;
|
||||
int32_t qBindStmtColsValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen) {
|
||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta);
|
||||
int32_t extendedRowSize = getExtendedRowSize(pDataBlock);
|
||||
SParsedDataColInfo* spd = &pDataBlock->boundColumnInfo;
|
||||
|
@ -1390,8 +1398,9 @@ int32_t qBindStmtColsValue(void *pBlock, TAOS_MULTI_BIND *bind, char *msgBuf, in
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t qBindStmtSingleColValue(void *pBlock, TAOS_MULTI_BIND *bind, char *msgBuf, int32_t msgBufLen, int32_t colIdx, int32_t rowNum) {
|
||||
STableDataBlocks *pDataBlock = (STableDataBlocks *)pBlock;
|
||||
int32_t qBindStmtSingleColValue(void* pBlock, TAOS_MULTI_BIND* bind, char* msgBuf, int32_t msgBufLen, int32_t colIdx,
|
||||
int32_t rowNum) {
|
||||
STableDataBlocks* pDataBlock = (STableDataBlocks*)pBlock;
|
||||
SSchema* pSchema = getTableColumnSchema(pDataBlock->pTableMeta);
|
||||
int32_t extendedRowSize = getExtendedRowSize(pDataBlock);
|
||||
SParsedDataColInfo* spd = &pDataBlock->boundColumnInfo;
|
||||
|
@ -1458,7 +1467,7 @@ int32_t qBindStmtSingleColValue(void *pBlock, TAOS_MULTI_BIND *bind, char *msgBu
|
|||
}
|
||||
|
||||
#ifdef TD_DEBUG_PRINT_ROW
|
||||
if(rowEnd) {
|
||||
if (rowEnd) {
|
||||
STSchema* pSTSchema = tdGetSTSChemaFromSSChema(&pSchema, spd->numOfCols);
|
||||
tdSRowPrint(row, pSTSchema, __func__);
|
||||
taosMemoryFree(pSTSchema);
|
||||
|
|
|
@ -498,14 +498,9 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
|
|||
ASSERT(blkKeyInfo.pKeyTuple != NULL && pBlocks->numOfRows > 0);
|
||||
}
|
||||
|
||||
int32_t len = pBlocks->numOfRows *
|
||||
(isRawPayload ? (pOneTableBlock->rowSize + expandSize) : getExtendedRowSize(pOneTableBlock)) +
|
||||
sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta);
|
||||
|
||||
// erase the empty space reserved for binary data
|
||||
int32_t finalLen =
|
||||
trimDataBlock(dataBuf->pData + dataBuf->size, pOneTableBlock, blkKeyInfo.pKeyTuple, isRawPayload);
|
||||
assert(finalLen <= len);
|
||||
|
||||
dataBuf->size += (finalLen + sizeof(SSubmitBlk));
|
||||
assert(dataBuf->size <= dataBuf->nAllocSize);
|
||||
|
|
|
@ -4062,6 +4062,7 @@ static int32_t setQuery(STranslateContext* pCxt, SQuery* pQuery) {
|
|||
|
||||
int32_t translate(SParseContext* pParseCxt, SQuery* pQuery) {
|
||||
STranslateContext cxt = {0};
|
||||
|
||||
int32_t code = initTranslateContext(pParseCxt, &cxt);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = fmFuncMgtInit();
|
||||
|
|
|
@ -100,6 +100,17 @@ void generateInformationSchema(MockCatalogService* mcs) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Table:t1
|
||||
* Field | Type | DataType | Bytes |
|
||||
* ==========================================================================
|
||||
* ts | column | TIMESTAMP | 8 |
|
||||
* c1 | column | INT | 4 |
|
||||
* c2 | column | VARCHAR | 20 |
|
||||
* c3 | column | BIGINT | 8 |
|
||||
* c4 | column | DOUBLE | 8 |
|
||||
* c5 | column | DOUBLE | 8 |
|
||||
*/
|
||||
void generateTestT1(MockCatalogService* mcs) {
|
||||
ITableBuilder& builder = mcs->createTableBuilder("test", "t1", TSDB_NORMAL_TABLE, 6)
|
||||
.setPrecision(TSDB_TIME_PRECISION_MILLI)
|
||||
|
@ -113,6 +124,17 @@ void generateTestT1(MockCatalogService* mcs) {
|
|||
builder.done();
|
||||
}
|
||||
|
||||
/*
|
||||
* Super Table: st1
|
||||
* Field | Type | DataType | Bytes |
|
||||
* ==========================================================================
|
||||
* ts | column | TIMESTAMP | 8 |
|
||||
* c1 | column | INT | 4 |
|
||||
* c2 | column | VARCHAR | 20 |
|
||||
* tag1 | tag | INT | 4 |
|
||||
* tag2 | tag | VARCHAR | 20 |
|
||||
* Child Table: st1s1, st1s2
|
||||
*/
|
||||
void generateTestST1(MockCatalogService* mcs) {
|
||||
ITableBuilder& builder = mcs->createTableBuilder("test", "st1", TSDB_SUPER_TABLE, 3, 2)
|
||||
.setPrecision(TSDB_TIME_PRECISION_MILLI)
|
||||
|
|
|
@ -23,4 +23,6 @@ TEST_F(PlanSuperTableTest, tbname) {
|
|||
useDb("root", "test");
|
||||
|
||||
run("select tbname from st1");
|
||||
|
||||
run("select tbname, tag1, tag2 from st1");
|
||||
}
|
||||
|
|
|
@ -36,11 +36,11 @@ class PlannerEnv : public testing::Environment {
|
|||
static void parseArg(int argc, char* argv[]) {
|
||||
int opt = 0;
|
||||
const char* optstring = "";
|
||||
static struct option long_options[] = {{"dump", no_argument, NULL, 'd'}, {0, 0, 0, 0}};
|
||||
static struct option long_options[] = {{"dump", optional_argument, NULL, 'd'}, {0, 0, 0, 0}};
|
||||
while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
g_isDump = true;
|
||||
setDumpModule(optarg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
|
@ -34,7 +34,41 @@ using namespace testing;
|
|||
} \
|
||||
} while (0);
|
||||
|
||||
bool g_isDump = false;
|
||||
enum DumpModule {
|
||||
DUMP_MODULE_NOTHING = 1,
|
||||
DUMP_MODULE_PARSER,
|
||||
DUMP_MODULE_LOGIC,
|
||||
DUMP_MODULE_OPTIMIZED,
|
||||
DUMP_MODULE_SPLIT,
|
||||
DUMP_MODULE_SCALED,
|
||||
DUMP_MODULE_PHYSICAL,
|
||||
DUMP_MODULE_SUBPLAN,
|
||||
DUMP_MODULE_ALL
|
||||
};
|
||||
|
||||
DumpModule g_dumpModule = DUMP_MODULE_NOTHING;
|
||||
|
||||
void setDumpModule(const char* pModule) {
|
||||
if (NULL == pModule) {
|
||||
g_dumpModule = DUMP_MODULE_ALL;
|
||||
} else if (0 == strncasecmp(pModule, "parser", strlen(pModule))) {
|
||||
g_dumpModule = DUMP_MODULE_PARSER;
|
||||
} else if (0 == strncasecmp(pModule, "logic", strlen(pModule))) {
|
||||
g_dumpModule = DUMP_MODULE_LOGIC;
|
||||
} else if (0 == strncasecmp(pModule, "optimized", strlen(pModule))) {
|
||||
g_dumpModule = DUMP_MODULE_OPTIMIZED;
|
||||
} else if (0 == strncasecmp(pModule, "split", strlen(pModule))) {
|
||||
g_dumpModule = DUMP_MODULE_SPLIT;
|
||||
} else if (0 == strncasecmp(pModule, "scaled", strlen(pModule))) {
|
||||
g_dumpModule = DUMP_MODULE_SCALED;
|
||||
} else if (0 == strncasecmp(pModule, "physical", strlen(pModule))) {
|
||||
g_dumpModule = DUMP_MODULE_PHYSICAL;
|
||||
} else if (0 == strncasecmp(pModule, "subplan", strlen(pModule))) {
|
||||
g_dumpModule = DUMP_MODULE_SUBPLAN;
|
||||
} else if (0 == strncasecmp(pModule, "all", strlen(pModule))) {
|
||||
g_dumpModule = DUMP_MODULE_PHYSICAL;
|
||||
}
|
||||
}
|
||||
|
||||
class PlannerTestBaseImpl {
|
||||
public:
|
||||
|
@ -66,11 +100,9 @@ class PlannerTestBaseImpl {
|
|||
SQueryPlan* pPlan = nullptr;
|
||||
doCreatePhysiPlan(&cxt, pLogicPlan, &pPlan);
|
||||
|
||||
if (g_isDump) {
|
||||
dump();
|
||||
}
|
||||
dump(g_dumpModule);
|
||||
} catch (...) {
|
||||
dump();
|
||||
dump(DUMP_MODULE_ALL);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
@ -109,25 +141,50 @@ class PlannerTestBaseImpl {
|
|||
res_.physiSubplans_.clear();
|
||||
}
|
||||
|
||||
void dump() {
|
||||
void dump(DumpModule module) {
|
||||
if (DUMP_MODULE_NOTHING == module) {
|
||||
return;
|
||||
}
|
||||
|
||||
cout << "==========================================sql : [" << stmtEnv_.sql_ << "]" << endl;
|
||||
|
||||
if (DUMP_MODULE_ALL == module || DUMP_MODULE_PARSER == module) {
|
||||
cout << "syntax tree : " << endl;
|
||||
cout << res_.ast_ << endl;
|
||||
}
|
||||
|
||||
if (DUMP_MODULE_ALL == module || DUMP_MODULE_LOGIC == module) {
|
||||
cout << "raw logic plan : " << endl;
|
||||
cout << res_.rawLogicPlan_ << endl;
|
||||
}
|
||||
|
||||
if (DUMP_MODULE_ALL == module || DUMP_MODULE_OPTIMIZED == module) {
|
||||
cout << "optimized logic plan : " << endl;
|
||||
cout << res_.optimizedLogicPlan_ << endl;
|
||||
}
|
||||
|
||||
if (DUMP_MODULE_ALL == module || DUMP_MODULE_SPLIT == module) {
|
||||
cout << "split logic plan : " << endl;
|
||||
cout << res_.splitLogicPlan_ << endl;
|
||||
}
|
||||
|
||||
if (DUMP_MODULE_ALL == module || DUMP_MODULE_SCALED == module) {
|
||||
cout << "scaled logic plan : " << endl;
|
||||
cout << res_.scaledLogicPlan_ << endl;
|
||||
}
|
||||
|
||||
if (DUMP_MODULE_ALL == module || DUMP_MODULE_PHYSICAL == module) {
|
||||
cout << "physical plan : " << endl;
|
||||
cout << res_.physiPlan_ << endl;
|
||||
}
|
||||
|
||||
if (DUMP_MODULE_ALL == module || DUMP_MODULE_SUBPLAN == module) {
|
||||
cout << "physical subplan : " << endl;
|
||||
for (const auto& subplan : res_.physiSubplans_) {
|
||||
cout << subplan << endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void doParseSql(const string& sql, SQuery** pQuery) {
|
||||
stmtEnv_.sql_ = sql;
|
||||
|
|
|
@ -32,6 +32,6 @@ class PlannerTestBase : public testing::Test {
|
|||
std::unique_ptr<PlannerTestBaseImpl> impl_;
|
||||
};
|
||||
|
||||
extern bool g_isDump;
|
||||
extern void setDumpModule(const char* pModule);
|
||||
|
||||
#endif // PLAN_TEST_UTIL_H
|
||||
|
|
|
@ -709,6 +709,10 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
|
|||
int16_t outputType = GET_PARAM_TYPE(&pOutput[0]);
|
||||
int64_t outputLen = GET_PARAM_BYTES(&pOutput[0]);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(outputType)) {
|
||||
outputLen += VARSTR_HEADER_SIZE;
|
||||
}
|
||||
|
||||
char *outputBuf = taosMemoryCalloc(outputLen * pInput[0].numOfRows, 1);
|
||||
char *output = outputBuf;
|
||||
|
||||
|
@ -790,29 +794,30 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
|
|||
}
|
||||
case TSDB_DATA_TYPE_NCHAR: {
|
||||
int32_t outputCharLen = (outputLen - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
|
||||
int32_t len;
|
||||
if (inputType == TSDB_DATA_TYPE_BOOL) {
|
||||
char tmp[8] = {0};
|
||||
int32_t len = sprintf(tmp, "%.*s", outputCharLen, *(int8_t *)input ? "true" : "false" );
|
||||
len = sprintf(tmp, "%.*s", outputCharLen, *(int8_t *)input ? "true" : "false" );
|
||||
bool ret = taosMbsToUcs4(tmp, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len);
|
||||
if (!ret) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
varDataSetLen(output, len);
|
||||
} else if (inputType == TSDB_DATA_TYPE_BINARY) {
|
||||
int32_t len = outputCharLen > varDataLen(input) ? varDataLen(input) : outputCharLen;
|
||||
len = outputCharLen > varDataLen(input) ? varDataLen(input) : outputCharLen;
|
||||
bool ret = taosMbsToUcs4(input + VARSTR_HEADER_SIZE, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len);
|
||||
if (!ret) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
varDataSetLen(output, len);
|
||||
} else if (inputType == TSDB_DATA_TYPE_NCHAR) {
|
||||
int32_t len = TMIN(outputLen, varDataLen(input) + VARSTR_HEADER_SIZE);
|
||||
memcpy(output, input, len);
|
||||
varDataSetLen(output, len - VARSTR_HEADER_SIZE);
|
||||
len = TMIN(outputLen - VARSTR_HEADER_SIZE, varDataLen(input));
|
||||
memcpy(output, input, len + VARSTR_HEADER_SIZE);
|
||||
varDataSetLen(output, len);
|
||||
} else {
|
||||
char tmp[400] = {0};
|
||||
NUM_TO_STRING(inputType, input, sizeof(tmp), tmp);
|
||||
int32_t len = (int32_t)strlen(tmp);
|
||||
len = (int32_t)strlen(tmp);
|
||||
len = outputCharLen > len ? len : outputCharLen;
|
||||
bool ret = taosMbsToUcs4(tmp, len, (TdUcs4 *)varDataVal(output), outputLen - VARSTR_HEADER_SIZE, &len);
|
||||
if (!ret) {
|
||||
|
@ -820,6 +825,10 @@ int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutp
|
|||
}
|
||||
varDataSetLen(output, len);
|
||||
}
|
||||
//for constant conversion, need to set proper length of pOutput description
|
||||
if (len < outputLen - VARSTR_HEADER_SIZE) {
|
||||
pOutput->columnData->info.bytes = len;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
|
|
@ -152,8 +152,10 @@ int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, in
|
|||
|
||||
// sink
|
||||
if (pTask->sinkType == TASK_SINK__TABLE) {
|
||||
//
|
||||
blockDebugShowData(pRes);
|
||||
/*blockDebugShowData(pRes);*/
|
||||
ASSERT(pTask->tbSink.pTSchema);
|
||||
SSubmitReq* pReq = tdBlockToSubmit(pRes, pTask->tbSink.pTSchema);
|
||||
tPrintFixedSchemaSubmitReq(pReq, pTask->tbSink.pTSchema);
|
||||
} else if (pTask->sinkType == TASK_SINK__SMA) {
|
||||
pTask->smaSink.smaHandle(pTask->ahandle, pTask->smaSink.smaId, pRes);
|
||||
//
|
||||
|
@ -274,7 +276,8 @@ int32_t tEncodeSStreamTask(SCoder* pEncoder, const SStreamTask* pTask) {
|
|||
}
|
||||
|
||||
if (pTask->sinkType == TASK_SINK__TABLE) {
|
||||
if (tEncodeI8(pEncoder, pTask->tbSink.reserved) < 0) return -1;
|
||||
/*if (tEncodeI8(pEncoder, pTask->tbSink.reserved) < 0) return -1;*/
|
||||
if (tEncodeSSchemaWrapper(pEncoder, pTask->tbSink.pSchemaWrapper) < 0) return -1;
|
||||
} else if (pTask->sinkType == TASK_SINK__SMA) {
|
||||
if (tEncodeI64(pEncoder, pTask->smaSink.smaId) < 0) return -1;
|
||||
} else if (pTask->sinkType == TASK_SINK__FETCH) {
|
||||
|
@ -318,7 +321,10 @@ int32_t tDecodeSStreamTask(SCoder* pDecoder, SStreamTask* pTask) {
|
|||
}
|
||||
|
||||
if (pTask->sinkType == TASK_SINK__TABLE) {
|
||||
if (tDecodeI8(pDecoder, &pTask->tbSink.reserved) < 0) return -1;
|
||||
/*if (tDecodeI8(pDecoder, &pTask->tbSink.reserved) < 0) return -1;*/
|
||||
pTask->tbSink.pSchemaWrapper = taosMemoryCalloc(1, sizeof(SSchemaWrapper));
|
||||
if (pTask->tbSink.pSchemaWrapper == NULL) return -1;
|
||||
if (tDecodeSSchemaWrapper(pDecoder, pTask->tbSink.pSchemaWrapper) < 0) return -1;
|
||||
} else if (pTask->sinkType == TASK_SINK__SMA) {
|
||||
if (tDecodeI64(pDecoder, &pTask->smaSink.smaId) < 0) return -1;
|
||||
} else if (pTask->sinkType == TASK_SINK__FETCH) {
|
||||
|
|
|
@ -40,7 +40,9 @@ int tdbCommit(TENV *pEnv, TXN *pTxn);
|
|||
int tdbDbOpen(const char *fname, int keyLen, int valLen, tdb_cmpr_fn_t keyCmprFn, TENV *pEnv, TDB **ppDb);
|
||||
int tdbDbClose(TDB *pDb);
|
||||
int tdbDbDrop(TDB *pDb);
|
||||
int tdbDbPut(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn);
|
||||
int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn);
|
||||
int tdbDbDelete(TDB *pDb, const void *pKey, int kLen, TXN *pTxn);
|
||||
int tdbDbUpsert(TDB *pDb, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn);
|
||||
int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen);
|
||||
int tdbDbPGet(TDB *pDb, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen);
|
||||
|
||||
|
@ -53,11 +55,9 @@ int tdbDbcMoveToLast(TDBC *pDbc);
|
|||
int tdbDbcMoveToNext(TDBC *pDbc);
|
||||
int tdbDbcMoveToPrev(TDBC *pDbc);
|
||||
int tdbDbcGet(TDBC *pDbc, const void **ppKey, int *pkLen, const void **ppVal, int *pvLen);
|
||||
|
||||
int tdbDbcPut(TDBC *pDbc, const void *pKey, int keyLen, const void *pVal, int valLen);
|
||||
int tdbDbcUpdate(TDBC *pDbc, const void *pKey, int kLen, const void *pVal, int vLen);
|
||||
int tdbDbcDrop(TDBC *pDbc);
|
||||
int tdbDbcDelete(TDBC *pDbc);
|
||||
int tdbDbcNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||
int tdbDbcUpsert(TDBC *pDbc, const void *pKey, int nKey, const void *pData, int nData, int insert);
|
||||
|
||||
// TXN
|
||||
#define TDB_TXN_WRITE 0x1
|
||||
|
|
|
@ -138,67 +138,90 @@ int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, in
|
|||
}
|
||||
|
||||
if (btc.idx == -1) {
|
||||
idx = 0;
|
||||
btc.idx = 0;
|
||||
} else {
|
||||
if (c > 0) {
|
||||
idx = btc.idx + 1;
|
||||
} else if (c < 0) {
|
||||
idx = btc.idx;
|
||||
btc.idx++;
|
||||
} else if (c == 0) {
|
||||
// dup key not allowed
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
ret = tdbBtcUpsert(&btc, pKey, kLen, pVal, vLen, 1);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
tdbBtcClose(&btc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdbBtcClose(&btc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn) {
|
||||
SBTC btc;
|
||||
int c;
|
||||
int ret;
|
||||
|
||||
tdbBtcOpen(&btc, pBt, pTxn);
|
||||
|
||||
// move the cursor
|
||||
ret = tdbBtcMoveTo(&btc, pKey, kLen, &c);
|
||||
if (ret < 0) {
|
||||
tdbBtcClose(&btc);
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (btc.idx < 0 || c != 0) {
|
||||
tdbBtcClose(&btc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// delete the key
|
||||
if (tdbBtcDelete(&btc) < 0) {
|
||||
tdbBtcClose(&btc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdbBtcClose(&btc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbBtreeUpsert(SBTree *pBt, const void *pKey, int nKey, const void *pData, int nData, TXN *pTxn) {
|
||||
SBTC btc;
|
||||
int c;
|
||||
int ret;
|
||||
|
||||
tdbBtcOpen(&btc, pBt, pTxn);
|
||||
|
||||
// move the cursor
|
||||
ret = tdbBtcMoveTo(&btc, pKey, nKey, &c);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
tdbBtcClose(&btc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (btc.idx == -1) {
|
||||
btc.idx = 0;
|
||||
c = 1;
|
||||
} else {
|
||||
// TDB does NOT allow same key
|
||||
tdbBtcClose(&btc);
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
if (c > 0) {
|
||||
btc.idx = btc.idx + 1;
|
||||
}
|
||||
}
|
||||
|
||||
// make sure enough space to hold the cell
|
||||
szBuf = kLen + vLen + 14;
|
||||
pBuf = tdbRealloc(pBt->pBuf, pBt->pageSize > szBuf ? szBuf : pBt->pageSize);
|
||||
if (pBuf == NULL) {
|
||||
tdbBtcClose(&btc);
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
pBt->pBuf = pBuf;
|
||||
pCell = (SCell *)pBt->pBuf;
|
||||
|
||||
// encode cell
|
||||
ret = tdbBtreeEncodeCell(btc.pPage, pKey, kLen, pVal, vLen, pCell, &szCell);
|
||||
ret = tdbBtcUpsert(&btc, pKey, nKey, pData, nData, c);
|
||||
if (ret < 0) {
|
||||
tdbBtcClose(&btc);
|
||||
ASSERT(0);
|
||||
tdbBtcClose(&btc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// mark the page dirty
|
||||
ret = tdbPagerWrite(pBt->pPager, btc.pPage);
|
||||
if (ret < 0) {
|
||||
tdbBtcClose(&btc);
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// insert the cell
|
||||
ret = tdbPageInsertCell(btc.pPage, idx, pCell, szCell, 0);
|
||||
if (ret < 0) {
|
||||
tdbBtcClose(&btc);
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// check if need balance
|
||||
if (btc.pPage->nOverflow > 0) {
|
||||
ret = tdbBtreeBalance(&btc);
|
||||
if (ret < 0) {
|
||||
tdbBtcClose(&btc);
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
tdbBtcClose(&btc);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -552,14 +575,14 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
|||
SCell *pCell;
|
||||
int szLCell, szRCell;
|
||||
|
||||
// balance page (iNew) and (iNew-1)
|
||||
for (;;) {
|
||||
pCell = tdbPageGetCell(pOlds[infoNews[iNew - 1].iPage], infoNews[iNew - 1].oIdx);
|
||||
|
||||
if (childNotLeaf) {
|
||||
szLCell = szRCell = tdbBtreeCellSize(pOlds[infoNews[iNew - 1].iPage], pCell);
|
||||
} else {
|
||||
szLCell = tdbBtreeCellSize(pOlds[infoNews[iNew - 1].iPage], pCell);
|
||||
|
||||
if (!childNotLeaf) {
|
||||
szRCell = szLCell;
|
||||
} else {
|
||||
int iPage = infoNews[iNew - 1].iPage;
|
||||
int oIdx = infoNews[iNew - 1].oIdx + 1;
|
||||
SPage *pPage;
|
||||
|
@ -736,6 +759,13 @@ static int tdbBtreeBalanceNonRoot(SBTree *pBt, SPage *pParent, int idx, TXN *pTx
|
|||
}
|
||||
}
|
||||
|
||||
if (TDB_BTREE_PAGE_IS_ROOT(pParent) && TDB_PAGE_TOTAL_CELLS(pParent) == 0) {
|
||||
i8 flags = TDB_BTREE_ROOT | TDB_BTREE_PAGE_IS_LEAF(pNews[0]);
|
||||
// copy content to the parent page
|
||||
tdbBtreeInitPage(pParent, &(SBtreeInitPageArg){.flags = flags, .pBt = pBt}, 0);
|
||||
tdbPageCopy(pNews[0], pParent);
|
||||
}
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
if (pDivCell[i]) {
|
||||
tdbOsFree(pDivCell[i]);
|
||||
|
@ -1357,7 +1387,143 @@ int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int
|
|||
|
||||
if (ppVal) {
|
||||
*ppVal = (void *)pBtc->coder.pVal;
|
||||
*kLen = pBtc->coder.vLen;
|
||||
*vLen = pBtc->coder.vLen;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbBtcDelete(SBTC *pBtc) {
|
||||
int idx = pBtc->idx;
|
||||
int nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage);
|
||||
SPager *pPager = pBtc->pBt->pPager;
|
||||
const void *pKey;
|
||||
i8 iPage;
|
||||
SPage *pPage;
|
||||
SPgno pgno;
|
||||
SCell *pCell;
|
||||
int szCell;
|
||||
int nKey;
|
||||
int ret;
|
||||
|
||||
ASSERT(idx >= 0 && idx < nCells);
|
||||
|
||||
// drop the cell on the leaf
|
||||
ret = tdbPagerWrite(pPager, pBtc->pPage);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
tdbPageDropCell(pBtc->pPage, idx);
|
||||
|
||||
// update interior page or do balance
|
||||
if (idx == nCells - 1) {
|
||||
if (idx) {
|
||||
pBtc->idx--;
|
||||
tdbBtcGet(pBtc, &pKey, &nKey, NULL, NULL);
|
||||
|
||||
// loop to update the interial page
|
||||
pgno = TDB_PAGE_PGNO(pBtc->pPage);
|
||||
for (iPage = pBtc->iPage - 1; iPage >= 0; iPage--) {
|
||||
pPage = pBtc->pgStack[iPage];
|
||||
idx = pBtc->idxStack[iPage];
|
||||
nCells = TDB_PAGE_TOTAL_CELLS(pPage);
|
||||
|
||||
if (idx < nCells) {
|
||||
ret = tdbPagerWrite(pPager, pPage);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// update the cell with new key
|
||||
pCell = tdbOsMalloc(nKey + 9);
|
||||
tdbBtreeEncodeCell(pPage, pKey, nKey, &pgno, sizeof(pgno), pCell, &szCell);
|
||||
|
||||
ret = tdbPageUpdateCell(pPage, idx, pCell, szCell);
|
||||
if (ret < 0) {
|
||||
tdbOsFree(pCell);
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
tdbOsFree(pCell);
|
||||
break;
|
||||
} else {
|
||||
pgno = TDB_PAGE_PGNO(pPage);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// delete the leaf page and do balance
|
||||
ASSERT(TDB_PAGE_TOTAL_CELLS(pBtc->pPage) == 0);
|
||||
|
||||
ret = tdbBtreeBalance(pBtc);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int nData, int insert) {
|
||||
SCell *pCell;
|
||||
int szCell;
|
||||
int nCells = TDB_PAGE_TOTAL_CELLS(pBtc->pPage);
|
||||
int szBuf;
|
||||
void *pBuf;
|
||||
int ret;
|
||||
|
||||
ASSERT(pBtc->idx >= 0);
|
||||
|
||||
// alloc space
|
||||
szBuf = kLen + nData + 14;
|
||||
pBuf = tdbRealloc(pBtc->pBt->pBuf, pBtc->pBt->pageSize > szBuf ? szBuf : pBtc->pBt->pageSize);
|
||||
if (pBuf == NULL) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
pBtc->pBt->pBuf = pBuf;
|
||||
pCell = (SCell *)pBtc->pBt->pBuf;
|
||||
|
||||
// encode cell
|
||||
ret = tdbBtreeEncodeCell(pBtc->pPage, pKey, kLen, pData, nData, pCell, &szCell);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// mark dirty
|
||||
ret = tdbPagerWrite(pBtc->pBt->pPager, pBtc->pPage);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// insert or update
|
||||
if (insert) {
|
||||
ASSERT(pBtc->idx <= nCells);
|
||||
|
||||
ret = tdbPageInsertCell(pBtc->pPage, pBtc->idx, pCell, szCell, 0);
|
||||
} else {
|
||||
ASSERT(pBtc->idx < nCells);
|
||||
|
||||
ret = tdbPageUpdateCell(pBtc->pPage, pBtc->idx, pCell, szCell);
|
||||
}
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// check balance
|
||||
if (pBtc->pPage->nOverflow > 0) {
|
||||
ret = tdbBtreeBalance(pBtc);
|
||||
if (ret < 0) {
|
||||
ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -75,10 +75,16 @@ int tdbDbDrop(TDB *pDb) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbPut(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn) {
|
||||
int tdbDbInsert(TDB *pDb, const void *pKey, int keyLen, const void *pVal, int valLen, TXN *pTxn) {
|
||||
return tdbBtreeInsert(pDb->pBt, pKey, keyLen, pVal, valLen, pTxn);
|
||||
}
|
||||
|
||||
int tdbDbDelete(TDB *pDb, const void *pKey, int kLen, TXN *pTxn) { return tdbBtreeDelete(pDb->pBt, pKey, kLen, pTxn); }
|
||||
|
||||
int tdbDbUpsert(TDB *pDb, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn) {
|
||||
return tdbBtreeUpsert(pDb->pBt, pKey, kLen, pVal, vLen, pTxn);
|
||||
}
|
||||
|
||||
int tdbDbGet(TDB *pDb, const void *pKey, int kLen, void **ppVal, int *vLen) {
|
||||
return tdbBtreeGet(pDb->pBt, pKey, kLen, ppVal, vLen);
|
||||
}
|
||||
|
@ -117,28 +123,16 @@ int tdbDbcGet(TDBC *pDbc, const void **ppKey, int *pkLen, const void **ppVal, in
|
|||
return tdbBtcGet(&pDbc->btc, ppKey, pkLen, ppVal, pvLen);
|
||||
}
|
||||
|
||||
int tdbDbcPut(TDBC *pDbc, const void *pKey, int keyLen, const void *pVal, int valLen) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbcUpdate(TDBC *pDbc, const void *pKey, int kLen, const void *pVal, int vLen) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int tdbDbcDrop(TDBC *pDbc) {
|
||||
// TODO
|
||||
ASSERT(0);
|
||||
return 0;
|
||||
}
|
||||
int tdbDbcDelete(TDBC *pDbc) { return tdbBtcDelete(&pDbc->btc); }
|
||||
|
||||
int tdbDbcNext(TDBC *pDbc, void **ppKey, int *kLen, void **ppVal, int *vLen) {
|
||||
return tdbBtreeNext(&pDbc->btc, ppKey, kLen, ppVal, vLen);
|
||||
}
|
||||
|
||||
int tdbDbcUpsert(TDBC *pDbc, const void *pKey, int nKey, const void *pData, int nData, int insert) {
|
||||
return tdbBtcUpsert(&pDbc->btc, pKey, nKey, pData, nData, insert);
|
||||
}
|
||||
|
||||
int tdbDbcClose(TDBC *pDbc) {
|
||||
if (pDbc) {
|
||||
tdbBtcClose(&pDbc->btc);
|
||||
|
|
|
@ -171,6 +171,11 @@ int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl
|
|||
return 0;
|
||||
}
|
||||
|
||||
int tdbPageUpdateCell(SPage *pPage, int idx, SCell *pCell, int szCell) {
|
||||
tdbPageDropCell(pPage, idx);
|
||||
return tdbPageInsertCell(pPage, idx, pCell, szCell, 0);
|
||||
}
|
||||
|
||||
int tdbPageDropCell(SPage *pPage, int idx) {
|
||||
int lidx;
|
||||
SCell *pCell;
|
||||
|
|
|
@ -128,6 +128,8 @@ struct SBTC {
|
|||
int tdbBtreeOpen(int keyLen, int valLen, SPager *pFile, tdb_cmpr_fn_t kcmpr, SBTree **ppBt);
|
||||
int tdbBtreeClose(SBTree *pBt);
|
||||
int tdbBtreeInsert(SBTree *pBt, const void *pKey, int kLen, const void *pVal, int vLen, TXN *pTxn);
|
||||
int tdbBtreeDelete(SBTree *pBt, const void *pKey, int kLen, TXN *pTxn);
|
||||
int tdbBtreeUpsert(SBTree *pBt, const void *pKey, int nKey, const void *pData, int nData, TXN *pTxn);
|
||||
int tdbBtreeGet(SBTree *pBt, const void *pKey, int kLen, void **ppVal, int *vLen);
|
||||
int tdbBtreePGet(SBTree *pBt, const void *pKey, int kLen, void **ppKey, int *pkLen, void **ppVal, int *vLen);
|
||||
|
||||
|
@ -141,6 +143,8 @@ int tdbBtcMoveToNext(SBTC *pBtc);
|
|||
int tdbBtcMoveToPrev(SBTC *pBtc);
|
||||
int tdbBtreeNext(SBTC *pBtc, void **ppKey, int *kLen, void **ppVal, int *vLen);
|
||||
int tdbBtcGet(SBTC *pBtc, const void **ppKey, int *kLen, const void **ppVal, int *vLen);
|
||||
int tdbBtcDelete(SBTC *pBtc);
|
||||
int tdbBtcUpsert(SBTC *pBtc, const void *pKey, int kLen, const void *pData, int nData, int insert);
|
||||
|
||||
// tdbPager.c ====================================
|
||||
|
||||
|
@ -278,6 +282,7 @@ void tdbPageZero(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell
|
|||
void tdbPageInit(SPage *pPage, u8 szAmHdr, int (*xCellSize)(const SPage *, SCell *));
|
||||
int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell, u8 asOvfl);
|
||||
int tdbPageDropCell(SPage *pPage, int idx);
|
||||
int tdbPageUpdateCell(SPage *pPage, int idx, SCell *pCell, int szCell);
|
||||
void tdbPageCopy(SPage *pFromPage, SPage *pToPage);
|
||||
int tdbPageCapacity(int pageSize, int amHdrSize);
|
||||
|
||||
|
|
|
@ -115,12 +115,12 @@ static int tDefaultKeyCmpr(const void *pKey1, int keyLen1, const void *pKey2, in
|
|||
return cret;
|
||||
}
|
||||
|
||||
TEST(tdb_test, simple_test) {
|
||||
TEST(tdb_test, simple_insert1) {
|
||||
int ret;
|
||||
TENV *pEnv;
|
||||
TDB *pDb;
|
||||
tdb_cmpr_fn_t compFunc;
|
||||
int nData = 10000000;
|
||||
int nData = 1000000;
|
||||
TXN txn;
|
||||
|
||||
taosRemoveDir("tdb");
|
||||
|
@ -152,7 +152,7 @@ TEST(tdb_test, simple_test) {
|
|||
for (int iData = 1; iData <= nData; iData++) {
|
||||
sprintf(key, "key%d", iData);
|
||||
sprintf(val, "value%d", iData);
|
||||
ret = tdbDbPut(pDb, key, strlen(key), val, strlen(val), &txn);
|
||||
ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val), &txn);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
// if pool is full, commit the transaction and start a new one
|
||||
|
@ -202,6 +202,8 @@ TEST(tdb_test, simple_test) {
|
|||
ret = tdbDbcOpen(pDb, &pDBC, NULL);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
tdbDbcMoveToFirst(pDBC);
|
||||
|
||||
for (;;) {
|
||||
ret = tdbDbcNext(pDBC, &pKey, &kLen, &pVal, &vLen);
|
||||
if (ret < 0) break;
|
||||
|
@ -233,7 +235,7 @@ TEST(tdb_test, simple_test) {
|
|||
GTEST_ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
TEST(tdb_test, simple_test2) {
|
||||
TEST(tdb_test, simple_insert2) {
|
||||
int ret;
|
||||
TENV *pEnv;
|
||||
TDB *pDb;
|
||||
|
@ -269,7 +271,7 @@ TEST(tdb_test, simple_test2) {
|
|||
for (int iData = 1; iData <= nData; iData++) {
|
||||
sprintf(key, "key%d", iData);
|
||||
sprintf(val, "value%d", iData);
|
||||
ret = tdbDbPut(pDb, key, strlen(key), val, strlen(val), &txn);
|
||||
ret = tdbDbInsert(pDb, key, strlen(key), val, strlen(val), &txn);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
|
@ -283,13 +285,15 @@ TEST(tdb_test, simple_test2) {
|
|||
ret = tdbDbcOpen(pDb, &pDBC, NULL);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
tdbDbcMoveToFirst(pDBC);
|
||||
|
||||
for (;;) {
|
||||
ret = tdbDbcNext(pDBC, &pKey, &kLen, &pVal, &vLen);
|
||||
if (ret < 0) break;
|
||||
|
||||
std::cout.write((char *)pKey, kLen) /* << " " << kLen */ << " ";
|
||||
std::cout.write((char *)pVal, vLen) /* << " " << vLen */;
|
||||
std::cout << std::endl;
|
||||
// std::cout.write((char *)pKey, kLen) /* << " " << kLen */ << " ";
|
||||
// std::cout.write((char *)pVal, vLen) /* << " " << vLen */;
|
||||
// std::cout << std::endl;
|
||||
|
||||
count++;
|
||||
}
|
||||
|
@ -317,3 +321,163 @@ TEST(tdb_test, simple_test2) {
|
|||
ret = tdbEnvClose(pEnv);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
TEST(tdb_test, simple_delete1) {
|
||||
int ret;
|
||||
TDB *pDb;
|
||||
char key[128];
|
||||
char data[128];
|
||||
TXN txn;
|
||||
TENV *pEnv;
|
||||
SPoolMem *pPool;
|
||||
void *pKey = NULL;
|
||||
void *pData = NULL;
|
||||
int nKey;
|
||||
TDBC *pDbc;
|
||||
int nData;
|
||||
int nKV = 69;
|
||||
|
||||
taosRemoveDir("tdb");
|
||||
|
||||
pPool = openPool();
|
||||
|
||||
// open env
|
||||
ret = tdbEnvOpen("tdb", 1024, 256, &pEnv);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
// open database
|
||||
ret = tdbDbOpen("db.db", -1, -1, tKeyCmpr, pEnv, &pDb);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
tdbTxnOpen(&txn, 0, poolMalloc, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
|
||||
tdbBegin(pEnv, &txn);
|
||||
|
||||
// loop to insert batch data
|
||||
for (int iData = 0; iData < nKV; iData++) {
|
||||
sprintf(key, "key%d", iData);
|
||||
sprintf(data, "data%d", iData);
|
||||
ret = tdbDbInsert(pDb, key, strlen(key), data, strlen(data), &txn);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
// query the data
|
||||
for (int iData = 0; iData < nKV; iData++) {
|
||||
sprintf(key, "key%d", iData);
|
||||
sprintf(data, "data%d", iData);
|
||||
|
||||
ret = tdbDbGet(pDb, key, strlen(key), &pData, &nData);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
GTEST_ASSERT_EQ(memcmp(data, pData, nData), 0);
|
||||
}
|
||||
|
||||
// loop to delete some data
|
||||
for (int iData = nKV - 1; iData > 30; iData--) {
|
||||
sprintf(key, "key%d", iData);
|
||||
|
||||
ret = tdbDbDelete(pDb, key, strlen(key), &txn);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
// query the data
|
||||
for (int iData = 0; iData < nKV; iData++) {
|
||||
sprintf(key, "key%d", iData);
|
||||
|
||||
ret = tdbDbGet(pDb, key, strlen(key), &pData, &nData);
|
||||
if (iData <= 30) {
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
} else {
|
||||
GTEST_ASSERT_EQ(ret, -1);
|
||||
}
|
||||
}
|
||||
|
||||
// loop to iterate the data
|
||||
tdbDbcOpen(pDb, &pDbc, NULL);
|
||||
|
||||
ret = tdbDbcMoveToFirst(pDbc);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
pKey = NULL;
|
||||
pData = NULL;
|
||||
for (;;) {
|
||||
ret = tdbDbcNext(pDbc, &pKey, &nKey, &pData, &nData);
|
||||
if (ret < 0) break;
|
||||
|
||||
std::cout.write((char *)pKey, nKey) /* << " " << kLen */ << " ";
|
||||
std::cout.write((char *)pData, nData) /* << " " << vLen */;
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
tdbDbcClose(pDbc);
|
||||
|
||||
tdbCommit(pEnv, &txn);
|
||||
|
||||
closePool(pPool);
|
||||
|
||||
tdbDbClose(pDb);
|
||||
tdbEnvClose(pEnv);
|
||||
}
|
||||
|
||||
TEST(tdb_test, simple_upsert1) {
|
||||
int ret;
|
||||
TENV *pEnv;
|
||||
TDB *pDb;
|
||||
int nData = 100000;
|
||||
char key[64];
|
||||
char data[64];
|
||||
void *pData = NULL;
|
||||
SPoolMem *pPool;
|
||||
TXN txn;
|
||||
|
||||
taosRemoveDir("tdb");
|
||||
|
||||
// open env
|
||||
ret = tdbEnvOpen("tdb", 4096, 64, &pEnv);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
// open database
|
||||
ret = tdbDbOpen("db.db", -1, -1, NULL, pEnv, &pDb);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
|
||||
pPool = openPool();
|
||||
// insert some data
|
||||
tdbTxnOpen(&txn, 0, poolMalloc, poolFree, pPool, TDB_TXN_WRITE | TDB_TXN_READ_UNCOMMITTED);
|
||||
tdbBegin(pEnv, &txn);
|
||||
|
||||
for (int iData = 0; iData < nData; iData++) {
|
||||
sprintf(key, "key%d", iData);
|
||||
sprintf(data, "data%d", iData);
|
||||
ret = tdbDbInsert(pDb, key, strlen(key), data, strlen(data), &txn);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
// query the data
|
||||
for (int iData = 0; iData < nData; iData++) {
|
||||
sprintf(key, "key%d", iData);
|
||||
sprintf(data, "data%d", iData);
|
||||
ret = tdbDbGet(pDb, key, strlen(key), &pData, &nData);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
GTEST_ASSERT_EQ(memcmp(pData, data, nData), 0);
|
||||
}
|
||||
|
||||
// upsert some data
|
||||
for (int iData = 0; iData < nData; iData++) {
|
||||
sprintf(key, "key%d", iData);
|
||||
sprintf(data, "data%d-u", iData);
|
||||
ret = tdbDbUpsert(pDb, key, strlen(key), data, strlen(data), &txn);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
}
|
||||
|
||||
tdbCommit(pEnv, &txn);
|
||||
|
||||
// query the data
|
||||
for (int iData = 0; iData < nData; iData++) {
|
||||
sprintf(key, "key%d", iData);
|
||||
sprintf(data, "data%d-u", iData);
|
||||
ret = tdbDbGet(pDb, key, strlen(key), &pData, &nData);
|
||||
GTEST_ASSERT_EQ(ret, 0);
|
||||
GTEST_ASSERT_EQ(memcmp(pData, data, nData), 0);
|
||||
}
|
||||
|
||||
tdbDbClose(pDb);
|
||||
tdbEnvClose(pEnv);
|
||||
}
|
|
@ -435,7 +435,7 @@ int transDQSched(SDelayQueue* queue, void (*func)(void* arg), void* arg, uint64_
|
|||
if (minNode) {
|
||||
SDelayTask* minTask = container_of(minNode, SDelayTask, node);
|
||||
if (minTask->execTime < task->execTime) {
|
||||
timeoutMs = minTask->execTime <= now ? 0 : now - minTask->execTime;
|
||||
timeoutMs = minTask->execTime <= now ? 0 : minTask->execTime - now;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,7 +44,7 @@ int wordexp(char *words, wordexp_t *pwordexp, int flags) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
printf("parse relative path:%s to abs path:%s\n", words, pwordexp->wordPos);
|
||||
// printf("parse relative path:%s to abs path:%s\n", words, pwordexp->wordPos);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -195,6 +195,36 @@ int32_t taosUcs4len(TdUcs4 *ucs4) {
|
|||
return n;
|
||||
}
|
||||
|
||||
//dst buffer size should be at least 2*len + 1
|
||||
int32_t taosHexEncode(const char *src, char *dst, int32_t len) {
|
||||
if (!dst) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < len; ++i) {
|
||||
sprintf(dst + i * 2, "%02x", src[i] & 0xff);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t taosHexDecode(const char *src, char *dst, int32_t len) {
|
||||
if (!dst) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint16_t hn, ln, out;
|
||||
for (int i = 0, j = 0; i < len * 2; i += 2, ++j ) {
|
||||
hn = src[i] > '9' ? src[i] - 'A' + 10 : src[i] - '0';
|
||||
ln = src[i + 1] > '9' ? src[i + 1] - 'A' + 10 : src[i + 1] - '0';
|
||||
|
||||
out = (hn << 4) | ln;
|
||||
memcpy(dst + j, &out, 1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t taosWcharWidth(TdWchar wchar) { return wcwidth(wchar); }
|
||||
|
||||
int32_t taosWcharsWidth(TdWchar *pWchar, int32_t size) { return wcswidth(pWchar, size); }
|
||||
|
|
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tskiplist2.h"
|
||||
|
||||
struct SSLNode {
|
||||
int8_t level;
|
||||
SSLNode *forwards[];
|
||||
};
|
||||
|
||||
struct SSkipList2 {
|
||||
int8_t level;
|
||||
uint32_t seed;
|
||||
int32_t size;
|
||||
const SSLCfg *pCfg;
|
||||
SSLNode *pHead[];
|
||||
};
|
||||
|
||||
static void *slMalloc(void *pPool, int32_t size);
|
||||
static void slFree(void *pPool, void *p);
|
||||
static int32_t slCmprFn(const void *pKey, int32_t nKey, const void *pData, int32_t nData);
|
||||
|
||||
const SSLCfg slDefaultCfg = {.maxLevel = SL_MAX_LEVEL,
|
||||
.nKey = -1,
|
||||
.nData = -1,
|
||||
.cmprFn = slCmprFn,
|
||||
.pPool = NULL,
|
||||
.xMalloc = slMalloc,
|
||||
.xFree = slFree};
|
||||
|
||||
int32_t slOpen(const SSLCfg *pCfg, SSkipList2 **ppSl) {
|
||||
SSkipList2 *pSl = NULL;
|
||||
int32_t size;
|
||||
|
||||
*ppSl = NULL;
|
||||
if (pCfg == NULL) pCfg = &slDefaultCfg;
|
||||
|
||||
// check config (TODO)
|
||||
|
||||
// malloc handle
|
||||
size = sizeof(*pSl) + sizeof(SSLNode *) * pCfg->maxLevel * 2;
|
||||
pSl = pCfg->xMalloc(pCfg->pPool, size);
|
||||
if (pSl == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pSl->level = 0;
|
||||
pSl->seed = taosRand();
|
||||
pSl->size = 0;
|
||||
pSl->pCfg = pCfg;
|
||||
|
||||
// init an empty skiplist
|
||||
for (int32_t i = 0; i < pCfg->maxLevel * 2; i++) {
|
||||
pSl->pHead[i] = NULL;
|
||||
}
|
||||
|
||||
*ppSl = pSl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t slClose(SSkipList2 *pSl) {
|
||||
if (pSl) {
|
||||
slClear(pSl);
|
||||
if (pSl->pCfg->xFree) {
|
||||
pSl->pCfg->xFree(pSl->pCfg->pPool, pSl);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t slClear(SSkipList2 *pSl) {
|
||||
// loop to clear sl
|
||||
for (;;) {
|
||||
// (TODO)
|
||||
}
|
||||
|
||||
// init sl (TODO)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t slcOpen(SSkipList2 *pSl, SSLCursor *pSlc) {
|
||||
pSlc->pSl = pSl;
|
||||
|
||||
for (int i = 0; i < SL_MAX_LEVEL; i++) {
|
||||
if (i < pSl->pCfg->maxLevel) {
|
||||
} else {
|
||||
pSlc->forwards[i] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t slcClose(SSLCursor *pSlc) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t slcMoveTo(SSLCursor *pSlc, const void *pKey, int32_t nKey) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t slcMoveToNext(SSLCursor *pSlc) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t slcMoveToPrev(SSLCursor *pSlc) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t slcMoveToFirst(SSLCursor *pSlc) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t slcMoveToLast(SSLCursor *pSlc) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t slcPut(SSLCursor *pSlc, const void *pKey, int32_t nKey, const void *pData, int32_t nData) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t slcGet(SSLCursor *pSlc, const void **ppKey, int32_t *nKey, const void **ppData, int32_t *nData) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t slcDrop(SSLCursor *pSlc) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE void *slMalloc(void *pPool, int32_t size) { return taosMemoryMalloc(size); }
|
||||
|
||||
static FORCE_INLINE void slFree(void *pPool, void *p) { taosMemoryFree(p); }
|
||||
|
||||
static int32_t slCmprFn(const void *pKey1, int32_t nKey1, const void *pKey2, int32_t nKey2) {
|
||||
ASSERT(nKey1 >= 0 && nKey2 >= 0);
|
||||
|
||||
int32_t nKey = nKey1 > nKey2 ? nKey2 : nKey1;
|
||||
int32_t c;
|
||||
|
||||
c = memcmp(pKey1, pKey2, nKey);
|
||||
if (c == 0) {
|
||||
if (nKey1 > nKey2) {
|
||||
c = 1;
|
||||
} else if (nKey1 < nKey2) {
|
||||
c = -1;
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
|
@ -39,6 +39,7 @@
|
|||
./test.sh -f tsim/query/explain.sim
|
||||
./test.sh -f tsim/query/session.sim
|
||||
./test.sh -f tsim/query/scalarNull.sim
|
||||
./test.sh -f tsim/query/udf.sim
|
||||
|
||||
# ---- qnode
|
||||
./test.sh -f tsim/qnode/basic1.sim
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
#!/bin/bash
|
||||
|
||||
set +e
|
||||
#set -x
|
||||
|
||||
echo "Executing copy_udf.sh"
|
||||
|
||||
SCRIPT_DIR=`dirname $0`
|
||||
cd $SCRIPT_DIR/../
|
||||
|
||||
IN_TDINTERNAL="community"
|
||||
if [[ "$SCRIPT_DIR" == *"$IN_TDINTERNAL"* ]]; then
|
||||
cd ../../..
|
||||
else
|
||||
cd ../../
|
||||
fi
|
||||
|
||||
TAOS_DIR=`pwd`
|
||||
UDF1_DIR=`find $TAOS_DIR -name "libudf1.so"|grep lib|head -n1`
|
||||
UDF2_DIR=`find $TAOS_DIR -name "libudf2.so"|grep lib|head -n1`
|
||||
|
||||
echo $UDF1_DIR
|
||||
echo $UDF2_DIR
|
||||
|
||||
UDF_TMP=/tmp/udf
|
||||
mkdir $UDF_TMP
|
||||
rm $UDF_TMP/libudf1.so
|
||||
rm $UDF_TMP/libudf2.so
|
||||
|
||||
echo "Copy udf shared library files to $UDF_TMP"
|
||||
|
||||
cp $UDF1_DIR $UDF_TMP
|
||||
cp $UDF2_DIR $UDF_TMP
|
|
@ -66,7 +66,7 @@ print ============= create database
|
|||
# | REPLICA value [1 | 3]
|
||||
# | WAL value [1 | 2]
|
||||
|
||||
sql create database db CACHELAST 3 COMP 0 DAYS 345600 FSYNC 1000 MAXROWS 8000 MINROWS 10 KEEP 1440000 PRECISION 'ns' REPLICA 1 WAL 2 VGROUPS 6 SINGLE_STABLE 1
|
||||
sql create database db CACHELAST 3 COMP 0 DAYS 345600 FSYNC 1000 MAXROWS 8000 MINROWS 10 KEEP 1440000 PRECISION 'ns' REPLICA 3 WAL 2 VGROUPS 6 SINGLE_STABLE 1
|
||||
sql show databases
|
||||
print rows: $rows
|
||||
print $data00 $data01 $data02 $data03 $data04 $data05 $data06 $data07 $data08 $data09
|
||||
|
@ -86,7 +86,7 @@ endi
|
|||
if $data3_db != 0 then # ntables
|
||||
return -1
|
||||
endi
|
||||
if $data4_db != 1 then # replica
|
||||
if $data4_db != 3 then # replica
|
||||
return -1
|
||||
endi
|
||||
if $data5_db != nostrict then # strict
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
system sh/stop_dnodes.sh
|
||||
|
||||
system sh/deploy.sh -n dnode1 -i 1
|
||||
system sh/cfg.sh -n dnode1 -c wallevel -v 2
|
||||
system sh/cfg.sh -n dnode1 -c numOfMnodes -v 1
|
||||
|
||||
print ========= start dnode1 as LEADER
|
||||
system sh/exec.sh -n dnode1 -s start
|
||||
sleep 2000
|
||||
sql connect
|
||||
|
||||
print ======== step1 udf
|
||||
system sh/copy_udf.sh
|
||||
sql create database udf vgroups 3;
|
||||
sql use udf;
|
||||
sql show databases;
|
||||
|
||||
sql create table t (ts timestamp, f int);
|
||||
sql insert into t values(now, 1)(now+1s, 2);
|
||||
|
||||
sql create function udf1 as '/tmp/udf/libudf1.so' outputtype int bufSize 8;
|
||||
sql create aggregate function udf2 as '/tmp/udf/libudf2.so' outputtype double bufSize 8;
|
||||
sql show functions;
|
||||
if $rows != 2 then
|
||||
return -1
|
||||
endi
|
||||
sql select udf1(f) from t;
|
||||
if $rows != 2 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 88 then
|
||||
return -1
|
||||
endi
|
||||
if $data10 != 88 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
sql select udf2(f) from t;
|
||||
if $rows != 1 then
|
||||
return -1
|
||||
endi
|
||||
if $data00 != 2.236067977 then
|
||||
return -1
|
||||
endi
|
||||
|
||||
#sql drop function udf1;
|
||||
#sql drop function udf2;
|
||||
system sh/exec.sh -n dnode1 -s stop -x SIGKILL
|
|
@ -191,13 +191,13 @@ class TDTestCase:
|
|||
def support_types(self):
|
||||
type_error_sql_lists = [
|
||||
"select log(ts ,2 ) from t1" ,
|
||||
"select log(c7,2 ) from t1",
|
||||
"select log(c8,2 ) from t1",
|
||||
"select log(c9,2 ) from t1",
|
||||
"select log(ts,2 ) from ct1" ,
|
||||
"select log(c7,2 ) from ct1",
|
||||
"select log(c8,2 ) from ct1",
|
||||
"select log(c9,2 ) from ct1",
|
||||
"select log(c7,c2 ) from t1",
|
||||
"select log(c8,c1 ) from t1",
|
||||
"select log(c9,c2 ) from t1",
|
||||
"select log(ts,c7 ) from ct1" ,
|
||||
"select log(c7,c9 ) from ct1",
|
||||
"select log(c8,c2 ) from ct1",
|
||||
"select log(c9,c1 ) from ct1",
|
||||
"select log(ts,2 ) from ct3" ,
|
||||
"select log(c7,2 ) from ct3",
|
||||
"select log(c8,2 ) from ct3",
|
||||
|
|
|
@ -0,0 +1,652 @@
|
|||
import taos
|
||||
import sys
|
||||
import datetime
|
||||
import inspect
|
||||
import math
|
||||
from util.log import *
|
||||
from util.sql import *
|
||||
from util.cases import *
|
||||
|
||||
|
||||
class TDTestCase:
|
||||
updatecfgDict = {'debugFlag': 143 ,"cDebugFlag":143,"uDebugFlag":143 ,"rpcDebugFlag":143 , "tmrDebugFlag":143 ,
|
||||
"jniDebugFlag":143 ,"simDebugFlag":143,"dDebugFlag":143, "dDebugFlag":143,"vDebugFlag":143,"mDebugFlag":143,"qDebugFlag":143,
|
||||
"wDebugFlag":143,"sDebugFlag":143,"tsdbDebugFlag":143,"tqDebugFlag":143 ,"fsDebugFlag":143 ,"fnDebugFlag":143}
|
||||
def init(self, conn, powSql):
|
||||
tdLog.debug(f"start to excute {__file__}")
|
||||
tdSql.init(conn.cursor())
|
||||
|
||||
def prepare_datas(self):
|
||||
tdSql.execute(
|
||||
'''create table stb1
|
||||
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp)
|
||||
tags (t1 int)
|
||||
'''
|
||||
)
|
||||
|
||||
tdSql.execute(
|
||||
'''
|
||||
create table t1
|
||||
(ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(16),c9 nchar(32), c10 timestamp)
|
||||
'''
|
||||
)
|
||||
for i in range(4):
|
||||
tdSql.execute(f'create table ct{i+1} using stb1 tags ( {i+1} )')
|
||||
|
||||
for i in range(9):
|
||||
tdSql.execute(
|
||||
f"insert into ct1 values ( now()-{i*10}s, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )"
|
||||
)
|
||||
tdSql.execute(
|
||||
f"insert into ct4 values ( now()-{i*90}d, {1*i}, {11111*i}, {111*i}, {11*i}, {1.11*i}, {11.11*i}, {i%2}, 'binary{i}', 'nchar{i}', now()+{1*i}a )"
|
||||
)
|
||||
tdSql.execute("insert into ct1 values (now()-45s, 0, 0, 0, 0, 0, 0, 0, 'binary0', 'nchar0', now()+8a )")
|
||||
tdSql.execute("insert into ct1 values (now()+10s, 9, -99999, -999, -99, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )")
|
||||
tdSql.execute("insert into ct1 values (now()+15s, 9, -99999, -999, -99, -9.99, NULL, 1, 'binary9', 'nchar9', now()+9a )")
|
||||
tdSql.execute("insert into ct1 values (now()+20s, 9, -99999, -999, NULL, -9.99, -99.99, 1, 'binary9', 'nchar9', now()+9a )")
|
||||
|
||||
tdSql.execute("insert into ct4 values (now()-810d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
|
||||
tdSql.execute("insert into ct4 values (now()-400d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
|
||||
tdSql.execute("insert into ct4 values (now()+90d, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) ")
|
||||
|
||||
tdSql.execute(
|
||||
f'''insert into t1 values
|
||||
( '2020-04-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
|
||||
( '2020-10-21 01:01:01.000', 1, 11111, 111, 11, 1.11, 11.11, 1, "binary1", "nchar1", now()+1a )
|
||||
( '2020-12-31 01:01:01.000', 2, 22222, 222, 22, 2.22, 22.22, 0, "binary2", "nchar2", now()+2a )
|
||||
( '2021-01-01 01:01:06.000', 3, 33333, 333, 33, 3.33, 33.33, 0, "binary3", "nchar3", now()+3a )
|
||||
( '2021-05-07 01:01:10.000', 4, 44444, 444, 44, 4.44, 44.44, 1, "binary4", "nchar4", now()+4a )
|
||||
( '2021-07-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
|
||||
( '2021-09-30 01:01:16.000', 5, 55555, 555, 55, 5.55, 55.55, 0, "binary5", "nchar5", now()+5a )
|
||||
( '2022-02-01 01:01:20.000', 6, 66666, 666, 66, 6.66, 66.66, 1, "binary6", "nchar6", now()+6a )
|
||||
( '2022-10-28 01:01:26.000', 7, 00000, 000, 00, 0.00, 00.00, 1, "binary7", "nchar7", "1970-01-01 08:00:00.000" )
|
||||
( '2022-12-01 01:01:30.000', 8, -88888, -888, -88, -8.88, -88.88, 0, "binary8", "nchar8", "1969-01-01 01:00:00.000" )
|
||||
( '2022-12-31 01:01:36.000', 9, -99999999999999999, -999, -99, -9.99, -999999999999999999999.99, 1, "binary9", "nchar9", "1900-01-01 00:00:00.000" )
|
||||
( '2023-02-21 01:01:01.000', NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL )
|
||||
'''
|
||||
)
|
||||
|
||||
def check_result_auto_pow2(self ,origin_query , pow_query):
|
||||
|
||||
pow_result = tdSql.getResult(pow_query)
|
||||
origin_result = tdSql.getResult(origin_query)
|
||||
|
||||
auto_result =[]
|
||||
|
||||
for row in origin_result:
|
||||
row_check = []
|
||||
for elem in row:
|
||||
if elem == None:
|
||||
elem = None
|
||||
else:
|
||||
elem = math.pow(elem,2)
|
||||
row_check.append(elem)
|
||||
auto_result.append(row_check)
|
||||
|
||||
check_status = True
|
||||
|
||||
for row_index , row in enumerate(pow_result):
|
||||
for col_index , elem in enumerate(row):
|
||||
if auto_result[row_index][col_index] == None and not (auto_result[row_index][col_index] == None and elem == None):
|
||||
check_status = False
|
||||
elif auto_result[row_index][col_index] != None and (auto_result[row_index][col_index] - elem > 0.00000001):
|
||||
check_status = False
|
||||
else:
|
||||
pass
|
||||
if not check_status:
|
||||
tdLog.notice("pow function value has not as expected , sql is \"%s\" "%pow_query )
|
||||
sys.exit(1)
|
||||
else:
|
||||
tdLog.info("pow value check pass , it work as expected ,sql is \"%s\" "%pow_query )
|
||||
|
||||
def check_result_auto_pow1(self ,origin_query , pow_query):
|
||||
pow_result = tdSql.getResult(pow_query)
|
||||
origin_result = tdSql.getResult(origin_query)
|
||||
|
||||
auto_result =[]
|
||||
|
||||
for row in origin_result:
|
||||
row_check = []
|
||||
for elem in row:
|
||||
if elem == None:
|
||||
elem = None
|
||||
else :
|
||||
elem = pow(elem ,1)
|
||||
row_check.append(elem)
|
||||
auto_result.append(row_check)
|
||||
|
||||
check_status = True
|
||||
for row_index , row in enumerate(pow_result):
|
||||
for col_index , elem in enumerate(row):
|
||||
if auto_result[row_index][col_index] == None and not (auto_result[row_index][col_index] == None and elem == None):
|
||||
check_status = False
|
||||
elif auto_result[row_index][col_index] != None and (auto_result[row_index][col_index] - elem > 0.00000001):
|
||||
check_status = False
|
||||
else:
|
||||
pass
|
||||
if not check_status:
|
||||
tdLog.notice("pow function value has not as expected , sql is \"%s\" "%pow_query )
|
||||
sys.exit(1)
|
||||
else:
|
||||
tdLog.info("pow value check pass , it work as expected ,sql is \"%s\" "%pow_query )
|
||||
|
||||
def check_result_auto_pow__10(self ,origin_query , pow_query):
|
||||
pow_result = tdSql.getResult(pow_query)
|
||||
origin_result = tdSql.getResult(origin_query)
|
||||
|
||||
auto_result =[]
|
||||
|
||||
for row in origin_result:
|
||||
row_check = []
|
||||
for elem in row:
|
||||
if elem == None:
|
||||
elem = None
|
||||
elif elem == 0:
|
||||
elem = None
|
||||
else:
|
||||
elem = pow(elem ,-10)
|
||||
row_check.append(elem)
|
||||
auto_result.append(row_check)
|
||||
|
||||
check_status = True
|
||||
for row_index , row in enumerate(pow_result):
|
||||
for col_index , elem in enumerate(row):
|
||||
if auto_result[row_index][col_index] == None and not (auto_result[row_index][col_index] == None and elem == None):
|
||||
check_status = False
|
||||
elif auto_result[row_index][col_index] != None and (auto_result[row_index][col_index] - elem > 0.00000001):
|
||||
check_status = False
|
||||
else:
|
||||
pass
|
||||
if not check_status:
|
||||
tdLog.notice("pow function value has not as expected , sql is \"%s\" "%pow_query )
|
||||
sys.exit(1)
|
||||
else:
|
||||
tdLog.info("pow value check pass , it work as expected ,sql is \"%s\" "%pow_query )
|
||||
|
||||
def test_errors(self):
|
||||
error_sql_lists = [
|
||||
"select pow from t1",
|
||||
# "select pow(-+--+c1 ,2) from t1",
|
||||
# "select +-pow(c1,2) from t1",
|
||||
# "select ++-pow(c1,2) from t1",
|
||||
# "select ++--pow(c1,2) from t1",
|
||||
# "select - -pow(c1,2)*0 from t1",
|
||||
# "select pow(tbname+1,2) from t1 ",
|
||||
"select pow(123--123,2)==1 from t1",
|
||||
"select pow(c1,2) as 'd1' from t1",
|
||||
"select pow(c1 ,c2 ,2) from t1",
|
||||
"select pow(c1 ,NULL ,2) from t1",
|
||||
"select pow(, 2) from t1;",
|
||||
"select pow(pow(c1, 2) ab from t1)",
|
||||
"select pow(c1 ,2 ) as int from t1",
|
||||
"select pow from stb1",
|
||||
# "select pow(-+--+c1) from stb1",
|
||||
# "select +-pow(c1) from stb1",
|
||||
# "select ++-pow(c1) from stb1",
|
||||
# "select ++--pow(c1) from stb1",
|
||||
# "select - -pow(c1)*0 from stb1",
|
||||
# "select pow(tbname+1) from stb1 ",
|
||||
"select pow(123--123 ,2)==1 from stb1",
|
||||
"select pow(c1 ,2) as 'd1' from stb1",
|
||||
"select pow(c1 ,c2 ,2 ) from stb1",
|
||||
"select pow(c1 ,NULL,2) from stb1",
|
||||
"select pow(,) from stb1;",
|
||||
"select pow(pow(c1 , 2) ab from stb1)",
|
||||
"select pow(c1 , 2) as int from stb1"
|
||||
]
|
||||
for error_sql in error_sql_lists:
|
||||
tdSql.error(error_sql)
|
||||
|
||||
def support_types(self):
|
||||
type_error_sql_lists = [
|
||||
"select pow(ts ,2 ) from t1" ,
|
||||
"select pow(c7,c1 ) from t1",
|
||||
"select pow(c8,c2) from t1",
|
||||
"select pow(c9,c3 ) from t1",
|
||||
"select pow(ts,c4 ) from ct1" ,
|
||||
"select pow(c7,c5 ) from ct1",
|
||||
"select pow(c8,c6 ) from ct1",
|
||||
"select pow(c9,c8 ) from ct1",
|
||||
"select pow(ts,2 ) from ct3" ,
|
||||
"select pow(c7,2 ) from ct3",
|
||||
"select pow(c8,2 ) from ct3",
|
||||
"select pow(c9,2 ) from ct3",
|
||||
"select pow(ts,2 ) from ct4" ,
|
||||
"select pow(c7,2 ) from ct4",
|
||||
"select pow(c8,2 ) from ct4",
|
||||
"select pow(c9,2 ) from ct4",
|
||||
"select pow(ts,2 ) from stb1" ,
|
||||
"select pow(c7,2 ) from stb1",
|
||||
"select pow(c8,2 ) from stb1",
|
||||
"select pow(c9,2 ) from stb1" ,
|
||||
|
||||
"select pow(ts,2 ) from stbbb1" ,
|
||||
"select pow(c7,2 ) from stbbb1",
|
||||
|
||||
"select pow(ts,2 ) from tbname",
|
||||
"select pow(c9,2 ) from tbname"
|
||||
|
||||
]
|
||||
|
||||
for type_sql in type_error_sql_lists:
|
||||
tdSql.error(type_sql)
|
||||
|
||||
|
||||
type_sql_lists = [
|
||||
"select pow(c1,2 ) from t1",
|
||||
"select pow(c2,2 ) from t1",
|
||||
"select pow(c3,2 ) from t1",
|
||||
"select pow(c4,2 ) from t1",
|
||||
"select pow(c5,2 ) from t1",
|
||||
"select pow(c6,2 ) from t1",
|
||||
|
||||
"select pow(c1,2 ) from ct1",
|
||||
"select pow(c2,2 ) from ct1",
|
||||
"select pow(c3,2 ) from ct1",
|
||||
"select pow(c4,2 ) from ct1",
|
||||
"select pow(c5,2 ) from ct1",
|
||||
"select pow(c6,2 ) from ct1",
|
||||
|
||||
"select pow(c1,2 ) from ct3",
|
||||
"select pow(c2,2 ) from ct3",
|
||||
"select pow(c3,2 ) from ct3",
|
||||
"select pow(c4,2 ) from ct3",
|
||||
"select pow(c5,2 ) from ct3",
|
||||
"select pow(c6,2 ) from ct3",
|
||||
|
||||
"select pow(c1,2 ) from stb1",
|
||||
"select pow(c2,2 ) from stb1",
|
||||
"select pow(c3,2 ) from stb1",
|
||||
"select pow(c4,2 ) from stb1",
|
||||
"select pow(c5,2 ) from stb1",
|
||||
"select pow(c6,2 ) from stb1",
|
||||
|
||||
"select pow(c6,2) as alisb from stb1",
|
||||
"select pow(c6,2) alisb from stb1",
|
||||
]
|
||||
|
||||
for type_sql in type_sql_lists:
|
||||
tdSql.query(type_sql)
|
||||
|
||||
def basic_pow_function(self):
|
||||
|
||||
# basic query
|
||||
tdSql.query("select c1 from ct3")
|
||||
tdSql.checkRows(0)
|
||||
tdSql.query("select c1 from t1")
|
||||
tdSql.checkRows(12)
|
||||
tdSql.query("select c1 from stb1")
|
||||
tdSql.checkRows(25)
|
||||
|
||||
# used for empty table , ct3 is empty
|
||||
tdSql.query("select pow(c1 ,2) from ct3")
|
||||
tdSql.checkRows(0)
|
||||
tdSql.query("select pow(c2 ,2) from ct3")
|
||||
tdSql.checkRows(0)
|
||||
tdSql.query("select pow(c3 ,2) from ct3")
|
||||
tdSql.checkRows(0)
|
||||
tdSql.query("select pow(c4 ,2) from ct3")
|
||||
tdSql.checkRows(0)
|
||||
tdSql.query("select pow(c5 ,2) from ct3")
|
||||
tdSql.checkRows(0)
|
||||
tdSql.query("select pow(c6 ,2) from ct3")
|
||||
tdSql.checkRows(0)
|
||||
|
||||
|
||||
# # used for regular table
|
||||
tdSql.query("select pow(c1 ,2) from t1")
|
||||
tdSql.checkData(0, 0, None)
|
||||
tdSql.checkData(1 , 0, 1.000000000)
|
||||
tdSql.checkData(3 , 0, 9.000000000)
|
||||
tdSql.checkData(5 , 0, None)
|
||||
|
||||
tdSql.query("select c1, c2, c3 , c4, c5 from t1")
|
||||
tdSql.checkData(1, 4, 1.11000)
|
||||
tdSql.checkData(3, 3, 33)
|
||||
tdSql.checkData(5, 4, None)
|
||||
|
||||
tdSql.query("select ts,c1, c2, c3 , c4, c5 from t1")
|
||||
tdSql.checkData(1, 5, 1.11000)
|
||||
tdSql.checkData(3, 4, 33)
|
||||
tdSql.checkData(5, 5, None)
|
||||
|
||||
self.check_result_auto_pow2( "select c1, c2, c3 , c4, c5 from t1", "select pow(c1 ,2), pow(c2 ,2) ,pow(c3, 2), pow(c4 ,2), pow(c5 ,2) from t1")
|
||||
self.check_result_auto_pow1( "select c1, c2, c3 , c4, c5 from t1", "select pow(c1 ,1), pow(c2 ,1) ,pow(c3, 1), pow(c4 ,1), pow(c5 ,1) from t1")
|
||||
self.check_result_auto_pow__10( "select c1, c2, c3 , c4, c5 from t1", "select pow(c1 ,-10), pow(c2 ,-10) ,pow(c3, -10), pow(c4 ,-10), pow(c5 ,-10) from t1")
|
||||
|
||||
# used for sub table
|
||||
tdSql.query("select c1 ,pow(c1 ,2) from ct1")
|
||||
tdSql.checkData(0, 1, 64.000000000)
|
||||
tdSql.checkData(1 , 1, 49.000000000)
|
||||
tdSql.checkData(3 , 1, 25.000000000)
|
||||
tdSql.checkData(4 , 1, 0)
|
||||
|
||||
# # test bug fix for pow(c1,c2)
|
||||
|
||||
tdSql.query("select c1, c5 ,pow(c1,c5) from ct4")
|
||||
tdSql.checkData(0 , 2, None)
|
||||
tdSql.checkData(1 , 2, 104577724.506799981)
|
||||
tdSql.checkData(2 , 2, 3684781.623933245)
|
||||
tdSql.checkData(3 , 2, 152225.429759376)
|
||||
tdSql.checkData(4 , 2, 7573.273783071)
|
||||
|
||||
|
||||
self.check_result_auto_pow2( "select c1, c2, c3 , c4, c5 from ct1", "select pow(c1,2), pow(c2,2) ,pow(c3,2), pow(c4,2), pow(c5,2) from ct1")
|
||||
self.check_result_auto_pow__10( "select c1, c2, c3 , c4, c5 from ct1", "select pow(c1,-10), pow(c2,-10) ,pow(c3,-10), pow(c4,-10), pow(c5,-10) from ct1")
|
||||
|
||||
# nest query for pow functions
|
||||
tdSql.query("select c1 , pow(c1,2) ,pow(pow(c1,2),2) , pow(pow(pow(c1,2),2),2) from ct1;")
|
||||
tdSql.checkData(0 , 0 , 8)
|
||||
tdSql.checkData(0 , 1 , 64.000000000)
|
||||
tdSql.checkData(0 , 2 , 4096.000000000)
|
||||
tdSql.checkData(0 , 3 , 16777216.000000000)
|
||||
|
||||
tdSql.checkData(1 , 0 , 7)
|
||||
tdSql.checkData(1 , 1 , 49.000000000)
|
||||
tdSql.checkData(1 , 2 , 2401.000000000)
|
||||
tdSql.checkData(1 , 3 , 5764801.000000000)
|
||||
|
||||
tdSql.checkData(4 , 0 , 0)
|
||||
tdSql.checkData(4 , 1 , 0.000000000)
|
||||
tdSql.checkData(4 , 2 , 0.000000000)
|
||||
tdSql.checkData(4 , 3 , 0.000000000)
|
||||
|
||||
# # used for stable table
|
||||
|
||||
tdSql.query("select pow(c1, 2) from stb1")
|
||||
tdSql.checkRows(25)
|
||||
|
||||
|
||||
# used for not exists table
|
||||
tdSql.error("select pow(c1, 2) from stbbb1")
|
||||
tdSql.error("select pow(c1, 2) from tbname")
|
||||
tdSql.error("select pow(c1, 2) from ct5")
|
||||
|
||||
# mix with common col
|
||||
tdSql.query("select c1, pow(c1 ,2) from ct1")
|
||||
tdSql.checkData(0 , 0 ,8)
|
||||
tdSql.checkData(0 , 1 ,64.000000000)
|
||||
tdSql.checkData(4 , 0 ,0)
|
||||
tdSql.checkData(4 , 1 ,0.000000000)
|
||||
tdSql.query("select c1, pow(c1,2) from ct4")
|
||||
tdSql.checkData(0 , 0 , None)
|
||||
tdSql.checkData(0 , 1 ,None)
|
||||
tdSql.checkData(4 , 0 ,5)
|
||||
tdSql.checkData(4 , 1 ,25.000000000)
|
||||
tdSql.checkData(5 , 0 ,None)
|
||||
tdSql.checkData(5 , 1 ,None)
|
||||
|
||||
# mix with common functions
|
||||
tdSql.query("select c1, pow(c1 ,2),pow(c1,2), log(pow(c1,2) ,2) from ct4 ")
|
||||
tdSql.checkData(0 , 0 ,None)
|
||||
tdSql.checkData(0 , 1 ,None)
|
||||
tdSql.checkData(0 , 2 ,None)
|
||||
tdSql.checkData(0 , 3 ,None)
|
||||
|
||||
tdSql.checkData(3 , 0 , 6)
|
||||
tdSql.checkData(3 , 1 ,36.000000000)
|
||||
tdSql.checkData(3 , 2 ,36.000000000)
|
||||
tdSql.checkData(3 , 3 ,5.169925001)
|
||||
|
||||
tdSql.query("select c1, pow(c1,1),c5, floor(c5 ) from stb1 ")
|
||||
|
||||
# # mix with agg functions , not support
|
||||
tdSql.error("select c1, pow(c1 ,2),c5, count(c5) from stb1 ")
|
||||
tdSql.error("select c1, pow(c1 ,2),c5, count(c5) from ct1 ")
|
||||
tdSql.error("select pow(c1 ,2), count(c5) from stb1 ")
|
||||
tdSql.error("select pow(c1 ,2), count(c5) from ct1 ")
|
||||
tdSql.error("select c1, count(c5) from ct1 ")
|
||||
tdSql.error("select c1, count(c5) from stb1 ")
|
||||
|
||||
# agg functions mix with agg functions
|
||||
|
||||
tdSql.query("select max(c5), count(c5) from stb1")
|
||||
tdSql.query("select max(c5), count(c5) from ct1")
|
||||
|
||||
|
||||
# bug fix for count
|
||||
tdSql.query("select count(c1) from ct4 ")
|
||||
tdSql.checkData(0,0,9)
|
||||
tdSql.query("select count(*) from ct4 ")
|
||||
tdSql.checkData(0,0,12)
|
||||
tdSql.query("select count(c1) from stb1 ")
|
||||
tdSql.checkData(0,0,22)
|
||||
tdSql.query("select count(*) from stb1 ")
|
||||
tdSql.checkData(0,0,25)
|
||||
|
||||
# # bug fix for compute
|
||||
tdSql.query("select c1, pow(c1 ,2) -0 ,pow(c1-4 ,2)-0 from ct4 ")
|
||||
tdSql.checkData(0, 0, None)
|
||||
tdSql.checkData(0, 1, None)
|
||||
tdSql.checkData(0, 2, None)
|
||||
tdSql.checkData(1, 0, 8)
|
||||
tdSql.checkData(1, 1, 64.000000000)
|
||||
tdSql.checkData(1, 2, 16.000000000)
|
||||
|
||||
tdSql.query(" select c1, pow(c1 ,2) -0 ,pow(c1-0.1 ,2)-0.1 from ct4")
|
||||
tdSql.checkData(0, 0, None)
|
||||
tdSql.checkData(0, 1, None)
|
||||
tdSql.checkData(0, 2, None)
|
||||
tdSql.checkData(1, 0, 8)
|
||||
tdSql.checkData(1, 1, 64.000000000)
|
||||
tdSql.checkData(1, 2, 62.310000000)
|
||||
|
||||
tdSql.query("select c1, pow(c1, -10), c2, pow(c2, -10), c3, pow(c3, -10) from ct1")
|
||||
|
||||
def test_big_number(self):
|
||||
|
||||
tdSql.query("select c1, pow(c1, 100000000) from ct1") # bigint to double data overflow
|
||||
tdSql.checkData(0, 1, None)
|
||||
tdSql.checkData(1, 1, None)
|
||||
tdSql.checkData(4, 1, 0.000000000)
|
||||
|
||||
|
||||
tdSql.query("select c1, pow(c1, 10000000000000) from ct1") # bigint to double data overflow
|
||||
tdSql.checkData(0, 1, None)
|
||||
tdSql.checkData(1, 1, None)
|
||||
tdSql.checkData(4, 1, 0.000000000)
|
||||
|
||||
tdSql.query("select c1, pow(c1, 10000000000000000000000000) from ct1") # bigint to double data overflow
|
||||
tdSql.query("select c1, pow(c1, 10000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value
|
||||
tdSql.checkData(0, 1, None)
|
||||
tdSql.checkData(1, 1, None)
|
||||
tdSql.checkData(4, 1, 0.000000000)
|
||||
|
||||
tdSql.query("select c1, pow(c1, 10000000000000000000000000000000000) from ct1") # bigint to double data overflow
|
||||
tdSql.query("select c1, pow(c1, 10000000000000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value
|
||||
tdSql.checkData(0, 1, None)
|
||||
tdSql.checkData(1, 1, None)
|
||||
tdSql.checkData(4, 1, 0.000000000)
|
||||
|
||||
tdSql.query("select c1, pow(c1, 10000000000000000000000000000000000000000) from ct1") # bigint to double data overflow
|
||||
tdSql.query("select c1, pow(c1, 10000000000000000000000000000000000000000.0) from ct1") # 10000000000000000000000000.0 is a double value
|
||||
tdSql.checkData(0, 1, None)
|
||||
tdSql.checkData(1, 1, None)
|
||||
tdSql.checkData(4, 1, 0.000000000)
|
||||
|
||||
tdSql.query("select c1, pow(c1, 10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000) from ct1") # bigint to double data overflow
|
||||
|
||||
def pow_base_test(self):
|
||||
|
||||
# base is an regular number ,int or double
|
||||
tdSql.query("select c1, pow(c1, 2) from ct1")
|
||||
tdSql.checkData(0, 1,64.000000000)
|
||||
tdSql.query("select c1, pow(c1, 2.0) from ct1")
|
||||
tdSql.checkData(0, 1, 64.000000000)
|
||||
|
||||
tdSql.query("select c1, pow(1, 2.0) from ct1")
|
||||
tdSql.checkData(0, 1, 1.000000000)
|
||||
tdSql.checkRows(13)
|
||||
|
||||
|
||||
# # bug for compute in functions
|
||||
# tdSql.query("select c1, abs(1/0) from ct1")
|
||||
# tdSql.checkData(0, 0, 8)
|
||||
# tdSql.checkData(0, 1, 1)
|
||||
|
||||
tdSql.query("select c1, pow(1, 2.0) from ct1")
|
||||
tdSql.checkData(0, 1, 1.000000000)
|
||||
tdSql.checkRows(13)
|
||||
|
||||
# two cols start pow(x,y)
|
||||
tdSql.query("select c1,c2, pow(c1,c2) from ct1")
|
||||
tdSql.checkData(0, 2, None)
|
||||
tdSql.checkData(1, 2, None)
|
||||
tdSql.checkData(4, 2, 1.000000000)
|
||||
|
||||
tdSql.query("select c1,c2, pow(c2,c1) from ct1")
|
||||
tdSql.checkData(0, 2, 3897131646727578700481513520437089271808.000000000)
|
||||
tdSql.checkData(1, 2, 17217033054561120738612297152331776.000000000)
|
||||
tdSql.checkData(4, 2, 1.000000000)
|
||||
|
||||
tdSql.query("select c1, pow(2.0 , c1) from ct1")
|
||||
tdSql.checkData(0, 1, 256.000000000)
|
||||
tdSql.checkData(1, 1, 128.000000000)
|
||||
tdSql.checkData(4, 1, 1.000000000)
|
||||
|
||||
tdSql.query("select c1, pow(2.0 , c1) from ct1")
|
||||
tdSql.checkData(0, 1, 256.000000000)
|
||||
tdSql.checkData(1, 1, 128.000000000)
|
||||
tdSql.checkData(4, 1, 1.000000000)
|
||||
|
||||
def abs_func_filter(self):
|
||||
tdSql.execute("use db")
|
||||
tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(pow(c1,2)-0.5) from ct4 where c1>5 ")
|
||||
tdSql.checkRows(3)
|
||||
tdSql.checkData(0,0,8)
|
||||
tdSql.checkData(0,1,8.000000000)
|
||||
tdSql.checkData(0,2,8.000000000)
|
||||
tdSql.checkData(0,3,7.900000000)
|
||||
tdSql.checkData(0,4,64.000000000)
|
||||
|
||||
tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(pow(c1,2)-0.5) from ct4 where c1=5 ")
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0,0,5)
|
||||
tdSql.checkData(0,1,5.000000000)
|
||||
tdSql.checkData(0,2,5.000000000)
|
||||
tdSql.checkData(0,3,4.900000000)
|
||||
tdSql.checkData(0,4,25.000000000)
|
||||
|
||||
tdSql.query("select c1, abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(pow(c1,2)-0.5) from ct4 where c1=5 ")
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0,0,5)
|
||||
tdSql.checkData(0,1,5.000000000)
|
||||
tdSql.checkData(0,2,5.000000000)
|
||||
tdSql.checkData(0,3,4.900000000)
|
||||
tdSql.checkData(0,4,25.000000000)
|
||||
|
||||
tdSql.query("select c1,c2 , abs(c1) -0 ,ceil(c1-0.1)-0 ,floor(c1+0.1)-0.1 ,ceil(pow(c1,2)-0.5) from ct4 where c1<pow(c1,2) limit 1 ")
|
||||
tdSql.checkRows(1)
|
||||
tdSql.checkData(0,0,8)
|
||||
tdSql.checkData(0,1,88888)
|
||||
tdSql.checkData(0,2,8.000000000)
|
||||
tdSql.checkData(0,3,8.000000000)
|
||||
tdSql.checkData(0,4,7.900000000)
|
||||
tdSql.checkData(0,5,64.000000000)
|
||||
|
||||
def pow_Arithmetic(self):
|
||||
pass
|
||||
|
||||
def check_boundary_values(self):
|
||||
|
||||
tdSql.execute("drop database if exists bound_test")
|
||||
tdSql.execute("create database if not exists bound_test")
|
||||
time.sleep(3)
|
||||
tdSql.execute("use bound_test")
|
||||
tdSql.execute(
|
||||
"create table stb_bound (ts timestamp, c1 int, c2 bigint, c3 smallint, c4 tinyint, c5 float, c6 double, c7 bool, c8 binary(32),c9 nchar(32), c10 timestamp) tags (t1 int);"
|
||||
)
|
||||
tdSql.execute(f'create table sub1_bound using stb_bound tags ( 1 )')
|
||||
tdSql.execute(
|
||||
f"insert into sub1_bound values ( now()-1s, 2147483647, 9223372036854775807, 32767, 127, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
|
||||
)
|
||||
tdSql.execute(
|
||||
f"insert into sub1_bound values ( now()-1s, -2147483647, -9223372036854775807, -32767, -127, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
|
||||
)
|
||||
tdSql.execute(
|
||||
f"insert into sub1_bound values ( now(), 2147483646, 9223372036854775806, 32766, 126, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
|
||||
)
|
||||
tdSql.execute(
|
||||
f"insert into sub1_bound values ( now(), -2147483646, -9223372036854775806, -32766, -126, -3.40E+38, -1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
|
||||
)
|
||||
tdSql.error(
|
||||
f"insert into sub1_bound values ( now()+1s, 2147483648, 9223372036854775808, 32768, 128, 3.40E+38, 1.7e+308, True, 'binary_tb1', 'nchar_tb1', now() )"
|
||||
)
|
||||
self.check_result_auto_pow2( "select c1, c2, c3 , c4, c5 from sub1_bound ", "select pow(c1,2), pow(c2,2) ,pow(c3,2), pow(c4,2), pow(c5,2) from sub1_bound")
|
||||
self.check_result_auto_pow__10( "select c1, c2, c3 , c4, c5 from sub1_bound ", "select pow(c1,-10), pow(c2,-10) ,pow(c3,-10), pow(c4,-10), pow(c5,-10) from sub1_bound")
|
||||
|
||||
self.check_result_auto_pow2( "select c1, c2, c3 , c3, c2 ,c1 from sub1_bound ", "select pow(c1,2), pow(c2,2) ,pow(c3,2), pow(c3,2), pow(c2,2) ,pow(c1,2) from sub1_bound")
|
||||
|
||||
|
||||
self.check_result_auto_pow2("select abs(abs(abs(abs(abs(abs(abs(abs(abs(c1))))))))) nest_col_func from sub1_bound" , "select pow(abs(c1) ,2) from sub1_bound" )
|
||||
|
||||
# check basic elem for table per row
|
||||
tdSql.query("select pow(abs(c1),2) ,pow(abs(c2),2) , pow(abs(c3),2) , pow(abs(c4),2), pow(abs(c5),2), pow(abs(c6),2) from sub1_bound ")
|
||||
tdSql.checkData(0,0,math.pow(2147483647,2))
|
||||
tdSql.checkData(0,1,math.pow(9223372036854775807 ,2))
|
||||
tdSql.checkData(0,2,math.pow(32767,2))
|
||||
tdSql.checkData(0,3,math.pow(127 ,2))
|
||||
tdSql.checkData(0,4,math.pow(339999995214436424907732413799364296704.00000,2))
|
||||
tdSql.checkData(1,0,math.pow(2147483647 ,2))
|
||||
tdSql.checkData(1,1,math.pow(9223372036854775807 ,2))
|
||||
tdSql.checkData(1,2,math.pow(32767 ,2))
|
||||
tdSql.checkData(1,3,math.pow(127,2))
|
||||
tdSql.checkData(1,4,math.pow(339999995214436424907732413799364296704.00000 ,2))
|
||||
tdSql.checkData(3,0,math.pow(2147483646,2))
|
||||
tdSql.checkData(3,1,math.pow(9223372036854775806,2))
|
||||
tdSql.checkData(3,2,math.pow(32766,2))
|
||||
tdSql.checkData(3,3,math.pow(126 ,2))
|
||||
tdSql.checkData(3,4,math.pow(339999995214436424907732413799364296704.00000,2))
|
||||
|
||||
# check + - * / in functions
|
||||
tdSql.query("select pow(abs(c1+1) ,2) ,pow(abs(c2),2) , pow(abs(c3*1),2) , pow(abs(c4/2),2), pow(abs(c5) ,2)/2, pow(abs(c6) ,2) from sub1_bound ")
|
||||
tdSql.checkData(0,0,math.pow(2147483648.000000000,2))
|
||||
tdSql.checkData(0,1,math.pow(9223372036854775807,2))
|
||||
tdSql.checkData(0,2,math.pow(32767.000000000,2))
|
||||
tdSql.checkData(0,3,math.pow(63.500000000,2))
|
||||
tdSql.checkData(0,5,None)
|
||||
|
||||
|
||||
def run(self): # sourcery skip: extract-duplicate-method, remove-redundant-fstring
|
||||
tdSql.prepare()
|
||||
|
||||
tdLog.printNoPrefix("==========step1:create table ==============")
|
||||
|
||||
self.prepare_datas()
|
||||
|
||||
tdLog.printNoPrefix("==========step2:test errors ==============")
|
||||
|
||||
self.test_errors()
|
||||
|
||||
tdLog.printNoPrefix("==========step3:support types ============")
|
||||
|
||||
self.support_types()
|
||||
|
||||
tdLog.printNoPrefix("==========step4: pow basic query ============")
|
||||
|
||||
self.basic_pow_function()
|
||||
|
||||
tdLog.printNoPrefix("==========step5: big number pow query ============")
|
||||
|
||||
self.test_big_number()
|
||||
|
||||
tdLog.printNoPrefix("==========step6: base number for pow query ============")
|
||||
|
||||
self.pow_base_test()
|
||||
|
||||
tdLog.printNoPrefix("==========step7: pow boundary query ============")
|
||||
|
||||
self.check_boundary_values()
|
||||
|
||||
tdLog.printNoPrefix("==========step8: pow filter query ============")
|
||||
|
||||
self.abs_func_filter()
|
||||
|
||||
|
||||
|
||||
def stop(self):
|
||||
tdSql.close()
|
||||
tdLog.success(f"{__file__} successfully executed")
|
||||
|
||||
tdCases.addLinux(__file__, TDTestCase())
|
||||
tdCases.addWindows(__file__, TDTestCase())
|
|
@ -23,3 +23,4 @@ python3 ./test.py -f 2-query/ceil.py
|
|||
python3 ./test.py -f 2-query/floor.py
|
||||
python3 ./test.py -f 2-query/round.py
|
||||
python3 ./test.py -f 2-query/log.py
|
||||
python3 ./test.py -f 2-query/pow.py
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit bf6c766986c61ff4fc80421fdea682a8fd4b5b32
|
||||
Subproject commit 2f3dfddd4d9a869e706ba3cf98fb6d769404cd7c
|
Loading…
Reference in New Issue