diff --git a/cmake/install.inc b/cmake/install.inc index fced638966..4494c19d49 100755 --- a/cmake/install.inc +++ b/cmake/install.inc @@ -32,7 +32,7 @@ ELSEIF (TD_WINDOWS) #INSTALL(TARGETS taos RUNTIME DESTINATION driver) #INSTALL(TARGETS shell RUNTIME DESTINATION .) IF (TD_MVN_INSTALLED) - INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-*-dist.jar DESTINATION connector/jdbc) + INSTALL(FILES ${LIBRARY_OUTPUT_PATH}/taos-jdbcdriver-2.0.33-dist.jar DESTINATION connector/jdbc) ENDIF () ELSEIF (TD_DARWIN) SET(TD_MAKE_INSTALL_SH "${TD_COMMUNITY_DIR}/packaging/tools/make_install.sh") diff --git a/documentation20/cn/12.taos-sql/docs.md b/documentation20/cn/12.taos-sql/docs.md index 73fa5b34e5..b047bb9bb3 100644 --- a/documentation20/cn/12.taos-sql/docs.md +++ b/documentation20/cn/12.taos-sql/docs.md @@ -1338,7 +1338,7 @@ SELECT function_list FROM stb_name - 查询过滤、聚合等操作按照每个切分窗口为独立的单位执行。聚合查询目前支持三种窗口的划分方式: 1. 时间窗口:聚合时间段的窗口宽度由关键词 INTERVAL 指定,最短时间间隔 10 毫秒(10a);并且支持偏移 offset(偏移必须小于间隔),也即时间窗口划分与“UTC 时刻 0”相比的偏移量。SLIDING 语句用于指定聚合时间段的前向增量,也即每次窗口向前滑动的时长。当 SLIDING 与 INTERVAL 取值相等的时候,滑动窗口即为翻转窗口。 * 从 2.1.5.0 版本开始,INTERVAL 语句允许的最短时间间隔调整为 1 微秒(1u),当然如果所查询的 DATABASE 的时间精度设置为毫秒级,那么允许的最短时间间隔为 1 毫秒(1a)。 - 2. 状态窗口:使用整数(布尔值)或字符串来标识产生记录时设备的状态量,产生的记录如果具有相同的状态量取值则归属于同一个状态窗口,数值改变后该窗口关闭。状态量所对应的列作为 STATE_WINDOW 语句的参数来指定。 + 2. 状态窗口:使用整数或布尔值来标识产生记录时设备的状态量,产生的记录如果具有相同的状态量取值则归属于同一个状态窗口,数值改变后该窗口关闭。状态量所对应的列作为 STATE_WINDOW 语句的参数来指定。 3. 会话窗口:时间戳所在的列由 SESSION 语句的 ts_col 参数指定,会话窗口根据相邻两条记录的时间戳差值来确定是否属于同一个会话——如果时间戳差异在 tol_val 以内,则认为记录仍属于同一个窗口;如果时间变化超过 tol_val,则自动开启下一个窗口。 - WHERE 语句可以指定查询的起止时间和其他过滤条件。 - FILL 语句指定某一窗口区间数据缺失的情况下的填充模式。填充模式包括以下几种: diff --git a/documentation20/en/12.taos-sql/docs.md b/documentation20/en/12.taos-sql/docs.md index f215084392..2f344b4529 100644 --- a/documentation20/en/12.taos-sql/docs.md +++ b/documentation20/en/12.taos-sql/docs.md @@ -1132,7 +1132,7 @@ TDengine supports aggregations over data, they are listed below: ``` Function: Return the difference between the max value and the min value of a column in statistics /STable. - Return Data Type: Same as applicable fields. + Return Data Type: Double. Applicable Fields: All types except binary, nchar, bool. diff --git a/packaging/tools/makearbi.sh b/packaging/tools/makearbi.sh index 5346a79c8f..6dcabc2a06 100755 --- a/packaging/tools/makearbi.sh +++ b/packaging/tools/makearbi.sh @@ -59,7 +59,7 @@ pkg_name=${install_dir}-${osType}-${cpuType} # exit 1 # fi -if [ "$verType" == "beta" ]; then +if [[ "$verType" == "beta" ]] || [[ "$verType" == "preRelease" ]]; then pkg_name=${install_dir}-${verType}-${osType}-${cpuType} elif [ "$verType" == "stable" ]; then pkg_name=${pkg_name} diff --git a/packaging/tools/makeclient.sh b/packaging/tools/makeclient.sh index 97e80088be..8fc431bfbc 100755 --- a/packaging/tools/makeclient.sh +++ b/packaging/tools/makeclient.sh @@ -182,7 +182,7 @@ pkg_name=${install_dir}-${osType}-${cpuType} # exit 1 # fi -if [ "$verType" == "beta" ]; then +if [[ "$verType" == "beta" ]] || [[ "$verType" == "preRelease" ]]; then pkg_name=${install_dir}-${verType}-${osType}-${cpuType} elif [ "$verType" == "stable" ]; then pkg_name=${pkg_name} diff --git a/packaging/tools/makepkg.sh b/packaging/tools/makepkg.sh index 56ab24426f..1064f0b0e5 100755 --- a/packaging/tools/makepkg.sh +++ b/packaging/tools/makepkg.sh @@ -215,7 +215,7 @@ pkg_name=${install_dir}-${osType}-${cpuType} # exit 1 # fi -if [ "$verType" == "beta" ]; then +if [[ "$verType" == "beta" ]] || [[ "$verType" == "preRelease" ]]; then pkg_name=${install_dir}-${verType}-${osType}-${cpuType} elif [ "$verType" == "stable" ]; then pkg_name=${pkg_name} diff --git a/src/client/inc/tscUtil.h b/src/client/inc/tscUtil.h index 264070d70f..a4df124fa2 100644 --- a/src/client/inc/tscUtil.h +++ b/src/client/inc/tscUtil.h @@ -273,7 +273,7 @@ void tscVgroupTableCopy(SVgroupTableInfo* info, SVgroupTableInfo* pInfo); int tscGetSTableVgroupInfo(SSqlObj* pSql, SQueryInfo* pQueryInfo); int tscGetTableMeta(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo); -int tscGetTableMetaEx(SSqlObj* pSql, STableMetaInfo* pTableMetaInfo, bool createIfNotExists); +int tscGetTableMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool createIfNotExists, bool onlyLocal); int32_t tscGetUdfFromNode(SSqlObj *pSql, SQueryInfo* pQueryInfo); void tscResetForNextRetrieve(SSqlRes* pRes); diff --git a/src/client/src/tscParseInsert.c b/src/client/src/tscParseInsert.c index 98a22835e5..f24f7a7ecb 100644 --- a/src/client/src/tscParseInsert.c +++ b/src/client/src/tscParseInsert.c @@ -1482,7 +1482,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC return TSDB_CODE_TSC_SQL_SYNTAX_ERROR; } - code = tscGetTableMetaEx(pSql, pTableMetaInfo, true); + code = tscGetTableMetaEx(pSql, pTableMetaInfo, true, false); if (TSDB_CODE_TSC_ACTION_IN_PROGRESS == code) { return code; } @@ -1493,7 +1493,7 @@ static int32_t tscCheckIfCreateTable(char **sqlstr, SSqlObj *pSql, char** boundC } sql = sToken.z; - code = tscGetTableMetaEx(pSql, pTableMetaInfo, false); + code = tscGetTableMetaEx(pSql, pTableMetaInfo, false, false); if (pInsertParam->sql == NULL) { assert(code == TSDB_CODE_TSC_ACTION_IN_PROGRESS); } diff --git a/src/client/src/tscParseLineProtocol.c b/src/client/src/tscParseLineProtocol.c index 0386850f63..23ab0f297e 100644 --- a/src/client/src/tscParseLineProtocol.c +++ b/src/client/src/tscParseLineProtocol.c @@ -474,7 +474,7 @@ int32_t loadTableMeta(TAOS* taos, char* tableName, SSmlSTableSchema* schema) { return code; } -static int32_t reconcileDBSchemas(TAOS* taos, SArray* stableSchemas) { +static int32_t modifyDBSchemas(TAOS* taos, SArray* stableSchemas) { int32_t code = 0; size_t numStable = taosArrayGetSize(stableSchemas); for (int i = 0; i < numStable; ++i) { @@ -570,6 +570,40 @@ static int32_t getSmlMd5ChildTableName(TAOS_SML_DATA_POINT* point, char* tableNa return 0; } + +static int32_t changeChildTableTagValue(TAOS* taos, const char* cTableName, const char* tagName, TAOS_BIND* bind) { + char sql[512]; + sprintf(sql, "alter table %s set tag %s=?", cTableName, tagName); + + int32_t code; + TAOS_STMT* stmt = taos_stmt_init(taos); + code = taos_stmt_prepare(stmt, sql, (unsigned long)strlen(sql)); + + if (code != 0) { + tscError("%s", taos_stmt_errstr(stmt)); + return code; + } + + code = taos_stmt_bind_param(stmt, bind); + if (code != 0) { + tscError("%s", taos_stmt_errstr(stmt)); + return code; + } + + code = taos_stmt_execute(stmt); + if (code != 0) { + tscError("%s", taos_stmt_errstr(stmt)); + return code; + } + + code = taos_stmt_close(stmt); + if (code != 0) { + tscError("%s", taos_stmt_errstr(stmt)); + return code; + } + return code; +} + static int32_t creatChildTableIfNotExists(TAOS* taos, const char* cTableName, const char* sTableName, SArray* tagsSchema, SArray* tagsBind) { size_t numTags = taosArrayGetSize(tagsSchema); char* sql = malloc(tsMaxSQLStringLen+1); @@ -657,7 +691,6 @@ static int32_t insertChildTableBatch(TAOS* taos, char* cTableName, SArray* cols } do { - code = taos_stmt_set_tbname(stmt, cTableName); if (code != 0) { tscError("%s", taos_stmt_errstr(stmt)); @@ -742,97 +775,200 @@ static int32_t arrangePointsByChildTableName(TAOS_SML_DATA_POINT* points, int nu return 0; } -static int32_t insertPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t numPoints, SArray* stableSchemas) { +static int32_t applyChildTableTags(TAOS* taos, char* cTableName, char* sTableName, + SSmlSTableSchema* sTableSchema, SArray* cTablePoints) { + size_t numTags = taosArrayGetSize(sTableSchema->tags); + size_t rows = taosArrayGetSize(cTablePoints); + + TAOS_SML_KV* tagKVs[TSDB_MAX_TAGS] = {0}; + for (int i= 0; i < rows; ++i) { + TAOS_SML_DATA_POINT * pDataPoint = taosArrayGetP(cTablePoints, i); + for (int j = 0; j < pDataPoint->tagNum; ++j) { + TAOS_SML_KV* kv = pDataPoint->tags + j; + tagKVs[kv->fieldSchemaIdx] = kv; + } + } + + int32_t notNullTagsIndices[TSDB_MAX_TAGS] = {0}; + int32_t numNotNullTags = 0; + for (int32_t i = 0; i < numTags; ++i) { + if (tagKVs[i] != NULL) { + notNullTagsIndices[numNotNullTags] = i; + ++numNotNullTags; + } + } + + SArray* tagBinds = taosArrayInit(numTags, sizeof(TAOS_BIND)); + taosArraySetSize(tagBinds, numTags); + int isNullColBind = TSDB_TRUE; + for (int j = 0; j < numTags; ++j) { + TAOS_BIND* bind = taosArrayGet(tagBinds, j); + bind->is_null = &isNullColBind; + } + for (int j = 0; j < numTags; ++j) { + if (tagKVs[j] == NULL) continue; + TAOS_SML_KV* kv = tagKVs[j]; + TAOS_BIND* bind = taosArrayGet(tagBinds, kv->fieldSchemaIdx); + bind->buffer_type = kv->type; + bind->length = malloc(sizeof(uintptr_t*)); + *bind->length = kv->length; + bind->buffer = kv->value; + bind->is_null = NULL; + } + + // select tag1,tag2,... from stable where tbname in (ctable) + char* sql = malloc(tsMaxSQLStringLen+1); + int freeBytes = tsMaxSQLStringLen + 1; + snprintf(sql, freeBytes, "select tbname, "); + for (int i = 0; i < numNotNullTags ; ++i) { + snprintf(sql + strlen(sql), freeBytes-strlen(sql), "%s,", tagKVs[notNullTagsIndices[i]]->key); + } + snprintf(sql + strlen(sql) - 1, freeBytes - strlen(sql) + 1, + " from %s where tbname in (\'%s\')", sTableName, cTableName); + sql[strlen(sql)] = '\0'; + + TAOS_RES* result = taos_query(taos, sql); + free(sql); + + int32_t code = taos_errno(result); + if (code != 0) { + tscError("get child table %s tags failed. error string %s", cTableName, taos_errstr(result)); + goto cleanup; + } + + // check tag value and set tag values if different + TAOS_ROW row = taos_fetch_row(result); + if (row != NULL) { + int numFields = taos_field_count(result); + TAOS_FIELD* fields = taos_fetch_fields(result); + int* lengths = taos_fetch_lengths(result); + for (int i = 1; i < numFields; ++i) { + uint8_t dbType = fields[i].type; + int32_t length = lengths[i]; + char* val = row[i]; + + TAOS_SML_KV* tagKV = tagKVs[notNullTagsIndices[i-1]]; + if (tagKV->type != dbType) { + tscError("child table %s tag %s type mismatch. point type : %d, db type : %d", + cTableName, tagKV->key, tagKV->type, dbType); + return TSDB_CODE_TSC_INVALID_VALUE; + } + + assert(tagKV->value); + + if (val == NULL || length != tagKV->length || memcmp(tagKV->value, val, length) != 0) { + TAOS_BIND* bind = taosArrayGet(tagBinds, tagKV->fieldSchemaIdx); + code = changeChildTableTagValue(taos, cTableName, tagKV->key, bind); + if (code != 0) { + tscError("change child table tag failed. table name %s, tag %s", cTableName, tagKV->key); + goto cleanup; + } + } + } + tscDebug("successfully applied point tags. child table: %s", cTableName); + } else { + code = creatChildTableIfNotExists(taos, cTableName, sTableName, sTableSchema->tags, tagBinds); + if (code != 0) { + goto cleanup; + } + } + +cleanup: + taos_free_result(result); + for (int i = 0; i < taosArrayGetSize(tagBinds); ++i) { + TAOS_BIND* bind = taosArrayGet(tagBinds, i); + free(bind->length); + } + taosArrayDestroy(tagBinds); + return code; +} + +static int32_t applyChildTableFields(TAOS* taos, SSmlSTableSchema* sTableSchema, char* cTableName, SArray* cTablePoints) { int32_t code = TSDB_CODE_SUCCESS; - SHashObj* cname2points = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), - true, false); - arrangePointsByChildTableName(points, numPoints, cname2points, stableSchemas); + size_t numCols = taosArrayGetSize(sTableSchema->fields); + size_t rows = taosArrayGetSize(cTablePoints); + SArray* rowsBind = taosArrayInit(rows, POINTER_BYTES); - int isNullColBind = TSDB_TRUE; - SArray** pCTablePoints = taosHashIterate(cname2points, NULL); - while (pCTablePoints) { - SArray* cTablePoints = *pCTablePoints; + for (int i = 0; i < rows; ++i) { + TAOS_SML_DATA_POINT* point = taosArrayGetP(cTablePoints, i); - TAOS_SML_DATA_POINT * point = taosArrayGetP(cTablePoints, 0); - SSmlSTableSchema* sTableSchema = taosArrayGet(stableSchemas, point->schemaIdx); - size_t numTags = taosArrayGetSize(sTableSchema->tags); - size_t numCols = taosArrayGetSize(sTableSchema->fields); + TAOS_BIND* colBinds = calloc(numCols, sizeof(TAOS_BIND)); + if (colBinds == NULL) { + tscError("taos_sml_insert insert points, failed to allocated memory for TAOS_BIND, " + "num of rows: %zu, num of cols: %zu", rows, numCols); + return TSDB_CODE_TSC_OUT_OF_MEMORY; + } - SArray* tagBinds = taosArrayInit(numTags, sizeof(TAOS_BIND)); - taosArraySetSize(tagBinds, numTags); - for (int j = 0; j < numTags; ++j) { - TAOS_BIND* bind = taosArrayGet(tagBinds, j); + int isNullColBind = TSDB_TRUE; + for (int j = 0; j < numCols; ++j) { + TAOS_BIND* bind = colBinds + j; bind->is_null = &isNullColBind; } - for (int j = 0; j < point->tagNum; ++j) { - TAOS_SML_KV* kv = point->tags + j; - TAOS_BIND* bind = taosArrayGet(tagBinds, kv->fieldSchemaIdx); + for (int j = 0; j < point->fieldNum; ++j) { + TAOS_SML_KV* kv = point->fields + j; + TAOS_BIND* bind = colBinds + kv->fieldSchemaIdx; bind->buffer_type = kv->type; bind->length = malloc(sizeof(uintptr_t*)); *bind->length = kv->length; bind->buffer = kv->value; bind->is_null = NULL; } + taosArrayPush(rowsBind, &colBinds); + } - size_t rows = taosArrayGetSize(cTablePoints); - SArray* rowsBind = taosArrayInit(rows, POINTER_BYTES); + code = insertChildTableBatch(taos, cTableName, sTableSchema->fields, rowsBind); + if (code != 0) { + tscError("insert into child table %s failed. error %s", cTableName, tstrerror(code)); + } - for (int i = 0; i < rows; ++i) { - point = taosArrayGetP(cTablePoints, i); - - TAOS_BIND* colBinds = calloc(numCols, sizeof(TAOS_BIND)); - if (colBinds == NULL) { - tscError("taos_sml_insert insert points, failed to allocated memory for TAOS_BIND, " - "num of rows: %zu, num of cols: %zu", rows, numCols); - } - for (int j = 0; j < numCols; ++j) { - TAOS_BIND* bind = colBinds + j; - bind->is_null = &isNullColBind; - } - for (int j = 0; j < point->fieldNum; ++j) { - TAOS_SML_KV* kv = point->fields + j; - TAOS_BIND* bind = colBinds + kv->fieldSchemaIdx; - bind->buffer_type = kv->type; - bind->length = malloc(sizeof(uintptr_t*)); - *bind->length = kv->length; - bind->buffer = kv->value; - bind->is_null = NULL; - } - taosArrayPush(rowsBind, &colBinds); - } - - code = creatChildTableIfNotExists(taos, point->childTableName, point->stableName, sTableSchema->tags, tagBinds); - if (code == 0) { - code = insertChildTableBatch(taos, point->childTableName, sTableSchema->fields, rowsBind); - if (code != 0) { - tscError("insert into child table %s failed. error %s", point->childTableName, tstrerror(code)); - } - } else { - tscError("Create Child Table %s failed, error %s", point->childTableName, tstrerror(code)); - } - - for (int i = 0; i < taosArrayGetSize(tagBinds); ++i) { - TAOS_BIND* bind = taosArrayGet(tagBinds, i); + for (int i = 0; i < rows; ++i) { + TAOS_BIND* colBinds = taosArrayGetP(rowsBind, i); + for (int j = 0; j < numCols; ++j) { + TAOS_BIND* bind = colBinds + j; free(bind->length); } - taosArrayDestroy(tagBinds); - for (int i = 0; i < rows; ++i) { - TAOS_BIND* colBinds = taosArrayGetP(rowsBind, i); - for (int j = 0; j < numCols; ++j) { - TAOS_BIND* bind = colBinds + j; - free(bind->length); - } - free(colBinds); - } - taosArrayDestroy(rowsBind); - taosArrayDestroy(cTablePoints); + free(colBinds); + } + taosArrayDestroy(rowsBind); + return code; +} + +static int32_t applyDataPoints(TAOS* taos, TAOS_SML_DATA_POINT* points, int32_t numPoints, SArray* stableSchemas) { + int32_t code = TSDB_CODE_SUCCESS; + + SHashObj* cname2points = taosHashInit(128, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), true, false); + arrangePointsByChildTableName(points, numPoints, cname2points, stableSchemas); + + SArray** pCTablePoints = taosHashIterate(cname2points, NULL); + while (pCTablePoints) { + SArray* cTablePoints = *pCTablePoints; + + TAOS_SML_DATA_POINT* point = taosArrayGetP(cTablePoints, 0); + SSmlSTableSchema* sTableSchema = taosArrayGet(stableSchemas, point->schemaIdx); + code = applyChildTableTags(taos, point->childTableName, point->stableName, sTableSchema, cTablePoints); if (code != 0) { - break; + tscError("apply child table tags failed. child table %s, error %s", point->childTableName, tstrerror(code)); + goto cleanup; } + code = applyChildTableFields(taos, sTableSchema, point->childTableName, cTablePoints); + if (code != 0) { + tscError("Apply child table fields failed. child table %s, error %s", point->childTableName, tstrerror(code)); + goto cleanup; + } + + tscDebug("successfully applied data points of child table %s", point->childTableName); + pCTablePoints = taosHashIterate(cname2points, pCTablePoints); } +cleanup: + pCTablePoints = taosHashIterate(cname2points, NULL); + while (pCTablePoints) { + SArray* pPoints = *pCTablePoints; + taosArrayDestroy(pPoints); + pCTablePoints = taosHashIterate(cname2points, pCTablePoints); + } taosHashCleanup(cname2points); return code; } @@ -849,15 +985,15 @@ int taos_sml_insert(TAOS* taos, TAOS_SML_DATA_POINT* points, int numPoint) { goto clean_up; } - code = reconcileDBSchemas(taos, stableSchemas); + code = modifyDBSchemas(taos, stableSchemas); if (code != 0) { tscError("error change db schema : %s", tstrerror(code)); goto clean_up; } - code = insertPoints(taos, points, numPoint, stableSchemas); + code = applyDataPoints(taos, points, numPoint, stableSchemas); if (code != 0) { - tscError("error insert points : %s", tstrerror(code)); + tscError("error apply data points : %s", tstrerror(code)); } clean_up: @@ -1823,6 +1959,8 @@ int taos_insert_lines(TAOS* taos, char* lines[], int numLines) { cleanup: tscDebug("taos_insert_lines finish inserting %d lines. code: %d", numLines, code); + points = TARRAY_GET_START(lpPoints); + numPoints = taosArrayGetSize(lpPoints); for (int i=0; iname, &fullname, sizeof(fullname)); - code = tscGetTableMeta(pSql, pTableMetaInfo); + code = tscGetTableMetaEx(pSql, pTableMetaInfo, false, true); if (code != TSDB_CODE_SUCCESS) { STMT_RET(code); } diff --git a/src/client/src/tscProfile.c b/src/client/src/tscProfile.c index 661bd602b3..70a3e03d62 100644 --- a/src/client/src/tscProfile.c +++ b/src/client/src/tscProfile.c @@ -16,6 +16,7 @@ #include "os.h" #include "tscLog.h" #include "tsclient.h" +#include "tsocket.h" #include "ttimer.h" #include "tutil.h" #include "taosmsg.h" @@ -228,7 +229,7 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) { SHeartBeatMsg *pHeartbeat = pMsg; int allocedQueriesNum = pHeartbeat->numOfQueries; int allocedStreamsNum = pHeartbeat->numOfStreams; - + pHeartbeat->numOfQueries = 0; SQueryDesc *pQdesc = (SQueryDesc *)pHeartbeat->pData; @@ -252,6 +253,16 @@ int tscBuildQueryStreamDesc(void *pMsg, STscObj *pObj) { //pQdesc->useconds = htobe64(pSql->res.useconds); pQdesc->useconds = htobe64(now - pSql->stime); pQdesc->qId = htobe64(pSql->res.qId); + pQdesc->sqlObjId = htobe64(pSql->self); + pQdesc->pid = pHeartbeat->pid; + if (pSql->cmd.pQueryInfo->stableQuery == true) { + pQdesc->numOfSub = pSql->subState.numOfSub; + } else { + pQdesc->numOfSub = 1; + } + pQdesc->numOfSub = htonl(pQdesc->numOfSub); + + taosGetFqdn(pQdesc->fqdn); pHeartbeat->numOfQueries++; pQdesc++; diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index fef9aafad0..48ce465a7e 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -6020,7 +6020,7 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { int16_t i; uint32_t nLen = 0; for (i = 0; i < numOfColumns; ++i) { - nLen += pSchema[i].colId != columnIndex.columnIndex ? pSchema[i].bytes : pItem->bytes; + nLen += (i != columnIndex.columnIndex) ? pSchema[i].bytes : pItem->bytes; } if (nLen >= TSDB_MAX_BYTES_PER_ROW) { return invalidOperationMsg(pMsg, msg24); @@ -6066,14 +6066,14 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { return invalidOperationMsg(pMsg, msg22); } - SSchema* pSchema = (SSchema*) pTableMetaInfo->pTableMeta->schema; - int16_t numOfColumns = pTableMetaInfo->pTableMeta->tableInfo.numOfColumns; + SSchema* pSchema = tscGetTableTagSchema(pTableMetaInfo->pTableMeta); + int16_t numOfTags = tscGetNumOfTags(pTableMetaInfo->pTableMeta); int16_t i; uint32_t nLen = 0; - for (i = 0; i < numOfColumns; ++i) { - nLen += pSchema[i].colId != columnIndex.columnIndex ? pSchema[i].bytes : pItem->bytes; + for (i = 0; i < numOfTags; ++i) { + nLen += (i != columnIndex.columnIndex) ? pSchema[i].bytes : pItem->bytes; } - if (nLen >= TSDB_MAX_BYTES_PER_ROW) { + if (nLen >= TSDB_MAX_TAGS_LEN) { return invalidOperationMsg(pMsg, msg24); } diff --git a/src/client/src/tscServer.c b/src/client/src/tscServer.c index 8276ec4359..b60a28b9fd 100644 --- a/src/client/src/tscServer.c +++ b/src/client/src/tscServer.c @@ -2788,7 +2788,7 @@ int32_t getMultiTableMetaFromMnode(SSqlObj *pSql, SArray* pNameList, SArray* pVg return code; } -int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool autocreate) { +int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool autocreate, bool onlyLocal) { assert(tIsValidName(&pTableMetaInfo->name)); uint32_t size = tscGetTableMetaMaxSize(); @@ -2834,15 +2834,20 @@ int32_t tscGetTableMetaImpl(SSqlObj* pSql, STableMetaInfo *pTableMetaInfo, bool } return TSDB_CODE_SUCCESS; } + + if (onlyLocal) { + return TSDB_CODE_TSC_NO_META_CACHED; + } + return getTableMetaFromMnode(pSql, pTableMetaInfo, autocreate); } int32_t tscGetTableMeta(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo) { - return tscGetTableMetaImpl(pSql, pTableMetaInfo, false); + return tscGetTableMetaImpl(pSql, pTableMetaInfo, false, false); } -int tscGetTableMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool createIfNotExists) { - return tscGetTableMetaImpl(pSql, pTableMetaInfo, createIfNotExists); +int tscGetTableMetaEx(SSqlObj *pSql, STableMetaInfo *pTableMetaInfo, bool createIfNotExists, bool onlyLocal) { + return tscGetTableMetaImpl(pSql, pTableMetaInfo, createIfNotExists, onlyLocal); } int32_t tscGetUdfFromNode(SSqlObj *pSql, SQueryInfo* pQueryInfo) { diff --git a/src/common/src/ttypes.c b/src/common/src/ttypes.c index 6021a8f579..13bcfe6480 100644 --- a/src/common/src/ttypes.c +++ b/src/common/src/ttypes.c @@ -38,7 +38,11 @@ const int32_t TYPE_BYTES[15] = { #define DO_STATICS(__sum, __min, __max, __minIndex, __maxIndex, _list, _index) \ do { \ - (__sum) += (_list)[(_index)]; \ + if (_list[(_index)] >= (INT64_MAX - (__sum))) { \ + __sum = INT64_MAX; \ + } else { \ + (__sum) += (_list)[(_index)]; \ + } \ if ((__min) > (_list)[(_index)]) { \ (__min) = (_list)[(_index)]; \ (__minIndex) = (_index); \ diff --git a/src/connector/grafanaplugin b/src/connector/grafanaplugin index 3530c6df09..4a4d79099b 160000 --- a/src/connector/grafanaplugin +++ b/src/connector/grafanaplugin @@ -1 +1 @@ -Subproject commit 3530c6df097134a410bacec6b3cd013ef38a61aa +Subproject commit 4a4d79099b076b8ff12d5b4fdbcba54049a6866d diff --git a/src/connector/jdbc/CMakeLists.txt b/src/connector/jdbc/CMakeLists.txt index 7791317969..b88869e954 100644 --- a/src/connector/jdbc/CMakeLists.txt +++ b/src/connector/jdbc/CMakeLists.txt @@ -8,7 +8,7 @@ IF (TD_MVN_INSTALLED) ADD_CUSTOM_COMMAND(OUTPUT ${JDBC_CMD_NAME} POST_BUILD COMMAND mvn -Dmaven.test.skip=true install -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-*-dist.jar ${LIBRARY_OUTPUT_PATH} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/target/taos-jdbcdriver-2.0.33-dist.jar ${LIBRARY_OUTPUT_PATH} COMMAND mvn -Dmaven.test.skip=true clean -f ${CMAKE_CURRENT_SOURCE_DIR}/pom.xml COMMENT "build jdbc driver") ADD_CUSTOM_TARGET(${JDBC_TARGET_NAME} ALL WORKING_DIRECTORY ${EXECUTABLE_OUTPUT_PATH} DEPENDS ${JDBC_CMD_NAME}) diff --git a/src/connector/jdbc/deploy-pom.xml b/src/connector/jdbc/deploy-pom.xml index 06122372f0..86f498b24a 100755 --- a/src/connector/jdbc/deploy-pom.xml +++ b/src/connector/jdbc/deploy-pom.xml @@ -5,7 +5,7 @@ com.taosdata.jdbc taos-jdbcdriver - 2.0.32 + 2.0.33 jar JDBCDriver diff --git a/src/inc/taoserror.h b/src/inc/taoserror.h index f57e553e3f..2214078f55 100644 --- a/src/inc/taoserror.h +++ b/src/inc/taoserror.h @@ -102,6 +102,7 @@ int32_t* taosGetErrno(); #define TSDB_CODE_TSC_EXCEED_SQL_LIMIT TAOS_DEF_ERROR_CODE(0, 0x0219) //"SQL statement too long check maxSQLLength config") #define TSDB_CODE_TSC_FILE_EMPTY TAOS_DEF_ERROR_CODE(0, 0x021A) //"File is empty") #define TSDB_CODE_TSC_LINE_SYNTAX_ERROR TAOS_DEF_ERROR_CODE(0, 0x021B) //"Syntax error in Line") +#define TSDB_CODE_TSC_NO_META_CACHED TAOS_DEF_ERROR_CODE(0, 0x021C) //"No table meta cached") // mnode #define TSDB_CODE_MND_MSG_NOT_PROCESSED TAOS_DEF_ERROR_CODE(0, 0x0300) //"Message not processed") diff --git a/src/inc/taosmsg.h b/src/inc/taosmsg.h index 2370b909ef..fb5bbe6c2d 100644 --- a/src/inc/taosmsg.h +++ b/src/inc/taosmsg.h @@ -874,6 +874,10 @@ typedef struct { int64_t useconds; int64_t stime; uint64_t qId; + uint64_t sqlObjId; + int32_t pid; + char fqdn[TSDB_FQDN_LEN]; + int32_t numOfSub; } SQueryDesc; typedef struct { diff --git a/src/kit/taosdemo/taosdemo.c b/src/kit/taosdemo/taosdemo.c index f9b147d43d..439e2a476f 100644 --- a/src/kit/taosdemo/taosdemo.c +++ b/src/kit/taosdemo/taosdemo.c @@ -743,8 +743,8 @@ static void printHelp() { "The number of threads. Default is 10."); printf("%s%s%s%s\n", indent, "-i", indent, "The sleep time (ms) between insertion. Default is 0."); - printf("%s%s%s%s%d\n", indent, "-S", indent, - "The timestamp step between insertion. Default is %d.", + printf("%s%s%s%s%d.\n", indent, "-S", indent, + "The timestamp step between insertion. Default is ", DEFAULT_TIMESTAMP_STEP); printf("%s%s%s%s\n", indent, "-r", indent, "The number of records per request. Default is 30000."); @@ -5940,14 +5940,15 @@ static int32_t prepareStbStmt( if (-1 == prepareStbStmtBind( tagsArray, stbInfo, tagRand, -1, -1, false /* is tag */)) { - free(tagsArray); + tmfree(tagsValBuf); + tmfree(tagsArray); return -1; } ret = taos_stmt_set_tbname_tags(stmt, tableName, (TAOS_BIND *)tagsArray); tmfree(tagsValBuf); - tmfree((char *)tagsArray); + tmfree(tagsArray); } else { ret = taos_stmt_set_tbname(stmt, tableName); } diff --git a/src/kit/taosdump/taosdump.c b/src/kit/taosdump/taosdump.c index 5139f98cde..50a58991b8 100644 --- a/src/kit/taosdump/taosdump.c +++ b/src/kit/taosdump/taosdump.c @@ -453,6 +453,8 @@ static error_t parse_opt(int key, char *arg, struct argp_state *state) { case 'E': g_args.end_time = atol(arg); break; + case 'C': + break; case 'B': g_args.data_batch = atoi(arg); if (g_args.data_batch > MAX_RECORDS_PER_REQ) { diff --git a/src/mnode/src/mnodeProfile.c b/src/mnode/src/mnodeProfile.c index cbf713af65..2c117310b3 100644 --- a/src/mnode/src/mnodeProfile.c +++ b/src/mnode/src/mnodeProfile.c @@ -32,6 +32,7 @@ #define CONN_KEEP_TIME (tsShellActivityTimer * 3) #define CONN_CHECK_TIME (tsShellActivityTimer * 2) #define QUERY_ID_SIZE 20 +#define QUERY_OBJ_ID_SIZE 10 #define QUERY_STREAM_SAVE_SIZE 20 static SCacheObj *tsMnodeConnCache = NULL; @@ -361,6 +362,30 @@ static int32_t mnodeGetQueryMeta(STableMetaMsg *pMeta, SShowObj *pShow, void *pC pSchema[cols].bytes = htons(pShow->bytes[cols]); cols++; + pShow->bytes[cols] = QUERY_OBJ_ID_SIZE + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "sql_obj_id"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "pid"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = TSDB_EP_LEN + VARSTR_HEADER_SIZE; + pSchema[cols].type = TSDB_DATA_TYPE_BINARY; + strcpy(pSchema[cols].name, "ep"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + + pShow->bytes[cols] = 4; + pSchema[cols].type = TSDB_DATA_TYPE_INT; + strcpy(pSchema[cols].name, "sub_queries"); + pSchema[cols].bytes = htons(pShow->bytes[cols]); + cols++; + pShow->bytes[cols] = TSDB_SHOW_SQL_LEN + VARSTR_HEADER_SIZE; pSchema[cols].type = TSDB_DATA_TYPE_BINARY; strcpy(pSchema[cols].name, "sql"); @@ -434,6 +459,29 @@ static int32_t mnodeRetrieveQueries(SShowObj *pShow, char *data, int32_t rows, v pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; *(int64_t *)pWrite = htobe64(pDesc->useconds); cols++; + /* + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int64_t *)pWrite = htobe64(pDesc->sqlObjId); + cols++; + */ + snprintf(str, tListLen(str), "0x%08" PRIx64, htobe64(pDesc->sqlObjId)); + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, str, pShow->bytes[cols]); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int32_t *)pWrite = htonl(pDesc->pid); + cols++; + + char epBuf[TSDB_EP_LEN + 1] = {0}; + snprintf(epBuf, tListLen(epBuf), "%s:%u", pDesc->fqdn, pConnObj->port); + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + STR_WITH_MAXSIZE_TO_VARSTR(pWrite, epBuf, pShow->bytes[cols]); + cols++; + + pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; + *(int32_t *)pWrite = htonl(pDesc->numOfSub); + cols++; pWrite = data + pShow->offset[cols] * rows + pShow->bytes[cols] * numOfRows; STR_WITH_MAXSIZE_TO_VARSTR(pWrite, pDesc->sql, pShow->bytes[cols]); diff --git a/src/query/src/qSqlParser.c b/src/query/src/qSqlParser.c index 874ec7b692..eb920b3e17 100644 --- a/src/query/src/qSqlParser.c +++ b/src/query/src/qSqlParser.c @@ -712,9 +712,8 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) { } else { int32_t bytes = -(int32_t)(type->type); if (bytes > (TSDB_MAX_NCHAR_LEN - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE) { - // we have to postpone reporting the error because it cannot be done here - // as pField->bytes is int16_t, use 'TSDB_MAX_NCHAR_LEN + 1' to avoid overflow - bytes = TSDB_MAX_NCHAR_LEN + 1; + // overflowed. set bytes to -1 so that error can be reported + bytes = -1; } else { bytes = bytes * TSDB_NCHAR_SIZE + VARSTR_HEADER_SIZE; } @@ -727,8 +726,8 @@ void tSetColumnType(TAOS_FIELD *pField, SStrToken *type) { } else { int32_t bytes = -(int32_t)(type->type); if (bytes > TSDB_MAX_BINARY_LEN - VARSTR_HEADER_SIZE) { - // refer comment for NCHAR above - bytes = TSDB_MAX_BINARY_LEN + 1; + // overflowed. set bytes to -1 so that error can be reported + bytes = -1; } else { bytes += VARSTR_HEADER_SIZE; } diff --git a/src/util/src/terror.c b/src/util/src/terror.c index 46a33569b2..42fc76e6c9 100644 --- a/src/util/src/terror.c +++ b/src/util/src/terror.c @@ -110,6 +110,8 @@ TAOS_DEFINE_ERROR(TSDB_CODE_TSC_DB_NOT_SELECTED, "Database not specifie TAOS_DEFINE_ERROR(TSDB_CODE_TSC_INVALID_TABLE_NAME, "Table does not exist") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_EXCEED_SQL_LIMIT, "SQL statement too long, check maxSQLLength config") TAOS_DEFINE_ERROR(TSDB_CODE_TSC_FILE_EMPTY, "File is empty") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_LINE_SYNTAX_ERROR, "Syntax error in Line") +TAOS_DEFINE_ERROR(TSDB_CODE_TSC_NO_META_CACHED, "No table meta cached") // mnode TAOS_DEFINE_ERROR(TSDB_CODE_MND_MSG_NOT_PROCESSED, "Message not processed") diff --git a/tests/examples/c/apitest.c b/tests/examples/c/apitest.c index 2b0d36a40f..0817b6deb4 100644 --- a/tests/examples/c/apitest.c +++ b/tests/examples/c/apitest.c @@ -954,7 +954,7 @@ int32_t verify_schema_less(TAOS* taos) { result = taos_query(taos, "drop database if exists test;"); taos_free_result(result); usleep(100000); - result = taos_query(taos, "create database test precision 'us';"); + result = taos_query(taos, "create database test precision 'us' update 1;"); taos_free_result(result); usleep(100000); @@ -963,6 +963,8 @@ int32_t verify_schema_less(TAOS* taos) { taos_free_result(result); usleep(100000); + int code = 0; + char* lines[] = { "st,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", "st,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns", @@ -975,8 +977,8 @@ int32_t verify_schema_less(TAOS* taos) { "stf,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933641000000ns" }; - int code = 0; code = taos_insert_lines(taos, lines , sizeof(lines)/sizeof(char*)); + char* lines2[] = { "stg,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", "stg,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833640000000ns" @@ -989,7 +991,27 @@ int32_t verify_schema_less(TAOS* taos) { "sth,t1=4i64,t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin_stf\",c2=false,c5=5f64,c6=7u64 1626006933654ms" }; code = taos_insert_lines(taos, lines3, 2); - return code; + + char* lines4[] = { + "st123456,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", + "dgtyqodr,t2=5f64,t3=L\"ste\" c1=tRue,c2=4i64,c3=\"iam\" 1626056811823316532ns" + }; + code = taos_insert_lines(taos, lines4, 2); + + char* lines5[] = { + "zqlbgs,id=\"zqlbgs_39302_21680\",t0=f,t1=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\" c0=f,c1=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64 1626006833639000000ns", + "zqlbgs,t9=f,id=\"zqlbgs_39302_21680\",t0=f,t1=127i8,t11=127i8,t2=32767i16,t3=2147483647i32,t4=9223372036854775807i64,t5=11.12345f32,t6=22.123456789f64,t7=\"binaryTagValue\",t8=L\"ncharTagValue\",t10=L\"ncharTagValue\" c10=f,c0=f,c1=127i8,c12=127i8,c2=32767i16,c3=2147483647i32,c4=9223372036854775807i64,c5=11.12345f32,c6=22.123456789f64,c7=\"binaryColValue\",c8=L\"ncharColValue\",c9=7u64,c11=L\"ncharColValue\" 1626006833639000000ns" + }; + code = taos_insert_lines(taos, &lines5[0], 1); + code = taos_insert_lines(taos, &lines5[1], 1); + + + char* lines6[] = { + "st123456,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000ns", + "dgtyqodr,t2=5f64,t3=L\"ste\" c1=tRue,c2=4i64,c3=\"iam\" 1626056811823316532ns" + }; + code = taos_insert_lines(taos, lines6, 2); + return (code); } int main(int argc, char *argv[]) { diff --git a/tests/examples/c/schemaless.c b/tests/examples/c/schemaless.c index d6450914df..8fae408049 100644 --- a/tests/examples/c/schemaless.c +++ b/tests/examples/c/schemaless.c @@ -9,8 +9,8 @@ #include int numSuperTables = 8; -int numChildTables = 1024; -int numRowsPerChildTable = 128; +int numChildTables = 4; +int numRowsPerChildTable = 2048; void shuffle(char**lines, size_t n) { diff --git a/tests/pytest/fulltest.sh b/tests/pytest/fulltest.sh index bdebb5ef35..22d9e0506e 100755 --- a/tests/pytest/fulltest.sh +++ b/tests/pytest/fulltest.sh @@ -44,6 +44,7 @@ python3 ./test.py -f table/del_stable.py #stable python3 ./test.py -f stable/insert.py +python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJsonStmt.py # tag python3 ./test.py -f tag_lite/filter.py @@ -353,8 +354,7 @@ python3 ./test.py -f alter/alter_debugFlag.py python3 ./test.py -f query/queryBetweenAnd.py python3 ./test.py -f tag_lite/alter_tag.py -#python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJson.py -#python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJsonStmt.py +python3 test.py -f tools/taosdemoAllTest/taosdemoTestInsertWithJson.py python3 test.py -f tools/taosdemoAllTest/taosdemoTestQueryWithJson.py python3 test.py -f tools/taosdemoAllTest/TD-4985/query-limit-offset.py python3 ./test.py -f tag_lite/drop_auto_create.py