Merge branch '3.0' into feature/3.0_glzhao
This commit is contained in:
commit
57cd462000
|
@ -15,12 +15,12 @@ MESSAGE(STATUS "Project executable files output path: " ${EXECUTABLE_OUTPUT_PATH
|
|||
MESSAGE(STATUS "Project library files output path: " ${LIBRARY_OUTPUT_PATH})
|
||||
|
||||
find_package(Git QUIET)
|
||||
if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
|
||||
if(GIT_FOUND AND EXISTS "${TD_SOURCE_DIR}/.git")
|
||||
# Update submodules as needed
|
||||
option(GIT_SUBMODULE "Check submodules during build" ON)
|
||||
if(GIT_SUBMODULE)
|
||||
message(STATUS "Submodule update")
|
||||
execute_process(COMMAND ${GIT_EXECUTABLE} submodule update --init --recursive
|
||||
execute_process(COMMAND cd ${TD_SOURCE_DIR} && ${GIT_EXECUTABLE} submodule update --init --recursive
|
||||
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
RESULT_VARIABLE GIT_SUBMOD_RESULT)
|
||||
if(NOT GIT_SUBMOD_RESULT EQUAL "0")
|
||||
|
@ -29,7 +29,7 @@ if(GIT_FOUND AND EXISTS "${PROJECT_SOURCE_DIR}/.git")
|
|||
endif()
|
||||
endif()
|
||||
|
||||
if(NOT EXISTS "${PROJECT_SOURCE_DIR}/tools/taos-tools/CMakeLists.txt")
|
||||
if(NOT EXISTS "${TD_SOURCE_DIR}/tools/taos-tools/CMakeLists.txt")
|
||||
message(WARNING "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules manually if you need build them.")
|
||||
endif()
|
||||
|
||||
|
|
|
@ -83,7 +83,7 @@ int32_t create_stream() {
|
|||
/*pRes = tmq_create_stream(pConn, "stream1", "out1", sql);*/
|
||||
pRes = taos_query(
|
||||
pConn,
|
||||
"create stream stream1 trigger window_close into outstb as select _wstartts, min(k), max(k), sum(k) as sum_of_k "
|
||||
"create stream stream1 trigger at_once into outstb 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));
|
||||
|
|
|
@ -221,15 +221,12 @@ DLL_EXPORT void tmq_list_destroy(tmq_list_t *);
|
|||
DLL_EXPORT int32_t tmq_list_get_size(const tmq_list_t *);
|
||||
DLL_EXPORT char **tmq_list_to_c_array(const tmq_list_t *);
|
||||
|
||||
#if 0
|
||||
DLL_EXPORT tmq_t *tmq_consumer_new(void *conn, tmq_conf_t *conf, char *errstr, int32_t errstrLen);
|
||||
#endif
|
||||
|
||||
DLL_EXPORT tmq_t *tmq_consumer_new(tmq_conf_t *conf, char *errstr, int32_t errstrLen);
|
||||
|
||||
DLL_EXPORT const char *tmq_err2str(tmq_resp_err_t);
|
||||
|
||||
/* ------------------------TMQ CONSUMER INTERFACE------------------------ */
|
||||
|
||||
DLL_EXPORT tmq_resp_err_t tmq_subscribe(tmq_t *tmq, const tmq_list_t *topic_list);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_unsubscribe(tmq_t *tmq);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_subscription(tmq_t *tmq, tmq_list_t **topics);
|
||||
|
@ -240,6 +237,7 @@ DLL_EXPORT tmq_resp_err_t tmq_commit(tmq_t *tmq, const tmq_topic_vgroup_list_t *
|
|||
DLL_EXPORT tmq_resp_err_t tmq_commit_message(tmq_t* tmq, const tmq_message_t* tmqmessage, int32_t async);
|
||||
DLL_EXPORT tmq_resp_err_t tmq_seek(tmq_t *tmq, const tmq_topic_vgroup_t *offset);
|
||||
#endif
|
||||
|
||||
/* ----------------------TMQ CONFIGURATION INTERFACE---------------------- */
|
||||
|
||||
enum tmq_conf_res_t {
|
||||
|
@ -268,12 +266,9 @@ DLL_EXPORT char *tmq_get_table_name(TAOS_RES *res);
|
|||
DLL_EXPORT int64_t tmq_get_request_offset(tmq_message_t *message);
|
||||
DLL_EXPORT int64_t tmq_get_response_offset(tmq_message_t *message);
|
||||
#endif
|
||||
/* --------------------TMPORARY INTERFACE FOR TESTING--------------------- */
|
||||
#if 0
|
||||
DLL_EXPORT TAOS_RES *tmq_create_topic(TAOS *taos, const char *name, const char *sql, int sqlLen);
|
||||
DLL_EXPORT TAOS_RES *tmq_create_stream(TAOS *taos, const char *streamName, const char *tbName, const char *sql);
|
||||
#endif
|
||||
|
||||
/* ------------------------------ TMQ END -------------------------------- */
|
||||
|
||||
#if 1 // Shuduo: temporary enable for app build
|
||||
typedef void (*TAOS_SUBSCRIBE_CALLBACK)(TAOS_SUB *tsub, TAOS_RES *res, void *param, int code);
|
||||
#endif
|
||||
|
|
|
@ -45,7 +45,6 @@ extern "C" {
|
|||
|
||||
#define TSDB_PERFORMANCE_SCHEMA_DB "performance_schema"
|
||||
#define TSDB_PERFS_TABLE_SMAS "smas"
|
||||
#define TSDB_PERFS_TABLE_SUBSCRIBES "subscribes"
|
||||
#define TSDB_PERFS_TABLE_CONNECTIONS "connections"
|
||||
#define TSDB_PERFS_TABLE_QUERIES "queries"
|
||||
#define TSDB_PERFS_TABLE_TOPICS "topics"
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
/*
|
||||
* 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_TDATA_H_
|
||||
#define _TD_TDATA_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "os.h"
|
||||
|
||||
typedef struct STaosData TDATA, tdata_t;
|
||||
|
||||
typedef enum {
|
||||
TAOS_META_STABLE_DATA = 0, // super table meta
|
||||
TAOS_META_TABLE_DATA, // non-super table meta
|
||||
TAOS_TS_ROW_DATA, // row time-series data
|
||||
TAOS_TS_COL_DATA, // col time-series data
|
||||
TAOS_DATA_MAX
|
||||
} ETaosDataT;
|
||||
|
||||
struct STaosData {
|
||||
ETaosDataT type;
|
||||
uint32_t nPayload;
|
||||
uint8_t *pPayload;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_TDATA_H_*/
|
|
@ -150,29 +150,6 @@ int32_t tdAddColToSchema(STSchemaBuilder *pBuilder, int8_t type, int8_t flags,
|
|||
STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder);
|
||||
|
||||
// ----------------- Semantic timestamp key definition
|
||||
#ifdef TD_2_0
|
||||
|
||||
typedef uint64_t TKEY;
|
||||
|
||||
#define TKEY_INVALID UINT64_MAX
|
||||
#define TKEY_NULL TKEY_INVALID
|
||||
#define TKEY_NEGATIVE_FLAG (((TKEY)1) << 63)
|
||||
#define TKEY_DELETE_FLAG (((TKEY)1) << 62)
|
||||
#define TKEY_VALUE_FILTER (~(TKEY_NEGATIVE_FLAG | TKEY_DELETE_FLAG))
|
||||
|
||||
#define TKEY_IS_NEGATIVE(tkey) (((tkey)&TKEY_NEGATIVE_FLAG) != 0)
|
||||
#define TKEY_IS_DELETED(tkey) (((tkey)&TKEY_DELETE_FLAG) != 0)
|
||||
#define tdSetTKEYDeleted(tkey) ((tkey) | TKEY_DELETE_FLAG)
|
||||
#define tdGetTKEY(key) (((TKEY)TABS(key)) | (TKEY_NEGATIVE_FLAG & (TKEY)(key)))
|
||||
#define tdGetKey(tkey) (((TSKEY)((tkey)&TKEY_VALUE_FILTER)) * (TKEY_IS_NEGATIVE(tkey) ? -1 : 1))
|
||||
|
||||
#define MIN_TS_KEY ((TSKEY)0x8000000000000001)
|
||||
#define MAX_TS_KEY ((TSKEY)0x3fffffffffffffff)
|
||||
|
||||
#define TD_TO_TKEY(key) tdGetTKEY(((key) < MIN_TS_KEY) ? MIN_TS_KEY : (((key) > MAX_TS_KEY) ? MAX_TS_KEY : key))
|
||||
|
||||
#else
|
||||
|
||||
// typedef uint64_t TKEY;
|
||||
#define TKEY TSKEY
|
||||
|
||||
|
@ -192,8 +169,6 @@ typedef uint64_t TKEY;
|
|||
|
||||
#define TD_TO_TKEY(key) tdGetTKEY(((key) < MIN_TS_KEY) ? MIN_TS_KEY : (((key) > MAX_TS_KEY) ? MAX_TS_KEY : key))
|
||||
|
||||
#endif
|
||||
|
||||
static FORCE_INLINE TKEY keyToTkey(TSKEY key) {
|
||||
TSKEY lkey = key;
|
||||
if (key > MAX_TS_KEY) {
|
||||
|
@ -218,157 +193,6 @@ static FORCE_INLINE int32_t tkeyComparFn(const void *tkey1, const void *tkey2) {
|
|||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
// ----------------- Data row structure
|
||||
|
||||
/* A data row, the format is like below:
|
||||
* |<------------------------------------------------ len ---------------------------------->|
|
||||
* |<-- Head -->|<--------- flen -------------->| |
|
||||
* +---------------------+---------------------------------+---------------------------------+
|
||||
* | uint16_t | int16_t | | |
|
||||
* +----------+----------+---------------------------------+---------------------------------+
|
||||
* | len | sversion | First part | Second part |
|
||||
* +----------+----------+---------------------------------+---------------------------------+
|
||||
*
|
||||
* NOTE: timestamp in this row structure is TKEY instead of TSKEY
|
||||
*/
|
||||
typedef void *SDataRow;
|
||||
|
||||
#define TD_DATA_ROW_HEAD_SIZE (sizeof(uint16_t) + sizeof(int16_t))
|
||||
|
||||
#define dataRowLen(r) (*(TDRowLenT *)(r)) // 0~65535
|
||||
#define dataRowEnd(r) POINTER_SHIFT(r, dataRowLen(r))
|
||||
#define dataRowVersion(r) (*(int16_t *)POINTER_SHIFT(r, sizeof(int16_t)))
|
||||
#define dataRowTuple(r) POINTER_SHIFT(r, TD_DATA_ROW_HEAD_SIZE)
|
||||
#define dataRowTKey(r) (*(TKEY *)(dataRowTuple(r)))
|
||||
#define dataRowKey(r) tdGetKey(dataRowTKey(r))
|
||||
#define dataRowSetLen(r, l) (dataRowLen(r) = (l))
|
||||
#define dataRowSetVersion(r, v) (dataRowVersion(r) = (v))
|
||||
#define dataRowCpy(dst, r) memcpy((dst), (r), dataRowLen(r))
|
||||
#define dataRowMaxBytesFromSchema(s) (schemaTLen(s) + TD_DATA_ROW_HEAD_SIZE)
|
||||
#define dataRowDeleted(r) TKEY_IS_DELETED(dataRowTKey(r))
|
||||
|
||||
SDataRow tdNewDataRowFromSchema(STSchema *pSchema);
|
||||
void tdFreeDataRow(SDataRow row);
|
||||
void tdInitDataRow(SDataRow row, STSchema *pSchema);
|
||||
SDataRow tdDataRowDup(SDataRow row);
|
||||
|
||||
// offset here not include dataRow header length
|
||||
static FORCE_INLINE int32_t tdAppendDataColVal(SDataRow row, const void *value, bool isCopyVarData, int8_t type,
|
||||
int32_t offset) {
|
||||
assert(value != NULL);
|
||||
int32_t toffset = offset + TD_DATA_ROW_HEAD_SIZE;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
*(VarDataOffsetT *)POINTER_SHIFT(row, toffset) = dataRowLen(row);
|
||||
if (isCopyVarData) {
|
||||
memcpy(POINTER_SHIFT(row, dataRowLen(row)), value, varDataTLen(value));
|
||||
}
|
||||
dataRowLen(row) += varDataTLen(value);
|
||||
} else {
|
||||
if (offset == 0) {
|
||||
assert(type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
TKEY tvalue = tdGetTKEY(*(TSKEY *)value);
|
||||
memcpy(POINTER_SHIFT(row, toffset), (const void *)(&tvalue), TYPE_BYTES[type]);
|
||||
} else {
|
||||
memcpy(POINTER_SHIFT(row, toffset), value, TYPE_BYTES[type]);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// offset here not include dataRow header length
|
||||
static FORCE_INLINE int32_t tdAppendColVal(SDataRow row, const void *value, int8_t type, int32_t offset) {
|
||||
return tdAppendDataColVal(row, value, true, type, offset);
|
||||
}
|
||||
|
||||
// NOTE: offset here including the header size
|
||||
static FORCE_INLINE void *tdGetRowDataOfCol(SDataRow row, int8_t type, int32_t offset) {
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
return POINTER_SHIFT(row, *(VarDataOffsetT *)POINTER_SHIFT(row, offset));
|
||||
} else {
|
||||
return POINTER_SHIFT(row, offset);
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE void *tdGetPtrToCol(SDataRow row, STSchema *pSchema, int32_t idx) {
|
||||
return POINTER_SHIFT(row, TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void *tdGetColOfRowBySchema(SDataRow row, STSchema *pSchema, int32_t idx) {
|
||||
int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
|
||||
return tdGetRowDataOfCol(row, type, offset);
|
||||
}
|
||||
|
||||
static FORCE_INLINE bool tdIsColOfRowNullBySchema(SDataRow row, STSchema *pSchema, int32_t idx) {
|
||||
int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
|
||||
return isNull(tdGetRowDataOfCol(row, type, offset), type);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tdSetColOfRowNullBySchema(SDataRow row, STSchema *pSchema, int32_t idx) {
|
||||
int16_t offset = TD_DATA_ROW_HEAD_SIZE + pSchema->columns[idx].offset;
|
||||
int8_t type = pSchema->columns[idx].type;
|
||||
int16_t bytes = pSchema->columns[idx].bytes;
|
||||
|
||||
setNull(tdGetRowDataOfCol(row, type, offset), type, bytes);
|
||||
}
|
||||
|
||||
static FORCE_INLINE void tdCopyColOfRowBySchema(SDataRow dst, STSchema *pDstSchema, int32_t dstIdx, SDataRow src,
|
||||
STSchema *pSrcSchema, int32_t srcIdx) {
|
||||
int8_t type = pDstSchema->columns[dstIdx].type;
|
||||
assert(type == pSrcSchema->columns[srcIdx].type);
|
||||
void *pData = tdGetPtrToCol(dst, pDstSchema, dstIdx);
|
||||
void *value = tdGetPtrToCol(src, pSrcSchema, srcIdx);
|
||||
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_BINARY:
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
*(VarDataOffsetT *)pData = *(VarDataOffsetT *)value;
|
||||
pData = POINTER_SHIFT(dst, *(VarDataOffsetT *)pData);
|
||||
value = POINTER_SHIFT(src, *(VarDataOffsetT *)value);
|
||||
memcpy(pData, value, varDataTLen(value));
|
||||
break;
|
||||
case TSDB_DATA_TYPE_NULL:
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
*(uint8_t *)pData = *(uint8_t *)value;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
*(uint16_t *)pData = *(uint16_t *)value;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
*(uint32_t *)pData = *(uint32_t *)value;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
*(uint64_t *)pData = *(uint64_t *)value;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
SET_FLOAT_PTR(pData, value);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
SET_DOUBLE_PTR(pData, value);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
if (pSrcSchema->columns[srcIdx].colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
*(TSKEY *)pData = tdGetKey(*(TKEY *)value);
|
||||
} else {
|
||||
*(TSKEY *)pData = *(TSKEY *)value;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
memcpy(pData, value, pSrcSchema->columns[srcIdx].bytes);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
// ----------------- Data column structure
|
||||
// SDataCol arrangement: data => bitmap => dataOffset
|
||||
typedef struct SDataCol {
|
||||
|
@ -398,29 +222,6 @@ void *dataColSetOffset(SDataCol *pCol, int32_t nEle);
|
|||
|
||||
bool isNEleNull(SDataCol *pCol, int32_t nEle);
|
||||
|
||||
#if 0
|
||||
// Get the data pointer from a column-wised data
|
||||
static FORCE_INLINE const void *tdGetColDataOfRow(SDataCol *pCol, int32_t row) {
|
||||
if (isAllRowsNull(pCol)) {
|
||||
return getNullValue(pCol->type);
|
||||
}
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
return POINTER_SHIFT(pCol->pData, pCol->dataOff[row]);
|
||||
} else {
|
||||
return POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * row);
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t dataColGetNEleLen(SDataCol *pDataCol, int32_t rows) {
|
||||
assert(rows > 0);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pDataCol->type)) {
|
||||
return pDataCol->dataOff[rows - 1] + varDataTLen(tdGetColDataOfRow(pDataCol, rows - 1));
|
||||
} else {
|
||||
return TYPE_BYTES[pDataCol->type] * rows;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
typedef struct {
|
||||
col_id_t maxCols; // max number of columns
|
||||
col_id_t numOfCols; // Total number of cols
|
||||
|
@ -479,7 +280,8 @@ void tdResetDataCols(SDataCols *pCols);
|
|||
int32_t tdInitDataCols(SDataCols *pCols, STSchema *pSchema);
|
||||
SDataCols *tdDupDataCols(SDataCols *pCols, bool keepData);
|
||||
SDataCols *tdFreeDataCols(SDataCols *pCols);
|
||||
int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToMerge, int32_t *pOffset, bool update, TDRowVerT maxVer);
|
||||
int32_t tdMergeDataCols(SDataCols *target, SDataCols *source, int32_t rowsToMerge, int32_t *pOffset, bool update,
|
||||
TDRowVerT maxVer);
|
||||
|
||||
// ----------------- K-V data row structure
|
||||
/* |<-------------------------------------- len -------------------------------------------->|
|
||||
|
@ -542,54 +344,6 @@ static FORCE_INLINE void *tdGetKVRowIdxOfCol(SKVRow row, int16_t colId) {
|
|||
return taosbsearch(&colId, kvRowColIdx(row), kvRowNCols(row), sizeof(SColIdx), comparTagId, TD_EQ);
|
||||
}
|
||||
|
||||
#if 0
|
||||
// offset here not include kvRow header length
|
||||
static FORCE_INLINE int32_t tdAppendKvColVal(SKVRow row, const void *value, bool isCopyValData, int16_t colId, int8_t type,
|
||||
int32_t offset) {
|
||||
assert(value != NULL);
|
||||
int32_t toffset = offset + TD_KV_ROW_HEAD_SIZE;
|
||||
SColIdx *pColIdx = (SColIdx *)POINTER_SHIFT(row, toffset);
|
||||
char * ptr = (char *)POINTER_SHIFT(row, kvRowLen(row));
|
||||
|
||||
pColIdx->colId = colId;
|
||||
pColIdx->offset = kvRowLen(row); // offset of pColIdx including the TD_KV_ROW_HEAD_SIZE
|
||||
|
||||
if (IS_VAR_DATA_TYPE(type)) {
|
||||
if (isCopyValData) {
|
||||
memcpy(ptr, value, varDataTLen(value));
|
||||
}
|
||||
kvRowLen(row) += varDataTLen(value);
|
||||
} else {
|
||||
if (offset == 0) {
|
||||
assert(type == TSDB_DATA_TYPE_TIMESTAMP);
|
||||
TKEY tvalue = tdGetTKEY(*(TSKEY *)value);
|
||||
memcpy(ptr, (void *)(&tvalue), TYPE_BYTES[type]);
|
||||
} else {
|
||||
memcpy(ptr, value, TYPE_BYTES[type]);
|
||||
}
|
||||
kvRowLen(row) += TYPE_BYTES[type];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// NOTE: offset here including the header size
|
||||
static FORCE_INLINE void *tdGetKvRowDataOfCol(void *row, int32_t offset) { return POINTER_SHIFT(row, offset); }
|
||||
|
||||
static FORCE_INLINE void *tdGetKVRowValOfColEx(SKVRow row, int16_t colId, int32_t *nIdx) {
|
||||
while (*nIdx < kvRowNCols(row)) {
|
||||
SColIdx *pColIdx = kvRowColIdxAt(row, *nIdx);
|
||||
if (pColIdx->colId == colId) {
|
||||
++(*nIdx);
|
||||
return tdGetKvRowDataOfCol(row, pColIdx->offset);
|
||||
} else if (pColIdx->colId > colId) {
|
||||
return NULL;
|
||||
} else {
|
||||
++(*nIdx);
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
// ----------------- K-V data row builder
|
||||
typedef struct {
|
||||
int16_t tCols;
|
||||
|
@ -632,166 +386,6 @@ static FORCE_INLINE int32_t tdAddColToKVRow(SKVRowBuilder *pBuilder, col_id_t co
|
|||
|
||||
return 0;
|
||||
}
|
||||
#if 0
|
||||
// ----------------- SMemRow appended with tuple row structure
|
||||
/*
|
||||
* |---------|------------------------------------------------- len ---------------------------------->|
|
||||
* |<-------- Head ------>|<--------- flen -------------->| |
|
||||
* |---------+---------------------+---------------------------------+---------------------------------+
|
||||
* | uint8_t | uint16_t | int16_t | | |
|
||||
* |---------+----------+----------+---------------------------------+---------------------------------+
|
||||
* | flag | len | sversion | First part | Second part |
|
||||
* +---------+----------+----------+---------------------------------+---------------------------------+
|
||||
*
|
||||
* NOTE: timestamp in this row structure is TKEY instead of TSKEY
|
||||
*/
|
||||
|
||||
// ----------------- SMemRow appended with extended K-V data row structure
|
||||
/* |--------------------|------------------------------------------------ len ---------------------------------->|
|
||||
* |<------------- Head ------------>|<--------- flen -------------->| |
|
||||
* |--------------------+----------+--------------------------------------------+---------------------------------+
|
||||
* | uint8_t | int16_t | uint16_t | int16_t | | |
|
||||
* |---------+----------+----------+----------+---------------------------------+---------------------------------+
|
||||
* | flag | sversion | len | ncols | cols index | data part |
|
||||
* |---------+----------+----------+----------+---------------------------------+---------------------------------+
|
||||
*/
|
||||
|
||||
typedef void *SMemRow;
|
||||
|
||||
#define TD_MEM_ROW_TYPE_SIZE sizeof(uint8_t)
|
||||
#define TD_MEM_ROW_KV_VER_SIZE sizeof(int16_t)
|
||||
#define TD_MEM_ROW_KV_TYPE_VER_SIZE (TD_MEM_ROW_TYPE_SIZE + TD_MEM_ROW_KV_VER_SIZE)
|
||||
#define TD_MEM_ROW_DATA_HEAD_SIZE (TD_MEM_ROW_TYPE_SIZE + TD_DATA_ROW_HEAD_SIZE)
|
||||
#define TD_MEM_ROW_KV_HEAD_SIZE (TD_MEM_ROW_TYPE_SIZE + TD_MEM_ROW_KV_VER_SIZE + TD_KV_ROW_HEAD_SIZE)
|
||||
|
||||
#define SMEM_ROW_DATA 0x0U // SDataRow
|
||||
#define SMEM_ROW_KV 0x01U // SKVRow
|
||||
|
||||
#define KVRatioConvert (0.9f)
|
||||
|
||||
#define memRowType(r) ((*(uint8_t *)(r)) & 0x01)
|
||||
|
||||
#define memRowSetType(r, t) ((*(uint8_t *)(r)) = (t)) // set the total byte in case of dirty memory
|
||||
#define isDataRowT(t) (SMEM_ROW_DATA == (((uint8_t)(t)) & 0x01))
|
||||
#define isDataRow(r) (SMEM_ROW_DATA == memRowType(r))
|
||||
#define isKvRowT(t) (SMEM_ROW_KV == (((uint8_t)(t)) & 0x01))
|
||||
#define isKvRow(r) (SMEM_ROW_KV == memRowType(r))
|
||||
#define isUtilizeKVRow(k, d) ((k) < ((d)*KVRatioConvert))
|
||||
|
||||
#define memRowDataBody(r) POINTER_SHIFT(r, TD_MEM_ROW_TYPE_SIZE) // section after flag
|
||||
#define memRowKvBody(r) \
|
||||
POINTER_SHIFT(r, TD_MEM_ROW_KV_TYPE_VER_SIZE) // section after flag + sversion as to reuse SKVRow
|
||||
|
||||
#define memRowDataLen(r) (*(TDRowLenT *)memRowDataBody(r)) // 0~65535
|
||||
#define memRowKvLen(r) (*(TDRowLenT *)memRowKvBody(r)) // 0~65535
|
||||
|
||||
#define memRowDataTLen(r) \
|
||||
((TDRowLenT)(memRowDataLen(r) + TD_MEM_ROW_TYPE_SIZE)) // using uint32_t/int32_t to store the TLen
|
||||
|
||||
#define memRowKvTLen(r) ((TDRowLenT)(memRowKvLen(r) + TD_MEM_ROW_KV_TYPE_VER_SIZE))
|
||||
|
||||
#define memRowLen(r) (isDataRow(r) ? memRowDataLen(r) : memRowKvLen(r))
|
||||
#define memRowTLen(r) (isDataRow(r) ? memRowDataTLen(r) : memRowKvTLen(r)) // using uint32_t/int32_t to store the TLen
|
||||
|
||||
static FORCE_INLINE char *memRowEnd(SMemRow row) {
|
||||
if (isDataRow(row)) {
|
||||
return (char *)dataRowEnd(memRowDataBody(row));
|
||||
} else {
|
||||
return (char *)kvRowEnd(memRowKvBody(row));
|
||||
}
|
||||
}
|
||||
|
||||
#define memRowDataVersion(r) dataRowVersion(memRowDataBody(r))
|
||||
#define memRowKvVersion(r) (*(int16_t *)POINTER_SHIFT(r, TD_MEM_ROW_TYPE_SIZE))
|
||||
#define memRowVersion(r) (isDataRow(r) ? memRowDataVersion(r) : memRowKvVersion(r)) // schema version
|
||||
#define memRowSetKvVersion(r, v) (memRowKvVersion(r) = (v))
|
||||
#define memRowTuple(r) (isDataRow(r) ? dataRowTuple(memRowDataBody(r)) : kvRowValues(memRowKvBody(r)))
|
||||
|
||||
#define memRowTKey(r) (isDataRow(r) ? dataRowTKey(memRowDataBody(r)) : kvRowTKey(memRowKvBody(r)))
|
||||
#define memRowKey(r) (isDataRow(r) ? dataRowKey(memRowDataBody(r)) : kvRowKey(memRowKvBody(r)))
|
||||
#define memRowKeys(r) (isDataRow(r) ? dataRowTuple(memRowDataBody(r)) : kvRowKeys(memRowKvBody(r)))
|
||||
#define memRowSetTKey(r, k) \
|
||||
do { \
|
||||
if (isDataRow(r)) { \
|
||||
dataRowTKey(memRowDataBody(r)) = (k); \
|
||||
} else { \
|
||||
kvRowTKey(memRowKvBody(r)) = (k); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define memRowSetLen(r, l) (isDataRow(r) ? memRowDataLen(r) = (l) : memRowKvLen(r) = (l))
|
||||
#define memRowSetVersion(r, v) (isDataRow(r) ? dataRowSetVersion(memRowDataBody(r), v) : memRowSetKvVersion(r, v))
|
||||
#define memRowCpy(dst, r) memcpy((dst), (r), memRowTLen(r))
|
||||
#define memRowMaxBytesFromSchema(s) (schemaTLen(s) + TD_MEM_ROW_DATA_HEAD_SIZE)
|
||||
#define memRowDeleted(r) TKEY_IS_DELETED(memRowTKey(r))
|
||||
|
||||
SMemRow tdMemRowDup(SMemRow row);
|
||||
void tdAppendMemRowToDataCol(SMemRow row, STSchema *pSchema, SDataCols *pCols, bool forceSetNull);
|
||||
|
||||
// NOTE: offset here including the header size
|
||||
static FORCE_INLINE void *tdGetMemRowDataOfCol(void *row, int16_t colId, int8_t colType, uint16_t offset) {
|
||||
if (isDataRow(row)) {
|
||||
return tdGetRowDataOfCol(memRowDataBody(row), colType, offset);
|
||||
} else {
|
||||
return tdGetKVRowValOfCol(memRowKvBody(row), colId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* NOTE:
|
||||
* 1. Applicable to scan columns one by one
|
||||
* 2. offset here including the header size
|
||||
*/
|
||||
static FORCE_INLINE void *tdGetMemRowDataOfColEx(void *row, int16_t colId, int8_t colType, int32_t offset,
|
||||
int32_t *kvNIdx) {
|
||||
if (isDataRow(row)) {
|
||||
return tdGetRowDataOfCol(memRowDataBody(row), colType, offset);
|
||||
} else {
|
||||
return tdGetKVRowValOfColEx(memRowKvBody(row), colId, kvNIdx);
|
||||
}
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tdAppendMemRowColVal(SMemRow row, const void *value, bool isCopyVarData, int16_t colId,
|
||||
int8_t type, int32_t offset) {
|
||||
if (isDataRow(row)) {
|
||||
tdAppendDataColVal(memRowDataBody(row), value, isCopyVarData, type, offset);
|
||||
} else {
|
||||
tdAppendKvColVal(memRowKvBody(row), value, isCopyVarData, colId, type, offset);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// make sure schema->flen appended for SDataRow
|
||||
static FORCE_INLINE int32_t tdGetColAppendLen(uint8_t rowType, const void *value, int8_t colType) {
|
||||
int32_t len = 0;
|
||||
if (IS_VAR_DATA_TYPE(colType)) {
|
||||
len += varDataTLen(value);
|
||||
if (rowType == SMEM_ROW_KV) {
|
||||
len += sizeof(SColIdx);
|
||||
}
|
||||
} else {
|
||||
if (rowType == SMEM_ROW_KV) {
|
||||
len += TYPE_BYTES[colType];
|
||||
len += sizeof(SColIdx);
|
||||
}
|
||||
}
|
||||
return len;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int16_t colId;
|
||||
uint8_t colType;
|
||||
char * colVal;
|
||||
} SColInfo;
|
||||
|
||||
static FORCE_INLINE void setSColInfo(SColInfo *colInfo, int16_t colId, uint8_t colType, char *colVal) {
|
||||
colInfo->colId = colId;
|
||||
colInfo->colType = colType;
|
||||
colInfo->colVal = colVal;
|
||||
}
|
||||
|
||||
SMemRow mergeTwoMemRows(void *buffer, SMemRow row1, SMemRow row2, STSchema *pSchema1, STSchema *pSchema2);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -99,7 +99,7 @@ typedef enum _mgmt_table {
|
|||
TSDB_MGMT_TABLE_VGROUP,
|
||||
TSDB_MGMT_TABLE_TOPICS,
|
||||
TSDB_MGMT_TABLE_CONSUMERS,
|
||||
TSDB_MGMT_TABLE_SUBSCRIBES,
|
||||
TSDB_MGMT_TABLE_SUBSCRIPTIONS,
|
||||
TSDB_MGMT_TABLE_TRANS,
|
||||
TSDB_MGMT_TABLE_SMAS,
|
||||
TSDB_MGMT_TABLE_CONFIGS,
|
||||
|
@ -131,12 +131,10 @@ typedef enum _mgmt_table {
|
|||
#define TSDB_ALTER_USER_SUPERUSER 0x2
|
||||
#define TSDB_ALTER_USER_ADD_READ_DB 0x3
|
||||
#define TSDB_ALTER_USER_REMOVE_READ_DB 0x4
|
||||
#define TSDB_ALTER_USER_CLEAR_READ_DB 0x5
|
||||
#define TSDB_ALTER_USER_ADD_WRITE_DB 0x6
|
||||
#define TSDB_ALTER_USER_REMOVE_WRITE_DB 0x7
|
||||
#define TSDB_ALTER_USER_CLEAR_WRITE_DB 0x8
|
||||
#define TSDB_ALTER_USER_ADD_ALL_DB 0x9
|
||||
#define TSDB_ALTER_USER_REMOVE_ALL_DB 0xA
|
||||
#define TSDB_ALTER_USER_ADD_WRITE_DB 0x5
|
||||
#define TSDB_ALTER_USER_REMOVE_WRITE_DB 0x6
|
||||
#define TSDB_ALTER_USER_ADD_ALL_DB 0x7
|
||||
#define TSDB_ALTER_USER_REMOVE_ALL_DB 0x8
|
||||
|
||||
#define TSDB_ALTER_USER_PRIVILEGES 0x2
|
||||
|
||||
|
@ -1457,7 +1455,7 @@ typedef struct {
|
|||
static FORCE_INLINE SMqRebInfo* tNewSMqRebSubscribe(const char* key) {
|
||||
SMqRebInfo* pRebInfo = (SMqRebInfo*)taosMemoryCalloc(1, sizeof(SMqRebInfo));
|
||||
if (pRebInfo == NULL) {
|
||||
goto _err;
|
||||
return NULL;
|
||||
}
|
||||
strcpy(pRebInfo->key, key);
|
||||
pRebInfo->lostConsumers = taosArrayInit(0, sizeof(int64_t));
|
||||
|
|
|
@ -57,6 +57,7 @@ typedef struct {
|
|||
RegisterBrokenLinkArgFp registerBrokenLinkArgFp;
|
||||
ReleaseHandleFp releaseHandleFp;
|
||||
ReportStartup reportStartupFp;
|
||||
void* clientRpc;
|
||||
} SMsgCb;
|
||||
|
||||
void tmsgSetDefaultMsgCb(const SMsgCb* pMsgCb);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#ifndef _TD_COMMON_NAME_H_
|
||||
#define _TD_COMMON_NAME_H_
|
||||
|
||||
#include "tarray.h"
|
||||
#include "tdef.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -62,9 +63,21 @@ int32_t tNameSetAcctId(SName* dst, int32_t acctId);
|
|||
|
||||
bool tNameDBNameEqual(SName* left, SName* right);
|
||||
|
||||
typedef struct {
|
||||
// input
|
||||
SArray* tags; // element is SSmlKv
|
||||
const char* sTableName; // super table name
|
||||
uint8_t sTableNameLen; // the length of super table name
|
||||
|
||||
// output
|
||||
char* childTableName; // must have size of TSDB_TABLE_NAME_LEN;
|
||||
uint64_t uid; // child table uid, may be useful
|
||||
} RandTableName;
|
||||
|
||||
void buildChildTableName(RandTableName* rName);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /*_TD_COMMON_NAME_H_*/
|
||||
#endif /*_TD_COMMON_NAME_H_*/
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -22,6 +22,7 @@ extern "C" {
|
|||
|
||||
#include "query.h"
|
||||
#include "tcommon.h"
|
||||
#include "tmsgcb.h"
|
||||
|
||||
typedef void* qTaskInfo_t;
|
||||
typedef void* DataSinkHandle;
|
||||
|
@ -29,11 +30,12 @@ struct SRpcMsg;
|
|||
struct SSubplan;
|
||||
|
||||
typedef struct SReadHandle {
|
||||
void* reader;
|
||||
void* meta;
|
||||
void* config;
|
||||
void* vnode;
|
||||
void* mnd;
|
||||
void* reader;
|
||||
void* meta;
|
||||
void* config;
|
||||
void* vnode;
|
||||
void* mnd;
|
||||
SMsgCb* pMsgCb;
|
||||
} SReadHandle;
|
||||
|
||||
#define STREAM_DATA_TYPE_SUBMIT_BLOCK 0x1
|
||||
|
|
|
@ -336,6 +336,17 @@ int32_t udfcOpen();
|
|||
*/
|
||||
int32_t udfcClose();
|
||||
|
||||
/**
|
||||
* start udfd that serves udf function invocation under dnode startDnodeId
|
||||
* @param startDnodeId
|
||||
* @return
|
||||
*/
|
||||
int32_t udfStartUdfd(int32_t startDnodeId);
|
||||
/**
|
||||
* stop udfd
|
||||
* @return
|
||||
*/
|
||||
int32_t udfStopUdfd();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -156,6 +156,7 @@ bool fmIsWindowClauseFunc(int32_t funcId);
|
|||
bool fmIsSpecialDataRequiredFunc(int32_t funcId);
|
||||
bool fmIsDynamicScanOptimizedFunc(int32_t funcId);
|
||||
bool fmIsMultiResFunc(int32_t funcId);
|
||||
bool fmIsRepeatScanFunc(int32_t funcId);
|
||||
bool fmIsUserDefinedFunc(int32_t funcId);
|
||||
|
||||
typedef enum EFuncDataRequired {
|
||||
|
@ -172,7 +173,7 @@ int32_t fmGetScalarFuncExecFuncs(int32_t funcId, SScalarFuncExecFuncs* pFpSet);
|
|||
int32_t fmGetUdafExecFuncs(int32_t funcId, SFuncExecFuncs* pFpSet);
|
||||
int32_t fmSetInvertFunc(int32_t funcId, SFuncExecFuncs* pFpSet);
|
||||
int32_t fmSetNormalFunc(int32_t funcId, SFuncExecFuncs* pFpSet);
|
||||
bool fmIsInvertible(int32_t funcId);
|
||||
bool fmIsInvertible(int32_t funcId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -206,6 +206,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_PHYSICAL_PLAN_EXCHANGE,
|
||||
QUERY_NODE_PHYSICAL_PLAN_SORT,
|
||||
QUERY_NODE_PHYSICAL_PLAN_INTERVAL,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL,
|
||||
QUERY_NODE_PHYSICAL_PLAN_FILL,
|
||||
QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW,
|
||||
QUERY_NODE_PHYSICAL_PLAN_STATE_WINDOW,
|
||||
|
|
|
@ -274,6 +274,8 @@ typedef struct SIntervalPhysiNode {
|
|||
int8_t slidingUnit;
|
||||
} SIntervalPhysiNode;
|
||||
|
||||
typedef SIntervalPhysiNode SStreamIntervalPhysiNode;
|
||||
|
||||
typedef struct SFillPhysiNode {
|
||||
SPhysiNode node;
|
||||
EFillMode mode;
|
||||
|
|
|
@ -233,6 +233,7 @@ typedef struct SSelectStmt {
|
|||
uint8_t precision;
|
||||
bool isEmptyResult;
|
||||
bool hasAggFuncs;
|
||||
bool hasRepeatScanFuncs;
|
||||
bool isTimeOrderQuery;
|
||||
} SSelectStmt;
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@ extern "C" {
|
|||
#include "thash.h"
|
||||
#include "tlog.h"
|
||||
#include "tmsg.h"
|
||||
#include "tmsgcb.h"
|
||||
|
||||
typedef enum {
|
||||
JOB_TASK_STATUS_NULL = 0,
|
||||
|
@ -149,7 +150,8 @@ int32_t cleanupTaskQueue();
|
|||
*/
|
||||
int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code);
|
||||
|
||||
int32_t asyncSendMsgToServerExt(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo, bool persistHandle, void *ctx);
|
||||
int32_t asyncSendMsgToServerExt(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo,
|
||||
bool persistHandle, void* ctx);
|
||||
|
||||
/**
|
||||
* Asynchronously send message to server, after the response received, the callback will be incured.
|
||||
|
@ -182,7 +184,7 @@ extern int32_t (*queryProcessMsgRsp[TDMT_MAX])(void* output, char* msg, int32_t
|
|||
#define SET_META_TYPE_TABLE(t) (t) = META_TYPE_TABLE
|
||||
#define SET_META_TYPE_BOTH_TABLE(t) (t) = META_TYPE_BOTH_TABLE
|
||||
|
||||
#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_INVALID_TABLE_ID || (_code) == TSDB_CODE_VND_TB_NOT_EXIST)
|
||||
#define NEED_CLIENT_RM_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_PAR_TABLE_NOT_EXIST || (_code) == TSDB_CODE_VND_TB_NOT_EXIST)
|
||||
#define NEED_CLIENT_REFRESH_VG_ERROR(_code) ((_code) == TSDB_CODE_VND_HASH_MISMATCH || (_code) == TSDB_CODE_VND_INVALID_VGROUP_ID)
|
||||
#define NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code) ((_code) == TSDB_CODE_TDB_TABLE_RECREATED)
|
||||
#define NEED_CLIENT_HANDLE_ERROR(_code) (NEED_CLIENT_RM_TBLMETA_ERROR(_code) || NEED_CLIENT_REFRESH_VG_ERROR(_code) || NEED_CLIENT_REFRESH_TBLMETA_ERROR(_code))
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#include "tdatablock.h"
|
||||
#include "tmsg.h"
|
||||
#include "tmsgcb.h"
|
||||
#include "tqueue.h"
|
||||
#include "trpc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -154,6 +155,10 @@ struct SStreamTask {
|
|||
STaskDispatcherShuffle shuffleDispatcher;
|
||||
};
|
||||
|
||||
// msg buffer
|
||||
int32_t memUsed;
|
||||
STaosQueue* inputQ;
|
||||
|
||||
// application storage
|
||||
void* ahandle;
|
||||
};
|
||||
|
@ -194,6 +199,8 @@ typedef struct {
|
|||
SArray* res; // SArray<SSDataBlock>
|
||||
} SStreamSinkReq;
|
||||
|
||||
int32_t streamEnqueueData(SStreamTask* pTask, const void* input, int32_t inputType);
|
||||
|
||||
int32_t streamExecTask(SStreamTask* pTask, SMsgCb* pMsgCb, const void* input, int32_t inputType, int32_t workId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -80,6 +80,7 @@ int64_t taosWriteFile(TdFilePtr pFile, const void *buf, int64_t count);
|
|||
void taosFprintfFile(TdFilePtr pFile, const char *format, ...);
|
||||
|
||||
int64_t taosGetLineFile(TdFilePtr pFile, char ** __restrict ptrBuf);
|
||||
int64_t taosGetsFile(TdFilePtr pFile, int32_t maxSize, char *__restrict buf);
|
||||
|
||||
int32_t taosEOFFile(TdFilePtr pFile);
|
||||
|
||||
|
|
|
@ -88,6 +88,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_CFG_NOT_FOUND TAOS_DEF_ERROR_CODE(0, 0x0114)
|
||||
#define TSDB_CODE_REPEAT_INIT TAOS_DEF_ERROR_CODE(0, 0x0115)
|
||||
#define TSDB_CODE_DUP_KEY TAOS_DEF_ERROR_CODE(0, 0x0116)
|
||||
#define TSDB_CODE_NEED_RETRY TAOS_DEF_ERROR_CODE(0, 0x0117)
|
||||
|
||||
#define TSDB_CODE_REF_NO_MEMORY TAOS_DEF_ERROR_CODE(0, 0x0140)
|
||||
#define TSDB_CODE_REF_FULL TAOS_DEF_ERROR_CODE(0, 0x0141)
|
||||
|
|
|
@ -86,10 +86,9 @@ extern const int32_t TYPE_BYTES[15];
|
|||
#define TS_PATH_DELIMITER "."
|
||||
#define TS_ESCAPE_CHAR '`'
|
||||
|
||||
|
||||
#define TSDB_TIME_PRECISION_MILLI 0
|
||||
#define TSDB_TIME_PRECISION_MICRO 1
|
||||
#define TSDB_TIME_PRECISION_NANO 2
|
||||
#define TSDB_TIME_PRECISION_MILLI 0
|
||||
#define TSDB_TIME_PRECISION_MICRO 1
|
||||
#define TSDB_TIME_PRECISION_NANO 2
|
||||
#define TSDB_TIME_PRECISION_HOURS 3
|
||||
#define TSDB_TIME_PRECISION_MINUTES 4
|
||||
#define TSDB_TIME_PRECISION_SECONDS 5
|
||||
|
@ -249,7 +248,6 @@ typedef enum ELogicConditionType {
|
|||
#define TSDB_SHOW_SQL_LEN 512
|
||||
#define TSDB_SLOW_QUERY_SQL_LEN 512
|
||||
#define TSDB_SHOW_SUBQUERY_LEN 1000
|
||||
#define TSDB_SHOW_LIST_LEN 1000
|
||||
|
||||
#define TSDB_TRANS_STAGE_LEN 12
|
||||
#define TSDB_TRANS_TYPE_LEN 16
|
||||
|
@ -376,9 +374,9 @@ typedef enum ELogicConditionType {
|
|||
* 1. ordinary sub query for select * from super_table
|
||||
* 2. all sqlobj generated by createSubqueryObj with this flag
|
||||
*/
|
||||
#define TSDB_QUERY_TYPE_INSERT 0x100u // insert type
|
||||
#define TSDB_QUERY_TYPE_FILE_INSERT 0x400u // insert data from file
|
||||
#define TSDB_QUERY_TYPE_STMT_INSERT 0x800u // stmt insert type
|
||||
#define TSDB_QUERY_TYPE_INSERT 0x100u // insert type
|
||||
#define TSDB_QUERY_TYPE_FILE_INSERT 0x400u // insert data from file
|
||||
#define TSDB_QUERY_TYPE_STMT_INSERT 0x800u // stmt insert type
|
||||
|
||||
#define TSDB_QUERY_HAS_TYPE(x, _type) (((x) & (_type)) != 0)
|
||||
#define TSDB_QUERY_SET_TYPE(x, _type) ((x) |= (_type))
|
||||
|
|
|
@ -1,70 +0,0 @@
|
|||
/*
|
||||
* 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_*/
|
|
@ -310,6 +310,7 @@ void hbMgrInitMqHbRspHandle();
|
|||
SRequestObj* launchQueryImpl(SRequestObj* pRequest, SQuery* pQuery, int32_t code, bool keepQuery);
|
||||
int32_t getQueryPlan(SRequestObj* pRequest, SQuery* pQuery, SArray** pNodeList);
|
||||
int32_t scheduleQuery(SRequestObj* pRequest, SQueryPlan* pDag, SArray* pNodeList);
|
||||
int32_t refreshMeta(STscObj* pTscObj, SRequestObj* pRequest);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ typedef struct SStmtBindInfo {
|
|||
int32_t sBindRowNum;
|
||||
int32_t sBindLastIdx;
|
||||
int8_t tbType;
|
||||
bool tagsCached;
|
||||
void* boundTags;
|
||||
char* tbName;
|
||||
SName sname;
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include "tcommon.h"
|
||||
#include "catalog.h"
|
||||
#include "clientInt.h"
|
||||
#include "tname.h"
|
||||
//=================================================================================================
|
||||
|
||||
#define SPACE ' '
|
||||
|
@ -97,6 +98,21 @@ typedef struct {
|
|||
char *buf;
|
||||
} SSmlMsgBuf;
|
||||
|
||||
typedef struct {
|
||||
int32_t code;
|
||||
int32_t lineNum;
|
||||
|
||||
int32_t numOfSTables;
|
||||
int32_t numOfCTables;
|
||||
int32_t numOfCreateSTables;
|
||||
|
||||
int64_t parseTime;
|
||||
int64_t schemaTime;
|
||||
int64_t insertBindTime;
|
||||
int64_t insertRpcTime;
|
||||
int64_t endTime;
|
||||
} SSmlCostInfo;
|
||||
|
||||
typedef struct {
|
||||
uint64_t id;
|
||||
|
||||
|
@ -114,6 +130,7 @@ typedef struct {
|
|||
SRequestObj *pRequest;
|
||||
SQuery *pQuery;
|
||||
|
||||
SSmlCostInfo cost;
|
||||
int32_t affectedRows;
|
||||
SSmlMsgBuf msgBuf;
|
||||
SHashObj *dumplicateKey; // for dumplicate key
|
||||
|
@ -147,45 +164,6 @@ static int32_t smlBuildInvalidDataMsg(SSmlMsgBuf* pBuf, const char *msg1, const
|
|||
return TSDB_CODE_SML_INVALID_DATA;
|
||||
}
|
||||
|
||||
static int smlCompareKv(const void* p1, const void* p2) {
|
||||
SSmlKv* kv1 = *(SSmlKv**)p1;
|
||||
SSmlKv* kv2 = *(SSmlKv**)p2;
|
||||
int32_t kvLen1 = kv1->keyLen;
|
||||
int32_t kvLen2 = kv2->keyLen;
|
||||
int32_t res = strncasecmp(kv1->key, kv2->key, TMIN(kvLen1, kvLen2));
|
||||
if (res != 0) {
|
||||
return res;
|
||||
} else {
|
||||
return kvLen1-kvLen2;
|
||||
}
|
||||
}
|
||||
|
||||
static void smlBuildChildTableName(SSmlTableInfo *tags) {
|
||||
int32_t size = taosArrayGetSize(tags->tags);
|
||||
ASSERT(size > 0);
|
||||
taosArraySort(tags->tags, smlCompareKv);
|
||||
|
||||
SStringBuilder sb = {0};
|
||||
taosStringBuilderAppendStringLen(&sb, tags->sTableName, tags->sTableNameLen);
|
||||
for (int j = 0; j < size; ++j) {
|
||||
SSmlKv *tagKv = taosArrayGetP(tags->tags, j);
|
||||
taosStringBuilderAppendStringLen(&sb, tagKv->key, tagKv->keyLen);
|
||||
taosStringBuilderAppendStringLen(&sb, tagKv->value, tagKv->valueLen);
|
||||
}
|
||||
size_t len = 0;
|
||||
char* keyJoined = taosStringBuilderGetResult(&sb, &len);
|
||||
T_MD5_CTX context;
|
||||
tMD5Init(&context);
|
||||
tMD5Update(&context, (uint8_t *)keyJoined, (uint32_t)len);
|
||||
tMD5Final(&context);
|
||||
uint64_t digest1 = *(uint64_t*)(context.digest);
|
||||
//uint64_t digest2 = *(uint64_t*)(context.digest + 8);
|
||||
//snprintf(tags->childTableName, TSDB_TABLE_NAME_LEN, "t_%016"PRIx64"%016"PRIx64, digest1, digest2);
|
||||
snprintf(tags->childTableName, TSDB_TABLE_NAME_LEN, "t_%016"PRIx64, digest1);
|
||||
taosStringBuilderDestroy(&sb);
|
||||
tags->uid = digest1;
|
||||
}
|
||||
|
||||
static int32_t smlGenerateSchemaAction(SSchema* pointColField, SHashObj* dbAttrHash, SArray* dbAttrArray, bool isTag, char sTableName[],
|
||||
SSchemaAction* action, bool* actionNeeded, SSmlHandle* info) {
|
||||
// char fieldName[TSDB_COL_NAME_LEN] = {0};
|
||||
|
@ -427,7 +405,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle* info) {
|
|||
|
||||
code = catalogGetSTableMeta(info->pCatalog, info->taos->pAppInfo->pTransporter, &ep, &pName, &pTableMeta);
|
||||
|
||||
if (code == TSDB_CODE_TDB_INVALID_TABLE_ID || code == TSDB_CODE_MND_INVALID_STB) {
|
||||
if (code == TSDB_CODE_PAR_TABLE_NOT_EXIST || code == TSDB_CODE_MND_INVALID_STB) {
|
||||
SSchemaAction schemaAction = {0};
|
||||
schemaAction.action = SCHEMA_ACTION_CREATE_STABLE;
|
||||
memcpy(schemaAction.createSTable.sTableName, superTable, superTableLen);
|
||||
|
@ -444,6 +422,7 @@ static int32_t smlModifyDBSchemas(SSmlHandle* info) {
|
|||
uError("SML:0x%"PRIx64" catalogGetSTableMeta failed. super table name %s", info->id, schemaAction.createSTable.sTableName);
|
||||
return code;
|
||||
}
|
||||
info->cost.numOfCreateSTables++;
|
||||
}else if (code == TSDB_CODE_SUCCESS) {
|
||||
} else {
|
||||
uError("SML:0x%"PRIx64" load table meta error: %s", info->id, tstrerror(code));
|
||||
|
@ -926,20 +905,6 @@ static bool smlParseValue(SSmlKv *pVal, SSmlMsgBuf *msg) {
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool checkDuplicateKey(char *key, SHashObj *pHash, SSmlHandle* info) {
|
||||
char *val = NULL;
|
||||
val = taosHashGet(pHash, key, strlen(key));
|
||||
if (val) {
|
||||
uError("SML:0x%"PRIx64" Duplicate key detected:%s", info->id, key);
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t dummy_val = 0;
|
||||
taosHashPut(pHash, key, strlen(key), &dummy_val, sizeof(uint8_t));
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static int32_t smlParseString(const char* sql, SSmlLineInfo *elements, SSmlMsgBuf *msg){
|
||||
if(!sql) return TSDB_CODE_SML_INVALID_DATA;
|
||||
while (*sql != '\0') { // jump the space at the begining
|
||||
|
@ -1546,8 +1511,10 @@ static int32_t smlParseLine(SSmlHandle* info, const char* sql) {
|
|||
|
||||
tinfo->sTableName = elements.measure;
|
||||
tinfo->sTableNameLen = elements.measureLen;
|
||||
smlBuildChildTableName(tinfo);
|
||||
uDebug("SML:0x%"PRIx64" child table name: %s", info->id, tinfo->childTableName);
|
||||
RandTableName rName = {.tags=tinfo->tags, .sTableName=tinfo->sTableName, .sTableNameLen=tinfo->sTableNameLen,
|
||||
.childTableName=tinfo->childTableName};
|
||||
buildChildTableName(&rName);
|
||||
tinfo->uid = rName.uid;
|
||||
|
||||
SSmlSTableMeta** tableMeta = taosHashGet(info->superTables, elements.measure, elements.measureLen);
|
||||
if(tableMeta){ // update meta
|
||||
|
@ -1604,7 +1571,7 @@ static void smlDestroyInfo(SSmlHandle* info){
|
|||
|
||||
static SSmlHandle* smlBuildSmlInfo(TAOS* taos, SRequestObj* request, SMLProtocolType protocol, int8_t precision, bool dataFormat){
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SSmlHandle* info = taosMemoryMalloc(sizeof(SSmlHandle));
|
||||
SSmlHandle* info = taosMemoryCalloc(1, sizeof(SSmlHandle));
|
||||
if (NULL == info) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -1699,12 +1666,23 @@ static int32_t smlInsertData(SSmlHandle* info) {
|
|||
}
|
||||
|
||||
smlBuildOutput(info->exec, info->pVgHash);
|
||||
info->cost.insertRpcTime = taosGetTimestampUs();
|
||||
|
||||
launchQueryImpl(info->pRequest, info->pQuery, TSDB_CODE_SUCCESS, true);
|
||||
|
||||
info->affectedRows = taos_affected_rows(info->pRequest);
|
||||
return info->pRequest->code;
|
||||
}
|
||||
|
||||
static void smlPrintStatisticInfo(SSmlHandle *info){
|
||||
uError("SML:0x%"PRIx64" smlInsertLines result, code:%d,lineNum:%d,stable num:%d,ctable num:%d,create stable num:%d \
|
||||
parse cost:%"PRId64",schema cost:%"PRId64",bind cost:%"PRId64",rpc cost:%"PRId64",total cost:%"PRId64"", info->id, info->cost.code,
|
||||
info->cost.lineNum, info->cost.numOfSTables, info->cost.numOfCTables, info->cost.numOfCreateSTables,
|
||||
info->cost.schemaTime-info->cost.parseTime, info->cost.insertBindTime-info->cost.schemaTime,
|
||||
info->cost.insertRpcTime-info->cost.insertBindTime, info->cost.endTime-info->cost.insertRpcTime,
|
||||
info->cost.endTime-info->cost.parseTime);
|
||||
}
|
||||
|
||||
static int smlInsertLines(SSmlHandle *info, char* lines[], int numLines) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
|
@ -1714,6 +1692,7 @@ static int smlInsertLines(SSmlHandle *info, char* lines[], int numLines) {
|
|||
goto cleanup;
|
||||
}
|
||||
|
||||
info->cost.parseTime = taosGetTimestampUs();
|
||||
for (int32_t i = 0; i < numLines; ++i) {
|
||||
code = smlParseLine(info, lines[i]);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
|
@ -1721,24 +1700,29 @@ static int smlInsertLines(SSmlHandle *info, char* lines[], int numLines) {
|
|||
goto cleanup;
|
||||
}
|
||||
}
|
||||
uDebug("SML:0x%"PRIx64" smlInsertLines parse success. tables %d", info->id, taosHashGetSize(info->childTables));
|
||||
uDebug("SML:0x%"PRIx64" smlInsertLines parse success. super tables %d", info->id, taosHashGetSize(info->superTables));
|
||||
|
||||
info->cost.lineNum = numLines;
|
||||
info->cost.numOfSTables = taosHashGetSize(info->superTables);
|
||||
info->cost.numOfCTables = taosHashGetSize(info->childTables);
|
||||
|
||||
info->cost.schemaTime = taosGetTimestampUs();
|
||||
code = smlModifyDBSchemas(info);
|
||||
if (code != 0) {
|
||||
uError("SML:0x%"PRIx64" smlModifyDBSchemas error : %s", info->id, tstrerror(code));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
info->cost.insertBindTime = taosGetTimestampUs();
|
||||
code = smlInsertData(info);
|
||||
if (code != 0) {
|
||||
uError("SML:0x%"PRIx64" smlInsertData error : %s", info->id, tstrerror(code));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
uDebug("SML:0x%"PRIx64" smlInsertLines finish inserting %d lines.", info->id, numLines);
|
||||
info->cost.endTime = taosGetTimestampUs();
|
||||
|
||||
cleanup:
|
||||
info->cost.code = code;
|
||||
smlPrintStatisticInfo(info);
|
||||
return code;
|
||||
}
|
||||
|
||||
|
@ -1790,7 +1774,6 @@ TAOS_RES* taos_schemaless_insert(TAOS* taos, char* lines[], int numLines, int pr
|
|||
}
|
||||
smlDestroyInfo(info);
|
||||
|
||||
end:
|
||||
return (TAOS_RES*)request;
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,11 @@ int32_t stmtSwitchStatus(STscStmt* pStmt, STMT_STATUS newStatus) {
|
|||
if (STMT_STATUS_EQ(INIT) || STMT_STATUS_EQ(BIND_COL)) {
|
||||
code = TSDB_CODE_TSC_STMT_API_ERROR;
|
||||
}
|
||||
/*
|
||||
if ((pStmt->sql.type == STMT_TYPE_MULTI_INSERT) && ()) {
|
||||
code = TSDB_CODE_TSC_STMT_API_ERROR;
|
||||
}
|
||||
*/
|
||||
break;
|
||||
case STMT_BIND_COL:
|
||||
if (STMT_STATUS_EQ(INIT) || STMT_STATUS_EQ(BIND)) {
|
||||
|
@ -123,6 +128,7 @@ int32_t stmtSetBindInfo(TAOS_STMT* stmt, STableMeta* pTableMeta, void* tags) {
|
|||
pStmt->bInfo.tbSuid = pTableMeta->suid;
|
||||
pStmt->bInfo.tbType = pTableMeta->tableType;
|
||||
pStmt->bInfo.boundTags = tags;
|
||||
pStmt->bInfo.tagsCached = false;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -207,8 +213,6 @@ int32_t stmtParseSql(STscStmt* pStmt) {
|
|||
STMT_ERR_RET(TSDB_CODE_TSC_STMT_CLAUSE_ERROR);
|
||||
}
|
||||
|
||||
STMT_ERR_RET(stmtCacheBlock(pStmt));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -219,8 +223,10 @@ int32_t stmtCleanBindInfo(STscStmt* pStmt) {
|
|||
pStmt->bInfo.needParse = true;
|
||||
|
||||
taosMemoryFreeClear(pStmt->bInfo.tbName);
|
||||
destroyBoundColumnInfo(pStmt->bInfo.boundTags);
|
||||
taosMemoryFreeClear(pStmt->bInfo.boundTags);
|
||||
if (!pStmt->bInfo.tagsCached) {
|
||||
destroyBoundColumnInfo(pStmt->bInfo.boundTags);
|
||||
taosMemoryFreeClear(pStmt->bInfo.boundTags);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -275,6 +281,7 @@ int32_t stmtCleanSQLInfo(STscStmt* pStmt) {
|
|||
|
||||
qDestroyStmtDataBlock(pCache->pDataBlock);
|
||||
destroyBoundColumnInfo(pCache->boundTags);
|
||||
taosMemoryFreeClear(pCache->boundTags);
|
||||
|
||||
pIter = taosHashIterate(pStmt->sql.pTableCache, pIter);
|
||||
}
|
||||
|
@ -302,7 +309,15 @@ int32_t stmtGetFromCache(STscStmt* pStmt) {
|
|||
|
||||
STableMeta *pTableMeta = NULL;
|
||||
SEpSet ep = getEpSet_s(&pStmt->taos->pAppInfo->mgmtEp);
|
||||
STMT_ERR_RET(catalogGetTableMeta(pStmt->pCatalog, pStmt->taos->pAppInfo->pTransporter, &ep, &pStmt->bInfo.sname, &pTableMeta));
|
||||
int32_t code = catalogGetTableMeta(pStmt->pCatalog, pStmt->taos->pAppInfo->pTransporter, &ep, &pStmt->bInfo.sname, &pTableMeta);
|
||||
if (TSDB_CODE_PAR_TABLE_NOT_EXIST == code) {
|
||||
STMT_ERR_RET(stmtCleanBindInfo(pStmt));
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
STMT_ERR_RET(code);
|
||||
|
||||
uint64_t uid = pTableMeta->uid;
|
||||
uint64_t suid = pTableMeta->suid;
|
||||
int8_t tableType = pTableMeta->tableType;
|
||||
|
@ -328,6 +343,7 @@ int32_t stmtGetFromCache(STscStmt* pStmt) {
|
|||
pStmt->bInfo.tbSuid = suid;
|
||||
pStmt->bInfo.tbType = tableType;
|
||||
pStmt->bInfo.boundTags = pCache->boundTags;
|
||||
pStmt->bInfo.tagsCached = true;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -340,6 +356,7 @@ int32_t stmtGetFromCache(STscStmt* pStmt) {
|
|||
pStmt->bInfo.tbSuid = suid;
|
||||
pStmt->bInfo.tbType = tableType;
|
||||
pStmt->bInfo.boundTags = pCache->boundTags;
|
||||
pStmt->bInfo.tagsCached = true;
|
||||
|
||||
STableDataBlocks* pNewBlock = NULL;
|
||||
STMT_ERR_RET(qRebuildStmtDataBlock(&pNewBlock, pCache->pDataBlock));
|
||||
|
@ -448,10 +465,12 @@ int stmtSetTbTags(TAOS_STMT *stmt, TAOS_MULTI_BIND *tags) {
|
|||
|
||||
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_SETTAGS));
|
||||
|
||||
if (pStmt->bInfo.needParse) {
|
||||
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||
if (!pStmt->bInfo.needParse) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||
|
||||
STableDataBlocks **pDataBlock = (STableDataBlocks**)taosHashGet(pStmt->exec.pBlockHash, (const char*)&pStmt->bInfo.tbUid, sizeof(pStmt->bInfo.tbUid));
|
||||
if (NULL == pDataBlock) {
|
||||
tscError("table uid %" PRIx64 "not found in exec blockHash", pStmt->bInfo.tbUid);
|
||||
|
@ -501,8 +520,6 @@ int32_t stmtFetchColFields(STscStmt* pStmt, int32_t *fieldNum, TAOS_FIELD** fiel
|
|||
int stmtBindBatch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int32_t colIdx) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
|
||||
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_BIND));
|
||||
|
||||
if (pStmt->bInfo.needParse && pStmt->sql.runTimes && pStmt->sql.type > 0 && STMT_TYPE_MULTI_INSERT != pStmt->sql.type) {
|
||||
pStmt->bInfo.needParse = false;
|
||||
}
|
||||
|
@ -520,6 +537,8 @@ int stmtBindBatch(TAOS_STMT *stmt, TAOS_MULTI_BIND *bind, int32_t colIdx) {
|
|||
STMT_ERR_RET(stmtParseSql(pStmt));
|
||||
}
|
||||
|
||||
STMT_ERR_RET(stmtSwitchStatus(pStmt, STMT_BIND));
|
||||
|
||||
if (STMT_TYPE_QUERY == pStmt->sql.type) {
|
||||
if (NULL == pStmt->sql.pQueryPlan) {
|
||||
STMT_ERR_RET(getQueryPlan(pStmt->exec.pRequest, pStmt->sql.pQuery, &pStmt->sql.nodeList));
|
||||
|
@ -586,6 +605,16 @@ int stmtExec(TAOS_STMT *stmt) {
|
|||
STMT_ERR_RET(qBuildStmtOutput(pStmt->sql.pQuery, pStmt->exec.pVgHash, pStmt->exec.pBlockHash));
|
||||
launchQueryImpl(pStmt->exec.pRequest, pStmt->sql.pQuery, TSDB_CODE_SUCCESS, true);
|
||||
}
|
||||
|
||||
if (pStmt->exec.pRequest->code && NEED_CLIENT_HANDLE_ERROR(pStmt->exec.pRequest->code)) {
|
||||
code = refreshMeta(pStmt->exec.pRequest->pTscObj, pStmt->exec.pRequest);
|
||||
if (code) {
|
||||
pStmt->exec.pRequest->code = code;
|
||||
} else {
|
||||
STMT_ERR_RET(stmtResetStmt(pStmt));
|
||||
STMT_ERR_RET(TSDB_CODE_NEED_RETRY);
|
||||
}
|
||||
}
|
||||
|
||||
STMT_ERR_JRET(pStmt->exec.pRequest->code);
|
||||
|
||||
|
@ -613,13 +642,11 @@ int stmtClose(TAOS_STMT *stmt) {
|
|||
const char *stmtErrstr(TAOS_STMT *stmt) {
|
||||
STscStmt* pStmt = (STscStmt*)stmt;
|
||||
|
||||
if (stmt == NULL) {
|
||||
if (stmt == NULL || NULL == pStmt->exec.pRequest) {
|
||||
return (char*) tstrerror(terrno);
|
||||
}
|
||||
|
||||
if (pStmt->exec.pRequest) {
|
||||
pStmt->exec.pRequest->code = terrno;
|
||||
}
|
||||
pStmt->exec.pRequest->code = terrno;
|
||||
|
||||
return taos_errstr(pStmt->exec.pRequest);
|
||||
}
|
||||
|
|
|
@ -187,7 +187,7 @@ typedef struct {
|
|||
|
||||
tmq_conf_t* tmq_conf_new() {
|
||||
tmq_conf_t* conf = taosMemoryCalloc(1, sizeof(tmq_conf_t));
|
||||
conf->autoCommit = false;
|
||||
conf->autoCommit = true;
|
||||
conf->autoCommitInterval = 5000;
|
||||
conf->resetOffset = TMQ_CONF__RESET_OFFSET__EARLIEAST;
|
||||
return conf;
|
||||
|
@ -395,7 +395,7 @@ tmq_resp_err_t tmq_subscription(tmq_t* tmq, tmq_list_t** topics) {
|
|||
}
|
||||
for (int i = 0; i < taosArrayGetSize(tmq->clientTopics); i++) {
|
||||
SMqClientTopic* topic = taosArrayGet(tmq->clientTopics, i);
|
||||
tmq_list_append(*topics, topic->topicName);
|
||||
tmq_list_append(*topics, strchr(topic->topicName, '.') + 1);
|
||||
}
|
||||
return TMQ_RESP_ERR__SUCCESS;
|
||||
}
|
||||
|
|
|
@ -14,9 +14,9 @@
|
|||
*/
|
||||
|
||||
#include "systable.h"
|
||||
#include "taos.h"
|
||||
#include "tdef.h"
|
||||
#include "types.h"
|
||||
#include "taos.h"
|
||||
|
||||
#define SYSTABLE_SCH_TABLE_NAME_LEN ((TSDB_TABLE_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||
#define SYSTABLE_SCH_DB_NAME_LEN ((TSDB_DB_NAME_LEN - 1) + VARSTR_HEADER_SIZE)
|
||||
|
@ -265,7 +265,7 @@ static const SSysDbTableSchema consumerSchema[] = {
|
|||
{.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "app_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "status", .bytes = 20 + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "topics", .bytes = TSDB_SHOW_LIST_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "topics", .bytes = TSDB_TOPIC_FNAME_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "pid", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "end_point", .bytes = TSDB_EP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "up_time", .bytes = 8, .type = TSDB_DATA_TYPE_TIMESTAMP},
|
||||
|
@ -274,8 +274,8 @@ static const SSysDbTableSchema consumerSchema[] = {
|
|||
};
|
||||
|
||||
static const SSysDbTableSchema subscriptionSchema[] = {
|
||||
{.name = "topic_name", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "group_id", .bytes = SYSTABLE_SCH_TABLE_NAME_LEN, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "topic_name", .bytes = TSDB_TOPIC_FNAME_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "group_id", .bytes = TSDB_CGROUP_LEN + VARSTR_HEADER_SIZE, .type = TSDB_DATA_TYPE_BINARY},
|
||||
{.name = "vgroup_id", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "consumer_id", .bytes = 8, .type = TSDB_DATA_TYPE_BIGINT},
|
||||
};
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
|
@ -493,7 +493,7 @@ SSDataBlock* blockDataExtractBlock(SSDataBlock* pBlock, int32_t startIndex, int3
|
|||
for (int32_t j = startIndex; j < (startIndex + rowCount); ++j) {
|
||||
bool isNull = false;
|
||||
if (pBlock->pBlockAgg == NULL) {
|
||||
isNull = colDataIsNull_s(pColData, pBlock->info.rows);
|
||||
isNull = colDataIsNull_s(pColData, j);
|
||||
} else {
|
||||
isNull = colDataIsNull(pColData, pBlock->info.rows, j, pBlock->pBlockAgg[i]);
|
||||
}
|
||||
|
|
|
@ -129,50 +129,6 @@ 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;
|
||||
|
||||
|
@ -260,49 +216,6 @@ STSchema *tdGetSchemaFromBuilder(STSchemaBuilder *pBuilder) {
|
|||
return pSchema;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/**
|
||||
* Initialize a data row
|
||||
*/
|
||||
void tdInitDataRow(SDataRow row, STSchema *pSchema) {
|
||||
dataRowSetLen(row, TD_DATA_ROW_HEAD_SIZE + schemaFLen(pSchema));
|
||||
dataRowSetVersion(row, schemaVersion(pSchema));
|
||||
}
|
||||
|
||||
SDataRow tdNewDataRowFromSchema(STSchema *pSchema) {
|
||||
int32_t size = dataRowMaxBytesFromSchema(pSchema);
|
||||
|
||||
SDataRow row = taosMemoryMalloc(size);
|
||||
if (row == NULL) return NULL;
|
||||
|
||||
tdInitDataRow(row, pSchema);
|
||||
return row;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the SDataRow object
|
||||
*/
|
||||
void tdFreeDataRow(SDataRow row) {
|
||||
if (row) taosMemoryFree(row);
|
||||
}
|
||||
|
||||
SDataRow tdDataRowDup(SDataRow row) {
|
||||
SDataRow trow = taosMemoryMalloc(dataRowLen(row));
|
||||
if (trow == NULL) return NULL;
|
||||
|
||||
dataRowCpy(trow, row);
|
||||
return trow;
|
||||
}
|
||||
|
||||
SMemRow tdMemRowDup(SMemRow row) {
|
||||
SMemRow trow = taosMemoryMalloc(memRowTLen(row));
|
||||
if (trow == NULL) return NULL;
|
||||
|
||||
memRowCpy(trow, row);
|
||||
return trow;
|
||||
}
|
||||
#endif
|
||||
|
||||
void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints) {
|
||||
pDataCol->type = colType(pCol);
|
||||
pDataCol->colId = colColId(pCol);
|
||||
|
@ -312,39 +225,6 @@ void dataColInit(SDataCol *pDataCol, STColumn *pCol, int maxPoints) {
|
|||
pDataCol->len = 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// value from timestamp should be TKEY here instead of TSKEY
|
||||
int dataColAppendVal(SDataCol *pCol, const void *value, int numOfRows, int maxPoints) {
|
||||
ASSERT(pCol != NULL && value != NULL);
|
||||
|
||||
if (isAllRowsNull(pCol)) {
|
||||
if (isNull(value, pCol->type)) {
|
||||
// all null value yet, just return
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (tdAllocMemForCol(pCol, maxPoints) < 0) return -1;
|
||||
if (numOfRows > 0) {
|
||||
// Find the first not null value, fill all previouse values as NULL
|
||||
dataColSetNEleNull(pCol, numOfRows);
|
||||
}
|
||||
}
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
// set offset
|
||||
pCol->dataOff[numOfRows] = pCol->len;
|
||||
// Copy data
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, varDataTLen(value));
|
||||
// Update the length
|
||||
pCol->len += varDataTLen(value);
|
||||
} else {
|
||||
ASSERT(pCol->len == TYPE_BYTES[pCol->type] * numOfRows);
|
||||
memcpy(POINTER_SHIFT(pCol->pData, pCol->len), value, pCol->bytes);
|
||||
pCol->len += pCol->bytes;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
static FORCE_INLINE const void *tdGetColDataOfRowUnsafe(SDataCol *pCol, int row) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
return POINTER_SHIFT(pCol->pData, pCol->dataOff[row]);
|
||||
|
@ -361,31 +241,6 @@ bool isNEleNull(SDataCol *pCol, int nEle) {
|
|||
return true;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static FORCE_INLINE void dataColSetNullAt(SDataCol *pCol, int index) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
pCol->dataOff[index] = pCol->len;
|
||||
char *ptr = POINTER_SHIFT(pCol->pData, pCol->len);
|
||||
setVardataNull(ptr, pCol->type);
|
||||
pCol->len += varDataTLen(ptr);
|
||||
} else {
|
||||
setNull(POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * index), pCol->type, pCol->bytes);
|
||||
pCol->len += TYPE_BYTES[pCol->type];
|
||||
}
|
||||
}
|
||||
|
||||
static void dataColSetNEleNull(SDataCol *pCol, int nEle, int8_t bitmapMode) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
pCol->len = 0;
|
||||
for (int i = 0; i < nEle; ++i) {
|
||||
dataColSetNullAt(pCol, i);
|
||||
}
|
||||
} else {
|
||||
setNullN(pCol->pData, pCol->type, pCol->bytes, nEle);
|
||||
pCol->len = TYPE_BYTES[pCol->type] * nEle;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
void *dataColSetOffset(SDataCol *pCol, int nEle) {
|
||||
ASSERT(((pCol->type == TSDB_DATA_TYPE_BINARY) || (pCol->type == TSDB_DATA_TYPE_NCHAR)));
|
||||
|
||||
|
@ -483,42 +338,6 @@ SDataCols *tdFreeDataCols(SDataCols *pCols) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
#if 0
|
||||
SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) {
|
||||
SDataCols *pRet = tdNewDataCols(pDataCols->maxCols, pDataCols->maxPoints);
|
||||
if (pRet == NULL) return NULL;
|
||||
|
||||
pRet->numOfCols = pDataCols->numOfCols;
|
||||
pRet->sversion = pDataCols->sversion;
|
||||
if (keepData) pRet->numOfRows = pDataCols->numOfRows;
|
||||
|
||||
for (int i = 0; i < pDataCols->numOfCols; i++) {
|
||||
pRet->cols[i].type = pDataCols->cols[i].type;
|
||||
pRet->cols[i].bitmap = pDataCols->cols[i].bitmap;
|
||||
pRet->cols[i].colId = pDataCols->cols[i].colId;
|
||||
pRet->cols[i].bytes = pDataCols->cols[i].bytes;
|
||||
pRet->cols[i].offset = pDataCols->cols[i].offset;
|
||||
|
||||
if (keepData) {
|
||||
if (pDataCols->cols[i].len > 0) {
|
||||
if (tdAllocMemForCol(&pRet->cols[i], pRet->maxPoints) < 0) {
|
||||
tdFreeDataCols(pRet);
|
||||
return NULL;
|
||||
}
|
||||
pRet->cols[i].len = pDataCols->cols[i].len;
|
||||
memcpy(pRet->cols[i].pData, pDataCols->cols[i].pData, pDataCols->cols[i].len);
|
||||
if (IS_VAR_DATA_TYPE(pRet->cols[i].type)) {
|
||||
int dataOffSize = sizeof(VarDataOffsetT) * pDataCols->maxPoints;
|
||||
memcpy(pRet->cols[i].dataOff, pDataCols->cols[i].dataOff, dataOffSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return pRet;
|
||||
}
|
||||
#endif
|
||||
|
||||
void tdResetDataCols(SDataCols *pCols) {
|
||||
if (pCols != NULL) {
|
||||
pCols->numOfRows = 0;
|
||||
|
@ -528,180 +347,6 @@ void tdResetDataCols(SDataCols *pCols) {
|
|||
}
|
||||
}
|
||||
}
|
||||
#if 0
|
||||
static void tdAppendDataRowToDataCol(SDataRow row, STSchema *pSchema, SDataCols *pCols, bool forceSetNull) {
|
||||
ASSERT(pCols->numOfRows == 0 || dataColsKeyLast(pCols) < dataRowKey(row));
|
||||
|
||||
int rcol = 0;
|
||||
int dcol = 0;
|
||||
|
||||
while (dcol < pCols->numOfCols) {
|
||||
bool setCol = 0;
|
||||
SDataCol *pDataCol = &(pCols->cols[dcol]);
|
||||
if (rcol >= schemaNCols(pSchema)) {
|
||||
dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints);
|
||||
dcol++;
|
||||
continue;
|
||||
}
|
||||
|
||||
STColumn *pRowCol = schemaColAt(pSchema, rcol);
|
||||
if (pRowCol->colId == pDataCol->colId) {
|
||||
void *value = tdGetRowDataOfCol(row, pRowCol->type, pRowCol->offset + TD_DATA_ROW_HEAD_SIZE);
|
||||
if(!isNull(value, pDataCol->type)) setCol = 1;
|
||||
dataColAppendVal(pDataCol, value, pCols->numOfRows, pCols->maxPoints);
|
||||
dcol++;
|
||||
rcol++;
|
||||
} else if (pRowCol->colId < pDataCol->colId) {
|
||||
rcol++;
|
||||
} else {
|
||||
if(forceSetNull || setCol) {
|
||||
dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints);
|
||||
}
|
||||
dcol++;
|
||||
}
|
||||
}
|
||||
pCols->numOfRows++;
|
||||
}
|
||||
|
||||
static void tdAppendKVRowToDataCol(SKVRow row, STSchema *pSchema, SDataCols *pCols, bool forceSetNull) {
|
||||
ASSERT(pCols->numOfRows == 0 || dataColsKeyLast(pCols) < kvRowKey(row));
|
||||
|
||||
int rcol = 0;
|
||||
int dcol = 0;
|
||||
|
||||
int nRowCols = kvRowNCols(row);
|
||||
|
||||
while (dcol < pCols->numOfCols) {
|
||||
bool setCol = 0;
|
||||
SDataCol *pDataCol = &(pCols->cols[dcol]);
|
||||
if (rcol >= nRowCols || rcol >= schemaNCols(pSchema)) {
|
||||
dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints);
|
||||
++dcol;
|
||||
continue;
|
||||
}
|
||||
|
||||
SColIdx *colIdx = kvRowColIdxAt(row, rcol);
|
||||
|
||||
if (colIdx->colId == pDataCol->colId) {
|
||||
void *value = tdGetKvRowDataOfCol(row, colIdx->offset);
|
||||
if(!isNull(value, pDataCol->type)) setCol = 1;
|
||||
dataColAppendVal(pDataCol, value, pCols->numOfRows, pCols->maxPoints);
|
||||
++dcol;
|
||||
++rcol;
|
||||
} else if (colIdx->colId < pDataCol->colId) {
|
||||
++rcol;
|
||||
} else {
|
||||
if(forceSetNull || setCol) {
|
||||
dataColAppendVal(pDataCol, getNullValue(pDataCol->type), pCols->numOfRows, pCols->maxPoints);
|
||||
}
|
||||
++dcol;
|
||||
}
|
||||
}
|
||||
pCols->numOfRows++;
|
||||
}
|
||||
|
||||
void tdAppendMemRowToDataCol(SMemRow row, STSchema *pSchema, SDataCols *pCols, bool forceSetNull) {
|
||||
if (isDataRow(row)) {
|
||||
tdAppendDataRowToDataCol(memRowDataBody(row), pSchema, pCols, forceSetNull);
|
||||
} else if (isKvRow(row)) {
|
||||
tdAppendKVRowToDataCol(memRowKvBody(row), pSchema, pCols, forceSetNull);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
int tdMergeDataCols(SDataCols *target, SDataCols *source, int rowsToMerge, int *pOffset, bool forceSetNull) {
|
||||
ASSERT(rowsToMerge > 0 && rowsToMerge <= source->numOfRows);
|
||||
ASSERT(target->numOfCols == source->numOfCols);
|
||||
int offset = 0;
|
||||
|
||||
if (pOffset == NULL) {
|
||||
pOffset = &offset;
|
||||
}
|
||||
|
||||
SDataCols *pTarget = NULL;
|
||||
|
||||
if ((target->numOfRows == 0) || (dataColsKeyLast(target) < dataColsKeyAtRow(source, *pOffset))) { // No overlap
|
||||
ASSERT(target->numOfRows + rowsToMerge <= target->maxPoints);
|
||||
for (int i = 0; i < rowsToMerge; i++) {
|
||||
for (int j = 0; j < source->numOfCols; j++) {
|
||||
if (source->cols[j].len > 0 || target->cols[j].len > 0) {
|
||||
dataColAppendVal(target->cols + j, tdGetColDataOfRow(source->cols + j, i + (*pOffset)), target->numOfRows,
|
||||
target->maxPoints);
|
||||
}
|
||||
}
|
||||
target->numOfRows++;
|
||||
}
|
||||
(*pOffset) += rowsToMerge;
|
||||
} else {
|
||||
pTarget = tdDupDataCols(target, true);
|
||||
if (pTarget == NULL) goto _err;
|
||||
|
||||
int iter1 = 0;
|
||||
tdMergeTwoDataCols(target, pTarget, &iter1, pTarget->numOfRows, source, pOffset, source->numOfRows,
|
||||
pTarget->numOfRows + rowsToMerge, forceSetNull);
|
||||
}
|
||||
|
||||
tdFreeDataCols(pTarget);
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
tdFreeDataCols(pTarget);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// src2 data has more priority than src1
|
||||
static void tdMergeTwoDataCols(SDataCols *target, SDataCols *src1, int *iter1, int limit1, SDataCols *src2, int *iter2,
|
||||
int limit2, int tRows, bool forceSetNull) {
|
||||
tdResetDataCols(target);
|
||||
ASSERT(limit1 <= src1->numOfRows && limit2 <= src2->numOfRows);
|
||||
|
||||
while (target->numOfRows < tRows) {
|
||||
if (*iter1 >= limit1 && *iter2 >= limit2) break;
|
||||
|
||||
TSKEY key1 = (*iter1 >= limit1) ? INT64_MAX : dataColsKeyAt(src1, *iter1);
|
||||
TKEY tkey1 = (*iter1 >= limit1) ? TKEY_NULL : dataColsTKeyAt(src1, *iter1);
|
||||
TSKEY key2 = (*iter2 >= limit2) ? INT64_MAX : dataColsKeyAt(src2, *iter2);
|
||||
TKEY tkey2 = (*iter2 >= limit2) ? TKEY_NULL : dataColsTKeyAt(src2, *iter2);
|
||||
|
||||
ASSERT(tkey1 == TKEY_NULL || (!TKEY_IS_DELETED(tkey1)));
|
||||
|
||||
if (key1 < key2) {
|
||||
for (int i = 0; i < src1->numOfCols; i++) {
|
||||
ASSERT(target->cols[i].type == src1->cols[i].type);
|
||||
if (src1->cols[i].len > 0 || target->cols[i].len > 0) {
|
||||
dataColAppendVal(&(target->cols[i]), tdGetColDataOfRow(src1->cols + i, *iter1), target->numOfRows,
|
||||
target->maxPoints);
|
||||
}
|
||||
}
|
||||
|
||||
target->numOfRows++;
|
||||
(*iter1)++;
|
||||
} else if (key1 >= key2) {
|
||||
if ((key1 > key2) || (key1 == key2 && !TKEY_IS_DELETED(tkey2))) {
|
||||
for (int i = 0; i < src2->numOfCols; i++) {
|
||||
ASSERT(target->cols[i].type == src2->cols[i].type);
|
||||
if (src2->cols[i].len > 0 && !isNull(src2->cols[i].pData, src2->cols[i].type)) {
|
||||
dataColAppendVal(&(target->cols[i]), tdGetColDataOfRow(src2->cols + i, *iter2), target->numOfRows,
|
||||
target->maxPoints);
|
||||
} else if(!forceSetNull && key1 == key2 && src1->cols[i].len > 0) {
|
||||
dataColAppendVal(&(target->cols[i]), tdGetColDataOfRow(src1->cols + i, *iter1), target->numOfRows,
|
||||
target->maxPoints);
|
||||
} else if(target->cols[i].len > 0) {
|
||||
dataColSetNullAt(&target->cols[i], target->numOfRows);
|
||||
}
|
||||
}
|
||||
target->numOfRows++;
|
||||
}
|
||||
|
||||
(*iter2)++;
|
||||
if (key1 == key2) (*iter1)++;
|
||||
}
|
||||
|
||||
ASSERT(target->numOfRows <= target->maxPoints);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
SKVRow tdKVRowDup(SKVRow row) {
|
||||
SKVRow trow = taosMemoryMalloc(kvRowLen(row));
|
||||
|
@ -859,98 +504,3 @@ SKVRow tdGetKVRowFromBuilder(SKVRowBuilder *pBuilder) {
|
|||
|
||||
return row;
|
||||
}
|
||||
#if 0
|
||||
SMemRow mergeTwoMemRows(void *buffer, SMemRow row1, SMemRow row2, STSchema *pSchema1, STSchema *pSchema2) {
|
||||
#if 0
|
||||
ASSERT(memRowKey(row1) == memRowKey(row2));
|
||||
ASSERT(schemaVersion(pSchema1) == memRowVersion(row1));
|
||||
ASSERT(schemaVersion(pSchema2) == memRowVersion(row2));
|
||||
ASSERT(schemaVersion(pSchema1) >= schemaVersion(pSchema2));
|
||||
#endif
|
||||
|
||||
SArray *stashRow = taosArrayInit(pSchema1->numOfCols, sizeof(SColInfo));
|
||||
if (stashRow == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SMemRow pRow = buffer;
|
||||
SDataRow dataRow = memRowDataBody(pRow);
|
||||
memRowSetType(pRow, SMEM_ROW_DATA);
|
||||
dataRowSetVersion(dataRow, schemaVersion(pSchema1)); // use latest schema version
|
||||
dataRowSetLen(dataRow, (TDRowLenT)(TD_DATA_ROW_HEAD_SIZE + pSchema1->flen));
|
||||
|
||||
TDRowLenT dataLen = 0, kvLen = TD_MEM_ROW_KV_HEAD_SIZE;
|
||||
|
||||
int32_t i = 0; // row1
|
||||
int32_t j = 0; // row2
|
||||
int32_t nCols1 = schemaNCols(pSchema1);
|
||||
int32_t nCols2 = schemaNCols(pSchema2);
|
||||
SColInfo colInfo = {0};
|
||||
int32_t kvIdx1 = 0, kvIdx2 = 0;
|
||||
|
||||
while (i < nCols1) {
|
||||
STColumn *pCol = schemaColAt(pSchema1, i);
|
||||
void * val1 = tdGetMemRowDataOfColEx(row1, pCol->colId, pCol->type, TD_DATA_ROW_HEAD_SIZE + pCol->offset, &kvIdx1);
|
||||
// if val1 != NULL, use val1;
|
||||
if (val1 != NULL && !isNull(val1, pCol->type)) {
|
||||
tdAppendColVal(dataRow, val1, pCol->type, pCol->offset);
|
||||
kvLen += tdGetColAppendLen(SMEM_ROW_KV, val1, pCol->type);
|
||||
setSColInfo(&colInfo, pCol->colId, pCol->type, val1);
|
||||
taosArrayPush(stashRow, &colInfo);
|
||||
++i; // next col
|
||||
continue;
|
||||
}
|
||||
|
||||
void *val2 = NULL;
|
||||
while (j < nCols2) {
|
||||
STColumn *tCol = schemaColAt(pSchema2, j);
|
||||
if (tCol->colId < pCol->colId) {
|
||||
++j;
|
||||
continue;
|
||||
}
|
||||
if (tCol->colId == pCol->colId) {
|
||||
val2 = tdGetMemRowDataOfColEx(row2, tCol->colId, tCol->type, TD_DATA_ROW_HEAD_SIZE + tCol->offset, &kvIdx2);
|
||||
} else if (tCol->colId > pCol->colId) {
|
||||
// set NULL
|
||||
}
|
||||
break;
|
||||
} // end of while(j<nCols2)
|
||||
if (val2 == NULL) {
|
||||
val2 = (void *)getNullValue(pCol->type);
|
||||
}
|
||||
tdAppendColVal(dataRow, val2, pCol->type, pCol->offset);
|
||||
if (!isNull(val2, pCol->type)) {
|
||||
kvLen += tdGetColAppendLen(SMEM_ROW_KV, val2, pCol->type);
|
||||
setSColInfo(&colInfo, pCol->colId, pCol->type, val2);
|
||||
taosArrayPush(stashRow, &colInfo);
|
||||
}
|
||||
|
||||
++i; // next col
|
||||
}
|
||||
|
||||
dataLen = memRowTLen(pRow);
|
||||
|
||||
if (kvLen < dataLen) {
|
||||
// scan stashRow and generate SKVRow
|
||||
memset(buffer, 0, sizeof(dataLen));
|
||||
SMemRow tRow = buffer;
|
||||
memRowSetType(tRow, SMEM_ROW_KV);
|
||||
SKVRow kvRow = (SKVRow)memRowKvBody(tRow);
|
||||
int16_t nKvNCols = (int16_t) taosArrayGetSize(stashRow);
|
||||
kvRowSetLen(kvRow, (TDRowLenT)(TD_KV_ROW_HEAD_SIZE + sizeof(SColIdx) * nKvNCols));
|
||||
kvRowSetNCols(kvRow, nKvNCols);
|
||||
memRowSetKvVersion(tRow, pSchema1->version);
|
||||
|
||||
int32_t toffset = 0;
|
||||
int16_t k;
|
||||
for (k = 0; k < nKvNCols; ++k) {
|
||||
SColInfo *pColInfo = taosArrayGet(stashRow, k);
|
||||
tdAppendKvColVal(kvRow, pColInfo->colVal, true, pColInfo->colId, pColInfo->colType, toffset);
|
||||
toffset += sizeof(SColIdx);
|
||||
}
|
||||
ASSERT(kvLen == memRowTLen(tRow));
|
||||
}
|
||||
taosArrayDestroy(stashRow);
|
||||
return buffer;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1233,21 +1233,21 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs
|
|||
for (int32_t i = 0; i < numOfCreatedDbs; ++i) {
|
||||
char db[TSDB_DB_FNAME_LEN] = {0};
|
||||
if (tDecodeCStrTo(pDecoder, db) < 0) return -1;
|
||||
int32_t len = strlen(db) + 1;
|
||||
int32_t len = strlen(db);
|
||||
taosHashPut(pRsp->createdDbs, db, len, db, len);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfReadDbs; ++i) {
|
||||
char db[TSDB_DB_FNAME_LEN] = {0};
|
||||
if (tDecodeCStrTo(pDecoder, db) < 0) return -1;
|
||||
int32_t len = strlen(db) + 1;
|
||||
int32_t len = strlen(db);
|
||||
taosHashPut(pRsp->readDbs, db, len, db, len);
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfWriteDbs; ++i) {
|
||||
char db[TSDB_DB_FNAME_LEN] = {0};
|
||||
if (tDecodeCStrTo(pDecoder, db) < 0) return -1;
|
||||
int32_t len = strlen(db) + 1;
|
||||
int32_t len = strlen(db);
|
||||
taosHashPut(pRsp->writeDbs, db, len, db, len);
|
||||
}
|
||||
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "tname.h"
|
||||
#include "tcommon.h"
|
||||
#include "tstrbuild.h"
|
||||
|
||||
#define VALID_NAME_TYPE(x) ((x) == TSDB_DB_NAME_T || (x) == TSDB_TABLE_NAME_T)
|
||||
#define VALID_NAME_TYPE(x) ((x) == TSDB_DB_NAME_T || (x) == TSDB_TABLE_NAME_T)
|
||||
|
||||
bool tscValidateTableNameLength(size_t len) {
|
||||
return len < TSDB_TABLE_NAME_LEN;
|
||||
}
|
||||
bool tscValidateTableNameLength(size_t len) { return len < TSDB_TABLE_NAME_LEN; }
|
||||
|
||||
#if 0
|
||||
// TODO refactor
|
||||
|
@ -93,12 +93,12 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in
|
|||
* but in case of DST, the start time of one day need to be dynamically decided.
|
||||
*/
|
||||
// todo refactor to extract function that is available for Linux/Windows/Mac platform
|
||||
#if defined(WINDOWS) && _MSC_VER >= 1900
|
||||
#if defined(WINDOWS) && _MSC_VER >= 1900
|
||||
// see https://docs.microsoft.com/en-us/cpp/c-runtime-library/daylight-dstbias-timezone-and-tzname?view=vs-2019
|
||||
int64_t timezone = _timezone;
|
||||
int32_t daylight = _daylight;
|
||||
char** tzname = _tzname;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int64_t t = (precision == TSDB_TIME_PRECISION_MILLI) ? MILLISECOND_PER_SECOND : MILLISECOND_PER_SECOND * 1000L;
|
||||
start += timezone * t;
|
||||
|
@ -140,10 +140,10 @@ int32_t tNameExtractFullName(const SName* name, char* dst) {
|
|||
int32_t tNameLen(const SName* name) {
|
||||
assert(name != NULL);
|
||||
|
||||
char tmp[12] = {0};
|
||||
char tmp[12] = {0};
|
||||
int32_t len = sprintf(tmp, "%d", name->acctId);
|
||||
int32_t len1 = (int32_t) strlen(name->dbname);
|
||||
int32_t len2 = (int32_t) strlen(name->tname);
|
||||
int32_t len1 = (int32_t)strlen(name->dbname);
|
||||
int32_t len2 = (int32_t)strlen(name->tname);
|
||||
|
||||
if (name->type == TSDB_DB_NAME_T) {
|
||||
assert(len2 == 0);
|
||||
|
@ -198,9 +198,7 @@ const char* tNameGetTableName(const SName* name) {
|
|||
return &name->tname[0];
|
||||
}
|
||||
|
||||
void tNameAssign(SName* dst, const SName* src) {
|
||||
memcpy(dst, src, sizeof(SName));
|
||||
}
|
||||
void tNameAssign(SName* dst, const SName* src) { memcpy(dst, src, sizeof(SName)); }
|
||||
|
||||
int32_t tNameSetDbName(SName* dst, int32_t acct, const char* dbName, size_t nameLen) {
|
||||
assert(dst != NULL && dbName != NULL && nameLen > 0);
|
||||
|
@ -242,7 +240,6 @@ bool tNameDBNameEqual(SName* left, SName* right) {
|
|||
return (0 == strcmp(left->dbname, right->dbname));
|
||||
}
|
||||
|
||||
|
||||
int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
|
||||
assert(dst != NULL && str != NULL && strlen(str) > 0);
|
||||
|
||||
|
@ -258,14 +255,14 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
|
|||
|
||||
if ((type & T_NAME_DB) == T_NAME_DB) {
|
||||
dst->type = TSDB_DB_NAME_T;
|
||||
char* start = (char*)((p == NULL)? str:(p+1));
|
||||
char* start = (char*)((p == NULL) ? str : (p + 1));
|
||||
|
||||
int32_t len = 0;
|
||||
p = strstr(start, TS_PATH_DELIMITER);
|
||||
if (p == NULL) {
|
||||
len = (int32_t) strlen(start);
|
||||
len = (int32_t)strlen(start);
|
||||
} else {
|
||||
len = (int32_t) (p - start);
|
||||
len = (int32_t)(p - start);
|
||||
}
|
||||
|
||||
// too long account id or too long db name
|
||||
|
@ -273,25 +270,64 @@ int32_t tNameFromString(SName* dst, const char* str, uint32_t type) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
memcpy (dst->dbname, start, len);
|
||||
memcpy(dst->dbname, start, len);
|
||||
dst->dbname[len] = 0;
|
||||
}
|
||||
|
||||
if ((type & T_NAME_TABLE) == T_NAME_TABLE) {
|
||||
dst->type = TSDB_TABLE_NAME_T;
|
||||
char* start = (char*) ((p == NULL)? str: (p+1));
|
||||
char* start = (char*)((p == NULL) ? str : (p + 1));
|
||||
|
||||
// too long account id or too long db name
|
||||
int32_t len = (int32_t) strlen(start);
|
||||
int32_t len = (int32_t)strlen(start);
|
||||
if ((len >= tListLen(dst->tname)) || (len <= 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy (dst->tname, start, len);
|
||||
memcpy(dst->tname, start, len);
|
||||
dst->tname[len] = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int compareKv(const void* p1, const void* p2) {
|
||||
SSmlKv* kv1 = *(SSmlKv**)p1;
|
||||
SSmlKv* kv2 = *(SSmlKv**)p2;
|
||||
int32_t kvLen1 = kv1->keyLen;
|
||||
int32_t kvLen2 = kv2->keyLen;
|
||||
int32_t res = strncasecmp(kv1->key, kv2->key, TMIN(kvLen1, kvLen2));
|
||||
if (res != 0) {
|
||||
return res;
|
||||
} else {
|
||||
return kvLen1 - kvLen2;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* use stable name and tags to grearate child table name
|
||||
*/
|
||||
void buildChildTableName(RandTableName* rName) {
|
||||
int32_t size = taosArrayGetSize(rName->tags);
|
||||
ASSERT(size > 0);
|
||||
taosArraySort(rName->tags, compareKv);
|
||||
|
||||
SStringBuilder sb = {0};
|
||||
taosStringBuilderAppendStringLen(&sb, rName->sTableName, rName->sTableNameLen);
|
||||
for (int j = 0; j < size; ++j) {
|
||||
SSmlKv* tagKv = taosArrayGetP(rName->tags, j);
|
||||
taosStringBuilderAppendStringLen(&sb, tagKv->key, tagKv->keyLen);
|
||||
taosStringBuilderAppendStringLen(&sb, tagKv->value, tagKv->valueLen);
|
||||
}
|
||||
size_t len = 0;
|
||||
char* keyJoined = taosStringBuilderGetResult(&sb, &len);
|
||||
T_MD5_CTX context;
|
||||
tMD5Init(&context);
|
||||
tMD5Update(&context, (uint8_t*)keyJoined, (uint32_t)len);
|
||||
tMD5Final(&context);
|
||||
uint64_t digest1 = *(uint64_t*)(context.digest);
|
||||
uint64_t digest2 = *(uint64_t*)(context.digest + 8);
|
||||
snprintf(rName->childTableName, TSDB_TABLE_NAME_LEN, "t_%016" PRIx64 "%016" PRIx64, digest1, digest2);
|
||||
taosStringBuilderDestroy(&sb);
|
||||
rName->uid = digest1;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ const uint8_t tdVTypeByte[2][3] = {{
|
|||
|
||||
// declaration
|
||||
static uint8_t tdGetBitmapByte(uint8_t byte);
|
||||
static int32_t tdCompareColId(const void *arg1, const void *arg2);
|
||||
|
||||
// static void dataColSetNEleNull(SDataCol *pCol, int nEle);
|
||||
|
||||
|
@ -916,4 +917,937 @@ SDataCols *tdDupDataCols(SDataCols *pDataCols, bool keepData) {
|
|||
}
|
||||
|
||||
return pRet;
|
||||
}
|
||||
|
||||
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};
|
||||
if (!tdSTSRowIterNext(&iter, stCol->colId, stCol->type, &sVal)) {
|
||||
break;
|
||||
}
|
||||
ASSERT(sVal.valType == 0 || sVal.valType == 1 || sVal.valType == 2);
|
||||
tdSCellValPrint(&sVal, stCol->type);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
void tdSCellValPrint(SCellVal *pVal, int8_t colType) {
|
||||
if (tdValTypeIsNull(pVal->valType)) {
|
||||
printf("NULL ");
|
||||
return;
|
||||
} else if (tdValTypeIsNone(pVal->valType)) {
|
||||
printf("NONE ");
|
||||
return;
|
||||
}
|
||||
switch (colType) {
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
printf("%s ", (*(int8_t *)pVal->val) == 0 ? "false" : "true");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
printf("%" PRIi8 " ", *(int8_t *)pVal->val);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
printf("%" PRIi16 " ", *(int16_t *)pVal->val);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
printf("%" PRIi32 " ", *(int32_t *)pVal->val);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
printf("%" PRIi64 " ", *(int64_t *)pVal->val);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
printf("%f ", *(float *)pVal->val);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
printf("%lf ", *(double *)pVal->val);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
printf("VARCHAR ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
printf("%" PRIi64 " ", *(int64_t *)pVal->val);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_NCHAR:
|
||||
printf("NCHAR ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
printf("%" PRIu8 " ", *(uint8_t *)pVal->val);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
printf("%" PRIu16 " ", *(uint16_t *)pVal->val);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
printf("%" PRIu32 " ", *(uint32_t *)pVal->val);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
printf("%" PRIu64 " ", *(uint64_t *)pVal->val);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
printf("JSON ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
printf("VARBIN ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DECIMAL:
|
||||
printf("DECIMAL ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BLOB:
|
||||
printf("BLOB ");
|
||||
break;
|
||||
case TSDB_DATA_TYPE_MEDIUMBLOB:
|
||||
printf("MedBLOB ");
|
||||
break;
|
||||
// case TSDB_DATA_TYPE_BINARY:
|
||||
// printf("BINARY ");
|
||||
// break;
|
||||
case TSDB_DATA_TYPE_MAX:
|
||||
printf("UNDEF ");
|
||||
break;
|
||||
default:
|
||||
printf("UNDEF ");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t dataColGetNEleLen(SDataCol *pDataCol, int32_t rows, int8_t bitmapMode) {
|
||||
ASSERT(rows > 0);
|
||||
int32_t result = 0;
|
||||
|
||||
if (IS_VAR_DATA_TYPE(pDataCol->type)) {
|
||||
result += pDataCol->dataOff[rows - 1];
|
||||
SCellVal val = {0};
|
||||
if (tdGetColDataOfRow(&val, pDataCol, rows - 1, bitmapMode) < 0) {
|
||||
TASSERT(0);
|
||||
}
|
||||
|
||||
// Currently, count the varDataTLen in of Null/None cols considering back compatibility test for 2.4
|
||||
result += varDataTLen(val.val);
|
||||
// TODO: later on, don't save Null/None for VarDataT for 3.0
|
||||
// if (tdValTypeIsNorm(val.valType)) {
|
||||
// result += varDataTLen(val.val);
|
||||
// }
|
||||
} else {
|
||||
result += TYPE_BYTES[pDataCol->type] * rows;
|
||||
}
|
||||
|
||||
ASSERT(pDataCol->len == result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool tdSKvRowGetVal(STSRow *pRow, col_id_t colId, uint32_t offset, col_id_t colIdx, SCellVal *pVal) {
|
||||
if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
tdRowSetVal(pVal, TD_VTYPE_NORM, TD_ROW_KEY_ADDR(pRow));
|
||||
return true;
|
||||
}
|
||||
void *pBitmap = tdGetBitmapAddrKv(pRow, tdRowGetNCols(pRow));
|
||||
tdGetKvRowValOfCol(pVal, pRow, pBitmap, offset, colIdx);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tdSTpRowGetVal(STSRow *pRow, col_id_t colId, col_type_t colType, int32_t flen, uint32_t offset, col_id_t colIdx,
|
||||
SCellVal *pVal) {
|
||||
if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
tdRowSetVal(pVal, TD_VTYPE_NORM, TD_ROW_KEY_ADDR(pRow));
|
||||
return true;
|
||||
}
|
||||
void *pBitmap = tdGetBitmapAddrTp(pRow, flen);
|
||||
tdGetTpRowValOfCol(pVal, pRow, pBitmap, colType, offset - sizeof(TSKEY), colIdx);
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t tdGetColDataOfRow(SCellVal *pVal, SDataCol *pCol, int32_t row, int8_t bitmapMode) {
|
||||
if (isAllRowsNone(pCol)) {
|
||||
pVal->valType = TD_VTYPE_NULL;
|
||||
#ifdef TD_SUPPORT_READ2
|
||||
pVal->val = (void *)getNullValue(pCol->type);
|
||||
#else
|
||||
pVal->val = NULL;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (TD_COL_ROWS_NORM(pCol)) {
|
||||
pVal->valType = TD_VTYPE_NORM;
|
||||
} else if (tdGetBitmapValType(pCol->pBitmap, row, &(pVal->valType), bitmapMode) < 0) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
if (tdValTypeIsNorm(pVal->valType)) {
|
||||
if (IS_VAR_DATA_TYPE(pCol->type)) {
|
||||
pVal->val = POINTER_SHIFT(pCol->pData, pCol->dataOff[row]);
|
||||
} else {
|
||||
pVal->val = POINTER_SHIFT(pCol->pData, TYPE_BYTES[pCol->type] * row);
|
||||
}
|
||||
} else {
|
||||
pVal->valType = TD_VTYPE_NULL;
|
||||
#ifdef TD_SUPPORT_READ2
|
||||
pVal->val = (void *)getNullValue(pCol->type);
|
||||
#else
|
||||
pVal->val = NULL;
|
||||
#endif
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
bool tdSTSRowIterNext(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCellVal *pVal) {
|
||||
if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
pVal->val = &pIter->pRow->ts;
|
||||
pVal->valType = TD_VTYPE_NORM;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (TD_IS_TP_ROW(pIter->pRow)) {
|
||||
STColumn *pCol = NULL;
|
||||
STSchema *pSchema = pIter->pSchema;
|
||||
while (pIter->colIdx < pSchema->numOfCols) {
|
||||
pCol = &pSchema->columns[pIter->colIdx]; // 1st column of schema is primary TS key
|
||||
if (colId == pCol->colId) {
|
||||
break;
|
||||
} else if (pCol->colId < colId) {
|
||||
++pIter->colIdx;
|
||||
continue;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
tdGetTpRowDataOfCol(pIter, pCol->type, pCol->offset - sizeof(TSKEY), pVal);
|
||||
++pIter->colIdx;
|
||||
} else if (TD_IS_KV_ROW(pIter->pRow)) {
|
||||
return tdGetKvRowValOfColEx(pIter, colId, colType, &pIter->kvIdx, pVal);
|
||||
} else {
|
||||
pVal->valType = TD_VTYPE_NONE;
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
if (COL_REACH_END(colId, pIter->maxColId)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tdGetKvRowValOfColEx(STSRowIter *pIter, col_id_t colId, col_type_t colType, col_id_t *nIdx, SCellVal *pVal) {
|
||||
STSRow *pRow = pIter->pRow;
|
||||
SKvRowIdx *pKvIdx = NULL;
|
||||
bool colFound = false;
|
||||
col_id_t kvNCols = tdRowGetNCols(pRow) - 1;
|
||||
while (*nIdx < kvNCols) {
|
||||
pKvIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(pRow), *nIdx * sizeof(SKvRowIdx));
|
||||
if (pKvIdx->colId == colId) {
|
||||
++(*nIdx);
|
||||
pVal->val = POINTER_SHIFT(pRow, pKvIdx->offset);
|
||||
colFound = true;
|
||||
break;
|
||||
} else if (pKvIdx->colId > colId) {
|
||||
pVal->valType = TD_VTYPE_NONE;
|
||||
return true;
|
||||
} else {
|
||||
++(*nIdx);
|
||||
}
|
||||
}
|
||||
|
||||
if (!colFound) {
|
||||
if (colId <= pIter->maxColId) {
|
||||
pVal->valType = TD_VTYPE_NONE;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
int16_t colIdx = -1;
|
||||
if (pKvIdx) colIdx = POINTER_DISTANCE(TD_ROW_COL_IDX(pRow), pKvIdx) / sizeof(SKvRowIdx);
|
||||
if (tdGetBitmapValType(pIter->pBitmap, colIdx, &pVal->valType, 0) != TSDB_CODE_SUCCESS) {
|
||||
pVal->valType = TD_VTYPE_NONE;
|
||||
}
|
||||
#else
|
||||
pVal->valType = isNull(pVal->val, colType) ? TD_VTYPE_NULL : TD_VTYPE_NORM;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool tdGetTpRowDataOfCol(STSRowIter *pIter, col_type_t colType, int32_t offset, SCellVal *pVal) {
|
||||
STSRow *pRow = pIter->pRow;
|
||||
if (IS_VAR_DATA_TYPE(colType)) {
|
||||
pVal->val = POINTER_SHIFT(pRow, *(VarDataOffsetT *)POINTER_SHIFT(TD_ROW_DATA(pRow), offset));
|
||||
} else {
|
||||
pVal->val = POINTER_SHIFT(TD_ROW_DATA(pRow), offset);
|
||||
}
|
||||
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
if (tdGetBitmapValType(pIter->pBitmap, pIter->colIdx - 1, &pVal->valType, 0) != TSDB_CODE_SUCCESS) {
|
||||
pVal->valType = TD_VTYPE_NONE;
|
||||
}
|
||||
#else
|
||||
pVal->valType = isNull(pVal->val, colType) ? TD_VTYPE_NULL : TD_VTYPE_NORM;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t compareKvRowColId(const void *key1, const void *key2) {
|
||||
if (*(int16_t *)key1 > ((SColIdx *)key2)->colId) {
|
||||
return 1;
|
||||
} else if (*(int16_t *)key1 < ((SColIdx *)key2)->colId) {
|
||||
return -1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool tdSTSRowGetVal(STSRowIter *pIter, col_id_t colId, col_type_t colType, SCellVal *pVal) {
|
||||
if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
pVal->val = &pIter->pRow->ts;
|
||||
pVal->valType = TD_VTYPE_NORM;
|
||||
return true;
|
||||
}
|
||||
|
||||
STSRow *pRow = pIter->pRow;
|
||||
int16_t colIdx = -1;
|
||||
if (TD_IS_TP_ROW(pRow)) {
|
||||
STSchema *pSchema = pIter->pSchema;
|
||||
STColumn *pCol =
|
||||
(STColumn *)taosbsearch(&colId, pSchema->columns, pSchema->numOfCols, sizeof(STColumn), tdCompareColId, TD_EQ);
|
||||
if (!pCol) {
|
||||
pVal->valType = TD_VTYPE_NONE;
|
||||
if (COL_REACH_END(colId, pIter->maxColId)) return false;
|
||||
return true;
|
||||
}
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
colIdx = POINTER_DISTANCE(pCol, pSchema->columns) / sizeof(STColumn);
|
||||
#endif
|
||||
tdGetTpRowValOfCol(pVal, pRow, pIter->pBitmap, pCol->type, pCol->offset - sizeof(TSKEY), colIdx - 1);
|
||||
} else if (TD_IS_KV_ROW(pRow)) {
|
||||
SKvRowIdx *pIdx = (SKvRowIdx *)taosbsearch(&colId, TD_ROW_COL_IDX(pRow), tdRowGetNCols(pRow), sizeof(SKvRowIdx),
|
||||
compareKvRowColId, TD_EQ);
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
if (pIdx) {
|
||||
colIdx = POINTER_DISTANCE(TD_ROW_COL_IDX(pRow), pIdx) / sizeof(SKvRowIdx);
|
||||
}
|
||||
#endif
|
||||
tdGetKvRowValOfCol(pVal, pRow, pIter->pBitmap, pIdx ? pIdx->offset : -1, colIdx);
|
||||
} else {
|
||||
if (COL_REACH_END(colId, pIter->maxColId)) return false;
|
||||
pVal->valType = TD_VTYPE_NONE;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static int32_t tdCompareColId(const void *arg1, const void *arg2) {
|
||||
int32_t colId = *(int32_t *)arg1;
|
||||
STColumn *pCol = (STColumn *)arg2;
|
||||
|
||||
if (colId < pCol->colId) {
|
||||
return -1;
|
||||
} else if (colId == pCol->colId) {
|
||||
return 0;
|
||||
} else {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pValType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
int16_t nBytes = colIdx / TD_VTYPE_PARTS;
|
||||
int16_t nOffset = colIdx & TD_VTYPE_OPTR;
|
||||
char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes);
|
||||
// use literal value directly and not use formula to simplify the codes
|
||||
switch (nOffset) {
|
||||
case 0:
|
||||
*pValType = (((*pDestByte) & 0xC0) >> 6);
|
||||
break;
|
||||
case 1:
|
||||
*pValType = (((*pDestByte) & 0x30) >> 4);
|
||||
break;
|
||||
case 2:
|
||||
*pValType = (((*pDestByte) & 0x0C) >> 2);
|
||||
break;
|
||||
case 3:
|
||||
*pValType = ((*pDestByte) & 0x03);
|
||||
break;
|
||||
default:
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tdGetBitmapValTypeI(const void *pBitmap, int16_t colIdx, TDRowValT *pValType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
int16_t nBytes = colIdx / TD_VTYPE_PARTS_I;
|
||||
int16_t nOffset = colIdx & TD_VTYPE_OPTR_I;
|
||||
char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes);
|
||||
// use literal value directly and not use formula to simplify the codes
|
||||
switch (nOffset) {
|
||||
case 0:
|
||||
*pValType = (((*pDestByte) & 0x80) >> 7);
|
||||
break;
|
||||
case 1:
|
||||
*pValType = (((*pDestByte) & 0x40) >> 6);
|
||||
break;
|
||||
case 2:
|
||||
*pValType = (((*pDestByte) & 0x20) >> 5);
|
||||
break;
|
||||
case 3:
|
||||
*pValType = (((*pDestByte) & 0x10) >> 4);
|
||||
break;
|
||||
case 4:
|
||||
*pValType = (((*pDestByte) & 0x08) >> 3);
|
||||
break;
|
||||
case 5:
|
||||
*pValType = (((*pDestByte) & 0x04) >> 2);
|
||||
break;
|
||||
case 6:
|
||||
*pValType = (((*pDestByte) & 0x02) >> 1);
|
||||
break;
|
||||
case 7:
|
||||
*pValType = ((*pDestByte) & 0x01);
|
||||
break;
|
||||
default:
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, TDRowValT valType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
int16_t nBytes = colIdx / TD_VTYPE_PARTS_I;
|
||||
int16_t nOffset = colIdx & TD_VTYPE_OPTR_I;
|
||||
char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes);
|
||||
// use literal value directly and not use formula to simplify the codes
|
||||
switch (nOffset) {
|
||||
case 0:
|
||||
*pDestByte = ((*pDestByte) & 0x7F) | (valType << 7);
|
||||
// set the value and clear other partitions for offset 0
|
||||
// *pDestByte |= (valType << 7);
|
||||
break;
|
||||
case 1:
|
||||
*pDestByte = ((*pDestByte) & 0xBF) | (valType << 6);
|
||||
// *pDestByte |= (valType << 6);
|
||||
break;
|
||||
case 2:
|
||||
*pDestByte = ((*pDestByte) & 0xDF) | (valType << 5);
|
||||
// *pDestByte |= (valType << 5);
|
||||
break;
|
||||
case 3:
|
||||
*pDestByte = ((*pDestByte) & 0xEF) | (valType << 4);
|
||||
// *pDestByte |= (valType << 4);
|
||||
break;
|
||||
case 4:
|
||||
*pDestByte = ((*pDestByte) & 0xF7) | (valType << 3);
|
||||
// *pDestByte |= (valType << 3);
|
||||
break;
|
||||
case 5:
|
||||
*pDestByte = ((*pDestByte) & 0xFB) | (valType << 2);
|
||||
// *pDestByte |= (valType << 2);
|
||||
break;
|
||||
case 6:
|
||||
*pDestByte = ((*pDestByte) & 0xFD) | (valType << 1);
|
||||
// *pDestByte |= (valType << 1);
|
||||
break;
|
||||
case 7:
|
||||
*pDestByte = ((*pDestByte) & 0xFE) | valType;
|
||||
// *pDestByte |= (valType);
|
||||
break;
|
||||
default:
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tdGetKvRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int32_t offset, int16_t colIdx) {
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
TASSERT(colIdx < tdRowGetNCols(pRow) - 1);
|
||||
if (tdGetBitmapValType(pBitmap, colIdx, &output->valType, 0) != TSDB_CODE_SUCCESS) {
|
||||
output->valType = TD_VTYPE_NONE;
|
||||
return terrno;
|
||||
}
|
||||
if (tdValTypeIsNorm(output->valType)) {
|
||||
if (offset < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
output->valType = TD_VTYPE_NONE;
|
||||
return terrno;
|
||||
}
|
||||
output->val = POINTER_SHIFT(pRow, offset);
|
||||
}
|
||||
#else
|
||||
TASSERT(0);
|
||||
if (offset < 0) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
output->valType = TD_VTYPE_NONE;
|
||||
return terrno;
|
||||
}
|
||||
output->val = POINTER_SHIFT(pRow, offset);
|
||||
output->valType = isNull(output->val, colType) ? TD_VTYPE_NULL : TD_VTYPE_NORM;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tdGetTpRowValOfCol(SCellVal *output, STSRow *pRow, void *pBitmap, int8_t colType, int32_t offset,
|
||||
int16_t colIdx) {
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
if (tdGetBitmapValType(pBitmap, colIdx, &output->valType, 0) != TSDB_CODE_SUCCESS) {
|
||||
output->valType = TD_VTYPE_NONE;
|
||||
return terrno;
|
||||
}
|
||||
if (tdValTypeIsNorm(output->valType)) {
|
||||
if (IS_VAR_DATA_TYPE(colType)) {
|
||||
output->val = POINTER_SHIFT(pRow, *(VarDataOffsetT *)POINTER_SHIFT(TD_ROW_DATA(pRow), offset));
|
||||
} else {
|
||||
output->val = POINTER_SHIFT(TD_ROW_DATA(pRow), offset);
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (IS_VAR_DATA_TYPE(colType)) {
|
||||
output->val = POINTER_SHIFT(pRow, *(VarDataOffsetT *)POINTER_SHIFT(TD_ROW_DATA(pRow), offset));
|
||||
} else {
|
||||
output->val = POINTER_SHIFT(TD_ROW_DATA(pRow), offset);
|
||||
}
|
||||
output->valType = isNull(output->val, colType) ? TD_VTYPE_NULL : TD_VTYPE_NORM;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tdAppendColValToRow(SRowBuilder *pBuilder, col_id_t colId, int8_t colType, TDRowValT valType, const void *val,
|
||||
bool isCopyVarData, int32_t offset, col_id_t colIdx) {
|
||||
STSRow *pRow = pBuilder->pBuf;
|
||||
if (!val) {
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
if (tdValTypeIsNorm(valType)) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return terrno;
|
||||
}
|
||||
#else
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
#endif
|
||||
}
|
||||
// TS KEY is stored in STSRow.ts and not included in STSRow.data field.
|
||||
if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) {
|
||||
TD_ROW_KEY(pRow) = *(TSKEY *)val;
|
||||
// The primary TS key is Norm all the time, thus its valType is not stored in bitmap.
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
// TODO: We can avoid the type judegement by FP, but would prevent the inline scheme.
|
||||
if (TD_IS_TP_ROW(pRow)) {
|
||||
tdAppendColValToTpRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset);
|
||||
} else {
|
||||
tdAppendColValToKvRow(pBuilder, valType, val, isCopyVarData, colType, colIdx, offset, colId);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tdAppendColValToKvRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val, bool isCopyVarData,
|
||||
int8_t colType, int16_t colIdx, int32_t offset, col_id_t colId) {
|
||||
if ((offset < (int32_t)sizeof(SKvRowIdx)) || (colIdx < 1)) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
offset -= sizeof(SKvRowIdx);
|
||||
--colIdx;
|
||||
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
if (tdSetBitmapValType(pBuilder->pBitmap, colIdx, valType, 0) != TSDB_CODE_SUCCESS) {
|
||||
return terrno;
|
||||
}
|
||||
#endif
|
||||
|
||||
STSRow *row = pBuilder->pBuf;
|
||||
// No need to store None/Null values.
|
||||
if (tdValIsNorm(valType, val, colType)) {
|
||||
// ts key stored in STSRow.ts
|
||||
SKvRowIdx *pColIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(row), offset);
|
||||
char *ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row));
|
||||
pColIdx->colId = colId;
|
||||
pColIdx->offset = TD_ROW_LEN(row); // the offset include the TD_ROW_HEAD_LEN
|
||||
|
||||
if (IS_VAR_DATA_TYPE(colType)) {
|
||||
if (isCopyVarData) {
|
||||
memcpy(ptr, val, varDataTLen(val));
|
||||
}
|
||||
TD_ROW_LEN(row) += varDataTLen(val);
|
||||
} else {
|
||||
memcpy(ptr, val, TYPE_BYTES[colType]);
|
||||
TD_ROW_LEN(row) += TYPE_BYTES[colType];
|
||||
}
|
||||
}
|
||||
#ifdef TD_SUPPORT_BACK2
|
||||
// NULL/None value
|
||||
else {
|
||||
SKvRowIdx *pColIdx = (SKvRowIdx *)POINTER_SHIFT(TD_ROW_COL_IDX(row), offset);
|
||||
char *ptr = (char *)POINTER_SHIFT(row, TD_ROW_LEN(row));
|
||||
pColIdx->colId = colId;
|
||||
pColIdx->offset = TD_ROW_LEN(row); // the offset include the TD_ROW_HEAD_LEN
|
||||
const void *nullVal = getNullValue(colType);
|
||||
|
||||
if (IS_VAR_DATA_TYPE(colType)) {
|
||||
if (isCopyVarData) {
|
||||
memcpy(ptr, nullVal, varDataTLen(nullVal));
|
||||
}
|
||||
TD_ROW_LEN(row) += varDataTLen(nullVal);
|
||||
} else {
|
||||
memcpy(ptr, nullVal, TYPE_BYTES[colType]);
|
||||
TD_ROW_LEN(row) += TYPE_BYTES[colType];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tdAppendColValToTpRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val, bool isCopyVarData,
|
||||
int8_t colType, int16_t colIdx, int32_t offset) {
|
||||
if ((offset < (int32_t)sizeof(TSKEY)) || (colIdx < 1)) {
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
offset -= sizeof(TSKEY);
|
||||
--colIdx;
|
||||
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
if (tdSetBitmapValType(pBuilder->pBitmap, colIdx, valType, 0) != TSDB_CODE_SUCCESS) {
|
||||
return terrno;
|
||||
}
|
||||
#endif
|
||||
|
||||
STSRow *row = pBuilder->pBuf;
|
||||
|
||||
// 1. No need to set flen part for Null/None, just use bitmap. When upsert for the same primary TS key, the bitmap
|
||||
// should be updated simultaneously if Norm val overwrite Null/None cols.
|
||||
// 2. When consume STSRow in memory by taos client/tq, the output of Null/None cols should both be Null.
|
||||
if (tdValIsNorm(valType, val, colType)) {
|
||||
// TODO: The layout of new data types imported since 3.0 like blob/medium blob is the same with binary/nchar.
|
||||
if (IS_VAR_DATA_TYPE(colType)) {
|
||||
// ts key stored in STSRow.ts
|
||||
*(VarDataOffsetT *)POINTER_SHIFT(TD_ROW_DATA(row), offset) = TD_ROW_LEN(row);
|
||||
if (isCopyVarData) {
|
||||
memcpy(POINTER_SHIFT(row, TD_ROW_LEN(row)), val, varDataTLen(val));
|
||||
}
|
||||
TD_ROW_LEN(row) += varDataTLen(val);
|
||||
} else {
|
||||
memcpy(POINTER_SHIFT(TD_ROW_DATA(row), offset), val, TYPE_BYTES[colType]);
|
||||
}
|
||||
}
|
||||
#ifdef TD_SUPPORT_BACK2
|
||||
// NULL/None value
|
||||
else {
|
||||
// TODO: Null value for new data types imported since 3.0 need to be defined.
|
||||
const void *nullVal = getNullValue(colType);
|
||||
if (IS_VAR_DATA_TYPE(colType)) {
|
||||
// ts key stored in STSRow.ts
|
||||
*(VarDataOffsetT *)POINTER_SHIFT(TD_ROW_DATA(row), offset) = TD_ROW_LEN(row);
|
||||
|
||||
if (isCopyVarData) {
|
||||
memcpy(POINTER_SHIFT(row, TD_ROW_LEN(row)), nullVal, varDataTLen(nullVal));
|
||||
}
|
||||
TD_ROW_LEN(row) += varDataTLen(nullVal);
|
||||
} else {
|
||||
memcpy(POINTER_SHIFT(TD_ROW_DATA(row), offset), nullVal, TYPE_BYTES[colType]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int32_t tdSRowSetExtendedInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBoundCols, int32_t flen,
|
||||
int32_t allNullLen, int32_t boundNullLen) {
|
||||
if ((boundNullLen > 0) && (allNullLen > 0) && (nBoundCols > 0)) {
|
||||
uint32_t tpLen = allNullLen;
|
||||
uint32_t kvLen = sizeof(col_id_t) + sizeof(SKvRowIdx) * nBoundCols + boundNullLen;
|
||||
if (isSelectKVRow(kvLen, tpLen)) {
|
||||
pBuilder->rowType = TD_ROW_KV;
|
||||
} else {
|
||||
pBuilder->rowType = TD_ROW_TP;
|
||||
}
|
||||
|
||||
} else {
|
||||
pBuilder->rowType = TD_ROW_TP;
|
||||
}
|
||||
|
||||
pBuilder->flen = flen;
|
||||
pBuilder->nCols = nCols;
|
||||
pBuilder->nBoundCols = nBoundCols;
|
||||
if (pBuilder->flen <= 0 || pBuilder->nCols <= 0) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
// the primary TS key is stored separatedly
|
||||
pBuilder->nBitmaps = (col_id_t)TD_BITMAP_BYTES(pBuilder->nCols - 1);
|
||||
if (nBoundCols > 0) {
|
||||
pBuilder->nBoundBitmaps = (col_id_t)TD_BITMAP_BYTES(pBuilder->nBoundCols - 1);
|
||||
} else {
|
||||
pBuilder->nBoundBitmaps = 0;
|
||||
}
|
||||
#else
|
||||
pBuilder->nBitmaps = 0;
|
||||
pBuilder->nBoundBitmaps = 0;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tdSRowResetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
||||
pBuilder->pBuf = (STSRow *)pBuf;
|
||||
if (!pBuilder->pBuf) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
TD_ROW_SET_INFO(pBuilder->pBuf, 0);
|
||||
TD_ROW_SET_TYPE(pBuilder->pBuf, pBuilder->rowType);
|
||||
|
||||
TASSERT(pBuilder->nBitmaps > 0 && pBuilder->flen > 0);
|
||||
|
||||
uint32_t len = 0;
|
||||
switch (pBuilder->rowType) {
|
||||
case TD_ROW_TP:
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
pBuilder->pBitmap = tdGetBitmapAddrTp(pBuilder->pBuf, pBuilder->flen);
|
||||
memset(pBuilder->pBitmap, TD_VTYPE_NONE_BYTE_II, pBuilder->nBitmaps);
|
||||
#endif
|
||||
// the primary TS key is stored separatedly
|
||||
len = TD_ROW_HEAD_LEN + pBuilder->flen - sizeof(TSKEY) + pBuilder->nBitmaps;
|
||||
TD_ROW_SET_LEN(pBuilder->pBuf, len);
|
||||
TD_ROW_SET_SVER(pBuilder->pBuf, pBuilder->sver);
|
||||
break;
|
||||
case TD_ROW_KV:
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
pBuilder->pBitmap = tdGetBitmapAddrKv(pBuilder->pBuf, pBuilder->nBoundCols);
|
||||
memset(pBuilder->pBitmap, TD_VTYPE_NONE_BYTE_II, pBuilder->nBoundBitmaps);
|
||||
#endif
|
||||
len = TD_ROW_HEAD_LEN + TD_ROW_NCOLS_LEN + (pBuilder->nBoundCols - 1) * sizeof(SKvRowIdx) +
|
||||
pBuilder->nBoundBitmaps; // add
|
||||
TD_ROW_SET_LEN(pBuilder->pBuf, len);
|
||||
TD_ROW_SET_SVER(pBuilder->pBuf, pBuilder->sver);
|
||||
TD_ROW_SET_NCOLS(pBuilder->pBuf, pBuilder->nBoundCols);
|
||||
break;
|
||||
default:
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tdSRowGetBuf(SRowBuilder *pBuilder, void *pBuf) {
|
||||
pBuilder->pBuf = (STSRow *)pBuf;
|
||||
if (!pBuilder->pBuf) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
|
||||
TASSERT(pBuilder->nBitmaps > 0 && pBuilder->flen > 0);
|
||||
|
||||
uint32_t len = 0;
|
||||
switch (pBuilder->rowType) {
|
||||
case TD_ROW_TP:
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
pBuilder->pBitmap = tdGetBitmapAddrTp(pBuilder->pBuf, pBuilder->flen);
|
||||
#endif
|
||||
break;
|
||||
case TD_ROW_KV:
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
pBuilder->pBitmap = tdGetBitmapAddrKv(pBuilder->pBuf, pBuilder->nBoundCols);
|
||||
#endif
|
||||
break;
|
||||
default:
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tdSRowInitEx(SRowBuilder *pBuilder, void *pBuf, uint32_t allNullLen, uint32_t boundNullLen, int32_t nCols,
|
||||
int32_t nBoundCols, int32_t flen) {
|
||||
if (tdSRowSetExtendedInfo(pBuilder, allNullLen, boundNullLen, nCols, nBoundCols, flen) < 0) {
|
||||
return terrno;
|
||||
}
|
||||
return tdSRowResetBuf(pBuilder, pBuf);
|
||||
}
|
||||
|
||||
void tdSRowReset(SRowBuilder *pBuilder) {
|
||||
pBuilder->rowType = TD_ROW_TP;
|
||||
pBuilder->pBuf = NULL;
|
||||
pBuilder->nBoundCols = -1;
|
||||
pBuilder->nCols = -1;
|
||||
pBuilder->flen = -1;
|
||||
pBuilder->pBitmap = NULL;
|
||||
}
|
||||
|
||||
int32_t tdSRowSetTpInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t flen) {
|
||||
pBuilder->flen = flen;
|
||||
pBuilder->nCols = nCols;
|
||||
if (pBuilder->flen <= 0 || pBuilder->nCols <= 0) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
// the primary TS key is stored separatedly
|
||||
pBuilder->nBitmaps = (int16_t)TD_BITMAP_BYTES(pBuilder->nCols - 1);
|
||||
#else
|
||||
pBuilder->nBitmaps = 0;
|
||||
pBuilder->nBoundBitmaps = 0;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tdSRowSetInfo(SRowBuilder *pBuilder, int32_t nCols, int32_t nBoundCols, int32_t flen) {
|
||||
pBuilder->flen = flen;
|
||||
pBuilder->nCols = nCols;
|
||||
pBuilder->nBoundCols = nBoundCols;
|
||||
if (pBuilder->flen <= 0 || pBuilder->nCols <= 0) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
// the primary TS key is stored separatedly
|
||||
pBuilder->nBitmaps = (int16_t)TD_BITMAP_BYTES(pBuilder->nCols - 1);
|
||||
if (nBoundCols > 0) {
|
||||
pBuilder->nBoundBitmaps = (int16_t)TD_BITMAP_BYTES(pBuilder->nBoundCols - 1);
|
||||
} else {
|
||||
pBuilder->nBoundBitmaps = 0;
|
||||
}
|
||||
#else
|
||||
pBuilder->nBitmaps = 0;
|
||||
pBuilder->nBoundBitmaps = 0;
|
||||
#endif
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValType, int8_t bitmapMode) {
|
||||
switch (bitmapMode) {
|
||||
case 0:
|
||||
tdGetBitmapValTypeII(pBitmap, colIdx, pValType);
|
||||
break;
|
||||
case -1:
|
||||
case 1:
|
||||
tdGetBitmapValTypeI(pBitmap, colIdx, pValType);
|
||||
break;
|
||||
default:
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
bool tdIsBitmapValTypeNorm(const void *pBitmap, int16_t idx, int8_t bitmapMode) {
|
||||
TDRowValT valType = 0;
|
||||
tdGetBitmapValType(pBitmap, idx, &valType, bitmapMode);
|
||||
if (tdValTypeIsNorm(valType)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT valType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
int16_t nBytes = colIdx / TD_VTYPE_PARTS;
|
||||
int16_t nOffset = colIdx & TD_VTYPE_OPTR;
|
||||
char *pDestByte = (char *)POINTER_SHIFT(pBitmap, nBytes);
|
||||
// use literal value directly and not use formula to simplify the codes
|
||||
switch (nOffset) {
|
||||
case 0:
|
||||
*pDestByte = ((*pDestByte) & 0x3F) | (valType << 6);
|
||||
// set the value and clear other partitions for offset 0
|
||||
// *pDestByte |= (valType << 6);
|
||||
break;
|
||||
case 1:
|
||||
*pDestByte = ((*pDestByte) & 0xCF) | (valType << 4);
|
||||
// *pDestByte |= (valType << 4);
|
||||
break;
|
||||
case 2:
|
||||
*pDestByte = ((*pDestByte) & 0xF3) | (valType << 2);
|
||||
// *pDestByte |= (valType << 2);
|
||||
break;
|
||||
case 3:
|
||||
*pDestByte = ((*pDestByte) & 0xFC) | valType;
|
||||
// *pDestByte |= (valType);
|
||||
break;
|
||||
default:
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return terrno;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT valType, int8_t bitmapMode) {
|
||||
switch (bitmapMode) {
|
||||
case 0:
|
||||
tdSetBitmapValTypeII(pBitmap, colIdx, valType);
|
||||
break;
|
||||
case -1:
|
||||
case 1:
|
||||
tdSetBitmapValTypeI(pBitmap, colIdx, valType);
|
||||
break;
|
||||
default:
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
void *tdGetBitmapAddr(STSRow *pRow, uint8_t rowType, uint32_t flen, col_id_t nKvCols) {
|
||||
#ifdef TD_SUPPORT_BITMAP
|
||||
switch (rowType) {
|
||||
case TD_ROW_TP:
|
||||
return tdGetBitmapAddrTp(pRow, flen);
|
||||
case TD_ROW_KV:
|
||||
return tdGetBitmapAddrKv(pRow, nKvCols);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void tdSTSRowIterReset(STSRowIter *pIter, STSRow *pRow) {
|
||||
pIter->pRow = pRow;
|
||||
pIter->pBitmap = tdGetBitmapAddr(pRow, pRow->type, pIter->pSchema->flen, tdRowGetNCols(pRow));
|
||||
pIter->offset = 0;
|
||||
pIter->colIdx = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
pIter->kvIdx = 0;
|
||||
}
|
||||
|
||||
void tdSTSRowIterInit(STSRowIter *pIter, STSchema *pSchema) {
|
||||
pIter->pSchema = pSchema;
|
||||
pIter->maxColId = pSchema->columns[pSchema->numOfCols - 1].colId;
|
||||
}
|
|
@ -26,8 +26,10 @@ int32_t dmOpenNode(SMgmtWrapper *pWrapper);
|
|||
void dmCloseNode(SMgmtWrapper *pWrapper);
|
||||
|
||||
// dmTransport.c
|
||||
int32_t dmInitTrans(SDnode *pDnode);
|
||||
void dmCleanupTrans(SDnode *pDnode);
|
||||
int32_t dmInitServer(SDnode *pDnode);
|
||||
void dmCleanupServer(SDnode *pDnode);
|
||||
int32_t dmInitClient(SDnode *pDnode);
|
||||
void dmCleanupClient(SDnode *pDnode);
|
||||
SProcCfg dmGenProcCfg(SMgmtWrapper *pWrapper);
|
||||
SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper);
|
||||
int32_t dmInitMsgHandle(SDnode *pDnode);
|
||||
|
|
|
@ -213,10 +213,12 @@ static int32_t dmOpenNodes(SDnode *pDnode) {
|
|||
}
|
||||
|
||||
pWrapper->procType = DND_PROC_CHILD;
|
||||
if (dmInitClient(pDnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SMsgCb msgCb = pDnode->data.msgCb;
|
||||
msgCb.pWrapper = pWrapper;
|
||||
tmsgSetDefaultMsgCb(&msgCb);
|
||||
pDnode->data.msgCb = dmGetMsgcb(pWrapper);
|
||||
tmsgSetDefaultMsgCb(&pDnode->data.msgCb);
|
||||
|
||||
if (dmOpenNode(pWrapper) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
|
@ -234,6 +236,15 @@ static int32_t dmOpenNodes(SDnode *pDnode) {
|
|||
pWrapper->procType = DND_PROC_SINGLE;
|
||||
}
|
||||
|
||||
if (n == DNODE) {
|
||||
if (dmInitClient(pDnode) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
pDnode->data.msgCb = dmGetMsgcb(pWrapper);
|
||||
tmsgSetDefaultMsgCb(&pDnode->data.msgCb);
|
||||
}
|
||||
|
||||
if (dmOpenNode(pWrapper) != 0) {
|
||||
dError("node:%s, failed to open since %s", pWrapper->name, terrstr());
|
||||
return -1;
|
||||
|
@ -281,21 +292,21 @@ static void dmProcessProcHandle(void *handle) {
|
|||
}
|
||||
|
||||
static void dmWatchNodes(SDnode *pDnode) {
|
||||
taosThreadMutexLock(&pDnode->mutex);
|
||||
if (pDnode->ptype == DND_PROC_PARENT) {
|
||||
for (EDndNodeType n = DNODE + 1; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (pWrapper->procType != DND_PROC_PARENT) continue;
|
||||
if (pDnode->ntype == NODE_END) continue;
|
||||
if (pDnode->ptype != DND_PROC_PARENT) return;
|
||||
if (pDnode->ntype == NODE_END) return;
|
||||
|
||||
if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) {
|
||||
dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId);
|
||||
if (pWrapper->procObj) {
|
||||
taosProcCloseHandles(pWrapper->procObj, dmProcessProcHandle);
|
||||
}
|
||||
dmNewNodeProc(pWrapper, n);
|
||||
taosThreadMutexLock(&pDnode->mutex);
|
||||
for (EDndNodeType n = DNODE + 1; n < NODE_END; ++n) {
|
||||
SMgmtWrapper *pWrapper = &pDnode->wrappers[n];
|
||||
if (!pWrapper->required) continue;
|
||||
if (pWrapper->procType != DND_PROC_PARENT) continue;
|
||||
|
||||
if (pWrapper->procId <= 0 || !taosProcExist(pWrapper->procId)) {
|
||||
dWarn("node:%s, process:%d is killed and needs to be restarted", pWrapper->name, pWrapper->procId);
|
||||
if (pWrapper->procObj) {
|
||||
taosProcCloseHandles(pWrapper->procObj, dmProcessProcHandle);
|
||||
}
|
||||
dmNewNodeProc(pWrapper, n);
|
||||
}
|
||||
}
|
||||
taosThreadMutexUnlock(&pDnode->mutex);
|
||||
|
|
|
@ -217,145 +217,6 @@ static void dmStopMgmt(SMgmtWrapper *pWrapper) {
|
|||
dmStopStatusThread(pWrapper->pDnode);
|
||||
}
|
||||
|
||||
static int32_t dmSpawnUdfd(SDnode *pDnode);
|
||||
|
||||
void dmUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal) {
|
||||
dInfo("udfd process exited with status %" PRId64 ", signal %d", exitStatus, termSignal);
|
||||
SDnode *pDnode = process->data;
|
||||
if (exitStatus == 0 && termSignal == 0 || atomic_load_32(&pDnode->udfdData.stopCalled)) {
|
||||
dInfo("udfd process exit due to SIGINT or dnode-mgmt called stop");
|
||||
} else {
|
||||
dInfo("udfd process restart");
|
||||
dmSpawnUdfd(pDnode);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t dmSpawnUdfd(SDnode *pDnode) {
|
||||
dInfo("dnode start spawning udfd");
|
||||
uv_process_options_t options = {0};
|
||||
|
||||
char path[PATH_MAX] = {0};
|
||||
if (tsProcPath == NULL) {
|
||||
path[0] = '.';
|
||||
} else {
|
||||
strncpy(path, tsProcPath, strlen(tsProcPath));
|
||||
taosDirName(path);
|
||||
}
|
||||
#ifdef WINDOWS
|
||||
strcat(path, "udfd.exe");
|
||||
#else
|
||||
strcat(path, "/udfd");
|
||||
#endif
|
||||
char* argsUdfd[] = {path, "-c", configDir, NULL};
|
||||
options.args = argsUdfd;
|
||||
options.file = path;
|
||||
|
||||
options.exit_cb = dmUdfdExit;
|
||||
|
||||
SUdfdData *pData = &pDnode->udfdData;
|
||||
uv_pipe_init(&pData->loop, &pData->ctrlPipe, 1);
|
||||
|
||||
uv_stdio_container_t child_stdio[3];
|
||||
child_stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;
|
||||
child_stdio[0].data.stream = (uv_stream_t*) &pData->ctrlPipe;
|
||||
child_stdio[1].flags = UV_IGNORE;
|
||||
child_stdio[2].flags = UV_INHERIT_FD;
|
||||
child_stdio[2].data.fd = 2;
|
||||
options.stdio_count = 3;
|
||||
options.stdio = child_stdio;
|
||||
|
||||
options.flags = UV_PROCESS_DETACHED;
|
||||
|
||||
char dnodeIdEnvItem[32] = {0};
|
||||
char thrdPoolSizeEnvItem[32] = {0};
|
||||
snprintf(dnodeIdEnvItem, 32, "%s=%d", "DNODE_ID", pDnode->data.dnodeId);
|
||||
float numCpuCores = 4;
|
||||
taosGetCpuCores(&numCpuCores);
|
||||
snprintf(thrdPoolSizeEnvItem,32, "%s=%d", "UV_THREADPOOL_SIZE", (int)numCpuCores*2);
|
||||
char* envUdfd[] = {dnodeIdEnvItem, thrdPoolSizeEnvItem, NULL};
|
||||
options.env = envUdfd;
|
||||
|
||||
int err = uv_spawn(&pData->loop, &pData->process, &options);
|
||||
pData->process.data = (void*)pDnode;
|
||||
|
||||
if (err != 0) {
|
||||
dError("can not spawn udfd. path: %s, error: %s", path, uv_strerror(err));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static void dmUdfdCloseWalkCb(uv_handle_t* handle, void* arg) {
|
||||
if (!uv_is_closing(handle)) {
|
||||
uv_close(handle, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void dmUdfdStopAsyncCb(uv_async_t *async) {
|
||||
SDnode *pDnode = async->data;
|
||||
SUdfdData *pData = &pDnode->udfdData;
|
||||
uv_stop(&pData->loop);
|
||||
}
|
||||
|
||||
static void dmWatchUdfd(void *args) {
|
||||
SDnode *pDnode = args;
|
||||
SUdfdData *pData = &pDnode->udfdData;
|
||||
uv_loop_init(&pData->loop);
|
||||
uv_async_init(&pData->loop, &pData->stopAsync, dmUdfdStopAsyncCb);
|
||||
pData->stopAsync.data = pDnode;
|
||||
int32_t err = dmSpawnUdfd(pDnode);
|
||||
atomic_store_32(&pData->spawnErr, err);
|
||||
uv_barrier_wait(&pData->barrier);
|
||||
uv_run(&pData->loop, UV_RUN_DEFAULT);
|
||||
uv_loop_close(&pData->loop);
|
||||
|
||||
uv_walk(&pData->loop, dmUdfdCloseWalkCb, NULL);
|
||||
uv_run(&pData->loop, UV_RUN_DEFAULT);
|
||||
uv_loop_close(&pData->loop);
|
||||
return;
|
||||
}
|
||||
|
||||
static int32_t dmStartUdfd(SDnode *pDnode) {
|
||||
char dnodeId[8] = {0};
|
||||
snprintf(dnodeId, sizeof(dnodeId), "%d", pDnode->data.dnodeId);
|
||||
uv_os_setenv("DNODE_ID", dnodeId);
|
||||
SUdfdData *pData = &pDnode->udfdData;
|
||||
if (pData->startCalled) {
|
||||
dInfo("dnode-mgmt start udfd already called");
|
||||
return 0;
|
||||
}
|
||||
pData->startCalled = true;
|
||||
uv_barrier_init(&pData->barrier, 2);
|
||||
uv_thread_create(&pData->thread, dmWatchUdfd, pDnode);
|
||||
uv_barrier_wait(&pData->barrier);
|
||||
int32_t err = atomic_load_32(&pData->spawnErr);
|
||||
if (err != 0) {
|
||||
uv_barrier_destroy(&pData->barrier);
|
||||
uv_async_send(&pData->stopAsync);
|
||||
uv_thread_join(&pData->thread);
|
||||
pData->needCleanUp = false;
|
||||
dInfo("dnode-mgmt udfd cleaned up after spawn err");
|
||||
} else {
|
||||
pData->needCleanUp = true;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static int32_t dmStopUdfd(SDnode *pDnode) {
|
||||
dInfo("dnode-mgmt to stop udfd. need cleanup: %d, spawn err: %d",
|
||||
pDnode->udfdData.needCleanUp, pDnode->udfdData.spawnErr);
|
||||
SUdfdData *pData = &pDnode->udfdData;
|
||||
if (!pData->needCleanUp || atomic_load_32(&pData->stopCalled)) {
|
||||
return 0;
|
||||
}
|
||||
atomic_store_32(&pData->stopCalled, 1);
|
||||
pData->needCleanUp = false;
|
||||
uv_barrier_destroy(&pData->barrier);
|
||||
uv_async_send(&pData->stopAsync);
|
||||
uv_thread_join(&pData->thread);
|
||||
dInfo("dnode-mgmt udfd cleaned up");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t dmInitMgmt(SMgmtWrapper *pWrapper) {
|
||||
dInfo("dnode-mgmt start to init");
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
|
@ -381,13 +242,13 @@ static int32_t dmInitMgmt(SMgmtWrapper *pWrapper) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
if (dmInitTrans(pDnode) != 0) {
|
||||
if (dmInitServer(pDnode) != 0) {
|
||||
dError("failed to init transport since %s", terrstr());
|
||||
return -1;
|
||||
}
|
||||
dmReportStartup(pDnode, "dnode-transport", "initialized");
|
||||
|
||||
if (dmStartUdfd(pDnode) != 0) {
|
||||
if (udfStartUdfd(pDnode->data.dnodeId) != 0) {
|
||||
dError("failed to start udfd");
|
||||
}
|
||||
|
||||
|
@ -398,7 +259,9 @@ static int32_t dmInitMgmt(SMgmtWrapper *pWrapper) {
|
|||
static void dmCleanupMgmt(SMgmtWrapper *pWrapper) {
|
||||
dInfo("dnode-mgmt start to clean up");
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
dmStopUdfd(pDnode);
|
||||
|
||||
udfStopUdfd();
|
||||
|
||||
dmStopWorker(pDnode);
|
||||
|
||||
taosWLockLatch(&pDnode->data.latch);
|
||||
|
@ -412,7 +275,8 @@ static void dmCleanupMgmt(SMgmtWrapper *pWrapper) {
|
|||
}
|
||||
taosWUnLockLatch(&pDnode->data.latch);
|
||||
|
||||
dmCleanupTrans(pDnode);
|
||||
dmCleanupClient(pDnode);
|
||||
dmCleanupServer(pDnode);
|
||||
dInfo("dnode-mgmt is cleaned up");
|
||||
}
|
||||
|
||||
|
|
|
@ -124,9 +124,6 @@ SDnode *dmCreate(const SDnodeOpt *pOption) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
pDnode->data.msgCb = dmGetMsgcb(&pDnode->wrappers[DNODE]);
|
||||
tmsgSetDefaultMsgCb(&pDnode->data.msgCb);
|
||||
|
||||
dInfo("dnode is created, data:%p", pDnode);
|
||||
code = 0;
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "dmImp.h"
|
||||
|
||||
#include "qworker.h"
|
||||
|
||||
#define INTERNAL_USER "_dnd"
|
||||
#define INTERNAL_CKEY "_key"
|
||||
#define INTERNAL_SECRET "_pwd"
|
||||
|
@ -85,17 +87,14 @@ static void dmProcessRpcMsg(SMgmtWrapper *pWrapper, SRpcMsg *pRpc, SEpSet *pEpSe
|
|||
if ((pMsg = taosAllocateQitem(sizeof(SNodeMsg))) == NULL) goto _OVER;
|
||||
if (dmBuildMsg(pMsg, pRpc) != 0) goto _OVER;
|
||||
|
||||
if (pWrapper->procType == DND_PROC_SINGLE) {
|
||||
if (pWrapper->procType != DND_PROC_PARENT) {
|
||||
dTrace("msg:%p, created, type:%s handle:%p user:%s", pMsg, TMSG_INFO(msgType), pRpc->handle, pMsg->user);
|
||||
code = (*msgFp)(pWrapper, pMsg);
|
||||
} else if (pWrapper->procType == DND_PROC_PARENT) {
|
||||
} else {
|
||||
dTrace("msg:%p, created and put into child queue, type:%s handle:%p code:0x%04x user:%s contLen:%d", pMsg,
|
||||
TMSG_INFO(msgType), pRpc->handle, pMsg->rpcMsg.code & 0XFFFF, pMsg->user, pRpc->contLen);
|
||||
code = taosProcPutToChildQ(pWrapper->procObj, pMsg, sizeof(SNodeMsg), pRpc->pCont, pRpc->contLen,
|
||||
(isReq && (pMsg->rpcMsg.code == 0)) ? pRpc->handle : NULL, pRpc->refId, PROC_FUNC_REQ);
|
||||
} else {
|
||||
dTrace("msg:%p, should not processed in child process, handle:%p user:%s", pMsg, pRpc->handle, pMsg->user);
|
||||
ASSERT(1);
|
||||
}
|
||||
|
||||
_OVER:
|
||||
|
@ -108,7 +107,7 @@ _OVER:
|
|||
} else {
|
||||
dError("msg:%p, type:%s handle:%p failed to process since 0x%04x:%s", pMsg, TMSG_INFO(msgType), pRpc->handle,
|
||||
code & 0XFFFF, terrstr());
|
||||
if (msgType & 1U) {
|
||||
if (isReq) {
|
||||
if (terrno != 0) code = terrno;
|
||||
if (code == TSDB_CODE_NODE_NOT_DEPLOYED || code == TSDB_CODE_NODE_OFFLINE) {
|
||||
if (msgType > TDMT_MND_MSG && msgType < TDMT_VND_MSG) {
|
||||
|
@ -130,22 +129,27 @@ _OVER:
|
|||
}
|
||||
|
||||
static void dmProcessMsg(SDnode *pDnode, SRpcMsg *pMsg, SEpSet *pEpSet) {
|
||||
SDnodeTrans * pTrans = &pDnode->trans;
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
tmsg_t msgType = pMsg->msgType;
|
||||
bool isReq = msgType & 1u;
|
||||
SMsgHandle * pHandle = &pTrans->msgHandles[TMSG_INDEX(msgType)];
|
||||
SMsgHandle *pHandle = &pTrans->msgHandles[TMSG_INDEX(msgType)];
|
||||
SMgmtWrapper *pWrapper = pHandle->pNdWrapper;
|
||||
|
||||
if (msgType == TDMT_DND_SERVER_STATUS) {
|
||||
dTrace("server status req will be processed, handle:%p, app:%p", pMsg->handle, pMsg->ahandle);
|
||||
dmProcessServerStatusReq(pDnode, pMsg);
|
||||
return;
|
||||
}
|
||||
|
||||
if (msgType == TDMT_DND_NET_TEST) {
|
||||
dTrace("net test req will be processed, handle:%p, app:%p", pMsg->handle, pMsg->ahandle);
|
||||
dmProcessServerStatusReq(pDnode, pMsg);
|
||||
return;
|
||||
switch (msgType) {
|
||||
case TDMT_DND_SERVER_STATUS:
|
||||
dTrace("server status req will be processed, handle:%p, app:%p", pMsg->handle, pMsg->ahandle);
|
||||
dmProcessServerStatusReq(pDnode, pMsg);
|
||||
return;
|
||||
case TDMT_DND_NET_TEST:
|
||||
dTrace("net test req will be processed, handle:%p, app:%p", pMsg->handle, pMsg->ahandle);
|
||||
dmProcessNetTestReq(pDnode, pMsg);
|
||||
return;
|
||||
case TDMT_MND_SYSTABLE_RETRIEVE_RSP:
|
||||
case TDMT_VND_FETCH_RSP:
|
||||
dTrace("retrieve rsp is received");
|
||||
qWorkerProcessFetchRsp(NULL, NULL, pMsg);
|
||||
pMsg->pCont = NULL; // already freed in qworker
|
||||
return;
|
||||
}
|
||||
|
||||
if (pDnode->status != DND_STAT_RUNNING) {
|
||||
|
@ -233,16 +237,6 @@ int32_t dmInitMsgHandle(SDnode *pDnode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline int32_t dmSendRpcReq(SDnode *pDnode, const SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
if (pDnode->trans.clientRpc == NULL) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rpcSendRequest(pDnode->trans.clientRpc, pEpSet, pReq, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmSendRpcRedirectRsp(SDnode *pDnode, const SRpcMsg *pReq) {
|
||||
SEpSet epSet = {0};
|
||||
dmGetMnodeEpSet(pDnode, &epSet);
|
||||
|
@ -288,28 +282,20 @@ void dmSendToMnodeRecv(SDnode *pDnode, SRpcMsg *pReq, SRpcMsg *pRsp) {
|
|||
}
|
||||
|
||||
static inline int32_t dmSendReq(SMgmtWrapper *pWrapper, const SEpSet *pEpSet, SRpcMsg *pReq) {
|
||||
if (pWrapper->pDnode->status != DND_STAT_RUNNING) {
|
||||
SDnode *pDnode = pWrapper->pDnode;
|
||||
if (pDnode->status != DND_STAT_RUNNING) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
dError("failed to send rpc msg since %s, handle:%p", terrstr(), pReq->handle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pWrapper->procType != DND_PROC_CHILD) {
|
||||
return dmSendRpcReq(pWrapper->pDnode, pEpSet, pReq);
|
||||
} else {
|
||||
char *pHead = taosMemoryMalloc(sizeof(SRpcMsg) + sizeof(SEpSet));
|
||||
if (pHead == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(pHead, pReq, sizeof(SRpcMsg));
|
||||
memcpy(pHead + sizeof(SRpcMsg), pEpSet, sizeof(SEpSet));
|
||||
taosProcPutToParentQ(pWrapper->procObj, pHead, sizeof(SRpcMsg) + sizeof(SEpSet), pReq->pCont, pReq->contLen,
|
||||
PROC_FUNC_REQ);
|
||||
taosMemoryFree(pHead);
|
||||
return 0;
|
||||
if (pDnode->trans.clientRpc == NULL) {
|
||||
terrno = TSDB_CODE_NODE_OFFLINE;
|
||||
return -1;
|
||||
}
|
||||
|
||||
rpcSendRequest(pDnode->trans.clientRpc, pEpSet, pReq, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline void dmSendRsp(SMgmtWrapper *pWrapper, const SRpcMsg *pRsp) {
|
||||
|
@ -396,9 +382,10 @@ static void dmConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t
|
|||
pMsg->pCont = pCont;
|
||||
|
||||
if (ftype == PROC_FUNC_REQ) {
|
||||
ASSERT(1);
|
||||
dTrace("msg:%p, get from parent queue, send req:%s handle:%p code:0x%04x, app:%p", pMsg, TMSG_INFO(pMsg->msgType),
|
||||
pMsg->handle, code, pMsg->ahandle);
|
||||
dmSendRpcReq(pWrapper->pDnode, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg);
|
||||
dmSendReq(pWrapper, (SEpSet *)((char *)pMsg + sizeof(SRpcMsg)), pMsg);
|
||||
} else if (ftype == PROC_FUNC_RSP) {
|
||||
dTrace("msg:%p, get from parent queue, rsp handle:%p code:0x%04x, app:%p", pMsg, pMsg->handle, code, pMsg->ahandle);
|
||||
pMsg->refId = taosProcRemoveHandle(pWrapper->procObj, pMsg->handle);
|
||||
|
@ -421,23 +408,25 @@ static void dmConsumeParentQueue(SMgmtWrapper *pWrapper, SRpcMsg *pMsg, int16_t
|
|||
}
|
||||
|
||||
SProcCfg dmGenProcCfg(SMgmtWrapper *pWrapper) {
|
||||
SProcCfg cfg = {.childConsumeFp = (ProcConsumeFp)dmConsumeChildQueue,
|
||||
.childMallocHeadFp = (ProcMallocFp)taosAllocateQitem,
|
||||
.childFreeHeadFp = (ProcFreeFp)taosFreeQitem,
|
||||
.childMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.childFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.parentConsumeFp = (ProcConsumeFp)dmConsumeParentQueue,
|
||||
.parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc,
|
||||
.parentFreeHeadFp = (ProcFreeFp)taosMemoryFree,
|
||||
.parentMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.parentFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.shm = pWrapper->procShm,
|
||||
.parent = pWrapper,
|
||||
.name = pWrapper->name};
|
||||
SProcCfg cfg = {
|
||||
.childConsumeFp = (ProcConsumeFp)dmConsumeChildQueue,
|
||||
.childMallocHeadFp = (ProcMallocFp)taosAllocateQitem,
|
||||
.childFreeHeadFp = (ProcFreeFp)taosFreeQitem,
|
||||
.childMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.childFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.parentConsumeFp = (ProcConsumeFp)dmConsumeParentQueue,
|
||||
.parentMallocHeadFp = (ProcMallocFp)taosMemoryMalloc,
|
||||
.parentFreeHeadFp = (ProcFreeFp)taosMemoryFree,
|
||||
.parentMallocBodyFp = (ProcMallocFp)rpcMallocCont,
|
||||
.parentFreeBodyFp = (ProcFreeFp)rpcFreeCont,
|
||||
.shm = pWrapper->procShm,
|
||||
.parent = pWrapper,
|
||||
.name = pWrapper->name,
|
||||
};
|
||||
return cfg;
|
||||
}
|
||||
|
||||
bool rpcRfp(int32_t code) {
|
||||
static bool rpcRfp(int32_t code) {
|
||||
if (code == TSDB_CODE_RPC_REDIRECT) {
|
||||
return true;
|
||||
} else {
|
||||
|
@ -445,7 +434,7 @@ bool rpcRfp(int32_t code) {
|
|||
}
|
||||
}
|
||||
|
||||
static int32_t dmInitClient(SDnode *pDnode) {
|
||||
int32_t dmInitClient(SDnode *pDnode) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
|
||||
SRpcInit rpcInit = {0};
|
||||
|
@ -471,11 +460,15 @@ static int32_t dmInitClient(SDnode *pDnode) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
pDnode->data.msgCb = dmGetMsgcb(&pDnode->wrappers[DNODE]);
|
||||
tmsgSetDefaultMsgCb(&pDnode->data.msgCb);
|
||||
|
||||
dDebug("dnode rpc client is initialized");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void dmCleanupClient(SDnode *pDnode) {
|
||||
void dmCleanupClient(SDnode *pDnode) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
if (pTrans->clientRpc) {
|
||||
rpcClose(pTrans->clientRpc);
|
||||
|
@ -517,7 +510,7 @@ static inline int32_t dmRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *s
|
|||
SAuthReq authReq = {0};
|
||||
tstrncpy(authReq.user, user, TSDB_USER_LEN);
|
||||
int32_t contLen = tSerializeSAuthReq(NULL, 0, &authReq);
|
||||
void * pReq = rpcMallocCont(contLen);
|
||||
void *pReq = rpcMallocCont(contLen);
|
||||
tSerializeSAuthReq(pReq, contLen, &authReq);
|
||||
|
||||
SRpcMsg rpcMsg = {.pCont = pReq, .contLen = contLen, .msgType = TDMT_MND_AUTH, .ahandle = (void *)9528};
|
||||
|
@ -543,7 +536,7 @@ static inline int32_t dmRetrieveUserAuthInfo(SDnode *pDnode, char *user, char *s
|
|||
return rpcRsp.code;
|
||||
}
|
||||
|
||||
static int32_t dmInitServer(SDnode *pDnode) {
|
||||
int32_t dmInitServer(SDnode *pDnode) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
|
||||
SRpcInit rpcInit = {0};
|
||||
|
@ -569,7 +562,7 @@ static int32_t dmInitServer(SDnode *pDnode) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static void dmCleanupServer(SDnode *pDnode) {
|
||||
void dmCleanupServer(SDnode *pDnode) {
|
||||
SDnodeTrans *pTrans = &pDnode->trans;
|
||||
if (pTrans->serverRpc) {
|
||||
rpcClose(pTrans->serverRpc);
|
||||
|
@ -578,17 +571,6 @@ static void dmCleanupServer(SDnode *pDnode) {
|
|||
}
|
||||
}
|
||||
|
||||
int32_t dmInitTrans(SDnode *pDnode) {
|
||||
if (dmInitServer(pDnode) != 0) return -1;
|
||||
if (dmInitClient(pDnode) != 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void dmCleanupTrans(SDnode *pDnode) {
|
||||
dmCleanupServer(pDnode);
|
||||
dmCleanupClient(pDnode);
|
||||
}
|
||||
|
||||
SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper) {
|
||||
SMsgCb msgCb = {
|
||||
.sendReqFp = dmSendReq,
|
||||
|
@ -598,6 +580,7 @@ SMsgCb dmGetMsgcb(SMgmtWrapper *pWrapper) {
|
|||
.releaseHandleFp = dmReleaseHandle,
|
||||
.reportStartupFp = dmReportStartupByWrapper,
|
||||
.pWrapper = pWrapper,
|
||||
.clientRpc = pWrapper->pDnode->trans.clientRpc,
|
||||
};
|
||||
return msgCb;
|
||||
}
|
||||
|
|
|
@ -156,6 +156,8 @@ typedef struct SUdfdData {
|
|||
uv_pipe_t ctrlPipe;
|
||||
uv_async_t stopAsync;
|
||||
int32_t stopCalled;
|
||||
|
||||
int32_t dnodeId;
|
||||
} SUdfdData;
|
||||
|
||||
typedef struct SDnode {
|
||||
|
|
|
@ -37,7 +37,7 @@ void dmSetMsgHandle(SMgmtWrapper *pWrapper, tmsg_t msgType, NodeMsgFp nodeMsgF
|
|||
void dmReportStartup(SDnode *pDnode, const char *pName, const char *pDesc);
|
||||
void dmReportStartupByWrapper(SMgmtWrapper *pWrapper, const char *pName, const char *pDesc);
|
||||
void dmProcessServerStatusReq(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
void dmProcessNettestReq(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
void dmProcessNetTestReq(SDnode *pDnode, SRpcMsg *pMsg);
|
||||
void dmGetMonitorSysInfo(SMonSysInfo *pInfo);
|
||||
|
||||
// dmFile.c
|
||||
|
|
|
@ -171,16 +171,17 @@ static void dmGetServerStatus(SDnode *pDnode, SServerStatusRsp *pStatus) {
|
|||
}
|
||||
}
|
||||
|
||||
void dmProcessNettestReq(SDnode *pDnode, SRpcMsg *pRpc) {
|
||||
void dmProcessNetTestReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
dDebug("net test req is received");
|
||||
SRpcMsg rsp = {.handle = pRpc->handle, .refId = pRpc->refId, .ahandle = pRpc->ahandle, .code = 0};
|
||||
rsp.pCont = rpcMallocCont(pRpc->contLen);
|
||||
SRpcMsg rsp = {.handle = pReq->handle, .refId = pReq->refId, .ahandle = pReq->ahandle, .code = 0};
|
||||
rsp.pCont = rpcMallocCont(pReq->contLen);
|
||||
if (rsp.pCont == NULL) {
|
||||
rsp.code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
} else {
|
||||
rsp.contLen = pRpc->contLen;
|
||||
rsp.contLen = pReq->contLen;
|
||||
}
|
||||
rpcSendResponse(&rsp);
|
||||
rpcFreeCont(pReq->pCont);
|
||||
}
|
||||
|
||||
void dmProcessServerStatusReq(SDnode *pDnode, SRpcMsg *pReq) {
|
||||
|
@ -208,6 +209,7 @@ void dmProcessServerStatusReq(SDnode *pDnode, SRpcMsg *pReq) {
|
|||
|
||||
_OVER:
|
||||
rpcSendResponse(&rspMsg);
|
||||
rpcFreeCont(pReq->pCont);
|
||||
}
|
||||
|
||||
void dmGetMonitorSysInfo(SMonSysInfo *pInfo) {
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
#define _DEFAULT_SOURCE
|
||||
#include "smInt.h"
|
||||
#include "libs/function/function.h"
|
||||
|
||||
static int32_t smRequire(SMgmtWrapper *pWrapper, bool *required) { return dmReadFile(pWrapper, required); }
|
||||
|
||||
|
@ -29,6 +30,9 @@ static void smClose(SMgmtWrapper *pWrapper) {
|
|||
if (pMgmt == NULL) return;
|
||||
|
||||
dInfo("snode-mgmt start to cleanup");
|
||||
|
||||
udfcClose();
|
||||
|
||||
if (pMgmt->pSnode != NULL) {
|
||||
smStopWorker(pMgmt);
|
||||
sndClose(pMgmt->pSnode);
|
||||
|
@ -68,6 +72,10 @@ int32_t smOpen(SMgmtWrapper *pWrapper) {
|
|||
}
|
||||
dmReportStartup(pWrapper->pDnode, "snode-worker", "initialized");
|
||||
|
||||
if (udfcOpen() != 0) {
|
||||
dError("failed to open udfc in snode");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -289,7 +289,6 @@ void vmInitMsgHandle(SMgmtWrapper *pWrapper) {
|
|||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY, vmProcessQueryMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_QUERY_CONTINUE, vmProcessQueryMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_FETCH, vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_FETCH_RSP, vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_ALTER_TABLE, vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_UPDATE_TAG_VAL, vmProcessWriteMsg, DEFAULT_HANDLE);
|
||||
dmSetMsgHandle(pWrapper, TDMT_VND_TABLE_META, vmProcessFetchMsg, DEFAULT_HANDLE);
|
||||
|
|
|
@ -324,7 +324,7 @@ static int32_t vmInit(SMgmtWrapper *pWrapper) {
|
|||
dmReportStartup(pDnode, "vnode-vnodes", "initialized");
|
||||
|
||||
if (udfcOpen() != 0) {
|
||||
dError("failed to open udfc in dnode");
|
||||
dError("failed to open udfc in vnode");
|
||||
}
|
||||
|
||||
code = 0;
|
||||
|
|
|
@ -198,6 +198,9 @@ static void vmProcessApplyQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numO
|
|||
rsp.refId = pMsg->rpcMsg.refId;
|
||||
tmsgSendRsp(&rsp);
|
||||
}
|
||||
|
||||
rpcFreeCont(pMsg->rpcMsg.pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -211,6 +214,9 @@ static void vmProcessSyncQueue(SQueueInfo *pInfo, STaosQall *qall, int32_t numOf
|
|||
// todo
|
||||
SRpcMsg *pRsp = NULL;
|
||||
(void)vnodeProcessSyncReq(pVnode->pImpl, &pMsg->rpcMsg, &pRsp);
|
||||
|
||||
rpcFreeCont(pMsg->rpcMsg.pCont);
|
||||
taosFreeQitem(pMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ int32_t mndInitAuth(SMnode *pMnode);
|
|||
void mndCleanupAuth(SMnode *pMnode);
|
||||
|
||||
int32_t mndCheckCreateUserAuth(SUserObj *pOperUser);
|
||||
int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SDbObj *pDb, SAlterUserReq *pAlter);
|
||||
int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SAlterUserReq *pAlter);
|
||||
int32_t mndCheckDropUserAuth(SUserObj *pOperUser);
|
||||
|
||||
int32_t mndCheckNodeAuth(SUserObj *pOperUser);
|
||||
|
|
|
@ -33,6 +33,8 @@ SSdbRow *mndTopicActionDecode(SSdbRaw *pRaw);
|
|||
|
||||
int32_t mndDropTopicByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb);
|
||||
|
||||
const char *mndTopicGetShowName(const char topic[TSDB_TOPIC_FNAME_LEN]);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -79,14 +79,12 @@ int32_t mndCheckCreateUserAuth(SUserObj *pOperUser) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SDbObj *pDb, SAlterUserReq *pAlter) {
|
||||
int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SAlterUserReq *pAlter) {
|
||||
if (pAlter->alterType == TSDB_ALTER_USER_PASSWD) {
|
||||
if (pOperUser->superUser || strcmp(pUser->user, pOperUser->user) == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (pAlter->alterType == TSDB_ALTER_USER_SUPERUSER) {
|
||||
} else if (pAlter->alterType == TSDB_ALTER_USER_SUPERUSER) {
|
||||
if (strcmp(pUser->user, TSDB_DEFAULT_USER) == 0) {
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
|
@ -95,21 +93,12 @@ int32_t mndCheckAlterUserAuth(SUserObj *pOperUser, SUserObj *pUser, SDbObj *pDb,
|
|||
if (pOperUser->superUser) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (pAlter->alterType == TSDB_ALTER_USER_CLEAR_WRITE_DB || pAlter->alterType == TSDB_ALTER_USER_CLEAR_READ_DB) {
|
||||
} else {
|
||||
if (pOperUser->superUser) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (pAlter->alterType == TSDB_ALTER_USER_ADD_READ_DB || pAlter->alterType == TSDB_ALTER_USER_REMOVE_READ_DB ||
|
||||
pAlter->alterType == TSDB_ALTER_USER_ADD_WRITE_DB || pAlter->alterType == TSDB_ALTER_USER_REMOVE_WRITE_DB) {
|
||||
if (pOperUser->superUser || strcmp(pUser->user, pDb->createUser) == 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
terrno = TSDB_CODE_MND_NO_RIGHTS;
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -790,71 +790,83 @@ static int32_t mndRetrieveConsumer(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock
|
|||
pShow->pIter = sdbFetch(pSdb, SDB_CONSUMER, pShow->pIter, (void **)&pConsumer);
|
||||
if (pShow->pIter == NULL) break;
|
||||
|
||||
SColumnInfoData *pColInfo;
|
||||
int32_t cols = 0;
|
||||
|
||||
taosRLockLatch(&pConsumer->lock);
|
||||
|
||||
// consumer id
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->consumerId, false);
|
||||
int32_t topicSz = taosArrayGetSize(pConsumer->assignedTopics);
|
||||
bool hasTopic = true;
|
||||
if (topicSz == 0) {
|
||||
hasTopic = false;
|
||||
topicSz = 1;
|
||||
}
|
||||
|
||||
// group id
|
||||
char groupId[TSDB_CGROUP_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
tstrncpy(varDataVal(groupId), pConsumer->cgroup, TSDB_CGROUP_LEN);
|
||||
varDataSetLen(groupId, strlen(varDataVal(groupId)));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)groupId, false);
|
||||
for (int32_t i = 0; i < topicSz; i++) {
|
||||
if (numOfRows + topicSz > rowsCapacity) {
|
||||
blockDataEnsureCapacity(pBlock, numOfRows + topicSz);
|
||||
}
|
||||
SColumnInfoData *pColInfo;
|
||||
int32_t cols = 0;
|
||||
|
||||
// app id
|
||||
char appId[TSDB_CGROUP_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
tstrncpy(varDataVal(appId), pConsumer->appId, TSDB_CGROUP_LEN);
|
||||
varDataSetLen(appId, strlen(varDataVal(appId)));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)appId, false);
|
||||
// consumer id
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->consumerId, false);
|
||||
|
||||
// status
|
||||
char status[20 + VARSTR_HEADER_SIZE] = {0};
|
||||
tstrncpy(varDataVal(status), mndConsumerStatusName(pConsumer->status), 20);
|
||||
varDataSetLen(status, strlen(varDataVal(status)));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)status, false);
|
||||
// group id
|
||||
char groupId[TSDB_CGROUP_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
tstrncpy(varDataVal(groupId), pConsumer->cgroup, TSDB_CGROUP_LEN);
|
||||
varDataSetLen(groupId, strlen(varDataVal(groupId)));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)groupId, false);
|
||||
|
||||
// subscribed topics
|
||||
// TODO: split into multiple rows
|
||||
char topics[TSDB_SHOW_LIST_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
char *showStr = taosShowStrArray(pConsumer->assignedTopics);
|
||||
tstrncpy(varDataVal(topics), showStr, TSDB_SHOW_LIST_LEN);
|
||||
taosMemoryFree(showStr);
|
||||
varDataSetLen(topics, strlen(varDataVal(topics)));
|
||||
// app id
|
||||
char appId[TSDB_CGROUP_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
tstrncpy(varDataVal(appId), pConsumer->appId, TSDB_CGROUP_LEN);
|
||||
varDataSetLen(appId, strlen(varDataVal(appId)));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)appId, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)topics, false);
|
||||
// status
|
||||
char status[20 + VARSTR_HEADER_SIZE] = {0};
|
||||
tstrncpy(varDataVal(status), mndConsumerStatusName(pConsumer->status), 20);
|
||||
varDataSetLen(status, strlen(varDataVal(status)));
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)status, false);
|
||||
|
||||
// pid
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->pid, true);
|
||||
// one subscribed topic
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
if (hasTopic) {
|
||||
char topic[TSDB_TOPIC_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
const char *topicName = mndTopicGetShowName(taosArrayGetP(pConsumer->assignedTopics, i));
|
||||
tstrncpy(varDataVal(topic), topicName, TSDB_TOPIC_FNAME_LEN);
|
||||
varDataSetLen(topic, strlen(varDataVal(topic)));
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)topic, false);
|
||||
} else {
|
||||
colDataAppend(pColInfo, numOfRows, NULL, true);
|
||||
}
|
||||
|
||||
// end point
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->ep, true);
|
||||
// pid
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->pid, true);
|
||||
|
||||
// up time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->upTime, false);
|
||||
// end point
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->ep, true);
|
||||
|
||||
// subscribe time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->subscribeTime, false);
|
||||
// up time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->upTime, false);
|
||||
|
||||
// rebalance time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->rebalanceTime, pConsumer->rebalanceTime == 0);
|
||||
// subscribe time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->subscribeTime, false);
|
||||
|
||||
// rebalance time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumer->rebalanceTime, pConsumer->rebalanceTime == 0);
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
taosRUnLockLatch(&pConsumer->lock);
|
||||
sdbRelease(pSdb, pConsumer);
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
|
||||
pShow->numOfRows += numOfRows;
|
||||
|
|
|
@ -1550,10 +1550,8 @@ static void dumpDbInfoData(SSDataBlock *pBlock, SDbObj *pDb, SShowObj *pShow, in
|
|||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, rows, (const char *)t, false);
|
||||
|
||||
// single stable model
|
||||
int8_t m = 0;
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, rows, (const char *)&m, false);
|
||||
colDataAppend(pColInfo, rows, (const char *)&pDb->cfg.numOfStables, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols);
|
||||
colDataAppend(pColInfo, rows, (const char *)b, false);
|
||||
|
|
|
@ -196,7 +196,9 @@ SMqVgEp *tCloneSMqVgEp(const SMqVgEp *pVgEp) {
|
|||
return pVgEpNew;
|
||||
}
|
||||
|
||||
void tDeleteSMqVgEp(SMqVgEp *pVgEp) { taosMemoryFree(pVgEp->qmsg); }
|
||||
void tDeleteSMqVgEp(SMqVgEp *pVgEp) {
|
||||
if (pVgEp->qmsg) taosMemoryFree(pVgEp->qmsg);
|
||||
}
|
||||
|
||||
int32_t tEncodeSMqVgEp(void **buf, const SMqVgEp *pVgEp) {
|
||||
int32_t tlen = 0;
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
int32_t mndProcessQueryMsg(SNodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pNode;
|
||||
SReadHandle handle = {.mnd = pMnode};
|
||||
SReadHandle handle = {.mnd = pMnode, .pMsgCb = &pMnode->msgCb};
|
||||
|
||||
mTrace("msg:%p, in query queue is processing", pReq);
|
||||
switch (pReq->rpcMsg.msgType) {
|
||||
|
|
|
@ -85,8 +85,8 @@ static int32_t convertToRetrieveType(char *name, int32_t len) {
|
|||
type = TSDB_MGMT_TABLE_VGROUP;
|
||||
} else if (strncasecmp(name, TSDB_PERFS_TABLE_CONSUMERS, len) == 0) {
|
||||
type = TSDB_MGMT_TABLE_CONSUMERS;
|
||||
} else if (strncasecmp(name, TSDB_PERFS_TABLE_SUBSCRIBES, len) == 0) {
|
||||
type = TSDB_MGMT_TABLE_SUBSCRIBES;
|
||||
} else if (strncasecmp(name, TSDB_PERFS_TABLE_SUBSCRIPTIONS, len) == 0) {
|
||||
type = TSDB_MGMT_TABLE_SUBSCRIPTIONS;
|
||||
} else if (strncasecmp(name, TSDB_PERFS_TABLE_TRANS, len) == 0) {
|
||||
type = TSDB_MGMT_TABLE_TRANS;
|
||||
} else if (strncasecmp(name, TSDB_PERFS_TABLE_SMAS, len) == 0) {
|
||||
|
|
|
@ -259,7 +259,7 @@ int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast
|
|||
return -1;
|
||||
}
|
||||
|
||||
#if 1
|
||||
#if 0
|
||||
printf("|");
|
||||
for (int i = 0; i < pStream->outputSchema.nCols; i++) {
|
||||
printf(" %15s |", (char *)pStream->outputSchema.pSchema[i].name);
|
||||
|
|
|
@ -44,6 +44,9 @@ static int32_t mndSubActionUpdate(SSdb *pSdb, SMqSubscribeObj *pOldSub, SMqSubs
|
|||
static int32_t mndProcessRebalanceReq(SNodeMsg *pMsg);
|
||||
static int32_t mndProcessSubscribeInternalRsp(SNodeMsg *pMsg);
|
||||
|
||||
static int32_t mndRetrieveSubscribe(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||
static void mndCancelGetNextSubscribe(SMnode *pMnode, void *pIter);
|
||||
|
||||
static int32_t mndSetSubRedoLogs(SMnode *pMnode, STrans *pTrans, SMqSubscribeObj *pSub) {
|
||||
SSdbRaw *pRedoRaw = mndSubActionEncode(pSub);
|
||||
if (pRedoRaw == NULL) return -1;
|
||||
|
@ -71,6 +74,10 @@ int32_t mndInitSubscribe(SMnode *pMnode) {
|
|||
|
||||
mndSetMsgHandle(pMnode, TDMT_VND_MQ_VG_CHANGE_RSP, mndProcessSubscribeInternalRsp);
|
||||
mndSetMsgHandle(pMnode, TDMT_MND_MQ_DO_REBALANCE, mndProcessRebalanceReq);
|
||||
|
||||
mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_SUBSCRIPTIONS, mndRetrieveSubscribe);
|
||||
mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_TOPICS, mndCancelGetNextSubscribe);
|
||||
|
||||
return sdbSetTable(pMnode->pSdb, table);
|
||||
}
|
||||
|
||||
|
@ -706,3 +713,124 @@ int32_t mndDropSubByDB(SMnode *pMnode, STrans *pTrans, SDbObj *pDb) {
|
|||
END:
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t mndRetrieveSubscribe(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rowsCapacity) {
|
||||
SMnode *pMnode = pReq->pNode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
int32_t numOfRows = 0;
|
||||
SMqSubscribeObj *pSub = NULL;
|
||||
|
||||
while (numOfRows < rowsCapacity) {
|
||||
pShow->pIter = sdbFetch(pSdb, SDB_SUBSCRIBE, pShow->pIter, (void **)&pSub);
|
||||
if (pShow->pIter == NULL) break;
|
||||
|
||||
taosRLockLatch(&pSub->lock);
|
||||
|
||||
if (numOfRows + pSub->vgNum > rowsCapacity) {
|
||||
blockDataEnsureCapacity(pBlock, numOfRows + pSub->vgNum);
|
||||
}
|
||||
|
||||
SMqConsumerEp *pConsumerEp = NULL;
|
||||
void *pIter = NULL;
|
||||
while (1) {
|
||||
pIter = taosHashIterate(pSub->consumerHash, pIter);
|
||||
if (pIter == NULL) break;
|
||||
pConsumerEp = (SMqConsumerEp *)pIter;
|
||||
|
||||
int32_t sz = taosArrayGetSize(pConsumerEp->vgs);
|
||||
for (int32_t j = 0; j < sz; j++) {
|
||||
SMqVgEp *pVgEp = taosArrayGetP(pConsumerEp->vgs, j);
|
||||
|
||||
SColumnInfoData *pColInfo;
|
||||
int32_t cols = 0;
|
||||
|
||||
// topic and cgroup
|
||||
char topic[TSDB_TOPIC_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
char cgroup[TSDB_CGROUP_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
mndSplitSubscribeKey(pSub->key, topic, cgroup);
|
||||
varDataSetLen(topic, strlen(varDataVal(topic)));
|
||||
varDataSetLen(cgroup, strlen(varDataVal(cgroup)));
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)topic, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)cgroup, false);
|
||||
|
||||
// vg id
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pVgEp->vgId, false);
|
||||
|
||||
// consumer id
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pConsumerEp->consumerId, false);
|
||||
|
||||
// offset
|
||||
#if 0
|
||||
// subscribe time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pSub->subscribeTime, false);
|
||||
|
||||
// rebalance time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pSub->rebalanceTime, pConsumer->rebalanceTime == 0);
|
||||
#endif
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t sz = taosArrayGetSize(pSub->unassignedVgs);
|
||||
for (int32_t i = 0; i < sz; i++) {
|
||||
SMqVgEp *pVgEp = taosArrayGetP(pSub->unassignedVgs, i);
|
||||
|
||||
SColumnInfoData *pColInfo;
|
||||
int32_t cols = 0;
|
||||
|
||||
// topic and cgroup
|
||||
char topic[TSDB_TOPIC_FNAME_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
char cgroup[TSDB_CGROUP_LEN + VARSTR_HEADER_SIZE] = {0};
|
||||
mndSplitSubscribeKey(pSub->key, topic, cgroup);
|
||||
varDataSetLen(topic, strlen(varDataVal(topic)));
|
||||
varDataSetLen(cgroup, strlen(varDataVal(cgroup)));
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)topic, false);
|
||||
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)cgroup, false);
|
||||
|
||||
// vg id
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pVgEp->vgId, false);
|
||||
|
||||
// consumer id
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, NULL, true);
|
||||
|
||||
// offset
|
||||
#if 0
|
||||
// subscribe time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pSub->subscribeTime, false);
|
||||
|
||||
// rebalance time
|
||||
pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
|
||||
colDataAppend(pColInfo, numOfRows, (const char *)&pSub->rebalanceTime, pConsumer->rebalanceTime == 0);
|
||||
#endif
|
||||
|
||||
numOfRows++;
|
||||
}
|
||||
|
||||
taosRUnLockLatch(&pSub->lock);
|
||||
sdbRelease(pSdb, pSub);
|
||||
}
|
||||
|
||||
pShow->numOfRows += numOfRows;
|
||||
return numOfRows;
|
||||
}
|
||||
|
||||
static void mndCancelGetNextSubscribe(SMnode *pMnode, void *pIter) {
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
sdbCancelFetch(pSdb, pIter);
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ static int32_t mndTopicActionUpdate(SSdb *pSdb, SMqTopicObj *pTopic, SMqTopicObj
|
|||
static int32_t mndProcessCreateTopicReq(SNodeMsg *pReq);
|
||||
static int32_t mndProcessDropTopicReq(SNodeMsg *pReq);
|
||||
static int32_t mndProcessDropTopicInRsp(SNodeMsg *pRsp);
|
||||
|
||||
static int32_t mndRetrieveTopic(SNodeMsg *pReq, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows);
|
||||
static void mndCancelGetNextTopic(SMnode *pMnode, void *pIter);
|
||||
|
||||
|
@ -61,6 +62,11 @@ int32_t mndInitTopic(SMnode *pMnode) {
|
|||
|
||||
void mndCleanupTopic(SMnode *pMnode) {}
|
||||
|
||||
const char *mndTopicGetShowName(const char topic[TSDB_TOPIC_FNAME_LEN]) {
|
||||
//
|
||||
return strchr(topic, '.') + 1;
|
||||
}
|
||||
|
||||
SSdbRaw *mndTopicActionEncode(SMqTopicObj *pTopic) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
|
||||
|
@ -292,6 +298,8 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
|
|||
|
||||
SNode *pAst = NULL;
|
||||
if (nodesStringToNode(pCreate->ast, &pAst) != 0) {
|
||||
taosMemoryFree(topicObj.ast);
|
||||
taosMemoryFree(topicObj.sql);
|
||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -301,16 +309,22 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
|
|||
SPlanContext cxt = {.pAstRoot = pAst, .topicQuery = true};
|
||||
if (qCreateQueryPlan(&cxt, &pPlan, NULL) != 0) {
|
||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
taosMemoryFree(topicObj.ast);
|
||||
taosMemoryFree(topicObj.sql);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qExtractResultSchema(pAst, &topicObj.schema.nCols, &topicObj.schema.pSchema) != 0) {
|
||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
taosMemoryFree(topicObj.ast);
|
||||
taosMemoryFree(topicObj.sql);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (nodesNodeToString(pPlan, false, &topicObj.physicalPlan, NULL) != 0) {
|
||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
taosMemoryFree(topicObj.ast);
|
||||
taosMemoryFree(topicObj.sql);
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
|
@ -325,6 +339,8 @@ static int32_t mndCreateTopic(SMnode *pMnode, SNodeMsg *pReq, SCMCreateTopicReq
|
|||
STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_TYPE_CREATE_TOPIC, &pReq->rpcMsg);
|
||||
if (pTrans == NULL) {
|
||||
mError("topic:%s, failed to create since %s", pCreate->name, terrstr());
|
||||
taosMemoryFreeClear(topicObj.ast);
|
||||
taosMemoryFreeClear(topicObj.sql);
|
||||
taosMemoryFreeClear(topicObj.physicalPlan);
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -394,6 +394,8 @@ static SHashObj *mndDupDbHash(SHashObj *pOld) {
|
|||
|
||||
static int32_t mndProcessAlterUserReq(SNodeMsg *pReq) {
|
||||
SMnode *pMnode = pReq->pNode;
|
||||
SSdb *pSdb = pMnode->pSdb;
|
||||
void *pIter = NULL;
|
||||
int32_t code = -1;
|
||||
SUserObj *pUser = NULL;
|
||||
SUserObj *pOperUser = NULL;
|
||||
|
@ -429,7 +431,13 @@ static int32_t mndProcessAlterUserReq(SNodeMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
if (mndCheckAlterUserAuth(pOperUser, pUser, &alterReq) != 0) {
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
memcpy(&newUser, pUser, sizeof(SUserObj));
|
||||
newUser.authVersion++;
|
||||
newUser.updateTime = taosGetTimestampMs();
|
||||
|
||||
taosRLockLatch(&pUser->lock);
|
||||
newUser.readDbs = mndDupDbHash(pUser->readDbs);
|
||||
|
@ -440,63 +448,90 @@ static int32_t mndProcessAlterUserReq(SNodeMsg *pReq) {
|
|||
goto _OVER;
|
||||
}
|
||||
|
||||
int32_t len = strlen(alterReq.dbname) + 1;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, alterReq.dbname);
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_PASSWD) {
|
||||
char pass[TSDB_PASSWORD_LEN + 1] = {0};
|
||||
taosEncryptPass_c((uint8_t *)alterReq.pass, strlen(alterReq.pass), pass);
|
||||
memcpy(newUser.pass, pass, TSDB_PASSWORD_LEN);
|
||||
} else if (alterReq.alterType == TSDB_ALTER_USER_SUPERUSER) {
|
||||
newUser.superUser = alterReq.superUser;
|
||||
} else if (alterReq.alterType == TSDB_ALTER_USER_ADD_READ_DB) {
|
||||
if (pDb == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosHashPut(newUser.readDbs, alterReq.dbname, len, alterReq.dbname, TSDB_DB_FNAME_LEN) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
newUser.authVersion++;
|
||||
} else if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_READ_DB) {
|
||||
if (taosHashRemove(newUser.readDbs, alterReq.dbname, len) != 0) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
goto _OVER;
|
||||
}
|
||||
newUser.authVersion++;
|
||||
} else if (alterReq.alterType == TSDB_ALTER_USER_CLEAR_READ_DB) {
|
||||
taosHashClear(newUser.readDbs);
|
||||
newUser.authVersion++;
|
||||
} else if (alterReq.alterType == TSDB_ALTER_USER_ADD_WRITE_DB) {
|
||||
if (pDb == NULL) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosHashPut(newUser.writeDbs, alterReq.dbname, len, alterReq.dbname, TSDB_DB_FNAME_LEN) != 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
}
|
||||
newUser.authVersion++;
|
||||
} else if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_WRITE_DB) {
|
||||
if (taosHashRemove(newUser.writeDbs, alterReq.dbname, len) != 0) {
|
||||
terrno = TSDB_CODE_MND_DB_NOT_EXIST;
|
||||
goto _OVER;
|
||||
}
|
||||
newUser.authVersion++;
|
||||
} else if (alterReq.alterType == TSDB_ALTER_USER_CLEAR_WRITE_DB) {
|
||||
taosHashClear(newUser.writeDbs);
|
||||
newUser.authVersion++;
|
||||
} else {
|
||||
terrno = TSDB_CODE_MND_INVALID_ALTER_OPER;
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
newUser.updateTime = taosGetTimestampMs();
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_SUPERUSER) {
|
||||
newUser.superUser = alterReq.superUser;
|
||||
}
|
||||
|
||||
if (mndCheckAlterUserAuth(pOperUser, pUser, pDb, &alterReq) != 0) {
|
||||
goto _OVER;
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_ADD_READ_DB || alterReq.alterType == TSDB_ALTER_USER_ADD_ALL_DB) {
|
||||
if (strcmp(alterReq.dbname, "1.*") != 0) {
|
||||
int32_t len = strlen(alterReq.dbname) + 1;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, alterReq.dbname);
|
||||
if (pDb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosHashPut(newUser.readDbs, alterReq.dbname, len, alterReq.dbname, TSDB_DB_FNAME_LEN) != 0) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
goto _OVER;
|
||||
}
|
||||
} else {
|
||||
while (1) {
|
||||
SDbObj *pDb = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_DB, pIter, (void **)&pDb);
|
||||
if (pIter == NULL) break;
|
||||
int32_t len = strlen(pDb->name) + 1;
|
||||
taosHashPut(newUser.readDbs, pDb->name, len, pDb->name, TSDB_DB_FNAME_LEN);
|
||||
sdbRelease(pSdb, pDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_ADD_WRITE_DB || alterReq.alterType == TSDB_ALTER_USER_ADD_ALL_DB) {
|
||||
if (strcmp(alterReq.dbname, "1.*") != 0) {
|
||||
int32_t len = strlen(alterReq.dbname) + 1;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, alterReq.dbname);
|
||||
if (pDb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
goto _OVER;
|
||||
}
|
||||
if (taosHashPut(newUser.writeDbs, alterReq.dbname, len, alterReq.dbname, TSDB_DB_FNAME_LEN) != 0) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
goto _OVER;
|
||||
}
|
||||
} else {
|
||||
while (1) {
|
||||
SDbObj *pDb = NULL;
|
||||
pIter = sdbFetch(pSdb, SDB_DB, pIter, (void **)&pDb);
|
||||
if (pIter == NULL) break;
|
||||
int32_t len = strlen(pDb->name) + 1;
|
||||
taosHashPut(newUser.writeDbs, pDb->name, len, pDb->name, TSDB_DB_FNAME_LEN);
|
||||
sdbRelease(pSdb, pDb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_READ_DB || alterReq.alterType == TSDB_ALTER_USER_REMOVE_ALL_DB) {
|
||||
if (strcmp(alterReq.dbname, "*") != 0) {
|
||||
int32_t len = strlen(alterReq.dbname) + 1;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, alterReq.dbname);
|
||||
if (pDb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
goto _OVER;
|
||||
}
|
||||
taosHashRemove(newUser.readDbs, alterReq.dbname, len);
|
||||
} else {
|
||||
taosHashClear(newUser.readDbs);
|
||||
}
|
||||
}
|
||||
|
||||
if (alterReq.alterType == TSDB_ALTER_USER_REMOVE_WRITE_DB || alterReq.alterType == TSDB_ALTER_USER_REMOVE_ALL_DB) {
|
||||
if (strcmp(alterReq.dbname, "*") != 0) {
|
||||
int32_t len = strlen(alterReq.dbname) + 1;
|
||||
SDbObj *pDb = mndAcquireDb(pMnode, alterReq.dbname);
|
||||
if (pDb == NULL) {
|
||||
mndReleaseDb(pMnode, pDb);
|
||||
goto _OVER;
|
||||
}
|
||||
taosHashRemove(newUser.writeDbs, alterReq.dbname, len);
|
||||
} else {
|
||||
taosHashClear(newUser.writeDbs);
|
||||
}
|
||||
}
|
||||
|
||||
code = mndAlterUser(pMnode, pUser, &newUser, pReq);
|
||||
|
|
|
@ -238,9 +238,10 @@ TEST_F(MndTestUser, 03_Alter_User) {
|
|||
|
||||
{
|
||||
SAlterUserReq alterReq = {0};
|
||||
alterReq.alterType = TSDB_ALTER_USER_CLEAR_WRITE_DB;
|
||||
alterReq.alterType = TSDB_ALTER_USER_REMOVE_ALL_DB;
|
||||
strcpy(alterReq.user, "u3");
|
||||
strcpy(alterReq.pass, "1");
|
||||
strcpy(alterReq.dbname, "*");
|
||||
|
||||
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
|
@ -253,9 +254,10 @@ TEST_F(MndTestUser, 03_Alter_User) {
|
|||
|
||||
{
|
||||
SAlterUserReq alterReq = {0};
|
||||
alterReq.alterType = TSDB_ALTER_USER_CLEAR_READ_DB;
|
||||
alterReq.alterType = TSDB_ALTER_USER_REMOVE_ALL_DB;
|
||||
strcpy(alterReq.user, "u3");
|
||||
strcpy(alterReq.pass, "1");
|
||||
strcpy(alterReq.dbname, "*");
|
||||
|
||||
int32_t contLen = tSerializeSAlterUserReq(NULL, 0, &alterReq);
|
||||
void* pReq = rpcMallocCont(contLen);
|
||||
|
@ -365,8 +367,8 @@ TEST_F(MndTestUser, 03_Alter_User) {
|
|||
EXPECT_EQ(numOfReadDbs, 1);
|
||||
EXPECT_EQ(numOfWriteDbs, 0);
|
||||
|
||||
char* dbname = (char*)taosHashGet(authRsp.readDbs, "1.d2", 5);
|
||||
EXPECT_STREQ(dbname, "1.d2");
|
||||
char* dbname = (char*)taosHashGet(authRsp.readDbs, "1.d2", 4);
|
||||
EXPECT_TRUE(dbname != NULL);
|
||||
|
||||
taosHashCleanup(authRsp.readDbs);
|
||||
taosHashCleanup(authRsp.writeDbs);
|
||||
|
|
|
@ -51,7 +51,7 @@ int32_t qndGetLoad(SQnode *pQnode, SQnodeLoad *pLoad) { return 0; }
|
|||
|
||||
int32_t qndProcessQueryMsg(SQnode *pQnode, SRpcMsg *pMsg) {
|
||||
qTrace("message in qnode query queue is processing");
|
||||
SReadHandle handle = {0};
|
||||
SReadHandle handle = {.pMsgCb = &pQnode->msgCb};
|
||||
|
||||
switch (pMsg->msgType) {
|
||||
case TDMT_VND_QUERY: {
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
#include "tlockfree.h"
|
||||
#include "tlosertree.h"
|
||||
#include "tmallocator.h"
|
||||
#include "tmsgcb.h"
|
||||
#include "tskiplist.h"
|
||||
#include "tstream.h"
|
||||
#include "ttime.h"
|
||||
|
@ -121,7 +122,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId);
|
|||
|
||||
// sma
|
||||
|
||||
int32_t tsdbRegisterRSma(STsdb* pTsdb, SMeta* pMeta, SVCreateStbReq* pReq);
|
||||
int32_t tsdbRegisterRSma(STsdb* pTsdb, SMeta* pMeta, SVCreateStbReq* pReq, SMsgCb* pMsgCb);
|
||||
int32_t tsdbFetchTbUidList(STsdb* pTsdb, STbUidStore** ppStore, tb_uid_t suid, tb_uid_t uid);
|
||||
int32_t tsdbUpdateTbUidList(STsdb* pTsdb, STbUidStore* pUidStore);
|
||||
void tsdbUidStoreDestory(STbUidStore* pStore);
|
||||
|
|
|
@ -233,17 +233,19 @@ int32_t tqPushMsgNew(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_
|
|||
int tqPushMsg(STQ* pTq, void* msg, int32_t msgLen, tmsg_t msgType, int64_t ver) {
|
||||
if (msgType != TDMT_VND_SUBMIT) return 0;
|
||||
|
||||
// make sure msgType == TDMT_VND_SUBMIT
|
||||
if (tsdbUpdateSmaWindow(pTq->pVnode->pTsdb, msg, ver) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (taosHashGetSize(pTq->pStreamTasks) == 0) return 0;
|
||||
|
||||
void* data = taosMemoryMalloc(msgLen);
|
||||
if (data == NULL) {
|
||||
return -1;
|
||||
}
|
||||
memcpy(data, msg, msgLen);
|
||||
|
||||
// make sure msgType == TDMT_VND_SUBMIT
|
||||
if (tsdbUpdateSmaWindow(pTq->pVnode->pTsdb, msg, ver) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SRpcMsg req = {
|
||||
.msgType = TDMT_VND_STREAM_TRIGGER,
|
||||
.pCont = data,
|
||||
|
@ -378,6 +380,7 @@ int32_t tqDeserializeConsumer(STQ* pTq, const STqSerializedHead* pHead, STqConsu
|
|||
SReadHandle handle = {
|
||||
.reader = pReadHandle,
|
||||
.meta = pTq->pVnode->pMeta,
|
||||
.pMsgCb = &pTq->pVnode->msgCb,
|
||||
};
|
||||
pTopic->buffer.output[j].pReadHandle = pReadHandle;
|
||||
pTopic->buffer.output[j].task = qCreateStreamExecTaskInfo(pTopic->qmsg, &handle);
|
||||
|
@ -857,6 +860,7 @@ int32_t tqProcessVgChangeReq(STQ* pTq, char* msg, int32_t msgLen) {
|
|||
SReadHandle handle = {
|
||||
.reader = pExec->pExecReader[i],
|
||||
.meta = pTq->pVnode->pMeta,
|
||||
.pMsgCb = &pTq->pVnode->msgCb,
|
||||
};
|
||||
pExec->task[i] = qCreateStreamExecTaskInfo(pExec->qmsg, &handle);
|
||||
ASSERT(pExec->task[i]);
|
||||
|
@ -914,6 +918,7 @@ int32_t tqExpandTask(STQ* pTq, SStreamTask* pTask, int32_t parallel) {
|
|||
SReadHandle handle = {
|
||||
.reader = pStreamReader,
|
||||
.meta = pTq->pVnode->pMeta,
|
||||
.pMsgCb = &pTq->pVnode->msgCb,
|
||||
};
|
||||
pTask->exec.runners[i].inputHandle = pStreamReader;
|
||||
pTask->exec.runners[i].executor = qCreateStreamExecTaskInfo(pTask->exec.qmsg, &handle);
|
||||
|
|
|
@ -211,7 +211,7 @@ int tsdbCommit(STsdb *pRepo) {
|
|||
|
||||
void tsdbGetRtnSnap(STsdb *pRepo, SRtn *pRtn) {
|
||||
STsdbKeepCfg *pCfg = REPO_KEEP_CFG(pRepo);
|
||||
TSKEY minKey, midKey, maxKey, now;
|
||||
TSKEY minKey, midKey, maxKey, now;
|
||||
|
||||
now = taosGetTimestamp(pCfg->precision);
|
||||
minKey = now - pCfg->keep2 * tsTickPerDay[pCfg->precision];
|
||||
|
@ -1386,34 +1386,7 @@ static void tsdbLoadAndMergeFromCache(SDataCols *pDataCols, int *iter, SCommitIt
|
|||
|
||||
tSkipListIterNext(pCommitIter->pIter);
|
||||
} else {
|
||||
#if 0
|
||||
if (update != TD_ROW_OVERWRITE_UPDATE) {
|
||||
// copy disk data
|
||||
for (int i = 0; i < pDataCols->numOfCols; ++i) {
|
||||
// TODO: dataColAppendVal may fail
|
||||
SCellVal sVal = {0};
|
||||
if (tdGetColDataOfRow(&sVal, pDataCols->cols + i, *iter, pDataCols->bitmapMode) < 0) {
|
||||
TASSERT(0);
|
||||
}
|
||||
tdAppendValToDataCol(pTarget->cols + i, sVal.valType, sVal.val, pTarget->numOfRows, pTarget->maxPoints, pTarget->bitmapMode);
|
||||
}
|
||||
|
||||
if (update == TD_ROW_DISCARD_UPDATE) pTarget->numOfRows++;
|
||||
}
|
||||
if (update != TD_ROW_DISCARD_UPDATE) {
|
||||
// copy mem data
|
||||
if (pSchema == NULL || schemaVersion(pSchema) != TD_ROW_SVER(row)) {
|
||||
pSchema = tsdbGetTableSchemaImpl(pCommitIter->pTable, false, false, TD_ROW_SVER(row));
|
||||
ASSERT(pSchema != NULL);
|
||||
}
|
||||
|
||||
tdAppendSTSRowToDataCol(row, pSchema, pTarget, update == TD_ROW_OVERWRITE_UPDATE);
|
||||
}
|
||||
++(*iter);
|
||||
tSkipListIterNext(pCommitIter->pIter);
|
||||
#endif
|
||||
|
||||
if(lastKey != key1) {
|
||||
if (lastKey != key1) {
|
||||
lastKey = key1;
|
||||
++pTarget->numOfRows;
|
||||
}
|
||||
|
@ -1484,29 +1457,4 @@ static bool tsdbCanAddSubBlock(SCommitH *pCommith, SBlock *pBlock, SMergeInfo *p
|
|||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// int tsdbApplyRtn(STsdbRepo *pRepo) {
|
||||
// SRtn rtn;
|
||||
// SFSIter fsiter;
|
||||
// STsdbFS * pfs = REPO_FS(pRepo);
|
||||
// SDFileSet *pSet;
|
||||
|
||||
// // Get retention snapshot
|
||||
// tsdbGetRtnSnap(pRepo, &rtn);
|
||||
|
||||
// tsdbFSIterInit(&fsiter, pfs, TSDB_FS_ITER_FORWARD);
|
||||
// while ((pSet = tsdbFSIterNext(&fsiter))) {
|
||||
// if (pSet->fid < rtn.minFid) {
|
||||
// tsdbInfo("vgId:%d FSET %d at level %d disk id %d expires, remove it", REPO_ID(pRepo), pSet->fid,
|
||||
// TSDB_FSET_LEVEL(pSet), TSDB_FSET_ID(pSet));
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// if (tsdbApplyRtnOnFSet(pRepo, pSet, &rtn) < 0) {
|
||||
// return -1;
|
||||
// }
|
||||
// }
|
||||
|
||||
// return 0;
|
||||
// }
|
||||
}
|
|
@ -248,11 +248,13 @@ int tsdbLoadDataFromCache(STable *pTable, SSkipListIterator *pIter, TSKEY maxKey
|
|||
pMergeInfo->nOperations++;
|
||||
pMergeInfo->keyFirst = TMIN(pMergeInfo->keyFirst, rowKey);
|
||||
pMergeInfo->keyLast = TMAX(pMergeInfo->keyLast, rowKey);
|
||||
lastKey = rowKey;
|
||||
if (pCols) {
|
||||
++pCols->numOfRows;
|
||||
if (lastKey != TSKEY_INITIAL_VAL) {
|
||||
++pCols->numOfRows;
|
||||
}
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row, false);
|
||||
}
|
||||
lastKey = rowKey;
|
||||
} else {
|
||||
tsdbAppendTableRowToCols(pTable, pCols, &pSchema, row, true);
|
||||
}
|
||||
|
@ -326,6 +328,11 @@ int tsdbInsertTableData(STsdb *pTsdb, SSubmitMsgIter *pMsgIter, SSubmitBlk *pBlo
|
|||
|
||||
tSkipListPutBatchByIter(pTbData->pData, &blkIter, (iter_next_fn_t)tGetSubmitBlkNext);
|
||||
|
||||
#ifdef TD_DEBUG_PRINT_ROW
|
||||
printf("!!! %s:%d table %" PRIi64 " has %d rows in skiplist\n\n", __func__, __LINE__, pTbData->uid,
|
||||
SL_SIZE(pTbData->pData));
|
||||
#endif
|
||||
|
||||
// Set statistics
|
||||
keyMax = TD_ROW_KEY(blkIter.row);
|
||||
|
||||
|
|
|
@ -21,16 +21,19 @@ typedef struct SMemSkipList SMemSkipList;
|
|||
typedef struct SMemSkipListNode SMemSkipListNode;
|
||||
typedef struct SMemSkipListCurosr SMemSkipListCurosr;
|
||||
|
||||
#define SL_MAX_LEVEL 5
|
||||
|
||||
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;
|
||||
STsdb *pTsdb;
|
||||
TSKEY minKey;
|
||||
TSKEY maxKey;
|
||||
int64_t minVer;
|
||||
int64_t maxVer;
|
||||
int64_t nRows;
|
||||
int32_t nHash;
|
||||
int32_t nBucket;
|
||||
SMemData **pBuckets;
|
||||
SMemSkipListCurosr *pSlc;
|
||||
};
|
||||
|
||||
struct SMemSkipListNode {
|
||||
|
@ -60,9 +63,15 @@ struct SMemData {
|
|||
|
||||
struct SMemSkipListCurosr {
|
||||
SMemSkipList *pSl;
|
||||
SMemSkipListNode *pNodeC;
|
||||
SMemSkipListNode *pNodes[SL_MAX_LEVEL];
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
int64_t version;
|
||||
uint32_t szRow;
|
||||
const STSRow *pRow;
|
||||
} STsdbRow;
|
||||
|
||||
#define HASH_BUCKET(SUID, UID, NBUCKET) (TABS((SUID) + (UID)) % (NBUCKET))
|
||||
|
||||
#define SL_NODE_SIZE(l) (sizeof(SMemSkipListNode) + sizeof(SMemSkipListNode *) * (l)*2)
|
||||
|
@ -76,7 +85,19 @@ struct SMemSkipListCurosr {
|
|||
#define SL_HEAD_NODE_FORWARD(n, l) SL_NODE_FORWARD(n, l)
|
||||
#define SL_TAIL_NODE_BACKWARD(n, l) SL_NODE_FORWARD(n, l)
|
||||
|
||||
static int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl);
|
||||
static int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl);
|
||||
static int32_t tsdbEncodeRow(SEncoder *pEncoder, const STsdbRow *pRow);
|
||||
static int32_t tsdbDecodeRow(SDecoder *pDecoder, STsdbRow *pRow);
|
||||
static int32_t tsdbMemSkipListCursorCreate(int8_t maxLevel, SMemSkipListCurosr **ppSlc);
|
||||
static void tsdbMemSkipListCursorDestroy(SMemSkipListCurosr *pSlc);
|
||||
static void tsdbMemSkipListCursorInit(SMemSkipListCurosr *pSlc, SMemSkipList *pSl);
|
||||
static void tsdbMemSkipListCursorPut(SMemSkipListCurosr *pSlc, SMemSkipListNode *pNode);
|
||||
static int32_t tsdbMemSkipListCursorMoveTo(SMemSkipListCurosr *pSlc, int64_t version, TSKEY ts, int32_t flags);
|
||||
static void tsdbMemSkipListCursorMoveToFirst(SMemSkipListCurosr *pSlc);
|
||||
static void tsdbMemSkipListCursorMoveToLast(SMemSkipListCurosr *pSlc);
|
||||
static int32_t tsdbMemSkipListCursorMoveToNext(SMemSkipListCurosr *pSlc);
|
||||
static int32_t tsdbMemSkipListCursorMoveToPrev(SMemSkipListCurosr *pSlc);
|
||||
static SMemSkipListNode *tsdbMemSkipListNodeCreate(SVBufPool *pPool, SMemSkipList *pSl, const STsdbRow *pTRow);
|
||||
|
||||
// SMemTable
|
||||
int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTb) {
|
||||
|
@ -102,6 +123,11 @@ int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTb) {
|
|||
taosMemoryFree(pMemTb);
|
||||
return -1;
|
||||
}
|
||||
if (tsdbMemSkipListCursorCreate(pTsdb->pVnode->config.tsdbCfg.slLevel, &pMemTb->pSlc) < 0) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
taosMemoryFree(pMemTb->pBuckets);
|
||||
taosMemoryFree(pMemTb);
|
||||
}
|
||||
|
||||
*ppMemTb = pMemTb;
|
||||
return 0;
|
||||
|
@ -110,6 +136,7 @@ int32_t tsdbMemTableCreate2(STsdb *pTsdb, SMemTable **ppMemTb) {
|
|||
int32_t tsdbMemTableDestroy2(STsdb *pTsdb, SMemTable *pMemTb) {
|
||||
if (pMemTb) {
|
||||
// loop to destroy the contents (todo)
|
||||
tsdbMemSkipListCursorDestroy(pMemTb->pSlc);
|
||||
taosMemoryFree(pMemTb->pBuckets);
|
||||
taosMemoryFree(pMemTb);
|
||||
}
|
||||
|
@ -177,52 +204,42 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p
|
|||
}
|
||||
|
||||
// do insert data to SMemData
|
||||
SMemSkipListCurosr slc = {0};
|
||||
const STSRow *pRow;
|
||||
uint32_t szRow;
|
||||
SDecoder decoder = {0};
|
||||
SMemSkipListNode *forwards[SL_MAX_LEVEL];
|
||||
SMemSkipListNode *pNode;
|
||||
int32_t iRow;
|
||||
STsdbRow tRow = {.version = version};
|
||||
SEncoder ec = {0};
|
||||
SDecoder dc = {0};
|
||||
|
||||
tDecoderInit(&decoder, pSubmitBlk->pData, pSubmitBlk->nData);
|
||||
for (;;) {
|
||||
if (tDecodeIsEnd(&decoder)) break;
|
||||
tDecoderInit(&dc, pSubmitBlk->pData, pSubmitBlk->nData);
|
||||
tsdbMemSkipListCursorInit(pMemTb->pSlc, &pMemData->sl);
|
||||
for (iRow = 0;; iRow++) {
|
||||
if (tDecodeIsEnd(&dc)) break;
|
||||
|
||||
if (tDecodeBinary(&decoder, (const uint8_t **)&pRow, &szRow) < 0) {
|
||||
// decode row
|
||||
if (tDecodeBinary(&dc, (const uint8_t **)&tRow.pRow, &tRow.szRow) < 0) {
|
||||
terrno = TSDB_CODE_INVALID_MSG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// check the row (todo)
|
||||
|
||||
// // move the cursor to position to write (todo)
|
||||
// int32_t c;
|
||||
// tsdbMemSkipListCursorMoveTo(&slc, pTSRow, version, &c);
|
||||
// ASSERT(c);
|
||||
// move cursor
|
||||
tsdbMemSkipListCursorMoveTo(pMemTb->pSlc, version, tRow.pRow->ts, 0);
|
||||
|
||||
// encode row
|
||||
int8_t level = tsdbMemSkipListRandLevel(&pMemData->sl);
|
||||
int32_t tsize = SL_NODE_SIZE(level) + sizeof(version) + (0 /*todo*/);
|
||||
SMemSkipListNode *pNode = vnodeBufPoolMalloc(pPool, tsize);
|
||||
pNode = tsdbMemSkipListNodeCreate(pPool, &pMemData->sl, &tRow);
|
||||
if (pNode == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pNode->level = level;
|
||||
|
||||
// uint8_t *pData = SL_NODE_DATA(pSlNode);
|
||||
// *(int64_t *)pData = version;
|
||||
// pData += sizeof(version);
|
||||
// memcpy(pData, pt, p - pt);
|
||||
|
||||
// // insert row
|
||||
// tsdbMemSkipListCursorPut(&slc, pSlNode);
|
||||
// put the node
|
||||
tsdbMemSkipListCursorPut(pMemTb->pSlc, pNode);
|
||||
|
||||
// update status
|
||||
if (pRow->ts < pMemData->minKey) pMemData->minKey = pRow->ts;
|
||||
if (pRow->ts > pMemData->maxKey) pMemData->maxKey = pRow->ts;
|
||||
if (tRow.pRow->ts < pMemData->minKey) pMemData->minKey = tRow.pRow->ts;
|
||||
if (tRow.pRow->ts > pMemData->maxKey) pMemData->maxKey = tRow.pRow->ts;
|
||||
}
|
||||
tDecoderClear(&decoder);
|
||||
// tsdbMemSkipListCursorClose(&slc);
|
||||
tDecoderClear(&dc);
|
||||
|
||||
// update status
|
||||
if (pMemData->minVer == -1) pMemData->minVer = version;
|
||||
|
@ -236,17 +253,128 @@ int32_t tsdbInsertData2(SMemTable *pMemTb, int64_t version, const SVSubmitBlk *p
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl) {
|
||||
static FORCE_INLINE int8_t tsdbMemSkipListRandLevel(SMemSkipList *pSl) {
|
||||
int8_t level = 1;
|
||||
int8_t tlevel;
|
||||
int8_t tlevel = TMIN(pSl->maxLevel, pSl->level + 1);
|
||||
const uint32_t factor = 4;
|
||||
|
||||
if (pSl->size) {
|
||||
tlevel = TMIN(pSl->maxLevel, pSl->level + 1);
|
||||
while ((taosRandR(&pSl->seed) % factor) == 0 && level < tlevel) {
|
||||
level++;
|
||||
}
|
||||
while ((taosRandR(&pSl->seed) % factor) == 0 && level < tlevel) {
|
||||
level++;
|
||||
}
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsdbEncodeRow(SEncoder *pEncoder, const STsdbRow *pRow) {
|
||||
if (tEncodeI64(pEncoder, pRow->version) < 0) return -1;
|
||||
if (tEncodeBinary(pEncoder, (const uint8_t *)pRow->pRow, pRow->szRow) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tsdbDecodeRow(SDecoder *pDecoder, STsdbRow *pRow) {
|
||||
if (tDecodeI64(pDecoder, &pRow->version) < 0) return -1;
|
||||
if (tDecodeBinary(pDecoder, (const uint8_t **)&pRow->pRow, &pRow->szRow) < 0) return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tsdbMemSkipListCursorCreate(int8_t maxLevel, SMemSkipListCurosr **ppSlc) {
|
||||
*ppSlc = (SMemSkipListCurosr *)taosMemoryCalloc(1, sizeof(**ppSlc) + sizeof(SMemSkipListNode *) * maxLevel);
|
||||
if (*ppSlc == NULL) {
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void tsdbMemSkipListCursorDestroy(SMemSkipListCurosr *pSlc) { taosMemoryFree(pSlc); }
|
||||
|
||||
static void tsdbMemSkipListCursorInit(SMemSkipListCurosr *pSlc, SMemSkipList *pSl) {
|
||||
SMemSkipListNode *pHead = SL_HEAD_NODE(pSl);
|
||||
pSlc->pSl = pSl;
|
||||
// for (int8_t iLevel = 0; iLevel < pSl->maxLevel; iLevel++) {
|
||||
// pSlc->forwards[iLevel] = pHead;
|
||||
// }
|
||||
}
|
||||
|
||||
static void tsdbMemSkipListCursorPut(SMemSkipListCurosr *pSlc, SMemSkipListNode *pNode) {
|
||||
SMemSkipList *pSl = pSlc->pSl;
|
||||
SMemSkipListNode *pNodeNext;
|
||||
|
||||
for (int8_t iLevel = 0; iLevel < pNode->level; iLevel++) {
|
||||
// todo
|
||||
|
||||
ASSERT(0);
|
||||
}
|
||||
|
||||
if (pSl->level < pNode->level) {
|
||||
pSl->level = pNode->level;
|
||||
}
|
||||
|
||||
pSl->size += 1;
|
||||
}
|
||||
|
||||
static int32_t tsdbMemSkipListCursorMoveTo(SMemSkipListCurosr *pSlc, int64_t version, TSKEY ts, int32_t flags) {
|
||||
SMemSkipListNode **pForwards = NULL;
|
||||
SMemSkipList *pSl = pSlc->pSl;
|
||||
int8_t maxLevel = pSl->maxLevel;
|
||||
SMemSkipListNode *pHead = SL_HEAD_NODE(pSl);
|
||||
SMemSkipListNode *pTail = SL_TAIL_NODE(pSl);
|
||||
|
||||
if (pSl->size == 0) {
|
||||
for (int8_t iLevel = 0; iLevel < pSl->maxLevel; iLevel++) {
|
||||
pForwards[iLevel] = pHead;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void tsdbMemSkipListCursorMoveToFirst(SMemSkipListCurosr *pSlc) {
|
||||
SMemSkipList *pSl = pSlc->pSl;
|
||||
SMemSkipListNode *pHead = SL_HEAD_NODE(pSl);
|
||||
|
||||
for (int8_t iLevel = 0; iLevel < pSl->maxLevel; iLevel++) {
|
||||
pSlc->pNodes[iLevel] = pHead;
|
||||
}
|
||||
|
||||
tsdbMemSkipListCursorMoveToNext(pSlc);
|
||||
}
|
||||
|
||||
static void tsdbMemSkipListCursorMoveToLast(SMemSkipListCurosr *pSlc) {
|
||||
SMemSkipList *pSl = pSlc->pSl;
|
||||
SMemSkipListNode *pTail = SL_TAIL_NODE(pSl);
|
||||
|
||||
for (int8_t iLevel = 0; iLevel < pSl->maxLevel; iLevel++) {
|
||||
pSlc->pNodes[iLevel] = pTail;
|
||||
}
|
||||
|
||||
tsdbMemSkipListCursorMoveToPrev(pSlc);
|
||||
}
|
||||
|
||||
static int32_t tsdbMemSkipListCursorMoveToNext(SMemSkipListCurosr *pSlc) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int32_t tsdbMemSkipListCursorMoveToPrev(SMemSkipListCurosr *pSlc) {
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
static SMemSkipListNode *tsdbMemSkipListNodeCreate(SVBufPool *pPool, SMemSkipList *pSl, const STsdbRow *pTRow) {
|
||||
int32_t tsize;
|
||||
int32_t ret;
|
||||
int8_t level = tsdbMemSkipListRandLevel(pSl);
|
||||
SMemSkipListNode *pNode = NULL;
|
||||
SEncoder ec = {0};
|
||||
|
||||
tEncodeSize(tsdbEncodeRow, pTRow, tsize, ret);
|
||||
pNode = vnodeBufPoolMalloc(pPool, tsize + SL_NODE_SIZE(level));
|
||||
if (pNode) {
|
||||
pNode->level = level;
|
||||
tEncoderInit(&ec, (uint8_t *)SL_NODE_DATA(pNode), tsize);
|
||||
tsdbEncodeRow(&ec, pTRow);
|
||||
tEncoderClear(&ec);
|
||||
}
|
||||
|
||||
return pNode;
|
||||
}
|
|
@ -351,35 +351,26 @@ static void setQueryTimewindow(STsdbReadHandle* pTsdbReadHandle, SQueryTableData
|
|||
pTsdbReadHandle->window.ekey, pTsdbReadHandle->idStr);
|
||||
}
|
||||
}
|
||||
#if 1
|
||||
int nQUERY = 0;
|
||||
#endif
|
||||
|
||||
static STsdb* getTsdbByRetentions(SVnode* pVnode, STsdbReadHandle* pReadHandle, TSKEY winSKey, SRetention* retentions) {
|
||||
if (vnodeIsRollup(pVnode)) {
|
||||
int level = 0;
|
||||
#if 0
|
||||
int level = 0;
|
||||
int64_t now = taosGetTimestamp(pVnode->config.tsdbCfg.precision);
|
||||
|
||||
for (int i = 0; i < TSDB_RETENTION_MAX; ++i) {
|
||||
SRetention* pRetention = retentions + i;
|
||||
if (pRetention->keep <= 0 || (now - pRetention->keep) >= winSKey) {
|
||||
SRetention* pRetention = retentions + level;
|
||||
if (pRetention->keep <= 0) {
|
||||
if (level > 0) {
|
||||
--level;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ((now - pRetention->keep) <= winSKey) {
|
||||
break;
|
||||
}
|
||||
++level;
|
||||
}
|
||||
#endif
|
||||
#if 1
|
||||
switch ((nQUERY++) % 3) {
|
||||
case 0:
|
||||
level = 0;
|
||||
break;
|
||||
case 1:
|
||||
level = 1;
|
||||
break;
|
||||
default:
|
||||
level = 2;
|
||||
break;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (level == TSDB_RETENTION_L0) {
|
||||
tsdbDebug("%p rsma level %d is selected to query\n", pReadHandle, level);
|
||||
return VND_RSMA0(pVnode);
|
||||
|
@ -391,7 +382,7 @@ static STsdb* getTsdbByRetentions(SVnode* pVnode, STsdbReadHandle* pReadHandle,
|
|||
return VND_RSMA2(pVnode);
|
||||
}
|
||||
}
|
||||
return pVnode->pTsdb;
|
||||
return VND_TSDB(pVnode);
|
||||
}
|
||||
|
||||
static STsdbReadHandle* tsdbQueryTablesImpl(SVnode* pVnode, SQueryTableDataCond* pCond, uint64_t qId, uint64_t taskId) {
|
||||
|
@ -879,14 +870,14 @@ static TSKEY extractFirstTraverseKey(STableCheckInfo* pCheckInfo, int32_t order,
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
static STSRow* getSRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int32_t update, STSRow** extraRow, TDRowVerT maxVer) {
|
||||
static STSRow* getSRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int32_t update, STSRow** extraRow,
|
||||
TDRowVerT maxVer) {
|
||||
STSRow *rmem = NULL, *rimem = NULL;
|
||||
if (pCheckInfo->iter) {
|
||||
SSkipListNode* node = tSkipListIterGet(pCheckInfo->iter);
|
||||
if (node != NULL) {
|
||||
rmem = (STSRow*)SL_GET_NODE_DATA(node);
|
||||
#if 0 // TODO: skiplist refactor
|
||||
#if 0 // TODO: skiplist refactor
|
||||
if (TD_ROW_VER(rmem) > maxVer) {
|
||||
rmem = NULL;
|
||||
}
|
||||
|
@ -898,7 +889,7 @@ static STSRow* getSRowInTableMem(STableCheckInfo* pCheckInfo, int32_t order, int
|
|||
SSkipListNode* node = tSkipListIterGet(pCheckInfo->iiter);
|
||||
if (node != NULL) {
|
||||
rimem = (STSRow*)SL_GET_NODE_DATA(node);
|
||||
#if 0 // TODO: skiplist refactor
|
||||
#if 0 // TODO: skiplist refactor
|
||||
if (TD_ROW_VER(rimem) > maxVer) {
|
||||
rimem = NULL;
|
||||
}
|
||||
|
@ -1677,7 +1668,7 @@ static int32_t mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capa
|
|||
colIdOfRow2 = tdKvRowColIdAt(row2, k);
|
||||
}
|
||||
|
||||
if (colIdOfRow1 < colIdOfRow2) { // the most probability
|
||||
if (colIdOfRow1 < colIdOfRow2) { // the most probability
|
||||
if (colIdOfRow1 < pColInfo->info.colId) {
|
||||
++j;
|
||||
continue;
|
||||
|
@ -1720,7 +1711,7 @@ static int32_t mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capa
|
|||
++(*curRow);
|
||||
}
|
||||
++nResult;
|
||||
} else if (update){
|
||||
} else if (update) {
|
||||
mergeOption = 2;
|
||||
} else {
|
||||
mergeOption = 0;
|
||||
|
@ -1741,7 +1732,7 @@ static int32_t mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capa
|
|||
++(*curRow);
|
||||
}
|
||||
++nResult;
|
||||
} else if(update) {
|
||||
} else if (update) {
|
||||
mergeOption = 2;
|
||||
} else {
|
||||
mergeOption = 0;
|
||||
|
@ -2018,9 +2009,9 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
rv2 = TD_ROW_SVER(row2);
|
||||
}
|
||||
|
||||
numOfRows += mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, row1, row2, numOfCols,
|
||||
pCheckInfo->tableId, pSchema1, pSchema2, pCfg->update, &lastKeyAppend);
|
||||
// numOfRows += 1;
|
||||
numOfRows +=
|
||||
mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, row1, row2, numOfCols,
|
||||
pCheckInfo->tableId, pSchema1, pSchema2, pCfg->update, &lastKeyAppend);
|
||||
if (cur->win.skey == TSKEY_INITIAL_VAL) {
|
||||
cur->win.skey = key;
|
||||
}
|
||||
|
@ -2028,7 +2019,6 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
cur->win.ekey = key;
|
||||
cur->lastKey = key + step;
|
||||
cur->mixBlock = true;
|
||||
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
} else if (key == tsArray[pos]) { // data in buffer has the same timestamp of data in file block, ignore it
|
||||
#if 0
|
||||
|
@ -2064,7 +2054,11 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
}
|
||||
#endif
|
||||
if (TD_SUPPORT_UPDATE(pCfg->update)) {
|
||||
doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, curRow, pos, pos);
|
||||
if (lastKeyAppend != key) {
|
||||
lastKeyAppend = key;
|
||||
++curRow;
|
||||
}
|
||||
numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, curRow, pos, pos);
|
||||
|
||||
if (rv1 != TD_ROW_SVER(row1)) {
|
||||
// pSchema1 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row1));
|
||||
|
@ -2074,10 +2068,10 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
// pSchema2 = tsdbGetTableSchemaByVersion(pTable, memRowVersion(row2));
|
||||
rv2 = TD_ROW_SVER(row2);
|
||||
}
|
||||
numOfRows +=
|
||||
mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, row1, row2, numOfCols,
|
||||
pCheckInfo->tableId, pSchema1, pSchema2, pCfg->update, &lastKeyAppend);
|
||||
|
||||
numOfRows += mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, row1, row2, numOfCols,
|
||||
pCheckInfo->tableId, pSchema1, pSchema2, pCfg->update, &lastKeyAppend);
|
||||
// ++numOfRows;
|
||||
if (cur->win.skey == TSKEY_INITIAL_VAL) {
|
||||
cur->win.skey = key;
|
||||
}
|
||||
|
@ -2117,15 +2111,20 @@ static void doMergeTwoLevelData(STsdbReadHandle* pTsdbReadHandle, STableCheckInf
|
|||
|
||||
int32_t qstart = 0, qend = 0;
|
||||
getQualifiedRowsPos(pTsdbReadHandle, pos, end, numOfRows, &qstart, &qend);
|
||||
lastKeyAppend = tsArray[qend];
|
||||
|
||||
numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, numOfRows, qstart, qend);
|
||||
if ((lastKeyAppend != TSKEY_INITIAL_VAL) &&
|
||||
(lastKeyAppend != (ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? tsArray[qstart] : tsArray[qend]))) {
|
||||
++curRow;
|
||||
}
|
||||
numOfRows = doCopyRowsFromFileBlock(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, curRow, qstart, qend);
|
||||
pos += (qend - qstart + 1) * step;
|
||||
if(numOfRows > 0) {
|
||||
if (numOfRows > 0) {
|
||||
curRow = numOfRows - 1;
|
||||
}
|
||||
|
||||
cur->win.ekey = ASCENDING_TRAVERSE(pTsdbReadHandle->order) ? tsArray[qend] : tsArray[qstart];
|
||||
cur->lastKey = cur->win.ekey + step;
|
||||
lastKeyAppend = cur->win.ekey;
|
||||
}
|
||||
} while (numOfRows < pTsdbReadHandle->outputCapacity);
|
||||
|
||||
|
@ -2429,7 +2428,7 @@ static int32_t getFirstFileDataBlock(STsdbReadHandle* pTsdbReadHandle, bool* exi
|
|||
int32_t numOfTables = (int32_t)taosArrayGetSize(pTsdbReadHandle->pTableCheckInfo);
|
||||
|
||||
STsdbKeepCfg* pCfg = REPO_KEEP_CFG(pTsdbReadHandle->pTsdb);
|
||||
STimeWindow win = TSWINDOW_INITIALIZER;
|
||||
STimeWindow win = TSWINDOW_INITIALIZER;
|
||||
|
||||
while (true) {
|
||||
tsdbRLockFS(REPO_FS(pTsdbReadHandle->pTsdb));
|
||||
|
@ -2735,7 +2734,6 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
|
|||
STSchema* pSchema = NULL;
|
||||
TSKEY lastRowKey = TSKEY_INITIAL_VAL;
|
||||
|
||||
|
||||
do {
|
||||
STSRow* row = getSRowInTableMem(pCheckInfo, pTsdbReadHandle->order, pCfg->update, NULL, TD_VER_MAX);
|
||||
if (row == NULL) {
|
||||
|
@ -2760,8 +2758,8 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
|
|||
pSchema = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), pCheckInfo->tableId, 0);
|
||||
rv = TD_ROW_SVER(row);
|
||||
}
|
||||
numOfRows += mergeTwoRowFromMem(pTsdbReadHandle, maxRowsToRead, &curRows, row, NULL, numOfCols, pCheckInfo->tableId, pSchema,
|
||||
NULL, pCfg->update, &lastRowKey);
|
||||
numOfRows += mergeTwoRowFromMem(pTsdbReadHandle, maxRowsToRead, &curRows, row, NULL, numOfCols, pCheckInfo->tableId,
|
||||
pSchema, NULL, pCfg->update, &lastRowKey);
|
||||
|
||||
if (numOfRows >= maxRowsToRead) {
|
||||
moveToNextRowInMem(pCheckInfo);
|
||||
|
@ -2770,7 +2768,7 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
|
|||
|
||||
} while (moveToNextRowInMem(pCheckInfo));
|
||||
|
||||
taosMemoryFreeClear(pSchema); // free the STSChema
|
||||
taosMemoryFreeClear(pSchema); // free the STSChema
|
||||
|
||||
assert(numOfRows <= maxRowsToRead);
|
||||
|
||||
|
@ -2898,8 +2896,8 @@ static bool loadCachedLastRow(STsdbReadHandle* pTsdbReadHandle) {
|
|||
// if (ret != TSDB_CODE_SUCCESS) {
|
||||
// return false;
|
||||
// }
|
||||
mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, pRow, NULL, numOfCols, pCheckInfo->tableId,
|
||||
NULL, NULL, true, &lastRowKey);
|
||||
mergeTwoRowFromMem(pTsdbReadHandle, pTsdbReadHandle->outputCapacity, &curRow, pRow, NULL, numOfCols,
|
||||
pCheckInfo->tableId, NULL, NULL, true, &lastRowKey);
|
||||
taosMemoryFreeClear(pRow);
|
||||
|
||||
// update the last key value
|
||||
|
@ -3468,7 +3466,7 @@ void tsdbRetrieveDataBlockInfo(tsdbReaderT* pTsdbReadHandle, SDataBlockInfo* pDa
|
|||
|
||||
pDataBlockInfo->rows = cur->rows;
|
||||
pDataBlockInfo->window = cur->win;
|
||||
// ASSERT(pDataBlockInfo->numOfCols >= (int32_t)(QH_GET_NUM_OF_COLS(pHandle));
|
||||
// ASSERT(pDataBlockInfo->numOfCols >= (int32_t)(QH_GET_NUM_OF_COLS(pHandle));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -3872,7 +3870,7 @@ int32_t tsdbQuerySTableByTagCond(void* pMeta, uint64_t uid, TSKEY skey, const ch
|
|||
|
||||
if (metaGetTableEntryByUid(&mr, uid) < 0) {
|
||||
tsdbError("%p failed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId);
|
||||
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
goto _error;
|
||||
} else {
|
||||
tsdbDebug("%p succeed to get stable, uid:%" PRIu64 ", TID:0x%" PRIx64 " QID:0x%" PRIx64, pMeta, uid, taskId, reqId);
|
||||
|
@ -3942,7 +3940,7 @@ int32_t tsdbGetOneTableGroup(void* pMeta, uint64_t uid, TSKEY startKey, STableGr
|
|||
metaReaderInit(&mr, (SMeta*)pMeta, 0);
|
||||
|
||||
if (metaGetTableEntryByUid(&mr, uid) < 0) {
|
||||
terrno = TSDB_CODE_TDB_INVALID_TABLE_ID;
|
||||
terrno = TSDB_CODE_PAR_TABLE_NOT_EXIST;
|
||||
goto _error;
|
||||
}
|
||||
|
||||
|
|
|
@ -1698,7 +1698,7 @@ int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) {
|
|||
* @param pReq
|
||||
* @return int32_t
|
||||
*/
|
||||
int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateStbReq *pReq) {
|
||||
int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateStbReq *pReq, SMsgCb *pMsgCb) {
|
||||
if (!pReq->rollup) {
|
||||
tsdbDebug("vgId:%d return directly since no rollup for stable %s %" PRIi64, REPO_ID(pTsdb), pReq->name, pReq->suid);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1742,6 +1742,7 @@ int32_t tsdbRegisterRSma(STsdb *pTsdb, SMeta *pMeta, SVCreateStbReq *pReq) {
|
|||
SReadHandle handle = {
|
||||
.reader = pReadHandle,
|
||||
.meta = pMeta,
|
||||
.pMsgCb = pMsgCb,
|
||||
};
|
||||
|
||||
if (param->qmsg1) {
|
||||
|
|
|
@ -142,9 +142,9 @@ _err:
|
|||
int vnodeProcessQueryMsg(SVnode *pVnode, SRpcMsg *pMsg) {
|
||||
vTrace("message in vnode query queue is processing");
|
||||
#if 0
|
||||
SReadHandle handle = {.reader = pVnode->pTsdb, .meta = pVnode->pMeta, .config = &pVnode->config, .vnode = pVnode};
|
||||
SReadHandle handle = {.reader = pVnode->pTsdb, .meta = pVnode->pMeta, .config = &pVnode->config, .vnode = pVnode, .pMsgCb = &pVnode->msgCb};
|
||||
#endif
|
||||
SReadHandle handle = {.meta = pVnode->pMeta, .config = &pVnode->config, .vnode = pVnode};
|
||||
SReadHandle handle = {.meta = pVnode->pMeta, .config = &pVnode->config, .vnode = pVnode, .pMsgCb = &pVnode->msgCb};
|
||||
switch (pMsg->msgType) {
|
||||
case TDMT_VND_QUERY:
|
||||
return qWorkerProcessQueryMsg(&handle, pVnode->pQuery, pMsg);
|
||||
|
@ -305,7 +305,7 @@ static int vnodeProcessCreateStbReq(SVnode *pVnode, int64_t version, void *pReq,
|
|||
goto _err;
|
||||
}
|
||||
|
||||
tsdbRegisterRSma(pVnode->pTsdb, pVnode->pMeta, &req);
|
||||
tsdbRegisterRSma(pVnode->pTsdb, pVnode->pMeta, &req, &pVnode->msgCb);
|
||||
|
||||
tDecoderClear(&coder);
|
||||
return 0;
|
||||
|
@ -497,6 +497,47 @@ _exit:
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int vnodeDebugPrintSubmitMsg(SVnode *pVnode, SSubmitReq *pMsg, const char* tags) {
|
||||
ASSERT(pMsg != NULL);
|
||||
SSubmitMsgIter msgIter = {0};
|
||||
SMeta *pMeta = pVnode->pMeta;
|
||||
SSubmitBlk *pBlock = NULL;
|
||||
SSubmitBlkIter blkIter = {0};
|
||||
STSRow *row = NULL;
|
||||
STSchema *pSchema = NULL;
|
||||
tb_uid_t suid = 0;
|
||||
|
||||
if (tInitSubmitMsgIter(pMsg, &msgIter) < 0) return -1;
|
||||
while (true) {
|
||||
if (tGetSubmitMsgNext(&msgIter, &pBlock) < 0) return -1;
|
||||
if (pBlock == NULL) break;
|
||||
tInitSubmitBlkIter(&msgIter, pBlock, &blkIter);
|
||||
if (blkIter.row == NULL) continue;
|
||||
if (!pSchema || (suid != msgIter.suid)) {
|
||||
if (pSchema) {
|
||||
taosMemoryFreeClear(pSchema);
|
||||
}
|
||||
pSchema = metaGetTbTSchema(pMeta, msgIter.suid, 0); // TODO: use the real schema
|
||||
if(pSchema) {
|
||||
suid = msgIter.suid;
|
||||
}
|
||||
}
|
||||
if(!pSchema) {
|
||||
printf("%s:%d no valid schema\n", tags, __LINE__);
|
||||
continue;
|
||||
}
|
||||
char __tags[128] = {0};
|
||||
snprintf(__tags, 128, "%s: uid %" PRIi64 " ", tags, msgIter.uid);
|
||||
while ((row = tGetSubmitBlkNext(&blkIter))) {
|
||||
tdSRowPrint(row, pSchema, __tags);
|
||||
}
|
||||
}
|
||||
|
||||
taosMemoryFreeClear(pSchema);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, int32_t len, SRpcMsg *pRsp) {
|
||||
SSubmitReq *pSubmitReq = (SSubmitReq *)pReq;
|
||||
SSubmitMsgIter msgIter = {0};
|
||||
|
@ -508,6 +549,10 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, in
|
|||
|
||||
pRsp->code = 0;
|
||||
|
||||
#ifdef TD_DEBUG_PRINT_ROW
|
||||
vnodeDebugPrintSubmitMsg(pVnode, pReq, __func__);
|
||||
#endif
|
||||
|
||||
// handle the request
|
||||
if (tInitSubmitMsgIter(pSubmitReq, &msgIter) < 0) {
|
||||
pRsp->code = TSDB_CODE_INVALID_MSG;
|
||||
|
@ -550,7 +595,8 @@ static int vnodeProcessSubmitReq(SVnode *pVnode, int64_t version, void *pReq, in
|
|||
goto _exit;
|
||||
}
|
||||
|
||||
rsp.numOfRows += nRows;
|
||||
rsp.affectedRows += nRows;
|
||||
|
||||
}
|
||||
|
||||
_exit:
|
||||
|
|
|
@ -36,7 +36,7 @@ extern "C" {
|
|||
|
||||
#define CTG_DEFAULT_INVALID_VERSION (-1)
|
||||
|
||||
#define CTG_ERR_CODE_TABLE_NOT_EXIST TSDB_CODE_TDB_INVALID_TABLE_ID
|
||||
#define CTG_ERR_CODE_TABLE_NOT_EXIST TSDB_CODE_PAR_TABLE_NOT_EXIST
|
||||
|
||||
enum {
|
||||
CTG_READ = 1,
|
||||
|
|
|
@ -392,10 +392,7 @@ typedef struct SStreamBlockScanInfo {
|
|||
} SStreamBlockScanInfo;
|
||||
|
||||
typedef struct SSysTableScanInfo {
|
||||
union {
|
||||
void* pTransporter;
|
||||
SReadHandle readHandle;
|
||||
};
|
||||
SReadHandle readHandle;
|
||||
|
||||
SRetrieveMetaTableRsp* pRsp;
|
||||
SRetrieveTableReq req;
|
||||
|
@ -663,8 +660,6 @@ SResultRow* doSetResultOutBufByKey(SDiskbasedBuf* pResultBuf, SResultRowInfo* pR
|
|||
char* pData, int16_t bytes, bool masterscan, uint64_t groupId,
|
||||
SExecTaskInfo* pTaskInfo, bool isIntervalQuery, SAggSupporter* pSup);
|
||||
|
||||
SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pDataReader, SQueryTableDataCond* pCond, int32_t numOfOutput, int32_t dataLoadFlag, const uint8_t* scanInfo,
|
||||
SArray* pColMatchInfo, SSDataBlock* pResBlock, SNode* pCondition, SInterval* pInterval, double sampleRatio, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <libs/function/function.h>
|
||||
#include "filter.h"
|
||||
#include "function.h"
|
||||
#include "functionMgt.h"
|
||||
|
@ -203,9 +204,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) { // todo disable it temporarily
|
||||
// continue;
|
||||
// }
|
||||
// if (!pDescNode->output) { // todo disable it temporarily
|
||||
// continue;
|
||||
// }
|
||||
|
||||
idata.info.type = pDescNode->dataType.type;
|
||||
idata.info.bytes = pDescNode->dataType.bytes;
|
||||
|
@ -803,7 +804,8 @@ static void doAggregateImpl(SOperatorInfo* pOperator, TSKEY startTs, SqlFunction
|
|||
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]);
|
||||
if (pCtx[k].fpSet.process != NULL)
|
||||
pCtx[k].fpSet.process(&pCtx[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -833,7 +835,8 @@ int32_t projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBloc
|
|||
if (pExpr[k].pExpr->nodeType == QUERY_NODE_COLUMN) { // it is a project query
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pResult->pDataBlock, outputSlotId);
|
||||
if (pResult->info.rows > 0 && !createNewColModel) {
|
||||
colDataMergeCol(pColInfoData, pResult->info.rows, &pResult->info.capacity, pfCtx->input.pData[0], pfCtx->input.numOfRows);
|
||||
colDataMergeCol(pColInfoData, pResult->info.rows, &pResult->info.capacity, pfCtx->input.pData[0],
|
||||
pfCtx->input.numOfRows);
|
||||
} else {
|
||||
colDataAssign(pColInfoData, pfCtx->input.pData[0], pfCtx->input.numOfRows);
|
||||
}
|
||||
|
@ -1074,35 +1077,36 @@ void setBlockStatisInfo(SqlFunctionCtx* pCtx, SExprInfo* pExprInfo, SSDataBlock*
|
|||
// set the output buffer for the selectivity + tag query
|
||||
static int32_t setCtxTagColumnInfo(SqlFunctionCtx* pCtx, int32_t numOfOutput) {
|
||||
int32_t num = 0;
|
||||
int16_t tagLen = 0;
|
||||
|
||||
SqlFunctionCtx* p = NULL;
|
||||
SqlFunctionCtx** pTagCtx = taosMemoryCalloc(numOfOutput, POINTER_BYTES);
|
||||
if (pTagCtx == NULL) {
|
||||
SqlFunctionCtx** pValCtx = taosMemoryCalloc(numOfOutput, POINTER_BYTES);
|
||||
if (pValCtx == NULL) {
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
for (int32_t i = 0; i < numOfOutput; ++i) {
|
||||
int32_t functionId = pCtx[i].functionId;
|
||||
|
||||
if (functionId == FUNCTION_TAG_DUMMY || functionId == FUNCTION_TS_DUMMY) {
|
||||
tagLen += pCtx[i].resDataInfo.bytes;
|
||||
pTagCtx[num++] = &pCtx[i];
|
||||
} else if (1 /*(aAggs[functionId].status & FUNCSTATE_SELECTIVITY) != 0*/) {
|
||||
p = &pCtx[i];
|
||||
} else if (functionId == FUNCTION_TS || functionId == FUNCTION_TAG) {
|
||||
// tag function may be the group by tag column
|
||||
// ts may be the required primary timestamp column
|
||||
continue;
|
||||
if (strcmp(pCtx[i].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
|
||||
pValCtx[num++] = &pCtx[i];
|
||||
} else {
|
||||
// the column may be the normal column, group by normal_column, the functionId is FUNCTION_PRJ
|
||||
p = &pCtx[i];
|
||||
}
|
||||
// if (functionId == FUNCTION_TAG_DUMMY || functionId == FUNCTION_TS_DUMMY) {
|
||||
// tagLen += pCtx[i].resDataInfo.bytes;
|
||||
// pTagCtx[num++] = &pCtx[i];
|
||||
// } else if (functionId == FUNCTION_TS || functionId == FUNCTION_TAG) {
|
||||
// // tag function may be the group by tag column
|
||||
// // ts may be the required primary timestamp column
|
||||
// continue;
|
||||
// } else {
|
||||
// // the column may be the normal column, group by normal_column, the functionId is FUNCTION_PRJ
|
||||
// }
|
||||
}
|
||||
|
||||
if (p != NULL) {
|
||||
p->subsidiaries.pCtx = pTagCtx;
|
||||
p->subsidiaries.pCtx = pValCtx;
|
||||
p->subsidiaries.num = num;
|
||||
} else {
|
||||
taosMemoryFreeClear(pTagCtx);
|
||||
taosMemoryFreeClear(pValCtx);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1873,7 +1877,7 @@ static void updateTableQueryInfoForReverseScan(STableQueryInfo* pTableQueryInfo)
|
|||
}
|
||||
|
||||
void initResultRow(SResultRow* pResultRow) {
|
||||
// pResultRow->pEntryInfo = (struct SResultRowEntryInfo*)((char*)pResultRow + sizeof(SResultRow));
|
||||
// pResultRow->pEntryInfo = (struct SResultRowEntryInfo*)((char*)pResultRow + sizeof(SResultRow));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1885,7 +1889,8 @@ void initResultRow(SResultRow* pResultRow) {
|
|||
* offset[0] offset[1] offset[2]
|
||||
*/
|
||||
// TODO refactor: some function move away
|
||||
void setFunctionResultOutput(SOptrBasicInfo* pInfo, SAggSupporter* pSup, int32_t stage, int32_t numOfExprs, SExecTaskInfo* pTaskInfo) {
|
||||
void setFunctionResultOutput(SOptrBasicInfo* pInfo, SAggSupporter* pSup, int32_t stage, int32_t numOfExprs,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
SqlFunctionCtx* pCtx = pInfo->pCtx;
|
||||
SSDataBlock* pDataBlock = pInfo->pRes;
|
||||
int32_t* rowCellInfoOffset = pInfo->rowCellInfoOffset;
|
||||
|
@ -2219,6 +2224,8 @@ int32_t doCopyToSDataBlock(SSDataBlock* pBlock, SExprInfo* pExprInfo, SDiskbased
|
|||
pCtx[j].resultInfo = getResultCell(pRow, j, rowCellOffset);
|
||||
if (pCtx[j].fpSet.process) {
|
||||
pCtx[j].fpSet.finalize(&pCtx[j], pBlock);
|
||||
} else if (strcmp(pCtx[j].pExpr->pExpr->_function.functionName, "_select_value") == 0) {
|
||||
// do nothing, todo refactor
|
||||
} else {
|
||||
SColumnInfoData* pColInfoData = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||
|
||||
|
@ -2240,12 +2247,13 @@ int32_t doCopyToSDataBlock(SSDataBlock* pBlock, SExprInfo* pExprInfo, SDiskbased
|
|||
return 0;
|
||||
}
|
||||
|
||||
void doBuildResultDatablock(SOptrBasicInfo *pbInfo, SGroupResInfo* pGroupResInfo, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf) {
|
||||
void doBuildResultDatablock(SOptrBasicInfo* pbInfo, SGroupResInfo* pGroupResInfo, SExprInfo* pExprInfo,
|
||||
SDiskbasedBuf* pBuf) {
|
||||
assert(pGroupResInfo->currentGroup <= pGroupResInfo->totalGroup);
|
||||
|
||||
int32_t* rowCellOffset = pbInfo->rowCellInfoOffset;
|
||||
SSDataBlock* pBlock = pbInfo->pRes;
|
||||
SqlFunctionCtx* pCtx = pbInfo->pCtx;
|
||||
int32_t* rowCellOffset = pbInfo->rowCellInfoOffset;
|
||||
SSDataBlock* pBlock = pbInfo->pRes;
|
||||
SqlFunctionCtx* pCtx = pbInfo->pCtx;
|
||||
|
||||
blockDataCleanup(pBlock);
|
||||
if (!hasRemainDataInCurrentGroup(pGroupResInfo)) {
|
||||
|
@ -2419,7 +2427,8 @@ void queryCostStatis(SExecTaskInfo* pTaskInfo) {
|
|||
|
||||
SFileBlockLoadRecorder* pRecorder = pSummary->pRecoder;
|
||||
if (pSummary->pRecoder != NULL) {
|
||||
qDebug("%s :cost summary: elapsed time:%" PRId64 " us, first merge:%" PRId64 " us, total blocks:%d, "
|
||||
qDebug("%s :cost summary: elapsed time:%" PRId64 " us, first merge:%" PRId64
|
||||
" us, total blocks:%d, "
|
||||
"load block statis:%d, load data block:%d, total rows:%" PRId64 ", check rows:%" PRId64,
|
||||
GET_TASKID(pTaskInfo), pSummary->elapsedTime, pSummary->firstStageMergeTime, pRecorder->totalBlocks,
|
||||
pRecorder->loadBlockStatis, pRecorder->loadBlocks, pRecorder->totalRows, pRecorder->totalCheckedRows);
|
||||
|
@ -2954,7 +2963,7 @@ int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadI
|
|||
relocateColumnData(pRes, pColList, pBlock->pDataBlock);
|
||||
taosArrayDestroy(pBlock->pDataBlock);
|
||||
taosMemoryFree(pBlock);
|
||||
// blockDataDestroy(pBlock);
|
||||
// blockDataDestroy(pBlock);
|
||||
}
|
||||
|
||||
pRes->info.rows = numOfRows;
|
||||
|
@ -3259,7 +3268,8 @@ static int32_t initDataSource(int32_t numOfSources, SExchangeInfo* pInfo) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo) {
|
||||
SOperatorInfo* createExchangeOperatorInfo(void *pTransporter, const SNodeList* pSources, SSDataBlock* pBlock,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
SExchangeInfo* pInfo = taosMemoryCalloc(1, sizeof(SExchangeInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
|
||||
|
@ -3302,29 +3312,7 @@ SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock
|
|||
|
||||
pOperator->fpSet = createOperatorFpSet(prepareLoadRemoteData, doLoadRemoteData, NULL, NULL,
|
||||
destroyExchangeOperatorInfo, NULL, NULL, NULL);
|
||||
|
||||
#if 1
|
||||
{ // todo refactor
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localPort = 0;
|
||||
rpcInit.label = "EX";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = qProcessFetchRsp;
|
||||
rpcInit.sessions = tsMaxConnections;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.user = (char*)"root";
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.ckey = "key";
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.secret = (char*)"dcc5bed04851fec854c035b2e40263b6";
|
||||
|
||||
pInfo->pTransporter = rpcOpen(&rpcInit);
|
||||
if (pInfo->pTransporter == NULL) {
|
||||
return NULL; // todo
|
||||
}
|
||||
}
|
||||
#endif
|
||||
pInfo->pTransporter = pTransporter;
|
||||
|
||||
return pOperator;
|
||||
|
||||
|
@ -3974,6 +3962,7 @@ static SSDataBlock* doProjectOperation(SOperatorInfo* pOperator) {
|
|||
SSDataBlock* pRes = pInfo->pRes;
|
||||
blockDataCleanup(pRes);
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
if (pOperator->status == OP_EXEC_DONE) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -4037,9 +4026,13 @@ 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->numOfExprs,
|
||||
pTaskInfo->code = projectApplyFunctions(pOperator->pExpr, pInfo->pRes, pBlock, pInfo->pCtx, pOperator->numOfExprs,
|
||||
pProjectInfo->pPseudoColInfo);
|
||||
|
||||
if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, pTaskInfo->code);
|
||||
}
|
||||
|
||||
int32_t status = handleLimitOffset(pOperator, pBlock);
|
||||
if (status == PROJECT_RETRIEVE_CONTINUE) {
|
||||
continue;
|
||||
|
@ -4099,8 +4092,8 @@ static SSDataBlock* doFill(SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
// todo handle different group data interpolation
|
||||
bool n = false;
|
||||
bool *newgroup = &n;
|
||||
bool n = false;
|
||||
bool* newgroup = &n;
|
||||
doHandleRemainBlockFromNewGroup(pInfo, pResultInfo, newgroup, pTaskInfo);
|
||||
if (pResBlock->info.rows > pResultInfo->threshold || (!pInfo->multigroupResult && pResBlock->info.rows > 0)) {
|
||||
return pResBlock;
|
||||
|
@ -4206,7 +4199,7 @@ static void destroyOperatorInfo(SOperatorInfo* pOperator) {
|
|||
}
|
||||
}
|
||||
|
||||
taosMemoryFree(pOperator->pExpr);
|
||||
taosMemoryFreeClear(pOperator->pExpr);
|
||||
taosMemoryFreeClear(pOperator->info);
|
||||
taosMemoryFreeClear(pOperator);
|
||||
}
|
||||
|
@ -4224,7 +4217,7 @@ int32_t doInitAggInfoSup(SAggSupporter* pAggSup, SqlFunctionCtx* pCtx, int32_t n
|
|||
}
|
||||
|
||||
uint32_t defaultPgsz = 4096;
|
||||
while(defaultPgsz < pAggSup->resultRowSize*4) {
|
||||
while (defaultPgsz < pAggSup->resultRowSize * 4) {
|
||||
defaultPgsz <<= 1u;
|
||||
}
|
||||
|
||||
|
@ -4375,7 +4368,7 @@ void destroyBasicOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
}
|
||||
|
||||
void destroyMergeJoinOperator(void* param, int32_t numOfOutput) {
|
||||
SJoinOperatorInfo* pJoinOperator = (SJoinOperatorInfo*) param;
|
||||
SJoinOperatorInfo* pJoinOperator = (SJoinOperatorInfo*)param;
|
||||
}
|
||||
|
||||
void destroyAggOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
|
@ -4391,6 +4384,9 @@ void destroySFillOperatorInfo(void* param, int32_t numOfOutput) {
|
|||
}
|
||||
|
||||
static void destroyProjectOperatorInfo(void* param, int32_t numOfOutput) {
|
||||
if (NULL == param) {
|
||||
return;
|
||||
}
|
||||
SProjectOperatorInfo* pInfo = (SProjectOperatorInfo*)param;
|
||||
doDestroyBasicInfo(&pInfo->binfo, numOfOutput);
|
||||
cleanupAggSup(&pInfo->aggSup);
|
||||
|
@ -4487,8 +4483,9 @@ static int32_t initFillInfo(SFillOperatorInfo* pInfo, SExprInfo* pExpr, int32_t
|
|||
}
|
||||
|
||||
SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols,
|
||||
SInterval* pInterval, STimeWindow* pWindow, SSDataBlock* pResBlock, int32_t fillType, SNodeListNode* pValueNode,
|
||||
bool multigroupResult, SExecTaskInfo* pTaskInfo) {
|
||||
SInterval* pInterval, STimeWindow* pWindow, SSDataBlock* pResBlock,
|
||||
int32_t fillType, SNodeListNode* pValueNode, bool multigroupResult,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
SFillOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SFillOperatorInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
|
||||
|
@ -4522,8 +4519,8 @@ SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExp
|
|||
SResultInfo* pResultInfo = &pOperator->resultInfo;
|
||||
initResultSizeInfo(pOperator, 4096);
|
||||
|
||||
int32_t code = initFillInfo(pInfo, pExpr, numOfCols, pValueNode, *pWindow, pResultInfo->capacity,
|
||||
pTaskInfo->id.str, pInterval, type);
|
||||
int32_t code = initFillInfo(pInfo, pExpr, numOfCols, pValueNode, *pWindow, pResultInfo->capacity, pTaskInfo->id.str,
|
||||
pInterval, type);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
}
|
||||
|
@ -4736,7 +4733,8 @@ static int32_t doCreateTableGroup(void* metaHandle, int32_t tableType, uint64_t
|
|||
uint64_t queryId, uint64_t taskId);
|
||||
static SArray* extractTableIdList(const STableGroupInfo* pTableGroupInfo);
|
||||
static SArray* extractColumnInfo(SNodeList* pNodeList);
|
||||
static SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols, int32_t type);
|
||||
static SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols,
|
||||
int32_t type);
|
||||
|
||||
static SArray* createSortInfo(SNodeList* pNodeList);
|
||||
static SArray* extractPartitionColInfo(SNodeList* pNodeList);
|
||||
|
@ -4776,33 +4774,34 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
SSDataBlock* pResBlock = createResDataBlock(pDescNode);
|
||||
|
||||
SQueryTableDataCond cond = {0};
|
||||
int32_t code = initQueryTableDataCond(&cond, pTableScanNode);
|
||||
int32_t code = initQueryTableDataCond(&cond, pTableScanNode);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
SInterval interval = extractIntervalInfo(pTableScanNode);
|
||||
SOperatorInfo* pOperator = createTableScanOperatorInfo(pDataReader, &cond, numOfCols, pTableScanNode->dataRequired,
|
||||
pTableScanNode->scanSeq, pColList, pResBlock, pScanPhyNode->node.pConditions,
|
||||
&interval, pTableScanNode->ratio, pTaskInfo);
|
||||
SInterval interval = extractIntervalInfo(pTableScanNode);
|
||||
SOperatorInfo* pOperator = createTableScanOperatorInfo(
|
||||
pDataReader, &cond, numOfCols, pTableScanNode->dataRequired, pTableScanNode->scanSeq, pColList, pResBlock,
|
||||
pScanPhyNode->node.pConditions, &interval, pTableScanNode->ratio, pTaskInfo);
|
||||
STableScanInfo* pScanInfo = pOperator->info;
|
||||
pTaskInfo->cost.pRecoder = &pScanInfo->readRecorder;
|
||||
return pOperator;
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_EXCHANGE == type) {
|
||||
SExchangePhysiNode* pExchange = (SExchangePhysiNode*)pPhyNode;
|
||||
SSDataBlock* pResBlock = createResDataBlock(pExchange->node.pOutputDataBlockDesc);
|
||||
return createExchangeOperatorInfo(pExchange->pSrcEndPoints, pResBlock, pTaskInfo);
|
||||
return createExchangeOperatorInfo(pHandle->pMsgCb->clientRpc, pExchange->pSrcEndPoints, pResBlock, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_STREAM_SCAN == type) {
|
||||
SScanPhysiNode* pScanPhyNode = (SScanPhysiNode*)pPhyNode; // simple child table.
|
||||
|
||||
int32_t code = doCreateTableGroup(pHandle->meta, pScanPhyNode->tableType, pScanPhyNode->uid, pTableGroupInfo, queryId, taskId);
|
||||
int32_t code = doCreateTableGroup(pHandle->meta, pScanPhyNode->tableType, pScanPhyNode->uid, pTableGroupInfo,
|
||||
queryId, taskId);
|
||||
SArray* tableIdList = extractTableIdList(pTableGroupInfo);
|
||||
|
||||
SDataBlockDescNode* pDescNode = pScanPhyNode->node.pOutputDataBlockDesc;
|
||||
SSDataBlock* pResBlock = createResDataBlock(pDescNode);
|
||||
SSDataBlock* pResBlock = createResDataBlock(pDescNode);
|
||||
|
||||
int32_t numOfCols = 0;
|
||||
SArray* pCols = extractColMatchInfo(pScanPhyNode->pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID);
|
||||
int32_t numOfCols = 0;
|
||||
SArray* pCols = extractColMatchInfo(pScanPhyNode->pScanCols, pDescNode, &numOfCols, COL_MATCH_FROM_COL_ID);
|
||||
SOperatorInfo* pOperator = createStreamScanOperatorInfo(pHandle->reader, pResBlock, pCols, tableIdList, pTaskInfo,
|
||||
pScanPhyNode->node.pConditions);
|
||||
taosArrayDestroy(tableIdList);
|
||||
|
@ -4822,25 +4821,27 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
pTaskInfo, pSysScanPhyNode->showRewrite, pSysScanPhyNode->accountId);
|
||||
return pOperator;
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_TAG_SCAN == type) {
|
||||
STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*) pPhyNode;
|
||||
STagScanPhysiNode* pScanPhyNode = (STagScanPhysiNode*)pPhyNode;
|
||||
|
||||
SDataBlockDescNode* pDescNode = pScanPhyNode->node.pOutputDataBlockDesc;
|
||||
|
||||
SSDataBlock* pResBlock = createResDataBlock(pDescNode);
|
||||
|
||||
int32_t code =
|
||||
doCreateTableGroup(pHandle->meta, pScanPhyNode->tableType, pScanPhyNode->uid, pTableGroupInfo, queryId, taskId);
|
||||
int32_t code = doCreateTableGroup(pHandle->meta, pScanPhyNode->tableType, pScanPhyNode->uid, pTableGroupInfo,
|
||||
queryId, taskId);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int32_t num = 0;
|
||||
int32_t num = 0;
|
||||
SExprInfo* pExprInfo = createExprInfo(pScanPhyNode->pScanPseudoCols, NULL, &num);
|
||||
|
||||
int32_t numOfOutputCols = 0;
|
||||
SArray* colList = extractColMatchInfo(pScanPhyNode->pScanPseudoCols, pDescNode, &numOfOutputCols, COL_MATCH_FROM_COL_ID);
|
||||
SArray* colList =
|
||||
extractColMatchInfo(pScanPhyNode->pScanPseudoCols, pDescNode, &numOfOutputCols, COL_MATCH_FROM_COL_ID);
|
||||
|
||||
SOperatorInfo* pOperator = createTagScanOperatorInfo(pHandle, pExprInfo, num, pResBlock, colList, pTableGroupInfo, pTaskInfo);
|
||||
SOperatorInfo* pOperator =
|
||||
createTagScanOperatorInfo(pHandle, pExprInfo, num, pResBlock, colList, pTableGroupInfo, pTaskInfo);
|
||||
return pOperator;
|
||||
} else {
|
||||
ASSERT(0);
|
||||
|
@ -4887,7 +4888,7 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
pOptr = createAggregateOperatorInfo(ops[0], pExprInfo, num, pResBlock, pScalarExprInfo, numOfScalarExpr,
|
||||
pTaskInfo, pTableGroupInfo);
|
||||
}
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_INTERVAL == type) {
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_INTERVAL == type || QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL == type) {
|
||||
SIntervalPhysiNode* pIntervalPhyNode = (SIntervalPhysiNode*)pPhyNode;
|
||||
|
||||
SExprInfo* pExprInfo = createExprInfo(pIntervalPhyNode->window.pFuncs, NULL, &num);
|
||||
|
@ -4925,13 +4926,15 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
} else if (QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW == type) {
|
||||
SSessionWinodwPhysiNode* pSessionNode = (SSessionWinodwPhysiNode*)pPhyNode;
|
||||
|
||||
STimeWindowAggSupp as = {.waterMark = pSessionNode->window.watermark, .calTrigger = pSessionNode->window.triggerType};
|
||||
STimeWindowAggSupp as = {.waterMark = pSessionNode->window.watermark,
|
||||
.calTrigger = pSessionNode->window.triggerType};
|
||||
|
||||
SExprInfo* pExprInfo = createExprInfo(pSessionNode->window.pFuncs, NULL, &num);
|
||||
SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
|
||||
int32_t tsSlotId = ((SColumnNode*)pSessionNode->window.pTspk)->slotId;
|
||||
|
||||
pOptr = createSessionAggOperatorInfo(ops[0], pExprInfo, num, pResBlock, pSessionNode->gap, tsSlotId, &as, pTaskInfo);
|
||||
pOptr =
|
||||
createSessionAggOperatorInfo(ops[0], pExprInfo, num, pResBlock, pSessionNode->gap, tsSlotId, &as, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_PARTITION == type) {
|
||||
SPartitionPhysiNode* pPartNode = (SPartitionPhysiNode*)pPhyNode;
|
||||
SArray* pColList = extractPartitionColInfo(pPartNode->pPartitionKeys);
|
||||
|
@ -4957,11 +4960,12 @@ SOperatorInfo* createOperatorTree(SPhysiNode* pPhyNode, SExecTaskInfo* pTaskInfo
|
|||
pOptr = createMergeJoinOperatorInfo(ops, size, pExprInfo, num, pResBlock, pJoinNode->pOnConditions, pTaskInfo);
|
||||
} else if (QUERY_NODE_PHYSICAL_PLAN_FILL == type) {
|
||||
SFillPhysiNode* pFillNode = (SFillPhysiNode*)pPhyNode;
|
||||
SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
|
||||
SExprInfo* pExprInfo = createExprInfo(pFillNode->pTargets, NULL, &num);
|
||||
SSDataBlock* pResBlock = createResDataBlock(pPhyNode->pOutputDataBlockDesc);
|
||||
SExprInfo* pExprInfo = createExprInfo(pFillNode->pTargets, NULL, &num);
|
||||
|
||||
SInterval* pInterval = &((SIntervalAggOperatorInfo*)ops[0]->info)->interval;
|
||||
pOptr = createFillOperatorInfo(ops[0], pExprInfo, num, pInterval, &pFillNode->timeRange, pResBlock, pFillNode->mode, (SNodeListNode*)pFillNode->pValues, false, pTaskInfo);
|
||||
pOptr = createFillOperatorInfo(ops[0], pExprInfo, num, pInterval, &pFillNode->timeRange, pResBlock, pFillNode->mode,
|
||||
(SNodeListNode*)pFillNode->pValues, false, pTaskInfo);
|
||||
} else {
|
||||
ASSERT(0);
|
||||
}
|
||||
|
@ -5101,7 +5105,8 @@ SArray* createSortInfo(SNodeList* pNodeList) {
|
|||
return pList;
|
||||
}
|
||||
|
||||
SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols, int32_t type) {
|
||||
SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNodeList, int32_t* numOfOutputCols,
|
||||
int32_t type) {
|
||||
size_t numOfCols = LIST_LENGTH(pNodeList);
|
||||
SArray* pList = taosArrayInit(numOfCols, sizeof(SColMatchInfo));
|
||||
if (pList == NULL) {
|
||||
|
@ -5114,10 +5119,10 @@ SArray* extractColMatchInfo(SNodeList* pNodeList, SDataBlockDescNode* pOutputNod
|
|||
SColumnNode* pColNode = (SColumnNode*)pNode->pExpr;
|
||||
|
||||
SColMatchInfo c = {0};
|
||||
c.output = true;
|
||||
c.colId = pColNode->colId;
|
||||
c.srcSlotId = pColNode->slotId;
|
||||
c.matchType = type;
|
||||
c.output = true;
|
||||
c.colId = pColNode->colId;
|
||||
c.srcSlotId = pColNode->slotId;
|
||||
c.matchType = type;
|
||||
c.targetSlotId = pNode->slotId;
|
||||
taosArrayPush(pList, &c);
|
||||
}
|
||||
|
@ -5527,8 +5532,8 @@ static SSDataBlock* doMergeJoin(struct SOperatorInfo* pOperator) {
|
|||
}
|
||||
|
||||
SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream, SExprInfo* pExprInfo,
|
||||
int32_t numOfCols, SSDataBlock* pResBlock, SNode* pOnCondition,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
int32_t numOfCols, SSDataBlock* pResBlock, SNode* pOnCondition,
|
||||
SExecTaskInfo* pTaskInfo) {
|
||||
SJoinOperatorInfo* pInfo = taosMemoryCalloc(1, sizeof(SJoinOperatorInfo));
|
||||
SOperatorInfo* pOperator = taosMemoryCalloc(1, sizeof(SOperatorInfo));
|
||||
if (pOperator == NULL || pInfo == NULL) {
|
||||
|
@ -5537,14 +5542,14 @@ SOperatorInfo* createMergeJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t
|
|||
|
||||
initResultSizeInfo(pOperator, 4096);
|
||||
|
||||
pInfo->pRes = pResBlock;
|
||||
pOperator->name = "MergeJoinOperator";
|
||||
pInfo->pRes = pResBlock;
|
||||
pOperator->name = "MergeJoinOperator";
|
||||
pOperator->operatorType = QUERY_NODE_PHYSICAL_PLAN_JOIN;
|
||||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->blocking = false;
|
||||
pOperator->status = OP_NOT_OPENED;
|
||||
pOperator->pExpr = pExprInfo;
|
||||
pOperator->numOfExprs = numOfCols;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->info = pInfo;
|
||||
pOperator->pTaskInfo = pTaskInfo;
|
||||
|
||||
SOperatorNode* pNode = (SOperatorNode*)pOnCondition;
|
||||
|
@ -5568,9 +5573,9 @@ _error:
|
|||
}
|
||||
|
||||
void setJoinColumnInfo(SColumnInfo* pColumn, const SColumnNode* pColumnNode) {
|
||||
pColumn->slotId = pColumnNode->slotId;
|
||||
pColumn->type = pColumnNode->node.resType.type;
|
||||
pColumn->bytes = pColumnNode->node.resType.bytes;
|
||||
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;
|
||||
pColumn->scale = pColumnNode->node.resType.scale;
|
||||
}
|
||||
|
|
|
@ -262,6 +262,8 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
SGroupbyOperatorInfo* pInfo = pOperator->info;
|
||||
SSDataBlock* pRes = pInfo->binfo.pRes;
|
||||
|
||||
|
@ -289,7 +291,10 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator) {
|
|||
|
||||
// there is an scalar expression that needs to be calculated right before apply the group aggregation.
|
||||
if (pInfo->pScalarExprInfo != NULL) {
|
||||
projectApplyFunctions(pInfo->pScalarExprInfo, pBlock, pBlock, pInfo->pScalarFuncCtx, pInfo->numOfScalarExpr, NULL);
|
||||
pTaskInfo->code = projectApplyFunctions(pInfo->pScalarExprInfo, pBlock, pBlock, pInfo->pScalarFuncCtx, pInfo->numOfScalarExpr, NULL);
|
||||
if (pTaskInfo->code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pTaskInfo->env, pTaskInfo->code);
|
||||
}
|
||||
}
|
||||
|
||||
// setTagValue(pOperator, pRuntimeEnv->current->pTable, pInfo->binfo.pCtx, pOperator->numOfExprs);
|
||||
|
|
|
@ -1057,7 +1057,8 @@ static SSDataBlock* doSysTableScan(SOperatorInfo* pOperator) {
|
|||
pMsgSendInfo->fp = loadSysTableCallback;
|
||||
|
||||
int64_t transporterId = 0;
|
||||
int32_t code = asyncSendMsgToServer(pInfo->pTransporter, &pInfo->epSet, &transporterId, pMsgSendInfo);
|
||||
int32_t code =
|
||||
asyncSendMsgToServer(pInfo->readHandle.pMsgCb->clientRpc, &pInfo->epSet, &transporterId, pMsgSendInfo);
|
||||
tsem_wait(&pInfo->ready);
|
||||
|
||||
if (pTaskInfo->code) {
|
||||
|
@ -1182,29 +1183,7 @@ SOperatorInfo* createSysTableScanOperatorInfo(void* readHandle, SSDataBlock* pRe
|
|||
} else {
|
||||
tsem_init(&pInfo->ready, 0, 0);
|
||||
pInfo->epSet = epset;
|
||||
|
||||
#if 1
|
||||
{ // todo refactor
|
||||
SRpcInit rpcInit;
|
||||
memset(&rpcInit, 0, sizeof(rpcInit));
|
||||
rpcInit.localPort = 0;
|
||||
rpcInit.label = "DB-META";
|
||||
rpcInit.numOfThreads = 1;
|
||||
rpcInit.cfp = qProcessFetchRsp;
|
||||
rpcInit.sessions = tsMaxConnections;
|
||||
rpcInit.connType = TAOS_CONN_CLIENT;
|
||||
rpcInit.user = (char*)"root";
|
||||
rpcInit.idleTime = tsShellActivityTimer * 1000;
|
||||
rpcInit.ckey = "key";
|
||||
rpcInit.spi = 1;
|
||||
rpcInit.secret = (char*)"dcc5bed04851fec854c035b2e40263b6";
|
||||
|
||||
pInfo->pTransporter = rpcOpen(&rpcInit);
|
||||
if (pInfo->pTransporter == NULL) {
|
||||
return NULL; // todo
|
||||
}
|
||||
}
|
||||
#endif
|
||||
pInfo->readHandle = *(SReadHandle*)readHandle;
|
||||
}
|
||||
|
||||
pOperator->name = "SysTableScanOperator";
|
||||
|
|
|
@ -114,7 +114,10 @@ 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);
|
||||
int32_t code = projectApplyFunctions(pOperator->pExpr, pBlock, pBlock, pSort->binfo.pCtx, pOperator->numOfExprs, NULL);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pOperator->pTaskInfo->env, code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,11 +37,11 @@ bool getSumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
|||
int32_t sumFunction(SqlFunctionCtx *pCtx);
|
||||
int32_t sumInvertFunction(SqlFunctionCtx *pCtx);
|
||||
|
||||
bool minFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
bool minmaxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
bool getMinmaxFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
int32_t minFunction(SqlFunctionCtx* pCtx);
|
||||
int32_t maxFunction(SqlFunctionCtx *pCtx);
|
||||
int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
||||
bool getAvgFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
bool avgFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
|
@ -76,6 +76,7 @@ int32_t lastFunction(SqlFunctionCtx *pCtx);
|
|||
|
||||
bool getTopBotFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv);
|
||||
int32_t topFunction(SqlFunctionCtx *pCtx);
|
||||
int32_t bottomFunction(SqlFunctionCtx *pCtx);
|
||||
int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock);
|
||||
|
||||
bool getSpreadFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
|
@ -92,6 +93,8 @@ bool getStateFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
|||
bool stateFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo);
|
||||
int32_t stateCountFunction(SqlFunctionCtx* pCtx);
|
||||
|
||||
bool getSelectivityFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -40,6 +40,7 @@ extern "C" {
|
|||
#define FUNC_MGT_MULTI_RES_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(11)
|
||||
#define FUNC_MGT_SCAN_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(12)
|
||||
#define FUNC_MGT_SELECT_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(13)
|
||||
#define FUNC_MGT_REPEAT_SCAN_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(14)
|
||||
|
||||
#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||
|
||||
|
|
|
@ -207,7 +207,8 @@ static int32_t translateTop(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
}
|
||||
|
||||
static int32_t translateBottom(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
// todo
|
||||
SDataType* pType = &((SExprNode*)nodesListGetNode(pFunc->pParameterList, 0))->resType;
|
||||
pFunc->node.resType = (SDataType){.bytes = pType->bytes, .type = pType->type};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -258,7 +259,7 @@ static int32_t translateHistogram(SFunctionNode* pFunc, char* pErrBuf, int32_t l
|
|||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType) { .bytes = 512, .type = TSDB_DATA_TYPE_BINARY };
|
||||
pFunc->node.resType = (SDataType){.bytes = 512, .type = TSDB_DATA_TYPE_BINARY};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -310,7 +311,8 @@ static int32_t translateDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
}
|
||||
|
||||
SExprNode* p1 = (SExprNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (!IS_NUMERIC_TYPE(p1->resType.type)) {
|
||||
if (!IS_SIGNED_NUMERIC_TYPE(p1->resType.type) && !IS_FLOAT_TYPE(p1->resType.type) &&
|
||||
TSDB_DATA_TYPE_BOOL != p1->resType.type) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
pFunc->node.resType = p1->resType;
|
||||
|
@ -546,9 +548,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.translateFunc = translateInOutNum,
|
||||
.dataRequiredFunc = statisDataRequired,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = minFunctionSetup,
|
||||
.initFunc = minmaxFunctionSetup,
|
||||
.processFunc = minFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
.finalizeFunc = minmaxFunctionFinalize
|
||||
},
|
||||
{
|
||||
.name = "max",
|
||||
|
@ -557,9 +559,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.translateFunc = translateInOutNum,
|
||||
.dataRequiredFunc = statisDataRequired,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.initFunc = minmaxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
.finalizeFunc = minmaxFunctionFinalize
|
||||
},
|
||||
{
|
||||
.name = "stddev",
|
||||
|
@ -597,7 +599,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "percentile",
|
||||
.type = FUNCTION_TYPE_PERCENTILE,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_REPEAT_SCAN_FUNC,
|
||||
.translateFunc = translatePercentile,
|
||||
.getEnvFunc = getPercentileFuncEnv,
|
||||
.initFunc = percentileFunctionSetup,
|
||||
|
@ -610,14 +612,14 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.translateFunc = translateApercentile,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.initFunc = minmaxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
{
|
||||
.name = "top",
|
||||
.type = FUNCTION_TYPE_TOP,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC,
|
||||
.translateFunc = translateTop,
|
||||
.getEnvFunc = getTopBotFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
|
@ -627,12 +629,12 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "bottom",
|
||||
.type = FUNCTION_TYPE_BOTTOM,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC,
|
||||
.translateFunc = translateBottom,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
.getEnvFunc = getTopBotFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
.processFunc = bottomFunction,
|
||||
.finalizeFunc = topBotFinalize
|
||||
},
|
||||
{
|
||||
.name = "spread",
|
||||
|
@ -651,7 +653,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC,
|
||||
.translateFunc = translateLastRow,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.initFunc = minmaxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
.finalizeFunc = functionFinalize
|
||||
},
|
||||
|
@ -1090,8 +1092,8 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.type = FUNCTION_TYPE_SELECT_VALUE,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SELECT_FUNC,
|
||||
.translateFunc = translateSelectValue,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.getEnvFunc = getSelectivityFuncEnv, // todo remove this function later.
|
||||
.initFunc = functionSetup,
|
||||
.sprocessFunc = NULL,
|
||||
.finalizeFunc = NULL
|
||||
}
|
||||
|
|
|
@ -37,13 +37,15 @@ typedef struct SAvgRes {
|
|||
int64_t count;
|
||||
} SAvgRes;
|
||||
|
||||
typedef struct STuplePos {
|
||||
int32_t pageId;
|
||||
int32_t offset;
|
||||
} STuplePos;
|
||||
|
||||
typedef struct STopBotResItem {
|
||||
SVariant v;
|
||||
uint64_t uid; // it is a table uid, used to extract tag data during building of the final result for the tag data
|
||||
struct {
|
||||
int32_t pageId;
|
||||
int32_t offset;
|
||||
} tuplePos; // tuple data of this chosen row
|
||||
SVariant v;
|
||||
uint64_t uid; // it is a table uid, used to extract tag data during building of the final result for the tag data
|
||||
STuplePos tuplePos; // tuple data of this chosen row
|
||||
} STopBotResItem;
|
||||
|
||||
typedef struct STopBotRes {
|
||||
|
@ -637,101 +639,25 @@ EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWin
|
|||
return FUNC_DATA_REQUIRED_STATIS_LOAD;
|
||||
}
|
||||
|
||||
bool maxFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) {
|
||||
if (!functionSetup(pCtx, pResultInfo)) {
|
||||
return false;
|
||||
}
|
||||
typedef struct SMinmaxResInfo {
|
||||
bool assign; // assign the first value or not
|
||||
int64_t v;
|
||||
STuplePos tuplePos;
|
||||
} SMinmaxResInfo;
|
||||
|
||||
char* buf = GET_ROWCELL_INTERBUF(pResultInfo);
|
||||
switch (pCtx->resDataInfo.type) {
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
*((int32_t*)buf) = INT32_MIN;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
*((uint32_t*)buf) = 0;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
*((float*)buf) = -FLT_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
SET_DOUBLE_VAL(((double*)buf), -DBL_MAX);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
*((int64_t*)buf) = INT64_MIN;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
*((uint64_t*)buf) = 0;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
*((int16_t*)buf) = INT16_MIN;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
*((uint16_t*)buf) = 0;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
*((int8_t*)buf) = INT8_MIN;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
*((uint8_t*)buf) = 0;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
*((int8_t*)buf) = 0;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool minFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) {
|
||||
bool minmaxFunctionSetup(SqlFunctionCtx* pCtx, SResultRowEntryInfo* pResultInfo) {
|
||||
if (!functionSetup(pCtx, pResultInfo)) {
|
||||
return false; // not initialized since it has been initialized
|
||||
}
|
||||
|
||||
char* buf = GET_ROWCELL_INTERBUF(pResultInfo);
|
||||
switch (pCtx->resDataInfo.type) {
|
||||
case TSDB_DATA_TYPE_TINYINT:
|
||||
*((int8_t*)buf) = INT8_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UTINYINT:
|
||||
*(uint8_t*)buf = UINT8_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_SMALLINT:
|
||||
*((int16_t*)buf) = INT16_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_USMALLINT:
|
||||
*((uint16_t*)buf) = UINT16_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
*((int32_t*)buf) = INT32_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UINT:
|
||||
*((uint32_t*)buf) = UINT32_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BIGINT:
|
||||
*((int64_t*)buf) = INT64_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_UBIGINT:
|
||||
*((uint64_t*)buf) = UINT64_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
*((float*)buf) = FLT_MAX;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_DOUBLE:
|
||||
SET_DOUBLE_VAL(((double*)buf), DBL_MAX);
|
||||
break;
|
||||
case TSDB_DATA_TYPE_BOOL:
|
||||
*((int8_t*)buf) = 1;
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
|
||||
SMinmaxResInfo* buf = GET_ROWCELL_INTERBUF(pResultInfo);
|
||||
buf->assign = false;
|
||||
buf->tuplePos.pageId = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool getMinmaxFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||
pEnv->calcMemSize = sizeof(int64_t);
|
||||
pEnv->calcMemSize = sizeof(SMinmaxResInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -779,6 +705,9 @@ bool getMinmaxFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
static void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos);
|
||||
static void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos);
|
||||
|
||||
int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
||||
int32_t numOfElems = 0;
|
||||
|
||||
|
@ -789,13 +718,12 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
|||
int32_t type = pCol->info.type;
|
||||
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
char* buf = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
SMinmaxResInfo *pBuf = GET_ROWCELL_INTERBUF(pResInfo);
|
||||
|
||||
// data in current data block are qualified to the query
|
||||
if (pInput->colDataAggIsSet) {
|
||||
numOfElems = pInput->numOfRows - pAgg->numOfNull;
|
||||
ASSERT(pInput->numOfRows == pInput->totalRows && numOfElems >= 0);
|
||||
|
||||
if (numOfElems == 0) {
|
||||
return numOfElems;
|
||||
}
|
||||
|
@ -814,48 +742,82 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
|||
// the index is the original position, not the relative position
|
||||
TSKEY key = (pCtx->ptsList != NULL) ? pCtx->ptsList[index] : TSKEY_INITIAL_VAL;
|
||||
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type)) {
|
||||
int64_t prev = 0;
|
||||
GET_TYPED_DATA(prev, int64_t, type, buf);
|
||||
if (!pBuf->assign) {
|
||||
pBuf->v = *(int64_t*)tval;
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
} else {
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type)) {
|
||||
int64_t prev = 0;
|
||||
GET_TYPED_DATA(prev, int64_t, type, &pBuf->v);
|
||||
|
||||
int64_t val = GET_INT64_VAL(tval);
|
||||
if ((prev < val) ^ isMinFunc) {
|
||||
*(int64_t*)buf = val;
|
||||
for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) {
|
||||
SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i];
|
||||
if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
|
||||
__ctx->tag.i = key;
|
||||
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT;
|
||||
int64_t val = GET_INT64_VAL(tval);
|
||||
if ((prev < val) ^ isMinFunc) {
|
||||
pBuf->v = val;
|
||||
// for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) {
|
||||
// SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i];
|
||||
// if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
|
||||
// __ctx->tag.i = key;
|
||||
// __ctx->tag.nType = TSDB_DATA_TYPE_BIGINT;
|
||||
// }
|
||||
//
|
||||
// __ctx->fpSet.process(__ctx);
|
||||
// }
|
||||
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
}
|
||||
|
||||
__ctx->fpSet.process(__ctx);
|
||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
|
||||
uint64_t prev = 0;
|
||||
GET_TYPED_DATA(prev, uint64_t, type, &pBuf->v);
|
||||
|
||||
uint64_t val = GET_UINT64_VAL(tval);
|
||||
if ((prev < val) ^ isMinFunc) {
|
||||
pBuf->v = val;
|
||||
// for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) {
|
||||
// SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i];
|
||||
// if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
|
||||
// __ctx->tag.i = key;
|
||||
// __ctx->tag.nType = TSDB_DATA_TYPE_BIGINT;
|
||||
// }
|
||||
//
|
||||
// __ctx->fpSet.process(__ctx);
|
||||
// }
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
|
||||
double prev = 0;
|
||||
GET_TYPED_DATA(prev, int64_t, type, &pBuf->v);
|
||||
|
||||
double val = GET_DOUBLE_VAL(tval);
|
||||
if ((prev < val) ^ isMinFunc) {
|
||||
pBuf->v = val;
|
||||
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_FLOAT) {
|
||||
double prev = 0;
|
||||
GET_TYPED_DATA(prev, int64_t, type, &pBuf->v);
|
||||
|
||||
double val = GET_DOUBLE_VAL(tval);
|
||||
if ((prev < val) ^ isMinFunc) {
|
||||
pBuf->v = val;
|
||||
}
|
||||
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, index, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
}
|
||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
|
||||
uint64_t prev = 0;
|
||||
GET_TYPED_DATA(prev, uint64_t, type, buf);
|
||||
|
||||
uint64_t val = GET_UINT64_VAL(tval);
|
||||
if ((prev < val) ^ isMinFunc) {
|
||||
*(uint64_t*)buf = val;
|
||||
for (int32_t i = 0; i < (pCtx)->subsidiaries.num; ++i) {
|
||||
SqlFunctionCtx* __ctx = pCtx->subsidiaries.pCtx[i];
|
||||
if (__ctx->functionId == FUNCTION_TS_DUMMY) { // TODO refactor
|
||||
__ctx->tag.i = key;
|
||||
__ctx->tag.nType = TSDB_DATA_TYPE_BIGINT;
|
||||
}
|
||||
|
||||
__ctx->fpSet.process(__ctx);
|
||||
}
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
|
||||
double val = GET_DOUBLE_VAL(tval);
|
||||
UPDATE_DATA(pCtx, *(double*)buf, val, numOfElems, isMinFunc, key);
|
||||
} else if (type == TSDB_DATA_TYPE_FLOAT) {
|
||||
double val = GET_DOUBLE_VAL(tval);
|
||||
UPDATE_DATA(pCtx, *(float*)buf, val, numOfElems, isMinFunc, key);
|
||||
}
|
||||
|
||||
pBuf->assign = true;
|
||||
return numOfElems;
|
||||
}
|
||||
|
||||
|
@ -864,47 +826,318 @@ int32_t doMinMaxHelper(SqlFunctionCtx* pCtx, int32_t isMinFunc) {
|
|||
|
||||
if (IS_SIGNED_NUMERIC_TYPE(type) || type == TSDB_DATA_TYPE_BOOL) {
|
||||
if (type == TSDB_DATA_TYPE_TINYINT || type == TSDB_DATA_TYPE_BOOL) {
|
||||
LOOPCHECK_N(*(int8_t*)buf, pCol, pCtx, int8_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
} else if (type == TSDB_DATA_TYPE_SMALLINT) {
|
||||
LOOPCHECK_N(*(int16_t*)buf, pCol, pCtx, int16_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
} else if (type == TSDB_DATA_TYPE_INT) {
|
||||
int32_t* pData = (int32_t*)pCol->pData;
|
||||
int32_t* val = (int32_t*)buf;
|
||||
int8_t* pData = (int8_t*)pCol->pData;
|
||||
int8_t* val = (int8_t*)&pBuf->v;
|
||||
|
||||
for (int32_t i = start; i < start + numOfRows; ++i) {
|
||||
if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*val < pData[i]) ^ isMinFunc) {
|
||||
if (!pBuf->assign) {
|
||||
*val = pData[i];
|
||||
TSKEY ts = (pCtx->ptsList != NULL) ? GET_TS_DATA(pCtx, i) : 0;
|
||||
DO_UPDATE_SUBSID_RES(pCtx, ts);
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
pBuf->assign = true;
|
||||
} else {
|
||||
// ignore the equivalent data value
|
||||
if ((*val) == pData[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*val < pData[i]) ^ isMinFunc) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
copyTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
numOfElems += 1;
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_SMALLINT) {
|
||||
int16_t* pData = (int16_t*)pCol->pData;
|
||||
int16_t* val = (int16_t*)&pBuf->v;
|
||||
|
||||
#if defined(_DEBUG_VIEW)
|
||||
qDebug("max value updated:%d", *retVal);
|
||||
#endif
|
||||
for (int32_t i = start; i < start + numOfRows; ++i) {
|
||||
if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!pBuf->assign) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
pBuf->assign = true;
|
||||
} else {
|
||||
// ignore the equivalent data value
|
||||
if ((*val) == pData[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*val < pData[i]) ^ isMinFunc) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
copyTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
numOfElems += 1;
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_INT) {
|
||||
int32_t* pData = (int32_t*)pCol->pData;
|
||||
int32_t* val = (int32_t*)&pBuf->v;
|
||||
|
||||
for (int32_t i = start; i < start + numOfRows; ++i) {
|
||||
if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!pBuf->assign) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
pBuf->assign = true;
|
||||
} else {
|
||||
// ignore the equivalent data value
|
||||
if ((*val) == pData[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*val < pData[i]) ^ isMinFunc) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
copyTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
numOfElems += 1;
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_BIGINT) {
|
||||
LOOPCHECK_N(*(int64_t*)buf, pCol, pCtx, int64_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
int64_t* pData = (int64_t*)pCol->pData;
|
||||
int64_t* val = (int64_t*)&pBuf->v;
|
||||
|
||||
for (int32_t i = start; i < start + numOfRows; ++i) {
|
||||
if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!pBuf->assign) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
pBuf->assign = true;
|
||||
} else {
|
||||
// ignore the equivalent data value
|
||||
if ((*val) == pData[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*val < pData[i]) ^ isMinFunc) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
copyTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
numOfElems += 1;
|
||||
}
|
||||
}
|
||||
} else if (IS_UNSIGNED_NUMERIC_TYPE(type)) {
|
||||
if (type == TSDB_DATA_TYPE_UTINYINT) {
|
||||
LOOPCHECK_N(*(uint8_t*)buf, pCol, pCtx, uint8_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
uint8_t* pData = (uint8_t*)pCol->pData;
|
||||
uint8_t* val = (uint8_t*)&pBuf->v;
|
||||
|
||||
for (int32_t i = start; i < start + numOfRows; ++i) {
|
||||
if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!pBuf->assign) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
pBuf->assign = true;
|
||||
} else {
|
||||
// ignore the equivalent data value
|
||||
if ((*val) == pData[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*val < pData[i]) ^ isMinFunc) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
copyTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
numOfElems += 1;
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_USMALLINT) {
|
||||
LOOPCHECK_N(*(uint16_t*)buf, pCol, pCtx, uint16_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
uint16_t* pData = (uint16_t*)pCol->pData;
|
||||
uint16_t* val = (uint16_t*)&pBuf->v;
|
||||
|
||||
for (int32_t i = start; i < start + numOfRows; ++i) {
|
||||
if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!pBuf->assign) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
pBuf->assign = true;
|
||||
} else {
|
||||
// ignore the equivalent data value
|
||||
if ((*val) == pData[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*val < pData[i]) ^ isMinFunc) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
copyTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
numOfElems += 1;
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_UINT) {
|
||||
LOOPCHECK_N(*(uint32_t*)buf, pCol, pCtx, uint32_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
uint32_t* pData = (uint32_t*)pCol->pData;
|
||||
uint32_t* val = (uint32_t*)&pBuf->v;
|
||||
|
||||
for (int32_t i = start; i < start + numOfRows; ++i) {
|
||||
if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!pBuf->assign) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
pBuf->assign = true;
|
||||
} else {
|
||||
// ignore the equivalent data value
|
||||
if ((*val) == pData[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*val < pData[i]) ^ isMinFunc) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
copyTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
numOfElems += 1;
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_UBIGINT) {
|
||||
LOOPCHECK_N(*(uint64_t*)buf, pCol, pCtx, uint64_t, numOfRows, start, isMinFunc, numOfElems);
|
||||
uint64_t* pData = (uint64_t*)pCol->pData;
|
||||
uint64_t* val = (uint64_t*)&pBuf->v;
|
||||
|
||||
for (int32_t i = start; i < start + numOfRows; ++i) {
|
||||
if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!pBuf->assign) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
pBuf->assign = true;
|
||||
} else {
|
||||
// ignore the equivalent data value
|
||||
if ((*val) == pData[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*val < pData[i]) ^ isMinFunc) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
copyTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
numOfElems += 1;
|
||||
}
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_DOUBLE) {
|
||||
LOOPCHECK_N(*(double*)buf, pCol, pCtx, double, numOfRows, start, isMinFunc, numOfElems);
|
||||
double* pData = (double*)pCol->pData;
|
||||
double* val = (double*)&pBuf->v;
|
||||
|
||||
for (int32_t i = start; i < start + numOfRows; ++i) {
|
||||
if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!pBuf->assign) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
pBuf->assign = true;
|
||||
} else {
|
||||
// ignore the equivalent data value
|
||||
if ((*val) == pData[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*val < pData[i]) ^ isMinFunc) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
copyTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
numOfElems += 1;
|
||||
}
|
||||
} else if (type == TSDB_DATA_TYPE_FLOAT) {
|
||||
LOOPCHECK_N(*(float*)buf, pCol, pCtx, float, numOfRows, start, isMinFunc, numOfElems);
|
||||
float* pData = (float*)pCol->pData;
|
||||
double* val = (double*)&pBuf->v;
|
||||
|
||||
for (int32_t i = start; i < start + numOfRows; ++i) {
|
||||
if ((pCol->hasNull) && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!pBuf->assign) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
saveTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
pBuf->assign = true;
|
||||
} else {
|
||||
// ignore the equivalent data value
|
||||
if ((*val) == pData[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((*val < pData[i]) ^ isMinFunc) {
|
||||
*val = pData[i];
|
||||
if (pCtx->subsidiaries.num > 0) {
|
||||
copyTupleData(pCtx, i, pCtx->pSrcBlock, &pBuf->tuplePos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
numOfElems += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return numOfElems;
|
||||
|
@ -922,6 +1155,65 @@ int32_t maxFunction(SqlFunctionCtx* pCtx) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static void setSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, const STuplePos *pTuplePos, int32_t rowIndex);
|
||||
|
||||
int32_t minmaxFunctionFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||
SResultRowEntryInfo* pEntryInfo = GET_RES_INFO(pCtx);
|
||||
|
||||
SMinmaxResInfo* pRes = GET_ROWCELL_INTERBUF(pEntryInfo);
|
||||
|
||||
int32_t type = pCtx->input.pData[0]->info.type;
|
||||
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
||||
|
||||
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||
|
||||
// todo assign the tag value
|
||||
int32_t currentRow = pBlock->info.rows;
|
||||
|
||||
if (pCol->info.type == TSDB_DATA_TYPE_FLOAT) {
|
||||
float v = *(double*) &pRes->v;
|
||||
colDataAppend(pCol, currentRow, (const char*)&v, false);
|
||||
} else {
|
||||
colDataAppend(pCol, currentRow, (const char*)&pRes->v, false);
|
||||
}
|
||||
|
||||
setSelectivityValue(pCtx, pBlock, &pRes->tuplePos, currentRow);
|
||||
return pEntryInfo->numOfRes;
|
||||
}
|
||||
|
||||
void setSelectivityValue(SqlFunctionCtx* pCtx, SSDataBlock* pBlock, const STuplePos *pTuplePos, int32_t rowIndex) {
|
||||
int32_t pageId = pTuplePos->pageId;
|
||||
int32_t offset = pTuplePos->offset;
|
||||
if (pTuplePos->pageId != -1) {
|
||||
SFilePage* pPage = getBufPage(pCtx->pBuf, pageId);
|
||||
|
||||
bool* nullList = (bool*)((char*)pPage + offset);
|
||||
char* pStart = (char*)(nullList + pCtx->pSrcBlock->info.numOfCols * sizeof(bool));
|
||||
|
||||
// todo set the offset value to optimize the performance.
|
||||
for (int32_t j = 0; j < pCtx->subsidiaries.num; ++j) {
|
||||
SqlFunctionCtx* pc = pCtx->subsidiaries.pCtx[j];
|
||||
|
||||
SFunctParam* pFuncParam = &pc->pExpr->base.pParam[0];
|
||||
int32_t srcSlotId = pFuncParam->pCol->slotId;
|
||||
int32_t dstSlotId = pc->pExpr->base.resSchema.slotId;
|
||||
|
||||
int32_t ps = 0;
|
||||
for (int32_t k = 0; k < srcSlotId; ++k) {
|
||||
SColumnInfoData* pSrcCol = taosArrayGet(pCtx->pSrcBlock->pDataBlock, k);
|
||||
ps += pSrcCol->info.bytes;
|
||||
}
|
||||
|
||||
SColumnInfoData* pDstCol = taosArrayGet(pBlock->pDataBlock, dstSlotId);
|
||||
if (nullList[srcSlotId]) {
|
||||
colDataAppendNULL(pDstCol, rowIndex);
|
||||
} else {
|
||||
colDataAppend(pDstCol, rowIndex, (pStart + ps), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool getStddevFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||
pEnv->calcMemSize = sizeof(SStddevRes);
|
||||
return true;
|
||||
|
@ -1440,6 +1732,14 @@ bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool getSelectivityFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||
SColumnNode* pNode = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
pEnv->calcMemSize = pNode->node.resType.bytes;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static FORCE_INLINE TSKEY getRowPTs(SColumnInfoData* pTsColInfo, int32_t rowIndex) {
|
||||
if (pTsColInfo == NULL) {
|
||||
return 0;
|
||||
|
@ -1818,35 +2118,49 @@ static STopBotRes* getTopBotOutputInfo(SqlFunctionCtx* pCtx) {
|
|||
}
|
||||
|
||||
static void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSDataBlock* pSrcBlock, uint16_t type,
|
||||
uint64_t uid, SResultRowEntryInfo* pEntryInfo);
|
||||
|
||||
static void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STopBotResItem* pItem);
|
||||
static void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STopBotResItem* pItem);
|
||||
uint64_t uid, SResultRowEntryInfo* pEntryInfo, bool isTopQuery);
|
||||
|
||||
int32_t topFunction(SqlFunctionCtx* pCtx) {
|
||||
int32_t numOfElems = 0;
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
|
||||
// if ((void *)pRes->res[0] != (void *)((char *)pRes + sizeof(STopBotRes) + POINTER_BYTES * pCtx->param[0].i)) {
|
||||
// buildTopBotStruct(pRes, pCtx);
|
||||
// }
|
||||
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
SColumnInfoData* pCol = pInput->pData[0];
|
||||
|
||||
int32_t type = pInput->pData[0]->info.type;
|
||||
|
||||
int32_t start = pInput->startRowIndex;
|
||||
int32_t numOfRows = pInput->numOfRows;
|
||||
|
||||
for (int32_t i = start; i < numOfRows + start; ++i) {
|
||||
for (int32_t i = start; i < pInput->numOfRows + start; ++i) {
|
||||
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
numOfElems++;
|
||||
|
||||
numOfElems++;
|
||||
char* data = colDataGetData(pCol, i);
|
||||
doAddIntoResult(pCtx, data, i, pCtx->pSrcBlock, type, pInput->uid, pResInfo);
|
||||
doAddIntoResult(pCtx, data, i, pCtx->pSrcBlock, type, pInput->uid, pResInfo, true);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t bottomFunction(SqlFunctionCtx* pCtx) {
|
||||
int32_t numOfElems = 0;
|
||||
SResultRowEntryInfo* pResInfo = GET_RES_INFO(pCtx);
|
||||
|
||||
SInputColumnInfoData* pInput = &pCtx->input;
|
||||
SColumnInfoData* pCol = pInput->pData[0];
|
||||
|
||||
int32_t type = pInput->pData[0]->info.type;
|
||||
|
||||
int32_t start = pInput->startRowIndex;
|
||||
for (int32_t i = start; i < pInput->numOfRows + start; ++i) {
|
||||
if (pCol->hasNull && colDataIsNull_f(pCol->nullbitmap, i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
numOfElems++;
|
||||
char* data = colDataGetData(pCol, i);
|
||||
doAddIntoResult(pCtx, data, i, pCtx->pSrcBlock, type, pInput->uid, pResInfo, false);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1880,7 +2194,7 @@ static int32_t topBotResComparFn(const void* p1, const void* p2, const void* par
|
|||
}
|
||||
|
||||
void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSDataBlock* pSrcBlock, uint16_t type,
|
||||
uint64_t uid, SResultRowEntryInfo* pEntryInfo) {
|
||||
uint64_t uid, SResultRowEntryInfo* pEntryInfo, bool isTopQuery) {
|
||||
STopBotRes* pRes = getTopBotOutputInfo(pCtx);
|
||||
int32_t maxSize = pCtx->param[1].param.i;
|
||||
|
||||
|
@ -1897,30 +2211,36 @@ void doAddIntoResult(SqlFunctionCtx* pCtx, void* pData, int32_t rowIndex, SSData
|
|||
pItem->uid = uid;
|
||||
|
||||
// save the data of this tuple
|
||||
saveTupleData(pCtx, rowIndex, pSrcBlock, pItem);
|
||||
saveTupleData(pCtx, rowIndex, pSrcBlock, &pItem->tuplePos);
|
||||
|
||||
// allocate the buffer and keep the data of this row into the new allocated buffer
|
||||
pEntryInfo->numOfRes++;
|
||||
taosheapsort((void*)pItems, sizeof(STopBotResItem), pEntryInfo->numOfRes, (const void*)&type, topBotResComparFn,
|
||||
false);
|
||||
!isTopQuery);
|
||||
} else { // replace the minimum value in the result
|
||||
if ((IS_SIGNED_NUMERIC_TYPE(type) && val.i > pItems[0].v.i) ||
|
||||
(IS_UNSIGNED_NUMERIC_TYPE(type) && val.u > pItems[0].v.u) || (IS_FLOAT_TYPE(type) && val.d > pItems[0].v.d)) {
|
||||
if ((isTopQuery && (
|
||||
(IS_SIGNED_NUMERIC_TYPE(type) && val.i > pItems[0].v.i) ||
|
||||
(IS_UNSIGNED_NUMERIC_TYPE(type) && val.u > pItems[0].v.u) ||
|
||||
(IS_FLOAT_TYPE(type) && val.d > pItems[0].v.d)))
|
||||
|| (!isTopQuery && (
|
||||
(IS_SIGNED_NUMERIC_TYPE(type) && val.i < pItems[0].v.i) ||
|
||||
(IS_UNSIGNED_NUMERIC_TYPE(type) && val.u < pItems[0].v.u) ||
|
||||
(IS_FLOAT_TYPE(type) && val.d < pItems[0].v.d))
|
||||
)) {
|
||||
// replace the old data and the coresponding tuple data
|
||||
STopBotResItem* pItem = &pItems[0];
|
||||
pItem->v = val;
|
||||
pItem->uid = uid;
|
||||
|
||||
// save the data of this tuple by over writing the old data
|
||||
copyTupleData(pCtx, rowIndex, pSrcBlock, pItem);
|
||||
|
||||
copyTupleData(pCtx, rowIndex, pSrcBlock, &pItem->tuplePos);
|
||||
taosheapadjust((void*)pItems, sizeof(STopBotResItem), 0, pEntryInfo->numOfRes - 1, (const void*)&type,
|
||||
topBotResComparFn, NULL, false);
|
||||
topBotResComparFn, NULL, !isTopQuery);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STopBotResItem* pItem) {
|
||||
void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos) {
|
||||
SFilePage* pPage = NULL;
|
||||
|
||||
int32_t completeRowSize = pSrcBlock->info.rowSize + pSrcBlock->info.numOfCols * sizeof(bool);
|
||||
|
@ -1936,7 +2256,7 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
|
|||
}
|
||||
}
|
||||
|
||||
pItem->tuplePos.pageId = pCtx->curBufPage;
|
||||
pPos->pageId = pCtx->curBufPage;
|
||||
|
||||
// keep the current row data, extract method
|
||||
int32_t offset = 0;
|
||||
|
@ -1947,6 +2267,7 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
|
|||
bool isNull = colDataIsNull_s(pCol, rowIndex);
|
||||
if (isNull) {
|
||||
nullList[i] = true;
|
||||
offset += pCol->info.bytes;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -1960,17 +2281,17 @@ void saveTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pS
|
|||
offset += pCol->info.bytes;
|
||||
}
|
||||
|
||||
pItem->tuplePos.offset = pPage->num;
|
||||
pPos->offset = pPage->num;
|
||||
pPage->num += completeRowSize;
|
||||
|
||||
setBufPageDirty(pPage, true);
|
||||
releaseBufPage(pCtx->pBuf, pPage);
|
||||
}
|
||||
|
||||
void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STopBotResItem* pItem) {
|
||||
SFilePage* pPage = getBufPage(pCtx->pBuf, pItem->tuplePos.pageId);
|
||||
void copyTupleData(SqlFunctionCtx* pCtx, int32_t rowIndex, const SSDataBlock* pSrcBlock, STuplePos* pPos) {
|
||||
SFilePage* pPage = getBufPage(pCtx->pBuf, pPos->pageId);
|
||||
|
||||
bool* nullList = (bool*)((char*)pPage + pItem->tuplePos.offset);
|
||||
bool* nullList = (bool*)((char*)pPage + pPos->offset);
|
||||
char* pStart = (char*)(nullList + pSrcBlock->info.numOfCols * sizeof(bool));
|
||||
|
||||
int32_t offset = 0;
|
||||
|
@ -1999,54 +2320,24 @@ int32_t topBotFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
|||
STopBotRes* pRes = GET_ROWCELL_INTERBUF(pEntryInfo);
|
||||
pEntryInfo->complete = true;
|
||||
|
||||
int32_t type = pCtx->input.pData[0]->info.type;
|
||||
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
||||
int32_t type = pCtx->input.pData[0]->info.type;
|
||||
int32_t slotId = pCtx->pExpr->base.resSchema.slotId;
|
||||
|
||||
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||
|
||||
// todo assign the tag value and the corresponding row data
|
||||
int32_t currentRow = pBlock->info.rows;
|
||||
switch (type) {
|
||||
case TSDB_DATA_TYPE_INT: {
|
||||
for (int32_t i = 0; i < pEntryInfo->numOfRes; ++i) {
|
||||
STopBotResItem* pItem = &pRes->pItems[i];
|
||||
colDataAppendInt32(pCol, currentRow, (int32_t*)&pItem->v.i);
|
||||
|
||||
int32_t pageId = pItem->tuplePos.pageId;
|
||||
int32_t offset = pItem->tuplePos.offset;
|
||||
if (pItem->tuplePos.pageId != -1) {
|
||||
SFilePage* pPage = getBufPage(pCtx->pBuf, pageId);
|
||||
|
||||
bool* nullList = (bool*)((char*)pPage + offset);
|
||||
char* pStart = (char*)(nullList + pCtx->pSrcBlock->info.numOfCols * sizeof(bool));
|
||||
|
||||
// todo set the offset value to optimize the performance.
|
||||
for (int32_t j = 0; j < pCtx->subsidiaries.num; ++j) {
|
||||
SqlFunctionCtx* pc = pCtx->subsidiaries.pCtx[j];
|
||||
|
||||
SFunctParam* pFuncParam = &pc->pExpr->base.pParam[0];
|
||||
int32_t srcSlotId = pFuncParam->pCol->slotId;
|
||||
int32_t dstSlotId = pCtx->pExpr->base.resSchema.slotId;
|
||||
|
||||
int32_t ps = 0;
|
||||
for (int32_t k = 0; k < srcSlotId; ++k) {
|
||||
SColumnInfoData* pSrcCol = taosArrayGet(pCtx->pSrcBlock->pDataBlock, k);
|
||||
ps += pSrcCol->info.bytes;
|
||||
}
|
||||
|
||||
SColumnInfoData* pDstCol = taosArrayGet(pBlock->pDataBlock, dstSlotId);
|
||||
if (nullList[srcSlotId]) {
|
||||
colDataAppendNULL(pDstCol, currentRow);
|
||||
} else {
|
||||
colDataAppend(pDstCol, currentRow, (pStart + ps), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentRow += 1;
|
||||
}
|
||||
|
||||
break;
|
||||
for (int32_t i = 0; i < pEntryInfo->numOfRes; ++i) {
|
||||
STopBotResItem* pItem = &pRes->pItems[i];
|
||||
if (type == TSDB_DATA_TYPE_FLOAT) {
|
||||
float v = pItem->v.d;
|
||||
colDataAppend(pCol, currentRow, (const char*)&v, false);
|
||||
} else {
|
||||
colDataAppend(pCol, currentRow, (const char*)&pItem->v.i, false);
|
||||
}
|
||||
|
||||
setSelectivityValue(pCtx, pBlock, &pRes->pItems[i].tuplePos, currentRow);
|
||||
currentRow += 1;
|
||||
}
|
||||
|
||||
return pEntryInfo->numOfRes;
|
||||
|
|
|
@ -169,6 +169,8 @@ bool fmIsDynamicScanOptimizedFunc(int32_t funcId) {
|
|||
|
||||
bool fmIsMultiResFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_MULTI_RES_FUNC); }
|
||||
|
||||
bool fmIsRepeatScanFunc(int32_t funcId) { return isSpecificClassifyFunc(funcId, FUNC_MGT_REPEAT_SCAN_FUNC); }
|
||||
|
||||
bool fmIsUserDefinedFunc(int32_t funcId) { return funcId > FUNC_UDF_ID_START; }
|
||||
|
||||
void fmFuncMgtDestroy() {
|
||||
|
@ -197,15 +199,14 @@ int32_t fmSetNormalFunc(int32_t funcId, SFuncExecFuncs* pFpSet) {
|
|||
bool fmIsInvertible(int32_t funcId) {
|
||||
bool res = false;
|
||||
switch (funcMgtBuiltins[funcId].type) {
|
||||
case FUNCTION_TYPE_COUNT:
|
||||
case FUNCTION_TYPE_SUM:
|
||||
case FUNCTION_TYPE_STDDEV:
|
||||
case FUNCTION_TYPE_AVG:
|
||||
res = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case FUNCTION_TYPE_COUNT:
|
||||
case FUNCTION_TYPE_SUM:
|
||||
case FUNCTION_TYPE_STDDEV:
|
||||
case FUNCTION_TYPE_AVG:
|
||||
res = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,10 +23,165 @@
|
|||
#include "builtinsimpl.h"
|
||||
#include "functionMgt.h"
|
||||
|
||||
//TODO: network error processing.
|
||||
//TODO: add unit test
|
||||
//TODO: include all global variable under context struct
|
||||
|
||||
typedef struct SUdfdData {
|
||||
bool startCalled;
|
||||
bool needCleanUp;
|
||||
uv_loop_t loop;
|
||||
uv_thread_t thread;
|
||||
uv_barrier_t barrier;
|
||||
uv_process_t process;
|
||||
int spawnErr;
|
||||
uv_pipe_t ctrlPipe;
|
||||
uv_async_t stopAsync;
|
||||
int32_t stopCalled;
|
||||
|
||||
int32_t dnodeId;
|
||||
} SUdfdData;
|
||||
|
||||
SUdfdData udfdGlobal = {0};
|
||||
|
||||
static int32_t udfSpawnUdfd(SUdfdData *pData);
|
||||
|
||||
void udfUdfdExit(uv_process_t *process, int64_t exitStatus, int termSignal) {
|
||||
fnInfo("udfd process exited with status %" PRId64 ", signal %d", exitStatus, termSignal);
|
||||
SUdfdData *pData = process->data;
|
||||
if (exitStatus == 0 && termSignal == 0 || atomic_load_32(&pData->stopCalled)) {
|
||||
fnInfo("udfd process exit due to SIGINT or dnode-mgmt called stop");
|
||||
} else {
|
||||
fnInfo("udfd process restart");
|
||||
udfSpawnUdfd(pData);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t udfSpawnUdfd(SUdfdData* pData) {
|
||||
fnInfo("dnode start spawning udfd");
|
||||
uv_process_options_t options = {0};
|
||||
|
||||
char path[PATH_MAX] = {0};
|
||||
if (tsProcPath == NULL) {
|
||||
path[0] = '.';
|
||||
} else {
|
||||
strncpy(path, tsProcPath, strlen(tsProcPath));
|
||||
taosDirName(path);
|
||||
}
|
||||
#ifdef WINDOWS
|
||||
strcat(path, "udfd.exe");
|
||||
#else
|
||||
strcat(path, "/udfd");
|
||||
#endif
|
||||
char* argsUdfd[] = {path, "-c", configDir, NULL};
|
||||
options.args = argsUdfd;
|
||||
options.file = path;
|
||||
|
||||
options.exit_cb = udfUdfdExit;
|
||||
|
||||
uv_pipe_init(&pData->loop, &pData->ctrlPipe, 1);
|
||||
|
||||
uv_stdio_container_t child_stdio[3];
|
||||
child_stdio[0].flags = UV_CREATE_PIPE | UV_READABLE_PIPE;
|
||||
child_stdio[0].data.stream = (uv_stream_t*) &pData->ctrlPipe;
|
||||
child_stdio[1].flags = UV_IGNORE;
|
||||
child_stdio[2].flags = UV_INHERIT_FD;
|
||||
child_stdio[2].data.fd = 2;
|
||||
options.stdio_count = 3;
|
||||
options.stdio = child_stdio;
|
||||
|
||||
options.flags = UV_PROCESS_DETACHED;
|
||||
|
||||
char dnodeIdEnvItem[32] = {0};
|
||||
char thrdPoolSizeEnvItem[32] = {0};
|
||||
snprintf(dnodeIdEnvItem, 32, "%s=%d", "DNODE_ID", pData->dnodeId);
|
||||
float numCpuCores = 4;
|
||||
taosGetCpuCores(&numCpuCores);
|
||||
snprintf(thrdPoolSizeEnvItem,32, "%s=%d", "UV_THREADPOOL_SIZE", (int)numCpuCores*2);
|
||||
char* envUdfd[] = {dnodeIdEnvItem, thrdPoolSizeEnvItem, NULL};
|
||||
options.env = envUdfd;
|
||||
|
||||
int err = uv_spawn(&pData->loop, &pData->process, &options);
|
||||
pData->process.data = (void*)pData;
|
||||
|
||||
if (err != 0) {
|
||||
fnError("can not spawn udfd. path: %s, error: %s", path, uv_strerror(err));
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
static void udfUdfdCloseWalkCb(uv_handle_t* handle, void* arg) {
|
||||
if (!uv_is_closing(handle)) {
|
||||
uv_close(handle, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static void udfUdfdStopAsyncCb(uv_async_t *async) {
|
||||
SUdfdData *pData = async->data;
|
||||
uv_stop(&pData->loop);
|
||||
}
|
||||
|
||||
static void udfWatchUdfd(void *args) {
|
||||
SUdfdData *pData = args;
|
||||
uv_loop_init(&pData->loop);
|
||||
uv_async_init(&pData->loop, &pData->stopAsync, udfUdfdStopAsyncCb);
|
||||
pData->stopAsync.data = pData;
|
||||
int32_t err = udfSpawnUdfd(pData);
|
||||
atomic_store_32(&pData->spawnErr, err);
|
||||
uv_barrier_wait(&pData->barrier);
|
||||
uv_run(&pData->loop, UV_RUN_DEFAULT);
|
||||
uv_loop_close(&pData->loop);
|
||||
|
||||
uv_walk(&pData->loop, udfUdfdCloseWalkCb, NULL);
|
||||
uv_run(&pData->loop, UV_RUN_DEFAULT);
|
||||
uv_loop_close(&pData->loop);
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t udfStartUdfd(int32_t startDnodeId) {
|
||||
SUdfdData *pData = &udfdGlobal;
|
||||
if (pData->startCalled) {
|
||||
fnInfo("dnode-mgmt start udfd already called");
|
||||
return 0;
|
||||
}
|
||||
pData->startCalled = true;
|
||||
char dnodeId[8] = {0};
|
||||
snprintf(dnodeId, sizeof(dnodeId), "%d", startDnodeId);
|
||||
uv_os_setenv("DNODE_ID", dnodeId);
|
||||
pData->dnodeId = startDnodeId;
|
||||
|
||||
uv_barrier_init(&pData->barrier, 2);
|
||||
uv_thread_create(&pData->thread, udfWatchUdfd, pData);
|
||||
uv_barrier_wait(&pData->barrier);
|
||||
int32_t err = atomic_load_32(&pData->spawnErr);
|
||||
if (err != 0) {
|
||||
uv_barrier_destroy(&pData->barrier);
|
||||
uv_async_send(&pData->stopAsync);
|
||||
uv_thread_join(&pData->thread);
|
||||
pData->needCleanUp = false;
|
||||
fnInfo("dnode-mgmt udfd cleaned up after spawn err");
|
||||
} else {
|
||||
pData->needCleanUp = true;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
int32_t udfStopUdfd() {
|
||||
SUdfdData *pData = &udfdGlobal;
|
||||
fnInfo("dnode-mgmt to stop udfd. need cleanup: %d, spawn err: %d",
|
||||
pData->needCleanUp, pData->spawnErr);
|
||||
if (!pData->needCleanUp || atomic_load_32(&pData->stopCalled)) {
|
||||
return 0;
|
||||
}
|
||||
atomic_store_32(&pData->stopCalled, 1);
|
||||
pData->needCleanUp = false;
|
||||
uv_barrier_destroy(&pData->barrier);
|
||||
uv_async_send(&pData->stopAsync);
|
||||
uv_thread_join(&pData->thread);
|
||||
fnInfo("dnode-mgmt udfd cleaned up");
|
||||
return 0;
|
||||
}
|
||||
|
||||
//==============================================================================================
|
||||
/* Copyright (c) 2013, Ben Noordhuis <info@bnoordhuis.nl>
|
||||
* The QUEUE is copied from queue.h under libuv
|
||||
* */
|
||||
|
|
|
@ -409,7 +409,7 @@ void udfdPipeCloseCb(uv_handle_t *pipe) {
|
|||
void udfdUvHandleError(SUdfdUvConn *conn) { uv_close((uv_handle_t *)conn->client, udfdPipeCloseCb); }
|
||||
|
||||
void udfdPipeRead(uv_stream_t *client, ssize_t nread, const uv_buf_t *buf) {
|
||||
fnDebug("udf read %zu bytes from client", nread);
|
||||
fnDebug("udf read %zd bytes from client", nread);
|
||||
if (nread == 0) return;
|
||||
|
||||
SUdfdUvConn *conn = client->data;
|
||||
|
|
|
@ -20,11 +20,23 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "indexInt.h"
|
||||
#include "tcompare.h"
|
||||
|
||||
extern char JSON_COLUMN[];
|
||||
extern char JSON_VALUE_DELIM;
|
||||
|
||||
char* indexPackJsonData(SIndexTerm* itm);
|
||||
char* indexPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip);
|
||||
|
||||
typedef enum { MATCH, CONTINUE, BREAK } TExeCond;
|
||||
|
||||
typedef TExeCond (*_cache_range_compare)(void* a, void* b, int8_t type);
|
||||
|
||||
TExeCond tDoCommpare(__compar_fn_t func, int8_t comType, void* a, void* b);
|
||||
|
||||
_cache_range_compare indexGetCompare(RangeType ty);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -60,50 +60,6 @@ static int32_t cacheSearchRange_JSON(void* cache, SIndexTerm* ct, SIdxTempResult
|
|||
static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, 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 tDoCommpare(__compar_fn_t func, int8_t comType, void* a, void* b) {
|
||||
// optime later
|
||||
int32_t ret = func(a, b);
|
||||
switch (comType) {
|
||||
case QUERY_LESS_THAN: {
|
||||
if (ret < 0) return MATCH;
|
||||
} break;
|
||||
case QUERY_LESS_EQUAL: {
|
||||
if (ret <= 0) return MATCH;
|
||||
break;
|
||||
}
|
||||
case QUERY_GREATER_THAN: {
|
||||
if (ret > 0) return MATCH;
|
||||
break;
|
||||
}
|
||||
case QUERY_GREATER_EQUAL: {
|
||||
if (ret >= 0) return MATCH;
|
||||
}
|
||||
}
|
||||
return CONTINUE;
|
||||
}
|
||||
static TExeCond tCompareLessThan(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = getComparFunc(type, 0);
|
||||
return tDoCommpare(func, QUERY_LESS_THAN, a, b);
|
||||
}
|
||||
static TExeCond tCompareLessEqual(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = getComparFunc(type, 0);
|
||||
return tDoCommpare(func, QUERY_LESS_EQUAL, a, b);
|
||||
}
|
||||
static TExeCond tCompareGreaterThan(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = getComparFunc(type, 0);
|
||||
return tDoCommpare(func, QUERY_GREATER_THAN, a, b);
|
||||
}
|
||||
static TExeCond tCompareGreaterEqual(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = getComparFunc(type, 0);
|
||||
return tDoCommpare(func, QUERY_GREATER_EQUAL, a, b);
|
||||
}
|
||||
|
||||
static TExeCond (*rangeCompare[])(void* a, void* b, int8_t type) = {tCompareLessThan, tCompareLessEqual,
|
||||
tCompareGreaterThan, tCompareGreaterEqual};
|
||||
|
||||
static int32_t (*cacheSearch[][QUERY_MAX])(void* cache, SIndexTerm* ct, SIdxTempResult* tr, STermValueType* s) = {
|
||||
{cacheSearchTerm, cacheSearchPrefix, cacheSearchSuffix, cacheSearchRegex, cacheSearchLessThan, cacheSearchLessEqual,
|
||||
cacheSearchGreaterThan, cacheSearchGreaterEqual, cacheSearchRange},
|
||||
|
@ -169,7 +125,7 @@ static int32_t cacheSearchCompareFunc(void* cache, SIndexTerm* term, SIdxTempRes
|
|||
return 0;
|
||||
}
|
||||
|
||||
_cache_range_compare cmpFn = rangeCompare[type];
|
||||
_cache_range_compare cmpFn = indexGetCompare(type);
|
||||
|
||||
MemTable* mem = cache;
|
||||
IndexCache* pCache = mem->pCache;
|
||||
|
@ -295,7 +251,7 @@ static int32_t cacheSearchCompareFunc_JSON(void* cache, SIndexTerm* term, SIdxTe
|
|||
if (cache == NULL) {
|
||||
return 0;
|
||||
}
|
||||
_cache_range_compare cmpFn = rangeCompare[type];
|
||||
_cache_range_compare cmpFn = indexGetCompare(type);
|
||||
|
||||
MemTable* mem = cache;
|
||||
IndexCache* pCache = mem->pCache;
|
||||
|
|
|
@ -13,12 +13,58 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "indexComm.h"
|
||||
#include "index.h"
|
||||
#include "indexInt.h"
|
||||
#include "tcompare.h"
|
||||
|
||||
char JSON_COLUMN[] = "JSON";
|
||||
char JSON_VALUE_DELIM = '&';
|
||||
|
||||
static TExeCond tCompareLessThan(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = getComparFunc(type, 0);
|
||||
return tDoCommpare(func, QUERY_LESS_THAN, a, b);
|
||||
}
|
||||
static TExeCond tCompareLessEqual(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = getComparFunc(type, 0);
|
||||
return tDoCommpare(func, QUERY_LESS_EQUAL, a, b);
|
||||
}
|
||||
static TExeCond tCompareGreaterThan(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = getComparFunc(type, 0);
|
||||
return tDoCommpare(func, QUERY_GREATER_THAN, a, b);
|
||||
}
|
||||
static TExeCond tCompareGreaterEqual(void* a, void* b, int8_t type) {
|
||||
__compar_fn_t func = getComparFunc(type, 0);
|
||||
return tDoCommpare(func, QUERY_GREATER_EQUAL, a, b);
|
||||
}
|
||||
|
||||
TExeCond tDoCommpare(__compar_fn_t func, int8_t comType, void* a, void* b) {
|
||||
// optime later
|
||||
int32_t ret = func(a, b);
|
||||
switch (comType) {
|
||||
case QUERY_LESS_THAN: {
|
||||
if (ret < 0) return MATCH;
|
||||
} break;
|
||||
case QUERY_LESS_EQUAL: {
|
||||
if (ret <= 0) return MATCH;
|
||||
break;
|
||||
}
|
||||
case QUERY_GREATER_THAN: {
|
||||
if (ret > 0) return MATCH;
|
||||
break;
|
||||
}
|
||||
case QUERY_GREATER_EQUAL: {
|
||||
if (ret >= 0) return MATCH;
|
||||
}
|
||||
}
|
||||
return CONTINUE;
|
||||
}
|
||||
|
||||
static TExeCond (*rangeCompare[])(void* a, void* b, int8_t type) = {tCompareLessThan, tCompareLessEqual,
|
||||
tCompareGreaterThan, tCompareGreaterEqual};
|
||||
|
||||
_cache_range_compare indexGetCompare(RangeType ty) { return rangeCompare[ty]; }
|
||||
|
||||
char* indexPackJsonData(SIndexTerm* itm) {
|
||||
/*
|
||||
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
|
||||
|
@ -46,6 +92,7 @@ char* indexPackJsonData(SIndexTerm* itm) {
|
|||
|
||||
return buf;
|
||||
}
|
||||
|
||||
char* indexPackJsonDataPrefix(SIndexTerm* itm, int32_t* skip) {
|
||||
/*
|
||||
* |<-----colname---->|<-----dataType---->|<--------colVal---------->|
|
||||
|
|
|
@ -72,9 +72,23 @@ 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, tfSearchLessThan,
|
||||
tfSearchLessEqual, tfSearchGreaterThan, tfSearchGreaterEqual, tfSearchRange};
|
||||
static int32_t tfSearchTerm_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchPrefix_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchSuffix_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchRegex_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchLessThan_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchLessEqual_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchGreaterThan_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchGreaterEqual_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
static int32_t tfSearchRange_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr);
|
||||
|
||||
static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr, RangeType ctype);
|
||||
|
||||
static int32_t (*tfSearch[][QUERY_MAX])(void* reader, SIndexTerm* tem, SIdxTempResult* tr) = {
|
||||
{tfSearchTerm, tfSearchPrefix, tfSearchSuffix, tfSearchRegex, tfSearchLessThan, tfSearchLessEqual,
|
||||
tfSearchGreaterThan, tfSearchGreaterEqual, tfSearchRange},
|
||||
{tfSearchTerm_JSON, tfSearchPrefix_JSON, tfSearchSuffix_JSON, tfSearchRegex_JSON, tfSearchLessThan_JSON,
|
||||
tfSearchLessEqual_JSON, tfSearchGreaterThan_JSON, tfSearchGreaterEqual_JSON, tfSearchRange_JSON}};
|
||||
|
||||
TFileCache* tfileCacheCreate(const char* path) {
|
||||
TFileCache* tcache = taosMemoryCalloc(1, sizeof(TFileCache));
|
||||
|
@ -202,14 +216,10 @@ void tfileReaderDestroy(TFileReader* reader) {
|
|||
taosMemoryFree(reader);
|
||||
}
|
||||
static int32_t tfSearchTerm(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
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);
|
||||
}
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
FstSlice key = fstSliceCreate(p, sz);
|
||||
uint64_t offset;
|
||||
|
@ -224,9 +234,6 @@ static int32_t tfSearchTerm(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
|||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, load all table info, time cost: %" PRIu64 "us", tem->suid,
|
||||
tem->colName, tem->colVal, cost);
|
||||
}
|
||||
if (hasJson) {
|
||||
taosMemoryFree(p);
|
||||
}
|
||||
fstSliceDestroy(&key);
|
||||
return 0;
|
||||
}
|
||||
|
@ -308,14 +315,11 @@ static int32_t tfSearchRegex(void* reader, SIndexTerm* tem, SIdxTempResult* tr)
|
|||
}
|
||||
|
||||
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;
|
||||
int skip = 0;
|
||||
int ret = 0;
|
||||
char* p = tem->colVal;
|
||||
int skip = 0;
|
||||
_cache_range_compare cmpFn = indexGetCompare(type);
|
||||
|
||||
if (hasJson) {
|
||||
p = indexPackJsonDataPrefix(tem, &skip);
|
||||
}
|
||||
SArray* offsets = taosArrayInit(16, sizeof(uint64_t));
|
||||
|
||||
AutomationCtx* ctx = automCtxCreate((void*)p, AUTOMATION_ALWAYS);
|
||||
|
@ -328,7 +332,16 @@ static int32_t tfSearchCompareFunc(void* reader, SIndexTerm* tem, SIdxTempResult
|
|||
StreamWithState* st = streamBuilderIntoStream(sb);
|
||||
StreamWithStateResult* rt = NULL;
|
||||
while ((rt = streamWithStateNextWith(st, NULL)) != NULL) {
|
||||
taosArrayPush(offsets, &(rt->out.out));
|
||||
FstSlice* s = &rt->data;
|
||||
char* ch = (char*)fstSliceData(s, NULL);
|
||||
TExeCond cond = cmpFn(ch, p, tem->colType);
|
||||
if (MATCH == cond) {
|
||||
tfileReaderLoadTableIds((TFileReader*)reader, rt->out.out, tr->total);
|
||||
} else if (CONTINUE == cond) {
|
||||
} else if (BREAK == cond) {
|
||||
swsResultDestroy(rt);
|
||||
break;
|
||||
}
|
||||
swsResultDestroy(rt);
|
||||
}
|
||||
streamWithStateDestroy(st);
|
||||
|
@ -376,17 +389,105 @@ static int32_t tfSearchRange(void* reader, SIndexTerm* tem, SIdxTempResult* tr)
|
|||
fstSliceDestroy(&key);
|
||||
return 0;
|
||||
}
|
||||
static int32_t tfSearchTerm_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
int ret = 0;
|
||||
char* p = indexPackJsonData(tem);
|
||||
int sz = strlen(p);
|
||||
|
||||
int64_t st = taosGetTimestampUs();
|
||||
FstSlice key = fstSliceCreate(p, sz);
|
||||
uint64_t offset;
|
||||
if (fstGet(((TFileReader*)reader)->fst, &key, &offset)) {
|
||||
int64_t et = taosGetTimestampUs();
|
||||
int64_t cost = et - st;
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, found table info in tindex, time cost: %" PRIu64 "us",
|
||||
tem->suid, tem->colName, tem->colVal, cost);
|
||||
|
||||
ret = tfileReaderLoadTableIds((TFileReader*)reader, offset, tr->total);
|
||||
cost = taosGetTimestampUs() - et;
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, load all table info, time cost: %" PRIu64 "us", tem->suid,
|
||||
tem->colName, tem->colVal, cost);
|
||||
}
|
||||
fstSliceDestroy(&key);
|
||||
return 0;
|
||||
// deprecate api
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t tfSearchPrefix_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t tfSearchSuffix_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t tfSearchRegex_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t tfSearchLessThan_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
return tfSearchCompareFunc_JSON(reader, tem, tr, LT);
|
||||
}
|
||||
static int32_t tfSearchLessEqual_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
return tfSearchCompareFunc_JSON(reader, tem, tr, LE);
|
||||
}
|
||||
static int32_t tfSearchGreaterThan_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
return tfSearchCompareFunc_JSON(reader, tem, tr, GT);
|
||||
}
|
||||
static int32_t tfSearchGreaterEqual_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
return tfSearchCompareFunc_JSON(reader, tem, tr, GE);
|
||||
}
|
||||
static int32_t tfSearchRange_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t tfSearchCompareFunc_JSON(void* reader, SIndexTerm* tem, SIdxTempResult* tr, RangeType ctype) {
|
||||
int ret = 0;
|
||||
int skip = 0;
|
||||
|
||||
char* p = indexPackJsonDataPrefix(tem, &skip);
|
||||
|
||||
_cache_range_compare cmpFn = indexGetCompare(ctype);
|
||||
|
||||
SArray* offsets = taosArrayInit(16, sizeof(uint64_t));
|
||||
|
||||
AutomationCtx* ctx = automCtxCreate((void*)p, AUTOMATION_PREFIX);
|
||||
FstStreamBuilder* sb = fstSearch(((TFileReader*)reader)->fst, ctx);
|
||||
|
||||
FstSlice h = fstSliceCreate((uint8_t*)p, skip);
|
||||
fstStreamBuilderSetRange(sb, &h, ctype);
|
||||
fstSliceDestroy(&h);
|
||||
|
||||
StreamWithState* st = streamBuilderIntoStream(sb);
|
||||
StreamWithStateResult* rt = NULL;
|
||||
while ((rt = streamWithStateNextWith(st, NULL)) != NULL) {
|
||||
FstSlice* s = &rt->data;
|
||||
char* ch = (char*)fstSliceData(s, NULL);
|
||||
TExeCond cond = cmpFn(ch, p, tem->colType);
|
||||
if (MATCH == cond) {
|
||||
tfileReaderLoadTableIds((TFileReader*)reader, rt->out.out, tr->total);
|
||||
} else if (CONTINUE == cond) {
|
||||
} else if (BREAK == cond) {
|
||||
swsResultDestroy(rt);
|
||||
break;
|
||||
}
|
||||
swsResultDestroy(rt);
|
||||
}
|
||||
streamWithStateDestroy(st);
|
||||
fstStreamBuilderDestroy(sb);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
int tfileReaderSearch(TFileReader* reader, SIndexTermQuery* query, SIdxTempResult* tr) {
|
||||
SIndexTerm* term = query->term;
|
||||
EIndexQueryType qtype = query->qType;
|
||||
if (qtype >= sizeof(tfSearch) / sizeof(tfSearch[0])) {
|
||||
indexInfo("index: %" PRIu64 ", col: %s, colVal: %s, not found table info in tindex", term->suid, term->colName,
|
||||
term->colVal);
|
||||
return -1;
|
||||
|
||||
if (INDEX_TYPE_CONTAIN_EXTERN_TYPE(term->colType, TSDB_DATA_TYPE_JSON)) {
|
||||
return tfSearch[1][qtype](reader, term, tr);
|
||||
} else {
|
||||
return tfSearch[qtype](reader, term, tr);
|
||||
return tfSearch[0][qtype](reader, term, tr);
|
||||
}
|
||||
|
||||
tfileReaderUnRef(reader);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -222,6 +222,8 @@ const char* nodesNodeName(ENodeType type) {
|
|||
return "PhysiSort";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
|
||||
return "PhysiInterval";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
|
||||
return "PhysiStreamInterval";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_FILL:
|
||||
return "PhysiFill";
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
|
||||
|
@ -2893,6 +2895,7 @@ static int32_t specificNodeToJson(const void* pObj, SJson* pJson) {
|
|||
case QUERY_NODE_PHYSICAL_PLAN_SORT:
|
||||
return physiSortNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
|
||||
return physiIntervalNodeToJson(pObj, pJson);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_FILL:
|
||||
return physiFillNodeToJson(pObj, pJson);
|
||||
|
@ -2983,6 +2986,7 @@ static int32_t jsonToSpecificNode(const SJson* pJson, void* pObj) {
|
|||
case QUERY_NODE_PHYSICAL_PLAN_SORT:
|
||||
return jsonToPhysiSortNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
|
||||
return jsonToPhysiIntervalNode(pJson, pObj);
|
||||
case QUERY_NODE_PHYSICAL_PLAN_FILL:
|
||||
return jsonToPhysiFillNode(pJson, pObj);
|
||||
|
@ -3099,6 +3103,7 @@ int32_t nodesStringToNode(const char* pStr, SNode** pNode) {
|
|||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
int32_t code = makeNodeByJson(pJson, pNode);
|
||||
tjsonDelete(pJson);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyNode(*pNode);
|
||||
*pNode = NULL;
|
||||
|
|
|
@ -513,6 +513,7 @@ static EDealRes dispatchPhysiPlan(SNode* pNode, ETraversalOrder order, FNodeWalk
|
|||
break;
|
||||
}
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
|
||||
res = walkWindowPhysi((SWinodwPhysiNode*)pNode, order, walker, pContext);
|
||||
break;
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
|
||||
|
|
|
@ -252,6 +252,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
|||
return makeNode(type, sizeof(SSortPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
|
||||
return makeNode(type, sizeof(SIntervalPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
|
||||
return makeNode(type, sizeof(SStreamIntervalPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_FILL:
|
||||
return makeNode(type, sizeof(SFillPhysiNode));
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
|
||||
|
@ -644,6 +646,7 @@ void nodesDestroyNode(SNodeptr pNode) {
|
|||
break;
|
||||
}
|
||||
case QUERY_NODE_PHYSICAL_PLAN_INTERVAL:
|
||||
case QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL:
|
||||
destroyWinodwPhysiNode((SWinodwPhysiNode*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_PHYSICAL_PLAN_SESSION_WINDOW:
|
||||
|
|
|
@ -64,8 +64,8 @@ int32_t parse(SParseContext* pParseCxt, SQuery** pQuery) {
|
|||
goto abort_parse;
|
||||
}
|
||||
default:
|
||||
Parse(pParser, t0.type, t0, &cxt);
|
||||
// ParseTrace(stdout, "");
|
||||
Parse(pParser, t0.type, t0, &cxt);
|
||||
if (TSDB_CODE_SUCCESS != cxt.errCode) {
|
||||
goto abort_parse;
|
||||
}
|
||||
|
|
|
@ -241,6 +241,15 @@ static int32_t getTableMetaImpl(SInsertParseContext* pCxt, SToken* pTname, bool
|
|||
SParseContext* pBasicCtx = pCxt->pComCxt;
|
||||
SName name = {0};
|
||||
createSName(&name, pTname, pBasicCtx->acctId, pBasicCtx->db, &pCxt->msg);
|
||||
|
||||
char dbFname[TSDB_DB_FNAME_LEN] = {0};
|
||||
tNameGetFullDbName(&name, dbFname);
|
||||
|
||||
bool pass = false;
|
||||
CHECK_CODE(catalogChkAuth(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, pBasicCtx->pUser, dbFname, AUTH_TYPE_WRITE, &pass));
|
||||
if (!pass) {
|
||||
return TSDB_CODE_PAR_PERMISSION_DENIED;
|
||||
}
|
||||
if (isStb) {
|
||||
CHECK_CODE(catalogGetSTableMeta(pBasicCtx->pCatalog, pBasicCtx->pTransporter, &pBasicCtx->mgmtEpSet, &name,
|
||||
&pCxt->pTableMeta));
|
||||
|
@ -1151,6 +1160,7 @@ static int32_t parseInsertBody(SInsertParseContext* pCxt) {
|
|||
(*pCxt->pStmtCb->setExecInfoFn)(pCxt->pStmtCb->pStmt, pCxt->pVgroupsHashObj, pCxt->pTableBlockHashObj);
|
||||
pCxt->pVgroupsHashObj = NULL;
|
||||
pCxt->pTableBlockHashObj = NULL;
|
||||
pCxt->pTableMeta = NULL;
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -1276,7 +1286,7 @@ int32_t qBindStmtTagsValue(void *pBlock, void *boundTags, int64_t suid, char *tN
|
|||
return TSDB_CODE_TSC_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SSchema* pSchema = getTableTagSchema(pDataBlock->pTableMeta);
|
||||
SSchema* pSchema = pDataBlock->pTableMeta->schema;
|
||||
SKvParam param = {.builder = &tagBuilder};
|
||||
|
||||
for (int c = 0; c < tags->numOfBound; ++c) {
|
||||
|
|
|
@ -469,7 +469,7 @@ int32_t mergeTableDataBlocks(SHashObj* pHashObj, uint8_t payloadType, SArray** p
|
|||
// the maximum expanded size in byte when a row-wise data is converted to SDataRow format
|
||||
int32_t expandSize = isRawPayload ? getRowExpandSize(pOneTableBlock->pTableMeta) : 0;
|
||||
int64_t destSize = dataBuf->size + pOneTableBlock->size + pBlocks->numOfRows * expandSize +
|
||||
sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta);
|
||||
sizeof(STColumn) * getNumOfColumns(pOneTableBlock->pTableMeta) + pOneTableBlock->createTbReqLen;
|
||||
|
||||
if (dataBuf->nAllocSize < destSize) {
|
||||
dataBuf->nAllocSize = (uint32_t)(destSize * 1.5);
|
||||
|
@ -601,6 +601,7 @@ int32_t qResetStmtDataBlock(void* block, bool keepBuf) {
|
|||
pBlock->numOfTables = 1;
|
||||
pBlock->nAllocSize = TSDB_PAYLOAD_SIZE;
|
||||
pBlock->headerSize = pBlock->size;
|
||||
pBlock->createTbReqLen = 0;
|
||||
|
||||
memset(&pBlock->rowBuilder, 0, sizeof(pBlock->rowBuilder));
|
||||
|
||||
|
|
|
@ -590,6 +590,8 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
if (seg == 4) { // ip address
|
||||
*tokenId = TK_NK_IPTOKEN;
|
||||
return i;
|
||||
} else if (seg > 2) {
|
||||
break;
|
||||
}
|
||||
|
||||
if ((z[i] == 'e' || z[i] == 'E') &&
|
||||
|
|
|
@ -699,6 +699,10 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc)
|
|||
if (isCountStar(pFunc)) {
|
||||
pCxt->errCode = rewriteCountStar(pCxt, pFunc);
|
||||
}
|
||||
|
||||
if (fmIsRepeatScanFunc(pFunc->funcId)) {
|
||||
pCxt->pCurrStmt->hasRepeatScanFuncs = true;
|
||||
}
|
||||
}
|
||||
return TSDB_CODE_SUCCESS == pCxt->errCode ? DEAL_RES_CONTINUE : DEAL_RES_ERROR;
|
||||
}
|
||||
|
@ -2255,8 +2259,8 @@ static int32_t checkTableColsSchema(STranslateContext* pCxt, SHashObj* pHash, SN
|
|||
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_DUPLICATED_COLUMN);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
if ((TSDB_DATA_TYPE_VARCHAR == pCol->dataType.type && pCol->dataType.bytes > TSDB_MAX_BINARY_LEN) ||
|
||||
(TSDB_DATA_TYPE_NCHAR == pCol->dataType.type && pCol->dataType.bytes > TSDB_MAX_NCHAR_LEN)) {
|
||||
if ((TSDB_DATA_TYPE_VARCHAR == pCol->dataType.type && calcTypeBytes(pCol->dataType) > TSDB_MAX_BINARY_LEN) ||
|
||||
(TSDB_DATA_TYPE_NCHAR == pCol->dataType.type && calcTypeBytes(pCol->dataType) > TSDB_MAX_NCHAR_LEN)) {
|
||||
code = code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INVALID_VAR_COLUMN_LEN);
|
||||
}
|
||||
}
|
||||
|
@ -2575,7 +2579,7 @@ static int32_t translateDropTable(STranslateContext* pCxt, SDropTableStmt* pStmt
|
|||
SName tableName;
|
||||
int32_t code = getTableMetaImpl(
|
||||
pCxt, toName(pCxt->pParseCxt->acctId, pClause->dbName, pClause->tableName, &tableName), &pTableMeta);
|
||||
if ((TSDB_CODE_TDB_INVALID_TABLE_ID == code || TSDB_CODE_VND_TB_NOT_EXIST == code) && pClause->ignoreNotExists) {
|
||||
if ((TSDB_CODE_PAR_TABLE_NOT_EXIST == code || TSDB_CODE_VND_TB_NOT_EXIST == code) && pClause->ignoreNotExists) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
|
@ -3146,7 +3150,7 @@ static int32_t translateGrant(STranslateContext* pCxt, SGrantStmt* pStmt) {
|
|||
req.alterType = TSDB_ALTER_USER_ADD_WRITE_DB;
|
||||
}
|
||||
strcpy(req.user, pStmt->userName);
|
||||
strcpy(req.dbname, pStmt->dbName);
|
||||
sprintf(req.dbname, "%d.%s", pCxt->pParseCxt->acctId, pStmt->dbName);
|
||||
return buildCmdMsg(pCxt, TDMT_MND_ALTER_USER, (FSerializeFunc)tSerializeSAlterUserReq, &req);
|
||||
}
|
||||
|
||||
|
|
|
@ -54,6 +54,9 @@ static EDealRes doRewriteExpr(SNode** pNode, void* pContext) {
|
|||
pCol->node.resType = pToBeRewrittenExpr->resType;
|
||||
strcpy(pCol->node.aliasName, pToBeRewrittenExpr->aliasName);
|
||||
strcpy(pCol->colName, ((SExprNode*)pExpr)->aliasName);
|
||||
if (QUERY_NODE_FUNCTION == nodeType(pExpr) && FUNCTION_TYPE_WSTARTTS == ((SFunctionNode*)pExpr)->funcType) {
|
||||
pCol->colId = PRIMARYKEY_TIMESTAMP_COL_ID;
|
||||
}
|
||||
nodesDestroyNode(*pNode);
|
||||
*pNode = (SNode*)pCol;
|
||||
return DEAL_RES_IGNORE_CHILD;
|
||||
|
@ -253,7 +256,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
|
||||
TSWAP(pScan->pMeta, pRealTable->pMeta);
|
||||
TSWAP(pScan->pVgroupList, pRealTable->pVgroupList);
|
||||
pScan->scanSeq[0] = 1;
|
||||
pScan->scanSeq[0] = pSelect->hasRepeatScanFuncs ? 2 : 1;
|
||||
pScan->scanSeq[1] = 0;
|
||||
pScan->scanRange = TSWINDOW_INITIALIZER;
|
||||
pScan->tableName.type = TSDB_TABLE_NAME_T;
|
||||
|
|
|
@ -754,10 +754,7 @@ static int32_t opkDoOptimized(SOptimizeContext* pCxt, SSortLogicNode* pSort, SNo
|
|||
EOrder order = opkGetPrimaryKeyOrder(pSort);
|
||||
if (ORDER_DESC == order) {
|
||||
SNode* pScan = NULL;
|
||||
FOREACH(pScan, pScanNodes) {
|
||||
((SScanLogicNode*)pScan)->scanSeq[0] = 0;
|
||||
((SScanLogicNode*)pScan)->scanSeq[1] = 1;
|
||||
}
|
||||
FOREACH(pScan, pScanNodes) { TSWAP(((SScanLogicNode*)pScan)->scanSeq[0], ((SScanLogicNode*)pScan)->scanSeq[1]); }
|
||||
}
|
||||
|
||||
if (NULL == pSort->node.pParent) {
|
||||
|
|
|
@ -869,7 +869,8 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList*
|
|||
static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren,
|
||||
SWindowLogicNode* pWindowLogicNode, SPhysiNode** pPhyNode) {
|
||||
SIntervalPhysiNode* pInterval = (SIntervalPhysiNode*)makePhysiNode(
|
||||
pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode, QUERY_NODE_PHYSICAL_PLAN_INTERVAL);
|
||||
pCxt, getPrecision(pChildren), (SLogicNode*)pWindowLogicNode,
|
||||
(pCxt->pPlanCxt->streamQuery ? QUERY_NODE_PHYSICAL_PLAN_STREAM_INTERVAL : QUERY_NODE_PHYSICAL_PLAN_INTERVAL));
|
||||
if (NULL == pInterval) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
|
|
@ -48,4 +48,6 @@ TEST_F(PlanBasicTest, func) {
|
|||
useDb("root", "test");
|
||||
|
||||
run("SELECT DIFF(c1) FROM t1");
|
||||
|
||||
run("SELECT PERCENTILE(c1, 60) FROM t1");
|
||||
}
|
||||
|
|
|
@ -37,4 +37,6 @@ TEST_F(PlanOptimizeTest, orderByPrimaryKey) {
|
|||
run("SELECT * FROM t1 ORDER BY ts DESC");
|
||||
run("SELECT c1 FROM t1 ORDER BY ts");
|
||||
run("SELECT c1 FROM t1 ORDER BY ts DESC");
|
||||
|
||||
run("SELECT COUNT(*) FROM t1 INTERVAL(10S) ORDER BY _WSTARTTS DESC");
|
||||
}
|
||||
|
|
|
@ -136,7 +136,8 @@ int32_t taosAsyncExec(__async_exec_fn_t execFn, void* execParam, int32_t* code)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int32_t asyncSendMsgToServerExt(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo, bool persistHandle, void *rpcCtx) {
|
||||
int32_t asyncSendMsgToServerExt(void* pTransporter, SEpSet* epSet, int64_t* pTransporterId, const SMsgSendInfo* pInfo,
|
||||
bool persistHandle, void* rpcCtx) {
|
||||
char* pMsg = rpcMallocCont(pInfo->msgInfo.len);
|
||||
if (NULL == pMsg) {
|
||||
qError("0x%" PRIx64 " msg:%s malloc failed", pInfo->requestId, TMSG_INFO(pInfo->msgType));
|
||||
|
|
|
@ -3577,6 +3577,22 @@ EDealRes fltReviseRewriter(SNode** pNode, void* pContext) {
|
|||
}
|
||||
|
||||
if (QUERY_NODE_NODE_LIST == nodeType(*pNode)) {
|
||||
SNodeListNode *listNode = (SNodeListNode *)*pNode;
|
||||
if (QUERY_NODE_VALUE != nodeType(listNode->pNodeList->pHead->pNode)) {
|
||||
stat->scalarMode = true;
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
SValueNode *valueNode = (SValueNode *)listNode->pNodeList->pHead->pNode;
|
||||
uint8_t type = valueNode->node.resType.type;
|
||||
SNode *node = NULL;
|
||||
FOREACH(node, listNode->pNodeList) {
|
||||
if (type != ((SValueNode *)node)->node.resType.type) {
|
||||
stat->scalarMode = true;
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
}
|
||||
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue