Merge branch '3.0' into test/chr/TD-14699
This commit is contained in:
commit
2fc27261da
|
@ -5,6 +5,7 @@ compile_commands.json
|
|||
.tasks
|
||||
.vimspector.json
|
||||
.vscode/
|
||||
.vscode
|
||||
.idea/
|
||||
cmake-build-debug/
|
||||
cmake-build-release/
|
||||
|
|
|
@ -179,7 +179,7 @@ typedef struct SQueryCostInfo {
|
|||
uint32_t totalBlocks;
|
||||
uint32_t loadBlocks;
|
||||
uint32_t loadBlockStatis;
|
||||
uint32_t discardBlocks;
|
||||
uint32_t skipBlocks;
|
||||
uint64_t elapsedTime;
|
||||
uint64_t firstStageMergeTime;
|
||||
uint64_t winInfoSize;
|
||||
|
|
|
@ -3144,7 +3144,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
|
|||
if ((*status) == BLK_DATA_NO_NEEDED || (*status) == BLK_DATA_DISCARD) {
|
||||
qDebug("QInfo:0x%"PRIx64" data block discard, brange:%" PRId64 "-%" PRId64 ", rows:%d", pQInfo->qId, pBlockInfo->window.skey,
|
||||
pBlockInfo->window.ekey, pBlockInfo->rows);
|
||||
pCost->discardBlocks += 1;
|
||||
pCost->skipBlocks += 1;
|
||||
} else if ((*status) == BLK_DATA_STATIS_NEEDED) {
|
||||
// this function never returns error?
|
||||
pCost->loadBlockStatis += 1;
|
||||
|
@ -3184,7 +3184,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
|
|||
load = topbot_datablock_filter(&pTableScanInfo->pCtx[i], (char*)&(pBlock->pBlockStatis[i].min),
|
||||
(char*)&(pBlock->pBlockStatis[i].max));
|
||||
if (!load) { // current block has been discard due to filter applied
|
||||
pCost->discardBlocks += 1;
|
||||
pCost->skipBlocks += 1;
|
||||
qDebug("QInfo:0x%"PRIx64" data block discard, brange:%" PRId64 "-%" PRId64 ", rows:%d", pQInfo->qId,
|
||||
pBlockInfo->window.skey, pBlockInfo->window.ekey, pBlockInfo->rows);
|
||||
(*status) = BLK_DATA_DISCARD;
|
||||
|
@ -3196,7 +3196,7 @@ int32_t loadDataBlockOnDemand(SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTa
|
|||
|
||||
// current block has been discard due to filter applied
|
||||
if (!doFilterByBlockStatistics(pRuntimeEnv, pBlock->pBlockStatis, pTableScanInfo->pCtx, pBlockInfo->rows)) {
|
||||
pCost->discardBlocks += 1;
|
||||
pCost->skipBlocks += 1;
|
||||
qDebug("QInfo:0x%"PRIx64" data block discard, brange:%" PRId64 "-%" PRId64 ", rows:%d", pQInfo->qId, pBlockInfo->window.skey,
|
||||
pBlockInfo->window.ekey, pBlockInfo->rows);
|
||||
(*status) = BLK_DATA_DISCARD;
|
||||
|
|
|
@ -17,6 +17,7 @@ include(${TD_SUPPORT_DIR}/cmake.platform)
|
|||
include(${TD_SUPPORT_DIR}/cmake.define)
|
||||
include(${TD_SUPPORT_DIR}/cmake.options)
|
||||
include(${TD_SUPPORT_DIR}/cmake.version)
|
||||
include(${TD_SUPPORT_DIR}/cmake.install)
|
||||
|
||||
# contrib
|
||||
add_subdirectory(contrib)
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
#set output directory
|
||||
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/lib)
|
||||
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/build/bin)
|
||||
SET(TD_TESTS_OUTPUT_DIR ${PROJECT_BINARY_DIR}/test)
|
||||
|
||||
MESSAGE(STATUS "Project source directory: " ${PROJECT_SOURCE_DIR})
|
||||
MESSAGE(STATUS "Project binary files output path: " ${PROJECT_BINARY_DIR})
|
||||
MESSAGE(STATUS "Project executable files output path: " ${EXECUTABLE_OUTPUT_PATH})
|
||||
MESSAGE(STATUS "Project library files output path: " ${LIBRARY_OUTPUT_PATH})
|
||||
|
||||
if (NOT DEFINED TD_GRANT)
|
||||
SET(TD_GRANT FALSE)
|
||||
endif()
|
||||
if (NOT DEFINED TD_USB_DONGLE)
|
||||
SET(TD_USB_DONGLE FALSE)
|
||||
endif()
|
||||
IF (TD_GRANT)
|
||||
ADD_DEFINITIONS(-D_GRANT)
|
||||
ENDIF ()
|
||||
|
||||
IF ("${BUILD_TOOLS}" STREQUAL "")
|
||||
IF (TD_LINUX)
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
IF (TD_LINUX)
|
||||
SET(TD_MAKE_INSTALL_SH "${TD_SOURCE_DIR}/packaging/make_install.sh")
|
||||
INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")")
|
||||
INSTALL(CODE "execute_process(COMMAND bash ${TD_MAKE_INSTALL_SH} ${TD_SOURCE_DIR} ${PROJECT_BINARY_DIR} Linux ${TD_VER_NUMBER})")
|
||||
ELSEIF (TD_WINDOWS)
|
||||
SET(CMAKE_INSTALL_PREFIX C:/TDengine)
|
||||
|
||||
INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/go DESTINATION connector)
|
||||
INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/nodejs DESTINATION connector)
|
||||
INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/python DESTINATION connector)
|
||||
INSTALL(DIRECTORY ${TD_SOURCE_DIR}/src/connector/C\# DESTINATION connector)
|
||||
INSTALL(DIRECTORY ${TD_SOURCE_DIR}/examples DESTINATION .)
|
||||
INSTALL(FILES ${TD_SOURCE_DIR}/packaging/cfg/taos.cfg DESTINATION cfg)
|
||||
INSTALL(FILES ${TD_SOURCE_DIR}/src/inc/taos.h DESTINATION include)
|
||||
INSTALL(FILES ${TD_SOURCE_DIR}/src/inc/taoserror.h DESTINATION include)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.lib DESTINATION driver)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos_static.lib DESTINATION driver)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.exp DESTINATION driver)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos.dll DESTINATION driver)
|
||||
|
||||
IF (TD_MVN_INSTALLED)
|
||||
INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.38-dist.jar DESTINATION connector/jdbc)
|
||||
ENDIF ()
|
||||
ELSEIF (TD_DARWIN)
|
||||
SET(TD_MAKE_INSTALL_SH "${TD_SOURCE_DIR}/packaging/tools/make_install.sh")
|
||||
INSTALL(CODE "MESSAGE(\"make install script: ${TD_MAKE_INSTALL_SH}\")")
|
||||
INSTALL(CODE "execute_process(COMMAND bash ${TD_MAKE_INSTALL_SH} ${TD_SOURCE_DIR} ${PROJECT_BINARY_DIR} Darwin ${TD_VER_NUMBER})")
|
||||
ENDIF ()
|
|
@ -18,15 +18,15 @@ target_sources(demoapi
|
|||
)
|
||||
|
||||
target_link_libraries(tmq
|
||||
taos
|
||||
taos_static
|
||||
)
|
||||
|
||||
target_link_libraries(tstream
|
||||
taos
|
||||
taos_static
|
||||
)
|
||||
|
||||
target_link_libraries(demoapi
|
||||
taos
|
||||
taos_static
|
||||
)
|
||||
|
||||
target_include_directories(tmq
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
fprintf(stderr, "\033[0m"); } while(0)
|
||||
|
||||
int64_t g_num_of_tb = 2;
|
||||
int64_t g_num_of_rec = 2;
|
||||
int64_t g_num_of_rec = 3;
|
||||
|
||||
static struct argp_option options[] = {
|
||||
{"tables", 't', "NUMBER", 0, "Number of child tables, default is 10000."},
|
||||
|
@ -42,10 +42,18 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) {
|
|||
switch (key) {
|
||||
case 't':
|
||||
g_num_of_tb = atoll(arg);
|
||||
if (g_num_of_tb < 1) {
|
||||
warnPrint("minimal g_num_of_tb is %d\n", 1);
|
||||
g_num_of_tb = 1;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
g_num_of_rec = atoll(arg);
|
||||
if (g_num_of_rec < 2) {
|
||||
warnPrint("minimal g_num_of_rec is %d\n", 2);
|
||||
g_num_of_rec = 2;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -65,15 +73,32 @@ static void prepare_data(TAOS* taos) {
|
|||
usleep(100000);
|
||||
taos_select_db(taos, "test");
|
||||
|
||||
res = taos_query(taos, "create table meters(ts timestamp, f float, n int, b binary(20), c nchar(20)) tags(area int, city binary(20), dist nchar(20));");
|
||||
char command[1024] = {0};
|
||||
sprintf(command, "%s", "create table meters(ts timestamp, f float, n int, bin1 binary(20), c nchar(20), bin2 binary(20)) tags(area int, city binary(20), dist nchar(20), street binary(20));");
|
||||
res = taos_query(taos, command);
|
||||
if ((res) && (0 == taos_errno(res))) {
|
||||
okPrint("%s created\n", "meters");
|
||||
} else {
|
||||
errorPrint("%s() LN%d: %s\n",
|
||||
__func__, __LINE__, taos_errstr(res));
|
||||
taos_free_result(res);
|
||||
exit(1);
|
||||
}
|
||||
taos_free_result(res);
|
||||
|
||||
char command[1024] = {0};
|
||||
for (int64_t i = 0; i < g_num_of_tb; i ++) {
|
||||
// sprintf(command, "create table t%"PRId64" using meters tags(%"PRId64", '%s', '%s');",
|
||||
// i, i, (i%2)?"beijing":"shanghai", (i%2)?"朝阳区":"黄浦区");
|
||||
sprintf(command, "create table t%"PRId64" using meters tags(%"PRId64", '%s', '%s');",
|
||||
i, i, (i%2)?"beijing":"shanghai", (i%2)?"chaoyang":"huangpu");
|
||||
sprintf(command, "create table t%"PRId64" using meters "
|
||||
"tags(%"PRId64", '%s', '%s', '%s');",
|
||||
i, i, (i%2)?"beijing":"shanghai",
|
||||
(i%2)?"朝阳区":"黄浦区",
|
||||
(i%2)?"长安街":"中山路");
|
||||
/* sprintf(command, "create table t%"PRId64" using meters "
|
||||
"tags(%"PRId64", '%s', '%s', '%s');",
|
||||
i, i,
|
||||
(i%2)?"beijing":"shanghai",
|
||||
(i%2)?"chaoyang":"huangpu",
|
||||
(i%2?"changan street":"jianguo rd"));
|
||||
*/
|
||||
res = taos_query(taos, command);
|
||||
if ((res) && (0 == taos_errno(res))) {
|
||||
okPrint("t%" PRId64 " created\n", i);
|
||||
|
@ -86,11 +111,15 @@ static void prepare_data(TAOS* taos) {
|
|||
int64_t j = 0;
|
||||
int64_t total = 0;
|
||||
int64_t affected;
|
||||
for (; j < g_num_of_rec -1; j ++) {
|
||||
for (; j < g_num_of_rec -2; j ++) {
|
||||
sprintf(command, "insert into t%"PRId64" "
|
||||
"values(%" PRId64 ", %f, %"PRId64", '%c%d', '%c%d')",
|
||||
i, 1650000000000+j, (float)j, j, 'a'+(int)j%25, rand(),
|
||||
'z' - (int)j%25, rand());
|
||||
"values(%" PRId64 ", %f, %"PRId64", "
|
||||
"'%c%d', '%s%c%d', '%c%d')",
|
||||
i, 1650000000000+j, (float)j, j,
|
||||
'a'+(int)j%25, rand(),
|
||||
"涛思", 'z' - (int)j%25, rand(),
|
||||
'b' - (int)j%25, rand()
|
||||
);
|
||||
res = taos_query(taos, command);
|
||||
if ((res) && (0 == taos_errno(res))) {
|
||||
affected = taos_affected_rows(res);
|
||||
|
@ -101,8 +130,25 @@ static void prepare_data(TAOS* taos) {
|
|||
}
|
||||
taos_free_result(res);
|
||||
}
|
||||
sprintf(command, "insert into t%"PRId64" values(%" PRId64 ", NULL, NULL, NULL, NULL)",
|
||||
i, 1650000000000+j+1);
|
||||
sprintf(command, "insert into t%"PRId64" values(%" PRId64 ", "
|
||||
"NULL, NULL, NULL, NULL, NULL)",
|
||||
i, 1650000000000+j);
|
||||
res = taos_query(taos, command);
|
||||
if ((res) && (0 == taos_errno(res))) {
|
||||
affected = taos_affected_rows(res);
|
||||
total += affected;
|
||||
} else {
|
||||
errorPrint("%s() LN%d: %s\n",
|
||||
__func__, __LINE__, taos_errstr(res));
|
||||
}
|
||||
sprintf(command, "insert into t%"PRId64" "
|
||||
"values(%" PRId64 ", %f, %"PRId64", "
|
||||
"'%c%d', '%s%c%d', '%c%d')",
|
||||
i, 1650000000000+j+1, (float)j, j,
|
||||
'a'+(int)j%25, rand(),
|
||||
"数据", 'z' - (int)j%25, rand(),
|
||||
'b' - (int)j%25, rand()
|
||||
);
|
||||
res = taos_query(taos, command);
|
||||
if ((res) && (0 == taos_errno(res))) {
|
||||
affected = taos_affected_rows(res);
|
||||
|
@ -113,7 +159,8 @@ static void prepare_data(TAOS* taos) {
|
|||
}
|
||||
taos_free_result(res);
|
||||
|
||||
printf("insert %"PRId64" records into t%"PRId64", total affected rows: %"PRId64"\n", j, i, total);
|
||||
okPrint("insert %"PRId64" records into t%"PRId64", "
|
||||
"total affected rows: %"PRId64"\n", j, i, total);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -127,29 +174,107 @@ static int print_result(char *tbname, TAOS_RES* res, int block) {
|
|||
printf("fields[%d].name=%s, fields[%d].type=%d, fields[%d].bytes=%d\n",
|
||||
f, fields[f].name, f, fields[f].type, f, fields[f].bytes);
|
||||
}
|
||||
|
||||
if (block) {
|
||||
warnPrint("%s() LN%d, call taos_fetch_block()\n", __func__, __LINE__);
|
||||
warnPrint("%s", "call taos_fetch_block()\n");
|
||||
int rows = 0;
|
||||
while ((rows = taos_fetch_block(res, &row))) {
|
||||
int *lengths = taos_fetch_lengths(res);
|
||||
for (int f = 0; f < num_fields; f++) {
|
||||
if ((fields[f].type != TSDB_DATA_TYPE_VARCHAR)
|
||||
&& (fields[f].type != TSDB_DATA_TYPE_NCHAR)
|
||||
&& (fields[f].type != TSDB_DATA_TYPE_JSON)) {
|
||||
printf("col%d type is %d, no need get offset\n",
|
||||
f, fields[f].type);
|
||||
for (int64_t c = 0; c < rows; c++) {
|
||||
switch(fields[f].type) {
|
||||
case TSDB_DATA_TYPE_TIMESTAMP:
|
||||
if (taos_is_null(res, c, f)) {
|
||||
printf("col%d, row: %"PRId64" "
|
||||
"value: NULL\n", f, c);
|
||||
} else {
|
||||
printf("col%d, row: %"PRId64", "
|
||||
"value: %"PRId64"\n",
|
||||
f, c,
|
||||
*(int64_t*)(row[f]+c*sizeof(int64_t)));
|
||||
}
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_INT:
|
||||
if (taos_is_null(res, c, f)) {
|
||||
printf("col%d, row: %"PRId64" "
|
||||
"value: NULL\n", f, c);
|
||||
} else {
|
||||
printf("col%d, row: %"PRId64", "
|
||||
"value: %d\n",
|
||||
f, c,
|
||||
*(int32_t*)(row[f]+c*sizeof(int32_t)));
|
||||
}
|
||||
break;
|
||||
|
||||
case TSDB_DATA_TYPE_FLOAT:
|
||||
if (taos_is_null(res, c, f)) {
|
||||
printf("col%d, row: %"PRId64" "
|
||||
"value: NULL\n", f, c);
|
||||
} else {
|
||||
printf("col%d, row: %"PRId64", "
|
||||
"value: %f\n",
|
||||
f, c,
|
||||
*(float*)(row[f]+c*sizeof(float)));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("type: %d is not processed\n",
|
||||
fields[f].type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int *offsets = taos_get_column_data_offset(res, f);
|
||||
if (offsets) {
|
||||
for (int c = 0; c < rows; c++) {
|
||||
if (offsets[c] != -1) {
|
||||
int length = *(int16_t*)(row[f] + offsets[c]);
|
||||
char *buf = calloc(1, length + 1);
|
||||
strncpy(buf, (char *)(row[f] + offsets[c] + 2), length);
|
||||
printf("row: %d, col: %d, offset: %d, length: %d, content: %s\n",
|
||||
c, f, offsets[c], length, buf);
|
||||
free(buf);
|
||||
} else {
|
||||
printf("row: %d, col: %d, offset: -1, means content is NULL\n",
|
||||
c, f);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
errorPrint("%s() LN%d: col%d's offsets is NULL\n",
|
||||
__func__, __LINE__, f);
|
||||
}
|
||||
}
|
||||
}
|
||||
num_rows += rows;
|
||||
}
|
||||
} else {
|
||||
warnPrint("%s() LN%d, call taos_fetch_rows()\n", __func__, __LINE__);
|
||||
warnPrint("%s", "call taos_fetch_rows()\n");
|
||||
while ((row = taos_fetch_row(res))) {
|
||||
char temp[256] = {0};
|
||||
taos_print_row(temp, row, fields, num_fields);
|
||||
puts(temp);
|
||||
num_rows ++;
|
||||
|
||||
int* lengths = taos_fetch_lengths(res);
|
||||
if (lengths) {
|
||||
for (int c = 0; c < num_fields; c++) {
|
||||
printf("length of column %d is %d\n", c, lengths[c]);
|
||||
printf("row: %"PRId64", col: %d, is_null: %s, length of column %d is %d\n",
|
||||
num_rows, c,
|
||||
taos_is_null(res, num_rows, c)?"True":"False",
|
||||
c, lengths[c]);
|
||||
}
|
||||
} else {
|
||||
errorPrint("%s() LN%d: %s's lengths is NULL\n",
|
||||
__func__, __LINE__, tbname);
|
||||
}
|
||||
|
||||
num_rows ++;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,8 +297,8 @@ static void verify_query(TAOS* taos) {
|
|||
int field_count = taos_field_count(res);
|
||||
printf("field_count: %d\n", field_count);
|
||||
int64_t rows = print_result(tbname, res, i % 2);
|
||||
printf("rows is: %"PRId64"\n", rows);
|
||||
|
||||
okPrint("total query %s result rows is: %"PRId64"\n",
|
||||
tbname, rows);
|
||||
} else {
|
||||
errorPrint("%s() LN%d: %s\n",
|
||||
__func__, __LINE__, taos_errstr(res));
|
||||
|
@ -207,7 +332,7 @@ int main(int argc, char *argv[]) {
|
|||
verify_query(taos);
|
||||
|
||||
taos_close(taos);
|
||||
printf("done\n");
|
||||
okPrint("%s", "done\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1209,12 +1209,17 @@ typedef struct {
|
|||
int32_t code;
|
||||
} STaskDropRsp;
|
||||
|
||||
#define STREAM_TRIGGER_AT_ONCE 1
|
||||
#define STREAM_TRIGGER_WINDOW_CLOSE 2
|
||||
|
||||
typedef struct {
|
||||
char name[TSDB_TOPIC_FNAME_LEN];
|
||||
char outputSTbName[TSDB_TABLE_FNAME_LEN];
|
||||
int8_t igExists;
|
||||
char* sql;
|
||||
char* ast;
|
||||
int8_t triggerType;
|
||||
int64_t watermark;
|
||||
} SCMCreateStreamReq;
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -162,38 +162,39 @@ typedef struct {
|
|||
int32_t extendedRowSize;
|
||||
} SRowBuilder;
|
||||
|
||||
#define TD_ROW_HEAD_LEN (sizeof(STSRow))
|
||||
#define TD_ROW_HEAD_LEN (sizeof(STSRow))
|
||||
#define TD_ROW_NCOLS_LEN (sizeof(col_id_t))
|
||||
|
||||
#define TD_ROW_INFO(r) ((r)->info)
|
||||
#define TD_ROW_TYPE(r) ((r)->type)
|
||||
#define TD_ROW_DELETE(r) ((r)->del)
|
||||
#define TD_ROW_ENDIAN(r) ((r)->endian)
|
||||
#define TD_ROW_SVER(r) ((r)->sver)
|
||||
#define TD_ROW_NCOLS(r) ((r)->data) // only valid for SKvRow
|
||||
#define TD_ROW_DATA(r) ((r)->data)
|
||||
#define TD_ROW_LEN(r) ((r)->len)
|
||||
#define TD_ROW_KEY(r) ((r)->ts)
|
||||
#define TD_ROW_INFO(r) ((r)->info)
|
||||
#define TD_ROW_TYPE(r) ((r)->type)
|
||||
#define TD_ROW_DELETE(r) ((r)->del)
|
||||
#define TD_ROW_ENDIAN(r) ((r)->endian)
|
||||
#define TD_ROW_SVER(r) ((r)->sver)
|
||||
#define TD_ROW_NCOLS(r) ((r)->data) // only valid for SKvRow
|
||||
#define TD_ROW_DATA(r) ((r)->data)
|
||||
#define TD_ROW_LEN(r) ((r)->len)
|
||||
#define TD_ROW_KEY(r) ((r)->ts)
|
||||
#define TD_ROW_VER(r) ((r)->ver)
|
||||
#define TD_ROW_KEY_ADDR(r) (r)
|
||||
|
||||
// N.B. If without STSchema, getExtendedRowSize() is used to get the rowMaxBytes and
|
||||
// (int32_t)ceil((double)nCols/TD_VTYPE_PARTS) should be added if TD_SUPPORT_BITMAP defined.
|
||||
#define TD_ROW_MAX_BYTES_FROM_SCHEMA(s) (schemaTLen(s) + TD_ROW_HEAD_LEN)
|
||||
|
||||
#define TD_ROW_SET_INFO(r, i) (TD_ROW_INFO(r) = (i))
|
||||
#define TD_ROW_SET_TYPE(r, t) (TD_ROW_TYPE(r) = (t))
|
||||
#define TD_ROW_SET_DELETE(r) (TD_ROW_DELETE(r) = 1)
|
||||
#define TD_ROW_SET_SVER(r, v) (TD_ROW_SVER(r) = (v))
|
||||
#define TD_ROW_SET_LEN(r, l) (TD_ROW_LEN(r) = (l))
|
||||
#define TD_ROW_SET_INFO(r, i) (TD_ROW_INFO(r) = (i))
|
||||
#define TD_ROW_SET_TYPE(r, t) (TD_ROW_TYPE(r) = (t))
|
||||
#define TD_ROW_SET_DELETE(r) (TD_ROW_DELETE(r) = 1)
|
||||
#define TD_ROW_SET_SVER(r, v) (TD_ROW_SVER(r) = (v))
|
||||
#define TD_ROW_SET_LEN(r, l) (TD_ROW_LEN(r) = (l))
|
||||
#define TD_ROW_SET_NCOLS(r, n) (*(col_id_t *)TD_ROW_NCOLS(r) = (n))
|
||||
|
||||
#define TD_ROW_IS_DELETED(r) (TD_ROW_DELETE(r) == 1)
|
||||
#define TD_IS_TP_ROW(r) (TD_ROW_TYPE(r) == TD_ROW_TP)
|
||||
#define TD_IS_KV_ROW(r) (TD_ROW_TYPE(r) == TD_ROW_KV)
|
||||
#define TD_IS_TP_ROW_T(t) ((t) == TD_ROW_TP)
|
||||
#define TD_IS_KV_ROW_T(t) ((t) == TD_ROW_KV)
|
||||
#define TD_IS_TP_ROW(r) (TD_ROW_TYPE(r) == TD_ROW_TP)
|
||||
#define TD_IS_KV_ROW(r) (TD_ROW_TYPE(r) == TD_ROW_KV)
|
||||
#define TD_IS_TP_ROW_T(t) ((t) == TD_ROW_TP)
|
||||
#define TD_IS_KV_ROW_T(t) ((t) == TD_ROW_KV)
|
||||
|
||||
#define TD_BOOL_STR(b) ((b) ? "true" : "false")
|
||||
#define TD_BOOL_STR(b) ((b) ? "true" : "false")
|
||||
#define isUtilizeKVRow(k, d) ((k) < ((d)*KVRatioConvert))
|
||||
|
||||
#define TD_ROW_COL_IDX(r) POINTER_SHIFT(TD_ROW_DATA(r), sizeof(col_id_t))
|
||||
|
@ -221,8 +222,10 @@ static FORCE_INLINE int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, T
|
|||
static FORCE_INLINE int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT valType);
|
||||
static FORCE_INLINE int32_t tdSetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT valType, int8_t bitmapMode);
|
||||
int32_t tdSetBitmapValTypeN(void *pBitmap, int16_t nEle, TDRowValT valType, int8_t bitmapMode);
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeI(void *pBitmap, int16_t colIdx, TDRowValT *pValType);
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT *pValType);
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeI(const void *pBitmap, int16_t colIdx, TDRowValT *pValType);
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pValType);
|
||||
static FORCE_INLINE int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValType, int8_t bitmapMode);
|
||||
static FORCE_INLINE bool tdIsBitmapValTypeNormII(const void *pBitmap, int16_t idx);
|
||||
int32_t tdAppendValToDataCol(SDataCol *pCol, TDRowValT valType, const void *val, int32_t numOfRows, int32_t maxPoints,
|
||||
int8_t bitmapMode);
|
||||
static FORCE_INLINE int32_t tdAppendColValToTpRow(SRowBuilder *pBuilder, TDRowValT valType, const void *val,
|
||||
|
@ -324,7 +327,16 @@ static FORCE_INLINE int32_t tdSetBitmapValTypeII(void *pBitmap, int16_t colIdx,
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tdGetBitmapValType(void *pBitmap, int16_t colIdx, TDRowValT *pValType, int8_t bitmapMode) {
|
||||
static FORCE_INLINE bool tdIsBitmapValTypeNormII(const void *pBitmap, int16_t idx) {
|
||||
TDRowValT valType = 0;
|
||||
tdGetBitmapValTypeII(pBitmap, idx, &valType);
|
||||
if (tdValTypeIsNorm(valType)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static FORCE_INLINE int32_t tdGetBitmapValType(const void *pBitmap, int16_t colIdx, TDRowValT *pValType, int8_t bitmapMode) {
|
||||
switch (bitmapMode) {
|
||||
case 0:
|
||||
tdGetBitmapValTypeII(pBitmap, colIdx, pValType);
|
||||
|
@ -349,7 +361,7 @@ static FORCE_INLINE int32_t tdGetBitmapValType(void *pBitmap, int16_t colIdx, TD
|
|||
* @param pValType
|
||||
* @return FORCE_INLINE
|
||||
*/
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeII(void *pBitmap, int16_t colIdx, TDRowValT *pValType) {
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeII(const void *pBitmap, int16_t colIdx, TDRowValT *pValType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
|
@ -448,7 +460,7 @@ static FORCE_INLINE int32_t tdSetBitmapValTypeI(void *pBitmap, int16_t colIdx, T
|
|||
* @param pValType
|
||||
* @return FORCE_INLINE
|
||||
*/
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeI(void *pBitmap, int16_t colIdx, TDRowValT *pValType) {
|
||||
static FORCE_INLINE int32_t tdGetBitmapValTypeI(const void *pBitmap, int16_t colIdx, TDRowValT *pValType) {
|
||||
if (!pBitmap || colIdx < 0) {
|
||||
TASSERT(0);
|
||||
terrno = TSDB_CODE_INVALID_PARA;
|
||||
|
|
|
@ -171,60 +171,70 @@
|
|||
#define TK_BUFSIZE 153
|
||||
#define TK_STREAM 154
|
||||
#define TK_INTO 155
|
||||
#define TK_KILL 156
|
||||
#define TK_CONNECTION 157
|
||||
#define TK_MERGE 158
|
||||
#define TK_VGROUP 159
|
||||
#define TK_REDISTRIBUTE 160
|
||||
#define TK_SPLIT 161
|
||||
#define TK_SYNCDB 162
|
||||
#define TK_NULL 163
|
||||
#define TK_FIRST 164
|
||||
#define TK_LAST 165
|
||||
#define TK_NOW 166
|
||||
#define TK_TODAY 167
|
||||
#define TK_CAST 168
|
||||
#define TK_ROWTS 169
|
||||
#define TK_TBNAME 170
|
||||
#define TK_QSTARTTS 171
|
||||
#define TK_QENDTS 172
|
||||
#define TK_WSTARTTS 173
|
||||
#define TK_WENDTS 174
|
||||
#define TK_WDURATION 175
|
||||
#define TK_BETWEEN 176
|
||||
#define TK_IS 177
|
||||
#define TK_NK_LT 178
|
||||
#define TK_NK_GT 179
|
||||
#define TK_NK_LE 180
|
||||
#define TK_NK_GE 181
|
||||
#define TK_NK_NE 182
|
||||
#define TK_MATCH 183
|
||||
#define TK_NMATCH 184
|
||||
#define TK_JOIN 185
|
||||
#define TK_INNER 186
|
||||
#define TK_SELECT 187
|
||||
#define TK_DISTINCT 188
|
||||
#define TK_WHERE 189
|
||||
#define TK_PARTITION 190
|
||||
#define TK_BY 191
|
||||
#define TK_SESSION 192
|
||||
#define TK_STATE_WINDOW 193
|
||||
#define TK_SLIDING 194
|
||||
#define TK_FILL 195
|
||||
#define TK_VALUE 196
|
||||
#define TK_NONE 197
|
||||
#define TK_PREV 198
|
||||
#define TK_LINEAR 199
|
||||
#define TK_NEXT 200
|
||||
#define TK_GROUP 201
|
||||
#define TK_HAVING 202
|
||||
#define TK_ORDER 203
|
||||
#define TK_SLIMIT 204
|
||||
#define TK_SOFFSET 205
|
||||
#define TK_LIMIT 206
|
||||
#define TK_OFFSET 207
|
||||
#define TK_ASC 208
|
||||
#define TK_NULLS 209
|
||||
#define TK_TRIGGER 156
|
||||
#define TK_AT_ONCE 157
|
||||
#define TK_WINDOW_CLOSE 158
|
||||
#define TK_WATERMARK 159
|
||||
#define TK_KILL 160
|
||||
#define TK_CONNECTION 161
|
||||
#define TK_MERGE 162
|
||||
#define TK_VGROUP 163
|
||||
#define TK_REDISTRIBUTE 164
|
||||
#define TK_SPLIT 165
|
||||
#define TK_SYNCDB 166
|
||||
#define TK_NULL 167
|
||||
#define TK_NK_QUESTION 168
|
||||
#define TK_NK_ARROW 169
|
||||
#define TK_ROWTS 170
|
||||
#define TK_TBNAME 171
|
||||
#define TK_QSTARTTS 172
|
||||
#define TK_QENDTS 173
|
||||
#define TK_WSTARTTS 174
|
||||
#define TK_WENDTS 175
|
||||
#define TK_WDURATION 176
|
||||
#define TK_CAST 177
|
||||
#define TK_NOW 178
|
||||
#define TK_TODAY 179
|
||||
#define TK_TIMEZONE 180
|
||||
#define TK_COUNT 181
|
||||
#define TK_FIRST 182
|
||||
#define TK_LAST 183
|
||||
#define TK_LAST_ROW 184
|
||||
#define TK_BETWEEN 185
|
||||
#define TK_IS 186
|
||||
#define TK_NK_LT 187
|
||||
#define TK_NK_GT 188
|
||||
#define TK_NK_LE 189
|
||||
#define TK_NK_GE 190
|
||||
#define TK_NK_NE 191
|
||||
#define TK_MATCH 192
|
||||
#define TK_NMATCH 193
|
||||
#define TK_CONTAINS 194
|
||||
#define TK_JOIN 195
|
||||
#define TK_INNER 196
|
||||
#define TK_SELECT 197
|
||||
#define TK_DISTINCT 198
|
||||
#define TK_WHERE 199
|
||||
#define TK_PARTITION 200
|
||||
#define TK_BY 201
|
||||
#define TK_SESSION 202
|
||||
#define TK_STATE_WINDOW 203
|
||||
#define TK_SLIDING 204
|
||||
#define TK_FILL 205
|
||||
#define TK_VALUE 206
|
||||
#define TK_NONE 207
|
||||
#define TK_PREV 208
|
||||
#define TK_LINEAR 209
|
||||
#define TK_NEXT 210
|
||||
#define TK_GROUP 211
|
||||
#define TK_HAVING 212
|
||||
#define TK_ORDER 213
|
||||
#define TK_SLIMIT 214
|
||||
#define TK_SOFFSET 215
|
||||
#define TK_LIMIT 216
|
||||
#define TK_OFFSET 217
|
||||
#define TK_ASC 218
|
||||
#define TK_NULLS 219
|
||||
|
||||
#define TK_NK_SPACE 300
|
||||
#define TK_NK_COMMENT 301
|
||||
|
@ -233,7 +243,6 @@
|
|||
#define TK_NK_OCT 304 // oct number
|
||||
#define TK_NK_BIN 305 // bin format data 0b111
|
||||
#define TK_NK_FILE 306
|
||||
#define TK_NK_QUESTION 307 // denoting the placeholder of "?",when invoking statement bind query
|
||||
|
||||
#define TK_NK_BITNOT 501
|
||||
#define TK_INSERT 502
|
||||
|
|
|
@ -248,7 +248,7 @@ typedef struct tDataTypeDescriptor {
|
|||
int32_t outputSize, char algorithm, char *const buffer, int32_t bufferSize);
|
||||
int32_t (*decompFunc)(const char *const input, int32_t compressedSize, const int32_t nelements, char *const output,
|
||||
int32_t outputSize, char algorithm, char *const buffer, int32_t bufferSize);
|
||||
void (*statisFunc)(const void *pData, int32_t numofrow, int64_t *min, int64_t *max, int64_t *sum, int16_t *minindex,
|
||||
void (*statisFunc)(const void* pBitmap, const void *pData, int32_t numofrow, int64_t *min, int64_t *max, int64_t *sum, int16_t *minindex,
|
||||
int16_t *maxindex, int16_t *numofnull);
|
||||
} tDataTypeDescriptor;
|
||||
|
||||
|
|
|
@ -137,12 +137,13 @@ bool fmIsWindowPseudoColumnFunc(int32_t funcId);
|
|||
bool fmIsWindowClauseFunc(int32_t funcId);
|
||||
bool fmIsSpecialDataRequiredFunc(int32_t funcId);
|
||||
bool fmIsDynamicScanOptimizedFunc(int32_t funcId);
|
||||
bool fmIsMultiResFunc(int32_t funcId);
|
||||
|
||||
typedef enum EFuncDataRequired {
|
||||
FUNC_DATA_REQUIRED_ALL_NEEDED = 1,
|
||||
FUNC_DATA_REQUIRED_STATIS_NEEDED,
|
||||
FUNC_DATA_REQUIRED_NO_NEEDED,
|
||||
FUNC_DATA_REQUIRED_DISCARD
|
||||
FUNC_DATA_REQUIRED_DATA_LOAD = 1,
|
||||
FUNC_DATA_REQUIRED_STATIS_LOAD,
|
||||
FUNC_DATA_REQUIRED_NOT_LOAD,
|
||||
FUNC_DATA_REQUIRED_FILTEROUT,
|
||||
} EFuncDataRequired;
|
||||
|
||||
EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
||||
|
|
|
@ -272,6 +272,28 @@ typedef struct SKillStmt {
|
|||
int32_t targetId;
|
||||
} SKillStmt;
|
||||
|
||||
typedef struct SStreamOptions {
|
||||
ENodeType type;
|
||||
int8_t triggerType;
|
||||
SNode* pWatermark;
|
||||
} SStreamOptions;
|
||||
|
||||
typedef struct SCreateStreamStmt {
|
||||
ENodeType type;
|
||||
char streamName[TSDB_TABLE_NAME_LEN];
|
||||
char targetDbName[TSDB_DB_NAME_LEN];
|
||||
char targetTabName[TSDB_TABLE_NAME_LEN];
|
||||
bool ignoreExists;
|
||||
SStreamOptions* pOptions;
|
||||
SNode* pQuery;
|
||||
} SCreateStreamStmt;
|
||||
|
||||
typedef struct SDropStreamStmt {
|
||||
ENodeType type;
|
||||
char streamName[TSDB_TABLE_NAME_LEN];
|
||||
bool ignoreNotExists;
|
||||
} SDropStreamStmt;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -80,6 +80,7 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_TABLE_OPTIONS,
|
||||
QUERY_NODE_INDEX_OPTIONS,
|
||||
QUERY_NODE_EXPLAIN_OPTIONS,
|
||||
QUERY_NODE_STREAM_OPTIONS,
|
||||
|
||||
// Statement nodes are used in parser and planner module.
|
||||
QUERY_NODE_SET_OPERATOR,
|
||||
|
@ -151,6 +152,12 @@ typedef enum ENodeType {
|
|||
QUERY_NODE_SHOW_CONNECTIONS_STMT,
|
||||
QUERY_NODE_SHOW_QUERIES_STMT,
|
||||
QUERY_NODE_SHOW_VNODES_STMT,
|
||||
QUERY_NODE_SHOW_APPS_STMT,
|
||||
QUERY_NODE_SHOW_SCORES_STMT,
|
||||
QUERY_NODE_SHOW_VARIABLE_STMT,
|
||||
QUERY_NODE_SHOW_CREATE_DATABASE_STMT,
|
||||
QUERY_NODE_SHOW_CREATE_TABLE_STMT,
|
||||
QUERY_NODE_SHOW_CREATE_STABLE_STMT,
|
||||
QUERY_NODE_KILL_CONNECTION_STMT,
|
||||
QUERY_NODE_KILL_QUERY_STMT,
|
||||
|
||||
|
|
|
@ -53,6 +53,11 @@ typedef struct SScanLogicNode {
|
|||
double ratio;
|
||||
SNodeList* pDynamicScanFuncs;
|
||||
int32_t dataRequired;
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
} SScanLogicNode;
|
||||
|
||||
typedef struct SJoinLogicNode {
|
||||
|
@ -109,6 +114,8 @@ typedef struct SWindowLogicNode {
|
|||
int64_t sessionGap;
|
||||
SNode* pTspk;
|
||||
SNode* pStateExpr;
|
||||
int8_t triggerType;
|
||||
int64_t watermark;
|
||||
} SWindowLogicNode;
|
||||
|
||||
typedef struct SSortLogicNode {
|
||||
|
@ -206,6 +213,11 @@ typedef struct STableScanPhysiNode {
|
|||
double ratio;
|
||||
int32_t dataRequired;
|
||||
SNodeList* pDynamicScanFuncs;
|
||||
int64_t interval;
|
||||
int64_t offset;
|
||||
int64_t sliding;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
} STableScanPhysiNode;
|
||||
|
||||
typedef STableScanPhysiNode STableSeqScanPhysiNode;
|
||||
|
@ -251,6 +263,8 @@ typedef struct SWinodwPhysiNode {
|
|||
SNodeList* pExprs; // these are expression list of parameter expression of function
|
||||
SNodeList* pFuncs;
|
||||
SNode* pTspk; // timestamp primary key
|
||||
int8_t triggerType;
|
||||
int64_t watermark;
|
||||
} SWinodwPhysiNode;
|
||||
|
||||
typedef struct SIntervalPhysiNode {
|
||||
|
@ -260,7 +274,6 @@ typedef struct SIntervalPhysiNode {
|
|||
int64_t sliding;
|
||||
int8_t intervalUnit;
|
||||
int8_t slidingUnit;
|
||||
uint8_t precision;
|
||||
SFillNode* pFill;
|
||||
} SIntervalPhysiNode;
|
||||
|
||||
|
|
|
@ -57,6 +57,7 @@ typedef enum EColumnType {
|
|||
typedef struct SColumnNode {
|
||||
SExprNode node; // QUERY_NODE_COLUMN
|
||||
uint64_t tableId;
|
||||
int8_t tableType;
|
||||
col_id_t colId;
|
||||
EColumnType colType; // column or tag
|
||||
char dbName[TSDB_DB_NAME_LEN];
|
||||
|
@ -196,8 +197,8 @@ typedef struct SStateWindowNode {
|
|||
|
||||
typedef struct SSessionWindowNode {
|
||||
ENodeType type; // QUERY_NODE_SESSION_WINDOW
|
||||
SNode* pCol; // timestamp primary key
|
||||
SNode* pGap; // gap between two session window(in microseconds)
|
||||
SColumnNode* pCol; // timestamp primary key
|
||||
SValueNode* pGap; // gap between two session window(in microseconds)
|
||||
} SSessionWindowNode;
|
||||
|
||||
typedef struct SIntervalWindowNode {
|
||||
|
|
|
@ -30,6 +30,8 @@ typedef struct SPlanContext {
|
|||
bool topicQuery;
|
||||
bool streamQuery;
|
||||
bool showRewrite;
|
||||
int8_t triggerType;
|
||||
int64_t watermark;
|
||||
} SPlanContext;
|
||||
|
||||
// Create the physical plan for the query, according to the AST.
|
||||
|
|
|
@ -80,6 +80,7 @@ int32_t timeTruncateFunction(SScalarParam *pInput, int32_t inputNum, SScalarPara
|
|||
int32_t timeDiffFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t nowFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t todayFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
int32_t timezoneFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput);
|
||||
|
||||
bool getTimePseudoFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
|
||||
|
|
|
@ -61,16 +61,16 @@ extern "C" {
|
|||
} \
|
||||
}
|
||||
|
||||
#define WAL_HEAD_VER 0
|
||||
#define WAL_HEAD_VER 0
|
||||
#define WAL_NOSUFFIX_LEN 20
|
||||
#define WAL_SUFFIX_AT (WAL_NOSUFFIX_LEN + 1)
|
||||
#define WAL_LOG_SUFFIX "log"
|
||||
#define WAL_SUFFIX_AT (WAL_NOSUFFIX_LEN + 1)
|
||||
#define WAL_LOG_SUFFIX "log"
|
||||
#define WAL_INDEX_SUFFIX "idx"
|
||||
#define WAL_REFRESH_MS 1000
|
||||
#define WAL_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalHead))
|
||||
#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12)
|
||||
#define WAL_FILE_LEN (WAL_PATH_LEN + 32)
|
||||
#define WAL_MAGIC 0xFAFBFCFDULL
|
||||
#define WAL_REFRESH_MS 1000
|
||||
#define WAL_MAX_SIZE (TSDB_MAX_WAL_SIZE + sizeof(SWalHead))
|
||||
#define WAL_PATH_LEN (TSDB_FILENAME_LEN + 12)
|
||||
#define WAL_FILE_LEN (WAL_PATH_LEN + 32)
|
||||
#define WAL_MAGIC 0xFAFBFCFDULL
|
||||
|
||||
#define WAL_CUR_FAILED 1
|
||||
|
||||
|
|
|
@ -579,7 +579,7 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_INVALID_PORT TAOS_DEF_ERROR_CODE(0, 0x2612)
|
||||
#define TSDB_CODE_PAR_INVALID_ENDPOINT TAOS_DEF_ERROR_CODE(0, 0x2613)
|
||||
#define TSDB_CODE_PAR_EXPRIE_STATEMENT TAOS_DEF_ERROR_CODE(0, 0x2614)
|
||||
#define TSDB_CODE_PAR_INTERVAL_VALUE_TOO_SMALL TAOS_DEF_ERROR_CODE(0, 0x2615)
|
||||
#define TSDB_CODE_PAR_INTER_VALUE_TOO_SMALL TAOS_DEF_ERROR_CODE(0, 0x2615)
|
||||
#define TSDB_CODE_PAR_DB_NOT_SPECIFIED TAOS_DEF_ERROR_CODE(0, 0x2616)
|
||||
#define TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME TAOS_DEF_ERROR_CODE(0, 0x2617)
|
||||
#define TSDB_CODE_PAR_CORRESPONDING_STABLE_ERR TAOS_DEF_ERROR_CODE(0, 0x2618)
|
||||
|
@ -597,6 +597,18 @@ int32_t* taosGetErrno();
|
|||
#define TSDB_CODE_PAR_GROUPBY_WINDOW_COEXIST TAOS_DEF_ERROR_CODE(0, 0x2624)
|
||||
#define TSDB_CODE_PAR_INVALID_OPTION_UNIT TAOS_DEF_ERROR_CODE(0, 0x2625)
|
||||
#define TSDB_CODE_PAR_INVALID_KEEP_UNIT TAOS_DEF_ERROR_CODE(0, 0x2626)
|
||||
#define TSDB_CODE_PAR_AGG_FUNC_NESTING TAOS_DEF_ERROR_CODE(0, 0x2627)
|
||||
#define TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE TAOS_DEF_ERROR_CODE(0, 0x2628)
|
||||
#define TSDB_CODE_PAR_INVALID_STATE_WIN_COL TAOS_DEF_ERROR_CODE(0, 0x2629)
|
||||
#define TSDB_CODE_PAR_INVALID_STATE_WIN_TABLE TAOS_DEF_ERROR_CODE(0, 0x262A)
|
||||
#define TSDB_CODE_PAR_INTER_SESSION_GAP TAOS_DEF_ERROR_CODE(0, 0x262B)
|
||||
#define TSDB_CODE_PAR_INTER_SESSION_COL TAOS_DEF_ERROR_CODE(0, 0x262C)
|
||||
#define TSDB_CODE_PAR_INTER_OFFSET_NEGATIVE TAOS_DEF_ERROR_CODE(0, 0x262D)
|
||||
#define TSDB_CODE_PAR_INTER_OFFSET_UNIT TAOS_DEF_ERROR_CODE(0, 0x262E)
|
||||
#define TSDB_CODE_PAR_INTER_OFFSET_TOO_BIG TAOS_DEF_ERROR_CODE(0, 0x262F)
|
||||
#define TSDB_CODE_PAR_INTER_SLIDING_UNIT TAOS_DEF_ERROR_CODE(0, 0x2630)
|
||||
#define TSDB_CODE_PAR_INTER_SLIDING_TOO_BIG TAOS_DEF_ERROR_CODE(0, 0x2631)
|
||||
#define TSDB_CODE_PAR_INTER_SLIDING_TOO_SMALL TAOS_DEF_ERROR_CODE(0, 0x2632)
|
||||
|
||||
//planner
|
||||
#define TSDB_CODE_PLAN_INTERNAL_ERROR TAOS_DEF_ERROR_CODE(0, 0x2700)
|
||||
|
|
|
@ -0,0 +1,657 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# This file is used to install TAOS time-series database on linux systems. The operating system
|
||||
# is required to use systemd to manage services at boot
|
||||
|
||||
set -e
|
||||
#set -x
|
||||
|
||||
# -----------------------Variables definition
|
||||
source_dir=$1
|
||||
binary_dir=$2
|
||||
osType=$3
|
||||
verNumber=$4
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
script_dir=$(dirname $(readlink -f "$0"))
|
||||
else
|
||||
script_dir=${source_dir}/packaging/tools
|
||||
fi
|
||||
|
||||
# Dynamic directory
|
||||
clientName="taos"
|
||||
serverName="taosd"
|
||||
logDir="/var/log/taos"
|
||||
dataDir="/var/lib/taos"
|
||||
configDir="/etc/taos"
|
||||
configFile="taos.cfg"
|
||||
installDir="/usr/local/taos"
|
||||
productName="TDengine"
|
||||
emailName="taosdata.com"
|
||||
uninstallScript="rmtaos"
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
data_dir=${dataDir}
|
||||
log_dir=${logDir}
|
||||
|
||||
cfg_install_dir=${configDir}
|
||||
|
||||
bin_link_dir="/usr/bin"
|
||||
lib_link_dir="/usr/lib"
|
||||
lib64_link_dir="/usr/lib64"
|
||||
inc_link_dir="/usr/include"
|
||||
|
||||
install_main_dir=${installDir}
|
||||
|
||||
bin_dir="${installDir}/bin"
|
||||
else
|
||||
data_dir="/usr/local${dataDir}"
|
||||
log_dir="/usr/local${logDir}"
|
||||
|
||||
cfg_install_dir="/usr/local${configDir}"
|
||||
|
||||
bin_link_dir="/usr/local/bin"
|
||||
lib_link_dir="/usr/local/lib"
|
||||
inc_link_dir="/usr/local/include"
|
||||
|
||||
install_main_dir="/usr/local/Cellar/tdengine/${verNumber}"
|
||||
install_main_2_dir="/usr/local/Cellar/tdengine@${verNumber}/${verNumber}"
|
||||
|
||||
bin_dir="/usr/local/Cellar/tdengine/${verNumber}/bin"
|
||||
bin_2_dir="/usr/local/Cellar/tdengine@${verNumber}/${verNumber}/bin"
|
||||
fi
|
||||
|
||||
service_config_dir="/etc/systemd/system"
|
||||
|
||||
# Color setting
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[1;32m'
|
||||
GREEN_DARK='\033[0;32m'
|
||||
GREEN_UNDERLINE='\033[4;32m'
|
||||
NC='\033[0m'
|
||||
|
||||
csudo=""
|
||||
|
||||
service_mod=2
|
||||
os_type=0
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
if command -v sudo >/dev/null; then
|
||||
csudo="sudo "
|
||||
fi
|
||||
initd_mod=0
|
||||
if pidof systemd &>/dev/null; then
|
||||
service_mod=0
|
||||
elif $(which service &>/dev/null); then
|
||||
service_mod=1
|
||||
service_config_dir="/etc/init.d"
|
||||
if $(which chkconfig &>/dev/null); then
|
||||
initd_mod=1
|
||||
elif $(which insserv &>/dev/null); then
|
||||
initd_mod=2
|
||||
elif $(which update-rc.d &>/dev/null); then
|
||||
initd_mod=3
|
||||
else
|
||||
service_mod=2
|
||||
fi
|
||||
else
|
||||
service_mod=2
|
||||
fi
|
||||
|
||||
# get the operating system type for using the corresponding init file
|
||||
# ubuntu/debian(deb), centos/fedora(rpm), others: opensuse, redhat, ..., no verification
|
||||
#osinfo=$(awk -F= '/^NAME/{print $2}' /etc/os-release)
|
||||
osinfo=$(cat /etc/os-release | grep "NAME" | cut -d '"' -f2)
|
||||
#echo "osinfo: ${osinfo}"
|
||||
if echo $osinfo | grep -qwi "ubuntu"; then
|
||||
echo "this is ubuntu system"
|
||||
os_type=1
|
||||
elif echo $osinfo | grep -qwi "debian"; then
|
||||
echo "this is debian system"
|
||||
os_type=1
|
||||
elif echo $osinfo | grep -qwi "Kylin"; then
|
||||
echo "this is Kylin system"
|
||||
os_type=1
|
||||
elif echo $osinfo | grep -qwi "centos"; then
|
||||
echo "this is centos system"
|
||||
os_type=2
|
||||
elif echo $osinfo | grep -qwi "fedora"; then
|
||||
echo "this is fedora system"
|
||||
os_type=2
|
||||
else
|
||||
echo "${osinfo}: This is an officially unverified linux system, If there are any problems with the installation and operation, "
|
||||
echo "please feel free to contact ${emailName} for support."
|
||||
os_type=1
|
||||
fi
|
||||
fi
|
||||
|
||||
function kill_taosadapter() {
|
||||
pid=$(ps -ef | grep "taosadapter" | grep -v "grep" | awk '{print $2}')
|
||||
if [ -n "$pid" ]; then
|
||||
${csudo}kill -9 $pid || :
|
||||
fi
|
||||
}
|
||||
|
||||
function kill_taosd() {
|
||||
ps -ef | grep ${serverName}
|
||||
pid=$(ps -ef | grep -w ${serverName} | grep -v "grep" | awk '{print $2}')
|
||||
if [ -n "$pid" ]; then
|
||||
${csudo}kill -9 $pid || :
|
||||
fi
|
||||
}
|
||||
|
||||
function install_main_path() {
|
||||
#create install main dir and all sub dir
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}rm -rf ${install_main_dir} || :
|
||||
${csudo}mkdir -p ${install_main_dir}
|
||||
${csudo}mkdir -p ${install_main_dir}/cfg
|
||||
${csudo}mkdir -p ${install_main_dir}/bin
|
||||
# ${csudo}mkdir -p ${install_main_dir}/connector
|
||||
${csudo}mkdir -p ${install_main_dir}/driver
|
||||
${csudo}mkdir -p ${install_main_dir}/examples
|
||||
${csudo}mkdir -p ${install_main_dir}/include
|
||||
# ${csudo}mkdir -p ${install_main_dir}/init.d
|
||||
else
|
||||
${csudo}rm -rf ${install_main_dir} || ${csudo}rm -rf ${install_main_2_dir} || :
|
||||
${csudo}mkdir -p ${install_main_dir} || ${csudo}mkdir -p ${install_main_2_dir}
|
||||
${csudo}mkdir -p ${install_main_dir}/cfg || ${csudo}mkdir -p ${install_main_2_dir}/cfg
|
||||
${csudo}mkdir -p ${install_main_dir}/bin || ${csudo}mkdir -p ${install_main_2_dir}/bin
|
||||
# ${csudo}mkdir -p ${install_main_dir}/connector || ${csudo}mkdir -p ${install_main_2_dir}/connector
|
||||
${csudo}mkdir -p ${install_main_dir}/driver || ${csudo}mkdir -p ${install_main_2_dir}/driver
|
||||
${csudo}mkdir -p ${install_main_dir}/examples || ${csudo}mkdir -p ${install_main_2_dir}/examples
|
||||
${csudo}mkdir -p ${install_main_dir}/include || ${csudo}mkdir -p ${install_main_2_dir}/include
|
||||
fi
|
||||
}
|
||||
|
||||
function install_bin() {
|
||||
# Remove links
|
||||
${csudo}rm -f ${bin_link_dir}/${clientName} || :
|
||||
${csudo}rm -f ${bin_link_dir}/${serverName} || :
|
||||
${csudo}rm -f ${bin_link_dir}/taosadapter || :
|
||||
${csudo}rm -f ${bin_link_dir}/taosdemo || :
|
||||
${csudo}rm -f ${bin_link_dir}/taosdump || :
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}rm -f ${bin_link_dir}/perfMonitor || :
|
||||
${csudo}rm -f ${bin_link_dir}/set_core || :
|
||||
${csudo}rm -f ${bin_link_dir}/run_taosd_and_taosadapter.sh || :
|
||||
${csudo}rm -f ${bin_link_dir}/${uninstallScript} || :
|
||||
|
||||
${csudo}cp -r ${binary_dir}/build/bin/${clientName} ${install_main_dir}/bin || :
|
||||
[ -f ${binary_dir}/build/bin/taosBenchmark ] && ${csudo}cp -r ${binary_dir}/build/bin/taosBenchmark ${install_main_dir}/bin || :
|
||||
[ -f ${install_main_dir}/bin/taosBenchmark ] && ${csudo}ln -sf ${install_main_dir}/bin/taosBenchmark ${install_main_dir}/bin/taosdemo || :
|
||||
[ -f ${binary_dir}/build/bin/taosdump ] && ${csudo}cp -r ${binary_dir}/build/bin/taosdump ${install_main_dir}/bin || :
|
||||
[ -f ${binary_dir}/build/bin/taosadapter ] && ${csudo}cp -r ${binary_dir}/build/bin/taosadapter ${install_main_dir}/bin || :
|
||||
${csudo}cp -r ${binary_dir}/build/bin/${serverName} ${install_main_dir}/bin || :
|
||||
${csudo}cp -r ${binary_dir}/build/bin/tarbitrator ${install_main_dir}/bin || :
|
||||
|
||||
${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin || :
|
||||
${csudo}cp -r ${script_dir}/remove.sh ${install_main_dir}/bin || :
|
||||
${csudo}cp -r ${script_dir}/set_core.sh ${install_main_dir}/bin || :
|
||||
${csudo}cp -r ${script_dir}/run_taosd_and_taosadapter.sh ${install_main_dir}/bin || :
|
||||
${csudo}cp -r ${script_dir}/startPre.sh ${install_main_dir}/bin || :
|
||||
|
||||
${csudo}chmod 0555 ${install_main_dir}/bin/*
|
||||
#Make link
|
||||
[ -x ${install_main_dir}/bin/${clientName} ] && ${csudo}ln -s ${install_main_dir}/bin/${clientName} ${bin_link_dir}/${clientName} || :
|
||||
[ -x ${install_main_dir}/bin/${serverName} ] && ${csudo}ln -s ${install_main_dir}/bin/${serverName} ${bin_link_dir}/${serverName} || :
|
||||
[ -x ${install_main_dir}/bin/taosadapter ] && ${csudo}ln -s ${install_main_dir}/bin/taosadapter ${bin_link_dir}/taosadapter || :
|
||||
[ -x ${install_main_dir}/bin/taosdump ] && ${csudo}ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || :
|
||||
[ -x ${install_main_dir}/bin/taosdemo ] && ${csudo}ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || :
|
||||
[ -x ${install_main_dir}/bin/perfMonitor ] && ${csudo}ln -s ${install_main_dir}/bin/perfMonitor ${bin_link_dir}/perfMonitor || :
|
||||
[ -x ${install_main_dir}/set_core.sh ] && ${csudo}ln -s ${install_main_dir}/bin/set_core.sh ${bin_link_dir}/set_core || :
|
||||
[ -x ${install_main_dir}/run_taosd_and_taosadapter.sh ] && ${csudo}ln -s ${install_main_dir}/bin/run_taosd_and_taosadapter.sh ${bin_link_dir}/run_taosd_and_taosadapter.sh || :
|
||||
[ -x ${install_main_dir}/bin/remove.sh ] && ${csudo}ln -s ${install_main_dir}/bin/remove.sh ${bin_link_dir}/${uninstallScript} || :
|
||||
else
|
||||
|
||||
${csudo}cp -r ${binary_dir}/build/bin/* ${install_main_dir}/bin || ${csudo}cp -r ${binary_dir}/build/bin/* ${install_main_2_dir}/bin || :
|
||||
${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_dir}/bin || ${csudo}cp -r ${script_dir}/taosd-dump-cfg.gdb ${install_main_2_dir} || :
|
||||
${csudo}cp -r ${script_dir}/remove_client.sh ${install_main_dir}/bin || ${csudo}cp -r ${script_dir}/remove_client.sh ${install_main_2_dir}/bin || :
|
||||
${csudo}chmod 0555 ${install_main_dir}/bin/* || ${csudo}chmod 0555 ${install_main_2_dir}/bin/*
|
||||
#Make link
|
||||
[ -x ${install_main_dir}/bin/${clientName} ] || [ -x ${install_main_2_dir}/bin/${clientName} ] && ${csudo}ln -s ${install_main_dir}/bin/${clientName} ${bin_link_dir}/${clientName} || ${csudo}ln -s ${install_main_2_dir}/bin/${clientName} || :
|
||||
[ -x ${install_main_dir}/bin/${serverName} ] || [ -x ${install_main_2_dir}/bin/${serverName} ] && ${csudo}ln -s ${install_main_dir}/bin/${serverName} ${bin_link_dir}/${serverName} || ${csudo}ln -s ${install_main_2_dir}/bin/${serverName} || :
|
||||
[ -x ${install_main_dir}/bin/taosadapter ] || [ -x ${install_main_2_dir}/bin/taosadapter ] && ${csudo}ln -s ${install_main_dir}/bin/taosadapter ${bin_link_dir}/taosadapter || ${csudo}ln -s ${install_main_2_dir}/bin/taosadapter || :
|
||||
[ -x ${install_main_dir}/bin/taosdump ] || [ -x ${install_main_2_dir}/bin/taosdump ] && ${csudo}ln -s ${install_main_dir}/bin/taosdump ${bin_link_dir}/taosdump || ln -s ${install_main_2_dir}/bin/taosdump ${bin_link_dir}/taosdump || :
|
||||
[ -x ${install_main_dir}/bin/taosdemo ] || [ -x ${install_main_2_dir}/bin/taosdemo ] && ${csudo}ln -s ${install_main_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || ln -s ${install_main_2_dir}/bin/taosdemo ${bin_link_dir}/taosdemo || :
|
||||
fi
|
||||
}
|
||||
|
||||
function install_jemalloc() {
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
/usr/bin/install -c -d /usr/local/bin
|
||||
|
||||
if [ -f "${binary_dir}/build/bin/jemalloc-config" ]; then
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc-config /usr/local/bin
|
||||
fi
|
||||
if [ -f "${binary_dir}/build/bin/jemalloc.sh" ]; then
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/bin/jemalloc.sh /usr/local/bin
|
||||
fi
|
||||
if [ -f "${binary_dir}/build/bin/jeprof" ]; then
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/bin/jeprof /usr/local/bin
|
||||
fi
|
||||
if [ -f "${binary_dir}/build/include/jemalloc/jemalloc.h" ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/include/jemalloc
|
||||
${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/include/jemalloc/jemalloc.h \
|
||||
/usr/local/include/jemalloc
|
||||
fi
|
||||
if [ -f "${binary_dir}/build/lib/libjemalloc.so.2" ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/lib
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.so.2 /usr/local/lib
|
||||
${csudo}ln -sf libjemalloc.so.2 /usr/local/lib/libjemalloc.so
|
||||
${csudo}/usr/bin/install -c -d /usr/local/lib
|
||||
[ -f ${binary_dir}/build/lib/libjemalloc.a ] &&
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc.a /usr/local/lib
|
||||
[ -f ${binary_dir}/build/lib/libjemalloc_pic.a ] &&
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/lib/libjemalloc_pic.a /usr/local/lib
|
||||
if [ -f "${binary_dir}/build/lib/pkgconfig/jemalloc.pc" ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/lib/pkgconfig
|
||||
${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/lib/pkgconfig/jemalloc.pc \
|
||||
/usr/local/lib/pkgconfig
|
||||
fi
|
||||
if [ -d /etc/ld.so.conf.d ]; then
|
||||
echo "/usr/local/lib" | ${csudo}tee /etc/ld.so.conf.d/jemalloc.conf >/dev/null || echo -e "failed to write /etc/ld.so.conf.d/jemalloc.conf"
|
||||
${csudo}ldconfig
|
||||
else
|
||||
echo "/etc/ld.so.conf.d not found!"
|
||||
fi
|
||||
fi
|
||||
if [ -f "${binary_dir}/build/share/doc/jemalloc/jemalloc.html" ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/share/doc/jemalloc
|
||||
${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/share/doc/jemalloc/jemalloc.html \
|
||||
/usr/local/share/doc/jemalloc
|
||||
fi
|
||||
if [ -f "${binary_dir}/build/share/man/man3/jemalloc.3" ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/share/man/man3
|
||||
${csudo}/usr/bin/install -c -m 644 ${binary_dir}/build/share/man/man3/jemalloc.3 \
|
||||
/usr/local/share/man/man3
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function install_avro() {
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
if [ -f "${binary_dir}/build/$1/libavro.so.23.0.0" ] && [ -d /usr/local/$1 ]; then
|
||||
${csudo}/usr/bin/install -c -d /usr/local/$1
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/$1/libavro.so.23.0.0 /usr/local/$1
|
||||
${csudo}ln -sf libavro.so.23.0.0 /usr/local/$1/libavro.so.23
|
||||
${csudo}ln -sf libavro.so.23 /usr/local/$1/libavro.so
|
||||
${csudo}/usr/bin/install -c -d /usr/local/$1
|
||||
[ -f ${binary_dir}/build/$1/libavro.a ] &&
|
||||
${csudo}/usr/bin/install -c -m 755 ${binary_dir}/build/$1/libavro.a /usr/local/$1
|
||||
|
||||
if [ -d /etc/ld.so.conf.d ]; then
|
||||
echo "/usr/local/$1" | ${csudo}tee /etc/ld.so.conf.d/libavro.conf >/dev/null || echo -e "failed to write /etc/ld.so.conf.d/libavro.conf"
|
||||
${csudo}ldconfig
|
||||
else
|
||||
echo "/etc/ld.so.conf.d not found!"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function install_lib() {
|
||||
# Remove links
|
||||
${csudo}rm -f ${lib_link_dir}/libtaos.* || :
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}rm -f ${lib64_link_dir}/libtaos.* || :
|
||||
fi
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}cp ${binary_dir}/build/lib/libtaos.so.${verNumber} \
|
||||
${install_main_dir}/driver &&
|
||||
${csudo}chmod 777 ${install_main_dir}/driver/*
|
||||
|
||||
${csudo}ln -sf ${install_main_dir}/driver/libtaos.* ${lib_link_dir}/libtaos.so.1
|
||||
${csudo}ln -sf ${lib_link_dir}/libtaos.so.1 ${lib_link_dir}/libtaos.so
|
||||
|
||||
if [ -d "${lib64_link_dir}" ]; then
|
||||
${csudo}ln -sf ${install_main_dir}/driver/libtaos.* ${lib64_link_dir}/libtaos.so.1
|
||||
${csudo}ln -sf ${lib64_link_dir}/libtaos.so.1 ${lib64_link_dir}/libtaos.so
|
||||
fi
|
||||
else
|
||||
${csudo}cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib \
|
||||
${install_main_dir}/driver ||
|
||||
${csudo}cp -Rf ${binary_dir}/build/lib/libtaos.${verNumber}.dylib \
|
||||
${install_main_2_dir}/driver &&
|
||||
${csudo}chmod 777 ${install_main_dir}/driver/* ||
|
||||
${csudo}chmod 777 ${install_main_2_dir}/driver/*
|
||||
|
||||
${csudo}ln -sf ${install_main_dir}/driver/libtaos.* \
|
||||
${install_main_dir}/driver/libtaos.1.dylib ||
|
||||
${csudo}ln -sf ${install_main_2_dir}/driver/libtaos.* \
|
||||
${install_main_2_dir}/driver/libtaos.1.dylib || :
|
||||
|
||||
${csudo}ln -sf ${install_main_dir}/driver/libtaos.1.dylib \
|
||||
${install_main_dir}/driver/libtaos.dylib ||
|
||||
${csudo}ln -sf ${install_main_2_dir}/driver/libtaos.1.dylib \
|
||||
${install_main_2_dir}/driver/libtaos.dylib || :
|
||||
|
||||
${csudo}ln -sf ${install_main_dir}/driver/libtaos.${verNumber}.dylib \
|
||||
${lib_link_dir}/libtaos.1.dylib ||
|
||||
${csudo}ln -sf ${install_main_2_dir}/driver/libtaos.${verNumber}.dylib \
|
||||
${lib_link_dir}/libtaos.1.dylib || :
|
||||
|
||||
${csudo}ln -sf ${lib_link_dir}/libtaos.1.dylib ${lib_link_dir}/libtaos.dylib || :
|
||||
fi
|
||||
|
||||
install_jemalloc
|
||||
install_avro lib
|
||||
install_avro lib64
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}ldconfig
|
||||
fi
|
||||
}
|
||||
|
||||
function install_header() {
|
||||
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}rm -f ${inc_link_dir}/taos.h ${inc_link_dir}/taosdef.h ${inc_link_dir}/taoserror.h || :
|
||||
${csudo}cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/common/taosdef.h ${source_dir}/include/util/taoserror.h \
|
||||
${install_main_dir}/include && ${csudo}chmod 644 ${install_main_dir}/include/*
|
||||
${csudo}ln -s ${install_main_dir}/include/taos.h ${inc_link_dir}/taos.h
|
||||
${csudo}ln -s ${install_main_dir}/include/taosdef.h ${inc_link_dir}/taosdef.h
|
||||
${csudo}ln -s ${install_main_dir}/include/taoserror.h ${inc_link_dir}/taoserror.h
|
||||
else
|
||||
${csudo}cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/common/taosdef.h ${source_dir}/include/util/taoserror.h \
|
||||
${install_main_dir}/include ||
|
||||
${csudo}cp -f ${source_dir}/include/client/taos.h ${source_dir}/include/common/taosdef.h ${source_dir}/include/util/taoserror.h \
|
||||
${install_main_2_dir}/include &&
|
||||
${csudo}chmod 644 ${install_main_dir}/include/* ||
|
||||
${csudo}chmod 644 ${install_main_2_dir}/include/*
|
||||
fi
|
||||
}
|
||||
|
||||
function install_config() {
|
||||
if [ ! -f ${cfg_install_dir}/${configFile} ]; then
|
||||
${csudo}mkdir -p ${cfg_install_dir}
|
||||
[ -f ${script_dir}/../cfg/${configFile} ] &&
|
||||
${csudo}cp ${script_dir}/../cfg/${configFile} ${cfg_install_dir} || :
|
||||
${csudo}chmod 644 ${cfg_install_dir}/${configFile}
|
||||
${csudo}cp -f ${script_dir}/../cfg/${configFile} \
|
||||
${cfg_install_dir}/${configFile}.${verNumber} || :
|
||||
${csudo}ln -s ${cfg_install_dir}/${configFile} \
|
||||
${install_main_dir}/cfg/${configFile}
|
||||
else
|
||||
${csudo}cp -f ${script_dir}/../cfg/${configFile} \
|
||||
${cfg_install_dir}/${configFile}.${verNumber} || :
|
||||
fi
|
||||
}
|
||||
|
||||
function install_taosadapter_config() {
|
||||
if [ ! -f "${cfg_install_dir}/taosadapter.toml" ]; then
|
||||
${csudo}mkdir -p ${cfg_install_dir} || :
|
||||
[ -f ${binary_dir}/test/cfg/taosadapter.toml ] &&
|
||||
${csudo}cp ${binary_dir}/test/cfg/taosadapter.toml ${cfg_install_dir} || :
|
||||
[ -f ${cfg_install_dir}/taosadapter.toml ] &&
|
||||
${csudo}chmod 644 ${cfg_install_dir}/taosadapter.toml || :
|
||||
[ -f ${binary_dir}/test/cfg/taosadapter.toml ] &&
|
||||
${csudo}cp -f ${binary_dir}/test/cfg/taosadapter.toml \
|
||||
${cfg_install_dir}/taosadapter.toml.${verNumber} || :
|
||||
[ -f ${cfg_install_dir}/taosadapter.toml ] &&
|
||||
${csudo}ln -s ${cfg_install_dir}/taosadapter.toml \
|
||||
${install_main_dir}/cfg/taosadapter.toml || :
|
||||
else
|
||||
if [ -f "${binary_dir}/test/cfg/taosadapter.toml" ]; then
|
||||
${csudo}cp -f ${binary_dir}/test/cfg/taosadapter.toml \
|
||||
${cfg_install_dir}/taosadapter.toml.${verNumber} || :
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
function install_log() {
|
||||
${csudo}rm -rf ${log_dir} || :
|
||||
${csudo}mkdir -p ${log_dir} && ${csudo}chmod 777 ${log_dir}
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}ln -s ${log_dir} ${install_main_dir}/log
|
||||
else
|
||||
${csudo}ln -s ${log_dir} ${install_main_dir}/log || ${csudo}ln -s ${log_dir} ${install_main_2_dir}/log
|
||||
fi
|
||||
}
|
||||
|
||||
function install_data() {
|
||||
${csudo}mkdir -p ${data_dir}
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}ln -s ${data_dir} ${install_main_dir}/data
|
||||
else
|
||||
${csudo}ln -s ${data_dir} ${install_main_dir}/data || ${csudo}ln -s ${data_dir} ${install_main_2_dir}/data
|
||||
fi
|
||||
}
|
||||
|
||||
function install_connector() {
|
||||
if find ${source_dir}/src/connector/go -mindepth 1 -maxdepth 1 | read; then
|
||||
${csudo}cp -r ${source_dir}/src/connector/go ${install_main_dir}/connector || :
|
||||
else
|
||||
echo "WARNING: go connector not found, please check if want to use it!"
|
||||
fi
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector || :
|
||||
${csudo}cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &>/dev/null && ${csudo}chmod 777 ${install_main_dir}/connector/*.jar || echo &>/dev/null || :
|
||||
else
|
||||
${csudo}cp -rf ${source_dir}/src/connector/python ${install_main_dir}/connector || ${csudo}cp -rf ${source_dir}/src/connector/python ${install_main_2_dir}/connector || :
|
||||
${csudo}cp ${binary_dir}/build/lib/*.jar ${install_main_dir}/connector &>/dev/null && ${csudo}chmod 777 ${install_main_dir}/connector/*.jar || echo &>/dev/null || :
|
||||
${csudo}cp ${binary_dir}/build/lib/*.jar ${install_main_2_dir}/connector &>/dev/null && ${csudo}chmod 777 ${install_main_2_dir}/connector/*.jar || echo &>/dev/null || :
|
||||
fi
|
||||
}
|
||||
|
||||
function install_examples() {
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
${csudo}cp -rf ${source_dir}/examples/* ${install_main_dir}/examples || :
|
||||
else
|
||||
${csudo}cp -rf ${source_dir}/examples/* ${install_main_dir}/examples || ${csudo}cp -rf ${source_dir}/examples/* ${install_main_2_dir}/examples || :
|
||||
fi
|
||||
}
|
||||
|
||||
function clean_service_on_sysvinit() {
|
||||
if pidof ${serverName} &>/dev/null; then
|
||||
${csudo}service ${serverName} stop || :
|
||||
fi
|
||||
|
||||
if ((${initd_mod} == 1)); then
|
||||
${csudo}chkconfig --del ${serverName} || :
|
||||
elif ((${initd_mod} == 2)); then
|
||||
${csudo}insserv -r ${serverName} || :
|
||||
elif ((${initd_mod} == 3)); then
|
||||
${csudo}update-rc.d -f ${serverName} remove || :
|
||||
fi
|
||||
|
||||
${csudo}rm -f ${service_config_dir}/${serverName} || :
|
||||
|
||||
if $(which init &>/dev/null); then
|
||||
${csudo}init q || :
|
||||
fi
|
||||
}
|
||||
|
||||
function install_service_on_sysvinit() {
|
||||
clean_service_on_sysvinit
|
||||
|
||||
sleep 1
|
||||
|
||||
if ((${os_type} == 1)); then
|
||||
# ${csudo}cp -f ${script_dir}/../deb/${serverName} ${install_main_dir}/init.d
|
||||
${csudo}cp ${script_dir}/../deb/${serverName} ${service_config_dir} && ${csudo}chmod a+x ${service_config_dir}/${serverName} || :
|
||||
elif ((${os_type} == 2)); then
|
||||
# ${csudo}cp -f ${script_dir}/../rpm/${serverName} ${install_main_dir}/init.d
|
||||
${csudo}cp ${script_dir}/../rpm/${serverName} ${service_config_dir} && ${csudo}chmod a+x ${service_config_dir}/${serverName} || :
|
||||
fi
|
||||
|
||||
if ((${initd_mod} == 1)); then
|
||||
${csudo}chkconfig --add ${serverName} || :
|
||||
${csudo}chkconfig --level 2345 ${serverName} on || :
|
||||
elif ((${initd_mod} == 2)); then
|
||||
${csudo}insserv ${serverName} || :
|
||||
${csudo}insserv -d ${serverName} || :
|
||||
elif ((${initd_mod} == 3)); then
|
||||
${csudo}update-rc.d ${serverName} defaults || :
|
||||
fi
|
||||
}
|
||||
|
||||
function clean_service_on_systemd() {
|
||||
taosd_service_config="${service_config_dir}/${serverName}.service"
|
||||
|
||||
if systemctl is-active --quiet ${serverName}; then
|
||||
echo "${productName} is running, stopping it..."
|
||||
${csudo}systemctl stop ${serverName} &>/dev/null || echo &>/dev/null
|
||||
fi
|
||||
${csudo}systemctl disable ${serverName} &>/dev/null || echo &>/dev/null
|
||||
|
||||
${csudo}rm -f ${taosd_service_config}
|
||||
}
|
||||
|
||||
function install_service_on_systemd() {
|
||||
clean_service_on_systemd
|
||||
|
||||
taosd_service_config="${service_config_dir}/${serverName}.service"
|
||||
|
||||
${csudo}bash -c "echo '[Unit]' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'Description=${productName} server service' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'After=network-online.target' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'Wants=network-online.target' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo '[Service]' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'Type=simple' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'ExecStart=/usr/bin/${serverName}' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'ExecStartPre=${installDir}/bin/startPre.sh' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'TimeoutStopSec=1000000s' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'LimitNOFILE=infinity' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'LimitNPROC=infinity' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'LimitCORE=infinity' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'TimeoutStartSec=0' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'StandardOutput=null' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'Restart=always' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'StartLimitBurst=3' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'StartLimitInterval=60s' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo '[Install]' >> ${taosd_service_config}"
|
||||
${csudo}bash -c "echo 'WantedBy=multi-user.target' >> ${taosd_service_config}"
|
||||
${csudo}systemctl enable ${serverName}
|
||||
}
|
||||
|
||||
function install_taosadapter_service() {
|
||||
if ((${service_mod} == 0)); then
|
||||
[ -f ${binary_dir}/test/cfg/taosadapter.service ] &&
|
||||
${csudo}cp ${binary_dir}/test/cfg/taosadapter.service \
|
||||
${service_config_dir}/ || :
|
||||
${csudo}systemctl daemon-reload
|
||||
fi
|
||||
}
|
||||
|
||||
function install_service() {
|
||||
if ((${service_mod} == 0)); then
|
||||
install_service_on_systemd
|
||||
elif ((${service_mod} == 1)); then
|
||||
install_service_on_sysvinit
|
||||
else
|
||||
kill_taosd
|
||||
fi
|
||||
}
|
||||
|
||||
function update_TDengine() {
|
||||
echo -e "${GREEN}Start to update ${productName}...${NC}"
|
||||
# Stop the service if running
|
||||
|
||||
if pidof ${serverName} &>/dev/null; then
|
||||
if ((${service_mod} == 0)); then
|
||||
${csudo}systemctl stop ${serverName} || :
|
||||
elif ((${service_mod} == 1)); then
|
||||
${csudo}service ${serverName} stop || :
|
||||
else
|
||||
kill_taosadapter
|
||||
kill_taosd
|
||||
fi
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
install_main_path
|
||||
|
||||
install_log
|
||||
install_header
|
||||
install_lib
|
||||
# install_connector
|
||||
install_examples
|
||||
install_bin
|
||||
|
||||
install_service
|
||||
install_taosadapter_service
|
||||
|
||||
install_config
|
||||
install_taosadapter_config
|
||||
|
||||
echo
|
||||
echo -e "\033[44;32;1m${productName} is updated successfully!${NC}"
|
||||
echo
|
||||
|
||||
echo -e "${GREEN_DARK}To configure ${productName} ${NC}: edit ${configDir}/${configFile}"
|
||||
echo -e "${GREEN_DARK}To configure Taos Adapter (if has) ${NC}: edit ${configDir}/taosadapter.toml"
|
||||
if ((${service_mod} == 0)); then
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}systemctl start ${serverName}${NC}"
|
||||
elif ((${service_mod} == 1)); then
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}service ${serverName} start${NC}"
|
||||
else
|
||||
echo -e "${GREEN_DARK}To start Taos Adapter (if has)${NC}: taosadapter &${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${serverName}${NC}"
|
||||
fi
|
||||
|
||||
echo -e "${GREEN_DARK}To access ${productName} ${NC}: use ${GREEN_UNDERLINE}${clientName}${NC} in shell${NC}"
|
||||
echo
|
||||
echo -e "\033[44;32;1m${productName} is updated successfully!${NC}"
|
||||
}
|
||||
|
||||
function install_TDengine() {
|
||||
# Start to install
|
||||
echo -e "${GREEN}Start to install ${productName}...${NC}"
|
||||
|
||||
install_main_path
|
||||
|
||||
install_data
|
||||
install_log
|
||||
install_header
|
||||
install_lib
|
||||
# install_connector
|
||||
install_examples
|
||||
install_bin
|
||||
|
||||
install_service
|
||||
install_taosadapter_service
|
||||
|
||||
install_config
|
||||
install_taosadapter_config
|
||||
|
||||
# Ask if to start the service
|
||||
echo
|
||||
echo -e "\033[44;32;1m${productName} is installed successfully!${NC}"
|
||||
echo
|
||||
echo -e "${GREEN_DARK}To configure ${productName} ${NC}: edit ${configDir}/${configFile}"
|
||||
echo -e "${GREEN_DARK}To configure taosadapter (if has) ${NC}: edit ${configDir}/taosadapter.toml"
|
||||
if ((${service_mod} == 0)); then
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}systemctl start ${serverName}${NC}"
|
||||
elif ((${service_mod} == 1)); then
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ${csudo}service ${serverName} start${NC}"
|
||||
else
|
||||
echo -e "${GREEN_DARK}To start Taos Adapter (if has)${NC}: taosadapter &${NC}"
|
||||
echo -e "${GREEN_DARK}To start ${productName} ${NC}: ./${serverName}${NC}"
|
||||
fi
|
||||
|
||||
echo -e "${GREEN_DARK}To access ${productName} ${NC}: use ${GREEN_UNDERLINE}${clientName}${NC} in shell${NC}"
|
||||
echo
|
||||
echo -e "\033[44;32;1m${productName} is installed successfully!${NC}"
|
||||
}
|
||||
|
||||
## ==============================Main program starts from here============================
|
||||
echo source directory: $1
|
||||
echo binary directory: $2
|
||||
if [ "$osType" != "Darwin" ]; then
|
||||
if [ -x ${bin_dir}/${clientName} ]; then
|
||||
update_TDengine
|
||||
else
|
||||
install_TDengine
|
||||
fi
|
||||
else
|
||||
if [ -x ${bin_dir}/${clientName} ] || [ -x ${bin_2_dir}/${clientName} ]; then
|
||||
update_TDengine
|
||||
else
|
||||
install_TDengine
|
||||
fi
|
||||
fi
|
|
@ -1,5 +1,5 @@
|
|||
aux_source_directory(src CLIENT_SRC)
|
||||
add_library(taos ${CLIENT_SRC})
|
||||
add_library(taos SHARED ${CLIENT_SRC})
|
||||
target_include_directories(
|
||||
taos
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/client"
|
||||
|
@ -11,6 +11,25 @@ target_link_libraries(
|
|||
PRIVATE os util common transport nodes parser command planner catalog scheduler function qcom
|
||||
)
|
||||
|
||||
set_target_properties(
|
||||
taos
|
||||
PROPERTIES
|
||||
VERSION ${TD_VER_NUMBER}
|
||||
SOVERSION ${TD_VER_NUMBER}
|
||||
)
|
||||
|
||||
add_library(taos_static STATIC ${CLIENT_SRC})
|
||||
target_include_directories(
|
||||
taos_static
|
||||
PUBLIC "${TD_SOURCE_DIR}/include/client"
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
taos_static
|
||||
INTERFACE api
|
||||
PRIVATE os util common transport nodes parser command planner catalog scheduler function qcom
|
||||
)
|
||||
|
||||
if(${BUILD_TEST})
|
||||
ADD_SUBDIRECTORY(test)
|
||||
endif(${BUILD_TEST})
|
|
@ -8,13 +8,13 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
|
|||
ADD_EXECUTABLE(clientTest clientTests.cpp)
|
||||
TARGET_LINK_LIBRARIES(
|
||||
clientTest
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos qcom
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos_static qcom
|
||||
)
|
||||
|
||||
ADD_EXECUTABLE(tmqTest tmqTest.cpp)
|
||||
TARGET_LINK_LIBRARIES(
|
||||
tmqTest
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos qcom
|
||||
PUBLIC os util common transport parser catalog scheduler function gtest taos_static qcom
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
|
|
|
@ -662,7 +662,7 @@ TEST(testCase, agg_query_tables) {
|
|||
TAOS_RES* pRes = taos_query(pConn, "use abc1");
|
||||
taos_free_result(pRes);
|
||||
|
||||
pRes = taos_query(pConn, "select * from test_block_raw.all_type");
|
||||
pRes = taos_query(pConn, "select count(*) from tu");
|
||||
if (taos_errno(pRes) != 0) {
|
||||
printf("failed to select from table, reason:%s\n", taos_errstr(pRes));
|
||||
taos_free_result(pRes);
|
||||
|
@ -674,9 +674,6 @@ TEST(testCase, agg_query_tables) {
|
|||
int32_t numOfFields = taos_num_fields(pRes);
|
||||
|
||||
int32_t n = 0;
|
||||
void* data = NULL;
|
||||
int32_t code = taos_fetch_raw_block(pRes, &n, &data);
|
||||
|
||||
char str[512] = {0};
|
||||
while ((pRow = taos_fetch_row(pRes)) != NULL) {
|
||||
int32_t* length = taos_fetch_lengths(pRes);
|
||||
|
|
|
@ -3381,6 +3381,8 @@ int32_t tSerializeSCMCreateStreamReq(void *buf, int32_t bufLen, const SCMCreateS
|
|||
if (tEncodeI8(&encoder, pReq->igExists) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, sqlLen) < 0) return -1;
|
||||
if (tEncodeI32(&encoder, astLen) < 0) return -1;
|
||||
if (tEncodeI8(&encoder, pReq->triggerType) < 0) return -1;
|
||||
if (tEncodeI64(&encoder, pReq->watermark) < 0) return -1;
|
||||
if (sqlLen > 0 && tEncodeCStr(&encoder, pReq->sql) < 0) return -1;
|
||||
if (astLen > 0 && tEncodeCStr(&encoder, pReq->ast) < 0) return -1;
|
||||
|
||||
|
@ -3404,6 +3406,8 @@ int32_t tDeserializeSCMCreateStreamReq(void *buf, int32_t bufLen, SCMCreateStrea
|
|||
if (tDecodeI8(&decoder, &pReq->igExists) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &sqlLen) < 0) return -1;
|
||||
if (tDecodeI32(&decoder, &astLen) < 0) return -1;
|
||||
if (tDecodeI8(&decoder, &pReq->triggerType) < 0) return -1;
|
||||
if (tDecodeI64(&decoder, &pReq->watermark) < 0) return -1;
|
||||
|
||||
if (sqlLen > 0) {
|
||||
pReq->sql = taosMemoryCalloc(1, sqlLen + 1);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
#define _DEFAULT_SOURCE
|
||||
#include "ttypes.h"
|
||||
#include "tcompression.h"
|
||||
#include "trow.h"
|
||||
|
||||
const int32_t TYPE_BYTES[15] = {
|
||||
-1, // TSDB_DATA_TYPE_NULL
|
||||
|
@ -49,7 +50,7 @@ const int32_t TYPE_BYTES[15] = {
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
static void getStatics_bool(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_bool(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int8_t *data = (int8_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
|
@ -60,7 +61,8 @@ static void getStatics_bool(const void *pData, int32_t numOfRow, int64_t *min, i
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (data[i] == TSDB_DATA_BOOL_NULL) {
|
||||
// if (data[i] == TSDB_DATA_BOOL_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -69,7 +71,7 @@ static void getStatics_bool(const void *pData, int32_t numOfRow, int64_t *min, i
|
|||
}
|
||||
}
|
||||
|
||||
static void getStatics_i8(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_i8(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int8_t *data = (int8_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
|
@ -80,7 +82,8 @@ static void getStatics_i8(const void *pData, int32_t numOfRow, int64_t *min, int
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint8_t)data[i]) == TSDB_DATA_TINYINT_NULL) {
|
||||
// if (((uint8_t)data[i]) == TSDB_DATA_TINYINT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -89,7 +92,7 @@ static void getStatics_i8(const void *pData, int32_t numOfRow, int64_t *min, int
|
|||
}
|
||||
}
|
||||
|
||||
static void getStatics_u8(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_u8(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
uint8_t *data = (uint8_t *)pData;
|
||||
uint64_t _min = UINT64_MAX;
|
||||
|
@ -102,7 +105,8 @@ static void getStatics_u8(const void *pData, int32_t numOfRow, int64_t *min, int
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint8_t)data[i]) == TSDB_DATA_UTINYINT_NULL) {
|
||||
// if (((uint8_t)data[i]) == TSDB_DATA_UTINYINT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -115,7 +119,7 @@ static void getStatics_u8(const void *pData, int32_t numOfRow, int64_t *min, int
|
|||
*sum = _sum;
|
||||
}
|
||||
|
||||
static void getStatics_i16(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_i16(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int16_t *data = (int16_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
|
@ -126,7 +130,8 @@ static void getStatics_i16(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint16_t)data[i]) == TSDB_DATA_SMALLINT_NULL) {
|
||||
// if (((uint16_t)data[i]) == TSDB_DATA_SMALLINT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -135,7 +140,7 @@ static void getStatics_i16(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
}
|
||||
}
|
||||
|
||||
static void getStatics_u16(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_u16(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
uint16_t *data = (uint16_t *)pData;
|
||||
uint64_t _min = UINT64_MAX;
|
||||
|
@ -148,7 +153,8 @@ static void getStatics_u16(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint16_t)data[i]) == TSDB_DATA_USMALLINT_NULL) {
|
||||
// if (((uint16_t)data[i]) == TSDB_DATA_USMALLINT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -161,7 +167,7 @@ static void getStatics_u16(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
*sum = _sum;
|
||||
}
|
||||
|
||||
static void getStatics_i32(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_i32(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int32_t *data = (int32_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
|
@ -172,7 +178,8 @@ static void getStatics_i32(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint32_t)data[i]) == TSDB_DATA_INT_NULL) {
|
||||
// if (((uint32_t)data[i]) == TSDB_DATA_INT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -181,7 +188,7 @@ static void getStatics_i32(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
}
|
||||
}
|
||||
|
||||
static void getStatics_u32(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_u32(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
uint32_t *data = (uint32_t *)pData;
|
||||
uint64_t _min = UINT64_MAX;
|
||||
|
@ -194,7 +201,8 @@ static void getStatics_u32(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint32_t)data[i]) == TSDB_DATA_UINT_NULL) {
|
||||
// if (((uint32_t)data[i]) == TSDB_DATA_UINT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -207,7 +215,7 @@ static void getStatics_u32(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
*sum = _sum;
|
||||
}
|
||||
|
||||
static void getStatics_i64(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_i64(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
int64_t *data = (int64_t *)pData;
|
||||
*min = INT64_MAX;
|
||||
|
@ -218,7 +226,8 @@ static void getStatics_i64(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint64_t)data[i]) == TSDB_DATA_BIGINT_NULL) {
|
||||
// if (((uint64_t)data[i]) == TSDB_DATA_BIGINT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -227,7 +236,7 @@ static void getStatics_i64(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
}
|
||||
}
|
||||
|
||||
static void getStatics_u64(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_u64(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
uint64_t *data = (uint64_t *)pData;
|
||||
uint64_t _min = UINT64_MAX;
|
||||
|
@ -240,7 +249,8 @@ static void getStatics_u64(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (((uint64_t)data[i]) == TSDB_DATA_UBIGINT_NULL) {
|
||||
// if (((uint64_t)data[i]) == TSDB_DATA_UBIGINT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -253,7 +263,7 @@ static void getStatics_u64(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
*sum = _sum;
|
||||
}
|
||||
|
||||
static void getStatics_f(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_f(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
float *data = (float *)pData;
|
||||
float fmin = FLT_MAX;
|
||||
|
@ -265,7 +275,8 @@ static void getStatics_f(const void *pData, int32_t numOfRow, int64_t *min, int6
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if ((*(uint32_t *)&(data[i])) == TSDB_DATA_FLOAT_NULL) {
|
||||
// if ((*(uint32_t *)&(data[i])) == TSDB_DATA_FLOAT_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -289,7 +300,7 @@ static void getStatics_f(const void *pData, int32_t numOfRow, int64_t *min, int6
|
|||
SET_DOUBLE_VAL(min, fmin);
|
||||
}
|
||||
|
||||
static void getStatics_d(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_d(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
double *data = (double *)pData;
|
||||
double dmin = DBL_MAX;
|
||||
|
@ -301,7 +312,8 @@ static void getStatics_d(const void *pData, int32_t numOfRow, int64_t *min, int6
|
|||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if ((*(uint64_t *)&(data[i])) == TSDB_DATA_DOUBLE_NULL) {
|
||||
// if ((*(uint64_t *)&(data[i])) == TSDB_DATA_DOUBLE_NULL) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
continue;
|
||||
}
|
||||
|
@ -325,13 +337,14 @@ static void getStatics_d(const void *pData, int32_t numOfRow, int64_t *min, int6
|
|||
SET_DOUBLE_PTR(min, &dmin);
|
||||
}
|
||||
|
||||
static void getStatics_bin(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_bin(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
const char *data = pData;
|
||||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (isNull(data, TSDB_DATA_TYPE_BINARY)) {
|
||||
// if (isNull(data, TSDB_DATA_TYPE_BINARY)) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
}
|
||||
|
||||
|
@ -345,13 +358,14 @@ static void getStatics_bin(const void *pData, int32_t numOfRow, int64_t *min, in
|
|||
*maxIndex = 0;
|
||||
}
|
||||
|
||||
static void getStatics_nchr(const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
static void getStatics_nchr(const void *pBitmap, const void *pData, int32_t numOfRow, int64_t *min, int64_t *max, int64_t *sum,
|
||||
int16_t *minIndex, int16_t *maxIndex, int16_t *numOfNull) {
|
||||
const char *data = pData;
|
||||
assert(numOfRow <= INT16_MAX);
|
||||
|
||||
for (int32_t i = 0; i < numOfRow; ++i) {
|
||||
if (isNull(data, TSDB_DATA_TYPE_NCHAR)) {
|
||||
// if (isNull(data, TSDB_DATA_TYPE_NCHAR)) {
|
||||
if (!tdIsBitmapValTypeNormII(pBitmap, i)) {
|
||||
(*numOfNull) += 1;
|
||||
}
|
||||
|
||||
|
@ -377,7 +391,7 @@ tDataTypeDescriptor tDataTypes[15] = {
|
|||
getStatics_i64},
|
||||
{TSDB_DATA_TYPE_FLOAT, 5, FLOAT_BYTES, "FLOAT", 0, 0, tsCompressFloat, tsDecompressFloat, getStatics_f},
|
||||
{TSDB_DATA_TYPE_DOUBLE, 6, DOUBLE_BYTES, "DOUBLE", 0, 0, tsCompressDouble, tsDecompressDouble, getStatics_d},
|
||||
{TSDB_DATA_TYPE_BINARY, 6, 0, "BINARY", 0, 0, tsCompressString, tsDecompressString, getStatics_bin},
|
||||
{TSDB_DATA_TYPE_VARCHAR, 6, 0, "VARCHAR", 0, 0, tsCompressString, tsDecompressString, getStatics_bin},
|
||||
{TSDB_DATA_TYPE_TIMESTAMP, 9, LONG_BYTES, "TIMESTAMP", INT64_MIN, INT64_MAX, tsCompressTimestamp,
|
||||
tsDecompressTimestamp, getStatics_i64},
|
||||
{TSDB_DATA_TYPE_NCHAR, 5, 8, "NCHAR", 0, 0, tsCompressString, tsDecompressString, getStatics_nchr},
|
||||
|
@ -402,7 +416,7 @@ char tTokenTypeSwitcher[13] = {
|
|||
TSDB_DATA_TYPE_DOUBLE, // TK_DOUBLE
|
||||
TSDB_DATA_TYPE_BINARY, // TK_STRING
|
||||
TSDB_DATA_TYPE_BIGINT, // TK_TIMESTAMP
|
||||
TSDB_DATA_TYPE_BINARY, // TK_BINARY
|
||||
TSDB_DATA_TYPE_VARCHAR, // TK_BINARY
|
||||
TSDB_DATA_TYPE_NCHAR, // TK_NCHAR
|
||||
};
|
||||
|
||||
|
|
|
@ -7,11 +7,3 @@ target_include_directories(
|
|||
dnode
|
||||
PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
|
||||
IF (TD_GRANT)
|
||||
TARGET_LINK_LIBRARIES(dnode grant)
|
||||
ENDIF ()
|
||||
IF (TD_USB_DONGLE)
|
||||
TARGET_LINK_LIBRARIES(dnode usb_dongle)
|
||||
else()
|
||||
ENDIF ()
|
|
@ -6,5 +6,5 @@ target_include_directories(
|
|||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/inc"
|
||||
)
|
||||
target_link_libraries(
|
||||
dnode_interface cjson mnode vnode qnode snode bnode wal sync taos tfs monitor
|
||||
dnode_interface cjson mnode vnode qnode snode bnode wal sync taos_static tfs monitor
|
||||
)
|
|
@ -83,9 +83,9 @@ int32_t vmProcessGetVnodeLoadsReq(SMgmtWrapper *pWrapper, SNodeMsg *pReq) {
|
|||
|
||||
static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
|
||||
pCfg->vgId = pCreate->vgId;
|
||||
pCfg->wsize = pCreate->cacheBlockSize;
|
||||
pCfg->ssize = pCreate->cacheBlockSize;
|
||||
pCfg->lsize = pCreate->cacheBlockSize;
|
||||
pCfg->wsize = pCreate->cacheBlockSize * 1024 * 1024;
|
||||
pCfg->ssize = 1024;
|
||||
pCfg->lsize = 1024 * 1024;
|
||||
pCfg->isHeapAllocator = true;
|
||||
pCfg->ttl = 4;
|
||||
pCfg->keep = pCreate->daysToKeep0;
|
||||
|
@ -96,13 +96,12 @@ static void vmGenerateVnodeCfg(SCreateVnodeReq *pCreate, SVnodeCfg *pCfg) {
|
|||
pCfg->tsdbCfg.keep1 = pCreate->daysToKeep0;
|
||||
pCfg->tsdbCfg.lruCacheSize = pCreate->cacheBlockSize;
|
||||
pCfg->tsdbCfg.retentions = pCreate->pRetensions;
|
||||
pCfg->metaCfg.lruSize = pCreate->cacheBlockSize;
|
||||
pCfg->walCfg.fsyncPeriod = pCreate->fsyncPeriod;
|
||||
pCfg->walCfg.level = pCreate->walLevel;
|
||||
pCfg->walCfg.retentionPeriod = 10;
|
||||
pCfg->walCfg.retentionSize = 128;
|
||||
pCfg->walCfg.rollPeriod = 128;
|
||||
pCfg->walCfg.segSize = 128;
|
||||
pCfg->walCfg.level = TAOS_WAL_WRITE;
|
||||
pCfg->walCfg.fsyncPeriod = 0;
|
||||
pCfg->walCfg.retentionPeriod = 0;
|
||||
pCfg->walCfg.retentionSize = 0;
|
||||
pCfg->walCfg.rollPeriod = 0;
|
||||
pCfg->walCfg.segSize = 0;
|
||||
pCfg->walCfg.vgId = pCreate->vgId;
|
||||
pCfg->hashBegin = pCreate->hashBegin;
|
||||
pCfg->hashEnd = pCreate->hashEnd;
|
||||
|
@ -160,13 +159,10 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) {
|
|||
msgCb.queueFps[APPLY_QUEUE] = vmPutMsgToApplyQueue;
|
||||
msgCb.qsizeFp = vmGetQueueSize;
|
||||
|
||||
vnodeCfg.msgCb = msgCb;
|
||||
vnodeCfg.pTfs = pMgmt->pTfs;
|
||||
vnodeCfg.dbId = wrapperCfg.dbUid;
|
||||
SVnode *pImpl = vnodeOpen(wrapperCfg.path, &vnodeCfg);
|
||||
SVnode *pImpl = vnodeOpen(path, pMgmt->pTfs, msgCb);
|
||||
if (pImpl == NULL) {
|
||||
tFreeSCreateVnodeReq(&createReq);
|
||||
dError("vgId:%d, failed to create vnode since %s", createReq.vgId, terrstr());
|
||||
tFreeSCreateVnodeReq(&createReq);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -175,7 +171,7 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) {
|
|||
tFreeSCreateVnodeReq(&createReq);
|
||||
dError("vgId:%d, failed to open vnode since %s", createReq.vgId, terrstr());
|
||||
vnodeClose(pImpl);
|
||||
vnodeDestroy(wrapperCfg.path);
|
||||
vnodeDestroy(path, pMgmt->pTfs);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
@ -184,7 +180,7 @@ int32_t vmProcessCreateVnodeReq(SVnodesMgmt *pMgmt, SNodeMsg *pMsg) {
|
|||
if (code != 0) {
|
||||
tFreeSCreateVnodeReq(&createReq);
|
||||
vnodeClose(pImpl);
|
||||
vnodeDestroy(wrapperCfg.path);
|
||||
vnodeDestroy(path, pMgmt->pTfs);
|
||||
terrno = code;
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -84,6 +84,8 @@ int32_t vmOpenVnode(SVnodesMgmt *pMgmt, SWrapperCfg *pCfg, SVnode *pImpl) {
|
|||
}
|
||||
|
||||
void vmCloseVnode(SVnodesMgmt *pMgmt, SVnodeObj *pVnode) {
|
||||
char path[TSDB_FILENAME_LEN];
|
||||
|
||||
taosWLockLatch(&pMgmt->latch);
|
||||
taosHashRemove(pMgmt->hash, &pVnode->vgId, sizeof(int32_t));
|
||||
taosWUnLockLatch(&pMgmt->latch);
|
||||
|
@ -104,7 +106,8 @@ void vmCloseVnode(SVnodesMgmt *pMgmt, SVnodeObj *pVnode) {
|
|||
|
||||
if (pVnode->dropped) {
|
||||
dDebug("vgId:%d, vnode is destroyed for dropped:%d", pVnode->vgId, pVnode->dropped);
|
||||
vnodeDestroy(pVnode->path);
|
||||
snprintf(path, TSDB_FILENAME_LEN, "vnode%svnode%d", TD_DIRSEP, pVnode->vgId);
|
||||
vnodeDestroy(path, pMgmt->pTfs);
|
||||
}
|
||||
|
||||
taosMemoryFree(pVnode->path);
|
||||
|
@ -116,6 +119,7 @@ static void *vmOpenVnodeFunc(void *param) {
|
|||
SVnodeThread *pThread = param;
|
||||
SVnodesMgmt *pMgmt = pThread->pMgmt;
|
||||
SDnode *pDnode = pMgmt->pDnode;
|
||||
char path[TSDB_FILENAME_LEN];
|
||||
|
||||
dDebug("thread:%d, start to open %d vnodes", pThread->threadIndex, pThread->vnodeNum);
|
||||
setThreadName("open-vnodes");
|
||||
|
@ -134,8 +138,8 @@ static void *vmOpenVnodeFunc(void *param) {
|
|||
msgCb.queueFps[FETCH_QUEUE] = vmPutMsgToFetchQueue;
|
||||
msgCb.queueFps[APPLY_QUEUE] = vmPutMsgToApplyQueue;
|
||||
msgCb.qsizeFp = vmGetQueueSize;
|
||||
SVnodeCfg cfg = {.msgCb = msgCb, .pTfs = pMgmt->pTfs, .vgId = pCfg->vgId, .dbId = pCfg->dbUid};
|
||||
SVnode *pImpl = vnodeOpen(pCfg->path, &cfg);
|
||||
snprintf(path, TSDB_FILENAME_LEN, "vnode%svnode%d", TD_DIRSEP, pCfg->vgId);
|
||||
SVnode *pImpl = vnodeOpen(path, pMgmt->pTfs, msgCb);
|
||||
if (pImpl == NULL) {
|
||||
dError("vgId:%d, failed to open vnode by thread:%d", pCfg->vgId, pThread->threadIndex);
|
||||
pThread->failed++;
|
||||
|
|
|
@ -12,8 +12,8 @@ target_link_libraries(
|
|||
IF (TD_GRANT)
|
||||
TARGET_LINK_LIBRARIES(mnode grant)
|
||||
ENDIF ()
|
||||
IF (TD_USB_DONGLE)
|
||||
TARGET_LINK_LIBRARIES(mnode usb_dongle)
|
||||
IF (TD_GRANT)
|
||||
ADD_DEFINITIONS(-D_GRANT)
|
||||
ENDIF ()
|
||||
|
||||
if(${BUILD_TEST})
|
||||
|
|
|
@ -31,7 +31,7 @@ void mndReleaseStream(SMnode *pMnode, SStreamObj *pStream);
|
|||
SSdbRaw *mndStreamActionEncode(SStreamObj *pStream);
|
||||
SSdbRow *mndStreamActionDecode(SSdbRaw *pRaw);
|
||||
|
||||
int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans);
|
||||
int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, int8_t triggerType, int64_t watermark, STrans *pTrans);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -106,6 +106,7 @@ static SSdbRaw *mndDbActionEncode(SDbObj *pDb) {
|
|||
SDB_SET_INT8(pRaw, dataPos, pDb->cfg.cacheLastRow, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pDb->cfg.numOfRetensions, DB_ENCODE_OVER)
|
||||
for (int32_t i = 0; i < pDb->cfg.numOfRetensions; ++i) {
|
||||
TASSERT(taosArrayGetSize(pDb->cfg.pRetensions) == pDb->cfg.numOfRetensions);
|
||||
SRetention *pRetension = taosArrayGet(pDb->cfg.pRetensions, i);
|
||||
SDB_SET_INT32(pRaw, dataPos, pRetension->freq, DB_ENCODE_OVER)
|
||||
SDB_SET_INT32(pRaw, dataPos, pRetension->keep, DB_ENCODE_OVER)
|
||||
|
|
|
@ -82,7 +82,7 @@ static const SInfosTableSchema userDBSchema[] = {
|
|||
{.name = "blocks", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "minrows", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "maxrows", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "wallevel", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT},
|
||||
{.name = "wal", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT},
|
||||
{.name = "fsync", .bytes = 4, .type = TSDB_DATA_TYPE_INT},
|
||||
{.name = "comp", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT},
|
||||
{.name = "cachelast", .bytes = 1, .type = TSDB_DATA_TYPE_TINYINT},
|
||||
|
|
|
@ -429,7 +429,7 @@ static int32_t mndCreateSma(SMnode *pMnode, SNodeMsg *pReq, SMCreateSmaReq *pCre
|
|||
if (mndSetCreateSmaRedoLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER;
|
||||
if (mndSetCreateSmaCommitLogs(pMnode, pTrans, &smaObj) != 0) goto _OVER;
|
||||
if (mndSetCreateSmaRedoActions(pMnode, pTrans, pDb, &smaObj) != 0) goto _OVER;
|
||||
if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans) != 0) goto _OVER;
|
||||
if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, STREAM_TRIGGER_AT_ONCE, 0, pTrans) != 0) goto _OVER;
|
||||
if (mndTransPrepare(pMnode, pTrans) != 0) goto _OVER;
|
||||
|
||||
code = 0;
|
||||
|
|
|
@ -218,7 +218,7 @@ static int32_t mndCheckCreateStreamReq(SCMCreateStreamReq *pCreate) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int32_t mndStreamGetPlanString(const char *ast, char **pStr) {
|
||||
static int32_t mndStreamGetPlanString(const char *ast, int8_t triggerType, int64_t watermark, char **pStr) {
|
||||
if (NULL == ast) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -232,6 +232,8 @@ static int32_t mndStreamGetPlanString(const char *ast, char **pStr) {
|
|||
.pAstRoot = pAst,
|
||||
.topicQuery = false,
|
||||
.streamQuery = true,
|
||||
.triggerType = triggerType,
|
||||
.watermark = watermark,
|
||||
};
|
||||
code = qCreateQueryPlan(&cxt, &pPlan, NULL);
|
||||
}
|
||||
|
@ -245,7 +247,7 @@ static int32_t mndStreamGetPlanString(const char *ast, char **pStr) {
|
|||
return code;
|
||||
}
|
||||
|
||||
int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, STrans *pTrans) {
|
||||
int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast, int8_t triggerType, int64_t watermark, STrans *pTrans) {
|
||||
SNode *pAst = NULL;
|
||||
|
||||
if (nodesStringToNode(ast, &pAst) < 0) {
|
||||
|
@ -265,7 +267,7 @@ int32_t mndAddStreamToTrans(SMnode *pMnode, SStreamObj *pStream, const char *ast
|
|||
|
||||
#endif
|
||||
|
||||
if (TSDB_CODE_SUCCESS != mndStreamGetPlanString(ast, &pStream->physicalPlan)) {
|
||||
if (TSDB_CODE_SUCCESS != mndStreamGetPlanString(ast, triggerType, watermark, &pStream->physicalPlan)) {
|
||||
mError("topic:%s, failed to get plan since %s", pStream->name, terrstr());
|
||||
return -1;
|
||||
}
|
||||
|
@ -313,7 +315,7 @@ static int32_t mndCreateStream(SMnode *pMnode, SNodeMsg *pReq, SCMCreateStreamRe
|
|||
}
|
||||
mDebug("trans:%d, used to create stream:%s", pTrans->id, pCreate->name);
|
||||
|
||||
if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pTrans) != 0) {
|
||||
if (mndAddStreamToTrans(pMnode, &streamObj, pCreate->ast, pCreate->triggerType, pCreate->watermark, pTrans) != 0) {
|
||||
mError("trans:%d, failed to add stream since %s", pTrans->id, terrstr());
|
||||
mndTransDrop(pTrans);
|
||||
return -1;
|
||||
|
|
|
@ -18,12 +18,11 @@ target_sources(
|
|||
"src/vnd/vnodeSvr.c"
|
||||
|
||||
# meta
|
||||
# "src/meta/metaBDBImpl.c"
|
||||
"src/meta/metaOpen.c"
|
||||
"src/meta/metaIdx.c"
|
||||
"src/meta/metaMain.c"
|
||||
"src/meta/metaTable.c"
|
||||
"src/meta/metaTbUid.c"
|
||||
"src/meta/metaTDBImpl.c"
|
||||
# "src/meta/metaBDBImpl.c"
|
||||
|
||||
# tsdb
|
||||
"src/tsdb/tsdbTDBImpl.c"
|
||||
|
|
|
@ -37,16 +37,14 @@ extern "C" {
|
|||
|
||||
// vnode
|
||||
typedef struct SVnode SVnode;
|
||||
typedef struct SMetaCfg SMetaCfg; // todo: remove
|
||||
typedef struct STsdbCfg STsdbCfg; // todo: remove
|
||||
typedef struct STqCfg STqCfg; // todo: remove
|
||||
typedef struct SVnodeCfg SVnodeCfg;
|
||||
|
||||
int vnodeInit(int nthreads);
|
||||
void vnodeCleanup();
|
||||
int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs);
|
||||
void vnodeDestroy(const char *path);
|
||||
SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg);
|
||||
void vnodeDestroy(const char *path, STfs *pTfs);
|
||||
SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb);
|
||||
void vnodeClose(SVnode *pVnode);
|
||||
void vnodePreprocessWriteReqs(SVnode *pVnode, SArray *pMsgs);
|
||||
int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp);
|
||||
|
@ -73,7 +71,6 @@ char *metaTbCursorNext(SMTbCursor *pTbCur);
|
|||
|
||||
// tsdb
|
||||
typedef struct STsdb STsdb;
|
||||
typedef struct SDataStatis SDataStatis;
|
||||
typedef struct STsdbQueryCond STsdbQueryCond;
|
||||
typedef void *tsdbReaderT;
|
||||
|
||||
|
@ -93,7 +90,7 @@ int32_t tsdbQuerySTableByTagCond(void *pMeta, uint64_t uid, TSKEY skey, con
|
|||
int64_t tsdbGetNumOfRowsInMemTable(tsdbReaderT *pHandle);
|
||||
bool tsdbNextDataBlock(tsdbReaderT pTsdbReadHandle);
|
||||
void tsdbRetrieveDataBlockInfo(tsdbReaderT *pTsdbReadHandle, SDataBlockInfo *pBlockInfo);
|
||||
int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SDataStatis **pBlockStatis);
|
||||
int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT *pTsdbReadHandle, SColumnDataAgg **pBlockStatis);
|
||||
SArray *tsdbRetrieveDataBlock(tsdbReaderT *pTsdbReadHandle, SArray *pColumnIdList);
|
||||
void tsdbDestroyTableGroup(STableGroupInfo *pGroupList);
|
||||
int32_t tsdbGetOneTableGroup(void *pMeta, uint64_t uid, TSKEY startKey, STableGroupInfo *pGroupInfo);
|
||||
|
@ -134,14 +131,9 @@ struct STsdbCfg {
|
|||
SArray *retentions;
|
||||
};
|
||||
|
||||
struct STqCfg {
|
||||
int32_t reserved;
|
||||
};
|
||||
|
||||
struct SVnodeCfg {
|
||||
int32_t vgId;
|
||||
uint64_t dbId;
|
||||
STfs *pTfs;
|
||||
uint64_t wsize;
|
||||
uint64_t ssize;
|
||||
uint64_t lsize;
|
||||
|
@ -151,25 +143,12 @@ struct SVnodeCfg {
|
|||
int8_t streamMode;
|
||||
bool isWeak;
|
||||
STsdbCfg tsdbCfg;
|
||||
SMetaCfg metaCfg;
|
||||
STqCfg tqCfg;
|
||||
SWalCfg walCfg;
|
||||
SMsgCb msgCb;
|
||||
uint32_t hashBegin;
|
||||
uint32_t hashEnd;
|
||||
int8_t hashMethod;
|
||||
};
|
||||
|
||||
struct SDataStatis {
|
||||
int16_t colId;
|
||||
int16_t maxIndex;
|
||||
int16_t minIndex;
|
||||
int16_t numOfNull;
|
||||
int64_t sum;
|
||||
int64_t max;
|
||||
int64_t min;
|
||||
};
|
||||
|
||||
struct STsdbQueryCond {
|
||||
STimeWindow twindow;
|
||||
int32_t order; // desc|asc order to iterate the data block
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct SMetaCache SMetaCache;
|
||||
typedef struct SMetaIdx SMetaIdx;
|
||||
typedef struct SMetaDB SMetaDB;
|
||||
typedef struct SMCtbCursor SMCtbCursor;
|
||||
|
@ -36,13 +35,22 @@ typedef struct SMSmaCursor SMSmaCursor;
|
|||
#define metaTrace(...) do { if (metaDebugFlag & DEBUG_TRACE) { taosPrintLog("META ", DEBUG_TRACE, metaDebugFlag, __VA_ARGS__); }} while(0)
|
||||
// clang-format on
|
||||
|
||||
// metaOpen ==================
|
||||
int metaOpen(SVnode* pVnode, SMeta** ppMeta);
|
||||
int metaClose(SMeta* pMeta);
|
||||
|
||||
// metaIdx ==================
|
||||
int metaOpenIdx(SMeta* pMeta);
|
||||
void metaCloseIdx(SMeta* pMeta);
|
||||
int metaSaveTableToIdx(SMeta* pMeta, const STbCfg* pTbOptions);
|
||||
int metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid);
|
||||
|
||||
static FORCE_INLINE tb_uid_t metaGenerateUid(SMeta* pMeta) { return tGenIdPI64(); }
|
||||
|
||||
#define META_SUPER_TABLE TD_SUPER_TABLE
|
||||
#define META_CHILD_TABLE TD_CHILD_TABLE
|
||||
#define META_NORMAL_TABLE TD_NORMAL_TABLE
|
||||
|
||||
SMeta* metaOpen(const char* path, const SMetaCfg* pMetaCfg, SMemAllocatorFactory* pMAF);
|
||||
void metaClose(SMeta* pMeta);
|
||||
void metaRemove(const char* path);
|
||||
int metaCreateTable(SMeta* pMeta, STbCfg* pTbCfg);
|
||||
int metaDropTable(SMeta* pMeta, tb_uid_t uid);
|
||||
int metaCommit(SMeta* pMeta);
|
||||
|
@ -71,38 +79,15 @@ int metaRemoveTableFromDb(SMeta* pMeta, tb_uid_t uid);
|
|||
int metaSaveSmaToDB(SMeta* pMeta, STSma* pTbCfg);
|
||||
int metaRemoveSmaFromDb(SMeta* pMeta, int64_t indexUid);
|
||||
|
||||
// SMetaCache
|
||||
int metaOpenCache(SMeta* pMeta);
|
||||
void metaCloseCache(SMeta* pMeta);
|
||||
|
||||
// SMetaIdx
|
||||
int metaOpenIdx(SMeta* pMeta);
|
||||
void metaCloseIdx(SMeta* pMeta);
|
||||
int metaSaveTableToIdx(SMeta* pMeta, const STbCfg* pTbOptions);
|
||||
int metaRemoveTableFromIdx(SMeta* pMeta, tb_uid_t uid);
|
||||
|
||||
// STbUidGnrt
|
||||
typedef struct STbUidGenerator {
|
||||
tb_uid_t nextUid;
|
||||
} STbUidGenerator;
|
||||
|
||||
// STableUidGenerator
|
||||
int metaOpenUidGnrt(SMeta* pMeta);
|
||||
void metaCloseUidGnrt(SMeta* pMeta);
|
||||
|
||||
// tb_uid_t
|
||||
#define IVLD_TB_UID 0
|
||||
tb_uid_t metaGenerateUid(SMeta* pMeta);
|
||||
|
||||
struct SMeta {
|
||||
char* path;
|
||||
SVnode* pVnode;
|
||||
SMetaCfg options;
|
||||
SMetaDB* pDB;
|
||||
SMetaIdx* pIdx;
|
||||
SMetaCache* pCache;
|
||||
STbUidGenerator uidGnrt;
|
||||
SMemAllocatorFactory* pmaf;
|
||||
char* path;
|
||||
SVnode* pVnode;
|
||||
SMetaDB* pDB;
|
||||
SMetaIdx* pIdx;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -160,7 +160,6 @@ struct STQ {
|
|||
// the handle of meta kvstore
|
||||
bool writeTrigger;
|
||||
char* path;
|
||||
STqCfg* tqConfig;
|
||||
STqMemRef tqMemRef;
|
||||
STqMetaStore* tqMeta;
|
||||
// STqPushMgr* tqPushMgr;
|
||||
|
@ -251,8 +250,7 @@ int tqInit();
|
|||
void tqCleanUp();
|
||||
|
||||
// open in each vnode
|
||||
STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pMeta, STqCfg* tqConfig,
|
||||
SMemAllocatorFactory* allocFac);
|
||||
STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pMeta, SMemAllocatorFactory* allocFac);
|
||||
void tqClose(STQ*);
|
||||
// required by vnode
|
||||
int tqPushMsg(STQ*, void* msg, int32_t msgLen, tmsg_t msgType, int64_t version);
|
||||
|
|
|
@ -43,10 +43,8 @@ typedef struct STable {
|
|||
#define TABLE_TID(t) (t)->tid
|
||||
#define TABLE_UID(t) (t)->uid
|
||||
|
||||
STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF, SMeta *pMeta,
|
||||
STfs *pTfs);
|
||||
STsdb *tsdbOpen(const char *path, SVnode *pVnode, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF);
|
||||
void tsdbClose(STsdb *);
|
||||
void tsdbRemove(const char *path);
|
||||
int tsdbInsertData(STsdb *pTsdb, SSubmitReq *pMsg, SSubmitRsp *pRsp);
|
||||
int tsdbPrepareCommit(STsdb *pTsdb);
|
||||
int tsdbCommit(STsdb *pTsdb);
|
||||
|
@ -167,16 +165,14 @@ struct STsdb {
|
|||
SRtn rtn;
|
||||
SMemAllocatorFactory *pmaf;
|
||||
STsdbFS *fs;
|
||||
SMeta *pMeta;
|
||||
STfs *pTfs;
|
||||
SSmaEnvs smaEnvs;
|
||||
};
|
||||
|
||||
#define REPO_ID(r) ((r)->vgId)
|
||||
#define REPO_CFG(r) (&(r)->config)
|
||||
#define REPO_FS(r) ((r)->fs)
|
||||
#define REPO_META(r) ((r)->pMeta)
|
||||
#define REPO_TFS(r) ((r)->pTfs)
|
||||
#define REPO_META(r) ((r)->pVnode->pMeta)
|
||||
#define REPO_TFS(r) ((r)->pVnode->pTfs)
|
||||
#define IS_REPO_LOCKED(r) ((r)->repoLocked)
|
||||
#define REPO_TSMA_NUM(r) ((r)->smaEnvs.nTSma)
|
||||
#define REPO_RSMA_NUM(r) ((r)->smaEnvs.nRSma)
|
||||
|
@ -438,7 +434,7 @@ int tsdbLoadBlockDataCols(SReadH *pReadh, SBlock *pBlock, SBlockInfo *pBlkInfo,
|
|||
int tsdbLoadBlockStatis(SReadH *pReadh, SBlock *pBlock);
|
||||
int tsdbEncodeSBlockIdx(void **buf, SBlockIdx *pIdx);
|
||||
void *tsdbDecodeSBlockIdx(void *buf, SBlockIdx *pIdx);
|
||||
void tsdbGetBlockStatis(SReadH *pReadh, SDataStatis *pStatis, int numOfCols, SBlock *pBlock);
|
||||
void tsdbGetBlockStatis(SReadH *pReadh, SColumnDataAgg *pStatis, int numOfCols, SBlock *pBlock);
|
||||
|
||||
static FORCE_INLINE int tsdbMakeRoom(void **ppBuf, size_t size) {
|
||||
void *pBuf = *ppBuf;
|
||||
|
|
|
@ -44,6 +44,11 @@ int vnodeGetTableMeta(SVnode* pVnode, SRpcMsg* pMsg);
|
|||
int vnodeSaveInfo(const char* dir, const SVnodeInfo* pCfg);
|
||||
int vnodeCommitInfo(const char* dir, const SVnodeInfo* pInfo);
|
||||
int vnodeLoadInfo(const char* dir, SVnodeInfo* pInfo);
|
||||
int vnodeBegin(SVnode* pVnode, int option);
|
||||
int vnodeSyncCommit(SVnode* pVnode);
|
||||
int vnodeAsyncCommit(SVnode* pVnode);
|
||||
|
||||
#define vnodeShouldCommit vnodeBufPoolIsFull
|
||||
|
||||
#if 1
|
||||
// SVBufPool
|
||||
|
@ -84,13 +89,8 @@ bool vmaIsFull(SVMemAllocator* pVMA);
|
|||
// vnodeCfg.h
|
||||
extern const SVnodeCfg vnodeCfgDefault;
|
||||
|
||||
int vnodeCheckCfg(const SVnodeCfg*);
|
||||
void vnodeOptionsCopy(SVnodeCfg* pDest, const SVnodeCfg* pSrc);
|
||||
int vnodeCheckCfg(const SVnodeCfg*);
|
||||
|
||||
// For commit
|
||||
#define vnodeShouldCommit vnodeBufPoolIsFull
|
||||
int vnodeSyncCommit(SVnode* pVnode);
|
||||
int vnodeAsyncCommit(SVnode* pVnode);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -52,6 +52,11 @@ typedef struct SVState SVState;
|
|||
typedef struct SVBufPool SVBufPool;
|
||||
typedef struct SQWorkerMgmt SQHandle;
|
||||
|
||||
#define VNODE_META_DIR "meta"
|
||||
#define VNODE_TSDB_DIR "tsdb"
|
||||
#define VNODE_TQ_DIR "tq"
|
||||
#define VNODE_WAL_DIR "wal"
|
||||
|
||||
typedef struct {
|
||||
int8_t streamType; // sma or other
|
||||
int8_t dstType;
|
||||
|
@ -80,10 +85,11 @@ struct SVnodeInfo {
|
|||
};
|
||||
|
||||
struct SVnode {
|
||||
int32_t vgId;
|
||||
char* path;
|
||||
SVnodeCfg config;
|
||||
SVState state;
|
||||
STfs* pTfs;
|
||||
SMsgCb msgCb;
|
||||
SVBufPool* pBufPool;
|
||||
SMeta* pMeta;
|
||||
STsdb* pTsdb;
|
||||
|
@ -92,10 +98,10 @@ struct SVnode {
|
|||
SSink* pSink;
|
||||
tsem_t canCommit;
|
||||
SQHandle* pQuery;
|
||||
SMsgCb msgCb;
|
||||
STfs* pTfs;
|
||||
};
|
||||
|
||||
#define TD_VID(PVNODE) (PVNODE)->config.vgId
|
||||
|
||||
// sma
|
||||
void smaHandleRes(void* pVnode, int64_t smaId, const SArray* data);
|
||||
|
||||
|
|
|
@ -1,111 +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/>.
|
||||
*/
|
||||
|
||||
#include "tcoding.h"
|
||||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
static SMeta *metaNew(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF);
|
||||
static void metaFree(SMeta *pMeta);
|
||||
static int metaOpenImpl(SMeta *pMeta);
|
||||
static void metaCloseImpl(SMeta *pMeta);
|
||||
|
||||
SMeta *metaOpen(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF) {
|
||||
SMeta *pMeta = NULL;
|
||||
|
||||
// Allocate handle
|
||||
pMeta = metaNew(path, pMetaCfg, pMAF);
|
||||
if (pMeta == NULL) {
|
||||
// TODO: handle error
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create META path (TODO)
|
||||
taosMkDir(path);
|
||||
|
||||
// Open meta
|
||||
if (metaOpenImpl(pMeta) < 0) {
|
||||
metaFree(pMeta);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pMeta;
|
||||
}
|
||||
|
||||
void metaClose(SMeta *pMeta) {
|
||||
if (pMeta) {
|
||||
metaCloseImpl(pMeta);
|
||||
metaFree(pMeta);
|
||||
}
|
||||
}
|
||||
|
||||
void metaRemove(const char *path) { taosRemoveDir(path); }
|
||||
|
||||
/* ------------------------ STATIC METHODS ------------------------ */
|
||||
static SMeta *metaNew(const char *path, const SMetaCfg *pMetaCfg, SMemAllocatorFactory *pMAF) {
|
||||
SMeta *pMeta;
|
||||
size_t psize = strlen(path);
|
||||
|
||||
pMeta = (SMeta *)taosMemoryCalloc(1, sizeof(*pMeta));
|
||||
if (pMeta == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pMeta->path = strdup(path);
|
||||
if (pMeta->path == NULL) {
|
||||
metaFree(pMeta);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return pMeta;
|
||||
};
|
||||
|
||||
static void metaFree(SMeta *pMeta) {
|
||||
if (pMeta) {
|
||||
taosMemoryFreeClear(pMeta->path);
|
||||
taosMemoryFree(pMeta);
|
||||
}
|
||||
}
|
||||
|
||||
static int metaOpenImpl(SMeta *pMeta) {
|
||||
// Open meta db
|
||||
if (metaOpenDB(pMeta) < 0) {
|
||||
// TODO: handle error
|
||||
metaCloseImpl(pMeta);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Open meta index
|
||||
if (metaOpenIdx(pMeta) < 0) {
|
||||
// TODO: handle error
|
||||
metaCloseImpl(pMeta);
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Open meta table uid generator
|
||||
if (metaOpenUidGnrt(pMeta) < 0) {
|
||||
// TODO: handle error
|
||||
metaCloseImpl(pMeta);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void metaCloseImpl(SMeta *pMeta) {
|
||||
metaCloseUidGnrt(pMeta);
|
||||
metaCloseIdx(pMeta);
|
||||
metaCloseDB(pMeta);
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
int metaOpen(SVnode *pVnode, SMeta **ppMeta) {
|
||||
SMeta *pMeta = NULL;
|
||||
int slen;
|
||||
|
||||
*ppMeta = NULL;
|
||||
|
||||
// create handle
|
||||
slen = strlen(tfsGetPrimaryPath(pVnode->pTfs)) + strlen(pVnode->path) + strlen(VNODE_META_DIR) + 3;
|
||||
if ((pMeta = taosMemoryCalloc(1, sizeof(*pMeta) + slen)) == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
return -1;
|
||||
}
|
||||
|
||||
pMeta->path = (char *)&pMeta[1];
|
||||
sprintf(pMeta->path, "%s%s%s%s%s", tfsGetPrimaryPath(pVnode->pTfs), TD_DIRSEP, pVnode->path, TD_DIRSEP,
|
||||
VNODE_META_DIR);
|
||||
pMeta->pVnode = pVnode;
|
||||
|
||||
// create path if not created yet
|
||||
taosMkDir(pMeta->path);
|
||||
|
||||
// open meta
|
||||
if (metaOpenDB(pMeta) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
if (metaOpenIdx(pMeta) < 0) {
|
||||
goto _err;
|
||||
}
|
||||
|
||||
*ppMeta = pMeta;
|
||||
return 0;
|
||||
|
||||
_err:
|
||||
if (pMeta->pIdx) metaCloseIdx(pMeta);
|
||||
if (pMeta->pDB) metaCloseDB(pMeta);
|
||||
taosMemoryFree(pMeta);
|
||||
return -1;
|
||||
}
|
||||
|
||||
int metaClose(SMeta *pMeta) {
|
||||
if (pMeta) {
|
||||
metaCloseIdx(pMeta);
|
||||
metaCloseDB(pMeta);
|
||||
taosMemoryFree(pMeta);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -19,15 +19,13 @@ int32_t tqInit() { return tqPushMgrInit(); }
|
|||
|
||||
void tqCleanUp() { tqPushMgrCleanUp(); }
|
||||
|
||||
STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pVnodeMeta, STqCfg* tqConfig,
|
||||
SMemAllocatorFactory* allocFac) {
|
||||
STQ* tqOpen(const char* path, SVnode* pVnode, SWal* pWal, SMeta* pVnodeMeta, SMemAllocatorFactory* allocFac) {
|
||||
STQ* pTq = taosMemoryMalloc(sizeof(STQ));
|
||||
if (pTq == NULL) {
|
||||
terrno = TSDB_CODE_TQ_OUT_OF_MEMORY;
|
||||
return NULL;
|
||||
}
|
||||
pTq->path = strdup(path);
|
||||
pTq->tqConfig = tqConfig;
|
||||
pTq->pVnode = pVnode;
|
||||
pTq->pWal = pWal;
|
||||
pTq->pVnodeMeta = pVnodeMeta;
|
||||
|
@ -267,7 +265,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
}
|
||||
|
||||
vDebug("tmq poll: consumer %ld (epoch %d) recv poll req in vg %d, req %ld %ld", consumerId, pReq->epoch,
|
||||
pTq->pVnode->vgId, pReq->currentOffset, fetchOffset);
|
||||
TD_VID(pTq->pVnode), pReq->currentOffset, fetchOffset);
|
||||
|
||||
SMqPollRsp rsp = {
|
||||
/*.consumerId = consumerId,*/
|
||||
|
@ -277,7 +275,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
|
||||
STqConsumer* pConsumer = tqHandleGet(pTq->tqMeta, consumerId);
|
||||
if (pConsumer == NULL) {
|
||||
vWarn("tmq poll: consumer %ld (epoch %d) not found in vg %d", consumerId, pReq->epoch, pTq->pVnode->vgId);
|
||||
vWarn("tmq poll: consumer %ld (epoch %d) not found in vg %d", consumerId, pReq->epoch, TD_VID(pTq->pVnode));
|
||||
pMsg->pCont = NULL;
|
||||
pMsg->contLen = 0;
|
||||
pMsg->code = -1;
|
||||
|
@ -303,7 +301,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
}
|
||||
if (pTopic == NULL) {
|
||||
vWarn("tmq poll: consumer %ld (epoch %d) topic %s not found in vg %d", consumerId, pReq->epoch, pReq->topic,
|
||||
pTq->pVnode->vgId);
|
||||
TD_VID(pTq->pVnode));
|
||||
pMsg->pCont = NULL;
|
||||
pMsg->contLen = 0;
|
||||
pMsg->code = -1;
|
||||
|
@ -312,7 +310,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
}
|
||||
|
||||
vDebug("poll topic %s from consumer %ld (epoch %d) vg %d", pTopic->topicName, consumerId, pReq->epoch,
|
||||
pTq->pVnode->vgId);
|
||||
TD_VID(pTq->pVnode));
|
||||
|
||||
rsp.reqOffset = pReq->currentOffset;
|
||||
rsp.skipLogNum = 0;
|
||||
|
@ -323,7 +321,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
consumerEpoch = atomic_load_32(&pConsumer->epoch);
|
||||
if (consumerEpoch > reqEpoch) {
|
||||
vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, found new consumer epoch %d discard req epoch %d",
|
||||
consumerId, pReq->epoch, pTq->pVnode->vgId, fetchOffset, consumerEpoch, reqEpoch);
|
||||
consumerId, pReq->epoch, TD_VID(pTq->pVnode), fetchOffset, consumerEpoch, reqEpoch);
|
||||
break;
|
||||
}
|
||||
SWalReadHead* pHead;
|
||||
|
@ -332,11 +330,11 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
// if data inserted during waiting, launch query and
|
||||
// response to user
|
||||
vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, no more log to return", consumerId, pReq->epoch,
|
||||
pTq->pVnode->vgId, fetchOffset);
|
||||
TD_VID(pTq->pVnode), fetchOffset);
|
||||
break;
|
||||
}
|
||||
vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d", consumerId, pReq->epoch,
|
||||
pTq->pVnode->vgId, fetchOffset, pHead->msgType);
|
||||
TD_VID(pTq->pVnode), fetchOffset, pHead->msgType);
|
||||
/*int8_t pos = fetchOffset % TQ_BUFFER_SIZE;*/
|
||||
/*pHead = pTopic->pReadhandle->pHead;*/
|
||||
if (pHead->msgType == TDMT_VND_SUBMIT) {
|
||||
|
@ -361,7 +359,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
|
||||
if (taosArrayGetSize(pRes) == 0) {
|
||||
vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d skip log %ld since not wanted", consumerId,
|
||||
pReq->epoch, pTq->pVnode->vgId, fetchOffset);
|
||||
pReq->epoch, TD_VID(pTq->pVnode), fetchOffset);
|
||||
fetchOffset++;
|
||||
rsp.skipLogNum++;
|
||||
taosArrayDestroy(pRes);
|
||||
|
@ -390,7 +388,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
pMsg->pCont = buf;
|
||||
pMsg->contLen = tlen;
|
||||
pMsg->code = 0;
|
||||
vDebug("vg %d offset %ld msgType %d from consumer %ld (epoch %d) actual rsp", pTq->pVnode->vgId, fetchOffset,
|
||||
vDebug("vg %d offset %ld msgType %d from consumer %ld (epoch %d) actual rsp", TD_VID(pTq->pVnode), fetchOffset,
|
||||
pHead->msgType, consumerId, pReq->epoch);
|
||||
tmsgSendRsp(pMsg);
|
||||
taosMemoryFree(pHead);
|
||||
|
@ -422,7 +420,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
pMsg->contLen = tlen;
|
||||
pMsg->code = 0;
|
||||
tmsgSendRsp(pMsg);
|
||||
vDebug("vg %d offset %ld from consumer %ld (epoch %d) not rsp", pTq->pVnode->vgId, fetchOffset, consumerId,
|
||||
vDebug("vg %d offset %ld from consumer %ld (epoch %d) not rsp", TD_VID(pTq->pVnode), fetchOffset, consumerId,
|
||||
pReq->epoch);
|
||||
/*}*/
|
||||
|
||||
|
@ -446,14 +444,14 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
}
|
||||
|
||||
vDebug("tmq poll: consumer %ld (epoch %d) recv poll req in vg %d, req %ld %ld", consumerId, pReq->epoch,
|
||||
pTq->pVnode->vgId, pReq->currentOffset, fetchOffset);
|
||||
TD_VID(pTq->pVnode), pReq->currentOffset, fetchOffset);
|
||||
|
||||
SMqPollRspV2 rspV2 = {0};
|
||||
rspV2.dataLen = 0;
|
||||
|
||||
STqConsumer* pConsumer = tqHandleGet(pTq->tqMeta, consumerId);
|
||||
if (pConsumer == NULL) {
|
||||
vWarn("tmq poll: consumer %ld (epoch %d) not found in vg %d", consumerId, pReq->epoch, pTq->pVnode->vgId);
|
||||
vWarn("tmq poll: consumer %ld (epoch %d) not found in vg %d", consumerId, pReq->epoch, TD_VID(pTq->pVnode));
|
||||
pMsg->pCont = NULL;
|
||||
pMsg->contLen = 0;
|
||||
pMsg->code = -1;
|
||||
|
@ -479,7 +477,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
}
|
||||
if (pTopic == NULL) {
|
||||
vWarn("tmq poll: consumer %ld (epoch %d) topic %s not found in vg %d", consumerId, pReq->epoch, pReq->topic,
|
||||
pTq->pVnode->vgId);
|
||||
TD_VID(pTq->pVnode));
|
||||
pMsg->pCont = NULL;
|
||||
pMsg->contLen = 0;
|
||||
pMsg->code = -1;
|
||||
|
@ -488,7 +486,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
}
|
||||
|
||||
vDebug("poll topic %s from consumer %ld (epoch %d) vg %d", pTopic->topicName, consumerId, pReq->epoch,
|
||||
pTq->pVnode->vgId);
|
||||
TD_VID(pTq->pVnode));
|
||||
|
||||
rspV2.reqOffset = pReq->currentOffset;
|
||||
rspV2.skipLogNum = 0;
|
||||
|
@ -499,7 +497,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
consumerEpoch = atomic_load_32(&pConsumer->epoch);
|
||||
if (consumerEpoch > reqEpoch) {
|
||||
vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, found new consumer epoch %d discard req epoch %d",
|
||||
consumerId, pReq->epoch, pTq->pVnode->vgId, fetchOffset, consumerEpoch, reqEpoch);
|
||||
consumerId, pReq->epoch, TD_VID(pTq->pVnode), fetchOffset, consumerEpoch, reqEpoch);
|
||||
break;
|
||||
}
|
||||
SWalReadHead* pHead;
|
||||
|
@ -508,11 +506,11 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
// if data inserted during waiting, launch query and
|
||||
// response to user
|
||||
vDebug("tmq poll: consumer %ld (epoch %d) vg %d offset %ld, no more log to return", consumerId, pReq->epoch,
|
||||
pTq->pVnode->vgId, fetchOffset);
|
||||
TD_VID(pTq->pVnode), fetchOffset);
|
||||
break;
|
||||
}
|
||||
vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d offset %ld msgType %d", consumerId, pReq->epoch,
|
||||
pTq->pVnode->vgId, fetchOffset, pHead->msgType);
|
||||
TD_VID(pTq->pVnode), fetchOffset, pHead->msgType);
|
||||
/*int8_t pos = fetchOffset % TQ_BUFFER_SIZE;*/
|
||||
/*pHead = pTopic->pReadhandle->pHead;*/
|
||||
if (pHead->msgType == TDMT_VND_SUBMIT) {
|
||||
|
@ -537,7 +535,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
|
||||
if (taosArrayGetSize(pRes) == 0) {
|
||||
vDebug("tmq poll: consumer %ld (epoch %d) iter log, vg %d skip log %ld since not wanted", consumerId,
|
||||
pReq->epoch, pTq->pVnode->vgId, fetchOffset);
|
||||
pReq->epoch, TD_VID(pTq->pVnode), fetchOffset);
|
||||
fetchOffset++;
|
||||
rspV2.skipLogNum++;
|
||||
taosArrayDestroy(pRes);
|
||||
|
@ -597,7 +595,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
pMsg->pCont = buf;
|
||||
pMsg->contLen = msgLen;
|
||||
pMsg->code = 0;
|
||||
vDebug("vg %d offset %ld msgType %d from consumer %ld (epoch %d) actual rsp", pTq->pVnode->vgId, fetchOffset,
|
||||
vDebug("vg %d offset %ld msgType %d from consumer %ld (epoch %d) actual rsp", TD_VID(pTq->pVnode), fetchOffset,
|
||||
pHead->msgType, consumerId, pReq->epoch);
|
||||
tmsgSendRsp(pMsg);
|
||||
taosMemoryFree(pHead);
|
||||
|
@ -631,7 +629,7 @@ int32_t tqProcessPollReq(STQ* pTq, SRpcMsg* pMsg, int32_t workerId) {
|
|||
pMsg->contLen = tlen;
|
||||
pMsg->code = 0;
|
||||
tmsgSendRsp(pMsg);
|
||||
vDebug("vg %d offset %ld from consumer %ld (epoch %d) not rsp", pTq->pVnode->vgId, fetchOffset, consumerId,
|
||||
vDebug("vg %d offset %ld from consumer %ld (epoch %d) not rsp", TD_VID(pTq->pVnode), fetchOffset, consumerId,
|
||||
pReq->epoch);
|
||||
/*}*/
|
||||
|
||||
|
@ -742,7 +740,7 @@ int32_t tqProcessSetConnReq(STQ* pTq, char* msg) {
|
|||
pTopic->buffer.output[i].task = qCreateStreamExecTaskInfo(req.qmsg, &handle);
|
||||
ASSERT(pTopic->buffer.output[i].task);
|
||||
}
|
||||
vDebug("set topic %s to consumer %ld on vg %d", pTopic->topicName, req.consumerId, pTq->pVnode->vgId);
|
||||
vDebug("set topic %s to consumer %ld on vg %d", pTopic->topicName, req.consumerId, TD_VID(pTq->pVnode));
|
||||
taosArrayPush(pConsumer->topics, pTopic);
|
||||
if (create) {
|
||||
tqHandleMovePut(pTq->tqMeta, req.consumerId, pConsumer);
|
||||
|
|
|
@ -100,7 +100,7 @@ int tsdbApplyRtnOnFSet(STsdb *pRepo, SDFileSet *pSet, SRtn *pRtn) {
|
|||
|
||||
level = tsdbGetFidLevel(pSet->fid, pRtn);
|
||||
|
||||
if (tfsAllocDisk(pRepo->pTfs, level, &did) < 0) {
|
||||
if (tfsAllocDisk(pRepo->pVnode->pTfs, level, &did) < 0) {
|
||||
terrno = TSDB_CODE_TDB_NO_AVAIL_DISK;
|
||||
return -1;
|
||||
}
|
||||
|
@ -427,7 +427,7 @@ static int tsdbCreateCommitIters(SCommitH *pCommith) {
|
|||
pCommitIter->pTable = (STable *)taosMemoryMalloc(sizeof(STable));
|
||||
pCommitIter->pTable->uid = pTbData->uid;
|
||||
pCommitIter->pTable->tid = pTbData->uid;
|
||||
pCommitIter->pTable->pSchema = metaGetTbTSchema(pRepo->pMeta, pTbData->uid, 0);
|
||||
pCommitIter->pTable->pSchema = metaGetTbTSchema(REPO_META(pRepo), pTbData->uid, 0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -459,7 +459,7 @@ static int tsdbSetAndOpenCommitFile(SCommitH *pCommith, SDFileSet *pSet, int fid
|
|||
STsdb *pRepo = TSDB_COMMIT_REPO(pCommith);
|
||||
SDFileSet *pWSet = TSDB_COMMIT_WRITE_FSET(pCommith);
|
||||
|
||||
if (tfsAllocDisk(pRepo->pTfs, tsdbGetFidLevel(fid, &(pCommith->rtn)), &did) < 0) {
|
||||
if (tfsAllocDisk(REPO_TFS(pRepo), tsdbGetFidLevel(fid, &(pCommith->rtn)), &did) < 0) {
|
||||
terrno = TSDB_CODE_TDB_NO_AVAIL_DISK;
|
||||
return -1;
|
||||
}
|
||||
|
@ -1250,7 +1250,7 @@ int tsdbWriteBlockImpl(STsdb *pRepo, STable *pTable, SDFile *pDFile, SDFile *pDF
|
|||
&(pBlockCol->sum), &(pBlockCol->minIndex), &(pBlockCol->maxIndex),
|
||||
&(pBlockCol->numOfNull));
|
||||
#endif
|
||||
(*tDataTypes[pDataCol->type].statisFunc)(pDataCol->pData, rowsToWrite, &(pAggrBlkCol->min), &(pAggrBlkCol->max),
|
||||
(*tDataTypes[pDataCol->type].statisFunc)(pDataCol->pBitmap, pDataCol->pData, rowsToWrite, &(pAggrBlkCol->min), &(pAggrBlkCol->max),
|
||||
&(pAggrBlkCol->sum), &(pAggrBlkCol->minIndex), &(pAggrBlkCol->maxIndex),
|
||||
&(pAggrBlkCol->numOfNull));
|
||||
|
||||
|
|
|
@ -644,7 +644,7 @@ static int tsdbComparFidFSet(const void *arg1, const void *arg2) {
|
|||
}
|
||||
|
||||
static void tsdbGetTxnFname(STsdb *pRepo, TSDB_TXN_FILE_T ftype, char fname[]) {
|
||||
snprintf(fname, TSDB_FILENAME_LEN, "%s/vnode/vnode%d/tsdb/%s", tfsGetPrimaryPath(pRepo->pTfs), pRepo->vgId,
|
||||
snprintf(fname, TSDB_FILENAME_LEN, "%s/vnode/vnode%d/tsdb/%s", tfsGetPrimaryPath(REPO_TFS(pRepo)), pRepo->vgId,
|
||||
tsdbTxnFname[ftype]);
|
||||
}
|
||||
|
||||
|
@ -912,7 +912,7 @@ static int tsdbScanRootDir(STsdb *pRepo) {
|
|||
const STfsFile *pf;
|
||||
|
||||
tsdbGetRootDir(REPO_ID(pRepo), rootDir);
|
||||
STfsDir *tdir = tfsOpendir(pRepo->pTfs, rootDir);
|
||||
STfsDir *tdir = tfsOpendir(REPO_TFS(pRepo), rootDir);
|
||||
if (tdir == NULL) {
|
||||
tsdbError("vgId:%d failed to open directory %s since %s", REPO_ID(pRepo), rootDir, tstrerror(terrno));
|
||||
return -1;
|
||||
|
@ -946,7 +946,7 @@ static int tsdbScanDataDir(STsdb *pRepo) {
|
|||
const STfsFile *pf;
|
||||
|
||||
tsdbGetDataDir(REPO_ID(pRepo), dataDir);
|
||||
STfsDir *tdir = tfsOpendir(pRepo->pTfs, dataDir);
|
||||
STfsDir *tdir = tfsOpendir(REPO_TFS(pRepo), dataDir);
|
||||
if (tdir == NULL) {
|
||||
tsdbError("vgId:%d failed to open directory %s since %s", REPO_ID(pRepo), dataDir, tstrerror(terrno));
|
||||
return -1;
|
||||
|
@ -1128,7 +1128,7 @@ static int tsdbRestoreDFileSet(STsdb *pRepo) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
tdir = tfsOpendir(pRepo->pTfs, dataDir);
|
||||
tdir = tfsOpendir(REPO_TFS(pRepo), dataDir);
|
||||
if (tdir == NULL) {
|
||||
tsdbError("vgId:%d failed to restore DFileSet while open directory %s since %s", REPO_ID(pRepo), dataDir,
|
||||
tstrerror(terrno));
|
||||
|
|
|
@ -311,7 +311,7 @@ void tsdbInitDFile(STsdb *pRepo, SDFile *pDFile, SDiskID did, int fid, uint32_t
|
|||
pDFile->info.fver = tsdbGetDFSVersion(ftype);
|
||||
|
||||
tsdbGetFilename(pRepo->vgId, fid, ver, ftype, fname);
|
||||
tfsInitFile(pRepo->pTfs, &(pDFile->f), did, fname);
|
||||
tfsInitFile(REPO_TFS(pRepo), &(pDFile->f), did, fname);
|
||||
}
|
||||
|
||||
void tsdbInitDFileEx(SDFile *pDFile, SDFile *pODFile) {
|
||||
|
@ -330,7 +330,7 @@ int tsdbEncodeSDFile(void **buf, SDFile *pDFile) {
|
|||
|
||||
void *tsdbDecodeSDFile(STsdb *pRepo, void *buf, SDFile *pDFile) {
|
||||
buf = tsdbDecodeDFInfo(buf, &(pDFile->info));
|
||||
buf = tfsDecodeFile(pRepo->pTfs, buf, &(pDFile->f));
|
||||
buf = tfsDecodeFile(REPO_TFS(pRepo), buf, &(pDFile->f));
|
||||
TSDB_FILE_SET_CLOSED(pDFile);
|
||||
|
||||
return buf;
|
||||
|
@ -365,7 +365,7 @@ int tsdbCreateDFile(STsdb *pRepo, SDFile *pDFile, bool updateHeader, TSDB_FILE_T
|
|||
if (errno == ENOENT) {
|
||||
// Try to create directory recursively
|
||||
char *s = strdup(TSDB_FILE_REL_NAME(pDFile));
|
||||
if (tfsMkdirRecurAt(pRepo->pTfs, taosDirName(s), TSDB_FILE_DID(pDFile)) < 0) {
|
||||
if (tfsMkdirRecurAt(REPO_TFS(pRepo), taosDirName(s), TSDB_FILE_DID(pDFile)) < 0) {
|
||||
taosMemoryFreeClear(s);
|
||||
return -1;
|
||||
}
|
||||
|
@ -443,7 +443,7 @@ int tsdbLoadDFileHeader(SDFile *pDFile, SDFInfo *pInfo) {
|
|||
}
|
||||
|
||||
static int tsdbScanAndTryFixDFile(STsdb *pRepo, SDFile *pDFile) {
|
||||
SDFile df;
|
||||
SDFile df;
|
||||
|
||||
tsdbInitDFileEx(&df, pDFile);
|
||||
|
||||
|
|
|
@ -15,14 +15,12 @@
|
|||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF,
|
||||
SMeta *pMeta, STfs *pTfs);
|
||||
static STsdb *tsdbNew(const char *path, SVnode *pVnode, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF);
|
||||
static void tsdbFree(STsdb *pTsdb);
|
||||
static int tsdbOpenImpl(STsdb *pTsdb);
|
||||
static void tsdbCloseImpl(STsdb *pTsdb);
|
||||
|
||||
STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF, SMeta *pMeta,
|
||||
STfs *pTfs) {
|
||||
STsdb *tsdbOpen(const char *path, SVnode *pVnode, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF) {
|
||||
STsdb *pTsdb = NULL;
|
||||
|
||||
// Set default TSDB Options
|
||||
|
@ -37,7 +35,7 @@ STsdb *tsdbOpen(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAl
|
|||
}
|
||||
|
||||
// Create the handle
|
||||
pTsdb = tsdbNew(path, vgId, pTsdbCfg, pMAF, pMeta, pTfs);
|
||||
pTsdb = tsdbNew(path, pVnode, pTsdbCfg, pMAF);
|
||||
if (pTsdb == NULL) {
|
||||
// TODO: handle error
|
||||
return NULL;
|
||||
|
@ -61,11 +59,8 @@ void tsdbClose(STsdb *pTsdb) {
|
|||
}
|
||||
}
|
||||
|
||||
void tsdbRemove(const char *path) { taosRemoveDir(path); }
|
||||
|
||||
/* ------------------------ STATIC METHODS ------------------------ */
|
||||
static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF,
|
||||
SMeta *pMeta, STfs *pTfs) {
|
||||
static STsdb *tsdbNew(const char *path, SVnode *pVnode, const STsdbCfg *pTsdbCfg, SMemAllocatorFactory *pMAF) {
|
||||
STsdb *pTsdb = NULL;
|
||||
|
||||
pTsdb = (STsdb *)taosMemoryCalloc(1, sizeof(STsdb));
|
||||
|
@ -75,11 +70,10 @@ static STsdb *tsdbNew(const char *path, int32_t vgId, const STsdbCfg *pTsdbCfg,
|
|||
}
|
||||
|
||||
pTsdb->path = strdup(path);
|
||||
pTsdb->vgId = vgId;
|
||||
pTsdb->vgId = TD_VID(pVnode);
|
||||
pTsdb->pVnode = pVnode;
|
||||
tsdbOptionsCopy(&(pTsdb->config), pTsdbCfg);
|
||||
pTsdb->pmaf = pMAF;
|
||||
pTsdb->pMeta = pMeta;
|
||||
pTsdb->pTfs = pTfs;
|
||||
pTsdb->fs = tsdbNewFS(pTsdbCfg);
|
||||
|
||||
return pTsdb;
|
||||
|
@ -156,7 +150,7 @@ int tsdbUnlockRepo(STsdb *pTsdb) {
|
|||
|
||||
#define IS_VALID_PRECISION(precision) \
|
||||
(((precision) >= TSDB_TIME_PRECISION_MILLI) && ((precision) <= TSDB_TIME_PRECISION_NANO))
|
||||
#define TSDB_DEFAULT_COMPRESSION TWO_STAGE_COMP
|
||||
#define TSDB_DEFAULT_COMPRESSION TWO_STAGE_COMP
|
||||
#define IS_VALID_COMPRESSION(compression) (((compression) >= NO_COMPRESSION) && ((compression) <= TWO_STAGE_COMP))
|
||||
|
||||
static int32_t tsdbCheckAndSetDefaultCfg(STsdbCfg *pCfg);
|
||||
|
|
|
@ -97,8 +97,8 @@ int tsdbMemTableInsert(STsdb *pTsdb, STsdbMemTable *pMemTable, SSubmitReq *pMsg,
|
|||
}
|
||||
|
||||
if (pRsp != NULL) {
|
||||
pRsp->affectedRows = htonl(affectedrows);
|
||||
pRsp->numOfRows = htonl(numOfRows);
|
||||
pRsp->affectedRows = affectedrows;
|
||||
pRsp->numOfRows = numOfRows;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -99,10 +99,10 @@ typedef struct SIOCostSummary {
|
|||
|
||||
typedef struct STsdbReadHandle {
|
||||
STsdb* pTsdb;
|
||||
SQueryFilePos cur; // current position
|
||||
SQueryFilePos cur; // current position
|
||||
int16_t order;
|
||||
STimeWindow window; // the primary query time window that applies to all queries
|
||||
SDataStatis* statis; // query level statistics, only one table block statistics info exists at any time
|
||||
STimeWindow window; // the primary query time window that applies to all queries
|
||||
SColumnDataAgg* statis; // query level statistics, only one table block statistics info exists at any time
|
||||
int32_t numOfBlocks;
|
||||
SArray* pColumns; // column list, SColumnInfoData array list
|
||||
bool locateStart;
|
||||
|
@ -377,7 +377,7 @@ static STsdbReadHandle* tsdbQueryTablesImpl(STsdb* tsdb, STsdbQueryCond* pCond,
|
|||
|
||||
if (pCond->numOfCols > 0) {
|
||||
// allocate buffer in order to load data blocks from file
|
||||
pReadHandle->statis = taosMemoryCalloc(pCond->numOfCols, sizeof(SDataStatis));
|
||||
pReadHandle->statis = taosMemoryCalloc(pCond->numOfCols, sizeof(SColumnDataAgg));
|
||||
if (pReadHandle->statis == NULL) {
|
||||
goto _end;
|
||||
}
|
||||
|
@ -477,7 +477,7 @@ void tsdbResetQueryHandle(tsdbReaderT queryHandle, STsdbQueryCond* pCond) {
|
|||
}
|
||||
|
||||
// allocate buffer in order to load data blocks from file
|
||||
memset(pTsdbReadHandle->statis, 0, sizeof(SDataStatis));
|
||||
memset(pTsdbReadHandle->statis, 0, sizeof(SColumnDataAgg));
|
||||
|
||||
tsdbInitDataBlockLoadInfo(&pTsdbReadHandle->dataBlockLoadInfo);
|
||||
tsdbInitCompBlockLoadInfo(&pTsdbReadHandle->compBlockLoadInfo);
|
||||
|
@ -505,7 +505,7 @@ void tsdbResetQueryHandleForNewTable(tsdbReaderT queryHandle, STsdbQueryCond* pC
|
|||
}
|
||||
|
||||
// allocate buffer in order to load data blocks from file
|
||||
memset(pTsdbReadHandle->statis, 0, sizeof(SDataStatis));
|
||||
memset(pTsdbReadHandle->statis, 0, sizeof(SColumnDataAgg));
|
||||
|
||||
tsdbInitDataBlockLoadInfo(&pTsdbReadHandle->dataBlockLoadInfo);
|
||||
tsdbInitCompBlockLoadInfo(&pTsdbReadHandle->compBlockLoadInfo);
|
||||
|
@ -986,7 +986,7 @@ static int32_t loadBlockInfo(STsdbReadHandle* pTsdbReadHandle, int32_t index, in
|
|||
pCheckInfo->numOfBlocks = 0;
|
||||
|
||||
STable table = {.uid = pCheckInfo->tableId, .tid = pCheckInfo->tableId};
|
||||
table.pSchema = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, pCheckInfo->tableId, 0);
|
||||
table.pSchema = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), pCheckInfo->tableId, 0);
|
||||
|
||||
if (tsdbSetReadTable(&pTsdbReadHandle->rhelper, &table) != TSDB_CODE_SUCCESS) {
|
||||
code = terrno;
|
||||
|
@ -1091,7 +1091,7 @@ static int32_t doLoadFileDataBlock(STsdbReadHandle* pTsdbReadHandle, SBlock* pBl
|
|||
int32_t slotIndex) {
|
||||
int64_t st = taosGetTimestampUs();
|
||||
|
||||
STSchema* pSchema = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, pCheckInfo->tableId, 0);
|
||||
STSchema* pSchema = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), pCheckInfo->tableId, 0);
|
||||
int32_t code = tdInitDataCols(pTsdbReadHandle->pDataCols, pSchema);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
tsdbError("%p failed to malloc buf for pDataCols, %s", pTsdbReadHandle, pTsdbReadHandle->idStr);
|
||||
|
@ -1483,7 +1483,7 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
|
|||
int32_t numOfColsOfRow1 = 0;
|
||||
|
||||
if (pSchema1 == NULL) {
|
||||
pSchema1 = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, uid, TD_ROW_SVER(row1));
|
||||
pSchema1 = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), uid, TD_ROW_SVER(row1));
|
||||
}
|
||||
|
||||
if (isRow1DataRow) {
|
||||
|
@ -1496,7 +1496,7 @@ static void mergeTwoRowFromMem(STsdbReadHandle* pTsdbReadHandle, int32_t capacit
|
|||
if (row2) {
|
||||
isRow2DataRow = TD_IS_TP_ROW(row2);
|
||||
if (pSchema2 == NULL) {
|
||||
pSchema2 = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, uid, TD_ROW_SVER(row2));
|
||||
pSchema2 = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), uid, TD_ROW_SVER(row2));
|
||||
}
|
||||
if (isRow2DataRow) {
|
||||
numOfColsOfRow2 = schemaNCols(pSchema2);
|
||||
|
@ -2514,7 +2514,7 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
|
|||
|
||||
win->ekey = key;
|
||||
if (rv != TD_ROW_SVER(row)) {
|
||||
pSchema = metaGetTbTSchema(pTsdbReadHandle->pTsdb->pMeta, pCheckInfo->tableId, 0);
|
||||
pSchema = metaGetTbTSchema(REPO_META(pTsdbReadHandle->pTsdb), pCheckInfo->tableId, 0);
|
||||
rv = TD_ROW_SVER(row);
|
||||
}
|
||||
mergeTwoRowFromMem(pTsdbReadHandle, maxRowsToRead, numOfRows, row, NULL, numOfCols, pCheckInfo->tableId, pSchema,
|
||||
|
@ -3222,7 +3222,7 @@ void tsdbRetrieveDataBlockInfo(tsdbReaderT* pTsdbReadHandle, SDataBlockInfo* pDa
|
|||
/*
|
||||
* return null for mixed data block, if not a complete file data block, the statistics value will always return NULL
|
||||
*/
|
||||
int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SDataStatis** pBlockStatis) {
|
||||
int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SColumnDataAgg** pBlockStatis) {
|
||||
STsdbReadHandle* pHandle = (STsdbReadHandle*)pTsdbReadHandle;
|
||||
|
||||
SQueryFilePos* c = &pHandle->cur;
|
||||
|
@ -3252,7 +3252,7 @@ int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SDataStati
|
|||
int16_t* colIds = pHandle->defaultLoadColumn->pData;
|
||||
|
||||
size_t numOfCols = QH_GET_NUM_OF_COLS(pHandle);
|
||||
memset(pHandle->statis, 0, numOfCols * sizeof(SDataStatis));
|
||||
memset(pHandle->statis, 0, numOfCols * sizeof(SColumnDataAgg));
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
pHandle->statis[i].colId = colIds[i];
|
||||
}
|
||||
|
@ -3260,7 +3260,7 @@ int32_t tsdbRetrieveDataBlockStatisInfo(tsdbReaderT* pTsdbReadHandle, SDataStati
|
|||
tsdbGetBlockStatis(&pHandle->rhelper, pHandle->statis, (int)numOfCols, pBlockInfo->compBlock);
|
||||
|
||||
// always load the first primary timestamp column data
|
||||
SDataStatis* pPrimaryColStatis = &pHandle->statis[0];
|
||||
SColumnDataAgg* pPrimaryColStatis = &pHandle->statis[0];
|
||||
assert(pPrimaryColStatis->colId == PRIMARYKEY_TIMESTAMP_COL_ID);
|
||||
|
||||
pPrimaryColStatis->numOfNull = 0;
|
||||
|
|
|
@ -433,7 +433,7 @@ void *tsdbDecodeSBlockIdx(void *buf, SBlockIdx *pIdx) {
|
|||
return buf;
|
||||
}
|
||||
|
||||
void tsdbGetBlockStatis(SReadH *pReadh, SDataStatis *pStatis, int numOfCols, SBlock *pBlock) {
|
||||
void tsdbGetBlockStatis(SReadH *pReadh, SColumnDataAgg *pStatis, int numOfCols, SBlock *pBlock) {
|
||||
#ifdef TD_REFACTOR_3
|
||||
SBlockData *pBlockData = pReadh->pBlkData;
|
||||
|
||||
|
@ -606,9 +606,10 @@ static int tsdbLoadBlockDataImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *pDat
|
|||
if (tsdbMakeRoom((void **)(&TSDB_READ_COMP_BUF(pReadh)), zsize) < 0) return -1;
|
||||
}
|
||||
|
||||
if (tsdbCheckAndDecodeColumnData(pDataCol, POINTER_SHIFT(pBlockData, tsize + toffset), tlen, pBlockCol->blen,
|
||||
pBlock->algorithm, pBlock->numOfRows, tLenBitmap, pDataCols->maxPoints,
|
||||
TSDB_READ_COMP_BUF(pReadh), (int)taosTSizeof(TSDB_READ_COMP_BUF(pReadh))) < 0) {
|
||||
if (tsdbCheckAndDecodeColumnData(pDataCol, POINTER_SHIFT(pBlockData, tsize + toffset), tlen,
|
||||
pBlockCol ? pBlockCol->blen : 0, pBlock->algorithm, pBlock->numOfRows,
|
||||
tLenBitmap, pDataCols->maxPoints, TSDB_READ_COMP_BUF(pReadh),
|
||||
(int)taosTSizeof(TSDB_READ_COMP_BUF(pReadh))) < 0) {
|
||||
tsdbError("vgId:%d file %s is broken at column %d block offset %" PRId64 " column offset %u",
|
||||
TSDB_READ_REPO_ID(pReadh), TSDB_FILE_FULL_NAME(pDFile), tcolId, (int64_t)pBlock->offset, toffset);
|
||||
return -1;
|
||||
|
@ -747,6 +748,7 @@ static int tsdbLoadBlockDataColsImpl(SReadH *pReadh, SBlock *pBlock, SDataCols *
|
|||
if (colId == PRIMARYKEY_TIMESTAMP_COL_ID) { // load the key row
|
||||
blockCol.colId = colId;
|
||||
TD_SET_COL_ROWS_NORM(&blockCol); // default is NORM for the primary key column
|
||||
blockCol.blen = 0;
|
||||
blockCol.len = pBlock->keyLen;
|
||||
blockCol.type = pDataCol->type;
|
||||
blockCol.offset = TSDB_KEY_COL_OFFSET;
|
||||
|
|
|
@ -260,7 +260,7 @@ static void poolFree(void *arg, void *ptr) {
|
|||
|
||||
int32_t tsdbInitSma(STsdb *pTsdb) {
|
||||
// tSma
|
||||
int32_t numOfTSma = taosArrayGetSize(metaGetSmaTbUids(pTsdb->pMeta, false));
|
||||
int32_t numOfTSma = taosArrayGetSize(metaGetSmaTbUids(REPO_META(pTsdb), false));
|
||||
if (numOfTSma > 0) {
|
||||
atomic_store_16(&REPO_TSMA_NUM(pTsdb), (int16_t)numOfTSma);
|
||||
}
|
||||
|
@ -314,8 +314,7 @@ static FORCE_INLINE void tsdbSmaStatSetDropped(SSmaStatItem *pStatItem) {
|
|||
}
|
||||
|
||||
static void tsdbGetSmaDir(int32_t vgId, ETsdbSmaType smaType, char dirName[]) {
|
||||
snprintf(dirName, TSDB_FILENAME_LEN, "vnode%svnode%d%stsdb%s%s", TD_DIRSEP, vgId, TD_DIRSEP, TD_DIRSEP,
|
||||
TSDB_SMA_DNAME[smaType]);
|
||||
snprintf(dirName, TSDB_FILENAME_LEN, "vnode%svnode%d%s%s", TD_DIRSEP, vgId, TD_DIRSEP, TSDB_SMA_DNAME[smaType]);
|
||||
}
|
||||
|
||||
static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did) {
|
||||
|
@ -349,7 +348,7 @@ static SSmaEnv *tsdbNewSmaEnv(const STsdb *pTsdb, const char *path, SDiskID did)
|
|||
}
|
||||
|
||||
char aname[TSDB_FILENAME_LEN] = {0};
|
||||
tfsAbsoluteName(pTsdb->pTfs, did, path, aname);
|
||||
tfsAbsoluteName(REPO_TFS(pTsdb), did, path, aname);
|
||||
if (tsdbOpenDBEnv(&pEnv->dbEnv, aname) != TSDB_CODE_SUCCESS) {
|
||||
tsdbFreeSmaEnv(pEnv);
|
||||
return NULL;
|
||||
|
@ -520,14 +519,14 @@ static int32_t tsdbCheckAndInitSmaEnv(STsdb *pTsdb, int8_t smaType) {
|
|||
char rname[TSDB_FILENAME_LEN] = {0};
|
||||
|
||||
SDiskID did = {0};
|
||||
tfsAllocDisk(pTsdb->pTfs, TFS_PRIMARY_LEVEL, &did);
|
||||
tfsAllocDisk(REPO_TFS(pTsdb), TFS_PRIMARY_LEVEL, &did);
|
||||
if (did.level < 0 || did.id < 0) {
|
||||
tsdbUnlockRepo(pTsdb);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
tsdbGetSmaDir(REPO_ID(pTsdb), smaType, rname);
|
||||
|
||||
if (tfsMkdirRecurAt(pTsdb->pTfs, rname, did) != TSDB_CODE_SUCCESS) {
|
||||
if (tfsMkdirRecurAt(REPO_TFS(pTsdb), rname, did) != TSDB_CODE_SUCCESS) {
|
||||
tsdbUnlockRepo(pTsdb);
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
@ -558,7 +557,7 @@ static int32_t tsdbSetExpiredWindow(STsdb *pTsdb, SHashObj *pItemsHash, int64_t
|
|||
}
|
||||
|
||||
// cache smaMeta
|
||||
STSma *pSma = metaGetSmaInfoByIndex(pTsdb->pMeta, indexUid, true);
|
||||
STSma *pSma = metaGetSmaInfoByIndex(REPO_META(pTsdb), indexUid, true);
|
||||
if (pSma == NULL) {
|
||||
terrno = TSDB_CODE_TDB_NO_SMA_INDEX_IN_META;
|
||||
taosHashCleanup(pItem->expiredWindows);
|
||||
|
@ -614,7 +613,7 @@ int32_t tsdbUpdateExpiredWindowImpl(STsdb *pTsdb, SSubmitReq *pMsg, int64_t vers
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
if (!pTsdb->pMeta) {
|
||||
if (!REPO_META(pTsdb)) {
|
||||
terrno = TSDB_CODE_INVALID_PTR;
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
@ -1584,7 +1583,7 @@ int32_t tsdbCreateTSma(STsdb *pTsdb, char *pMsg) {
|
|||
// record current timezone of server side
|
||||
vCreateSmaReq.tSma.timezoneInt = tsTimezone;
|
||||
|
||||
if (metaCreateTSma(pTsdb->pMeta, &vCreateSmaReq) < 0) {
|
||||
if (metaCreateTSma(REPO_META(pTsdb), &vCreateSmaReq) < 0) {
|
||||
// TODO: handle error
|
||||
tdDestroyTSma(&vCreateSmaReq.tSma);
|
||||
return -1;
|
||||
|
@ -1611,7 +1610,7 @@ int32_t tsdbDropTSma(STsdb *pTsdb, char *pMsg) {
|
|||
// }
|
||||
//
|
||||
|
||||
if (metaDropTSma(pTsdb->pMeta, vDropSmaReq.indexUid) < 0) {
|
||||
if (metaDropTSma(REPO_META(pTsdb), vDropSmaReq.indexUid) < 0) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -23,11 +23,6 @@ int vnodeCheckCfg(const SVnodeCfg *pCfg) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
#if 1 //======================================================================
|
||||
void vnodeOptionsCopy(SVnodeCfg *pDest, const SVnodeCfg *pSrc) {
|
||||
memcpy((void *)pDest, (void *)pSrc, sizeof(SVnodeCfg));
|
||||
}
|
||||
|
||||
int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) {
|
||||
uint32_t hashValue = 0;
|
||||
|
||||
|
@ -47,5 +42,3 @@ int vnodeValidateTableHash(SVnodeCfg *pVnodeOptions, char *tableFName) {
|
|||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
#endif
|
|
@ -108,7 +108,7 @@ int vnodeLoadInfo(const char *dir, SVnodeInfo *pInfo) {
|
|||
goto _err;
|
||||
}
|
||||
|
||||
pData = taosMemoryMalloc(size);
|
||||
pData = taosMemoryMalloc(size + 1);
|
||||
if (pData == NULL) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _err;
|
||||
|
@ -119,6 +119,8 @@ int vnodeLoadInfo(const char *dir, SVnodeInfo *pInfo) {
|
|||
goto _err;
|
||||
}
|
||||
|
||||
pData[size] = '\0';
|
||||
|
||||
taosCloseFile(&pFile);
|
||||
|
||||
// decode info
|
||||
|
@ -202,6 +204,16 @@ static int vnodeEncodeConfig(const void *pObj, SJson *pJson) {
|
|||
if (tjsonAddIntegerToObject(pJson, "keep1", pCfg->tsdbCfg.keep1) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "keep2", pCfg->tsdbCfg.keep2) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "lruCacheSize", pCfg->tsdbCfg.lruCacheSize) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "wal.vgId", pCfg->walCfg.vgId) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "wal.fsyncPeriod", pCfg->walCfg.fsyncPeriod) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "wal.retentionPeriod", pCfg->walCfg.retentionPeriod) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "wal.rollPeriod", pCfg->walCfg.rollPeriod) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "wal.retentionSize", pCfg->walCfg.retentionSize) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "wal.segSize", pCfg->walCfg.segSize) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "wal.level", pCfg->walCfg.level) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "hashBegin", pCfg->hashBegin) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "hashEnd", pCfg->hashEnd) < 0) return -1;
|
||||
if (tjsonAddIntegerToObject(pJson, "hashMethod", pCfg->hashMethod) < 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -229,6 +241,16 @@ static int vnodeDecodeConfig(const SJson *pJson, void *pObj) {
|
|||
if (tjsonGetNumberValue(pJson, "keep1", pCfg->tsdbCfg.keep1) < 0) return -1;
|
||||
if (tjsonGetNumberValue(pJson, "keep2", pCfg->tsdbCfg.keep2) < 0) return -1;
|
||||
if (tjsonGetNumberValue(pJson, "lruCacheSize", pCfg->tsdbCfg.lruCacheSize) < 0) return -1;
|
||||
if (tjsonGetNumberValue(pJson, "wal.vgId", pCfg->walCfg.vgId) < 0) return -1;
|
||||
if (tjsonGetNumberValue(pJson, "wal.fsyncPeriod", pCfg->walCfg.fsyncPeriod) < 0) return -1;
|
||||
if (tjsonGetNumberValue(pJson, "wal.retentionPeriod", pCfg->walCfg.retentionPeriod) < 0) return -1;
|
||||
if (tjsonGetNumberValue(pJson, "wal.rollPeriod", pCfg->walCfg.rollPeriod) < 0) return -1;
|
||||
if (tjsonGetNumberValue(pJson, "wal.retentionSize", pCfg->walCfg.retentionSize) < 0) return -1;
|
||||
if (tjsonGetNumberValue(pJson, "wal.segSize", pCfg->walCfg.segSize) < 0) return -1;
|
||||
if (tjsonGetNumberValue(pJson, "wal.level", pCfg->walCfg.level) < 0) return -1;
|
||||
if (tjsonGetNumberValue(pJson, "hashBegin", pCfg->hashBegin) < 0) return -1;
|
||||
if (tjsonGetNumberValue(pJson, "hashEnd", pCfg->hashEnd) < 0) return -1;
|
||||
if (tjsonGetNumberValue(pJson, "hashMethod", pCfg->hashMethod) < 0) return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -286,7 +308,7 @@ _err:
|
|||
static int vnodeDecodeInfo(uint8_t *pData, SVnodeInfo *pInfo) {
|
||||
SJson *pJson = NULL;
|
||||
|
||||
pJson = tjsonCreateObject();
|
||||
pJson = tjsonParse(pData);
|
||||
if (pJson == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -15,11 +15,6 @@
|
|||
|
||||
#include "vnodeInt.h"
|
||||
|
||||
static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg);
|
||||
static void vnodeFree(SVnode *pVnode);
|
||||
static int vnodeOpenImpl(SVnode *pVnode);
|
||||
static void vnodeCloseImpl(SVnode *pVnode);
|
||||
|
||||
int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) {
|
||||
SVnodeInfo info = {0};
|
||||
char dir[TSDB_FILENAME_LEN];
|
||||
|
@ -51,141 +46,116 @@ int vnodeCreate(const char *path, SVnodeCfg *pCfg, STfs *pTfs) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
SVnode *vnodeOpen(const char *path, const SVnodeCfg *pVnodeCfg) {
|
||||
SVnode *pVnode = NULL;
|
||||
void vnodeDestroy(const char *path, STfs *pTfs) { tfsRmdir(pTfs, path); }
|
||||
|
||||
// Set default options
|
||||
SVnodeCfg cfg = vnodeCfgDefault;
|
||||
if (pVnodeCfg != NULL) {
|
||||
cfg.vgId = pVnodeCfg->vgId;
|
||||
cfg.msgCb = pVnodeCfg->msgCb;
|
||||
cfg.pTfs = pVnodeCfg->pTfs;
|
||||
cfg.dbId = pVnodeCfg->dbId;
|
||||
cfg.hashBegin = pVnodeCfg->hashBegin;
|
||||
cfg.hashEnd = pVnodeCfg->hashEnd;
|
||||
cfg.hashMethod = pVnodeCfg->hashMethod;
|
||||
}
|
||||
SVnode *vnodeOpen(const char *path, STfs *pTfs, SMsgCb msgCb) {
|
||||
SVnode *pVnode = NULL;
|
||||
SVnodeInfo info = {0};
|
||||
char dir[TSDB_FILENAME_LEN];
|
||||
char tdir[TSDB_FILENAME_LEN * 2];
|
||||
int ret;
|
||||
|
||||
// Validate options
|
||||
if (vnodeCheckCfg(&cfg) < 0) {
|
||||
// TODO
|
||||
snprintf(dir, TSDB_FILENAME_LEN, "%s%s%s", tfsGetPrimaryPath(pTfs), TD_DIRSEP, path);
|
||||
|
||||
// load vnode info
|
||||
ret = vnodeLoadInfo(dir, &info);
|
||||
if (ret < 0) {
|
||||
vError("failed to open vnode from %s since %s", path, tstrerror(terrno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Create the handle
|
||||
pVnode = vnodeNew(path, &cfg);
|
||||
// create handle
|
||||
pVnode = (SVnode *)taosMemoryCalloc(1, sizeof(*pVnode) + strlen(path) + 1);
|
||||
if (pVnode == NULL) {
|
||||
// TODO: handle error
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
vError("vgId: %d failed to open vnode since %s", info.config.vgId, tstrerror(terrno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
taosMkDir(path);
|
||||
pVnode->path = (char *)&pVnode[1];
|
||||
strcpy(pVnode->path, path);
|
||||
pVnode->config = info.config;
|
||||
pVnode->state.committed = info.state.committed;
|
||||
pVnode->state.processed = pVnode->state.applied = pVnode->state.committed;
|
||||
pVnode->pTfs = pTfs;
|
||||
pVnode->msgCb = msgCb;
|
||||
|
||||
// Open the vnode
|
||||
if (vnodeOpenImpl(pVnode) < 0) {
|
||||
// TODO: handle error
|
||||
return NULL;
|
||||
tsem_init(&(pVnode->canCommit), 0, 1);
|
||||
|
||||
// open buffer pool
|
||||
if (vnodeOpenBufPool(pVnode) < 0) {
|
||||
vError("vgId: %d failed to open vnode buffer pool since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// open meta
|
||||
if (metaOpen(pVnode, &pVnode->pMeta) < 0) {
|
||||
vError("vgId: %d failed to open vnode meta since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// open tsdb
|
||||
sprintf(tdir, "%s%s%s", dir, TD_DIRSEP, VNODE_TSDB_DIR);
|
||||
pVnode->pTsdb = tsdbOpen(tdir, pVnode, &(pVnode->config.tsdbCfg), vBufPoolGetMAF(pVnode));
|
||||
if (pVnode->pTsdb == NULL) {
|
||||
vError("vgId: %d failed to open vnode tsdb since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// open wal
|
||||
sprintf(tdir, "%s%s%s", dir, TD_DIRSEP, VNODE_WAL_DIR);
|
||||
pVnode->pWal = walOpen(tdir, &(pVnode->config.walCfg));
|
||||
if (pVnode->pWal == NULL) {
|
||||
vError("vgId: %d failed to open vnode wal since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// open tq
|
||||
sprintf(tdir, "%s%s%s", dir, TD_DIRSEP, VNODE_TQ_DIR);
|
||||
pVnode->pTq = tqOpen(tdir, pVnode, pVnode->pWal, pVnode->pMeta, vBufPoolGetMAF(pVnode));
|
||||
if (pVnode->pTq == NULL) {
|
||||
vError("vgId: %d failed to open vnode tq since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
// open query
|
||||
if (vnodeQueryOpen(pVnode)) {
|
||||
vError("vgId: %d failed to open vnode query since %s", TD_VID(pVnode), tstrerror(terrno));
|
||||
goto _err;
|
||||
}
|
||||
|
||||
#if 0
|
||||
if (vnodeBegin() < 0) {
|
||||
goto _err;
|
||||
}
|
||||
#endif
|
||||
|
||||
return pVnode;
|
||||
|
||||
_err:
|
||||
if (pVnode->pQuery) vnodeQueryClose(pVnode);
|
||||
if (pVnode->pTq) tqClose(pVnode->pTq);
|
||||
if (pVnode->pWal) walClose(pVnode->pWal);
|
||||
if (pVnode->pTsdb) tsdbClose(pVnode->pTsdb);
|
||||
if (pVnode->pMeta) metaClose(pVnode->pMeta);
|
||||
tsem_destroy(&(pVnode->canCommit));
|
||||
taosMemoryFree(pVnode);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void vnodeClose(SVnode *pVnode) {
|
||||
if (pVnode) {
|
||||
vnodeCloseImpl(pVnode);
|
||||
vnodeFree(pVnode);
|
||||
}
|
||||
}
|
||||
|
||||
void vnodeDestroy(const char *path) { taosRemoveDir(path); }
|
||||
|
||||
/* ------------------------ STATIC METHODS ------------------------ */
|
||||
static SVnode *vnodeNew(const char *path, const SVnodeCfg *pVnodeCfg) {
|
||||
SVnode *pVnode = NULL;
|
||||
|
||||
pVnode = (SVnode *)taosMemoryCalloc(1, sizeof(*pVnode));
|
||||
if (pVnode == NULL) {
|
||||
// TODO
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pVnode->vgId = pVnodeCfg->vgId;
|
||||
pVnode->msgCb = pVnodeCfg->msgCb;
|
||||
pVnode->pTfs = pVnodeCfg->pTfs;
|
||||
pVnode->path = strdup(path);
|
||||
vnodeOptionsCopy(&(pVnode->config), pVnodeCfg);
|
||||
|
||||
tsem_init(&(pVnode->canCommit), 0, 1);
|
||||
|
||||
return pVnode;
|
||||
}
|
||||
|
||||
static void vnodeFree(SVnode *pVnode) {
|
||||
if (pVnode) {
|
||||
// commit (TODO: use option to control)
|
||||
vnodeSyncCommit(pVnode);
|
||||
// close vnode
|
||||
vnodeQueryClose(pVnode);
|
||||
walClose(pVnode->pWal);
|
||||
tqClose(pVnode->pTq);
|
||||
tsdbClose(pVnode->pTsdb);
|
||||
metaClose(pVnode->pMeta);
|
||||
vnodeCloseBufPool(pVnode);
|
||||
// destroy handle
|
||||
tsem_destroy(&(pVnode->canCommit));
|
||||
taosMemoryFreeClear(pVnode->path);
|
||||
taosMemoryFree(pVnode);
|
||||
}
|
||||
}
|
||||
|
||||
static int vnodeOpenImpl(SVnode *pVnode) {
|
||||
char dir[TSDB_FILENAME_LEN];
|
||||
|
||||
if (vnodeOpenBufPool(pVnode) < 0) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Open meta
|
||||
sprintf(dir, "%s/meta", pVnode->path);
|
||||
pVnode->pMeta = metaOpen(dir, &(pVnode->config.metaCfg), vBufPoolGetMAF(pVnode));
|
||||
if (pVnode->pMeta == NULL) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Open tsdb
|
||||
sprintf(dir, "%s/tsdb", pVnode->path);
|
||||
pVnode->pTsdb =
|
||||
tsdbOpen(dir, pVnode->vgId, &(pVnode->config.tsdbCfg), vBufPoolGetMAF(pVnode), pVnode->pMeta, pVnode->pTfs);
|
||||
if (pVnode->pTsdb == NULL) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Open WAL
|
||||
sprintf(dir, "%s/wal", pVnode->path);
|
||||
pVnode->pWal = walOpen(dir, &(pVnode->config.walCfg));
|
||||
if (pVnode->pWal == NULL) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Open TQ
|
||||
sprintf(dir, "%s/tq", pVnode->path);
|
||||
pVnode->pTq = tqOpen(dir, pVnode, pVnode->pWal, pVnode->pMeta, &(pVnode->config.tqCfg), vBufPoolGetMAF(pVnode));
|
||||
if (pVnode->pTq == NULL) {
|
||||
// TODO: handle error
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Open Query
|
||||
if (vnodeQueryOpen(pVnode)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// TODO
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vnodeCloseImpl(SVnode *pVnode) {
|
||||
vnodeSyncCommit(pVnode);
|
||||
if (pVnode) {
|
||||
vnodeCloseBufPool(pVnode);
|
||||
metaClose(pVnode->pMeta);
|
||||
tsdbClose(pVnode->pTsdb);
|
||||
tqClose(pVnode->pTq);
|
||||
walClose(pVnode->pWal);
|
||||
vnodeQueryClose(pVnode);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
#include "vnodeInt.h"
|
||||
|
||||
int vnodeQueryOpen(SVnode *pVnode) {
|
||||
return qWorkerInit(NODE_TYPE_VNODE, pVnode->vgId, NULL, (void **)&pVnode->pQuery, &pVnode->msgCb);
|
||||
return qWorkerInit(NODE_TYPE_VNODE, TD_VID(pVnode), NULL, (void **)&pVnode->pQuery, &pVnode->msgCb);
|
||||
}
|
||||
|
||||
void vnodeQueryClose(SVnode *pVnode) { qWorkerDestroy((void **)&pVnode->pQuery); }
|
||||
|
@ -101,7 +101,7 @@ int vnodeGetTableMeta(SVnode *pVnode, SRpcMsg *pMsg) {
|
|||
metaRsp.numOfColumns = nCols;
|
||||
metaRsp.tableType = pTbCfg->type;
|
||||
metaRsp.tuid = uid;
|
||||
metaRsp.vgId = pVnode->vgId;
|
||||
metaRsp.vgId = TD_VID(pVnode);
|
||||
|
||||
memcpy(metaRsp.pSchemas, pSW->pSchema, sizeof(SSchema) * pSW->nCols);
|
||||
if (nTagCols) {
|
||||
|
@ -151,7 +151,7 @@ _exit:
|
|||
}
|
||||
|
||||
int32_t vnodeGetLoad(SVnode *pVnode, SVnodeLoad *pLoad) {
|
||||
pLoad->vgId = pVnode->vgId;
|
||||
pLoad->vgId = TD_VID(pVnode);
|
||||
pLoad->role = TAOS_SYNC_STATE_LEADER;
|
||||
pLoad->numOfTables = metaGetTbNum(pVnode->pMeta);
|
||||
pLoad->numOfTimeSeries = 400;
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
static int vnodeProcessCreateStbReq(SVnode *pVnode, void *pReq);
|
||||
static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SRpcMsg **pRsp);
|
||||
static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq);
|
||||
static int vnodeProcessSubmitReq(SVnode *pVnode, SSubmitReq *pSubmitReq, SRpcMsg *pRsp);
|
||||
|
||||
void vnodePreprocessWriteReqs(SVnode *pVnode, SArray *pMsgs) {
|
||||
SNodeMsg *pMsg;
|
||||
|
@ -35,7 +36,7 @@ void vnodePreprocessWriteReqs(SVnode *pVnode, SArray *pMsgs) {
|
|||
if (walWrite(pVnode->pWal, ver, pRpc->msgType, pRpc->pCont, pRpc->contLen) < 0) {
|
||||
// TODO: handle error
|
||||
/*ASSERT(false);*/
|
||||
vError("vnode:%d write wal error since %s", pVnode->vgId, terrstr());
|
||||
vError("vnode:%d write wal error since %s", TD_VID(pVnode), terrstr());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,16 +73,17 @@ int vnodeProcessWriteReq(SVnode *pVnode, SRpcMsg *pMsg, SRpcMsg **pRsp) {
|
|||
case TDMT_VND_ALTER_STB:
|
||||
return vnodeProcessAlterStbReq(pVnode, POINTER_SHIFT(pMsg->pCont, sizeof(SMsgHead)));
|
||||
case TDMT_VND_DROP_STB:
|
||||
vTrace("vgId:%d, process drop stb req", pVnode->vgId);
|
||||
vTrace("vgId:%d, process drop stb req", TD_VID(pVnode));
|
||||
break;
|
||||
case TDMT_VND_DROP_TABLE:
|
||||
break;
|
||||
case TDMT_VND_SUBMIT:
|
||||
/*printf("vnode %d write data %ld\n", pVnode->vgId, ver);*/
|
||||
/*printf("vnode %d write data %ld\n", TD_VID(pVnode), ver);*/
|
||||
if (pVnode->config.streamMode == 0) {
|
||||
if (tsdbInsertData(pVnode->pTsdb, (SSubmitReq *)ptr, NULL) < 0) {
|
||||
// TODO: handle error
|
||||
}
|
||||
*pRsp = taosMemoryCalloc(1, sizeof(SRpcMsg));
|
||||
(*pRsp)->handle = pMsg->handle;
|
||||
(*pRsp)->ahandle = pMsg->ahandle;
|
||||
return vnodeProcessSubmitReq(pVnode, ptr, *pRsp);
|
||||
}
|
||||
break;
|
||||
case TDMT_VND_MQ_SET_CONN: {
|
||||
|
@ -243,7 +245,7 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
|||
|
||||
if (metaCreateTable(pVnode->pMeta, pCreateTbReq) < 0) {
|
||||
// TODO: handle error
|
||||
vError("vgId:%d, failed to create table: %s", pVnode->vgId, pCreateTbReq->name);
|
||||
vError("vgId:%d, failed to create table: %s", TD_VID(pVnode), pCreateTbReq->name);
|
||||
}
|
||||
// TODO: to encapsule a free API
|
||||
taosMemoryFree(pCreateTbReq->name);
|
||||
|
@ -266,7 +268,7 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
|||
}
|
||||
}
|
||||
|
||||
vTrace("vgId:%d process create %" PRIzu " tables", pVnode->vgId, taosArrayGetSize(vCreateTbBatchReq.pArray));
|
||||
vTrace("vgId:%d process create %" PRIzu " tables", TD_VID(pVnode), taosArrayGetSize(vCreateTbBatchReq.pArray));
|
||||
taosArrayDestroy(vCreateTbBatchReq.pArray);
|
||||
if (vCreateTbBatchRsp.rspList) {
|
||||
int32_t contLen = tSerializeSVCreateTbBatchRsp(NULL, 0, &vCreateTbBatchRsp);
|
||||
|
@ -287,7 +289,7 @@ static int vnodeProcessCreateTbReq(SVnode *pVnode, SRpcMsg *pMsg, void *pReq, SR
|
|||
|
||||
static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq) {
|
||||
SVCreateTbReq vAlterTbReq = {0};
|
||||
vTrace("vgId:%d, process alter stb req", pVnode->vgId);
|
||||
vTrace("vgId:%d, process alter stb req", TD_VID(pVnode));
|
||||
tDeserializeSVCreateTbReq(pReq, &vAlterTbReq);
|
||||
// TODO: to encapsule a free API
|
||||
taosMemoryFree(vAlterTbReq.stbCfg.pSchema);
|
||||
|
@ -300,3 +302,23 @@ static int vnodeProcessAlterStbReq(SVnode *pVnode, void *pReq) {
|
|||
taosMemoryFree(vAlterTbReq.name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int vnodeProcessSubmitReq(SVnode *pVnode, SSubmitReq *pSubmitReq, SRpcMsg *pRsp) {
|
||||
SSubmitRsp rsp = {0};
|
||||
|
||||
pRsp->code = 0;
|
||||
|
||||
// handle the request
|
||||
if (tsdbInsertData(pVnode->pTsdb, pSubmitReq, &rsp) < 0) {
|
||||
pRsp->code = terrno;
|
||||
return -1;
|
||||
}
|
||||
|
||||
// encode the response (TODO)
|
||||
pRsp->msgType = TDMT_VND_SUBMIT_RSP;
|
||||
pRsp->pCont = rpcMallocCont(sizeof(SSubmitRsp));
|
||||
memcpy(pRsp->pCont, &rsp, sizeof(rsp));
|
||||
pRsp->contLen = sizeof(SSubmitRsp);
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -8,7 +8,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
|
|||
ADD_EXECUTABLE(catalogTest ${SOURCE_LIST})
|
||||
TARGET_LINK_LIBRARIES(
|
||||
catalogTest
|
||||
PUBLIC os util common catalog transport gtest qcom taos
|
||||
PUBLIC os util common catalog transport gtest qcom taos_static
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
|
|
|
@ -316,6 +316,9 @@ int32_t qExplainResAppendRow(SExplainCtx *ctx, char *tbuf, int32_t len, int32_t
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static uint8_t getIntervalPrecision(SIntervalPhysiNode* pIntNode) {
|
||||
return ((SColumnNode*)pIntNode->window.pTspk)->node.resType.precision;
|
||||
}
|
||||
|
||||
int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, int32_t level) {
|
||||
int32_t tlen = 0;
|
||||
|
@ -658,10 +661,10 @@ int32_t qExplainResNodeToRowsImpl(SExplainResNode *pResNode, SExplainCtx *ctx, i
|
|||
EXPLAIN_ROW_APPEND(EXPLAIN_WIDTH_FORMAT, pIntNode->window.node.pOutputDataBlockDesc->outputRowSize);
|
||||
EXPLAIN_ROW_END();
|
||||
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||
|
||||
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_TIME_WINDOWS_FORMAT, INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->interval, pIntNode->intervalUnit, pIntNode->precision),
|
||||
pIntNode->intervalUnit, pIntNode->offset, getPrecisionUnit(pIntNode->precision),
|
||||
INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->sliding, pIntNode->slidingUnit, pIntNode->precision), pIntNode->slidingUnit);
|
||||
uint8_t precision = getIntervalPrecision(pIntNode);
|
||||
EXPLAIN_ROW_NEW(level + 1, EXPLAIN_TIME_WINDOWS_FORMAT, INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->interval, pIntNode->intervalUnit, precision),
|
||||
pIntNode->intervalUnit, pIntNode->offset, getPrecisionUnit(precision),
|
||||
INVERAL_TIME_FROM_PRECISION_TO_UNIT(pIntNode->sliding, pIntNode->slidingUnit, precision), pIntNode->slidingUnit);
|
||||
EXPLAIN_ROW_END();
|
||||
QRY_ERR_RET(qExplainResAppendRow(ctx, tbuf, tlen, level + 1));
|
||||
|
||||
|
|
|
@ -42,10 +42,6 @@
|
|||
|
||||
#define curTimeWindowIndex(_winres) ((_winres)->curIndex)
|
||||
|
||||
struct SColumnFilterElem;
|
||||
|
||||
typedef bool (*__filter_func_t)(struct SColumnFilterElem* pFilter, const char* val1, const char* val2, int16_t type);
|
||||
|
||||
typedef struct SGroupResInfo {
|
||||
int32_t totalGroup;
|
||||
int32_t currentGroup;
|
||||
|
@ -76,7 +72,8 @@ typedef struct SResultRowInfo {
|
|||
SResultRowPosition *pPosition;
|
||||
int32_t size; // number of result set
|
||||
int32_t capacity; // max capacity
|
||||
int32_t curPos; // current active result row index of pResult list
|
||||
// int32_t curPos; // current active result row index of pResult list
|
||||
SResultRowPosition cur;
|
||||
} SResultRowInfo;
|
||||
|
||||
struct STaskAttr;
|
||||
|
|
|
@ -20,9 +20,9 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#include "os.h"
|
||||
#include "tsort.h"
|
||||
#include "tcommon.h"
|
||||
#include "tlosertree.h"
|
||||
#include "tsort.h"
|
||||
#include "ttszip.h"
|
||||
#include "tvariant.h"
|
||||
|
||||
|
@ -35,15 +35,13 @@ extern "C" {
|
|||
#include "tarray.h"
|
||||
#include "thash.h"
|
||||
#include "tlockfree.h"
|
||||
#include "tpagedbuf.h"
|
||||
#include "tmsg.h"
|
||||
|
||||
struct SColumnFilterElem;
|
||||
#include "tpagedbuf.h"
|
||||
|
||||
typedef int32_t (*__block_search_fn_t)(char* data, int32_t num, int64_t key, int32_t order);
|
||||
|
||||
#define IS_QUERY_KILLED(_q) ((_q)->code == TSDB_CODE_TSC_QUERY_CANCELLED)
|
||||
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0u)
|
||||
#define IS_QUERY_KILLED(_q) ((_q)->code == TSDB_CODE_TSC_QUERY_CANCELLED)
|
||||
#define Q_STATUS_EQUAL(p, s) (((p) & (s)) != 0u)
|
||||
#define QUERY_IS_ASC_QUERY(q) (GET_FORWARD_DIRECTION_FACTOR((q)->order.order) == QUERY_ASC_FORWARD_STEP)
|
||||
|
||||
#define GET_TABLEGROUP(q, _index) ((SArray*)taosArrayGetP((q)->tableqinfoGroupInfo.pGroupList, (_index)))
|
||||
|
@ -67,7 +65,7 @@ enum {
|
|||
};
|
||||
|
||||
typedef struct SResultRowCell {
|
||||
uint64_t groupId;
|
||||
uint64_t groupId;
|
||||
SResultRowPosition pos;
|
||||
} SResultRowCell;
|
||||
|
||||
|
@ -75,19 +73,19 @@ typedef struct SResultRowCell {
|
|||
* If the number of generated results is greater than this value,
|
||||
* query query will be halt and return results to client immediate.
|
||||
*/
|
||||
typedef struct SResultInfo { // TODO refactor
|
||||
int64_t totalRows; // total generated result size in rows
|
||||
int64_t totalBytes; // total results in bytes.
|
||||
int32_t capacity; // capacity of current result output buffer
|
||||
int32_t threshold; // result size threshold in rows.
|
||||
typedef struct SResultInfo { // TODO refactor
|
||||
int64_t totalRows; // total generated result size in rows
|
||||
int64_t totalBytes; // total results in bytes.
|
||||
int32_t capacity; // capacity of current result output buffer
|
||||
int32_t threshold; // result size threshold in rows.
|
||||
} SResultInfo;
|
||||
|
||||
typedef struct STableQueryInfo {
|
||||
TSKEY lastKey; // last check ts
|
||||
uint64_t uid; // table uid
|
||||
int32_t groupIndex; // group id in table list
|
||||
TSKEY lastKey; // last check ts, todo remove it later
|
||||
SResultRowPosition pos; // current active time window
|
||||
// int32_t groupIndex; // group id in table list
|
||||
// SVariant tag;
|
||||
SResultRowInfo resInfo; // result info
|
||||
// SResultRowInfo resInfo; // result info
|
||||
} STableQueryInfo;
|
||||
|
||||
typedef enum {
|
||||
|
@ -135,7 +133,8 @@ typedef struct STaskCostInfo {
|
|||
uint32_t totalBlocks;
|
||||
uint32_t loadBlocks;
|
||||
uint32_t loadBlockStatis;
|
||||
uint32_t discardBlocks;
|
||||
uint32_t skipBlocks;
|
||||
uint32_t filterOutBlocks;
|
||||
uint64_t elapsedTime;
|
||||
uint64_t firstStageMergeTime;
|
||||
uint64_t winInfoSize;
|
||||
|
@ -155,27 +154,27 @@ typedef struct SOperatorCostInfo {
|
|||
// The basic query information extracted from the SQueryInfo tree to support the
|
||||
// execution of query in a data node.
|
||||
typedef struct STaskAttr {
|
||||
SLimit limit;
|
||||
SLimit slimit;
|
||||
bool stableQuery; // super table query or not
|
||||
bool topBotQuery; // TODO used bitwise flag
|
||||
bool groupbyColumn; // denote if this is a groupby normal column query
|
||||
bool timeWindowInterpo; // if the time window start/end required interpolation
|
||||
bool tsCompQuery; // is tscomp query
|
||||
bool diffQuery; // is diff query
|
||||
bool pointInterpQuery; // point interpolation query
|
||||
int32_t havingNum; // having expr number
|
||||
int16_t numOfCols;
|
||||
int16_t numOfTags;
|
||||
STimeWindow window;
|
||||
SInterval interval;
|
||||
int16_t precision;
|
||||
int16_t numOfOutput;
|
||||
int16_t fillType;
|
||||
int32_t resultRowSize;
|
||||
int32_t tagLen; // tag value length of current query
|
||||
SLimit limit;
|
||||
SLimit slimit;
|
||||
bool stableQuery; // super table query or not
|
||||
bool topBotQuery; // TODO used bitwise flag
|
||||
bool groupbyColumn; // denote if this is a groupby normal column query
|
||||
bool timeWindowInterpo; // if the time window start/end required interpolation
|
||||
bool tsCompQuery; // is tscomp query
|
||||
bool diffQuery; // is diff query
|
||||
bool pointInterpQuery; // point interpolation query
|
||||
int32_t havingNum; // having expr number
|
||||
int16_t numOfCols;
|
||||
int16_t numOfTags;
|
||||
STimeWindow window;
|
||||
SInterval interval;
|
||||
int16_t precision;
|
||||
int16_t numOfOutput;
|
||||
int16_t fillType;
|
||||
int32_t resultRowSize;
|
||||
int32_t tagLen; // tag value length of current query
|
||||
|
||||
SExprInfo *pExpr1;
|
||||
SExprInfo* pExpr1;
|
||||
SColumnInfo* tagColList;
|
||||
int32_t numOfFilterCols;
|
||||
int64_t* fillVal;
|
||||
|
@ -188,13 +187,15 @@ struct SOperatorInfo;
|
|||
struct SAggSupporter;
|
||||
struct SOptrBasicInfo;
|
||||
|
||||
typedef void (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, struct SAggSupporter *pSup, struct SOptrBasicInfo *pInfo, char **result, int32_t *length);
|
||||
typedef bool (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, struct SAggSupporter *pSup, struct SOptrBasicInfo *pInfo, char *result, int32_t length);
|
||||
typedef void (*__optr_encode_fn_t)(struct SOperatorInfo* pOperator, struct SAggSupporter* pSup,
|
||||
struct SOptrBasicInfo* pInfo, char** result, int32_t* length);
|
||||
typedef bool (*__optr_decode_fn_t)(struct SOperatorInfo* pOperator, struct SAggSupporter* pSup,
|
||||
struct SOptrBasicInfo* pInfo, char* result, int32_t length);
|
||||
|
||||
typedef int32_t (*__optr_open_fn_t)(struct SOperatorInfo* pOptr);
|
||||
typedef SSDataBlock* (*__optr_fn_t)(struct SOperatorInfo* pOptr, bool* newgroup);
|
||||
typedef void (*__optr_close_fn_t)(void* param, int32_t num);
|
||||
typedef int32_t (*__optr_get_explain_fn_t)(struct SOperatorInfo* pOptr, void **pOptrExplain);
|
||||
typedef int32_t (*__optr_get_explain_fn_t)(struct SOperatorInfo* pOptr, void** pOptrExplain);
|
||||
|
||||
typedef struct STaskIdInfo {
|
||||
uint64_t queryId; // this is also a request id
|
||||
|
@ -204,61 +205,50 @@ typedef struct STaskIdInfo {
|
|||
} STaskIdInfo;
|
||||
|
||||
typedef struct SExecTaskInfo {
|
||||
STaskIdInfo id;
|
||||
uint32_t status;
|
||||
STimeWindow window;
|
||||
STaskCostInfo cost;
|
||||
int64_t owner; // if it is in execution
|
||||
int32_t code;
|
||||
uint64_t totalRows; // total number of rows
|
||||
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
|
||||
char* sql; // query sql string
|
||||
jmp_buf env; // jump to this position when error happens.
|
||||
EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model]
|
||||
STaskIdInfo id;
|
||||
uint32_t status;
|
||||
STimeWindow window;
|
||||
STaskCostInfo cost;
|
||||
int64_t owner; // if it is in execution
|
||||
int32_t code;
|
||||
uint64_t totalRows; // total number of rows
|
||||
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
|
||||
char* sql; // query sql string
|
||||
jmp_buf env; // jump to this position when error happens.
|
||||
EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model]
|
||||
struct SOperatorInfo* pRoot;
|
||||
} SExecTaskInfo;
|
||||
|
||||
typedef struct STaskRuntimeEnv {
|
||||
jmp_buf env;
|
||||
STaskAttr* pQueryAttr;
|
||||
uint32_t status; // query status
|
||||
void* qinfo;
|
||||
uint8_t scanFlag; // denotes reversed scan of data or not
|
||||
void* pTsdbReadHandle;
|
||||
|
||||
int32_t prevGroupId; // previous executed group id
|
||||
bool enableGroupData;
|
||||
SDiskbasedBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
||||
SHashObj* pResultRowHashTable; // quick locate the window object for each result
|
||||
SHashObj* pResultRowListSet; // used to check if current ResultRowInfo has ResultRow object or not
|
||||
SArray* pResultRowArrayList; // The array list that contains the Result rows
|
||||
char* keyBuf; // window key buffer
|
||||
// The window result objects pool, all the resultRow Objects are allocated and managed by this object.
|
||||
char** prevRow;
|
||||
SArray* prevResult; // intermediate result, SArray<SInterResult>
|
||||
STSBuf* pTsBuf; // timestamp filter list
|
||||
STSCursor cur;
|
||||
char** prevRow;
|
||||
STSBuf* pTsBuf; // timestamp filter list
|
||||
STSCursor cur;
|
||||
|
||||
char* tagVal; // tag value of current data block
|
||||
struct SScalarFunctionSupport* scalarSup;
|
||||
|
||||
SSDataBlock* outputBuf;
|
||||
char* tagVal; // tag value of current data block
|
||||
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
|
||||
struct SOperatorInfo* proot;
|
||||
SGroupResInfo groupResInfo;
|
||||
int64_t currentOffset; // dynamic offset value
|
||||
SGroupResInfo groupResInfo;
|
||||
int64_t currentOffset; // dynamic offset value
|
||||
|
||||
STableQueryInfo* current;
|
||||
SResultInfo resultInfo;
|
||||
SHashObj* pTableRetrieveTsMap;
|
||||
struct SUdfInfo* pUdfInfo;
|
||||
} STaskRuntimeEnv;
|
||||
|
||||
enum {
|
||||
OP_NOT_OPENED = 0x0,
|
||||
OP_OPENED = 0x1,
|
||||
OP_NOT_OPENED = 0x0,
|
||||
OP_OPENED = 0x1,
|
||||
OP_RES_TO_RETURN = 0x5,
|
||||
OP_EXEC_DONE = 0x9,
|
||||
OP_EXEC_DONE = 0x9,
|
||||
};
|
||||
|
||||
typedef struct SOperatorInfo {
|
||||
|
@ -269,16 +259,16 @@ typedef struct SOperatorInfo {
|
|||
char* name; // name, used to show the query execution plan
|
||||
void* info; // extension attribution
|
||||
SExprInfo* pExpr;
|
||||
STaskRuntimeEnv* pRuntimeEnv; // todo remove it
|
||||
SExecTaskInfo* pTaskInfo;
|
||||
SOperatorCostInfo cost;
|
||||
SResultInfo resultInfo;
|
||||
struct SOperatorInfo** pDownstream; // downstram pointer list
|
||||
int32_t numOfDownstream; // number of downstream. The value is always ONE expect for join operator
|
||||
// todo extract struct
|
||||
__optr_open_fn_t _openFn; // DO NOT invoke this function directly
|
||||
__optr_fn_t getNextFn;
|
||||
__optr_fn_t getStreamResFn; // execute the aggregate in the stream model.
|
||||
__optr_fn_t cleanupFn; // call this function to release the allocated resources ASAP
|
||||
__optr_fn_t getStreamResFn; // execute the aggregate in the stream model.
|
||||
__optr_fn_t cleanupFn; // call this function to release the allocated resources ASAP
|
||||
__optr_close_fn_t closeFn;
|
||||
__optr_encode_fn_t encodeResultRow;
|
||||
__optr_decode_fn_t decodeResultRow;
|
||||
|
@ -298,28 +288,28 @@ typedef enum {
|
|||
} EX_SOURCE_STATUS;
|
||||
|
||||
typedef struct SSourceDataInfo {
|
||||
struct SExchangeInfo *pEx;
|
||||
struct SExchangeInfo* pEx;
|
||||
int32_t index;
|
||||
SRetrieveTableRsp *pRsp;
|
||||
SRetrieveTableRsp* pRsp;
|
||||
uint64_t totalRows;
|
||||
int32_t code;
|
||||
EX_SOURCE_STATUS status;
|
||||
} SSourceDataInfo;
|
||||
|
||||
typedef struct SLoadRemoteDataInfo {
|
||||
uint64_t totalSize; // total load bytes from remote
|
||||
uint64_t totalRows; // total number of rows
|
||||
uint64_t totalElapsed; // total elapsed time
|
||||
uint64_t totalSize; // total load bytes from remote
|
||||
uint64_t totalRows; // total number of rows
|
||||
uint64_t totalElapsed; // total elapsed time
|
||||
} SLoadRemoteDataInfo;
|
||||
|
||||
typedef struct SExchangeInfo {
|
||||
SArray* pSources;
|
||||
SArray* pSourceDataInfo;
|
||||
tsem_t ready;
|
||||
void* pTransporter;
|
||||
SSDataBlock* pResult;
|
||||
bool seqLoadData; // sequential load data or not, false by default
|
||||
int32_t current;
|
||||
SArray* pSources;
|
||||
SArray* pSourceDataInfo;
|
||||
tsem_t ready;
|
||||
void* pTransporter;
|
||||
SSDataBlock* pResult;
|
||||
bool seqLoadData; // sequential load data or not, false by default
|
||||
int32_t current;
|
||||
SLoadRemoteDataInfo loadInfo;
|
||||
} SExchangeInfo;
|
||||
|
||||
|
@ -340,7 +330,7 @@ typedef struct STableScanInfo {
|
|||
int32_t current;
|
||||
int32_t reverseTimes; // 0 by default
|
||||
SNode* pFilterNode; // filter operator info
|
||||
SqlFunctionCtx* pCtx; // next operator query context
|
||||
SqlFunctionCtx* pCtx; // next operator query context
|
||||
SResultRowInfo* pResultRowInfo;
|
||||
int32_t* rowCellInfoOffset;
|
||||
SExprInfo* pExpr;
|
||||
|
@ -349,7 +339,11 @@ typedef struct STableScanInfo {
|
|||
int32_t numOfOutput;
|
||||
int64_t elapsedTime;
|
||||
int32_t prevGroupId; // previous table group id
|
||||
int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan
|
||||
|
||||
int32_t scanFlag; // table scan flag to denote if it is a repeat/reverse/main scan
|
||||
int32_t dataBlockLoadFlag;
|
||||
double sampleRatio; // data block sample ratio
|
||||
SInterval interval; // if the upstream is an interval operator, the interval info is also kept here to get the time window to check if current data block needs to be loaded.
|
||||
} STableScanInfo;
|
||||
|
||||
typedef struct STagScanInfo {
|
||||
|
@ -360,15 +354,15 @@ typedef struct STagScanInfo {
|
|||
} STagScanInfo;
|
||||
|
||||
typedef struct SStreamBlockScanInfo {
|
||||
SArray* pBlockLists; // multiple SSDatablock.
|
||||
SSDataBlock* pRes; // result SSDataBlock
|
||||
int32_t blockType; // current block type
|
||||
int32_t validBlockIndex; // Is current data has returned?
|
||||
SColumnInfo* pCols; // the output column info
|
||||
uint64_t numOfRows; // total scanned rows
|
||||
uint64_t numOfExec; // execution times
|
||||
void* readerHandle; // stream block reader handle
|
||||
SArray* pColMatchInfo; //
|
||||
SArray* pBlockLists; // multiple SSDatablock.
|
||||
SSDataBlock* pRes; // result SSDataBlock
|
||||
int32_t blockType; // current block type
|
||||
int32_t validBlockIndex; // Is current data has returned?
|
||||
SColumnInfo* pCols; // the output column info
|
||||
uint64_t numOfRows; // total scanned rows
|
||||
uint64_t numOfExec; // execution times
|
||||
void* readerHandle; // stream block reader handle
|
||||
SArray* pColMatchInfo; //
|
||||
} SStreamBlockScanInfo;
|
||||
|
||||
typedef struct SSysTableScanInfo {
|
||||
|
@ -377,83 +371,87 @@ typedef struct SSysTableScanInfo {
|
|||
void* readHandle;
|
||||
};
|
||||
|
||||
SRetrieveMetaTableRsp *pRsp;
|
||||
SRetrieveTableReq req;
|
||||
SEpSet epSet;
|
||||
tsem_t ready;
|
||||
SRetrieveMetaTableRsp* pRsp;
|
||||
SRetrieveTableReq req;
|
||||
SEpSet epSet;
|
||||
tsem_t ready;
|
||||
|
||||
int32_t accountId;
|
||||
bool showRewrite;
|
||||
SNode *pCondition; // db_name filter condition, to discard data that are not in current database
|
||||
void *pCur; // cursor for iterate the local table meta store.
|
||||
SArray *scanCols; // SArray<int16_t> scan column id list
|
||||
int32_t accountId;
|
||||
bool showRewrite;
|
||||
SNode* pCondition; // db_name filter condition, to discard data that are not in current database
|
||||
void* pCur; // cursor for iterate the local table meta store.
|
||||
SArray* scanCols; // SArray<int16_t> scan column id list
|
||||
|
||||
int32_t type; // show type, TODO remove it
|
||||
int32_t type; // show type, TODO remove it
|
||||
SName name;
|
||||
SSDataBlock *pRes;
|
||||
SSDataBlock* pRes;
|
||||
int32_t capacity;
|
||||
int64_t numOfBlocks; // extract basic running information.
|
||||
SLoadRemoteDataInfo loadInfo;
|
||||
} SSysTableScanInfo;
|
||||
|
||||
typedef struct SOptrBasicInfo {
|
||||
SResultRowInfo resultRowInfo;
|
||||
int32_t* rowCellInfoOffset; // offset value for each row result cell info
|
||||
SqlFunctionCtx* pCtx;
|
||||
SSDataBlock* pRes;
|
||||
int32_t capacity; // TODO remove it
|
||||
SResultRowInfo resultRowInfo;
|
||||
int32_t* rowCellInfoOffset; // offset value for each row result cell info
|
||||
SqlFunctionCtx* pCtx;
|
||||
SSDataBlock* pRes;
|
||||
int32_t capacity; // TODO remove it
|
||||
} SOptrBasicInfo;
|
||||
|
||||
//TODO move the resultrowsiz together with SOptrBasicInfo:rowCellInfoOffset
|
||||
// TODO move the resultrowsiz together with SOptrBasicInfo:rowCellInfoOffset
|
||||
typedef struct SAggSupporter {
|
||||
SHashObj* pResultRowHashTable; // quick locate the window object for each result
|
||||
SHashObj* pResultRowListSet; // used to check if current ResultRowInfo has ResultRow object or not
|
||||
SArray* pResultRowArrayList; // The array list that contains the Result rows
|
||||
char* keyBuf; // window key buffer
|
||||
SDiskbasedBuf *pResultBuf; // query result buffer based on blocked-wised disk file
|
||||
int32_t resultRowSize; // the result buffer size for each result row, with the meta data size for each row
|
||||
SHashObj* pResultRowHashTable; // quick locate the window object for each result
|
||||
SHashObj* pResultRowListSet; // used to check if current ResultRowInfo has ResultRow object or not
|
||||
SArray* pResultRowArrayList; // The array list that contains the Result rows
|
||||
char* keyBuf; // window key buffer
|
||||
SDiskbasedBuf* pResultBuf; // query result buffer based on blocked-wised disk file
|
||||
int32_t resultRowSize; // the result buffer size for each result row, with the meta data size for each row
|
||||
} SAggSupporter;
|
||||
|
||||
typedef struct STableIntervalOperatorInfo {
|
||||
SOptrBasicInfo binfo; // basic info
|
||||
SGroupResInfo groupResInfo; // multiple results build supporter
|
||||
SInterval interval; // interval info
|
||||
int32_t primaryTsIndex; // primary time stamp slot id from result of downstream operator.
|
||||
STimeWindow win; // query time range
|
||||
bool timeWindowInterpo; // interpolation needed or not
|
||||
char **pRow; // previous row/tuple of already processed datablock
|
||||
SAggSupporter aggSup; // aggregate supporter
|
||||
STableQueryInfo *pCurrent; // current tableQueryInfo struct
|
||||
int32_t order; // current SSDataBlock scan order
|
||||
EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model]
|
||||
SArray *pUpdatedWindow; // updated time window due to the input data block from the downstream operator.
|
||||
SColumnInfoData timeWindowData; // query time window info for scalar function execution.
|
||||
SOptrBasicInfo binfo; // basic info
|
||||
SGroupResInfo groupResInfo; // multiple results build supporter
|
||||
SInterval interval; // interval info
|
||||
int32_t primaryTsIndex; // primary time stamp slot id from result of downstream operator.
|
||||
STimeWindow win; // query time range
|
||||
bool timeWindowInterpo; // interpolation needed or not
|
||||
char** pRow; // previous row/tuple of already processed datablock
|
||||
SAggSupporter aggSup; // aggregate supporter
|
||||
STableQueryInfo* pCurrent; // current tableQueryInfo struct
|
||||
int32_t order; // current SSDataBlock scan order
|
||||
EOPTR_EXEC_MODEL execModel; // operator execution model [batch model|stream model]
|
||||
SArray* pUpdatedWindow; // updated time window due to the input data block from the downstream operator.
|
||||
SColumnInfoData timeWindowData; // query time window info for scalar function execution.
|
||||
} STableIntervalOperatorInfo;
|
||||
|
||||
typedef struct SAggOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
SDiskbasedBuf *pResultBuf; // query result buffer based on blocked-wised disk file
|
||||
SAggSupporter aggSup;
|
||||
STableQueryInfo *current;
|
||||
uint32_t groupId;
|
||||
uint64_t groupId;
|
||||
SGroupResInfo groupResInfo;
|
||||
STableQueryInfo *pTableQueryInfo;
|
||||
|
||||
SExprInfo *pScalarExprInfo;
|
||||
int32_t numOfScalarExpr; // the number of scalar expression before the aggregate function can be applied
|
||||
SqlFunctionCtx *pScalarCtx; // scalar function requried sql function struct.
|
||||
int32_t *rowCellInfoOffset; // offset value for each row result cell info
|
||||
} SAggOperatorInfo;
|
||||
|
||||
typedef struct SProjectOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
SAggSupporter aggSup;
|
||||
SSDataBlock *existDataBlock;
|
||||
SArray *pPseudoColInfo;
|
||||
SSDataBlock* existDataBlock;
|
||||
SArray* pPseudoColInfo;
|
||||
SLimit limit;
|
||||
SLimit slimit;
|
||||
|
||||
uint64_t groupId;
|
||||
int64_t curSOffset;
|
||||
int64_t curGroupOutput;
|
||||
uint64_t groupId;
|
||||
int64_t curSOffset;
|
||||
int64_t curGroupOutput;
|
||||
|
||||
int64_t curOffset;
|
||||
int64_t curOutput;
|
||||
int64_t curOffset;
|
||||
int64_t curOutput;
|
||||
} SProjectOperatorInfo;
|
||||
|
||||
typedef struct SFillOperatorInfo {
|
||||
|
@ -468,86 +466,87 @@ typedef struct SFillOperatorInfo {
|
|||
} SFillOperatorInfo;
|
||||
|
||||
typedef struct {
|
||||
char *pData;
|
||||
bool isNull;
|
||||
int16_t type;
|
||||
int32_t bytes;
|
||||
char* pData;
|
||||
bool isNull;
|
||||
int16_t type;
|
||||
int32_t bytes;
|
||||
} SGroupKeys, SStateKeys;
|
||||
|
||||
typedef struct SGroupbyOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
SArray* pGroupCols;
|
||||
SArray* pGroupColVals; // current group column values, SArray<SGroupKeys>
|
||||
SNode* pCondition;
|
||||
bool isInit; // denote if current val is initialized or not
|
||||
char* keyBuf; // group by keys for hash
|
||||
int32_t groupKeyLen; // total group by column width
|
||||
SGroupResInfo groupResInfo;
|
||||
SAggSupporter aggSup;
|
||||
SExprInfo* pScalarExprInfo;
|
||||
int32_t numOfScalarExpr;// the number of scalar expression in group operator
|
||||
SqlFunctionCtx*pScalarFuncCtx;
|
||||
SOptrBasicInfo binfo;
|
||||
SArray* pGroupCols;
|
||||
SArray* pGroupColVals; // current group column values, SArray<SGroupKeys>
|
||||
SNode* pCondition;
|
||||
bool isInit; // denote if current val is initialized or not
|
||||
char* keyBuf; // group by keys for hash
|
||||
int32_t groupKeyLen; // total group by column width
|
||||
SGroupResInfo groupResInfo;
|
||||
SAggSupporter aggSup;
|
||||
SExprInfo* pScalarExprInfo;
|
||||
int32_t numOfScalarExpr; // the number of scalar expression in group operator
|
||||
SqlFunctionCtx* pScalarFuncCtx;
|
||||
} SGroupbyOperatorInfo;
|
||||
|
||||
typedef struct SDataGroupInfo {
|
||||
uint64_t groupId;
|
||||
int64_t numOfRows;
|
||||
SArray *pPageList;
|
||||
SArray* pPageList;
|
||||
} SDataGroupInfo;
|
||||
|
||||
// The sort in partition may be needed later.
|
||||
typedef struct SPartitionOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
SArray* pGroupCols;
|
||||
SArray* pGroupColVals; // current group column values, SArray<SGroupKeys>
|
||||
char* keyBuf; // group by keys for hash
|
||||
int32_t groupKeyLen; // total group by column width
|
||||
SHashObj* pGroupSet; // quick locate the window object for each result
|
||||
SOptrBasicInfo binfo;
|
||||
SArray* pGroupCols;
|
||||
SArray* pGroupColVals; // current group column values, SArray<SGroupKeys>
|
||||
char* keyBuf; // group by keys for hash
|
||||
int32_t groupKeyLen; // total group by column width
|
||||
SHashObj* pGroupSet; // quick locate the window object for each result
|
||||
|
||||
SDiskbasedBuf* pBuf; // query result buffer based on blocked-wised disk file
|
||||
int32_t rowCapacity; // maximum number of rows for each buffer page
|
||||
int32_t* columnOffset; // start position for each column data
|
||||
SDiskbasedBuf* pBuf; // query result buffer based on blocked-wised disk file
|
||||
int32_t rowCapacity; // maximum number of rows for each buffer page
|
||||
int32_t* columnOffset; // start position for each column data
|
||||
|
||||
void* pGroupIter; // group iterator
|
||||
int32_t pageIndex; // page index of current group
|
||||
void* pGroupIter; // group iterator
|
||||
int32_t pageIndex; // page index of current group
|
||||
} SPartitionOperatorInfo;
|
||||
|
||||
typedef struct SWindowRowsSup {
|
||||
STimeWindow win;
|
||||
TSKEY prevTs;
|
||||
int32_t startRowIndex;
|
||||
int32_t numOfRows;
|
||||
STimeWindow win;
|
||||
TSKEY prevTs;
|
||||
int32_t startRowIndex;
|
||||
int32_t numOfRows;
|
||||
} SWindowRowsSup;
|
||||
|
||||
typedef struct SSessionAggOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
SAggSupporter aggSup;
|
||||
SGroupResInfo groupResInfo;
|
||||
SWindowRowsSup winSup;
|
||||
bool reptScan; // next round scan
|
||||
int64_t gap; // session window gap
|
||||
SColumnInfoData timeWindowData; // query time window info for scalar function execution.
|
||||
SOptrBasicInfo binfo;
|
||||
SAggSupporter aggSup;
|
||||
SGroupResInfo groupResInfo;
|
||||
SWindowRowsSup winSup;
|
||||
bool reptScan; // next round scan
|
||||
int64_t gap; // session window gap
|
||||
SColumnInfoData timeWindowData; // query time window info for scalar function execution.
|
||||
} SSessionAggOperatorInfo;
|
||||
|
||||
typedef struct STimeSliceOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
SInterval interval;
|
||||
SGroupResInfo groupResInfo; // multiple results build supporter
|
||||
SOptrBasicInfo binfo;
|
||||
SInterval interval;
|
||||
SGroupResInfo groupResInfo; // multiple results build supporter
|
||||
} STimeSliceOperatorInfo;
|
||||
|
||||
typedef struct SStateWindowOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
SAggSupporter aggSup;
|
||||
SGroupResInfo groupResInfo;
|
||||
SWindowRowsSup winSup;
|
||||
int32_t colIndex; // start row index
|
||||
bool hasKey;
|
||||
SStateKeys stateKey;
|
||||
SColumnInfoData timeWindowData; // query time window info for scalar function execution.
|
||||
// bool reptScan;
|
||||
SOptrBasicInfo binfo;
|
||||
SAggSupporter aggSup;
|
||||
SGroupResInfo groupResInfo;
|
||||
SWindowRowsSup winSup;
|
||||
int32_t colIndex; // start row index
|
||||
bool hasKey;
|
||||
SStateKeys stateKey;
|
||||
SColumnInfoData timeWindowData; // query time window info for scalar function execution.
|
||||
// bool reptScan;
|
||||
} SStateWindowOperatorInfo;
|
||||
|
||||
typedef struct SSortedMergeOperatorInfo {
|
||||
|
||||
SOptrBasicInfo binfo;
|
||||
SArray* pSortInfo;
|
||||
int32_t numOfSources;
|
||||
|
@ -564,22 +563,26 @@ typedef struct SSortedMergeOperatorInfo {
|
|||
} SSortedMergeOperatorInfo;
|
||||
|
||||
typedef struct SSortOperatorInfo {
|
||||
uint32_t sortBufSize; // max buffer size for in-memory sort
|
||||
SSDataBlock *pDataBlock;
|
||||
SArray* pSortInfo;
|
||||
SSortHandle *pSortHandle;
|
||||
SArray* inputSlotMap; // for index map from table scan output
|
||||
int32_t bufPageSize;
|
||||
int32_t numOfRowsInRes;
|
||||
uint32_t sortBufSize; // max buffer size for in-memory sort
|
||||
SSDataBlock* pDataBlock;
|
||||
SArray* pSortInfo;
|
||||
SSortHandle* pSortHandle;
|
||||
SArray* inputSlotMap; // for index map from table scan output
|
||||
int32_t bufPageSize;
|
||||
int32_t numOfRowsInRes;
|
||||
|
||||
// TODO extact struct
|
||||
int64_t startTs; // sort start time
|
||||
uint64_t sortElapsed; // sort elapsed time, time to flush to disk not included.
|
||||
uint64_t totalSize; // total load bytes from remote
|
||||
uint64_t totalRows; // total number of rows
|
||||
uint64_t totalElapsed; // total elapsed time
|
||||
int64_t startTs; // sort start time
|
||||
uint64_t sortElapsed; // sort elapsed time, time to flush to disk not included.
|
||||
uint64_t totalSize; // total load bytes from remote
|
||||
uint64_t totalRows; // total number of rows
|
||||
uint64_t totalElapsed; // total elapsed time
|
||||
} SSortOperatorInfo;
|
||||
|
||||
typedef struct STagFilterOperatorInfo {
|
||||
SOptrBasicInfo binfo;
|
||||
} STagFilterOperatorInfo;
|
||||
|
||||
typedef struct SJoinOperatorInfo {
|
||||
SSDataBlock *pRes;
|
||||
int32_t joinType;
|
||||
|
@ -591,58 +594,73 @@ typedef struct SJoinOperatorInfo {
|
|||
SSDataBlock *pRight;
|
||||
int32_t rightPos;
|
||||
SColumnInfo rightCol;
|
||||
|
||||
SNode *pOnCondition;
|
||||
// SJoinStatus *status;
|
||||
// int32_t numOfUpstream;
|
||||
// SRspResultInfo resultInfo;
|
||||
} SJoinOperatorInfo;
|
||||
|
||||
int32_t operatorDummyOpenFn(SOperatorInfo* pOperator);
|
||||
void operatorDummyCloseFn(void* param, int32_t numOfCols);
|
||||
void operatorDummyCloseFn(void* param, int32_t numOfCols);
|
||||
int32_t appendDownstream(SOperatorInfo* p, SOperatorInfo** pDownstream, int32_t num);
|
||||
int32_t initAggInfo(SOptrBasicInfo* pBasicInfo, SAggSupporter* pAggSup, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
int32_t numOfRows, SSDataBlock* pResultBlock, size_t keyBufSize, const char* pkey);
|
||||
void toSDatablock(SSDataBlock* pBlock, int32_t rowCapacity, SGroupResInfo* pGroupResInfo, SExprInfo* pExprInfo, SDiskbasedBuf* pBuf, int32_t* rowCellOffset);
|
||||
void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbasedBuf* pBuf, SResultRowInfo* pResultRowInfo, int32_t* rowCellInfoOffset);
|
||||
void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, SColumnInfoData* pTimeWindowData, int32_t offset, int32_t forwardStep, TSKEY* tsCol, int32_t numOfTotal, int32_t numOfOutput, int32_t order);
|
||||
int32_t setGroupResultOutputBuf(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type, int16_t bytes, int32_t groupId, SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, SAggSupporter* pAggSup);
|
||||
void doDestroyBasicInfo(SOptrBasicInfo* pInfo, int32_t numOfOutput);
|
||||
int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadInfo, int32_t numOfRows,
|
||||
char* pData, int32_t compLen, int32_t numOfOutput, int64_t startTs,
|
||||
uint64_t* total, SArray* pColList);
|
||||
void doSetOperatorCompleted(SOperatorInfo* pOperator);
|
||||
void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock);
|
||||
void toSDatablock(SSDataBlock* pBlock, int32_t rowCapacity, SGroupResInfo* pGroupResInfo, SExprInfo* pExprInfo,
|
||||
SDiskbasedBuf* pBuf, int32_t* rowCellOffset);
|
||||
void finalizeMultiTupleQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput, SDiskbasedBuf* pBuf,
|
||||
SResultRowInfo* pResultRowInfo, int32_t* rowCellInfoOffset);
|
||||
void doApplyFunctions(SqlFunctionCtx* pCtx, STimeWindow* pWin, SColumnInfoData* pTimeWindowData, int32_t offset,
|
||||
int32_t forwardStep, TSKEY* tsCol, int32_t numOfTotal, int32_t numOfOutput, int32_t order);
|
||||
int32_t setGroupResultOutputBuf(SOptrBasicInfo* binfo, int32_t numOfCols, char* pData, int16_t type, int16_t bytes,
|
||||
int32_t groupId, SDiskbasedBuf* pBuf, SExecTaskInfo* pTaskInfo, SAggSupporter* pAggSup);
|
||||
void doDestroyBasicInfo(SOptrBasicInfo* pInfo, int32_t numOfOutput);
|
||||
int32_t setSDataBlockFromFetchRsp(SSDataBlock* pRes, SLoadRemoteDataInfo* pLoadInfo, int32_t numOfRows, char* pData,
|
||||
int32_t compLen, int32_t numOfOutput, int64_t startTs, uint64_t* total,
|
||||
SArray* pColList);
|
||||
void getAlignQueryTimeWindow(SInterval* pInterval, int32_t precision, int64_t key, int64_t keyFirst, int64_t keyLast, STimeWindow* win);
|
||||
|
||||
void doSetOperatorCompleted(SOperatorInfo* pOperator);
|
||||
void doFilter(const SNode* pFilterNode, SSDataBlock* pBlock);
|
||||
SqlFunctionCtx* createSqlFunctionCtx(SExprInfo* pExprInfo, int32_t numOfOutput, int32_t** rowCellInfoOffset);
|
||||
|
||||
SOperatorInfo* createExchangeOperatorInfo(const SNodeList* pSources, SSDataBlock* pBlock, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfCols, int32_t repeatTime,
|
||||
int32_t reverseTime, SArray* pColMatchInfo, SSDataBlock* pResBlock, SNode* pCondition, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock,
|
||||
SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createMultiTableAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfCols, int32_t dataLoadFlag, int32_t repeatTime,
|
||||
int32_t reverseTime, SArray* pColMatchInfo, SSDataBlock* pResBlock, SNode* pCondition,
|
||||
SInterval* pInterval, double ratio, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createAggregateOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExprInfo* pScalarExprInfo,
|
||||
int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
|
||||
SOperatorInfo* createProjectOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t num, SSDataBlock* pResBlock, SLimit* pLimit, SLimit* pSlimit, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo *createSortOperatorInfo(SOperatorInfo* downstream, SSDataBlock* pResBlock, SArray* pSortInfo, SArray* pIndexMap, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createSortedMergeOperatorInfo(SOperatorInfo** downstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t num, SArray* pSortInfo, SArray* pGroupInfo, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createSysTableScanOperatorInfo(void* pSysTableReadHandle, SSDataBlock* pResBlock, const SName* pName,
|
||||
SNode* pCondition, SEpSet epset, SArray* colList, SExecTaskInfo* pTaskInfo, bool showRewrite, int32_t accountId);
|
||||
SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlot,
|
||||
SNode* pCondition, SEpSet epset, SArray* colList,
|
||||
SExecTaskInfo* pTaskInfo, bool showRewrite, int32_t accountId);
|
||||
SOperatorInfo* createIntervalOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SSDataBlock* pResBlock, SInterval* pInterval, int32_t primaryTsSlot,
|
||||
const STableGroupInfo* pTableGroupInfo, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, int64_t gap, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList,
|
||||
SNode* pCondition, SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createSessionAggOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SSDataBlock* pResBlock, int64_t gap, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SSDataBlock* pResultBlock, SArray* pGroupColList, SNode* pCondition,
|
||||
SExprInfo* pScalarExprInfo, int32_t numOfScalarExpr, SExecTaskInfo* pTaskInfo,
|
||||
const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createDataBlockInfoScanOperator(void* dataReader, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pResBlock, SArray* pColList, SArray* pTableIdList, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createStreamScanOperatorInfo(void* streamReadHandle, SSDataBlock* pResBlock, SArray* pColList,
|
||||
SArray* pTableIdList, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, SInterval* pInterval, SSDataBlock* pResBlock,
|
||||
int32_t fillType, char* fillVal, bool multigroupResult, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols, SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createFillOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols,
|
||||
SInterval* pInterval, SSDataBlock* pResBlock, int32_t fillType, char* fillVal,
|
||||
bool multigroupResult, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createStatewindowOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExpr, int32_t numOfCols,
|
||||
SSDataBlock* pResBlock, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SArray* pGroupColList,
|
||||
SExecTaskInfo* pTaskInfo, const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo);
|
||||
SOperatorInfo* createPartitionOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SSDataBlock* pResultBlock, SArray* pGroupColList, SExecTaskInfo* pTaskInfo,
|
||||
const STableGroupInfo* pTableGroupInfo);
|
||||
SOperatorInfo* createTimeSliceOperatorInfo(SOperatorInfo* downstream, SExprInfo* pExprInfo, int32_t numOfCols,
|
||||
SSDataBlock* pResultBlock, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOfDownstream, SExprInfo* pExprInfo, int32_t numOfCols, SSDataBlock* pResBlock, SNode* pOnCondition, SExecTaskInfo* pTaskInfo);
|
||||
|
||||
|
@ -650,14 +668,13 @@ SOperatorInfo* createJoinOperatorInfo(SOperatorInfo** pDownstream, int32_t numOf
|
|||
SOperatorInfo* createTableSeqScanOperatorInfo(void* pTsdbReadHandle, STaskRuntimeEnv* pRuntimeEnv);
|
||||
SOperatorInfo* createMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream,
|
||||
SExprInfo* pExpr, int32_t numOfOutput);
|
||||
SOperatorInfo* createAllMultiTableTimeIntervalOperatorInfo(STaskRuntimeEnv* pRuntimeEnv, SOperatorInfo* downstream,
|
||||
SExprInfo* pExpr, int32_t numOfOutput);
|
||||
SOperatorInfo* createTagScanOperatorInfo(SReaderHandle* pReaderHandle, SExprInfo* pExpr, int32_t numOfOutput);
|
||||
#endif
|
||||
|
||||
void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx, int32_t numOfOutput, SArray* pPseudoList);
|
||||
void projectApplyFunctions(SExprInfo* pExpr, SSDataBlock* pResult, SSDataBlock* pSrcBlock, SqlFunctionCtx* pCtx,
|
||||
int32_t numOfOutput, SArray* pPseudoList);
|
||||
|
||||
void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order);
|
||||
void setInputDataBlock(SOperatorInfo* pOperator, SqlFunctionCtx* pCtx, SSDataBlock* pBlock, int32_t order, bool createDummyCol);
|
||||
|
||||
void finalizeQueryResult(SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||
void copyTsColoum(SSDataBlock* pRes, SqlFunctionCtx* pCtx, int32_t numOfOutput);
|
||||
|
@ -667,23 +684,27 @@ STableQueryInfo* createTableQueryInfo(void* buf, bool groupbyColumn, STimeWindow
|
|||
bool isTaskKilled(SExecTaskInfo* pTaskInfo);
|
||||
int32_t checkForQueryBuf(size_t numOfTables);
|
||||
|
||||
void setTaskKilled(SExecTaskInfo* pTaskInfo);
|
||||
void setTaskKilled(SExecTaskInfo* pTaskInfo);
|
||||
|
||||
void publishOperatorProfEvent(SOperatorInfo* operatorInfo, EQueryProfEventType eventType);
|
||||
void publishQueryAbortEvent(SExecTaskInfo* pTaskInfo, int32_t code);
|
||||
|
||||
void queryCostStatis(SExecTaskInfo* pTaskInfo);
|
||||
|
||||
void doDestroyTask(SExecTaskInfo* pTaskInfo);
|
||||
void doDestroyTask(SExecTaskInfo* pTaskInfo);
|
||||
int32_t getMaximumIdleDurationSec();
|
||||
|
||||
void doInvokeUdf(struct SUdfInfo* pUdfInfo, SqlFunctionCtx* pCtx, int32_t idx, int32_t type);
|
||||
void setTaskStatus(SExecTaskInfo* pTaskInfo, int8_t status);
|
||||
int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId, EOPTR_EXEC_MODEL model);
|
||||
int32_t getOperatorExplainExecInfo(SOperatorInfo *operatorInfo, SExplainExecInfo **pRes, int32_t *capacity, int32_t *resNum);
|
||||
int32_t createExecTaskInfoImpl(SSubplan* pPlan, SExecTaskInfo** pTaskInfo, SReadHandle* pHandle, uint64_t taskId,
|
||||
EOPTR_EXEC_MODEL model);
|
||||
int32_t getOperatorExplainExecInfo(SOperatorInfo* operatorInfo, SExplainExecInfo** pRes, int32_t* capacity,
|
||||
int32_t* resNum);
|
||||
|
||||
bool aggDecodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasicInfo *pInfo, char* result, int32_t length);
|
||||
void aggEncodeResultRow(SOperatorInfo* pOperator, SAggSupporter *pSup, SOptrBasicInfo *pInfo, char **result, int32_t *length);
|
||||
bool aggDecodeResultRow(SOperatorInfo* pOperator, SAggSupporter* pSup, SOptrBasicInfo* pInfo, char* result,
|
||||
int32_t length);
|
||||
void aggEncodeResultRow(SOperatorInfo* pOperator, SAggSupporter* pSup, SOptrBasicInfo* pInfo, char** result,
|
||||
int32_t* length);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -13,18 +13,11 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "vnodeInt.h"
|
||||
#include "filter.h"
|
||||
#include "tglobal.h"
|
||||
|
||||
int metaOpenUidGnrt(SMeta *pMeta) {
|
||||
// Init a generator
|
||||
pMeta->uidGnrt.nextUid = IVLD_TB_UID;
|
||||
return 0;
|
||||
}
|
||||
typedef enum { SFLT_NOT_INDEX, SFLT_COARSE_INDEX, SFLT_ACCURATE_INDEX } SIdxFltStatus;
|
||||
|
||||
void metaCloseUidGnrt(SMeta *pMeta) { /* TODO */
|
||||
}
|
||||
|
||||
tb_uid_t metaGenerateUid(SMeta *pMeta) {
|
||||
// Generate a new table UID
|
||||
return tGenIdPI64();
|
||||
}
|
||||
SIdxFltStatus idxGetFltStatus(SNode *pFilterNode);
|
||||
// construct tag filter operator later
|
||||
int32_t doFilterTag(const SNode *pFilterNode, SArray *resutl);
|
|
@ -52,11 +52,11 @@ int32_t getOutputInterResultBufSize(STaskAttr* pQueryAttr) {
|
|||
}
|
||||
|
||||
int32_t initResultRowInfo(SResultRowInfo *pResultRowInfo, int32_t size) {
|
||||
pResultRowInfo->size = 0;
|
||||
pResultRowInfo->curPos = -1;
|
||||
pResultRowInfo->capacity = size;
|
||||
pResultRowInfo->pPosition = taosMemoryCalloc(pResultRowInfo->capacity, sizeof(SResultRowPosition));
|
||||
pResultRowInfo->size = 0;
|
||||
pResultRowInfo->capacity = size;
|
||||
pResultRowInfo->cur.pageId = -1;
|
||||
|
||||
pResultRowInfo->pPosition = taosMemoryCalloc(pResultRowInfo->capacity, sizeof(SResultRowPosition));
|
||||
if (pResultRowInfo->pPosition == NULL) {
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -114,7 +114,6 @@ void closeAllResultRows(SResultRowInfo *pResultRowInfo) {
|
|||
assert(pResultRowInfo->size >= 0 && pResultRowInfo->capacity >= pResultRowInfo->size);
|
||||
|
||||
for (int32_t i = 0; i < pResultRowInfo->size; ++i) {
|
||||
// ASSERT(0);
|
||||
// SResultRow* pRow = pResultRowInfo->pResult[i];
|
||||
// if (pRow->closed) {
|
||||
// continue;
|
||||
|
@ -378,7 +377,7 @@ static int32_t mergeIntoGroupResultImplRv(STaskRuntimeEnv *pRuntimeEnv, SGroupRe
|
|||
static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv, SGroupResInfo* pGroupResInfo, SArray *pTableList,
|
||||
int32_t* rowCellInfoOffset) {
|
||||
bool ascQuery = true;
|
||||
|
||||
#if 0
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
int32_t *posList = NULL;
|
||||
|
@ -402,16 +401,16 @@ static UNUSED_FUNC int32_t mergeIntoGroupResultImpl(STaskRuntimeEnv *pRuntimeEnv
|
|||
int32_t numOfTables = 0;
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
STableQueryInfo *item = taosArrayGetP(pTableList, i);
|
||||
if (item->resInfo.size > 0) {
|
||||
pTableQueryInfoList[numOfTables++] = item;
|
||||
}
|
||||
// if (item->resInfo.size > 0) {
|
||||
// pTableQueryInfoList[numOfTables++] = item;
|
||||
// }
|
||||
}
|
||||
|
||||
// there is no data in current group
|
||||
// no need to merge results since only one table in each group
|
||||
if (numOfTables == 0) {
|
||||
goto _end;
|
||||
}
|
||||
// if (numOfTables == 0) {
|
||||
// goto _end;
|
||||
// }
|
||||
|
||||
int32_t order = TSDB_ORDER_ASC;
|
||||
SCompSupporter cs = {pTableQueryInfoList, posList, order};
|
||||
|
@ -498,6 +497,7 @@ int32_t mergeIntoGroupResult(SGroupResInfo* pGroupResInfo, STaskRuntimeEnv* pRun
|
|||
// int64_t elapsedTime = taosGetTimestampUs() - st;
|
||||
// qDebug("QInfo:%"PRIu64" merge res data into group, index:%d, total group:%d, elapsed time:%" PRId64 "us", GET_TASKID(pRuntimeEnv),
|
||||
// pGroupResInfo->currentGroup, pGroupResInfo->totalGroup, elapsedTime);
|
||||
#endif
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -284,9 +284,9 @@ static SSDataBlock* hashGroupbyAggregate(SOperatorInfo* pOperator, bool* newgrou
|
|||
}
|
||||
|
||||
// the pDataBlock are always the same one, no need to call this again
|
||||
setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order);
|
||||
setInputDataBlock(pOperator, pInfo->binfo.pCtx, pBlock, order, true);
|
||||
|
||||
// there is an scalar expression that needs to be calculated before apply the group aggregation.
|
||||
// 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);
|
||||
}
|
||||
|
@ -343,7 +343,6 @@ SOperatorInfo* createGroupOperatorInfo(SOperatorInfo* downstream, SExprInfo* pEx
|
|||
pInfo->numOfScalarExpr = numOfScalarExpr;
|
||||
pInfo->pScalarFuncCtx = createSqlFunctionCtx(pExprInfo, numOfCols, &pInfo->binfo.rowCellInfoOffset);
|
||||
|
||||
|
||||
int32_t code = initGroupOptrInfo(&pInfo->pGroupColVals, &pInfo->groupKeyLen, &pInfo->keyBuf, pGroupColList);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
goto _error;
|
||||
|
|
|
@ -0,0 +1,434 @@
|
|||
/*
|
||||
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
|
||||
*
|
||||
* This program is free software: you can use, redistribute, and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3
|
||||
* or later ("AGPL"), as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "indexoperator.h"
|
||||
#include "executorimpl.h"
|
||||
#include "nodes.h"
|
||||
|
||||
typedef struct SIFCtx {
|
||||
int32_t code;
|
||||
SHashObj *pRes; /* element is SScalarParam */
|
||||
} SIFCtx;
|
||||
|
||||
#define SIF_ERR_RET(c) \
|
||||
do { \
|
||||
int32_t _code = c; \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = _code; \
|
||||
return _code; \
|
||||
} \
|
||||
} while (0)
|
||||
#define SIF_RET(c) \
|
||||
do { \
|
||||
int32_t _code = c; \
|
||||
if (_code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = _code; \
|
||||
} \
|
||||
return _code; \
|
||||
} while (0)
|
||||
#define SIF_ERR_JRET(c) \
|
||||
do { \
|
||||
code = c; \
|
||||
if (code != TSDB_CODE_SUCCESS) { \
|
||||
terrno = code; \
|
||||
goto _return; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
typedef struct SIFParam {
|
||||
SArray * result;
|
||||
SHashObj *pFilter;
|
||||
} SIFParam;
|
||||
|
||||
typedef int32_t (*sif_func_t)(SNode *left, SNode *rigth, SIFParam *output);
|
||||
// construct tag filter operator later
|
||||
static void destroyTagFilterOperatorInfo(void *param) { STagFilterOperatorInfo *pInfo = (STagFilterOperatorInfo *)param; }
|
||||
|
||||
static void sifFreeParam(SIFParam *param) {
|
||||
if (param == NULL) return;
|
||||
taosArrayDestroy(param->result);
|
||||
}
|
||||
|
||||
static int32_t sifGetOperParamNum(EOperatorType ty) {
|
||||
if (OP_TYPE_IS_NULL == ty || OP_TYPE_IS_NOT_NULL == ty || OP_TYPE_IS_TRUE == ty || OP_TYPE_IS_NOT_TRUE == ty || OP_TYPE_IS_FALSE == ty ||
|
||||
OP_TYPE_IS_NOT_FALSE == ty || OP_TYPE_IS_UNKNOWN == ty || OP_TYPE_IS_NOT_UNKNOWN == ty || OP_TYPE_MINUS == ty) {
|
||||
return 1;
|
||||
}
|
||||
return 2;
|
||||
}
|
||||
static int32_t sifInitParam(SNode *node, SIFParam *param, SIFCtx *ctx) {
|
||||
switch (nodeType(node)) {
|
||||
case QUERY_NODE_VALUE: {
|
||||
SValueNode *vn = (SValueNode *)node;
|
||||
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_COLUMN: {
|
||||
SColumnNode *cn = (SColumnNode *)node;
|
||||
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_NODE_LIST: {
|
||||
SNodeListNode *nl = (SNodeListNode *)node;
|
||||
if (LIST_LENGTH(nl->pNodeList) <= 0) {
|
||||
qError("invalid length for node:%p, length: %d", node, LIST_LENGTH(nl->pNodeList));
|
||||
SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
|
||||
if (taosHashPut(ctx->pRes, &node, POINTER_BYTES, param, sizeof(*param))) {
|
||||
taosHashCleanup(param->pFilter);
|
||||
qError("taosHashPut nodeList failed, size:%d", (int32_t)sizeof(*param));
|
||||
SIF_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case QUERY_NODE_FUNCTION:
|
||||
case QUERY_NODE_OPERATOR:
|
||||
case QUERY_NODE_LOGIC_CONDITION: {
|
||||
SIFParam *res = (SIFParam *)taosHashGet(ctx->pRes, &node, POINTER_BYTES);
|
||||
if (NULL == res) {
|
||||
qError("no result for node, type:%d, node:%p", nodeType(node), node);
|
||||
SIF_ERR_RET(TSDB_CODE_QRY_APP_ERROR);
|
||||
}
|
||||
*param = *res;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t sifInitOperParams(SIFParam **params, SOperatorNode *node, SIFCtx *ctx) {
|
||||
int32_t code = 0;
|
||||
int32_t nParam = sifGetOperParamNum(node->opType);
|
||||
if (NULL == node->pLeft || (nParam == 2 && NULL == node->pRight)) {
|
||||
qError("invalid operation node, left: %p, rigth: %p", node->pLeft, node->pRight);
|
||||
SIF_ERR_RET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
SIFParam *paramList = taosMemoryCalloc(nParam, sizeof(SIFParam));
|
||||
if (NULL == paramList) {
|
||||
SIF_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SIF_ERR_JRET(sifInitParam(node->pLeft, ¶mList[0], ctx));
|
||||
if (nParam > 1) {
|
||||
SIF_ERR_JRET(sifInitParam(node->pRight, ¶mList[1], ctx));
|
||||
}
|
||||
*params = paramList;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
_return:
|
||||
taosMemoryFree(paramList);
|
||||
SIF_RET(code);
|
||||
}
|
||||
static int32_t sifInitParamList(SIFParam **params, SNodeList *nodeList, SIFCtx *ctx) {
|
||||
int32_t code = 0;
|
||||
SIFParam *tParams = taosMemoryCalloc(nodeList->length, sizeof(SIFParam));
|
||||
if (tParams == NULL) {
|
||||
qError("failed to calloc, nodeList: %p", nodeList);
|
||||
SIF_ERR_RET(TSDB_CODE_QRY_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
SListCell *cell = nodeList->pHead;
|
||||
for (int32_t i = 0; i < nodeList->length; i++) {
|
||||
if (NULL == cell || NULL == cell->pNode) {
|
||||
SIF_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
SIF_ERR_JRET(sifInitParam(cell->pNode, &tParams[i], ctx));
|
||||
cell = cell->pNext;
|
||||
}
|
||||
*params = tParams;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
_return:
|
||||
taosMemoryFree(tParams);
|
||||
SIF_RET(code);
|
||||
}
|
||||
static int32_t sifExecFunction(SFunctionNode *node, SIFCtx *ctx, SIFParam *output) {
|
||||
qError("index-filter not support buildin function");
|
||||
return TSDB_CODE_QRY_INVALID_INPUT;
|
||||
}
|
||||
|
||||
static int32_t sifLessThanFunc(SNode *left, SNode *rigth, SIFParam *output) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t sifLessEqualFunc(SNode *left, SNode *rigth, SIFParam *output) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t sifGreaterThanFunc(SNode *left, SNode *rigth, SIFParam *output) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t sifGreaterEqualFunc(SNode *left, SNode *rigth, SIFParam *output) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t sifEqualFunc(SNode *left, SNode *rigth, SIFParam *output) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t sifNotEqualFunc(SNode *left, SNode *rigth, SIFParam *output) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t sifInFunc(SNode *left, SNode *rigth, SIFParam *output) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t sifNotInFunc(SNode *left, SNode *right, SIFParam *output) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t sifLikeFunc(SNode *left, SNode *right, SIFParam *output) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t sifNotLikeFunc(SNode *left, SNode *right, SIFParam *output) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t sifMatchFunc(SNode *left, SNode *rigth, SIFParam *output) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t sifNotMatchFunc(SNode *left, SNode *rigth, SIFParam *output) {
|
||||
// impl later
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
static int32_t sifDefaultFunc(SNode *left, SNode *rigth, SIFParam *output) {
|
||||
// add more except
|
||||
return TSDB_CODE_QRY_INVALID_INPUT;
|
||||
}
|
||||
|
||||
static sif_func_t sifGetOperFn(int32_t funcId) {
|
||||
// impl later
|
||||
switch (funcId) {
|
||||
case OP_TYPE_GREATER_THAN:
|
||||
return sifGreaterThanFunc;
|
||||
case OP_TYPE_GREATER_EQUAL:
|
||||
return sifGreaterEqualFunc;
|
||||
case OP_TYPE_LOWER_THAN:
|
||||
return sifLessThanFunc;
|
||||
case OP_TYPE_LOWER_EQUAL:
|
||||
return sifLessEqualFunc;
|
||||
case OP_TYPE_EQUAL:
|
||||
return sifEqualFunc;
|
||||
case OP_TYPE_NOT_EQUAL:
|
||||
return sifNotEqualFunc;
|
||||
case OP_TYPE_IN:
|
||||
return sifInFunc;
|
||||
case OP_TYPE_NOT_IN:
|
||||
return sifNotInFunc;
|
||||
case OP_TYPE_LIKE:
|
||||
return sifLikeFunc;
|
||||
case OP_TYPE_NOT_LIKE:
|
||||
return sifNotLikeFunc;
|
||||
case OP_TYPE_MATCH:
|
||||
return sifMatchFunc;
|
||||
case OP_TYPE_NMATCH:
|
||||
return sifNotMatchFunc;
|
||||
default:
|
||||
return sifDefaultFunc;
|
||||
}
|
||||
return sifDefaultFunc;
|
||||
}
|
||||
static int32_t sifExecOper(SOperatorNode *node, SIFCtx *ctx, SIFParam *output) {
|
||||
int32_t code = 0;
|
||||
SIFParam *params = NULL;
|
||||
SIF_ERR_RET(sifInitOperParams(¶ms, node, ctx));
|
||||
|
||||
int32_t nParam = sifGetOperParamNum(node->opType);
|
||||
if (nParam <= 1) {
|
||||
SIF_ERR_JRET(TSDB_CODE_QRY_INVALID_INPUT);
|
||||
}
|
||||
sif_func_t operFn = sifGetOperFn(node->opType);
|
||||
|
||||
return operFn(node->pLeft, node->pRight, output);
|
||||
_return:
|
||||
taosMemoryFree(params);
|
||||
SIF_RET(code);
|
||||
}
|
||||
|
||||
static int32_t sifExecLogic(SLogicConditionNode *node, SIFCtx *ctx, SIFParam *output) {
|
||||
if (NULL == node->pParameterList || node->pParameterList->length <= 0) {
|
||||
qError("invalid logic parameter list, list:%p, paramNum:%d", node->pParameterList, node->pParameterList ? node->pParameterList->length : 0);
|
||||
return TSDB_CODE_QRY_INVALID_INPUT;
|
||||
}
|
||||
|
||||
int32_t code;
|
||||
SIFParam *params = NULL;
|
||||
SIF_ERR_RET(sifInitParamList(¶ms, node->pParameterList, ctx));
|
||||
|
||||
for (int32_t m = 0; m < node->pParameterList->length; m++) {
|
||||
// add impl later
|
||||
if (node->condType == LOGIC_COND_TYPE_AND) {
|
||||
taosArrayAddAll(output->result, params[m].result);
|
||||
} else if (node->condType == LOGIC_COND_TYPE_OR) {
|
||||
taosArrayAddAll(output->result, params[m].result);
|
||||
} else if (node->condType == LOGIC_COND_TYPE_NOT) {
|
||||
taosArrayAddAll(output->result, params[m].result);
|
||||
}
|
||||
}
|
||||
_return:
|
||||
taosMemoryFree(params);
|
||||
SIF_RET(code);
|
||||
}
|
||||
|
||||
static EDealRes sifWalkFunction(SNode *pNode, void *context) {
|
||||
SFunctionNode *node = (SFunctionNode *)pNode;
|
||||
SIFParam output = {0};
|
||||
|
||||
SIFCtx *ctx = context;
|
||||
ctx->code = sifExecFunction(node, ctx, &output);
|
||||
if (ctx->code != TSDB_CODE_SUCCESS) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
|
||||
if (taosHashPut(ctx->pRes, &pNode, POINTER_BYTES, &output, sizeof(output))) {
|
||||
ctx->code = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
static EDealRes sifWalkLogic(SNode *pNode, void *context) {
|
||||
SLogicConditionNode *node = (SLogicConditionNode *)pNode;
|
||||
SIFParam output = {0};
|
||||
|
||||
SIFCtx *ctx = context;
|
||||
ctx->code = sifExecLogic(node, ctx, &output);
|
||||
if (ctx->code) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
|
||||
if (taosHashPut(ctx->pRes, &pNode, POINTER_BYTES, &output, sizeof(output))) {
|
||||
ctx->code = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
static EDealRes sifWalkOper(SNode *pNode, void *context) {
|
||||
SOperatorNode *node = (SOperatorNode *)pNode;
|
||||
SIFParam output = {0};
|
||||
|
||||
SIFCtx *ctx = context;
|
||||
ctx->code = sifExecOper(node, ctx, &output);
|
||||
if (ctx->code) {
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
|
||||
if (taosHashPut(ctx->pRes, &pNode, POINTER_BYTES, &output, sizeof(output))) {
|
||||
ctx->code = TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
EDealRes sifCalcWalker(SNode *node, void *context) {
|
||||
if (QUERY_NODE_VALUE == nodeType(node) || QUERY_NODE_NODE_LIST == nodeType(node) || QUERY_NODE_COLUMN == nodeType(node)) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
SIFCtx *ctx = (SIFCtx *)context;
|
||||
if (QUERY_NODE_FUNCTION == nodeType(node)) {
|
||||
return sifWalkFunction(node, ctx);
|
||||
}
|
||||
if (QUERY_NODE_LOGIC_CONDITION == nodeType(node)) {
|
||||
return sifWalkLogic(node, ctx);
|
||||
}
|
||||
if (QUERY_NODE_OPERATOR == nodeType(node)) {
|
||||
return sifWalkOper(node, ctx);
|
||||
}
|
||||
|
||||
qError("invalid node type for index filter calculating, type:%d", nodeType(node));
|
||||
ctx->code = TSDB_CODE_QRY_INVALID_INPUT;
|
||||
return DEAL_RES_ERROR;
|
||||
}
|
||||
|
||||
void sifFreeRes(SHashObj *res) {
|
||||
void *pIter = taosHashIterate(res, NULL);
|
||||
while (pIter) {
|
||||
SIFParam *p = pIter;
|
||||
if (p) {
|
||||
sifFreeParam(p);
|
||||
}
|
||||
pIter = taosHashIterate(res, pIter);
|
||||
}
|
||||
taosHashCleanup(res);
|
||||
}
|
||||
static int32_t sifCalculate(SNode *pNode, SIFParam *pDst) {
|
||||
if (pNode == NULL || pDst == NULL) {
|
||||
return TSDB_CODE_QRY_INVALID_INPUT;
|
||||
}
|
||||
int32_t code = 0;
|
||||
SIFCtx ctx = {.code = 0};
|
||||
ctx.pRes = taosHashInit(4, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BIGINT), false, HASH_NO_LOCK);
|
||||
if (NULL == ctx.pRes) {
|
||||
qError("index-filter failed to taosHashInit");
|
||||
return TSDB_CODE_QRY_OUT_OF_MEMORY;
|
||||
}
|
||||
nodesWalkExprPostOrder(pNode, sifCalcWalker, &ctx);
|
||||
if (ctx.code != TSDB_CODE_SUCCESS) {
|
||||
return ctx.code;
|
||||
}
|
||||
if (pDst) {
|
||||
SIFParam *res = (SIFParam *)taosHashGet(ctx.pRes, (void *)&pNode, POINTER_BYTES);
|
||||
if (res == NULL) {
|
||||
qError("no valid res in hash, node:(%p), type(%d)", (void *)&pNode, nodeType(pNode));
|
||||
return TSDB_CODE_QRY_APP_ERROR;
|
||||
}
|
||||
taosArrayAddAll(pDst->result, res->result);
|
||||
|
||||
sifFreeParam(res);
|
||||
taosHashRemove(ctx.pRes, (void *)&pNode, POINTER_BYTES);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t doFilterTag(const SNode *pFilterNode, SArray *result) {
|
||||
if (pFilterNode == NULL) {
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SFilterInfo *filter = NULL;
|
||||
// todo move to the initialization function
|
||||
int32_t code = filterInitFromNode((SNode *)pFilterNode, &filter, 0);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
SIFParam param = {0};
|
||||
code = sifCalculate((SNode *)pFilterNode, ¶m);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
return code;
|
||||
}
|
||||
|
||||
taosArrayAddAll(result, param.result);
|
||||
sifFreeParam(¶m);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
SIdxFltStatus idxGetFltStatus(SNode *pFilterNode) {
|
||||
if (pFilterNode == NULL) {
|
||||
return SFLT_NOT_INDEX;
|
||||
}
|
||||
// impl later
|
||||
return SFLT_ACCURATE_INDEX;
|
||||
}
|
|
@ -13,11 +13,13 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "tglobal.h"
|
||||
#include <common/ttime.h>
|
||||
#include "filter.h"
|
||||
#include "function.h"
|
||||
#include "functionMgt.h"
|
||||
#include "os.h"
|
||||
#include "querynodes.h"
|
||||
#include "tglobal.h"
|
||||
#include "tname.h"
|
||||
#include "vnode.h"
|
||||
|
||||
|
@ -64,35 +66,193 @@ static void setupQueryRangeForReverseScan(STableScanInfo* pTableScanInfo) {
|
|||
#endif
|
||||
}
|
||||
|
||||
int32_t loadDataBlock(SExecTaskInfo* pTaskInfo, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) {
|
||||
// relocated the column data according to the slotId
|
||||
static void relocateColumnData(SSDataBlock* pBlock, const SArray* pColMatchInfo, SArray* pCols) {
|
||||
int32_t numOfCols = pBlock->info.numOfCols;
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* p = taosArrayGet(pCols, i);
|
||||
SColMatchInfo* pmInfo = taosArrayGet(pColMatchInfo, i);
|
||||
if (!pmInfo->output) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ASSERT(pmInfo->colId == p->info.colId);
|
||||
taosArraySet(pBlock->pDataBlock, pmInfo->targetSlotId, p);
|
||||
}
|
||||
}
|
||||
|
||||
static void getNextTimeWindow(SInterval* pInterval, STimeWindow* tw, int32_t order) {
|
||||
int32_t factor = GET_FORWARD_DIRECTION_FACTOR(order);
|
||||
if (pInterval->intervalUnit != 'n' && pInterval->intervalUnit != 'y') {
|
||||
tw->skey += pInterval->sliding * factor;
|
||||
tw->ekey = tw->skey + pInterval->interval - 1;
|
||||
return;
|
||||
}
|
||||
|
||||
int64_t key = tw->skey, interval = pInterval->interval;
|
||||
//convert key to second
|
||||
key = convertTimePrecision(key, pInterval->precision, TSDB_TIME_PRECISION_MILLI) / 1000;
|
||||
|
||||
if (pInterval->intervalUnit == 'y') {
|
||||
interval *= 12;
|
||||
}
|
||||
|
||||
struct tm tm;
|
||||
time_t t = (time_t)key;
|
||||
taosLocalTime(&t, &tm);
|
||||
|
||||
int mon = (int)(tm.tm_year * 12 + tm.tm_mon + interval * factor);
|
||||
tm.tm_year = mon / 12;
|
||||
tm.tm_mon = mon % 12;
|
||||
tw->skey = convertTimePrecision((int64_t)taosMktime(&tm) * 1000L, TSDB_TIME_PRECISION_MILLI, pInterval->precision);
|
||||
|
||||
mon = (int)(mon + interval);
|
||||
tm.tm_year = mon / 12;
|
||||
tm.tm_mon = mon % 12;
|
||||
tw->ekey = convertTimePrecision((int64_t)taosMktime(&tm) * 1000L, TSDB_TIME_PRECISION_MILLI, pInterval->precision);
|
||||
|
||||
tw->ekey -= 1;
|
||||
}
|
||||
|
||||
static bool overlapWithTimeWindow(SInterval* pInterval, SDataBlockInfo* pBlockInfo) {
|
||||
STimeWindow w = {0};
|
||||
|
||||
// 0 by default, which means it is not a interval operator of the upstream operator.
|
||||
if (pInterval->interval == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// todo handle the time range case
|
||||
TSKEY sk = INT64_MIN;
|
||||
TSKEY ek = INT64_MAX;
|
||||
// TSKEY sk = MIN(pQueryAttr->window.skey, pQueryAttr->window.ekey);
|
||||
// TSKEY ek = MAX(pQueryAttr->window.skey, pQueryAttr->window.ekey);
|
||||
|
||||
if (true) {
|
||||
getAlignQueryTimeWindow(pInterval, pInterval->precision, pBlockInfo->window.skey, sk, ek, &w);
|
||||
assert(w.ekey >= pBlockInfo->window.skey);
|
||||
|
||||
if (w.ekey < pBlockInfo->window.ekey) {
|
||||
return true;
|
||||
}
|
||||
|
||||
while(1) { // todo handle the desc order scan case
|
||||
getNextTimeWindow(pInterval, &w, TSDB_ORDER_ASC);
|
||||
if (w.skey > pBlockInfo->window.ekey) {
|
||||
break;
|
||||
}
|
||||
|
||||
assert(w.ekey > pBlockInfo->window.ekey);
|
||||
if (w.skey <= pBlockInfo->window.ekey && w.skey > pBlockInfo->window.skey) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// getAlignQueryTimeWindow(pQueryAttr, pBlockInfo->window.ekey, sk, ek, &w);
|
||||
// assert(w.skey <= pBlockInfo->window.ekey);
|
||||
//
|
||||
// if (w.skey > pBlockInfo->window.skey) {
|
||||
// return true;
|
||||
// }
|
||||
//
|
||||
// while(1) {
|
||||
// getNextTimeWindow(pQueryAttr, &w);
|
||||
// if (w.ekey < pBlockInfo->window.skey) {
|
||||
// break;
|
||||
// }
|
||||
//
|
||||
// assert(w.skey < pBlockInfo->window.skey);
|
||||
// if (w.ekey < pBlockInfo->window.ekey && w.ekey >= pBlockInfo->window.skey) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t loadDataBlock(SOperatorInfo* pOperator, STableScanInfo* pTableScanInfo, SSDataBlock* pBlock, uint32_t* status) {
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
STableScanInfo* pInfo = pOperator->info;
|
||||
|
||||
STaskCostInfo* pCost = &pTaskInfo->cost;
|
||||
|
||||
pCost->totalBlocks += 1;
|
||||
pCost->totalRows += pBlock->info.rows;
|
||||
|
||||
*status = pInfo->dataBlockLoadFlag;
|
||||
if (pTableScanInfo->pFilterNode != NULL || overlapWithTimeWindow(&pTableScanInfo->interval, &pBlock->info)) {
|
||||
(*status) = FUNC_DATA_REQUIRED_DATA_LOAD;
|
||||
}
|
||||
|
||||
SDataBlockInfo* pBlockInfo = &pBlock->info;
|
||||
taosMemoryFreeClear(pBlock->pBlockAgg);
|
||||
|
||||
if (*status == FUNC_DATA_REQUIRED_FILTEROUT) {
|
||||
qDebug("%s data block filter out, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_TASKID(pTaskInfo), pBlockInfo->window.skey,
|
||||
pBlockInfo->window.ekey, pBlockInfo->rows);
|
||||
pCost->filterOutBlocks += 1;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else if (*status == FUNC_DATA_REQUIRED_NOT_LOAD) {
|
||||
qDebug("%s data block skipped, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_TASKID(pTaskInfo), pBlockInfo->window.skey,
|
||||
pBlockInfo->window.ekey, pBlockInfo->rows);
|
||||
pCost->skipBlocks += 1;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else if (*status == FUNC_DATA_REQUIRED_STATIS_LOAD) {
|
||||
pCost->loadBlockStatis += 1;
|
||||
|
||||
SColumnDataAgg* pColAgg = NULL;
|
||||
tsdbRetrieveDataBlockStatisInfo(pTableScanInfo->dataReader, &pColAgg);
|
||||
|
||||
if (pColAgg != NULL) {
|
||||
int32_t numOfCols = pBlock->info.numOfCols;
|
||||
|
||||
// todo create this buffer during creating operator
|
||||
pBlock->pBlockAgg = taosMemoryCalloc(numOfCols, sizeof(SColumnDataAgg));
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColMatchInfo* pColMatchInfo = taosArrayGet(pTableScanInfo->pColMatchInfo, i);
|
||||
if (!pColMatchInfo->output) {
|
||||
continue;
|
||||
}
|
||||
pBlock->pBlockAgg[pColMatchInfo->targetSlotId] = pColAgg[i];
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
} else { // failed to load the block sma data, data block statistics does not exist, load data block instead
|
||||
*status = FUNC_DATA_REQUIRED_DATA_LOAD;
|
||||
}
|
||||
}
|
||||
|
||||
ASSERT (*status == FUNC_DATA_REQUIRED_DATA_LOAD);
|
||||
|
||||
// todo filter data block according to the block sma data firstly
|
||||
#if 0
|
||||
if (!doFilterByBlockStatistics(pBlock->pBlockStatis, pTableScanInfo->pCtx, pBlockInfo->rows)) {
|
||||
pCost->filterOutBlocks += 1;
|
||||
qDebug("%s data block filter out, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_TASKID(pTaskInfo), pBlockInfo->window.skey,
|
||||
pBlockInfo->window.ekey, pBlockInfo->rows);
|
||||
(*status) = FUNC_DATA_REQUIRED_FILTEROUT;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
|
||||
pCost->totalCheckedRows += pBlock->info.rows;
|
||||
pCost->loadBlocks += 1;
|
||||
|
||||
*status = BLK_DATA_DATA_LOAD;
|
||||
|
||||
SArray* pCols = tsdbRetrieveDataBlock(pTableScanInfo->dataReader, NULL);
|
||||
if (pCols == NULL) {
|
||||
return terrno;
|
||||
}
|
||||
|
||||
int32_t numOfCols = pBlock->info.numOfCols;
|
||||
for (int32_t i = 0; i < numOfCols; ++i) {
|
||||
SColumnInfoData* p = taosArrayGet(pCols, i);
|
||||
SColMatchInfo* pColMatchInfo = taosArrayGet(pTableScanInfo->pColMatchInfo, i);
|
||||
if (!pColMatchInfo->output) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ASSERT(pColMatchInfo->colId == p->info.colId);
|
||||
taosArraySet(pBlock->pDataBlock, pColMatchInfo->targetSlotId, p);
|
||||
}
|
||||
relocateColumnData(pBlock, pTableScanInfo->pColMatchInfo, pCols);
|
||||
|
||||
doFilter(pTableScanInfo->pFilterNode, pBlock);
|
||||
if (pBlock->info.rows == 0) {
|
||||
pCost->filterOutBlocks += 1;
|
||||
qDebug("%s data block filter out, brange:%" PRId64 "-%" PRId64 ", rows:%d", GET_TASKID(pTaskInfo), pBlockInfo->window.skey,
|
||||
pBlockInfo->window.ekey, pBlockInfo->rows);
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
|
@ -111,7 +271,6 @@ static void setupEnvForReverseScan(STableScanInfo* pTableScanInfo, SqlFunctionCt
|
|||
|
||||
static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) {
|
||||
STableScanInfo* pTableScanInfo = pOperator->info;
|
||||
SExecTaskInfo* pTaskInfo = pOperator->pTaskInfo;
|
||||
|
||||
SSDataBlock* pBlock = pTableScanInfo->pResBlock;
|
||||
STableGroupInfo* pTableGroupInfo = &pOperator->pTaskInfo->tableqinfoGroupInfo;
|
||||
|
@ -138,15 +297,15 @@ static SSDataBlock* doTableScanImpl(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
// }
|
||||
|
||||
// this function never returns error?
|
||||
uint32_t status = BLK_DATA_DATA_LOAD;
|
||||
int32_t code = loadDataBlock(pTaskInfo, pTableScanInfo, pBlock, &status);
|
||||
uint32_t status = 0;
|
||||
int32_t code = loadDataBlock(pOperator, pTableScanInfo, pBlock, &status);
|
||||
// int32_t code = loadDataBlockOnDemand(pOperator->pRuntimeEnv, pTableScanInfo, pBlock, &status);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
longjmp(pOperator->pTaskInfo->env, code);
|
||||
}
|
||||
|
||||
// current block is ignored according to filter result by block statistics data, continue load the next block
|
||||
if (status == BLK_DATA_FILTEROUT || pBlock->info.rows == 0) {
|
||||
// current block is filter out according to filter condition, continue load the next block
|
||||
if (status == FUNC_DATA_REQUIRED_FILTEROUT || pBlock->info.rows == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -189,9 +348,9 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
setTaskStatus(pTaskInfo, TASK_NOT_COMPLETED);
|
||||
pTableScanInfo->scanFlag = REPEAT_SCAN;
|
||||
|
||||
if (pResultRowInfo->size > 0) {
|
||||
pResultRowInfo->curPos = 0;
|
||||
}
|
||||
// if (pResultRowInfo->size > 0) {
|
||||
// pResultRowInfo->curPos = 0;
|
||||
// }
|
||||
|
||||
qDebug("%s start to repeat scan data blocks due to query func required, qrange:%" PRId64 "-%" PRId64,
|
||||
GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey);
|
||||
|
@ -208,7 +367,7 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
GET_TASKID(pTaskInfo), pTaskInfo->window.skey, pTaskInfo->window.ekey);
|
||||
|
||||
if (pResultRowInfo->size > 0) {
|
||||
pResultRowInfo->curPos = pResultRowInfo->size - 1;
|
||||
// pResultRowInfo->curPos = pResultRowInfo->size - 1;
|
||||
}
|
||||
|
||||
p = doTableScanImpl(pOperator, newgroup);
|
||||
|
@ -217,9 +376,9 @@ static SSDataBlock* doTableScan(SOperatorInfo* pOperator, bool* newgroup) {
|
|||
return p;
|
||||
}
|
||||
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput,
|
||||
SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order, int32_t numOfOutput, int32_t dataLoadFlag,
|
||||
int32_t repeatTime, int32_t reverseTime, SArray* pColMatchInfo, SSDataBlock* pResBlock,
|
||||
SNode* pCondition, SExecTaskInfo* pTaskInfo) {
|
||||
SNode* pCondition, SInterval* pInterval, double sampleRatio, SExecTaskInfo* pTaskInfo) {
|
||||
assert(repeatTime > 0);
|
||||
|
||||
STableScanInfo* pInfo = taosMemoryCalloc(1, sizeof(STableScanInfo));
|
||||
|
@ -232,6 +391,9 @@ SOperatorInfo* createTableScanOperatorInfo(void* pTsdbReadHandle, int32_t order,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
pInfo->interval = *pInterval;
|
||||
pInfo->sampleRatio = sampleRatio;
|
||||
pInfo->dataBlockLoadFlag= dataLoadFlag;
|
||||
pInfo->pResBlock = pResBlock;
|
||||
pInfo->pFilterNode = pCondition;
|
||||
pInfo->dataReader = pTsdbReadHandle;
|
||||
|
|
|
@ -8,7 +8,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
|
|||
ADD_EXECUTABLE(executorTest ${SOURCE_LIST})
|
||||
TARGET_LINK_LIBRARIES(
|
||||
executorTest
|
||||
PRIVATE os util common transport gtest taos qcom executor function planner scalar nodes
|
||||
PRIVATE os util common transport gtest taos_static qcom executor function planner scalar nodes
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
|
|
|
@ -37,6 +37,7 @@ extern "C" {
|
|||
#define FUNC_MGT_WINDOW_PC_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(8)
|
||||
#define FUNC_MGT_SPECIAL_DATA_REQUIRED FUNC_MGT_FUNC_CLASSIFICATION_MASK(9)
|
||||
#define FUNC_MGT_DYNAMIC_SCAN_OPTIMIZED FUNC_MGT_FUNC_CLASSIFICATION_MASK(10)
|
||||
#define FUNC_MGT_MULTI_RES_FUNC FUNC_MGT_FUNC_CLASSIFICATION_MASK(11)
|
||||
|
||||
#define FUNC_MGT_TEST_MASK(val, mask) (((val) & (mask)) != 0)
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWind
|
|||
bool getCountFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
int32_t countFunction(SqlFunctionCtx *pCtx);
|
||||
|
||||
EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow);
|
||||
bool getSumFuncEnv(struct SFunctionNode* pFunc, SFuncExecEnv* pEnv);
|
||||
int32_t sumFunction(SqlFunctionCtx *pCtx);
|
||||
|
||||
|
|
|
@ -138,6 +138,12 @@ static int32_t translateTimePseudoColumn(SFunctionNode* pFunc, char* pErrBuf, in
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateTimezone(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
// pseudo column do not need to check parameters
|
||||
pFunc->node.resType = (SDataType){.bytes = TD_TIMEZONE_LEN, .type = TSDB_DATA_TYPE_BINARY};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translatePercentile(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
if (2 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
|
@ -203,9 +209,9 @@ static int32_t translateLastRow(SFunctionNode* pFunc, char* pErrBuf, int32_t len
|
|||
}
|
||||
|
||||
static int32_t translateFirstLast(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
// first(*)/first(col_list) has been rewritten as first(col)
|
||||
// first(col_list) will be rewritten as first(col)
|
||||
if (1 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
SNode* pPara = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
|
@ -231,33 +237,45 @@ static int32_t translateLength(SFunctionNode* pFunc, char* pErrBuf, int32_t len)
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, int32_t minParaNum, int32_t maxParaNum, int32_t primaryParaNo) {
|
||||
static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t len, int32_t minParaNum, int32_t maxParaNum, bool hasSep) {
|
||||
int32_t paraNum = LIST_LENGTH(pFunc->pParameterList);
|
||||
if (paraNum < minParaNum || paraNum > maxParaNum) {
|
||||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
uint8_t resultType = TSDB_DATA_TYPE_NCHAR;
|
||||
uint8_t resultType = TSDB_DATA_TYPE_BINARY;
|
||||
int32_t resultBytes = 0;
|
||||
int32_t sepBytes = 0;
|
||||
for (int32_t i = 0; i < LIST_LENGTH(pFunc->pParameterList); ++i) {
|
||||
|
||||
/* For concat/concat_ws function, if params have NCHAR type, promote the final result to NCHAR */
|
||||
for (int32_t i = 0; i < paraNum; ++i) {
|
||||
SNode* pPara = nodesListGetNode(pFunc->pParameterList, i);
|
||||
uint8_t paraType = ((SExprNode*)pPara)->resType.type;
|
||||
int32_t paraBytes = ((SExprNode*)pPara)->resType.bytes;
|
||||
if (!IS_VAR_DATA_TYPE(paraType)) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
if (i < primaryParaNo) {
|
||||
sepBytes = paraBytes;
|
||||
continue;
|
||||
if (TSDB_DATA_TYPE_NCHAR == paraType) {
|
||||
resultType = paraType;
|
||||
}
|
||||
if (TSDB_DATA_TYPE_BINARY == paraType) {
|
||||
resultType = TSDB_DATA_TYPE_BINARY;
|
||||
}
|
||||
resultBytes += paraBytes;
|
||||
}
|
||||
if (sepBytes > 0) {
|
||||
resultBytes += sepBytes * (paraNum - 2);
|
||||
|
||||
for (int32_t i = 0; i < paraNum; ++i) {
|
||||
SNode* pPara = nodesListGetNode(pFunc->pParameterList, i);
|
||||
uint8_t paraType = ((SExprNode*)pPara)->resType.type;
|
||||
int32_t paraBytes = ((SExprNode*)pPara)->resType.bytes;
|
||||
int32_t factor = 1;
|
||||
if (TSDB_DATA_TYPE_NCHAR == resultType && TSDB_DATA_TYPE_VARCHAR == paraType) {
|
||||
factor *= TSDB_NCHAR_SIZE;
|
||||
}
|
||||
resultBytes += paraBytes * factor;
|
||||
|
||||
if (i == 0) {
|
||||
sepBytes = paraBytes * factor;
|
||||
}
|
||||
}
|
||||
|
||||
if (hasSep) {
|
||||
resultBytes += sepBytes * (paraNum - 3);
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType) { .bytes = resultBytes, .type = resultType };
|
||||
|
@ -265,11 +283,11 @@ static int32_t translateConcatImpl(SFunctionNode* pFunc, char* pErrBuf, int32_t
|
|||
}
|
||||
|
||||
static int32_t translateConcat(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
return translateConcatImpl(pFunc, pErrBuf, len, 2, 8, 0);
|
||||
return translateConcatImpl(pFunc, pErrBuf, len, 2, 8, false);
|
||||
}
|
||||
|
||||
static int32_t translateConcatWs(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
return translateConcatImpl(pFunc, pErrBuf, len, 3, 9, 1);
|
||||
return translateConcatImpl(pFunc, pErrBuf, len, 3, 9, true);
|
||||
}
|
||||
|
||||
static int32_t translateSubstr(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
|
@ -370,6 +388,20 @@ static int32_t translateTimeDiff(SFunctionNode* pFunc, char* pErrBuf, int32_t le
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateToJson(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
||||
if (1 != LIST_LENGTH(pFunc->pParameterList)) {
|
||||
return invaildFuncParaNumErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
SExprNode* pPara = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_VALUE != nodeType(pPara) || (!IS_VAR_DATA_TYPE(pPara->resType.type))) {
|
||||
return invaildFuncParaTypeErrMsg(pErrBuf, len, pFunc->functionName);
|
||||
}
|
||||
|
||||
pFunc->node.resType = (SDataType) { .bytes = tDataTypes[TSDB_DATA_TYPE_JSON].bytes, .type = TSDB_DATA_TYPE_JSON};
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
||||
{
|
||||
.name = "count",
|
||||
|
@ -385,8 +417,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "sum",
|
||||
.type = FUNCTION_TYPE_SUM,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
||||
.translateFunc = translateSum,
|
||||
.dataRequiredFunc = statisDataRequired,
|
||||
.getEnvFunc = getSumFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
.processFunc = sumFunction,
|
||||
|
@ -395,8 +428,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "min",
|
||||
.type = FUNCTION_TYPE_MIN,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
||||
.translateFunc = translateInOutNum,
|
||||
.dataRequiredFunc = statisDataRequired,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = minFunctionSetup,
|
||||
.processFunc = minFunction,
|
||||
|
@ -405,8 +439,9 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "max",
|
||||
.type = FUNCTION_TYPE_MAX,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_SPECIAL_DATA_REQUIRED,
|
||||
.translateFunc = translateInOutNum,
|
||||
.dataRequiredFunc = statisDataRequired,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
.processFunc = maxFunction,
|
||||
|
@ -475,7 +510,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "last_row",
|
||||
.type = FUNCTION_TYPE_LAST_ROW,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC,
|
||||
.translateFunc = translateLastRow,
|
||||
.getEnvFunc = getMinmaxFuncEnv,
|
||||
.initFunc = maxFunctionSetup,
|
||||
|
@ -485,7 +520,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "first",
|
||||
.type = FUNCTION_TYPE_FIRST,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC,
|
||||
.translateFunc = translateFirstLast,
|
||||
.getEnvFunc = getFirstLastFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
|
@ -495,7 +530,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "last",
|
||||
.type = FUNCTION_TYPE_LAST,
|
||||
.classification = FUNC_MGT_AGG_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_MULTI_RES_FUNC,
|
||||
.translateFunc = translateFirstLast,
|
||||
.getEnvFunc = getFirstLastFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
|
@ -802,6 +837,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.sprocessFunc = todayFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "timezone",
|
||||
.type = FUNCTION_TYPE_TIMEZONE,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateTimezone,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = timezoneFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "_rowts",
|
||||
.type = FUNCTION_TYPE_ROWTS,
|
||||
|
@ -871,6 +916,16 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.initFunc = NULL,
|
||||
.sprocessFunc = winDurFunction,
|
||||
.finalizeFunc = NULL
|
||||
},
|
||||
{
|
||||
.name = "to_json",
|
||||
.type = FUNCTION_TYPE_TO_JSON,
|
||||
.classification = FUNC_MGT_SCALAR_FUNC,
|
||||
.translateFunc = translateToJson,
|
||||
.getEnvFunc = NULL,
|
||||
.initFunc = NULL,
|
||||
.sprocessFunc = NULL,
|
||||
.finalizeFunc = NULL
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -58,9 +58,9 @@ void functionFinalize(SqlFunctionCtx *pCtx) {
|
|||
EFuncDataRequired countDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) {
|
||||
SNode* pParam = nodesListGetNode(pFunc->pParameterList, 0);
|
||||
if (QUERY_NODE_COLUMN == nodeType(pParam) && PRIMARYKEY_TIMESTAMP_COL_ID == ((SColumnNode*)pParam)->colId) {
|
||||
return FUNC_DATA_REQUIRED_NO_NEEDED;
|
||||
return FUNC_DATA_REQUIRED_NOT_LOAD;
|
||||
}
|
||||
return FUNC_DATA_REQUIRED_STATIS_NEEDED;
|
||||
return FUNC_DATA_REQUIRED_STATIS_LOAD;
|
||||
}
|
||||
|
||||
bool getCountFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
||||
|
@ -183,6 +183,10 @@ bool getSumFuncEnv(SFunctionNode* UNUSED_PARAM(pFunc), SFuncExecEnv* pEnv) {
|
|||
return true;
|
||||
}
|
||||
|
||||
EFuncDataRequired statisDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow){
|
||||
return FUNC_DATA_REQUIRED_STATIS_LOAD;
|
||||
}
|
||||
|
||||
bool maxFunctionSetup(SqlFunctionCtx *pCtx, SResultRowEntryInfo* pResultInfo) {
|
||||
if (!functionSetup(pCtx, pResultInfo)) {
|
||||
return false;
|
||||
|
@ -357,20 +361,15 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) {
|
|||
index = pInput->pColumnDataAgg[0]->maxIndex;
|
||||
}
|
||||
|
||||
TSKEY key = TSKEY_INITIAL_VAL;
|
||||
if (pCtx->ptsList != NULL) {
|
||||
// the index is the original position, not the relative position
|
||||
key = pCtx->ptsList[index];
|
||||
}
|
||||
// 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);
|
||||
|
||||
int64_t val = GET_INT64_VAL(tval);
|
||||
|
||||
#if defined(_DEBUG_VIEW)
|
||||
qDebug("max value updated according to pre-cal:%d", *data);
|
||||
#endif
|
||||
|
||||
if ((*(int64_t*)buf < val) ^ isMinFunc) {
|
||||
if ((prev < val) ^ isMinFunc) {
|
||||
*(int64_t*) buf = val;
|
||||
for (int32_t i = 0; i < (pCtx)->subsidiaryRes.numOfCols; ++i) {
|
||||
SqlFunctionCtx* __ctx = pCtx->subsidiaryRes.pCtx[i];
|
||||
|
@ -383,14 +382,28 @@ int32_t doMinMaxHelper(SqlFunctionCtx *pCtx, int32_t isMinFunc) {
|
|||
}
|
||||
}
|
||||
} 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);
|
||||
UPDATE_DATA(pCtx, *(uint64_t*)buf, val, numOfElems, isMinFunc, key);
|
||||
if ((prev < val) ^ isMinFunc) {
|
||||
*(uint64_t*) buf = val;
|
||||
for (int32_t i = 0; i < (pCtx)->subsidiaryRes.numOfCols; ++i) {
|
||||
SqlFunctionCtx* __ctx = pCtx->subsidiaryRes.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);
|
||||
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, (float)val, numOfElems, isMinFunc, key);
|
||||
UPDATE_DATA(pCtx, *(float*) buf, val, numOfElems, isMinFunc, key);
|
||||
}
|
||||
|
||||
return numOfElems;
|
||||
|
|
|
@ -78,10 +78,10 @@ int32_t fmGetFuncResultType(SFunctionNode* pFunc, char* pErrBuf, int32_t len) {
|
|||
|
||||
EFuncDataRequired fmFuncDataRequired(SFunctionNode* pFunc, STimeWindow* pTimeWindow) {
|
||||
if (pFunc->funcId < 0 || pFunc->funcId >= funcMgtBuiltinsNum) {
|
||||
return FUNC_DATA_REQUIRED_ALL_NEEDED;
|
||||
return FUNC_DATA_REQUIRED_DATA_LOAD;
|
||||
}
|
||||
if (NULL == funcMgtBuiltins[pFunc->funcId].dataRequiredFunc) {
|
||||
return FUNC_DATA_REQUIRED_ALL_NEEDED;
|
||||
return FUNC_DATA_REQUIRED_DATA_LOAD;
|
||||
}
|
||||
return funcMgtBuiltins[pFunc->funcId].dataRequiredFunc(pFunc, pTimeWindow);
|
||||
}
|
||||
|
@ -138,6 +138,10 @@ bool fmIsDynamicScanOptimizedFunc(int32_t funcId) {
|
|||
return isSpecificClassifyFunc(funcId, FUNC_MGT_DYNAMIC_SCAN_OPTIMIZED);
|
||||
}
|
||||
|
||||
bool fmIsMultiResFunc(int32_t funcId) {
|
||||
return isSpecificClassifyFunc(funcId, FUNC_MGT_MULTI_RES_FUNC);
|
||||
}
|
||||
|
||||
void fmFuncMgtDestroy() {
|
||||
void* m = gFunMgtService.pFuncNameHashTable;
|
||||
if (m != NULL && atomic_val_compare_exchange_ptr((void**)&gFunMgtService.pFuncNameHashTable, m, 0) == m) {
|
||||
|
|
|
@ -748,6 +748,11 @@ static const char* jkTableScanPhysiPlanEndKey = "EndKey";
|
|||
static const char* jkTableScanPhysiPlanRatio = "Ratio";
|
||||
static const char* jkTableScanPhysiPlanDataRequired = "DataRequired";
|
||||
static const char* jkTableScanPhysiPlanDynamicScanFuncs = "DynamicScanFuncs";
|
||||
static const char* jkTableScanPhysiPlanInterval = "Interval";
|
||||
static const char* jkTableScanPhysiPlanOffset = "Offset";
|
||||
static const char* jkTableScanPhysiPlanSliding = "Sliding";
|
||||
static const char* jkTableScanPhysiPlanIntervalUnit = "intervalUnit";
|
||||
static const char* jkTableScanPhysiPlanSlidingUnit = "slidingUnit";
|
||||
|
||||
static int32_t physiTableScanNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const STableScanPhysiNode* pNode = (const STableScanPhysiNode*)pObj;
|
||||
|
@ -771,6 +776,21 @@ static int32_t physiTableScanNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodeListToJson(pJson, jkTableScanPhysiPlanDynamicScanFuncs, pNode->pDynamicScanFuncs);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanInterval, pNode->interval);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanOffset, pNode->offset);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanSliding, pNode->sliding);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanIntervalUnit, pNode->intervalUnit);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkTableScanPhysiPlanSlidingUnit, pNode->slidingUnit);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -797,6 +817,21 @@ static int32_t jsonToPhysiTableScanNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeList(pJson, jkTableScanPhysiPlanDynamicScanFuncs, &pNode->pDynamicScanFuncs);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetNumberValue(pJson, jkTableScanPhysiPlanInterval, pNode->interval);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetNumberValue(pJson, jkTableScanPhysiPlanOffset, pNode->offset);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetNumberValue(pJson, jkTableScanPhysiPlanSliding, pNode->sliding);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetNumberValue(pJson, jkTableScanPhysiPlanIntervalUnit, pNode->intervalUnit);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetNumberValue(pJson, jkTableScanPhysiPlanSlidingUnit, pNode->slidingUnit);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1104,6 +1139,8 @@ static int32_t jsonToPhysiSortNode(const SJson* pJson, void* pObj) {
|
|||
static const char* jkWindowPhysiPlanExprs = "Exprs";
|
||||
static const char* jkWindowPhysiPlanFuncs = "Funcs";
|
||||
static const char* jkWindowPhysiPlanTsPk = "TsPk";
|
||||
static const char* jkWindowPhysiPlanTriggerType = "TriggerType";
|
||||
static const char* jkWindowPhysiPlanWatermark = "Watermark";
|
||||
|
||||
static int32_t physiWindowNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SWinodwPhysiNode* pNode = (const SWinodwPhysiNode*)pObj;
|
||||
|
@ -1118,6 +1155,12 @@ static int32_t physiWindowNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkWindowPhysiPlanTsPk, nodeToJson, pNode->pTspk);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanTriggerType, pNode->triggerType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkWindowPhysiPlanWatermark, pNode->watermark);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1135,6 +1178,12 @@ static int32_t jsonToPhysiWindowNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkWindowPhysiPlanTsPk, (SNode**)&pNode->pTspk);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetNumberValue(pJson, jkWindowPhysiPlanTriggerType, pNode->triggerType);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetNumberValue(pJson, jkWindowPhysiPlanWatermark, pNode->watermark);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1145,7 +1194,6 @@ static const char* jkIntervalPhysiPlanSliding = "Sliding";
|
|||
static const char* jkIntervalPhysiPlanIntervalUnit = "intervalUnit";
|
||||
static const char* jkIntervalPhysiPlanSlidingUnit = "slidingUnit";
|
||||
static const char* jkIntervalPhysiPlanFill = "Fill";
|
||||
static const char* jkIntervalPhysiPlanPrecision = "Precision";
|
||||
|
||||
static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) {
|
||||
const SIntervalPhysiNode* pNode = (const SIntervalPhysiNode*)pObj;
|
||||
|
@ -1169,9 +1217,6 @@ static int32_t physiIntervalNodeToJson(const void* pObj, SJson* pJson) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddObject(pJson, jkIntervalPhysiPlanFill, nodeToJson, pNode->pFill);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonAddIntegerToObject(pJson, jkIntervalPhysiPlanPrecision, pNode->precision);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
@ -1198,9 +1243,6 @@ static int32_t jsonToPhysiIntervalNode(const SJson* pJson, void* pObj) {
|
|||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = jsonToNodeObject(pJson, jkIntervalPhysiPlanFill, (SNode**)&pNode->pFill);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = tjsonGetUTinyIntValue(pJson, jkIntervalPhysiPlanPrecision, &pNode->precision);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
|
|
@ -87,9 +87,9 @@ static EDealRes walkNode(SNode* pNode, ETraversalOrder order, FNodeWalker walker
|
|||
}
|
||||
case QUERY_NODE_SESSION_WINDOW: {
|
||||
SSessionWindowNode* pSession = (SSessionWindowNode*)pNode;
|
||||
res = walkNode(pSession->pCol, order, walker, pContext);
|
||||
res = walkNode((SNode*)pSession->pCol, order, walker, pContext);
|
||||
if (DEAL_RES_ERROR != res && DEAL_RES_END != res) {
|
||||
res = walkNode(pSession->pGap, order, walker, pContext);
|
||||
res = walkNode((SNode*)pSession->pGap, order, walker, pContext);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -227,9 +227,9 @@ static EDealRes rewriteNode(SNode** pRawNode, ETraversalOrder order, FNodeRewrit
|
|||
}
|
||||
case QUERY_NODE_SESSION_WINDOW: {
|
||||
SSessionWindowNode* pSession = (SSessionWindowNode*)pNode;
|
||||
res = rewriteNode(&pSession->pCol, order, rewriter, pContext);
|
||||
res = rewriteNode((SNode**)&pSession->pCol, order, rewriter, pContext);
|
||||
if (DEAL_RES_ERROR != res && DEAL_RES_END != res) {
|
||||
res = rewriteNode(&pSession->pGap, order, rewriter, pContext);
|
||||
res = rewriteNode((SNode**)&pSession->pGap, order, rewriter, pContext);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -84,6 +84,8 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
|||
return makeNode(type, sizeof(SIndexOptions));
|
||||
case QUERY_NODE_EXPLAIN_OPTIONS:
|
||||
return makeNode(type, sizeof(SExplainOptions));
|
||||
case QUERY_NODE_STREAM_OPTIONS:
|
||||
return makeNode(type, sizeof(SStreamOptions));
|
||||
case QUERY_NODE_SET_OPERATOR:
|
||||
return makeNode(type, sizeof(SSetOperator));
|
||||
case QUERY_NODE_SELECT_STMT:
|
||||
|
@ -146,6 +148,19 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
|||
return makeNode(type, sizeof(SDescribeStmt));
|
||||
case QUERY_NODE_RESET_QUERY_CACHE_STMT:
|
||||
return makeNode(type, sizeof(SNode));
|
||||
case QUERY_NODE_COMPACT_STMT:
|
||||
case QUERY_NODE_CREATE_FUNCTION_STMT:
|
||||
case QUERY_NODE_DROP_FUNCTION_STMT:
|
||||
break;
|
||||
case QUERY_NODE_CREATE_STREAM_STMT:
|
||||
return makeNode(type, sizeof(SCreateStreamStmt));
|
||||
case QUERY_NODE_DROP_STREAM_STMT:
|
||||
return makeNode(type, sizeof(SDropStreamStmt));
|
||||
case QUERY_NODE_MERGE_VGROUP_STMT:
|
||||
case QUERY_NODE_REDISTRIBUTE_VGROUP_STMT:
|
||||
case QUERY_NODE_SPLIT_VGROUP_STMT:
|
||||
case QUERY_NODE_SYNCDB_STMT:
|
||||
break;
|
||||
case QUERY_NODE_SHOW_DNODES_STMT:
|
||||
case QUERY_NODE_SHOW_MNODES_STMT:
|
||||
case QUERY_NODE_SHOW_MODULES_STMT:
|
||||
|
@ -169,7 +184,16 @@ SNodeptr nodesMakeNode(ENodeType type) {
|
|||
case QUERY_NODE_SHOW_CONFIGS_STMT:
|
||||
case QUERY_NODE_SHOW_QUERIES_STMT:
|
||||
case QUERY_NODE_SHOW_VNODES_STMT:
|
||||
case QUERY_NODE_SHOW_APPS_STMT:
|
||||
case QUERY_NODE_SHOW_SCORES_STMT:
|
||||
case QUERY_NODE_SHOW_VARIABLE_STMT:
|
||||
case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
|
||||
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
|
||||
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
|
||||
return makeNode(type, sizeof(SShowStmt));
|
||||
case QUERY_NODE_KILL_CONNECTION_STMT:
|
||||
case QUERY_NODE_KILL_QUERY_STMT:
|
||||
return makeNode(type, sizeof(SKillStmt));
|
||||
case QUERY_NODE_LOGIC_PLAN_SCAN:
|
||||
return makeNode(type, sizeof(SScanLogicNode));
|
||||
case QUERY_NODE_LOGIC_PLAN_JOIN:
|
||||
|
@ -675,6 +699,7 @@ int32_t nodesListAppend(SNodeList* pList, SNodeptr pNode) {
|
|||
if (NULL != pList->pTail) {
|
||||
pList->pTail->pNext = p;
|
||||
}
|
||||
p->pPrev = pList->pTail;
|
||||
pList->pTail = p;
|
||||
++(pList->length);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -1201,7 +1226,7 @@ void valueNodeToVariant(const SValueNode* pNode, SVariant* pVal) {
|
|||
case TSDB_DATA_TYPE_NCHAR:
|
||||
case TSDB_DATA_TYPE_VARCHAR:
|
||||
case TSDB_DATA_TYPE_VARBINARY:
|
||||
pVal->pz = pNode->datum.p + VARSTR_HEADER_SIZE;
|
||||
pVal->pz = pNode->datum.p;
|
||||
break;
|
||||
case TSDB_DATA_TYPE_JSON:
|
||||
case TSDB_DATA_TYPE_DECIMAL:
|
||||
|
|
|
@ -86,13 +86,14 @@ SNode* createColumnNode(SAstCreateContext* pCxt, SToken* pTableAlias, SToken* pC
|
|||
SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken* pLiteral);
|
||||
SNode* createDurationValueNode(SAstCreateContext* pCxt, const SToken* pLiteral);
|
||||
SNode* createDefaultDatabaseCondValue(SAstCreateContext* pCxt);
|
||||
SNode* createPlaceholderValueNode(SAstCreateContext* pCxt);
|
||||
SNode* setProjectionAlias(SAstCreateContext* pCxt, SNode* pNode, const SToken* pAlias);
|
||||
SNode* createLogicConditionNode(SAstCreateContext* pCxt, ELogicConditionType type, SNode* pParam1, SNode* pParam2);
|
||||
SNode* createOperatorNode(SAstCreateContext* pCxt, EOperatorType type, SNode* pLeft, SNode* pRight);
|
||||
SNode* createBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight);
|
||||
SNode* createNotBetweenAnd(SAstCreateContext* pCxt, SNode* pExpr, SNode* pLeft, SNode* pRight);
|
||||
SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNodeList* pParameterList);
|
||||
SNode* createFunctionNodeNoParam(SAstCreateContext* pCxt, const SToken* pFuncName);
|
||||
SNode* createFunctionNodeNoArg(SAstCreateContext* pCxt, const SToken* pFuncName);
|
||||
SNode* createCastFunctionNode(SAstCreateContext* pCxt, SNode* pExpr, SDataType dt);
|
||||
SNode* createNodeListNode(SAstCreateContext* pCxt, SNodeList* pList);
|
||||
SNode* createNodeListNodeEx(SAstCreateContext* pCxt, SNode* p1, SNode* p2);
|
||||
|
@ -166,8 +167,9 @@ SNode* createResetQueryCacheStmt(SAstCreateContext* pCxt);
|
|||
SNode* createCompactStmt(SAstCreateContext* pCxt, SNodeList* pVgroups);
|
||||
SNode* createCreateFunctionStmt(SAstCreateContext* pCxt, bool aggFunc, const SToken* pFuncName, const SToken* pLibPath, SDataType dataType, int32_t bufSize);
|
||||
SNode* createDropFunctionStmt(SAstCreateContext* pCxt, const SToken* pFuncName);
|
||||
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, const SToken* pStreamName, const SToken* pTableName, SNode* pQuery);
|
||||
SNode* createDropStreamStmt(SAstCreateContext* pCxt, const SToken* pStreamName);
|
||||
SNode* createStreamOptions(SAstCreateContext* pCxt);
|
||||
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable, SNode* pOptions, SNode* pQuery);
|
||||
SNode* createDropStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pStreamName);
|
||||
SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId);
|
||||
SNode* createMergeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId1, const SToken* pVgId2);
|
||||
SNode* createRedistributeVgroupStmt(SAstCreateContext* pCxt, const SToken* pVgId, SNodeList* pDnodes);
|
||||
|
|
|
@ -293,6 +293,7 @@ tags_def(A) ::= TAGS NK_LP column_def_list(B) NK_RP.
|
|||
table_options(A) ::= . { A = createTableOptions(pCxt); }
|
||||
table_options(A) ::= table_options(B) COMMENT NK_STRING(C). { ((STableOptions*)B)->pComments = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &C); A = B; }
|
||||
table_options(A) ::= table_options(B) KEEP integer_list(C). { ((STableOptions*)B)->pKeep = C; A = B; }
|
||||
table_options(A) ::= table_options(B) KEEP variable_list(C). { ((STableOptions*)B)->pKeep = C; A = B; }
|
||||
table_options(A) ::= table_options(B) TTL NK_INTEGER(C). { ((STableOptions*)B)->pTtl = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &C); A = B; }
|
||||
table_options(A) ::= table_options(B) SMA NK_LP col_name_list(C) NK_RP. { ((STableOptions*)B)->pSma = C; A = B; }
|
||||
table_options(A) ::= table_options(B) ROLLUP NK_LP func_name_list(C) NK_RP. { ((STableOptions*)B)->pFuncs = C; A = B; }
|
||||
|
@ -306,6 +307,7 @@ alter_table_options(A) ::= alter_table_options(B) alter_table_option(C).
|
|||
%destructor alter_table_option { }
|
||||
alter_table_option(A) ::= COMMENT NK_STRING(B). { A.type = TABLE_OPTION_COMMENT; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &B); }
|
||||
alter_table_option(A) ::= KEEP integer_list(B). { A.type = TABLE_OPTION_KEEP; A.pList = B; }
|
||||
alter_table_option(A) ::= KEEP variable_list(B). { A.type = TABLE_OPTION_KEEP; A.pList = B; }
|
||||
alter_table_option(A) ::= TTL NK_INTEGER(B). { A.type = TABLE_OPTION_TTL; A.pVal = (SValueNode*)createValueNode(pCxt, TSDB_DATA_TYPE_BIGINT, &B); }
|
||||
|
||||
%type col_name_list { SNodeList* }
|
||||
|
@ -424,8 +426,17 @@ bufsize_opt(A) ::= .
|
|||
bufsize_opt(A) ::= BUFSIZE NK_INTEGER(B). { A = strtol(B.z, NULL, 10); }
|
||||
|
||||
/************************************************ create/drop stream **************************************************/
|
||||
cmd ::= CREATE STREAM stream_name(A) INTO table_name(B) AS query_expression(C). { pCxt->pRootNode = createCreateStreamStmt(pCxt, &A, &B, C); }
|
||||
cmd ::= DROP STREAM stream_name(A). { pCxt->pRootNode = createDropStreamStmt(pCxt, &A); }
|
||||
cmd ::= CREATE STREAM not_exists_opt(E) stream_name(A)
|
||||
stream_options(B) into_opt(C) AS query_expression(D). { pCxt->pRootNode = createCreateStreamStmt(pCxt, E, &A, C, B, D); }
|
||||
cmd ::= DROP STREAM exists_opt(A) stream_name(B). { pCxt->pRootNode = createDropStreamStmt(pCxt, A, &B); }
|
||||
|
||||
into_opt(A) ::= . { A = NULL; }
|
||||
into_opt(A) ::= INTO full_table_name(B). { A = B; }
|
||||
|
||||
stream_options(A) ::= . { A = createStreamOptions(pCxt); }
|
||||
stream_options(A) ::= stream_options(B) TRIGGER AT_ONCE. { ((SStreamOptions*)B)->triggerType = STREAM_TRIGGER_AT_ONCE; A = B; }
|
||||
stream_options(A) ::= stream_options(B) TRIGGER WINDOW_CLOSE. { ((SStreamOptions*)B)->triggerType = STREAM_TRIGGER_WINDOW_CLOSE; A = B; }
|
||||
stream_options(A) ::= stream_options(B) WATERMARK duration_literal(C). { ((SStreamOptions*)B)->pWatermark = releaseRawExprNode(pCxt, C); A = B; }
|
||||
|
||||
/************************************************ kill connection/query ***********************************************/
|
||||
cmd ::= KILL CONNECTION NK_INTEGER(A). { pCxt->pRootNode = createKillStmt(pCxt, QUERY_NODE_KILL_CONNECTION_STMT, &A); }
|
||||
|
@ -455,6 +466,7 @@ literal(A) ::= NK_BOOL(B).
|
|||
literal(A) ::= TIMESTAMP(B) NK_STRING(C). { A = createRawExprNodeExt(pCxt, &B, &C, createValueNode(pCxt, TSDB_DATA_TYPE_TIMESTAMP, &C)); }
|
||||
literal(A) ::= duration_literal(B). { A = B; }
|
||||
literal(A) ::= NULL(B). { A = createRawExprNode(pCxt, &B, createValueNode(pCxt, TSDB_DATA_TYPE_NULL, NULL)); }
|
||||
literal(A) ::= NK_QUESTION(B). { A = createRawExprNode(pCxt, &B, createPlaceholderValueNode(pCxt)); }
|
||||
|
||||
duration_literal(A) ::= NK_VARIABLE(B). { A = createRawExprNode(pCxt, &B, createDurationValueNode(pCxt, &B)); }
|
||||
|
||||
|
@ -501,10 +513,6 @@ column_name(A) ::= NK_ID(B).
|
|||
%type function_name { SToken }
|
||||
%destructor function_name { }
|
||||
function_name(A) ::= NK_ID(B). { A = B; }
|
||||
function_name(A) ::= FIRST(B). { A = B; }
|
||||
function_name(A) ::= LAST(B). { A = B; }
|
||||
function_name(A) ::= NOW(B). { A = B; }
|
||||
function_name(A) ::= TODAY(B). { A = B; }
|
||||
|
||||
%type table_alias { SToken }
|
||||
%destructor table_alias { }
|
||||
|
@ -532,13 +540,9 @@ stream_name(A) ::= NK_ID(B).
|
|||
|
||||
/************************************************ expression **********************************************************/
|
||||
expression(A) ::= literal(B). { A = B; }
|
||||
//expression(A) ::= NK_QUESTION(B). { A = B; }
|
||||
expression(A) ::= pseudo_column(B). { A = B; }
|
||||
expression(A) ::= column_reference(B). { A = B; }
|
||||
expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
|
||||
expression(A) ::= function_name(B) NK_LP NK_STAR(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, createNodeList(pCxt, createColumnNode(pCxt, NULL, &C)))); }
|
||||
expression(A) ::= function_name(B) NK_LP NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNodeNoParam(pCxt, &B)); }
|
||||
expression(A) ::= CAST(B) NK_LP expression(C) AS type_name(D) NK_RP(E). { A = createRawExprNodeExt(pCxt, &B, &E, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, C), D)); }
|
||||
expression(A) ::= function_expression(B). { A = B; }
|
||||
//expression(A) ::= case_expression(B). { A = B; }
|
||||
expression(A) ::= subquery(B). { A = B; }
|
||||
expression(A) ::= NK_LP(B) expression(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, releaseRawExprNode(pCxt, C)); }
|
||||
|
@ -575,6 +579,10 @@ expression(A) ::= expression(B) NK_REM expression(C).
|
|||
SToken e = getTokenFromRawExprNode(pCxt, C);
|
||||
A = createRawExprNodeExt(pCxt, &s, &e, createOperatorNode(pCxt, OP_TYPE_MOD, releaseRawExprNode(pCxt, B), releaseRawExprNode(pCxt, C)));
|
||||
}
|
||||
expression(A) ::= column_reference(B) NK_ARROW NK_STRING(C). {
|
||||
SToken s = getTokenFromRawExprNode(pCxt, B);
|
||||
A = createRawExprNodeExt(pCxt, &s, &C, createOperatorNode(pCxt, OP_TYPE_JSON_GET_VALUE, releaseRawExprNode(pCxt, B), createValueNode(pCxt, TSDB_DATA_TYPE_BINARY, &C)));
|
||||
}
|
||||
|
||||
%type expression_list { SNodeList* }
|
||||
%destructor expression_list { nodesDestroyList($$); }
|
||||
|
@ -584,15 +592,44 @@ expression_list(A) ::= expression_list(B) NK_COMMA expression(C).
|
|||
column_reference(A) ::= column_name(B). { A = createRawExprNode(pCxt, &B, createColumnNode(pCxt, NULL, &B)); }
|
||||
column_reference(A) ::= table_name(B) NK_DOT column_name(C). { A = createRawExprNodeExt(pCxt, &B, &C, createColumnNode(pCxt, &B, &C)); }
|
||||
|
||||
//pseudo_column(A) ::= NOW(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
//pseudo_column(A) ::= TODAY(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= ROWTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= TBNAME(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= QSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= QENDTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WENDTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WDURATION(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= ROWTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= TBNAME(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= QSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= QENDTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WSTARTTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WENDTS(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
pseudo_column(A) ::= WDURATION(B). { A = createRawExprNode(pCxt, &B, createFunctionNode(pCxt, &B, NULL)); }
|
||||
|
||||
function_expression(A) ::= function_name(B) NK_LP expression_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
|
||||
function_expression(A) ::= star_func(B) NK_LP star_func_para_list(C) NK_RP(D). { A = createRawExprNodeExt(pCxt, &B, &D, createFunctionNode(pCxt, &B, C)); }
|
||||
function_expression(A) ::= CAST(B) NK_LP expression(C) AS type_name(D) NK_RP(E). { A = createRawExprNodeExt(pCxt, &B, &E, createCastFunctionNode(pCxt, releaseRawExprNode(pCxt, C), D)); }
|
||||
function_expression(A) ::= noarg_func(B) NK_LP NK_RP(C). { A = createRawExprNodeExt(pCxt, &B, &C, createFunctionNodeNoArg(pCxt, &B)); }
|
||||
|
||||
%type noarg_func { SToken }
|
||||
%destructor noarg_func { }
|
||||
noarg_func(A) ::= NOW(B). { A = B; }
|
||||
noarg_func(A) ::= TODAY(B). { A = B; }
|
||||
noarg_func(A) ::= TIMEZONE(B). { A = B; }
|
||||
|
||||
%type star_func { SToken }
|
||||
%destructor star_func { }
|
||||
star_func(A) ::= COUNT(B). { A = B; }
|
||||
star_func(A) ::= FIRST(B). { A = B; }
|
||||
star_func(A) ::= LAST(B). { A = B; }
|
||||
star_func(A) ::= LAST_ROW(B). { A = B; }
|
||||
|
||||
%type star_func_para_list { SNodeList* }
|
||||
%destructor star_func_para_list { nodesDestroyList($$); }
|
||||
star_func_para_list(A) ::= NK_STAR(B). { A = createNodeList(pCxt, createColumnNode(pCxt, NULL, &B)); }
|
||||
star_func_para_list(A) ::= other_para_list(B). { A = B; }
|
||||
|
||||
%type other_para_list { SNodeList* }
|
||||
%destructor other_para_list { nodesDestroyList($$); }
|
||||
other_para_list(A) ::= star_func_para(B). { A = createNodeList(pCxt, B); }
|
||||
other_para_list(A) ::= other_para_list(B) NK_COMMA star_func_para(C). { A = addNodeToList(pCxt, B, C); }
|
||||
|
||||
star_func_para(A) ::= expression(B). { A = releaseRawExprNode(pCxt, B); }
|
||||
star_func_para(A) ::= table_name(B) NK_DOT NK_STAR(C). { A = createColumnNode(pCxt, &B, &C); }
|
||||
|
||||
/************************************************ predicate ***********************************************************/
|
||||
predicate(A) ::= expression(B) compare_op(C) expression(D). {
|
||||
|
@ -637,6 +674,7 @@ compare_op(A) ::= LIKE.
|
|||
compare_op(A) ::= NOT LIKE. { A = OP_TYPE_NOT_LIKE; }
|
||||
compare_op(A) ::= MATCH. { A = OP_TYPE_MATCH; }
|
||||
compare_op(A) ::= NMATCH. { A = OP_TYPE_NMATCH; }
|
||||
compare_op(A) ::= CONTAINS. { A = OP_TYPE_JSON_CONTAINS; }
|
||||
|
||||
%type in_op { EOperatorType }
|
||||
%destructor in_op { }
|
||||
|
|
|
@ -260,7 +260,8 @@ SNode* createValueNode(SAstCreateContext* pCxt, int32_t dataType, const SToken*
|
|||
CHECK_OUT_OF_MEM(val);
|
||||
if (NULL != pLiteral) {
|
||||
val->literal = strndup(pLiteral->z, pLiteral->n);
|
||||
if (TK_NK_ID != pLiteral->type && (IS_VAR_DATA_TYPE(dataType) || TSDB_DATA_TYPE_TIMESTAMP == dataType)) {
|
||||
if (TK_NK_ID != pLiteral->type && TK_TIMEZONE != pLiteral->type &&
|
||||
(IS_VAR_DATA_TYPE(dataType) || TSDB_DATA_TYPE_TIMESTAMP == dataType)) {
|
||||
trimString(pLiteral->z, pLiteral->n, val->literal, pLiteral->n);
|
||||
}
|
||||
CHECK_OUT_OF_MEM(val->literal);
|
||||
|
@ -305,6 +306,13 @@ SNode* createDefaultDatabaseCondValue(SAstCreateContext* pCxt) {
|
|||
return (SNode*)val;
|
||||
}
|
||||
|
||||
SNode* createPlaceholderValueNode(SAstCreateContext* pCxt) {
|
||||
SValueNode* val = (SValueNode*)nodesMakeNode(QUERY_NODE_VALUE);
|
||||
CHECK_OUT_OF_MEM(val);
|
||||
// todo
|
||||
return (SNode*)val;
|
||||
}
|
||||
|
||||
SNode* createLogicConditionNode(SAstCreateContext* pCxt, ELogicConditionType type, SNode* pParam1, SNode* pParam2) {
|
||||
SLogicConditionNode* cond = (SLogicConditionNode*)nodesMakeNode(QUERY_NODE_LOGIC_CONDITION);
|
||||
CHECK_OUT_OF_MEM(cond);
|
||||
|
@ -360,7 +368,7 @@ SNode* createFunctionNode(SAstCreateContext* pCxt, const SToken* pFuncName, SNod
|
|||
return (SNode*)func;
|
||||
}
|
||||
|
||||
SNode* createFunctionNodeNoParam(SAstCreateContext* pCxt, const SToken* pFuncName) {
|
||||
SNode* createFunctionNodeNoArg(SAstCreateContext* pCxt, const SToken* pFuncName) {
|
||||
SFunctionNode* func = (SFunctionNode*)nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||
CHECK_OUT_OF_MEM(func);
|
||||
char buf[64] = {0};
|
||||
|
@ -379,11 +387,11 @@ SNode* createFunctionNodeNoParam(SAstCreateContext* pCxt, const SToken* pFuncNam
|
|||
dataType = TSDB_DATA_TYPE_BIGINT;
|
||||
break;
|
||||
}
|
||||
//case TK_TIMEZONE: {
|
||||
// strncpy(buf, tsTimezoneStr, strlen(tsTimezoneStr));
|
||||
// dataType = TSDB_DATA_TYPE_BINARY;
|
||||
// break;
|
||||
//}
|
||||
case TK_TIMEZONE: {
|
||||
strncpy(buf, tsTimezoneStr, strlen(tsTimezoneStr));
|
||||
dataType = TSDB_DATA_TYPE_BINARY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
SToken token = {.type = pFuncName->type, .n = strlen(buf), .z = buf};
|
||||
|
||||
|
@ -492,8 +500,8 @@ SNode* createOrderByExprNode(SAstCreateContext* pCxt, SNode* pExpr, EOrder order
|
|||
SNode* createSessionWindowNode(SAstCreateContext* pCxt, SNode* pCol, SNode* pGap) {
|
||||
SSessionWindowNode* session = (SSessionWindowNode*)nodesMakeNode(QUERY_NODE_SESSION_WINDOW);
|
||||
CHECK_OUT_OF_MEM(session);
|
||||
session->pCol = pCol;
|
||||
session->pGap = pGap;
|
||||
session->pCol = (SColumnNode*)pCol;
|
||||
session->pGap = (SValueNode*)pGap;
|
||||
return (SNode*)session;
|
||||
}
|
||||
|
||||
|
@ -944,6 +952,18 @@ SNode* createShowStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pDbName, S
|
|||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createShowCreateDatabaseStmt(SAstCreateContext* pCxt, const SToken* pDbName) {
|
||||
SNode* pStmt = nodesMakeNode(QUERY_NODE_SHOW_CREATE_DATABASE_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* createShowCreateTableStmt(SAstCreateContext* pCxt, ENodeType type, SNode* pRealTable) {
|
||||
SNode* pStmt = nodesMakeNode(type);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* createCreateUserStmt(SAstCreateContext* pCxt, SToken* pUserName, const SToken* pPassword) {
|
||||
char password[TSDB_USET_PASSWORD_LEN] = {0};
|
||||
if (!checkUserName(pCxt, pUserName) || !checkPassword(pCxt, pPassword, password)) {
|
||||
|
@ -1175,16 +1195,34 @@ SNode* createDropFunctionStmt(SAstCreateContext* pCxt, const SToken* pFuncName)
|
|||
return pStmt;
|
||||
}
|
||||
|
||||
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, const SToken* pStreamName, const SToken* pTableName, SNode* pQuery) {
|
||||
SNode* pStmt = nodesMakeNode(QUERY_NODE_CREATE_STREAM_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
return pStmt;
|
||||
SNode* createStreamOptions(SAstCreateContext* pCxt) {
|
||||
SStreamOptions* pOptions = nodesMakeNode(QUERY_NODE_STREAM_OPTIONS);
|
||||
CHECK_OUT_OF_MEM(pOptions);
|
||||
pOptions->triggerType = STREAM_TRIGGER_AT_ONCE;
|
||||
return (SNode*)pOptions;
|
||||
}
|
||||
|
||||
SNode* createDropStreamStmt(SAstCreateContext* pCxt, const SToken* pStreamName) {
|
||||
SNode* pStmt = nodesMakeNode(QUERY_NODE_DROP_STREAM_STMT);
|
||||
SNode* createCreateStreamStmt(SAstCreateContext* pCxt, bool ignoreExists, const SToken* pStreamName, SNode* pRealTable, SNode* pOptions, SNode* pQuery) {
|
||||
SCreateStreamStmt* pStmt = nodesMakeNode(QUERY_NODE_CREATE_STREAM_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
return pStmt;
|
||||
strncpy(pStmt->streamName, pStreamName->z, pStreamName->n);
|
||||
if (NULL != pRealTable) {
|
||||
strcpy(pStmt->targetDbName, ((SRealTableNode*)pRealTable)->table.dbName);
|
||||
strcpy(pStmt->targetTabName, ((SRealTableNode*)pRealTable)->table.tableName);
|
||||
nodesDestroyNode(pRealTable);
|
||||
}
|
||||
pStmt->ignoreExists = ignoreExists;
|
||||
pStmt->pOptions = (SStreamOptions*)pOptions;
|
||||
pStmt->pQuery = pQuery;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createDropStreamStmt(SAstCreateContext* pCxt, bool ignoreNotExists, const SToken* pStreamName) {
|
||||
SDropStreamStmt* pStmt = nodesMakeNode(QUERY_NODE_DROP_STREAM_STMT);
|
||||
CHECK_OUT_OF_MEM(pStmt);
|
||||
strncpy(pStmt->streamName, pStreamName->z, pStreamName->n);
|
||||
pStmt->ignoreNotExists = ignoreNotExists;
|
||||
return (SNode*)pStmt;
|
||||
}
|
||||
|
||||
SNode* createKillStmt(SAstCreateContext* pCxt, ENodeType type, const SToken* pId) {
|
||||
|
|
|
@ -39,6 +39,7 @@ static SKeyword keywordTable[] = {
|
|||
{"APPS", TK_APPS},
|
||||
{"AS", TK_AS},
|
||||
{"ASC", TK_ASC},
|
||||
{"AT_ONCE", TK_AT_ONCE},
|
||||
{"BETWEEN", TK_BETWEEN},
|
||||
{"BINARY", TK_BINARY},
|
||||
{"BIGINT", TK_BIGINT},
|
||||
|
@ -50,6 +51,7 @@ static SKeyword keywordTable[] = {
|
|||
{"BY", TK_BY},
|
||||
{"CACHE", TK_CACHE},
|
||||
{"CACHELAST", TK_CACHELAST},
|
||||
{"CAST", TK_CAST},
|
||||
{"COLUMN", TK_COLUMN},
|
||||
{"COMMENT", TK_COMMENT},
|
||||
{"COMP", TK_COMP},
|
||||
|
@ -57,6 +59,7 @@ static SKeyword keywordTable[] = {
|
|||
{"CONNS", TK_CONNS},
|
||||
{"CONNECTION", TK_CONNECTION},
|
||||
{"CONNECTIONS", TK_CONNECTIONS},
|
||||
{"COUNT", TK_COUNT},
|
||||
{"CREATE", TK_CREATE},
|
||||
{"DATABASE", TK_DATABASE},
|
||||
{"DATABASES", TK_DATABASES},
|
||||
|
@ -100,6 +103,7 @@ static SKeyword keywordTable[] = {
|
|||
{"KEEP", TK_KEEP},
|
||||
{"KILL", TK_KILL},
|
||||
{"LAST", TK_LAST},
|
||||
{"LAST_ROW", TK_LAST_ROW},
|
||||
{"LICENCE", TK_LICENCE},
|
||||
{"LIKE", TK_LIKE},
|
||||
{"LIMIT", TK_LIMIT},
|
||||
|
@ -132,10 +136,8 @@ static SKeyword keywordTable[] = {
|
|||
{"PRECISION", TK_PRECISION},
|
||||
{"PRIVILEGE", TK_PRIVILEGE},
|
||||
{"PREV", TK_PREV},
|
||||
{"_QENDTS", TK_QENDTS},
|
||||
{"QNODE", TK_QNODE},
|
||||
{"QNODES", TK_QNODES},
|
||||
{"_QSTARTTS", TK_QSTARTTS},
|
||||
{"QTIME", TK_QTIME},
|
||||
{"QUERIES", TK_QUERIES},
|
||||
{"QUERY", TK_QUERY},
|
||||
|
@ -145,7 +147,6 @@ static SKeyword keywordTable[] = {
|
|||
{"RESET", TK_RESET},
|
||||
{"RETENTIONS", TK_RETENTIONS},
|
||||
{"ROLLUP", TK_ROLLUP},
|
||||
{"_ROWTS", TK_ROWTS},
|
||||
{"SCORES", TK_SCORES},
|
||||
{"SELECT", TK_SELECT},
|
||||
{"SESSION", TK_SESSION},
|
||||
|
@ -174,10 +175,12 @@ static SKeyword keywordTable[] = {
|
|||
{"TAGS", TK_TAGS},
|
||||
{"TBNAME", TK_TBNAME},
|
||||
{"TIMESTAMP", TK_TIMESTAMP},
|
||||
{"TIMEZONE", TK_TIMEZONE},
|
||||
{"TINYINT", TK_TINYINT},
|
||||
{"TODAY", TK_TODAY},
|
||||
{"TOPIC", TK_TOPIC},
|
||||
{"TOPICS", TK_TOPICS},
|
||||
{"TRIGGER", TK_TRIGGER},
|
||||
{"TSERIES", TK_TSERIES},
|
||||
{"TTL", TK_TTL},
|
||||
{"UNION", TK_UNION},
|
||||
|
@ -194,9 +197,14 @@ static SKeyword keywordTable[] = {
|
|||
{"VGROUPS", TK_VGROUPS},
|
||||
{"VNODES", TK_VNODES},
|
||||
{"WAL", TK_WAL},
|
||||
{"WATERMARK", TK_WATERMARK},
|
||||
{"WHERE", TK_WHERE},
|
||||
{"WINDOW_CLOSE", TK_WINDOW_CLOSE},
|
||||
{"_QENDTS", TK_QENDTS},
|
||||
{"_QSTARTTS", TK_QSTARTTS},
|
||||
{"_ROWTS", TK_ROWTS},
|
||||
{"_WDURATION", TK_WDURATION},
|
||||
{"_WENDTS", TK_WENDTS},
|
||||
{"WHERE", TK_WHERE},
|
||||
{"_WSTARTTS", TK_WSTARTTS},
|
||||
// {"ID", TK_ID},
|
||||
// {"STRING", TK_STRING},
|
||||
|
@ -260,7 +268,6 @@ static SKeyword keywordTable[] = {
|
|||
// {"RESTRICT", TK_RESTRICT},
|
||||
// {"ROW", TK_ROW},
|
||||
// {"STATEMENT", TK_STATEMENT},
|
||||
// {"TRIGGER", TK_TRIGGER},
|
||||
// {"VIEW", TK_VIEW},
|
||||
// {"SEMI", TK_SEMI},
|
||||
// {"PARTITIONS", TK_PARTITIONS},
|
||||
|
@ -345,6 +352,9 @@ uint32_t tGetToken(const char* z, uint32_t* tokenId) {
|
|||
}
|
||||
*tokenId = TK_NK_COMMENT;
|
||||
return i;
|
||||
} else if (z[1] == '>') {
|
||||
*tokenId = TK_NK_ARROW;
|
||||
return 2;
|
||||
}
|
||||
*tokenId = TK_NK_MINUS;
|
||||
return 1;
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "cmdnodes.h"
|
||||
#include "functionMgt.h"
|
||||
#include "parUtil.h"
|
||||
#include "tglobal.h"
|
||||
#include "ttime.h"
|
||||
|
||||
#define GET_OPTION_VAL(pVal, defaultVal) (NULL == (pVal) ? (defaultVal) : getBigintFromValueNode((SValueNode*)(pVal)))
|
||||
|
@ -227,6 +228,7 @@ static void setColumnInfoBySchema(const SRealTableNode* pTable, const SSchema* p
|
|||
strcpy(pCol->node.aliasName, pColSchema->name);
|
||||
}
|
||||
pCol->tableId = pTable->pMeta->uid;
|
||||
pCol->tableType = pTable->pMeta->tableType;
|
||||
pCol->colId = pColSchema->colId;
|
||||
pCol->colType = isTag ? COLUMN_TYPE_TAG : COLUMN_TYPE_COLUMN;
|
||||
pCol->node.resType.type = pColSchema->type;
|
||||
|
@ -364,18 +366,38 @@ static bool translateColumnUseAlias(STranslateContext* pCxt, SColumnNode* pCol)
|
|||
}
|
||||
|
||||
static EDealRes translateColumn(STranslateContext* pCxt, SColumnNode* pCol) {
|
||||
// count(*)/first(*)/last(*)
|
||||
// count(*)/first(*)/last(*) and so on
|
||||
if (0 == strcmp(pCol->colName, "*")) {
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
EDealRes res = DEAL_RES_CONTINUE;
|
||||
if ('\0' != pCol->tableAlias[0]) {
|
||||
return translateColumnWithPrefix(pCxt, pCol);
|
||||
res = translateColumnWithPrefix(pCxt, pCol);
|
||||
} else {
|
||||
bool found = false;
|
||||
if (SQL_CLAUSE_ORDER_BY == pCxt->currClause) {
|
||||
found = translateColumnUseAlias(pCxt, pCol);
|
||||
}
|
||||
res = (found ? DEAL_RES_CONTINUE : translateColumnWithoutPrefix(pCxt, pCol));
|
||||
}
|
||||
bool found = false;
|
||||
if (SQL_CLAUSE_ORDER_BY == pCxt->currClause) {
|
||||
found = translateColumnUseAlias(pCxt, pCol);
|
||||
|
||||
if (DEAL_RES_ERROR == res) {
|
||||
return res;
|
||||
}
|
||||
return found ? DEAL_RES_CONTINUE : translateColumnWithoutPrefix(pCxt, pCol);
|
||||
|
||||
if (SQL_CLAUSE_WINDOW == pCxt->currClause && QUERY_NODE_STATE_WINDOW == nodeType(pCxt->pCurrStmt->pWindow)) {
|
||||
if (!IS_INTEGER_TYPE(pCol->node.resType.type)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE);
|
||||
}
|
||||
if (COLUMN_TYPE_TAG == pCol->colType) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_COL);
|
||||
}
|
||||
if (TSDB_SUPER_TABLE == pCol->tableType) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_STATE_WIN_TABLE);
|
||||
}
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static EDealRes translateValue(STranslateContext* pCxt, SValueNode* pVal) {
|
||||
|
@ -466,8 +488,18 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
|
|||
TSDB_DATA_TYPE_BLOB == rdt.type) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName);
|
||||
}
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
if (TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_TIMESTAMP == rdt.type) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_WRONG_VALUE_TYPE, ((SExprNode*)(pOp->pRight))->aliasName);
|
||||
}
|
||||
|
||||
if ((TSDB_DATA_TYPE_TIMESTAMP == ldt.type && TSDB_DATA_TYPE_BIGINT == rdt.type) ||
|
||||
(TSDB_DATA_TYPE_TIMESTAMP == rdt.type && TSDB_DATA_TYPE_BIGINT == ldt.type)) {
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_TIMESTAMP;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_TIMESTAMP].bytes;
|
||||
} else {
|
||||
pOp->node.resType.type = TSDB_DATA_TYPE_DOUBLE;
|
||||
pOp->node.resType.bytes = tDataTypes[TSDB_DATA_TYPE_DOUBLE].bytes;
|
||||
}
|
||||
} else if (nodesIsComparisonOp(pOp)) {
|
||||
if (TSDB_DATA_TYPE_JSON == ldt.type || TSDB_DATA_TYPE_BLOB == ldt.type || TSDB_DATA_TYPE_JSON == rdt.type ||
|
||||
TSDB_DATA_TYPE_BLOB == rdt.type) {
|
||||
|
@ -481,6 +513,14 @@ static EDealRes translateOperator(STranslateContext* pCxt, SOperatorNode* pOp) {
|
|||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static EDealRes haveAggFunction(SNode* pNode, void* pContext) {
|
||||
if (QUERY_NODE_FUNCTION == nodeType(pNode) && fmIsAggFunc(((SFunctionNode*)pNode)->funcId)) {
|
||||
*((bool*)pContext) = true;
|
||||
return DEAL_RES_END;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc) {
|
||||
if (TSDB_CODE_SUCCESS != fmGetFuncInfo(pFunc->functionName, &pFunc->funcId, &pFunc->funcType)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_INVALID_FUNTION, pFunc->functionName);
|
||||
|
@ -492,6 +532,11 @@ static EDealRes translateFunction(STranslateContext* pCxt, SFunctionNode* pFunc)
|
|||
if (fmIsAggFunc(pFunc->funcId) && beforeHaving(pCxt->currClause)) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_ILLEGAL_USE_AGG_FUNCTION);
|
||||
}
|
||||
bool haveAggFunc = false;
|
||||
nodesWalkExprs(pFunc->pParameterList, haveAggFunction, &haveAggFunc);
|
||||
if (haveAggFunc) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_AGG_FUNC_NESTING);
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
|
@ -626,7 +671,7 @@ static int32_t checkAggColCoexist(STranslateContext* pCxt, SSelectStmt* pSelect)
|
|||
if (!pSelect->isDistinct) {
|
||||
nodesWalkExprs(pSelect->pOrderByList, doCheckAggColCoexist, &cxt);
|
||||
}
|
||||
if (cxt.existAggFunc && cxt.existCol) {
|
||||
if ((cxt.existAggFunc || NULL != pSelect->pWindow) && cxt.existCol) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_NOT_SINGLE_GROUP);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
@ -770,92 +815,165 @@ static int32_t createAllColumns(STranslateContext* pCxt, SNodeList** pCols) {
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool isFirstLastFunc(SFunctionNode* pFunc) {
|
||||
return (FUNCTION_TYPE_FIRST == pFunc->funcType || FUNCTION_TYPE_LAST == pFunc->funcType);
|
||||
}
|
||||
|
||||
static bool isFirstLastStar(SNode* pNode) {
|
||||
if (QUERY_NODE_FUNCTION != nodeType(pNode) || !isFirstLastFunc((SFunctionNode*)pNode)) {
|
||||
static bool isMultiResFunc(SNode* pNode) {
|
||||
if (QUERY_NODE_FUNCTION != nodeType(pNode) || !fmIsMultiResFunc(((SFunctionNode*)pNode)->funcId)) {
|
||||
return false;
|
||||
}
|
||||
SNodeList* pParameterList = ((SFunctionNode*)pNode)->pParameterList;
|
||||
if (LIST_LENGTH(pParameterList) != 1) {
|
||||
return false;
|
||||
if (LIST_LENGTH(pParameterList) > 1) {
|
||||
return true;
|
||||
}
|
||||
SNode* pParam = nodesListGetNode(pParameterList, 0);
|
||||
return (QUERY_NODE_COLUMN == nodeType(pParam) ? 0 == strcmp(((SColumnNode*)pParam)->colName, "*") : false);
|
||||
}
|
||||
|
||||
static SNode* createFirstLastFunc(SFunctionNode* pSrcFunc, SColumnNode* pCol) {
|
||||
static SNode* createMultiResFunc(SFunctionNode* pSrcFunc, SExprNode* pExpr) {
|
||||
SFunctionNode* pFunc = nodesMakeNode(QUERY_NODE_FUNCTION);
|
||||
if (NULL == pFunc) {
|
||||
return NULL;
|
||||
}
|
||||
pFunc->pParameterList = nodesMakeList();
|
||||
if (NULL == pFunc->pParameterList || TSDB_CODE_SUCCESS != nodesListAppend(pFunc->pParameterList, pCol)) {
|
||||
if (NULL == pFunc->pParameterList || TSDB_CODE_SUCCESS != nodesListStrictAppend(pFunc->pParameterList, nodesCloneNode(pExpr))) {
|
||||
nodesDestroyNode(pFunc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
pFunc->node.resType = pCol->node.resType;
|
||||
pFunc->node.resType = pExpr->resType;
|
||||
pFunc->funcId = pSrcFunc->funcId;
|
||||
pFunc->funcType = pSrcFunc->funcType;
|
||||
strcpy(pFunc->functionName, pSrcFunc->functionName);
|
||||
snprintf(pFunc->node.aliasName, sizeof(pFunc->node.aliasName),
|
||||
(FUNCTION_TYPE_FIRST == pSrcFunc->funcType ? "first(%s)" : "last(%s)"), pCol->colName);
|
||||
char buf[TSDB_FUNC_NAME_LEN + TSDB_TABLE_NAME_LEN + TSDB_COL_NAME_LEN];
|
||||
int32_t len = 0;
|
||||
if (QUERY_NODE_COLUMN == nodeType(pExpr)) {
|
||||
SColumnNode* pCol = (SColumnNode*)pExpr;
|
||||
len = snprintf(buf, sizeof(buf), "%s(%s.%s)", pSrcFunc->functionName, pCol->tableAlias, pCol->colName);
|
||||
} else {
|
||||
len = snprintf(buf, sizeof(buf), "%s(%s)", pSrcFunc->functionName, pExpr->aliasName);
|
||||
}
|
||||
strncpy(pFunc->node.aliasName, buf, TMIN(len, sizeof(pFunc->node.aliasName) - 1));
|
||||
|
||||
return (SNode*)pFunc;
|
||||
}
|
||||
|
||||
static int32_t createFirstLastAllCols(STranslateContext* pCxt, SFunctionNode* pSrcFunc, SNodeList** pOutput) {
|
||||
SNodeList* pCols = NULL;
|
||||
if (TSDB_CODE_SUCCESS != createAllColumns(pCxt, &pCols)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
SNodeList* pFuncs = nodesMakeList();
|
||||
if (NULL == pFuncs) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
SNode* pCol = NULL;
|
||||
FOREACH(pCol, pCols) {
|
||||
if (TSDB_CODE_SUCCESS != nodesListStrictAppend(pFuncs, createFirstLastFunc(pSrcFunc, (SColumnNode*)pCol))) {
|
||||
nodesDestroyNode(pFuncs);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
*pOutput = pFuncs;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static bool isTableStar(SNode* pNode) {
|
||||
return (QUERY_NODE_COLUMN == nodeType(pNode)) && (0 == strcmp(((SColumnNode*)pNode)->colName, "*"));
|
||||
}
|
||||
|
||||
static int32_t createTableAllCols(STranslateContext* pCxt, SColumnNode* pCol, SNodeList** pOutput) {
|
||||
*pOutput = nodesMakeList();
|
||||
if (NULL == *pOutput) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
bool foundTable = false;
|
||||
static int32_t findTable(STranslateContext* pCxt, const char* pTableAlias, STableNode** pOutput) {
|
||||
SArray* pTables = taosArrayGetP(pCxt->pNsLevel, pCxt->currLevel);
|
||||
size_t nums = taosArrayGetSize(pTables);
|
||||
for (size_t i = 0; i < nums; ++i) {
|
||||
STableNode* pTable = taosArrayGetP(pTables, i);
|
||||
if (0 == strcmp(pTable->tableAlias, pCol->tableAlias)) {
|
||||
int32_t code = createColumnNodeByTable(pCxt, pTable, *pOutput);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
foundTable = true;
|
||||
if (NULL == pTableAlias || 0 == strcmp(pTable->tableAlias, pTableAlias)) {
|
||||
*pOutput = pTable;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
}
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_TABLE_NOT_EXIST, pTableAlias);
|
||||
}
|
||||
|
||||
static int32_t createTableAllCols(STranslateContext* pCxt, SColumnNode* pCol, SNodeList** pOutput) {
|
||||
STableNode* pTable = NULL;
|
||||
int32_t code = findTable(pCxt, pCol->tableAlias, &pTable);
|
||||
if (TSDB_CODE_SUCCESS == code && NULL == *pOutput) {
|
||||
*pOutput = nodesMakeList();
|
||||
if (NULL == *pOutput) {
|
||||
code = generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_OUT_OF_MEMORY);
|
||||
}
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createColumnNodeByTable(pCxt, pTable, *pOutput);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool isStar(SNode* pNode) {
|
||||
return (QUERY_NODE_COLUMN == nodeType(pNode)) && ('\0' == ((SColumnNode*)pNode)->tableAlias[0]) && (0 == strcmp(((SColumnNode*)pNode)->colName, "*"));
|
||||
}
|
||||
|
||||
static bool isTableStar(SNode* pNode) {
|
||||
return (QUERY_NODE_COLUMN == nodeType(pNode)) && ('\0' != ((SColumnNode*)pNode)->tableAlias[0]) && (0 == strcmp(((SColumnNode*)pNode)->colName, "*"));
|
||||
}
|
||||
|
||||
static int32_t createMultiResFuncsParas(STranslateContext* pCxt, SNodeList* pSrcParas, SNodeList** pOutput) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
||||
SNodeList* pExprs = NULL;
|
||||
SNode* pPara = NULL;
|
||||
FOREACH(pPara, pSrcParas) {
|
||||
if (isStar(pPara)) {
|
||||
code = createAllColumns(pCxt, &pExprs);
|
||||
// The syntax definition ensures that * and other parameters do not appear at the same time
|
||||
break;
|
||||
} else if (isTableStar(pPara)) {
|
||||
code = createTableAllCols(pCxt, (SColumnNode*)pPara, &pExprs);
|
||||
} else {
|
||||
code = nodesListMakeStrictAppend(&pExprs, nodesCloneNode(pPara));
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!foundTable) {
|
||||
return generateDealNodeErrMsg(pCxt, TSDB_CODE_PAR_TABLE_NOT_EXIST, pCol->tableAlias);
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pOutput = pExprs;
|
||||
} else {
|
||||
nodesDestroyList(pExprs);
|
||||
}
|
||||
return TSDB_CODE_SUCCESS;
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t createMultiResFuncs(SFunctionNode* pSrcFunc, SNodeList* pExprs, SNodeList** pOutput) {
|
||||
SNodeList* pFuncs = nodesMakeList();
|
||||
if (NULL == pFuncs) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
SNode* pExpr = NULL;
|
||||
FOREACH(pExpr, pExprs) {
|
||||
code = nodesListStrictAppend(pFuncs, createMultiResFunc(pSrcFunc, (SExprNode*)pExpr));
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pOutput = pFuncs;
|
||||
} else {
|
||||
nodesDestroyList(pFuncs);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t createMultiResFuncsFromStar(STranslateContext* pCxt, SFunctionNode* pSrcFunc, SNodeList** pOutput) {
|
||||
SNodeList* pExprs = NULL;
|
||||
int32_t code = createMultiResFuncsParas(pCxt, pSrcFunc->pParameterList, &pExprs);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = createMultiResFuncs(pSrcFunc, pExprs, pOutput);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
nodesDestroyList(pExprs);
|
||||
}
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
static bool isCountStar(SNode* pNode) {
|
||||
if (QUERY_NODE_FUNCTION != nodeType(pNode) || 1 != LIST_LENGTH(((SFunctionNode*)pNode)->pParameterList)) {
|
||||
return false;
|
||||
}
|
||||
SNode* pPara = nodesListGetNode(((SFunctionNode*)pNode)->pParameterList, 0);
|
||||
return (QUERY_NODE_COLUMN == nodeType(pPara) && 0 == strcmp(((SColumnNode*)pPara)->colName, "*"));
|
||||
}
|
||||
|
||||
static int32_t rewriteCountStar(STranslateContext* pCxt, SFunctionNode* pCount) {
|
||||
SColumnNode* pCol = nodesListGetNode(pCount->pParameterList, 0);
|
||||
STableNode* pTable = NULL;
|
||||
int32_t code = findTable(pCxt, ('\0' == pCol->tableAlias[0] ? NULL : pCol->tableAlias), &pTable);
|
||||
if (TSDB_CODE_SUCCESS == code && QUERY_NODE_REAL_TABLE == nodeType(pTable)) {
|
||||
setColumnInfoBySchema((SRealTableNode*)pTable, ((SRealTableNode*)pTable)->pMeta->schema, false, pCol);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
||||
|
@ -864,9 +982,9 @@ static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
|||
} else {
|
||||
SNode* pNode = NULL;
|
||||
WHERE_EACH(pNode, pSelect->pProjectionList) {
|
||||
if (isFirstLastStar(pNode)) {
|
||||
if (isMultiResFunc(pNode)) {
|
||||
SNodeList* pFuncs = NULL;
|
||||
if (TSDB_CODE_SUCCESS != createFirstLastAllCols(pCxt, (SFunctionNode*)pNode, &pFuncs)) {
|
||||
if (TSDB_CODE_SUCCESS != createMultiResFuncsFromStar(pCxt, (SFunctionNode*)pNode, &pFuncs)) {
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
INSERT_LIST(pSelect->pProjectionList, pFuncs);
|
||||
|
@ -880,6 +998,11 @@ static int32_t translateStar(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
|||
INSERT_LIST(pSelect->pProjectionList, pCols);
|
||||
ERASE_NODE(pSelect->pProjectionList);
|
||||
continue;
|
||||
} else if (isCountStar(pNode)) {
|
||||
int32_t code = rewriteCountStar(pCxt, (SFunctionNode*)pNode);
|
||||
if (TSDB_CODE_SUCCESS != code) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
WHERE_NEXT;
|
||||
}
|
||||
|
@ -1000,20 +1123,100 @@ static int32_t translateGroupBy(STranslateContext* pCxt, SSelectStmt* pSelect) {
|
|||
return translateExprList(pCxt, pSelect->pGroupByList);
|
||||
}
|
||||
|
||||
static int32_t translateIntervalWindow(STranslateContext* pCxt, SIntervalWindowNode* pInterval) {
|
||||
SValueNode* pIntervalVal = (SValueNode*)pInterval->pInterval;
|
||||
SValueNode* pIntervalOffset = (SValueNode*)pInterval->pOffset;
|
||||
SValueNode* pSliding = (SValueNode*)pInterval->pSliding;
|
||||
if (pIntervalVal->datum.i <= 0) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTERVAL_VALUE_TOO_SMALL, pIntervalVal->literal);
|
||||
static bool isValTimeUnit(char unit) {
|
||||
return ('n' == unit || 'y' == unit);
|
||||
}
|
||||
|
||||
static int64_t getMonthsFromTimeVal(int64_t val, int32_t fromPrecision, char unit) {
|
||||
int64_t days = convertTimeFromPrecisionToUnit(val, fromPrecision, 'd');
|
||||
switch (unit) {
|
||||
case 'b':
|
||||
case 'u':
|
||||
case 'a':
|
||||
case 's':
|
||||
case 'm':
|
||||
case 'h':
|
||||
case 'd':
|
||||
case 'w':
|
||||
return days / 28;
|
||||
case 'n':
|
||||
return val;
|
||||
case 'y':
|
||||
return val * 12;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int32_t checkIntervalWindow(STranslateContext* pCxt, SIntervalWindowNode* pInterval) {
|
||||
uint8_t precision = ((SColumnNode*)pInterval->pCol)->node.resType.precision;
|
||||
|
||||
SValueNode* pInter = (SValueNode*)pInterval->pInterval;
|
||||
bool valInter = isValTimeUnit(pInter->unit);
|
||||
if (pInter->datum.i <= 0 ||
|
||||
(!valInter && convertTimePrecision(pInter->datum.i, precision, TSDB_TIME_PRECISION_MICRO) < tsMinIntervalTime)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_VALUE_TOO_SMALL, tsMinIntervalTime);
|
||||
}
|
||||
|
||||
if (NULL != pInterval->pOffset) {
|
||||
SValueNode* pOffset = (SValueNode*)pInterval->pOffset;
|
||||
if (pOffset->datum.i <= 0) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_OFFSET_NEGATIVE);
|
||||
}
|
||||
if (pInter->unit == 'n' && pOffset->unit == 'y') {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_OFFSET_UNIT);
|
||||
}
|
||||
bool fixed = !isValTimeUnit(pOffset->unit) && !valInter;
|
||||
if ((fixed && pOffset->datum.i >= pInter->datum.i) ||
|
||||
(!fixed && getMonthsFromTimeVal(pOffset->datum.i, precision, pOffset->unit) >= getMonthsFromTimeVal(pInter->datum.i, precision, pInter->unit))) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_OFFSET_TOO_BIG);
|
||||
}
|
||||
}
|
||||
|
||||
if (NULL != pInterval->pSliding) {
|
||||
const static int32_t INTERVAL_SLIDING_FACTOR = 100;
|
||||
|
||||
SValueNode* pSliding = (SValueNode*)pInterval->pSliding;
|
||||
if (pInter->unit == 'n' || pInter->unit == 'y') {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_SLIDING_UNIT);
|
||||
}
|
||||
if ((pSliding->datum.i < convertTimePrecision(tsMinSlidingTime, TSDB_TIME_PRECISION_MILLI, precision)) ||
|
||||
(pInter->datum.i / pSliding->datum.i > INTERVAL_SLIDING_FACTOR)) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_SLIDING_TOO_SMALL);
|
||||
}
|
||||
if (pSliding->datum.i > pInter->datum.i) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_SLIDING_TOO_BIG);
|
||||
}
|
||||
}
|
||||
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t doTranslateWindow(STranslateContext* pCxt, SNode* pWindow) {
|
||||
static int32_t checkStateWindow(STranslateContext* pCxt, SStateWindowNode* pState) {
|
||||
// todo check for "function not support for state_window"
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t checkSessionWindow(STranslateContext* pCxt, SSessionWindowNode* pSession) {
|
||||
if ('y' == pSession->pGap->unit || 'n' == pSession->pGap->unit || 0 == pSession->pGap->datum.i) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_SESSION_GAP);
|
||||
}
|
||||
if (PRIMARYKEY_TIMESTAMP_COL_ID != pSession->pCol->colId) {
|
||||
return generateSyntaxErrMsg(&pCxt->msgBuf, TSDB_CODE_PAR_INTER_SESSION_COL);
|
||||
}
|
||||
// todo check for "function not support for session"
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t checkWindow(STranslateContext* pCxt, SNode* pWindow) {
|
||||
switch (nodeType(pWindow)) {
|
||||
case QUERY_NODE_STATE_WINDOW:
|
||||
return checkStateWindow(pCxt, (SStateWindowNode*)pWindow);
|
||||
case QUERY_NODE_SESSION_WINDOW:
|
||||
return checkSessionWindow(pCxt, (SSessionWindowNode*)pWindow);
|
||||
case QUERY_NODE_INTERVAL_WINDOW:
|
||||
return translateIntervalWindow(pCxt, (SIntervalWindowNode*)pWindow);
|
||||
return checkIntervalWindow(pCxt, (SIntervalWindowNode*)pWindow);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -1027,7 +1230,7 @@ static int32_t translateWindow(STranslateContext* pCxt, SNode* pWindow) {
|
|||
pCxt->currClause = SQL_CLAUSE_WINDOW;
|
||||
int32_t code = translateExpr(pCxt, pWindow);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = doTranslateWindow(pCxt, pWindow);
|
||||
code = checkWindow(pCxt, pWindow);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
@ -2067,6 +2270,54 @@ static int32_t translateKillQuery(STranslateContext* pCxt, SKillStmt* pStmt) {
|
|||
return buildCmdMsg(pCxt, TDMT_MND_KILL_QUERY, (FSerializeFunc)tSerializeSKillQueryReq, &killReq);
|
||||
}
|
||||
|
||||
static int32_t translateCreateStream(STranslateContext* pCxt, SCreateStreamStmt* pStmt) {
|
||||
SCMCreateStreamReq createReq = {0};
|
||||
|
||||
createReq.igExists = pStmt->ignoreExists;
|
||||
|
||||
SName name = {.type = TSDB_TABLE_NAME_T, .acctId = pCxt->pParseCxt->acctId};
|
||||
strcpy(name.dbname, pCxt->pParseCxt->db);
|
||||
strcpy(name.tname, pStmt->streamName);
|
||||
tNameExtractFullName(&name, createReq.name);
|
||||
|
||||
if ('\0' != pStmt->targetTabName[0]) {
|
||||
strcpy(name.dbname, pStmt->targetDbName);
|
||||
strcpy(name.tname, pStmt->targetTabName);
|
||||
tNameExtractFullName(&name, createReq.outputSTbName);
|
||||
}
|
||||
|
||||
int32_t code = translateQuery(pCxt, pStmt->pQuery);
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = nodesNodeToString(pStmt->pQuery, false, &createReq.ast, NULL);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
createReq.sql = strdup(pCxt->pParseCxt->pSql);
|
||||
if (NULL == createReq.sql) {
|
||||
code = TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code && NULL != pStmt->pOptions->pWatermark) {
|
||||
code = (DEAL_RES_ERROR == translateValue(pCxt, (SValueNode*)pStmt->pOptions->pWatermark)) ? pCxt->errCode : TSDB_CODE_SUCCESS;
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
createReq.triggerType = pStmt->pOptions->triggerType;
|
||||
createReq.watermark = (NULL != pStmt->pOptions->pWatermark ? ((SValueNode*)pStmt->pOptions->pWatermark)->datum.i : 0);
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = buildCmdMsg(pCxt, TDMT_MND_CREATE_STREAM, (FSerializeFunc)tSerializeSCMCreateStreamReq, &createReq);
|
||||
}
|
||||
|
||||
tFreeSCMCreateStreamReq(&createReq);
|
||||
return code;
|
||||
}
|
||||
|
||||
static int32_t translateDropStream(STranslateContext* pCxt, SDropStreamStmt* pStmt) {
|
||||
// todo
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
||||
int32_t code = TSDB_CODE_SUCCESS;
|
||||
|
@ -2160,6 +2411,12 @@ static int32_t translateQuery(STranslateContext* pCxt, SNode* pNode) {
|
|||
case QUERY_NODE_KILL_QUERY_STMT:
|
||||
code = translateKillQuery(pCxt, (SKillStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_CREATE_STREAM_STMT:
|
||||
code = translateCreateStream(pCxt, (SCreateStreamStmt*)pNode);
|
||||
break;
|
||||
case QUERY_NODE_DROP_STREAM_STMT:
|
||||
code = translateDropStream(pCxt, (SDropStreamStmt*)pNode);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -55,8 +55,8 @@ static char* getSyntaxErrFormat(int32_t errCode) {
|
|||
return "Endpoint should be in the format of 'fqdn:port'";
|
||||
case TSDB_CODE_PAR_EXPRIE_STATEMENT:
|
||||
return "This statement is no longer supported";
|
||||
case TSDB_CODE_PAR_INTERVAL_VALUE_TOO_SMALL:
|
||||
return "This interval value is too small : %s";
|
||||
case TSDB_CODE_PAR_INTER_VALUE_TOO_SMALL:
|
||||
return "Interval cannot be less than %d us";
|
||||
case TSDB_CODE_PAR_DB_NOT_SPECIFIED:
|
||||
return "Database not specified";
|
||||
case TSDB_CODE_PAR_INVALID_IDENTIFIER_NAME:
|
||||
|
@ -91,6 +91,30 @@ static char* getSyntaxErrFormat(int32_t errCode) {
|
|||
return "Invalid option %s unit: %c, only m, h, d allowed";
|
||||
case TSDB_CODE_PAR_INVALID_KEEP_UNIT:
|
||||
return "Invalid option keep unit: %c, %c, %c, only m, h, d allowed";
|
||||
case TSDB_CODE_PAR_AGG_FUNC_NESTING:
|
||||
return "Aggregate functions do not support nesting";
|
||||
case TSDB_CODE_PAR_INVALID_STATE_WIN_TYPE:
|
||||
return "Only support STATE_WINDOW on integer column";
|
||||
case TSDB_CODE_PAR_INVALID_STATE_WIN_COL:
|
||||
return "Not support STATE_WINDOW on tag column";
|
||||
case TSDB_CODE_PAR_INVALID_STATE_WIN_TABLE:
|
||||
return "STATE_WINDOW not support for super table query";
|
||||
case TSDB_CODE_PAR_INTER_SESSION_GAP:
|
||||
return "SESSION gap should be fixed time window, and greater than 0";
|
||||
case TSDB_CODE_PAR_INTER_SESSION_COL:
|
||||
return "Only support SESSION on primary timestamp column";
|
||||
case TSDB_CODE_PAR_INTER_OFFSET_NEGATIVE:
|
||||
return "Interval offset cannot be negative";
|
||||
case TSDB_CODE_PAR_INTER_OFFSET_UNIT:
|
||||
return "Cannot use 'year' as offset when interval is 'month'";
|
||||
case TSDB_CODE_PAR_INTER_OFFSET_TOO_BIG:
|
||||
return "Interval offset should be shorter than interval";
|
||||
case TSDB_CODE_PAR_INTER_SLIDING_UNIT:
|
||||
return "Does not support sliding when interval is natural month/year";
|
||||
case TSDB_CODE_PAR_INTER_SLIDING_TOO_BIG:
|
||||
return "sliding value no larger than the interval value";
|
||||
case TSDB_CODE_PAR_INTER_SLIDING_TOO_SMALL:
|
||||
return "sliding value can not less than 1% of interval value";
|
||||
case TSDB_CODE_OUT_OF_MEMORY:
|
||||
return "Out of memory";
|
||||
default:
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -264,7 +264,7 @@ private:
|
|||
}
|
||||
|
||||
std::string ftToString(int16_t colid, int16_t numOfColumns) const {
|
||||
return (0 == colid ? "column" : (colid <= numOfColumns ? "tag" : "column"));
|
||||
return (0 == colid ? "column" : (colid < numOfColumns ? "column" : "tag"));
|
||||
}
|
||||
|
||||
STableMeta* getTableSchemaMeta(const std::string& db, const std::string& tbname) const {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "parserTestUtil.h"
|
||||
#include "parInt.h"
|
||||
|
||||
using namespace std;
|
||||
|
@ -44,7 +45,7 @@ protected:
|
|||
query_ = nullptr;
|
||||
bool res = runImpl(parseCode, translateCode);
|
||||
qDestroyQuery(query_);
|
||||
if (1/*!res*/) {
|
||||
if (!res || g_isDump) {
|
||||
dump();
|
||||
}
|
||||
return res;
|
||||
|
@ -57,7 +58,7 @@ private:
|
|||
int32_t code = parse(&cxt_, &query_);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
parseErrStr_ = string("code:") + tstrerror(code) + string(", msg:") + errMagBuf_;
|
||||
return (terrno == parseCode);
|
||||
return (code == parseCode);
|
||||
}
|
||||
if (TSDB_CODE_SUCCESS != parseCode) {
|
||||
return false;
|
||||
|
@ -66,7 +67,7 @@ private:
|
|||
code = translate(&cxt_, query_);
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
translateErrStr_ = string("code:") + tstrerror(code) + string(", msg:") + errMagBuf_;
|
||||
return (terrno == translateCode);
|
||||
return (code == translateCode);
|
||||
}
|
||||
translatedAstStr_ = toString(query_->pRoot);
|
||||
code = calculateConstant(&cxt_, query_);
|
||||
|
@ -243,6 +244,19 @@ TEST_F(ParserTest, selectPseudoColumn) {
|
|||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(ParserTest, selectMultiResFunc) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
// bind("SELECT last(*), first(*), last_row(*) FROM t1");
|
||||
// ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT last(c1, c2), first(t1.*), last_row(c3) FROM t1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("SELECT last(t2.*), first(t1.c1, t2.*), last_row(t1.*, t2.*) FROM st1s1 t1, st1s2 t2 where t1.ts = t2.ts");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(ParserTest, selectClause) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
|
@ -726,6 +740,22 @@ TEST_F(ParserTest, dropTopic) {
|
|||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(ParserTest, createStream) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("create stream s1 as select * from t1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("create stream if not exists s1 as select * from t1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("create stream s1 into st1 as select * from t1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
bind("create stream if not exists s1 trigger window_close watermark 10s into st1 as select * from t1");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(ParserTest, explain) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
|
|
|
@ -15,12 +15,16 @@
|
|||
|
||||
#include <string>
|
||||
|
||||
#include <getopt.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "mockCatalog.h"
|
||||
#include "parserTestUtil.h"
|
||||
#include "parToken.h"
|
||||
#include "functionMgt.h"
|
||||
|
||||
bool g_isDump = false;
|
||||
|
||||
class ParserEnv : public testing::Environment {
|
||||
public:
|
||||
virtual void SetUp() {
|
||||
|
@ -38,8 +42,27 @@ public:
|
|||
virtual ~ParserEnv() {}
|
||||
};
|
||||
|
||||
static void parseArg(int argc, char* argv[]) {
|
||||
int opt = 0;
|
||||
const char *optstring = "";
|
||||
static struct option long_options[] = {
|
||||
{"dump", no_argument, NULL, 'd'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
while ((opt = getopt_long(argc, argv, optstring, long_options, NULL)) != -1) {
|
||||
switch (opt) {
|
||||
case 'd':
|
||||
g_isDump = true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
testing::AddGlobalTestEnvironment(new ParserEnv());
|
||||
testing::InitGoogleTest(&argc, argv);
|
||||
parseArg(argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
extern bool g_isDump;
|
|
@ -200,7 +200,7 @@ static int32_t createScanLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect
|
|||
strcpy(pScan->tableName.tname, pRealTable->table.tableName);
|
||||
pScan->showRewrite = pCxt->pPlanCxt->showRewrite;
|
||||
pScan->ratio = pRealTable->ratio;
|
||||
pScan->dataRequired = FUNC_DATA_REQUIRED_ALL_NEEDED;
|
||||
pScan->dataRequired = FUNC_DATA_REQUIRED_DATA_LOAD;
|
||||
|
||||
// set columns to scan
|
||||
SNodeList* pCols = NULL;
|
||||
|
@ -463,6 +463,11 @@ static int32_t createAggLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSelect,
|
|||
static int32_t createWindowLogicNodeFinalize(SLogicPlanContext* pCxt, SSelectStmt* pSelect, SWindowLogicNode* pWindow, SLogicNode** pLogicNode) {
|
||||
int32_t code = nodesCollectFuncs(pSelect, fmIsWindowClauseFunc, &pWindow->pFuncs);
|
||||
|
||||
if (pCxt->pPlanCxt->streamQuery) {
|
||||
pWindow->triggerType = pCxt->pPlanCxt->triggerType;
|
||||
pWindow->watermark = pCxt->pPlanCxt->watermark;
|
||||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
code = rewriteExpr(pWindow->pFuncs, pSelect, SQL_CLAUSE_WINDOW);
|
||||
}
|
||||
|
|
|
@ -56,6 +56,20 @@ typedef enum ECondAction {
|
|||
// after supporting outer join, there are other possibilities
|
||||
} ECondAction;
|
||||
|
||||
EDealRes haveNormalColImpl(SNode* pNode, void* pContext) {
|
||||
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
||||
*((bool*)pContext) = (COLUMN_TYPE_TAG != ((SColumnNode*)pNode)->colType);
|
||||
return *((bool*)pContext) ? DEAL_RES_END : DEAL_RES_IGNORE_CHILD;
|
||||
}
|
||||
return DEAL_RES_CONTINUE;
|
||||
}
|
||||
|
||||
static bool haveNormalCol(SNodeList* pList) {
|
||||
bool res = false;
|
||||
nodesWalkExprsPostOrder(pList, haveNormalColImpl, &res);
|
||||
return res;
|
||||
}
|
||||
|
||||
static bool osdMayBeOptimized(SLogicNode* pNode) {
|
||||
if (OPTIMIZE_FLAG_TEST_MASK(pNode->optimizedFlag, OPTIMIZE_FLAG_OSD)) {
|
||||
return false;
|
||||
|
@ -64,10 +78,13 @@ static bool osdMayBeOptimized(SLogicNode* pNode) {
|
|||
return false;
|
||||
}
|
||||
if (NULL == pNode->pParent ||
|
||||
(QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_AGG == nodeType(pNode->pParent))) {
|
||||
(QUERY_NODE_LOGIC_PLAN_WINDOW != nodeType(pNode->pParent) && QUERY_NODE_LOGIC_PLAN_AGG != nodeType(pNode->pParent))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
if (QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pNode->pParent)) {
|
||||
return (WINDOW_TYPE_INTERVAL == ((SWindowLogicNode*)pNode->pParent)->winType);
|
||||
}
|
||||
return !haveNormalCol(((SAggLogicNode*)pNode->pParent)->pGroupKeys);
|
||||
}
|
||||
|
||||
static SLogicNode* osdFindPossibleScanNode(SLogicNode* pNode) {
|
||||
|
@ -125,12 +142,12 @@ static int32_t osdMatch(SOptimizeContext* pCxt, SLogicNode* pLogicNode, SOsdInfo
|
|||
|
||||
static EFuncDataRequired osdPromoteDataRequired(EFuncDataRequired l , EFuncDataRequired r) {
|
||||
switch (l) {
|
||||
case FUNC_DATA_REQUIRED_ALL_NEEDED:
|
||||
case FUNC_DATA_REQUIRED_DATA_LOAD:
|
||||
return l;
|
||||
case FUNC_DATA_REQUIRED_STATIS_NEEDED:
|
||||
return FUNC_DATA_REQUIRED_ALL_NEEDED == r ? r : l;
|
||||
case FUNC_DATA_REQUIRED_NO_NEEDED:
|
||||
return FUNC_DATA_REQUIRED_DISCARD == r ? l : r;
|
||||
case FUNC_DATA_REQUIRED_STATIS_LOAD:
|
||||
return FUNC_DATA_REQUIRED_DATA_LOAD == r ? r : l;
|
||||
case FUNC_DATA_REQUIRED_NOT_LOAD:
|
||||
return FUNC_DATA_REQUIRED_FILTEROUT == r ? l : r;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -139,9 +156,9 @@ static EFuncDataRequired osdPromoteDataRequired(EFuncDataRequired l , EFuncDataR
|
|||
|
||||
static int32_t osdGetDataRequired(SNodeList* pFuncs) {
|
||||
if (NULL == pFuncs) {
|
||||
return FUNC_DATA_REQUIRED_ALL_NEEDED;
|
||||
return FUNC_DATA_REQUIRED_DATA_LOAD;
|
||||
}
|
||||
EFuncDataRequired dataRequired = FUNC_DATA_REQUIRED_DISCARD;
|
||||
EFuncDataRequired dataRequired = FUNC_DATA_REQUIRED_FILTEROUT;
|
||||
SNode* pFunc = NULL;
|
||||
FOREACH(pFunc, pFuncs) {
|
||||
dataRequired = osdPromoteDataRequired(dataRequired, fmFuncDataRequired((SFunctionNode*)pFunc, NULL));
|
||||
|
@ -149,12 +166,24 @@ static int32_t osdGetDataRequired(SNodeList* pFuncs) {
|
|||
return dataRequired;
|
||||
}
|
||||
|
||||
static void setScanWindowInfo(SScanLogicNode* pScan) {
|
||||
if (QUERY_NODE_LOGIC_PLAN_WINDOW == nodeType(pScan->node.pParent) &&
|
||||
WINDOW_TYPE_INTERVAL == ((SWindowLogicNode*)pScan->node.pParent)->winType) {
|
||||
pScan->interval = ((SWindowLogicNode*)pScan->node.pParent)->interval;
|
||||
pScan->offset = ((SWindowLogicNode*)pScan->node.pParent)->offset;
|
||||
pScan->sliding = ((SWindowLogicNode*)pScan->node.pParent)->sliding;
|
||||
pScan->intervalUnit = ((SWindowLogicNode*)pScan->node.pParent)->intervalUnit;
|
||||
pScan->slidingUnit = ((SWindowLogicNode*)pScan->node.pParent)->slidingUnit;
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t osdOptimize(SOptimizeContext* pCxt, SLogicNode* pLogicNode) {
|
||||
SOsdInfo info = {0};
|
||||
int32_t code = osdMatch(pCxt, pLogicNode, &info);
|
||||
if (TSDB_CODE_SUCCESS == code && (NULL != info.pDsoFuncs || NULL != info.pSdrFuncs)) {
|
||||
info.pScan->dataRequired = osdGetDataRequired(info.pSdrFuncs);
|
||||
info.pScan->pDynamicScanFuncs = info.pDsoFuncs;
|
||||
setScanWindowInfo((SScanLogicNode*)info.pScan);
|
||||
OPTIMIZE_FLAG_SET_MASK(info.pScan->node.optimizedFlag, OPTIMIZE_FLAG_OSD);
|
||||
pCxt->optimized = true;
|
||||
}
|
||||
|
|
|
@ -443,6 +443,11 @@ static int32_t createTableScanPhysiNode(SPhysiPlanContext* pCxt, SSubplan* pSubp
|
|||
nodesDestroyNode(pTableScan);
|
||||
return TSDB_CODE_OUT_OF_MEMORY;
|
||||
}
|
||||
pTableScan->interval = pScanLogicNode->interval;
|
||||
pTableScan->offset = pScanLogicNode->offset;
|
||||
pTableScan->sliding = pScanLogicNode->sliding;
|
||||
pTableScan->intervalUnit = pScanLogicNode->intervalUnit;
|
||||
pTableScan->slidingUnit = pScanLogicNode->slidingUnit;
|
||||
|
||||
return createScanPhysiNodeFinalize(pCxt, pScanLogicNode, (SScanPhysiNode*)pTableScan, pPhyNode);
|
||||
}
|
||||
|
@ -796,6 +801,9 @@ static int32_t createWindowPhysiNodeFinalize(SPhysiPlanContext* pCxt, SNodeList*
|
|||
}
|
||||
}
|
||||
|
||||
pWindow->triggerType = pWindowLogicNode->triggerType;
|
||||
pWindow->watermark = pWindowLogicNode->watermark;
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
*pPhyNode = (SPhysiNode*)pWindow;
|
||||
} else {
|
||||
|
@ -816,7 +824,6 @@ static int32_t createIntervalPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChil
|
|||
pInterval->sliding = pWindowLogicNode->sliding;
|
||||
pInterval->intervalUnit = pWindowLogicNode->intervalUnit;
|
||||
pInterval->slidingUnit = pWindowLogicNode->slidingUnit;
|
||||
pInterval->precision = ((SColumnNode*)pWindowLogicNode->pTspk)->node.resType.precision;
|
||||
|
||||
pInterval->pFill = nodesCloneNode(pWindowLogicNode->pFill);
|
||||
if (NULL != pWindowLogicNode->pFill && NULL == pInterval->pFill) {
|
||||
|
|
|
@ -45,7 +45,7 @@ protected:
|
|||
int32_t code = qParseQuerySql(&cxt_, &query_);
|
||||
|
||||
if (code != TSDB_CODE_SUCCESS) {
|
||||
cout << "sql:[" << cxt_.pSql << "] parser code:" << code << ", strerror:" << tstrerror(code) << ", msg:" << errMagBuf_ << endl;
|
||||
cout << "sql:[" << cxt_.pSql << "] qParseQuerySql code:" << code << ", strerror:" << tstrerror(code) << ", msg:" << errMagBuf_ << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,12 @@ private:
|
|||
tDeserializeSMCreateSmaReq(pQuery->pCmdMsg->pMsg, pQuery->pCmdMsg->msgLen, &req);
|
||||
nodesStringToNode(req.ast, &pCxt->pAstRoot);
|
||||
pCxt->streamQuery = true;
|
||||
} else if (QUERY_NODE_CREATE_STREAM_STMT == nodeType(pQuery->pRoot)) {
|
||||
SCreateStreamStmt* pStmt = (SCreateStreamStmt*)pQuery->pRoot;
|
||||
pCxt->pAstRoot = pStmt->pQuery;
|
||||
pCxt->streamQuery = true;
|
||||
pCxt->triggerType = pStmt->pOptions->triggerType;
|
||||
pCxt->watermark = (NULL != pStmt->pOptions->pWatermark ? ((SValueNode*)pStmt->pOptions->pWatermark)->datum.i : 0);
|
||||
} else {
|
||||
pCxt->pAstRoot = pQuery->pRoot;
|
||||
}
|
||||
|
@ -196,14 +202,14 @@ TEST_F(PlannerTest, selectGroupBy) {
|
|||
bind("SELECT count(*) FROM t1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
// bind("SELECT c1, max(c3), min(c2), count(*) FROM t1 GROUP BY c1");
|
||||
// ASSERT_TRUE(run());
|
||||
bind("SELECT c1, max(c3), min(c3), count(*) FROM t1 GROUP BY c1");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
// bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3");
|
||||
// ASSERT_TRUE(run());
|
||||
bind("SELECT c1 + c3, c1 + count(*) FROM t1 where c2 = 'abc' GROUP BY c1, c3");
|
||||
ASSERT_TRUE(run());
|
||||
|
||||
// bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3");
|
||||
// ASSERT_TRUE(run());
|
||||
bind("SELECT c1 + c3, sum(c4 * c5) FROM t1 where concat(c2, 'wwww') = 'abcwww' GROUP BY c1 + c3");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(PlannerTest, selectSubquery) {
|
||||
|
@ -353,11 +359,11 @@ TEST_F(PlannerTest, createTopic) {
|
|||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(PlannerTest, stream) {
|
||||
TEST_F(PlannerTest, createStream) {
|
||||
setDatabase("root", "test");
|
||||
|
||||
bind("SELECT sum(c1) FROM st1");
|
||||
ASSERT_TRUE(run(true));
|
||||
bind("create stream if not exists s1 trigger window_close watermark 10s into st1 as select count(*) from t1 interval(10s)");
|
||||
ASSERT_TRUE(run());
|
||||
}
|
||||
|
||||
TEST_F(PlannerTest, createSmaIndex) {
|
||||
|
|
|
@ -313,8 +313,8 @@ static int32_t doLengthFunction(SScalarParam *pInput, int32_t inputNum, SScalarP
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
static int32_t concatCopyHelper(const char *input, char *output, bool hasNcharCol, int32_t type, int16_t *dataLen) {
|
||||
if (hasNcharCol && type == TSDB_DATA_TYPE_VARCHAR) {
|
||||
static int32_t concatCopyHelper(const char *input, char *output, bool hasNchar, int32_t type, int16_t *dataLen) {
|
||||
if (hasNchar && type == TSDB_DATA_TYPE_VARCHAR) {
|
||||
TdUcs4 *newBuf = taosMemoryCalloc((varDataLen(input) + 1) * TSDB_NCHAR_SIZE, 1);
|
||||
bool ret = taosMbsToUcs4(varDataVal(input), varDataLen(input), newBuf, (varDataLen(input) + 1) * TSDB_NCHAR_SIZE, NULL);
|
||||
if (!ret) {
|
||||
|
@ -345,10 +345,6 @@ static int32_t getNumOfNullEntries(SColumnInfoData *pColumnInfoData, int32_t num
|
|||
}
|
||||
|
||||
int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum < 2 || inputNum > 8) { // concat accpet 2-8 input strings
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SColumnInfoData **pInputData = taosMemoryCalloc(inputNum, sizeof(SColumnInfoData *));
|
||||
SColumnInfoData *pOutputData = pOutput->columnData;
|
||||
char **input = taosMemoryCalloc(inputNum, POINTER_BYTES);
|
||||
|
@ -356,15 +352,8 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
|
|||
|
||||
int32_t inputLen = 0;
|
||||
int32_t numOfRows = 0;
|
||||
bool hasNcharCol = false;
|
||||
bool hasNchar = (GET_PARAM_TYPE(pOutput) == TSDB_DATA_TYPE_NCHAR) ? true : false;
|
||||
for (int32_t i = 0; i < inputNum; ++i) {
|
||||
int32_t type = GET_PARAM_TYPE(&pInput[i]);
|
||||
if (!IS_VAR_DATA_TYPE(type)) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (type == TSDB_DATA_TYPE_NCHAR) {
|
||||
hasNcharCol = true;
|
||||
}
|
||||
if (pInput[i].numOfRows > numOfRows) {
|
||||
numOfRows = pInput[i].numOfRows;
|
||||
}
|
||||
|
@ -373,7 +362,7 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
|
|||
pInputData[i] = pInput[i].columnData;
|
||||
input[i] = pInputData[i]->pData + pInputData[i]->varmeta.offset[0];
|
||||
int32_t factor = 1;
|
||||
if (hasNcharCol && (GET_PARAM_TYPE(&pInput[i]) == TSDB_DATA_TYPE_VARCHAR)) {
|
||||
if (hasNchar && (GET_PARAM_TYPE(&pInput[i]) == TSDB_DATA_TYPE_VARCHAR)) {
|
||||
factor = TSDB_NCHAR_SIZE;
|
||||
}
|
||||
|
||||
|
@ -405,7 +394,7 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
|
|||
|
||||
int16_t dataLen = 0;
|
||||
for (int32_t i = 0; i < inputNum; ++i) {
|
||||
int32_t ret = concatCopyHelper(input[i], output, hasNcharCol, GET_PARAM_TYPE(&pInput[i]), &dataLen);
|
||||
int32_t ret = concatCopyHelper(input[i], output, hasNchar, GET_PARAM_TYPE(&pInput[i]), &dataLen);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -428,10 +417,6 @@ int32_t concatFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
|
|||
|
||||
|
||||
int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum < 3 || inputNum > 9) { // concat accpet 3-9 input strings including the separator
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
SColumnInfoData **pInputData = taosMemoryCalloc(inputNum, sizeof(SColumnInfoData *));
|
||||
SColumnInfoData *pOutputData = pOutput->columnData;
|
||||
char **input = taosMemoryCalloc(inputNum, POINTER_BYTES);
|
||||
|
@ -439,15 +424,8 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
|
|||
|
||||
int32_t inputLen = 0;
|
||||
int32_t numOfRows = 0;
|
||||
bool hasNcharCol = false;
|
||||
bool hasNchar = (GET_PARAM_TYPE(pOutput) == TSDB_DATA_TYPE_NCHAR) ? true : false;
|
||||
for (int32_t i = 1; i < inputNum; ++i) {
|
||||
int32_t type = GET_PARAM_TYPE(&pInput[i]);
|
||||
if (!IS_VAR_DATA_TYPE(GET_PARAM_TYPE(&pInput[i]))) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
if (type == TSDB_DATA_TYPE_NCHAR) {
|
||||
hasNcharCol = true;
|
||||
}
|
||||
if (pInput[i].numOfRows > numOfRows) {
|
||||
numOfRows = pInput[i].numOfRows;
|
||||
}
|
||||
|
@ -456,7 +434,7 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
|
|||
pInputData[i] = pInput[i].columnData;
|
||||
input[i] = pInputData[i]->pData + pInputData[i]->varmeta.offset[0];
|
||||
int32_t factor = 1;
|
||||
if (hasNcharCol && (GET_PARAM_TYPE(&pInput[i]) == TSDB_DATA_TYPE_VARCHAR)) {
|
||||
if (hasNchar && (GET_PARAM_TYPE(&pInput[i]) == TSDB_DATA_TYPE_VARCHAR)) {
|
||||
factor = TSDB_NCHAR_SIZE;
|
||||
}
|
||||
|
||||
|
@ -487,7 +465,7 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
|
|||
continue;
|
||||
}
|
||||
|
||||
int32_t ret = concatCopyHelper(input[i], output, hasNcharCol, GET_PARAM_TYPE(&pInput[i]), &dataLen);
|
||||
int32_t ret = concatCopyHelper(input[i], output, hasNchar, GET_PARAM_TYPE(&pInput[i]), &dataLen);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -499,7 +477,7 @@ int32_t concatWsFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *p
|
|||
if (i < inputNum - 1) {
|
||||
//insert the separator
|
||||
char *sep = pInputData[0]->pData;
|
||||
int32_t ret = concatCopyHelper(sep, output, hasNcharCol, GET_PARAM_TYPE(&pInput[0]), &dataLen);
|
||||
int32_t ret = concatCopyHelper(sep, output, hasNchar, GET_PARAM_TYPE(&pInput[0]), &dataLen);
|
||||
if (ret != TSDB_CODE_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
@ -666,18 +644,14 @@ int32_t substrFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOu
|
|||
}
|
||||
|
||||
int32_t castFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum!= 3) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
|
||||
int16_t inputType = pInput[0].columnData->info.type;
|
||||
int16_t outputType = *(int16_t *)pInput[1].columnData->pData;
|
||||
int16_t outputType = pOutput[0].columnData->info.type;
|
||||
if (outputType != TSDB_DATA_TYPE_BIGINT && outputType != TSDB_DATA_TYPE_UBIGINT &&
|
||||
outputType != TSDB_DATA_TYPE_VARCHAR && outputType != TSDB_DATA_TYPE_NCHAR &&
|
||||
outputType != TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
int64_t outputLen = *(int64_t *)pInput[2].columnData->pData;
|
||||
int64_t outputLen = pOutput[0].columnData->info.bytes;
|
||||
|
||||
char *input = NULL;
|
||||
char *outputBuf = taosMemoryCalloc(outputLen * pInput[0].numOfRows, 1);
|
||||
|
@ -1275,6 +1249,14 @@ int32_t todayFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOut
|
|||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t timezoneFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
if (inputNum != 1) {
|
||||
return TSDB_CODE_FAILED;
|
||||
}
|
||||
colDataAppend(pOutput->columnData, pOutput->numOfRows, (char *)colDataGetData(pInput->columnData, 0), false);
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
||||
int32_t atanFunction(SScalarParam *pInput, int32_t inputNum, SScalarParam *pOutput) {
|
||||
return doScalarFunctionUnique(pInput, inputNum, pOutput, atan);
|
||||
}
|
||||
|
|
|
@ -79,6 +79,8 @@ _getBigintValue_fn_t getVectorBigintValueFn(int32_t srcType) {
|
|||
p = getVectorBigintValue_FLOAT;
|
||||
}else if(srcType==TSDB_DATA_TYPE_DOUBLE) {
|
||||
p = getVectorBigintValue_DOUBLE;
|
||||
}else if(srcType==TSDB_DATA_TYPE_TIMESTAMP) {
|
||||
p = getVectorBigintValue_BIGINT;
|
||||
}else {
|
||||
assert(0);
|
||||
}
|
||||
|
@ -565,6 +567,25 @@ static void vectorMathAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig
|
|||
}
|
||||
}
|
||||
|
||||
static void vectorMathBigintAddHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t i) {
|
||||
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
|
||||
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
|
||||
|
||||
int64_t *output = (int64_t *)pOutputCol->pData;
|
||||
|
||||
if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value
|
||||
colDataAppendNNULL(pOutputCol, 0, numOfRows);
|
||||
} else {
|
||||
for (; i >= 0 && i < numOfRows; i += step, output += 1) {
|
||||
*output = getVectorBigintValueFnLeft(pLeftCol->pData, i) + getVectorBigintValueFnRight(pRightCol->pData, 0);
|
||||
}
|
||||
pOutputCol->hasNull = pLeftCol->hasNull;
|
||||
if (pOutputCol->hasNull) {
|
||||
memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static SColumnInfoData* doVectorConvert(SScalarParam* pInput, int32_t* doConvert) {
|
||||
SScalarParam convertParam = {0};
|
||||
|
||||
|
@ -599,27 +620,53 @@ void vectorMathAdd(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
|
|||
SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
|
||||
SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
|
||||
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
|
||||
if ((GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_BIGINT) ||
|
||||
(GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BIGINT)) { //timestamp plus duration
|
||||
int64_t *output = (int64_t *)pOutputCol->pData;
|
||||
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
|
||||
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
|
||||
|
||||
double *output = (double *)pOutputCol->pData;
|
||||
if (pLeft->numOfRows == pRight->numOfRows) {
|
||||
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
|
||||
*output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) + getVectorDoubleValueFnRight(pRightCol->pData, i);
|
||||
}
|
||||
|
||||
pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
|
||||
if (pOutputCol->hasNull) {
|
||||
int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
|
||||
for (int32_t j = 0; j < numOfBitLen; ++j) {
|
||||
pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
|
||||
if (pLeft->numOfRows == pRight->numOfRows) {
|
||||
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
|
||||
*output = getVectorBigintValueFnLeft(pLeftCol->pData, i) + getVectorBigintValueFnRight(pRightCol->pData, i);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (pLeft->numOfRows == 1) {
|
||||
vectorMathAddHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i);
|
||||
} else if (pRight->numOfRows == 1) {
|
||||
vectorMathAddHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
|
||||
pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
|
||||
if (pOutputCol->hasNull) {
|
||||
int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
|
||||
for (int32_t j = 0; j < numOfBitLen; ++j) {
|
||||
pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
|
||||
}
|
||||
}
|
||||
|
||||
} else if (pLeft->numOfRows == 1) {
|
||||
vectorMathBigintAddHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i);
|
||||
} else if (pRight->numOfRows == 1) {
|
||||
vectorMathBigintAddHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
|
||||
}
|
||||
} else {
|
||||
double *output = (double *)pOutputCol->pData;
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
|
||||
|
||||
if (pLeft->numOfRows == pRight->numOfRows) {
|
||||
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
|
||||
*output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) + getVectorDoubleValueFnRight(pRightCol->pData, i);
|
||||
}
|
||||
|
||||
pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
|
||||
if (pOutputCol->hasNull) {
|
||||
int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
|
||||
for (int32_t j = 0; j < numOfBitLen; ++j) {
|
||||
pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
|
||||
}
|
||||
}
|
||||
|
||||
} else if (pLeft->numOfRows == 1) {
|
||||
vectorMathAddHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, i);
|
||||
} else if (pRight->numOfRows == 1) {
|
||||
vectorMathAddHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, i);
|
||||
}
|
||||
}
|
||||
|
||||
doReleaseVec(pLeftCol, leftConvert);
|
||||
|
@ -646,6 +693,25 @@ static void vectorMathSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRig
|
|||
}
|
||||
}
|
||||
|
||||
static void vectorMathBigintSubHelper(SColumnInfoData* pLeftCol, SColumnInfoData* pRightCol, SColumnInfoData* pOutputCol, int32_t numOfRows, int32_t step, int32_t factor, int32_t i) {
|
||||
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
|
||||
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
|
||||
|
||||
int64_t *output = (int64_t *)pOutputCol->pData;
|
||||
|
||||
if (colDataIsNull_f(pRightCol->nullbitmap, 0)) { // Set pLeft->numOfRows NULL value
|
||||
colDataAppendNNULL(pOutputCol, 0, numOfRows);
|
||||
} else {
|
||||
for (; i >= 0 && i < numOfRows; i += step, output += 1) {
|
||||
*output = (getVectorBigintValueFnLeft(pLeftCol->pData, i) - getVectorBigintValueFnRight(pRightCol->pData, 0)) * factor;
|
||||
}
|
||||
pOutputCol->hasNull = pLeftCol->hasNull;
|
||||
if (pOutputCol->hasNull) {
|
||||
memcpy(pOutputCol->nullbitmap, pLeftCol->nullbitmap, BitmapLen(numOfRows));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut, int32_t _ord) {
|
||||
SColumnInfoData *pOutputCol = pOut->columnData;
|
||||
|
||||
|
@ -658,27 +724,53 @@ void vectorMathSub(SScalarParam* pLeft, SScalarParam* pRight, SScalarParam *pOut
|
|||
SColumnInfoData *pLeftCol = doVectorConvert(pLeft, &leftConvert);
|
||||
SColumnInfoData *pRightCol = doVectorConvert(pRight, &rightConvert);
|
||||
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
|
||||
if ((GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_BIGINT) ||
|
||||
(GET_PARAM_TYPE(pRight) == TSDB_DATA_TYPE_TIMESTAMP && GET_PARAM_TYPE(pLeft) == TSDB_DATA_TYPE_BIGINT)) { //timestamp minus duration
|
||||
int64_t *output = (int64_t *)pOutputCol->pData;
|
||||
_getBigintValue_fn_t getVectorBigintValueFnLeft = getVectorBigintValueFn(pLeftCol->info.type);
|
||||
_getBigintValue_fn_t getVectorBigintValueFnRight = getVectorBigintValueFn(pRightCol->info.type);
|
||||
|
||||
double *output = (double *)pOutputCol->pData;
|
||||
if (pLeft->numOfRows == pRight->numOfRows) {
|
||||
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
|
||||
*output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) - getVectorDoubleValueFnRight(pRightCol->pData, i);
|
||||
}
|
||||
|
||||
pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
|
||||
if (pOutputCol->hasNull) {
|
||||
int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
|
||||
for (int32_t j = 0; j < numOfBitLen; ++j) {
|
||||
pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
|
||||
if (pLeft->numOfRows == pRight->numOfRows) {
|
||||
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
|
||||
*output = getVectorBigintValueFnLeft(pLeftCol->pData, i) - getVectorBigintValueFnRight(pRightCol->pData, i);
|
||||
}
|
||||
}
|
||||
|
||||
} else if (pLeft->numOfRows == 1) {
|
||||
vectorMathSubHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, -1, i);
|
||||
} else if (pRight->numOfRows == 1) {
|
||||
vectorMathSubHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, 1, i);
|
||||
pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
|
||||
if (pOutputCol->hasNull) {
|
||||
int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
|
||||
for (int32_t j = 0; j < numOfBitLen; ++j) {
|
||||
pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
|
||||
}
|
||||
}
|
||||
|
||||
} else if (pLeft->numOfRows == 1) {
|
||||
vectorMathBigintSubHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, -1, i);
|
||||
} else if (pRight->numOfRows == 1) {
|
||||
vectorMathBigintSubHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, 1, i);
|
||||
}
|
||||
} else {
|
||||
double *output = (double *)pOutputCol->pData;
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnLeft = getVectorDoubleValueFn(pLeftCol->info.type);
|
||||
_getDoubleValue_fn_t getVectorDoubleValueFnRight = getVectorDoubleValueFn(pRightCol->info.type);
|
||||
|
||||
if (pLeft->numOfRows == pRight->numOfRows) {
|
||||
for (; i < pRight->numOfRows && i >= 0; i += step, output += 1) {
|
||||
*output = getVectorDoubleValueFnLeft(pLeftCol->pData, i) - getVectorDoubleValueFnRight(pRightCol->pData, i);
|
||||
}
|
||||
|
||||
pOutputCol->hasNull = (pLeftCol->hasNull || pRightCol->hasNull);
|
||||
if (pOutputCol->hasNull) {
|
||||
int32_t numOfBitLen = BitmapLen(pLeft->numOfRows);
|
||||
for (int32_t j = 0; j < numOfBitLen; ++j) {
|
||||
pOutputCol->nullbitmap[j] = pLeftCol->nullbitmap[j] | pRightCol->nullbitmap[j];
|
||||
}
|
||||
}
|
||||
|
||||
} else if (pLeft->numOfRows == 1) {
|
||||
vectorMathSubHelper(pRightCol, pLeftCol, pOutputCol, pRight->numOfRows, step, -1, i);
|
||||
} else if (pRight->numOfRows == 1) {
|
||||
vectorMathSubHelper(pLeftCol, pRightCol, pOutputCol, pLeft->numOfRows, step, 1, i);
|
||||
}
|
||||
}
|
||||
|
||||
doReleaseVec(pLeftCol, leftConvert);
|
||||
|
|
|
@ -2738,7 +2738,9 @@ void schedulerDestroy(void) {
|
|||
|
||||
while (pJob) {
|
||||
refId = pJob->refId;
|
||||
|
||||
if (refId == 0) {
|
||||
break;
|
||||
}
|
||||
taosRemoveRef(schMgmt.jobRef, pJob->refId);
|
||||
|
||||
pJob = taosIterateRef(schMgmt.jobRef, refId);
|
||||
|
|
|
@ -8,7 +8,7 @@ AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} SOURCE_LIST)
|
|||
ADD_EXECUTABLE(schedulerTest ${SOURCE_LIST})
|
||||
TARGET_LINK_LIBRARIES(
|
||||
schedulerTest
|
||||
PUBLIC os util common catalog transport gtest qcom taos planner scheduler
|
||||
PUBLIC os util common catalog transport gtest qcom taos_static planner scheduler
|
||||
)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES(
|
||||
|
|
|
@ -35,11 +35,11 @@ CURR_DIR=`pwd`
|
|||
IN_TDINTERNAL="community"
|
||||
if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then
|
||||
TAOS_DIR=$CURR_DIR/../../..
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1`
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1`
|
||||
LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6,7|rev`/lib
|
||||
else
|
||||
TAOS_DIR=$CURR_DIR/../..
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1`
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1`
|
||||
LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib
|
||||
fi
|
||||
|
||||
|
|
|
@ -35,11 +35,11 @@ CURR_DIR=`pwd`
|
|||
IN_TDINTERNAL="community"
|
||||
if [[ "$CURR_DIR" == *"$IN_TDINTERNAL"* ]]; then
|
||||
TAOS_DIR=$CURR_DIR/../../..
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1`
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1`
|
||||
LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6,7|rev`/lib
|
||||
else
|
||||
TAOS_DIR=$CURR_DIR/../..
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep debug|head -n1`
|
||||
TAOSD_DIR=`find $TAOS_DIR -name "taosd"|grep bin|head -n1`
|
||||
LIB_DIR=`echo $TAOSD_DIR|rev|cut -d '/' -f 3,4,5,6|rev`/lib
|
||||
fi
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue