TDengine/source/libs/command/src/command.c

1337 lines
51 KiB
C
Raw Normal View History

/*
* 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 "command.h"
2025-07-17 06:17:47 +00:00
#include "catalog.h"
2022-07-14 10:42:26 +00:00
#include "commandInt.h"
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
#include "decimal.h"
2022-07-14 10:42:26 +00:00
#include "scheduler.h"
2022-08-24 09:36:10 +00:00
#include "systable.h"
2024-04-23 06:37:18 +00:00
#include "taosdef.h"
#include "tdatablock.h"
2025-02-25 10:21:32 +00:00
#include "tdataformat.h"
#include "tglobal.h"
2022-08-01 11:54:13 +00:00
#include "tgrant.h"
2024-07-15 10:45:41 +00:00
#define COL_DATA_SET_VAL_AND_CHECK(pCol, rows, buf, isNull) \
2024-08-20 09:25:12 +00:00
do { \
int _code = colDataSetVal(pCol, rows, buf, isNull); \
if (TSDB_CODE_SUCCESS != _code) { \
terrno = _code; \
return _code; \
} \
} while (0)
2024-07-15 10:45:41 +00:00
extern SConfig* tsCfg;
static int32_t buildRetrieveTableRsp(SSDataBlock* pBlock, int32_t numOfCols, SRetrieveTableRsp** pRsp) {
2024-11-07 08:19:57 +00:00
if (NULL == pBlock || NULL == pRsp) {
return TSDB_CODE_INVALID_PARA;
}
2024-10-20 14:17:16 +00:00
size_t dataEncodeBufSize = blockGetEncodeSize(pBlock);
size_t rspSize = sizeof(SRetrieveTableRsp) + dataEncodeBufSize + PAYLOAD_PREFIX_LEN;
*pRsp = taosMemoryCalloc(1, rspSize);
if (NULL == *pRsp) {
2024-08-07 08:51:39 +00:00
return terrno;
}
(*pRsp)->useconds = 0;
(*pRsp)->completed = 1;
(*pRsp)->precision = 0;
(*pRsp)->compressed = 0;
(*pRsp)->numOfRows = htobe64((int64_t)pBlock->info.rows);
(*pRsp)->numOfCols = htonl(numOfCols);
2025-02-25 10:21:32 +00:00
int32_t len = 0;
2025-02-25 15:18:13 +00:00
if (pBlock->info.rows > 0) {
2025-02-25 10:21:32 +00:00
len = blockEncode(pBlock, (*pRsp)->data + PAYLOAD_PREFIX_LEN, dataEncodeBufSize, numOfCols);
if (len < 0) {
taosMemoryFree(*pRsp);
*pRsp = NULL;
return terrno;
}
SET_PAYLOAD_LEN((*pRsp)->data, len, len);
2024-08-23 07:51:18 +00:00
}
int32_t payloadLen = len + PAYLOAD_PREFIX_LEN;
(*pRsp)->payloadLen = htonl(payloadLen);
(*pRsp)->compLen = htonl(payloadLen);
return TSDB_CODE_SUCCESS;
}
2022-04-02 07:27:07 +00:00
static int32_t getSchemaBytes(const SSchema* pSchema) {
switch (pSchema->type) {
case TSDB_DATA_TYPE_BINARY:
2023-09-01 05:24:47 +00:00
case TSDB_DATA_TYPE_VARBINARY:
Feature/3.0 geometry (#21037) * Add GEOMETRY data type and make sql.c able to parse it. The GEMETRY works like BINARY so far. * add GEOMETRY type into gConvertTypes to fix some issues like DELETE calling * change some test cases to make sure no same timestamp is inserted, and add my smoketest.sh * Add a function MakePoint() and introduce a lib geometry * implement sql functions GeomFromText() and AsText() * Use GEOS *_r funcions instead for thread safety * Handle with TSDB_DATA_TYPE_GEOMETRY when INSERT geometry data by converting WKT. Add geosWrapper to wrap the basic GEOS functions for TDEngine. * refactor AsText and MakePoint functions to be like GeomFromText * Show WKT when print geometry data in screen Dump hex data when dump geometry data in a file * define TYPE_BYTES item for TSDB_DATA_TYPE_GEOMETRY, which casued some strange issues. * set number of decimals of WKT to 6 * Implement SQL function Intersects() * refactor geometry sql functions * Add geosErrMsgeHandler() to get the GEOS error detail * use threadlocal to instantiate SGeosContext call destroyGeosContext() only if the thread exists * remove SGeosContext *context param for all geometry functions since we use thread local one, so that all caller do not need to know the context. * Modify Intersects() to call PreparedIntersects() when one of param is a constant, which has higher performance. * rename prepareFn() to initCtxFn() to avoid confusion with PreparedFn * Add prefix "ST_" for all geometry functions * move getThreadLocalGeosCtx() and destroyThreadLocalGeosCtx() into util, so that all unit test tools can compile * Add unit test for geometry lib, only test MakePoint so far * refactor and enhance existing cases in geomFuncTest * implement NULL type and NULL value test for geomFuncTest * add test on geomFromText() * add unit test on AsText() in geomFuncTest * combine some makePointFunction test items * add intersectsFunctionTwoColumns test refactor on callGeomFromTextWrapper functions * enhance intersectsFunction test to add cases like input constant , NULL type, NULL value, or wrong content * add more cases into intersectsFunction test * Add basic test on geometry in system test * Add ST_GeomFromText and ST_AsText function test in system test on geometry * add ST_Intersects function test in system test on geometry * support to check expectedErrno in system test on geometry * adjust geomTest unit test and geometry system test * add geometry data type and functions in doc english version * implement touchesFunction() in geometry lib refactor geometry relation functions model * separate gemFuncTest into several src files * add unit test on touchesFunction * support sql function ST_Touches() add system test on ST_Touches * add docs for ST_Touches() * Add ST_Contains() * Add ST_Covers() * Add ST_Equals() * add swapAllowed param for geomRelationFunction() read geom2 earlier intead of at doGeosRelation() * Add ST_ContainsProperly() * build on windows * Merge from 3.0 to 3.0_geometry * change macro definition TSDB_DATA_TYPE_GEOMETRY as the last one for compatibility * change '\\NULL' to 'NULL' back in shellDumpFieldToFile() * add /usr/local/include into include directory * add /usr/local/inlcude and /usr/local/lib in cmake.platform for DARWIN
2023-05-24 07:36:46 +00:00
case TSDB_DATA_TYPE_GEOMETRY:
2022-04-02 07:27:07 +00:00
return (pSchema->bytes - VARSTR_HEADER_SIZE);
case TSDB_DATA_TYPE_NCHAR:
2022-05-23 11:57:49 +00:00
case TSDB_DATA_TYPE_JSON:
2022-04-02 07:27:07 +00:00
return (pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE;
default:
return pSchema->bytes;
}
}
static const char* expandIdentifier(const char* name, char* output) {
if (NULL == name) return "";
bool containsEscapeChar = false;
for (const char* p = name; *p != '\0'; ++p) {
if (*p == TS_ESCAPE_CHAR) {
containsEscapeChar = true;
break;
}
}
if (!containsEscapeChar) return name;
if (NULL == output) return "";
char* out_ptr = output;
for (const char* src = name; *src != '\0'; ++src) {
if (*src == TS_ESCAPE_CHAR) {
*out_ptr++ = TS_ESCAPE_CHAR;
*out_ptr++ = TS_ESCAPE_CHAR;
} else {
*out_ptr++ = *src;
}
}
*out_ptr = '\0';
return output;
}
2022-10-17 07:43:42 +00:00
static int32_t buildDescResultDataBlock(SSDataBlock** pOutput) {
QRY_PARAM_CHECK(pOutput);
2024-07-27 10:55:34 +00:00
SSDataBlock* pBlock = NULL;
2024-08-20 09:25:12 +00:00
int32_t code = createDataBlock(&pBlock);
2024-07-27 10:55:34 +00:00
if (code) {
return code;
2022-10-17 07:43:42 +00:00
}
SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_FIELD_LEN, 1);
2024-07-27 10:55:34 +00:00
code = blockDataAppendColInfo(pBlock, &infoData);
2022-10-17 07:43:42 +00:00
if (TSDB_CODE_SUCCESS == code) {
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_TYPE_LEN, 2);
code = blockDataAppendColInfo(pBlock, &infoData);
}
if (TSDB_CODE_SUCCESS == code) {
infoData = createColumnInfoData(TSDB_DATA_TYPE_INT, tDataTypes[TSDB_DATA_TYPE_INT].bytes, 3);
code = blockDataAppendColInfo(pBlock, &infoData);
}
if (TSDB_CODE_SUCCESS == code) {
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_NOTE_LEN, 4);
code = blockDataAppendColInfo(pBlock, &infoData);
}
2024-03-12 08:46:41 +00:00
if (TSDB_CODE_SUCCESS == code) {
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_COPRESS_OPTION_LEN, 5);
code = blockDataAppendColInfo(pBlock, &infoData);
}
if (TSDB_CODE_SUCCESS == code) {
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_COPRESS_OPTION_LEN, 6);
code = blockDataAppendColInfo(pBlock, &infoData);
}
if (TSDB_CODE_SUCCESS == code) {
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_COPRESS_OPTION_LEN, 7);
code = blockDataAppendColInfo(pBlock, &infoData);
}
if (TSDB_CODE_SUCCESS == code) {
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, DESCRIBE_RESULT_COL_REF_LEN, 8);
code = blockDataAppendColInfo(pBlock, &infoData);
}
2022-10-17 07:43:42 +00:00
if (TSDB_CODE_SUCCESS == code) {
*pOutput = pBlock;
} else {
2024-07-16 03:50:52 +00:00
(void)blockDataDestroy(pBlock);
2022-10-17 07:43:42 +00:00
}
return code;
}
2024-03-13 07:17:43 +00:00
static int32_t setDescResultIntoDataBlock(bool sysInfoUser, SSDataBlock* pBlock, int32_t numOfRows, STableMeta* pMeta,
int8_t biMode) {
2023-09-21 01:55:13 +00:00
int32_t blockCap = (biMode != 0) ? numOfRows + 1 : numOfRows;
2024-07-15 10:45:41 +00:00
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, blockCap));
2022-08-24 09:36:10 +00:00
pBlock->info.rows = 0;
// field
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
// Type
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
// Length
SColumnInfoData* pCol3 = taosArrayGet(pBlock->pDataBlock, 2);
// Note
SColumnInfoData* pCol4 = taosArrayGet(pBlock->pDataBlock, 3);
2024-03-12 08:46:41 +00:00
// encode
2024-03-13 07:17:43 +00:00
SColumnInfoData* pCol5 = NULL;
2024-03-12 08:46:41 +00:00
// compress
2024-03-13 07:17:43 +00:00
SColumnInfoData* pCol6 = NULL;
2024-03-12 08:46:41 +00:00
// level
2024-03-13 07:17:43 +00:00
SColumnInfoData* pCol7 = NULL;
// colref
SColumnInfoData* pCol8 = NULL;
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (withExtSchema(pMeta->tableType)) {
2024-03-13 07:17:43 +00:00
pCol5 = taosArrayGet(pBlock->pDataBlock, 4);
pCol6 = taosArrayGet(pBlock->pDataBlock, 5);
pCol7 = taosArrayGet(pBlock->pDataBlock, 6);
}
if (hasRefCol(pMeta->tableType)) {
pCol5 = taosArrayGet(pBlock->pDataBlock, 4);
}
2024-04-23 06:37:18 +00:00
int32_t fillTagCol = 0;
char buf[DESCRIBE_RESULT_FIELD_LEN] = {0};
for (int32_t i = 0; i < numOfRows; ++i) {
2022-08-24 09:36:10 +00:00
if (invisibleColumn(sysInfoUser, pMeta->tableType, pMeta->schema[i].flags)) {
continue;
}
STR_TO_VARSTR(buf, pMeta->schema[i].name);
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol1, pBlock->info.rows, buf, false);
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (IS_DECIMAL_TYPE(pMeta->schema[i].type) && withExtSchema(pMeta->tableType)) {
uint8_t prec = 0, scale = 0;
decimalFromTypeMod(pMeta->schemaExt[i].typeMod, &prec, &scale);
size_t len = snprintf(buf + VARSTR_HEADER_SIZE, DESCRIBE_RESULT_FIELD_LEN - VARSTR_HEADER_SIZE, "%s(%hhu, %hhu)",
tDataTypes[pMeta->schema[i].type].name, prec, scale);
varDataSetLen(buf, len);
} else {
STR_TO_VARSTR(buf, tDataTypes[pMeta->schema[i].type].name);
}
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol2, pBlock->info.rows, buf, false);
2022-08-24 09:36:10 +00:00
int32_t bytes = getSchemaBytes(pMeta->schema + i);
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol3, pBlock->info.rows, (const char*)&bytes, false);
2023-10-11 10:49:47 +00:00
if (TSDB_VIEW_TABLE != pMeta->tableType) {
2024-03-19 08:31:51 +00:00
if (i >= pMeta->tableInfo.numOfColumns) {
STR_TO_VARSTR(buf, "TAG");
2024-04-23 06:37:18 +00:00
fillTagCol = 1;
2024-03-19 08:31:51 +00:00
} else if (i == 1 && pMeta->schema[i].flags & COL_IS_KEY) {
STR_TO_VARSTR(buf, "COMPOSITE KEY")
2024-03-19 08:31:51 +00:00
} else {
STR_TO_VARSTR(buf, "");
}
2023-10-11 10:49:47 +00:00
} else {
2023-10-20 00:41:49 +00:00
STR_TO_VARSTR(buf, "VIEW COL");
2023-10-11 10:49:47 +00:00
}
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol4, pBlock->info.rows, buf, false);
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
if (withExtSchema(pMeta->tableType) && pMeta->schemaExt) {
2024-03-13 07:17:43 +00:00
if (i < pMeta->tableInfo.numOfColumns) {
STR_TO_VARSTR(buf, columnEncodeStr(COMPRESS_L1_TYPE_U32(pMeta->schemaExt[i].compress)));
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol5, pBlock->info.rows, buf, false);
2024-03-13 07:17:43 +00:00
STR_TO_VARSTR(buf, columnCompressStr(COMPRESS_L2_TYPE_U32(pMeta->schemaExt[i].compress)));
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol6, pBlock->info.rows, buf, false);
2024-03-13 07:17:43 +00:00
STR_TO_VARSTR(buf, columnLevelStr(COMPRESS_L2_TYPE_LEVEL_U32(pMeta->schemaExt[i].compress)));
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol7, pBlock->info.rows, buf, false);
2024-03-13 07:17:43 +00:00
} else {
2024-04-23 06:37:18 +00:00
STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol5, pBlock->info.rows, buf, false);
2024-04-23 06:37:18 +00:00
STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol6, pBlock->info.rows, buf, false);
2024-04-23 06:37:18 +00:00
STR_TO_VARSTR(buf, fillTagCol == 0 ? "" : "disabled");
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol7, pBlock->info.rows, buf, false);
2024-03-13 07:17:43 +00:00
}
} else if (hasRefCol(pMeta->tableType) && pMeta->colRef) {
if (i < pMeta->numOfColRefs) {
if (pMeta->colRef[i].hasRef) {
char refColName[TSDB_DB_NAME_LEN + TSDB_NAME_DELIMITER_LEN + TSDB_COL_FNAME_LEN] = {0};
strcat(refColName, pMeta->colRef[i].refDbName);
strcat(refColName, ".");
strcat(refColName, pMeta->colRef[i].refTableName);
strcat(refColName, ".");
strcat(refColName, pMeta->colRef[i].refColName);
STR_TO_VARSTR(buf, refColName);
} else {
STR_TO_VARSTR(buf, "");
}
COL_DATA_SET_VAL_AND_CHECK(pCol5, pBlock->info.rows, buf, false);
} else {
STR_TO_VARSTR(buf, "");
COL_DATA_SET_VAL_AND_CHECK(pCol5, pBlock->info.rows, buf, false);
}
2024-03-12 08:46:41 +00:00
}
2024-03-13 07:17:43 +00:00
2024-04-23 06:37:18 +00:00
fillTagCol = 0;
2022-08-24 09:36:10 +00:00
++(pBlock->info.rows);
}
if (pMeta->tableType == TSDB_SUPER_TABLE && biMode != 0) {
2023-09-18 08:59:07 +00:00
STR_TO_VARSTR(buf, "tbname");
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol1, pBlock->info.rows, buf, false);
2023-09-18 08:59:07 +00:00
STR_TO_VARSTR(buf, "VARCHAR");
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol2, pBlock->info.rows, buf, false);
2023-09-18 08:59:07 +00:00
int32_t bytes = TSDB_TABLE_NAME_LEN - 1;
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol3, pBlock->info.rows, (const char*)&bytes, false);
2023-09-18 08:59:07 +00:00
STR_TO_VARSTR(buf, "TAG");
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol4, pBlock->info.rows, buf, false);
2023-09-18 08:59:07 +00:00
++(pBlock->info.rows);
}
if (pBlock->info.rows <= 0) {
qError("no permission to view any columns");
return TSDB_CODE_PAR_PERMISSION_DENIED;
}
return TSDB_CODE_SUCCESS;
}
2023-09-18 08:59:07 +00:00
static int32_t execDescribe(bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp, int8_t biMode) {
SDescribeStmt* pDesc = (SDescribeStmt*)pStmt;
2024-11-07 08:19:57 +00:00
if (NULL == pDesc || NULL == pDesc->pMeta) {
return TSDB_CODE_INVALID_PARA;
}
2024-11-26 08:08:16 +00:00
int32_t numOfRows = TABLE_TOTAL_COL_NUM(pDesc->pMeta);
2022-10-17 07:43:42 +00:00
SSDataBlock* pBlock = NULL;
int32_t code = buildDescResultDataBlock(&pBlock);
if (TSDB_CODE_SUCCESS == code) {
2023-09-18 08:59:07 +00:00
code = setDescResultIntoDataBlock(sysInfoUser, pBlock, numOfRows, pDesc->pMeta, biMode);
2022-10-17 07:43:42 +00:00
}
if (TSDB_CODE_SUCCESS == code) {
if (pDesc->pMeta) {
if (withExtSchema(pDesc->pMeta->tableType) && pDesc->pMeta->schemaExt) {
code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS_COMPRESS, pRsp);
} else if (hasRefCol(pDesc->pMeta->tableType) && pDesc->pMeta->colRef) {
code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS_REF, pRsp);
} else {
code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS, pRsp);
}
2024-03-13 07:17:43 +00:00
} else {
code = buildRetrieveTableRsp(pBlock, DESCRIBE_RESULT_COLS, pRsp);
}
2022-10-17 07:43:42 +00:00
}
2024-07-16 03:50:52 +00:00
(void)blockDataDestroy(pBlock);
2022-10-17 07:43:42 +00:00
return code;
}
static int32_t execResetQueryCache() { return catalogClearCache(); }
2022-10-17 07:43:42 +00:00
static int32_t buildCreateDBResultDataBlock(SSDataBlock** pOutput) {
QRY_PARAM_CHECK(pOutput);
2024-07-27 10:55:34 +00:00
SSDataBlock* pBlock = NULL;
2024-08-20 09:25:12 +00:00
int32_t code = createDataBlock(&pBlock);
2024-07-27 10:55:34 +00:00
if (code) {
return code;
2022-10-17 07:43:42 +00:00
}
2022-06-22 09:36:48 +00:00
SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_DB_RESULT_COLS, 1);
2024-07-27 10:55:34 +00:00
code = blockDataAppendColInfo(pBlock, &infoData);
2022-10-17 07:43:42 +00:00
if (TSDB_CODE_SUCCESS == code) {
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_DB_RESULT_FIELD2_LEN, 2);
code = blockDataAppendColInfo(pBlock, &infoData);
}
2022-06-18 11:50:53 +00:00
2022-10-17 07:43:42 +00:00
if (TSDB_CODE_SUCCESS == code) {
*pOutput = pBlock;
} else {
2024-07-16 03:50:52 +00:00
(void)blockDataDestroy(pBlock);
2022-10-17 07:43:42 +00:00
}
return code;
2022-06-18 11:50:53 +00:00
}
int64_t getValOfDiffPrecision(int8_t unit, int64_t val) {
int64_t v = 0;
switch (unit) {
case 's':
v = val / 1000;
break;
case 'm':
v = val / tsTickPerMin[TSDB_TIME_PRECISION_MILLI];
break;
case 'h':
v = val / (tsTickPerMin[TSDB_TIME_PRECISION_MILLI] * 60);
break;
case 'd':
v = val / (tsTickPerMin[TSDB_TIME_PRECISION_MILLI] * 24 * 60);
break;
case 'w':
v = val / (tsTickPerMin[TSDB_TIME_PRECISION_MILLI] * 24 * 60 * 7);
break;
default:
break;
}
return v;
}
2024-08-20 09:25:12 +00:00
static int32_t buildRetension(SArray* pRetension, char** ppRetentions) {
2022-06-18 11:50:53 +00:00
size_t size = taosArrayGetSize(pRetension);
if (size == 0) {
2024-07-15 10:45:41 +00:00
*ppRetentions = NULL;
return TSDB_CODE_SUCCESS;
2022-06-18 11:50:53 +00:00
}
2024-10-08 06:25:51 +00:00
const int lMaxLen = 128;
char* p1 = taosMemoryCalloc(1, lMaxLen);
2024-08-20 09:25:12 +00:00
if (NULL == p1) {
2024-08-07 08:51:39 +00:00
return terrno;
2024-07-15 10:45:41 +00:00
}
2022-06-18 11:50:53 +00:00
int32_t len = 0;
for (int32_t i = 0; i < size; ++i) {
SRetention* p = TARRAY_GET_ELEM(pRetension, i);
int64_t v1 = getValOfDiffPrecision(p->freqUnit, p->freq);
int64_t v2 = getValOfDiffPrecision(p->keepUnit, p->keep);
if (i == 0) {
2024-10-10 02:35:48 +00:00
len += tsnprintf(p1 + len, lMaxLen - len, "-:%" PRId64 "%c", v2, p->keepUnit);
} else {
2024-10-10 02:35:48 +00:00
len += tsnprintf(p1 + len, lMaxLen - len, "%" PRId64 "%c:%" PRId64 "%c", v1, p->freqUnit, v2, p->keepUnit);
}
2022-06-18 11:50:53 +00:00
if (i < size - 1) {
2024-10-10 02:35:48 +00:00
len += tsnprintf(p1 + len, lMaxLen - len, ",");
}
2022-06-18 11:50:53 +00:00
}
2024-07-15 10:45:41 +00:00
*ppRetentions = p1;
return TSDB_CODE_SUCCESS;
2022-06-18 11:50:53 +00:00
}
2022-08-02 12:20:44 +00:00
static const char* cacheModelStr(int8_t cacheModel) {
switch (cacheModel) {
case TSDB_CACHE_MODEL_NONE:
return TSDB_CACHE_MODEL_NONE_STR;
case TSDB_CACHE_MODEL_LAST_ROW:
return TSDB_CACHE_MODEL_LAST_ROW_STR;
case TSDB_CACHE_MODEL_LAST_VALUE:
return TSDB_CACHE_MODEL_LAST_VALUE_STR;
case TSDB_CACHE_MODEL_BOTH:
return TSDB_CACHE_MODEL_BOTH_STR;
default:
break;
}
return TSDB_CACHE_MODEL_NONE_STR;
}
2024-03-27 12:03:38 +00:00
static const char* encryptAlgorithmStr(int8_t encryptAlgorithm) {
switch (encryptAlgorithm) {
case TSDB_ENCRYPT_ALGO_NONE:
return TSDB_ENCRYPT_ALGO_NONE_STR;
case TSDB_ENCRYPT_ALGO_SM4:
return TSDB_ENCRYPT_ALGO_SM4_STR;
default:
break;
}
return TSDB_CACHE_MODEL_NONE_STR;
}
2024-10-09 01:45:56 +00:00
int32_t formatDurationOrKeep(char* buffer, int64_t bufSize, int32_t timeInMinutes) {
if (buffer == NULL || bufSize <= 0) {
return 0;
}
int32_t len = 0;
if (timeInMinutes % 1440 == 0) {
int32_t days = timeInMinutes / 1440;
len = tsnprintf(buffer, bufSize, "%dd", days);
} else if (timeInMinutes % 60 == 0) {
int32_t hours = timeInMinutes / 60;
len = tsnprintf(buffer, bufSize, "%dh", hours);
} else {
len = tsnprintf(buffer, bufSize, "%dm", timeInMinutes);
}
return len;
}
2024-07-15 10:45:41 +00:00
static int32_t setCreateDBResultIntoDataBlock(SSDataBlock* pBlock, char* dbName, char* dbFName, SDbCfgInfo* pCfg) {
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
2022-06-18 11:50:53 +00:00
pBlock->info.rows = 1;
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
char buf1[SHOW_CREATE_DB_RESULT_FIELD1_LEN] = {0};
STR_TO_VARSTR(buf1, dbName);
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol1, 0, buf1, false);
2022-06-18 11:50:53 +00:00
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
char buf2[SHOW_CREATE_DB_RESULT_FIELD2_LEN] = {0};
int32_t len = 0;
char* prec = NULL;
2022-06-18 11:50:53 +00:00
switch (pCfg->precision) {
case TSDB_TIME_PRECISION_MILLI:
prec = TSDB_TIME_PRECISION_MILLI_STR;
break;
case TSDB_TIME_PRECISION_MICRO:
prec = TSDB_TIME_PRECISION_MICRO_STR;
break;
case TSDB_TIME_PRECISION_NANO:
prec = TSDB_TIME_PRECISION_NANO_STR;
break;
default:
prec = "none";
break;
}
2024-08-20 09:25:12 +00:00
char* pRetentions = NULL;
2024-07-15 10:45:41 +00:00
QRY_ERR_RET(buildRetension(pCfg->pRetensions, &pRetentions));
int32_t dbFNameLen = strlen(dbFName);
int32_t hashPrefix = 0;
if (pCfg->hashPrefix > 0) {
hashPrefix = pCfg->hashPrefix - dbFNameLen - 1;
} else if (pCfg->hashPrefix < 0) {
hashPrefix = pCfg->hashPrefix + dbFNameLen + 1;
}
2024-09-11 01:11:56 +00:00
char durationStr[128] = {0};
char keep0Str[128] = {0};
char keep1Str[128] = {0};
char keep2Str[128] = {0};
2024-12-04 07:46:42 +00:00
char compactIntervalStr[13] = {0};
char compactStartTimeStr[13] = {0};
char compactEndTimeStr[13] = {0};
2024-09-11 01:11:56 +00:00
2024-10-09 01:45:56 +00:00
int32_t lenDuration = formatDurationOrKeep(durationStr, sizeof(durationStr), pCfg->daysPerFile);
int32_t lenKeep0 = formatDurationOrKeep(keep0Str, sizeof(keep0Str), pCfg->daysToKeep0);
int32_t lenKeep1 = formatDurationOrKeep(keep1Str, sizeof(keep1Str), pCfg->daysToKeep1);
int32_t lenKeep2 = formatDurationOrKeep(keep2Str, sizeof(keep2Str), pCfg->daysToKeep2);
2024-12-04 07:46:42 +00:00
UNUSED(formatDurationOrKeep(compactIntervalStr, sizeof(compactIntervalStr), pCfg->compactInterval));
UNUSED(formatDurationOrKeep(compactStartTimeStr, sizeof(compactStartTimeStr), pCfg->compactStartTime));
UNUSED(formatDurationOrKeep(compactEndTimeStr, sizeof(compactEndTimeStr), pCfg->compactEndTime));
2024-09-11 01:11:56 +00:00
2023-07-11 05:56:02 +00:00
if (IS_SYS_DBNAME(dbName)) {
2024-10-10 02:35:48 +00:00
len += tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_DB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
"CREATE DATABASE `%s`", dbName);
} else {
len +=
tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_DB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
"CREATE DATABASE `%s` BUFFER %d CACHESIZE %d CACHEMODEL '%s' COMP %d DURATION %s "
"WAL_FSYNC_PERIOD %d MAXROWS %d MINROWS %d STT_TRIGGER %d KEEP %s,%s,%s PAGES %d PAGESIZE %d "
"PRECISION '%s' REPLICA %d "
"WAL_LEVEL %d VGROUPS %d SINGLE_STABLE %d TABLE_PREFIX %d TABLE_SUFFIX %d TSDB_PAGESIZE %d "
"WAL_RETENTION_PERIOD %d WAL_RETENTION_SIZE %" PRId64
feat[ts-6107]: shared storage (#31552) * add API to use s3 as shared storage * support using local file system as shared storage * upload file to shared storage * support read, compact and drop * finish basic mnode & vnode msg processing * follower sync migration state * implement mnode transaction, and improve log * send migration progress msg to dnode to avoid deadlock * implement following migration * remove mcount * avoid redo migration on startup * avoid follower deadlock when leader is down * trigger migrate by timer, avoid compact after migration * comment out the usage of 'tcs' functions in stream * change config item prefix from s3 to ss * change db option prefix from s3 to ss * rename s3 data struct, function, file to ss * rename s3 macro to ss * update s3 sql to ss * rename remaining s3 items to ss * check ss configruation, improve s3 retry * grant object storage -> shared storage, check ssEnabled * fix memory leaks * update build options * omit sensitive information when dump config * fix backward compatibility issue * fix issues found in ci-checks * fix some failed test cases * avoid follower timeout and improve log * fix: follower timeout because migration status not updated * refuse migration if there's an in progress one * fix ss test case * remove garbage files and other minor improvement * fix failed test cases * update unit test * fix failed test case * fix failed test case * update document * update document and fix failed test cases * fix minor issues in code, test and document * check new commit after migration task is scheduled * fix several issus 1. migrate information cannot be dropped sometimes because progress response was put into read queue. 2. memory leak in rare cases 3. data corruption in rare cases 4. failed test case * add shared storage upgrade tool * fix compile error
2025-07-14 08:33:53 +00:00
" KEEP_TIME_OFFSET %d ENCRYPT_ALGORITHM '%s' SS_CHUNKPAGES %d SS_KEEPLOCAL %dm SS_COMPACT %d "
2024-12-04 07:46:42 +00:00
"COMPACT_INTERVAL %s COMPACT_TIME_RANGE %s,%s COMPACT_TIME_OFFSET %"PRIi8 "h",
dbName, pCfg->buffer, pCfg->cacheSize, cacheModelStr(pCfg->cacheLast), pCfg->compression, durationStr,
pCfg->walFsyncPeriod, pCfg->maxRows, pCfg->minRows, pCfg->sstTrigger, keep0Str, keep1Str, keep2Str,
pCfg->pages, pCfg->pageSize, prec, pCfg->replications, pCfg->walLevel, pCfg->numOfVgroups,
1 == pCfg->numOfStables, hashPrefix, pCfg->hashSuffix, pCfg->tsdbPageSize, pCfg->walRetentionPeriod,
pCfg->walRetentionSize, pCfg->keepTimeOffset, encryptAlgorithmStr(pCfg->encryptAlgorithm),
feat[ts-6107]: shared storage (#31552) * add API to use s3 as shared storage * support using local file system as shared storage * upload file to shared storage * support read, compact and drop * finish basic mnode & vnode msg processing * follower sync migration state * implement mnode transaction, and improve log * send migration progress msg to dnode to avoid deadlock * implement following migration * remove mcount * avoid redo migration on startup * avoid follower deadlock when leader is down * trigger migrate by timer, avoid compact after migration * comment out the usage of 'tcs' functions in stream * change config item prefix from s3 to ss * change db option prefix from s3 to ss * rename s3 data struct, function, file to ss * rename s3 macro to ss * update s3 sql to ss * rename remaining s3 items to ss * check ss configruation, improve s3 retry * grant object storage -> shared storage, check ssEnabled * fix memory leaks * update build options * omit sensitive information when dump config * fix backward compatibility issue * fix issues found in ci-checks * fix some failed test cases * avoid follower timeout and improve log * fix: follower timeout because migration status not updated * refuse migration if there's an in progress one * fix ss test case * remove garbage files and other minor improvement * fix failed test cases * update unit test * fix failed test case * fix failed test case * update document * update document and fix failed test cases * fix minor issues in code, test and document * check new commit after migration task is scheduled * fix several issus 1. migrate information cannot be dropped sometimes because progress response was put into read queue. 2. memory leak in rare cases 3. data corruption in rare cases 4. failed test case * add shared storage upgrade tool * fix compile error
2025-07-14 08:33:53 +00:00
pCfg->ssChunkSize, pCfg->ssKeepLocal, pCfg->ssCompact, compactIntervalStr, compactStartTimeStr,
2024-12-04 07:46:42 +00:00
compactEndTimeStr, pCfg->compactTimeOffset);
2023-07-11 05:56:02 +00:00
2024-07-15 10:45:41 +00:00
if (pRetentions) {
len += tsnprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_DB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
" RETENTIONS %s", pRetentions);
2023-07-11 05:56:02 +00:00
}
2022-06-18 11:50:53 +00:00
}
2024-07-15 10:45:41 +00:00
taosMemoryFree(pRetentions);
2023-09-06 02:57:49 +00:00
2022-06-18 11:50:53 +00:00
(varDataLen(buf2)) = len;
2024-07-15 10:45:41 +00:00
COL_DATA_SET_VAL_AND_CHECK(pCol2, 0, buf2, false);
return TSDB_CODE_SUCCESS;
2022-06-18 11:50:53 +00:00
}
static int32_t execShowCreateDatabase(SShowCreateDatabaseStmt* pStmt, SRetrieveTableRsp** pRsp) {
2022-10-17 07:43:42 +00:00
SSDataBlock* pBlock = NULL;
int32_t code = buildCreateDBResultDataBlock(&pBlock);
if (TSDB_CODE_SUCCESS == code) {
2024-07-15 10:45:41 +00:00
code = setCreateDBResultIntoDataBlock(pBlock, pStmt->dbName, pStmt->dbFName, pStmt->pCfg);
2022-10-17 07:43:42 +00:00
}
if (TSDB_CODE_SUCCESS == code) {
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_DB_RESULT_COLS, pRsp);
}
2024-07-16 03:50:52 +00:00
(void)blockDataDestroy(pBlock);
2022-10-17 07:43:42 +00:00
return code;
2022-06-18 11:50:53 +00:00
}
2022-10-17 07:43:42 +00:00
static int32_t buildCreateTbResultDataBlock(SSDataBlock** pOutput) {
QRY_PARAM_CHECK(pOutput);
2024-07-27 10:55:34 +00:00
SSDataBlock* pBlock = NULL;
2024-08-20 09:25:12 +00:00
int32_t code = createDataBlock(&pBlock);
2024-07-27 10:55:34 +00:00
if (code) {
return code;
2022-10-17 07:43:42 +00:00
}
2022-06-20 12:58:36 +00:00
2022-06-22 09:36:48 +00:00
SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_TB_RESULT_FIELD1_LEN, 1);
2024-07-27 10:55:34 +00:00
code = blockDataAppendColInfo(pBlock, &infoData);
2022-10-17 07:43:42 +00:00
if (TSDB_CODE_SUCCESS == code) {
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_TB_RESULT_FIELD2_LEN, 2);
code = blockDataAppendColInfo(pBlock, &infoData);
}
2022-06-20 12:58:36 +00:00
2022-10-17 07:43:42 +00:00
if (TSDB_CODE_SUCCESS == code) {
*pOutput = pBlock;
} else {
2024-07-16 03:50:52 +00:00
(void)blockDataDestroy(pBlock);
2022-10-17 07:43:42 +00:00
}
return code;
2022-06-20 12:58:36 +00:00
}
2023-10-11 02:38:22 +00:00
static int32_t buildCreateViewResultDataBlock(SSDataBlock** pOutput) {
QRY_PARAM_CHECK(pOutput);
2024-07-27 10:55:34 +00:00
SSDataBlock* pBlock = NULL;
2024-08-20 09:25:12 +00:00
int32_t code = createDataBlock(&pBlock);
2024-07-27 10:55:34 +00:00
if (code) {
return code;
2023-10-11 02:38:22 +00:00
}
SColumnInfoData infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_VIEW_RESULT_FIELD1_LEN, 1);
2024-07-27 10:55:34 +00:00
code = blockDataAppendColInfo(pBlock, &infoData);
2023-10-11 02:38:22 +00:00
if (TSDB_CODE_SUCCESS == code) {
infoData = createColumnInfoData(TSDB_DATA_TYPE_VARCHAR, SHOW_CREATE_VIEW_RESULT_FIELD2_LEN, 2);
code = blockDataAppendColInfo(pBlock, &infoData);
}
if (TSDB_CODE_SUCCESS == code) {
*pOutput = pBlock;
} else {
2024-07-16 03:50:52 +00:00
(void)blockDataDestroy(pBlock);
2023-10-11 02:38:22 +00:00
}
return code;
}
2024-11-07 08:19:57 +00:00
static void appendColumnFields(char* buf, int32_t* len, STableCfg* pCfg) {
char expandName[(SHOW_CREATE_TB_RESULT_FIELD1_LEN << 1) + 1] = {0};
2022-06-20 12:58:36 +00:00
for (int32_t i = 0; i < pCfg->numOfColumns; ++i) {
SSchema* pSchema = pCfg->pSchemas + i;
SColRef* pRef = pCfg->pColRefs + i;
2025-07-17 06:17:47 +00:00
#define LTYPE_LEN \
(32 + 60 + TSDB_COL_FNAME_LEN + TSDB_DB_NAME_LEN + \
10) // 60 byte for compress info, TSDB_COL_FNAME_LEN + TSDB_DB_NAME_LEN for column ref
2024-10-08 06:25:51 +00:00
char type[LTYPE_LEN];
snprintf(type, LTYPE_LEN, "%s", tDataTypes[pSchema->type].name);
int typeLen = strlen(type);
2024-04-23 06:37:18 +00:00
if (TSDB_DATA_TYPE_VARCHAR == pSchema->type || TSDB_DATA_TYPE_VARBINARY == pSchema->type ||
TSDB_DATA_TYPE_GEOMETRY == pSchema->type) {
2024-10-12 10:40:56 +00:00
typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, "(%d)", (int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE));
2022-06-20 12:58:36 +00:00
} else if (TSDB_DATA_TYPE_NCHAR == pSchema->type) {
2024-10-20 14:36:52 +00:00
typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, "(%d)",
(int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
} else if (IS_DECIMAL_TYPE(pSchema->type)) {
uint8_t precision, scale;
decimalFromTypeMod(pCfg->pSchemaExt[i].typeMod, &precision, &scale);
typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, "(%d,%d)", precision, scale);
2022-06-20 12:58:36 +00:00
}
2025-07-29 02:37:47 +00:00
if (withExtSchema(pCfg->tableType) && pCfg->pSchemaExt && tsShowFullCreateTableColumn) {
2024-10-12 10:40:56 +00:00
typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, " ENCODE \'%s\'",
columnEncodeStr(COMPRESS_L1_TYPE_U32(pCfg->pSchemaExt[i].compress)));
2024-10-12 10:40:56 +00:00
typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, " COMPRESS \'%s\'",
columnCompressStr(COMPRESS_L2_TYPE_U32(pCfg->pSchemaExt[i].compress)));
2024-10-12 10:40:56 +00:00
typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, " LEVEL \'%s\'",
columnLevelStr(COMPRESS_L2_TYPE_LEVEL_U32(pCfg->pSchemaExt[i].compress)));
2024-03-13 03:39:07 +00:00
}
if (hasRefCol(pCfg->tableType) && pCfg->pColRefs && pRef->hasRef) {
typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, " FROM `%s`", pRef->refDbName);
typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, ".");
typeLen +=
tsnprintf(type + typeLen, LTYPE_LEN - typeLen, "`%s`", expandIdentifier(pRef->refTableName, expandName));
typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, ".");
typeLen += tsnprintf(type + typeLen, LTYPE_LEN - typeLen, "`%s`", expandIdentifier(pRef->refColName, expandName));
}
if (!(pSchema->flags & COL_IS_KEY)) {
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
"%s`%s` %s", ((i > 0) ? ", " : ""), expandIdentifier(pSchema->name, expandName), type);
} else {
char* pk = "COMPOSITE KEY";
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
"%s`%s` %s %s", ((i > 0) ? ", " : ""), expandIdentifier(pSchema->name, expandName), type, pk);
}
2022-06-20 12:58:36 +00:00
}
}
static void appendColRefFields(char* buf, int32_t* len, STableCfg* pCfg) {
char expandName[(SHOW_CREATE_TB_RESULT_FIELD1_LEN << 1) + 1] = {0};
for (int32_t i = 1; i < pCfg->numOfColumns; ++i) {
SSchema* pSchema = pCfg->pSchemas + i;
SColRef* pRef = pCfg->pColRefs + i;
2025-07-17 06:17:47 +00:00
char type[TSDB_COL_NAME_LEN + 10 + TSDB_COL_FNAME_LEN + TSDB_DB_NAME_LEN];
int typeLen = 0;
if (hasRefCol(pCfg->tableType) && pCfg->pColRefs && pRef->hasRef) {
typeLen += tsnprintf(type + typeLen, sizeof(type) - typeLen, "FROM `%s`", pRef->refDbName);
typeLen += tsnprintf(type + typeLen, sizeof(type) - typeLen, ".");
typeLen += tsnprintf(type + typeLen, sizeof(type) - typeLen, "`%s`", expandIdentifier(pRef->refTableName, expandName));
typeLen += tsnprintf(type + typeLen, sizeof(type) - typeLen, ".");
typeLen += tsnprintf(type + typeLen, sizeof(type) - typeLen, "`%s`", expandIdentifier(pRef->refColName, expandName));
} else {
continue;
}
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
"%s`%s` %s", ((i > 1) ? ", " : ""), expandIdentifier(pSchema->name, expandName), type);
}
}
2024-11-07 08:19:57 +00:00
static void appendTagFields(char* buf, int32_t* len, STableCfg* pCfg) {
char expandName[(TSDB_COL_NAME_LEN << 1) + 1] = {0};
2022-06-20 12:58:36 +00:00
for (int32_t i = 0; i < pCfg->numOfTags; ++i) {
SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i;
char type[32];
2024-10-09 01:45:56 +00:00
snprintf(type, sizeof(type), "%s", tDataTypes[pSchema->type].name);
2024-04-23 06:37:18 +00:00
if (TSDB_DATA_TYPE_VARCHAR == pSchema->type || TSDB_DATA_TYPE_VARBINARY == pSchema->type ||
TSDB_DATA_TYPE_GEOMETRY == pSchema->type) {
snprintf(type + strlen(type), sizeof(type) - strlen(type), "(%d)",
(int32_t)(pSchema->bytes - VARSTR_HEADER_SIZE));
2022-06-20 12:58:36 +00:00
} else if (TSDB_DATA_TYPE_NCHAR == pSchema->type) {
2024-10-09 01:45:56 +00:00
snprintf(type + strlen(type), sizeof(type) - strlen(type), "(%d)",
2024-10-08 06:25:51 +00:00
(int32_t)((pSchema->bytes - VARSTR_HEADER_SIZE) / TSDB_NCHAR_SIZE));
2022-06-20 12:58:36 +00:00
}
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
"%s`%s` %s", ((i > 0) ? ", " : ""), expandIdentifier(pSchema->name, expandName), type);
2022-06-20 12:58:36 +00:00
}
}
2024-11-07 08:19:57 +00:00
static void appendTagNameFields(char* buf, int32_t* len, STableCfg* pCfg) {
char expandName[(TSDB_COL_NAME_LEN << 1) + 1] = {0};
2022-06-21 01:18:53 +00:00
for (int32_t i = 0; i < pCfg->numOfTags; ++i) {
SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i;
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
"%s`%s`", ((i > 0) ? ", " : ""), expandIdentifier(pSchema->name, expandName));
2022-06-21 01:18:53 +00:00
}
}
2024-12-09 08:15:48 +00:00
static int32_t appendTagValues(char* buf, int32_t* len, STableCfg* pCfg, void* charsetCxt) {
2024-07-21 10:57:08 +00:00
int32_t code = TSDB_CODE_SUCCESS;
SArray* pTagVals = NULL;
STag* pTag = (STag*)pCfg->pTags;
2022-10-18 08:33:27 +00:00
if (NULL == pCfg->pTags || pCfg->numOfTags <= 0) {
qError("tag missed in table cfg, pointer:%p, numOfTags:%d", pCfg->pTags, pCfg->numOfTags);
return TSDB_CODE_APP_ERROR;
}
if (tTagIsJson(pTag)) {
char* pJson = NULL;
2024-12-09 08:15:48 +00:00
parseTagDatatoJson(pTag, &pJson, charsetCxt);
2024-10-08 06:25:51 +00:00
if (NULL == pJson) {
2024-09-14 10:11:36 +00:00
qError("failed to parse tag to json, pJson is NULL");
return terrno;
}
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
"%s", pJson);
taosMemoryFree(pJson);
2022-06-20 12:58:36 +00:00
return TSDB_CODE_SUCCESS;
}
2024-07-15 10:45:41 +00:00
QRY_ERR_RET(tTagToValArray((const STag*)pCfg->pTags, &pTagVals));
2022-06-21 01:18:53 +00:00
int16_t valueNum = taosArrayGetSize(pTagVals);
2022-06-20 12:58:36 +00:00
int32_t num = 0;
2022-06-21 01:18:53 +00:00
int32_t j = 0;
for (int32_t i = 0; i < pCfg->numOfTags; ++i) {
SSchema* pSchema = pCfg->pSchemas + pCfg->numOfColumns + i;
if (i > 0) {
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
", ");
2022-06-21 01:18:53 +00:00
}
2022-06-21 01:18:53 +00:00
if (j >= valueNum) {
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
"NULL");
2022-06-21 01:18:53 +00:00
continue;
}
STagVal* pTagVal = (STagVal*)taosArrayGet(pTagVals, j);
2022-06-21 01:18:53 +00:00
if (pSchema->colId > pTagVal->cid) {
qError("tag value and column mismatch, schemaId:%d, valId:%d", pSchema->colId, pTagVal->cid);
2024-07-21 10:57:08 +00:00
code = TSDB_CODE_APP_ERROR;
TAOS_CHECK_ERRNO(code);
2022-06-21 01:18:53 +00:00
} else if (pSchema->colId == pTagVal->cid) {
char type = pTagVal->type;
int32_t tlen = 0;
2022-06-21 01:18:53 +00:00
2024-10-09 01:45:56 +00:00
int64_t leftSize = SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len);
if (leftSize <= 0) {
qError("no enough space to store tag value, leftSize:%" PRId64, leftSize);
code = TSDB_CODE_APP_ERROR;
TAOS_CHECK_ERRNO(code);
}
2022-06-21 01:18:53 +00:00
if (IS_VAR_DATA_TYPE(type)) {
2024-10-09 01:45:56 +00:00
code = dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, leftSize, type, pTagVal->pData, pTagVal->nData, &tlen);
2024-07-21 10:57:08 +00:00
TAOS_CHECK_ERRNO(code);
2022-06-21 01:18:53 +00:00
} else {
code = dataConverToStr(buf + VARSTR_HEADER_SIZE + *len, leftSize, type, &pTagVal->i64, tDataTypes[type].bytes,
&tlen);
2024-07-21 10:57:08 +00:00
TAOS_CHECK_ERRNO(code);
2022-06-21 01:18:53 +00:00
}
*len += tlen;
j++;
} else {
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
"NULL");
2022-06-21 01:18:53 +00:00
}
2022-06-20 12:58:36 +00:00
}
2024-07-15 10:45:41 +00:00
_exit:
2022-06-21 01:18:53 +00:00
taosArrayDestroy(pTagVals);
2024-07-21 10:57:08 +00:00
return code;
2022-06-20 12:58:36 +00:00
}
2024-11-07 08:19:57 +00:00
static void appendTableOptions(char* buf, int32_t* len, SDbCfgInfo* pDbCfg, STableCfg* pCfg) {
2022-06-20 12:58:36 +00:00
if (pCfg->commentLen > 0) {
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
" COMMENT '%s'", pCfg->pComment);
2022-06-20 12:58:36 +00:00
} else if (0 == pCfg->commentLen) {
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
" COMMENT ''");
2022-06-20 12:58:36 +00:00
}
2022-08-02 12:20:44 +00:00
if (NULL != pDbCfg->pRetensions && pCfg->watermark1 > 0) {
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
" WATERMARK %" PRId64 "a", pCfg->watermark1);
2022-06-20 12:58:36 +00:00
if (pCfg->watermark2 > 0) {
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
", %" PRId64 "a", pCfg->watermark2);
2022-06-20 12:58:36 +00:00
}
}
2022-08-02 12:20:44 +00:00
if (NULL != pDbCfg->pRetensions && pCfg->delay1 > 0) {
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
" MAX_DELAY %" PRId64 "a", pCfg->delay1);
2022-06-20 12:58:36 +00:00
if (pCfg->delay2 > 0) {
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
", %" PRId64 "a", pCfg->delay2);
2022-06-20 12:58:36 +00:00
}
}
int32_t funcNum = taosArrayGetSize(pCfg->pFuncs);
2022-08-02 12:20:44 +00:00
if (NULL != pDbCfg->pRetensions && funcNum > 0) {
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
" ROLLUP(");
2022-06-20 12:58:36 +00:00
for (int32_t i = 0; i < funcNum; ++i) {
char* pFunc = taosArrayGet(pCfg->pFuncs, i);
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
"%s%s", ((i > 0) ? ", " : ""), pFunc);
2022-06-20 12:58:36 +00:00
}
2024-10-08 06:25:51 +00:00
*len +=
snprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len), ")");
2022-06-20 12:58:36 +00:00
}
2022-06-21 10:41:12 +00:00
if (pCfg->ttl > 0) {
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
" TTL %d", pCfg->ttl);
2025-07-17 06:17:47 +00:00
}
if (pCfg->keep > 0) {
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
" KEEP %dm", pCfg->keep);
2022-06-21 10:41:12 +00:00
}
if (TSDB_SUPER_TABLE == pCfg->tableType || TSDB_NORMAL_TABLE == pCfg->tableType) {
int32_t nSma = 0;
for (int32_t i = 0; i < pCfg->numOfColumns; ++i) {
if (IS_BSMA_ON(pCfg->pSchemas + i)) {
++nSma;
}
}
2023-08-10 05:02:34 +00:00
if (nSma < pCfg->numOfColumns && nSma > 0) {
bool smaOn = false;
2024-10-10 02:35:29 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
" SMA(");
for (int32_t i = 0; i < pCfg->numOfColumns; ++i) {
if (IS_BSMA_ON(pCfg->pSchemas + i)) {
if (smaOn) {
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len,
SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len), ",`%s`",
(pCfg->pSchemas + i)->name);
} else {
smaOn = true;
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len,
SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len), "`%s`",
(pCfg->pSchemas + i)->name);
}
}
}
2024-10-10 02:35:48 +00:00
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE, ")");
}
}
if (pCfg->virtualStb) {
*len += tsnprintf(buf + VARSTR_HEADER_SIZE + *len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + *len),
" VIRTUAL %d", pCfg->virtualStb);
}
2022-06-20 12:58:36 +00:00
}
2024-12-11 07:46:44 +00:00
static int32_t setCreateTBResultIntoDataBlock(SSDataBlock* pBlock, SDbCfgInfo* pDbCfg, char* tbName, STableCfg* pCfg,
void* charsetCxt) {
2024-07-21 10:57:08 +00:00
int32_t code = TSDB_CODE_SUCCESS;
2024-07-15 10:45:41 +00:00
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
2022-06-20 12:58:36 +00:00
pBlock->info.rows = 1;
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
char buf1[(SHOW_CREATE_TB_RESULT_FIELD1_LEN << 1)] = {0};
2022-06-20 12:58:36 +00:00
STR_TO_VARSTR(buf1, tbName);
2024-07-15 10:45:41 +00:00
QRY_ERR_RET(colDataSetVal(pCol1, 0, buf1, false));
2022-06-20 12:58:36 +00:00
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
2022-10-21 09:24:06 +00:00
char* buf2 = taosMemoryMalloc(SHOW_CREATE_TB_RESULT_FIELD2_LEN);
if (NULL == buf2) {
2024-09-20 05:23:44 +00:00
QRY_ERR_RET(terrno);
2022-10-21 09:24:06 +00:00
}
2022-11-28 03:22:11 +00:00
int32_t len = 0;
2022-06-20 12:58:36 +00:00
if (TSDB_SUPER_TABLE == pCfg->tableType) {
2024-10-10 02:35:48 +00:00
len += tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_TB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
"CREATE STABLE `%s` (", expandIdentifier(tbName, buf1));
2022-06-20 12:58:36 +00:00
appendColumnFields(buf2, &len, pCfg);
2024-10-10 02:35:48 +00:00
len += tsnprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len),
") TAGS (");
appendTagFields(buf2, &len, pCfg);
2024-10-08 06:25:51 +00:00
len +=
snprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len), ")");
2022-08-02 12:20:44 +00:00
appendTableOptions(buf2, &len, pDbCfg, pCfg);
2022-06-20 12:58:36 +00:00
} else if (TSDB_CHILD_TABLE == pCfg->tableType) {
2024-10-10 02:35:48 +00:00
len += tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_TB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
"CREATE TABLE `%s` ", expandIdentifier(tbName, buf1));
len += tsnprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len),
"USING `%s` (", expandIdentifier(pCfg->stbName, buf1));
2022-06-21 01:18:53 +00:00
appendTagNameFields(buf2, &len, pCfg);
2024-10-10 02:35:48 +00:00
len += tsnprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len),
") TAGS (");
2024-12-09 08:15:48 +00:00
code = appendTagValues(buf2, &len, pCfg, charsetCxt);
2024-07-21 10:57:08 +00:00
TAOS_CHECK_ERRNO(code);
2024-10-08 06:25:51 +00:00
len +=
snprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len), ")");
2022-08-02 12:20:44 +00:00
appendTableOptions(buf2, &len, pDbCfg, pCfg);
} else if (TSDB_NORMAL_TABLE == pCfg->tableType) {
2024-10-10 02:35:48 +00:00
len += tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_TB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
"CREATE TABLE `%s` (", expandIdentifier(tbName, buf1));
2022-06-20 12:58:36 +00:00
appendColumnFields(buf2, &len, pCfg);
2024-10-08 06:25:51 +00:00
len +=
snprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len), ")");
appendTableOptions(buf2, &len, pDbCfg, pCfg);
} else if (TSDB_VIRTUAL_NORMAL_TABLE == pCfg->tableType) {
len += tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_TB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
"CREATE VTABLE `%s` (", expandIdentifier(tbName, buf1));
appendColumnFields(buf2, &len, pCfg);
len +=
snprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len), ")");
} else if (TSDB_VIRTUAL_CHILD_TABLE == pCfg->tableType) {
len += tsnprintf(buf2 + VARSTR_HEADER_SIZE, SHOW_CREATE_TB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
"CREATE VTABLE `%s` (", expandIdentifier(tbName, buf1));
appendColRefFields(buf2, &len, pCfg);
len += snprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len),
") USING `%s` (", expandIdentifier(pCfg->stbName, buf1));
appendTagNameFields(buf2, &len, pCfg);
len += tsnprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len),
") TAGS (");
code = appendTagValues(buf2, &len, pCfg, charsetCxt);
TAOS_CHECK_ERRNO(code);
len +=
snprintf(buf2 + VARSTR_HEADER_SIZE + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len), ")");
2022-06-20 12:58:36 +00:00
}
2022-11-14 07:48:01 +00:00
varDataLen(buf2) = (len > 65535) ? 65535 : len;
2024-07-21 10:57:08 +00:00
code = colDataSetVal(pCol2, 0, buf2, false);
TAOS_CHECK_ERRNO(code);
2022-06-20 12:58:36 +00:00
2024-07-15 10:45:41 +00:00
_exit:
2022-10-21 09:24:06 +00:00
taosMemoryFree(buf2);
2022-11-28 03:22:11 +00:00
2024-07-21 10:57:08 +00:00
return code;
2022-06-20 12:58:36 +00:00
}
2023-10-11 02:38:22 +00:00
static int32_t setCreateViewResultIntoDataBlock(SSDataBlock* pBlock, SShowCreateViewStmt* pStmt) {
int32_t code = 0;
2024-07-15 10:45:41 +00:00
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
2023-10-11 02:38:22 +00:00
pBlock->info.rows = 1;
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
char buf1[SHOW_CREATE_VIEW_RESULT_FIELD1_LEN + 1] = {0};
snprintf(varDataVal(buf1), TSDB_VIEW_FNAME_LEN + 4, "`%s`.`%s`", pStmt->dbName, pStmt->viewName);
varDataSetLen(buf1, strlen(varDataVal(buf1)));
2024-07-15 10:45:41 +00:00
QRY_ERR_RET(colDataSetVal(pCol1, 0, buf1, false));
2023-10-11 02:38:22 +00:00
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
char* buf2 = taosMemoryMalloc(SHOW_CREATE_VIEW_RESULT_FIELD2_LEN);
if (NULL == buf2) {
2024-08-19 10:58:07 +00:00
return terrno;
2023-10-11 02:38:22 +00:00
}
SViewMeta* pMeta = pStmt->pViewMeta;
if (NULL == pMeta) {
2024-08-19 10:58:07 +00:00
qError("exception: view meta is null");
taosMemoryFree(buf2);
2024-08-19 10:58:07 +00:00
return TSDB_CODE_APP_ERROR;
}
2024-04-23 06:37:18 +00:00
snprintf(varDataVal(buf2), SHOW_CREATE_VIEW_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE, "CREATE VIEW `%s`.`%s` AS %s",
pStmt->dbName, pStmt->viewName, pMeta->querySql);
2023-10-11 02:38:22 +00:00
int32_t len = strlen(varDataVal(buf2));
varDataLen(buf2) = (len > 65535) ? 65535 : len;
2024-07-21 10:57:08 +00:00
code = colDataSetVal(pCol2, 0, buf2, false);
2023-10-11 02:38:22 +00:00
taosMemoryFree(buf2);
2024-07-21 10:57:08 +00:00
return code;
2023-10-11 02:38:22 +00:00
}
extern const char* fmGetFuncName(int32_t funcId);
static int32_t setCreateRsmaResultIntoDataBlock(SSDataBlock* pBlock, SShowCreateRsmaStmt* pStmt) {
int32_t code = 0, lino = 0;
char* buf2 = NULL;
SRsmaInfoRsp* pMeta = pStmt->pRsmaMeta;
if (pMeta->nFuncs != pMeta->nColNames) {
qError("exception: rsma meta is invalid, nFuncs:%d != nColNames:%d", pMeta->nFuncs, pMeta->nColNames);
return TSDB_CODE_APP_ERROR;
}
TAOS_CHECK_EXIT(blockDataEnsureCapacity(pBlock, 1));
pBlock->info.rows = 1;
SColumnInfoData* pCol1 = taosArrayGet(pBlock->pDataBlock, 0);
char buf1[SHOW_CREATE_TB_RESULT_FIELD1_LEN << 1] = {0};
snprintf(varDataVal(buf1), TSDB_TABLE_FNAME_LEN + 4, "`%s`", expandIdentifier(pStmt->rsmaName, buf1));
varDataSetLen(buf1, strlen(varDataVal(buf1)));
TAOS_CHECK_EXIT(colDataSetVal(pCol1, 0, buf1, false));
SColumnInfoData* pCol2 = taosArrayGet(pBlock->pDataBlock, 1);
if (!(buf2 = taosMemoryMalloc(SHOW_CREATE_TB_RESULT_FIELD2_LEN))) {
return terrno;
}
SName name = {0};
TAOS_CHECK_EXIT(tNameFromString(&name, pMeta->tbFName, T_NAME_ACCT | T_NAME_DB | T_NAME_TABLE));
int32_t len = 0;
len += tsnprintf(varDataVal(buf2), SHOW_CREATE_TB_RESULT_FIELD2_LEN - VARSTR_HEADER_SIZE,
"CREATE RSMA `%s` ON `%s`.`%s` FUNCTION(", expandIdentifier(pStmt->rsmaName, buf1),
expandIdentifier(name.dbname, buf1), expandIdentifier(name.tname, buf1));
for (int32_t i = 0; i < pMeta->nFuncs; ++i) {
len += tsnprintf(varDataVal(buf2) + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len),
"%s%s(`%s`)", (i > 0) ? "," : "", fmGetFuncName(pMeta->funcIds[i]),
expandIdentifier(*(char**)TARRAY_GET_ELEM(pMeta->colNames, i), buf1));
}
len += tsnprintf(varDataVal(buf2) + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len),
") INTERVAL(%d%c", pMeta->interval[0], pMeta->intervalUnit);
if (pMeta->interval[1] > 0) {
len += tsnprintf(varDataVal(buf2) + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len),
",%d%c", pMeta->interval[1], pMeta->intervalUnit);
}
len += tsnprintf(varDataVal(buf2) + len, SHOW_CREATE_TB_RESULT_FIELD2_LEN - (VARSTR_HEADER_SIZE + len), ")");
varDataLen(buf2) = len;
code = colDataSetVal(pCol2, 0, buf2, false);
_exit:
taosMemoryFree(buf2);
return code;
}
2024-12-09 08:15:48 +00:00
static int32_t execShowCreateTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp, void* charsetCxt) {
2022-10-17 07:43:42 +00:00
SSDataBlock* pBlock = NULL;
int32_t code = buildCreateTbResultDataBlock(&pBlock);
if (TSDB_CODE_SUCCESS == code) {
2024-12-09 08:15:48 +00:00
code = setCreateTBResultIntoDataBlock(pBlock, pStmt->pDbCfg, pStmt->tableName, pStmt->pTableCfg, charsetCxt);
2022-06-20 12:58:36 +00:00
}
2022-10-17 07:43:42 +00:00
if (TSDB_CODE_SUCCESS == code) {
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_TB_RESULT_COLS, pRsp);
}
2024-07-16 03:50:52 +00:00
(void)blockDataDestroy(pBlock);
2022-10-17 07:43:42 +00:00
return code;
2022-06-20 12:58:36 +00:00
}
static int32_t execShowCreateVTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp, void* charsetCxt) {
SSDataBlock* pBlock = NULL;
int32_t code = buildCreateTbResultDataBlock(&pBlock);
if (TSDB_CODE_SUCCESS == code) {
code = setCreateTBResultIntoDataBlock(pBlock, pStmt->pDbCfg, pStmt->tableName, pStmt->pTableCfg, charsetCxt);
}
if (TSDB_CODE_SUCCESS == code) {
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_TB_RESULT_COLS, pRsp);
}
(void)blockDataDestroy(pBlock);
return code;
}
2024-12-09 08:15:48 +00:00
static int32_t execShowCreateSTable(SShowCreateTableStmt* pStmt, SRetrieveTableRsp** pRsp, void* charsetCxt) {
2022-08-02 12:20:44 +00:00
STableCfg* pCfg = (STableCfg*)pStmt->pTableCfg;
2022-06-20 12:58:36 +00:00
if (TSDB_SUPER_TABLE != pCfg->tableType) {
terrno = TSDB_CODE_TSC_NOT_STABLE_ERROR;
return terrno;
}
2024-12-09 08:15:48 +00:00
return execShowCreateTable(pStmt, pRsp, charsetCxt);
2022-06-20 12:58:36 +00:00
}
2022-07-14 06:03:27 +00:00
static int32_t execAlterCmd(char* cmd, char* value, bool* processed) {
int32_t code = 0;
2022-07-14 06:03:27 +00:00
if (0 == strcasecmp(cmd, COMMAND_RESET_LOG)) {
taosResetLog();
cfgDumpCfg(tsCfg, 0, false);
} else if (0 == strcasecmp(cmd, COMMAND_SCHEDULE_POLICY)) {
2024-10-08 06:25:51 +00:00
int32_t tmp = 0;
code = taosStr2int32(value, &tmp);
if (code) {
qError("invalid value:%s, error:%s", value, tstrerror(code));
return code;
}
code = schedulerUpdatePolicy(tmp);
2022-07-14 06:03:27 +00:00
} else if (0 == strcasecmp(cmd, COMMAND_ENABLE_RESCHEDULE)) {
2024-10-08 06:25:51 +00:00
int32_t tmp = 0;
code = taosStr2int32(value, &tmp);
if (code) {
qError("invalid value:%s, error:%s", value, tstrerror(code));
return code;
}
code = schedulerEnableReSchedule(tmp != 0);
2022-11-02 07:18:32 +00:00
} else if (0 == strcasecmp(cmd, COMMAND_CATALOG_DEBUG)) {
code = ctgdHandleDbgCommand(value);
2023-02-17 09:40:14 +00:00
} else if (0 == strcasecmp(cmd, COMMAND_ENABLE_MEM_DEBUG)) {
code = taosMemoryDbgInit();
if (code) {
qError("failed to init memory dbg, error:%s", tstrerror(code));
return code;
}
2023-02-17 09:45:44 +00:00
tsAsyncLog = false;
2023-02-17 09:40:14 +00:00
qInfo("memory dbg enabled");
} else if (0 == strcasecmp(cmd, COMMAND_DISABLE_MEM_DEBUG)) {
code = taosMemoryDbgInitRestore();
if (code) {
qError("failed to restore from memory dbg, error:%s", tstrerror(code));
return code;
}
qInfo("memory dbg disabled");
2022-07-14 06:03:27 +00:00
} else {
goto _return;
}
*processed = true;
_return:
if (code) {
terrno = code;
}
return code;
2022-07-14 06:03:27 +00:00
}
static int32_t execAlterLocal(SAlterLocalStmt* pStmt) {
2022-07-14 06:03:27 +00:00
bool processed = false;
2022-07-14 06:03:27 +00:00
if (execAlterCmd(pStmt->config, pStmt->value, &processed)) {
return terrno;
}
if (processed) {
goto _return;
}
2024-12-11 07:46:44 +00:00
if (cfgCheckRangeForDynUpdate(tsCfg, pStmt->config, pStmt->value, false, CFG_ALTER_LOCAL)) {
return terrno;
}
2024-11-15 11:44:03 +00:00
if (cfgSetItem(tsCfg, pStmt->config, pStmt->value, CFG_STYPE_ALTER_CLIENT_CMD, true)) {
return terrno;
2022-06-22 11:45:41 +00:00
}
2024-07-24 08:36:57 +00:00
TAOS_CHECK_RETURN(taosCfgDynamicOptions(tsCfg, pStmt->config, false));
2022-06-24 00:20:54 +00:00
2022-07-14 06:03:27 +00:00
_return:
2022-06-22 11:45:41 +00:00
return TSDB_CODE_SUCCESS;
}
2022-10-17 07:43:42 +00:00
static int32_t buildLocalVariablesResultDataBlock(SSDataBlock** pOutput) {
2022-06-22 09:17:18 +00:00
SSDataBlock* pBlock = taosMemoryCalloc(1, sizeof(SSDataBlock));
2022-10-17 07:43:42 +00:00
if (NULL == pBlock) {
2024-08-07 08:51:39 +00:00
return terrno;
2022-10-17 07:43:42 +00:00
}
2022-06-22 09:17:18 +00:00
pBlock->info.hasVarCol = true;
2022-06-23 05:59:31 +00:00
pBlock->pDataBlock = taosArrayInit(SHOW_LOCAL_VARIABLES_RESULT_COLS, sizeof(SColumnInfoData));
2024-07-16 03:50:52 +00:00
if (NULL == pBlock->pDataBlock) {
taosMemoryFree(pBlock);
2024-09-20 05:23:44 +00:00
return terrno;
2024-07-16 03:50:52 +00:00
}
2022-06-22 09:17:18 +00:00
SColumnInfoData infoData = {0};
2023-07-14 06:38:35 +00:00
2022-06-22 09:17:18 +00:00
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD1_LEN;
2024-08-20 09:25:12 +00:00
if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
2024-07-16 03:50:52 +00:00
goto _exit;
}
2022-06-22 09:17:18 +00:00
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD2_LEN;
2024-08-20 09:25:12 +00:00
if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
2024-07-16 03:50:52 +00:00
goto _exit;
}
2022-06-22 09:17:18 +00:00
2023-07-14 06:38:35 +00:00
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD3_LEN;
2024-08-20 09:25:12 +00:00
if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
2024-07-16 03:50:52 +00:00
goto _exit;
2024-11-13 08:51:40 +00:00
}
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD4_LEN;
if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
goto _exit;
2024-07-16 03:50:52 +00:00
}
2023-07-14 06:38:35 +00:00
2024-11-26 08:08:16 +00:00
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
infoData.info.bytes = SHOW_LOCAL_VARIABLES_RESULT_FIELD5_LEN;
if (taosArrayPush(pBlock->pDataBlock, &infoData) == NULL) {
goto _exit;
2024-07-16 03:50:52 +00:00
}
2023-07-14 06:38:35 +00:00
2022-10-17 07:43:42 +00:00
*pOutput = pBlock;
2024-07-16 03:50:52 +00:00
_exit:
2024-08-20 09:25:12 +00:00
if (terrno != TSDB_CODE_SUCCESS) {
2024-07-16 03:50:52 +00:00
taosArrayDestroy(pBlock->pDataBlock);
2024-11-12 07:03:48 +00:00
taosMemoryFree(pBlock);
2024-07-16 03:50:52 +00:00
}
return terrno;
2022-06-22 09:17:18 +00:00
}
2025-02-25 10:21:32 +00:00
static int32_t execShowLocalVariables(SShowStmt* pStmt, SRetrieveTableRsp** pRsp) {
2022-10-17 07:43:42 +00:00
SSDataBlock* pBlock = NULL;
2025-02-25 10:21:32 +00:00
char* likePattern = NULL;
2022-10-17 07:43:42 +00:00
int32_t code = buildLocalVariablesResultDataBlock(&pBlock);
if (TSDB_CODE_SUCCESS == code) {
2025-02-25 10:21:32 +00:00
if (pStmt->tableCondType == OP_TYPE_LIKE) {
likePattern = ((SValueNode*)pStmt->pTbName)->literal;
}
}
if (TSDB_CODE_SUCCESS == code) {
code = dumpConfToDataBlock(pBlock, 0, likePattern);
2022-06-22 09:17:18 +00:00
}
2022-10-17 07:43:42 +00:00
if (TSDB_CODE_SUCCESS == code) {
code = buildRetrieveTableRsp(pBlock, SHOW_LOCAL_VARIABLES_RESULT_COLS, pRsp);
}
2024-07-16 03:50:52 +00:00
(void)blockDataDestroy(pBlock);
2022-10-17 07:43:42 +00:00
return code;
}
2022-06-22 09:17:18 +00:00
static int32_t createSelectResultDataBlock(SNodeList* pProjects, SSDataBlock** pOutput) {
QRY_PARAM_CHECK(pOutput);
2024-07-27 10:55:34 +00:00
SSDataBlock* pBlock = NULL;
2024-08-20 09:25:12 +00:00
int32_t code = createDataBlock(&pBlock);
2024-07-27 10:55:34 +00:00
if (code) {
return code;
2022-06-22 09:17:18 +00:00
}
SNode* pProj = NULL;
FOREACH(pProj, pProjects) {
2022-11-28 03:22:11 +00:00
SExprNode* pExpr = (SExprNode*)pProj;
SColumnInfoData infoData = {0};
2022-11-28 03:22:11 +00:00
if (TSDB_DATA_TYPE_NULL == pExpr->resType.type) {
infoData.info.type = TSDB_DATA_TYPE_VARCHAR;
infoData.info.bytes = 0;
} else {
infoData.info.type = pExpr->resType.type;
infoData.info.bytes = pExpr->resType.bytes;
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
infoData.info.precision = pExpr->resType.precision;
infoData.info.scale = pExpr->resType.scale;
2022-11-28 03:22:11 +00:00
}
2024-07-15 10:45:41 +00:00
QRY_ERR_RET(blockDataAppendColInfo(pBlock, &infoData));
}
2024-07-27 10:55:34 +00:00
*pOutput = pBlock;
2024-07-27 10:55:34 +00:00
return code;
}
2024-11-07 08:19:57 +00:00
static int32_t buildSelectResultDataBlock(SNodeList* pProjects, SSDataBlock* pBlock) {
2024-07-15 10:45:41 +00:00
QRY_ERR_RET(blockDataEnsureCapacity(pBlock, 1));
int32_t index = 0;
SNode* pProj = NULL;
FOREACH(pProj, pProjects) {
2022-07-13 09:14:04 +00:00
if (QUERY_NODE_VALUE != nodeType(pProj)) {
return TSDB_CODE_PAR_INVALID_SELECTED_EXPR;
} else {
2022-07-13 09:14:04 +00:00
if (((SValueNode*)pProj)->isNull) {
2024-07-15 10:45:41 +00:00
QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0, NULL, true));
2022-07-13 09:14:04 +00:00
} else {
2024-08-20 09:25:12 +00:00
QRY_ERR_RET(colDataSetVal(taosArrayGet(pBlock->pDataBlock, index++), 0,
nodesGetValueFromNode((SValueNode*)pProj), false));
2022-07-13 09:14:04 +00:00
}
}
}
pBlock->info.rows = 1;
2022-06-22 09:17:18 +00:00
return TSDB_CODE_SUCCESS;
}
static int32_t execSelectWithoutFrom(SSelectStmt* pSelect, SRetrieveTableRsp** pRsp) {
SSDataBlock* pBlock = NULL;
int32_t code = createSelectResultDataBlock(pSelect->pProjectionList, &pBlock);
if (TSDB_CODE_SUCCESS == code) {
code = buildSelectResultDataBlock(pSelect->pProjectionList, pBlock);
}
if (TSDB_CODE_SUCCESS == code) {
code = buildRetrieveTableRsp(pBlock, LIST_LENGTH(pSelect->pProjectionList), pRsp);
}
2024-07-16 03:50:52 +00:00
(void)blockDataDestroy(pBlock);
return code;
}
2023-10-11 02:38:22 +00:00
static int32_t execShowCreateView(SShowCreateViewStmt* pStmt, SRetrieveTableRsp** pRsp) {
SSDataBlock* pBlock = NULL;
int32_t code = buildCreateViewResultDataBlock(&pBlock);
if (TSDB_CODE_SUCCESS == code) {
code = setCreateViewResultIntoDataBlock(pBlock, pStmt);
}
if (TSDB_CODE_SUCCESS == code) {
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_VIEW_RESULT_COLS, pRsp);
}
2024-07-16 03:50:52 +00:00
(void)blockDataDestroy(pBlock);
2023-10-11 02:38:22 +00:00
return code;
}
static int32_t execShowCreateRsma(SShowCreateRsmaStmt* pStmt, SRetrieveTableRsp** pRsp) {
SSDataBlock* pBlock = NULL;
int32_t code = buildCreateTbResultDataBlock(&pBlock);
if (TSDB_CODE_SUCCESS == code) {
code = setCreateRsmaResultIntoDataBlock(pBlock, pStmt);
}
if (TSDB_CODE_SUCCESS == code) {
code = buildRetrieveTableRsp(pBlock, SHOW_CREATE_TB_RESULT_COLS, pRsp);
}
(void)blockDataDestroy(pBlock);
return code;
}
2024-12-11 07:46:44 +00:00
int32_t qExecCommand(int64_t* pConnId, bool sysInfoUser, SNode* pStmt, SRetrieveTableRsp** pRsp, int8_t biMode,
void* charsetCxt) {
switch (nodeType(pStmt)) {
case QUERY_NODE_DESCRIBE_STMT:
2023-09-18 08:59:07 +00:00
return execDescribe(sysInfoUser, pStmt, pRsp, biMode);
case QUERY_NODE_RESET_QUERY_CACHE_STMT:
return execResetQueryCache();
case QUERY_NODE_SHOW_CREATE_DATABASE_STMT:
2022-06-18 11:50:53 +00:00
return execShowCreateDatabase((SShowCreateDatabaseStmt*)pStmt, pRsp);
case QUERY_NODE_SHOW_CREATE_TABLE_STMT:
2024-12-09 08:15:48 +00:00
return execShowCreateTable((SShowCreateTableStmt*)pStmt, pRsp, charsetCxt);
case QUERY_NODE_SHOW_CREATE_VTABLE_STMT:
return execShowCreateVTable((SShowCreateTableStmt*)pStmt, pRsp, charsetCxt);
case QUERY_NODE_SHOW_CREATE_STABLE_STMT:
2024-12-09 08:15:48 +00:00
return execShowCreateSTable((SShowCreateTableStmt*)pStmt, pRsp, charsetCxt);
2023-10-11 02:38:22 +00:00
case QUERY_NODE_SHOW_CREATE_VIEW_STMT:
return execShowCreateView((SShowCreateViewStmt*)pStmt, pRsp);
2025-09-26 09:32:32 +00:00
case QUERY_NODE_SHOW_CREATE_RSMA_STMT:
return execShowCreateRsma((SShowCreateRsmaStmt*)pStmt, pRsp);
case QUERY_NODE_ALTER_LOCAL_STMT:
return execAlterLocal((SAlterLocalStmt*)pStmt);
case QUERY_NODE_SHOW_LOCAL_VARIABLES_STMT:
2025-02-25 10:21:32 +00:00
return execShowLocalVariables((SShowStmt*)pStmt, pRsp);
case QUERY_NODE_SELECT_STMT:
return execSelectWithoutFrom((SSelectStmt*)pStmt, pRsp);
default:
break;
}
return TSDB_CODE_FAILED;
}