TDengine/tools/shell/src/shellEngine.c

1418 lines
38 KiB
C
Raw Normal View History

2019-07-11 08:36:16 +00:00
/*
* 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/>.
*/
2022-07-02 09:40:23 +00:00
#define ALLOW_FORBID_FUNC
#define _BSD_SOURCE
#define _GNU_SOURCE
2019-07-11 08:36:16 +00:00
#define _XOPEN_SOURCE
2019-07-13 06:04:30 +00:00
#define _DEFAULT_SOURCE
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
#include "geosWrapper.h"
2023-09-01 05:24:47 +00:00
#include "shellAuto.h"
#include "shellInt.h"
2019-07-11 08:36:16 +00:00
2023-10-24 07:05:24 +00:00
typedef struct {
const char *sql;
bool vertical;
tsem_t sem;
int64_t numOfRows; // the num of this batch
int64_t numOfAllRows;
int32_t numFields;
TAOS_FIELD *fields;
int32_t precision;
int32_t maxColNameLen; // for vertical print
int32_t width[TSDB_MAX_COLUMNS]; // for horizontal print
uint64_t resShowMaxNum;
} tsDumpInfo;
2022-04-21 13:09:43 +00:00
static bool shellIsEmptyCommand(const char *cmd);
static int32_t shellRunSingleCommand(char *command);
static void shellRecordCommandToHistory(char *command);
static int32_t shellRunCommand(char *command, bool recordHistory);
2022-04-21 13:09:43 +00:00
static void shellRunSingleCommandImp(char *command);
static char *shellFormatTimestamp(char *buf, int64_t val, int32_t precision);
static int64_t shellDumpResultToFile(const char *fname, TAOS_RES *tres);
2022-04-21 13:09:43 +00:00
static void shellPrintNChar(const char *str, int32_t length, int32_t width);
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
static void shellPrintGeometry(const unsigned char *str, int32_t length, int32_t width);
2023-10-24 07:05:24 +00:00
static void shellVerticalPrintResult(TAOS_RES *tres, tsDumpInfo* dump_info);
static void shellHorizontalPrintResult(TAOS_RES *tres, tsDumpInfo* dump_info);
static int64_t shellDumpResult(TAOS_RES *tres, char *fname, int32_t *error_no, bool vertical, const char *sql);
2022-04-21 13:09:43 +00:00
static void shellReadHistory();
static void shellWriteHistory();
static void shellPrintError(TAOS_RES *tres, int64_t st);
static bool shellIsCommentLine(char *line);
static void shellSourceFile(const char *file);
2024-05-11 06:59:05 +00:00
static bool shellGetGrantInfo(char* buf);
2023-09-01 05:24:47 +00:00
static void shellCleanup(void *arg);
static void *shellCancelHandler(void *arg);
static void *shellThreadLoop(void *arg);
2022-04-21 13:09:43 +00:00
2023-11-14 11:25:54 +00:00
static bool shellCmdkilled = false;
2022-04-21 13:09:43 +00:00
bool shellIsEmptyCommand(const char *cmd) {
for (char c = *cmd++; c != 0; c = *cmd++) {
if (c != ' ' && c != '\t' && c != ';') {
return false;
2019-07-11 08:36:16 +00:00
}
}
return true;
2019-07-11 08:36:16 +00:00
}
2022-04-21 13:09:43 +00:00
int32_t shellRunSingleCommand(char *command) {
2023-11-14 11:25:54 +00:00
shellCmdkilled = false;
2022-04-21 13:09:43 +00:00
if (shellIsEmptyCommand(command)) {
return 0;
2019-07-11 08:36:16 +00:00
}
2022-04-20 11:44:25 +00:00
if (shellRegexMatch(command, "^[ \t]*(quit|q|exit)[ \t;]*$", REG_EXTENDED | REG_ICASE)) {
return -1;
}
2022-04-20 11:44:25 +00:00
if (shellRegexMatch(command, "^[\t ]*clear[ \t;]*$", REG_EXTENDED | REG_ICASE)) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-result"
2023-09-01 05:24:47 +00:00
system("clear");
#pragma GCC diagnostic pop
return 0;
}
2022-04-20 11:44:25 +00:00
if (shellRegexMatch(command, "^[\t ]*set[ \t]+max_binary_display_width[ \t]+(default|[1-9][0-9]*)[ \t;]*$",
2022-04-21 13:09:43 +00:00
REG_EXTENDED | REG_ICASE)) {
strtok(command, " \t");
strtok(NULL, " \t");
2021-12-17 07:49:27 +00:00
char *p = strtok(NULL, " \t");
2022-04-22 09:59:41 +00:00
if (strncasecmp(p, "default", 7) == 0) {
2022-04-21 13:09:43 +00:00
shell.args.displayWidth = SHELL_DEFAULT_MAX_BINARY_DISPLAY_WIDTH;
} else {
2022-04-22 09:59:41 +00:00
int32_t displayWidth = atoi(p);
displayWidth = TRANGE(displayWidth, 1, 10 * 1024);
shell.args.displayWidth = displayWidth;
}
return 0;
}
2022-04-20 11:44:25 +00:00
if (shellRegexMatch(command, "^[ \t]*source[\t ]+[^ ]+[ \t;]*$", REG_EXTENDED | REG_ICASE)) {
2019-07-11 08:36:16 +00:00
/* If source file. */
char *c_ptr = strtok(command, " ;");
2022-10-09 07:40:27 +00:00
if (c_ptr == NULL) {
shellRunSingleCommandImp(command);
return 0;
}
2019-07-11 08:36:16 +00:00
c_ptr = strtok(NULL, " ;");
2022-10-09 07:40:27 +00:00
if (c_ptr == NULL) {
shellRunSingleCommandImp(command);
return 0;
}
2022-04-21 13:09:43 +00:00
shellSourceFile(c_ptr);
return 0;
2019-07-11 08:36:16 +00:00
}
#ifdef WEBSOCKET
if (shell.args.restful || shell.args.cloud) {
2023-03-22 08:08:16 +00:00
shellRunSingleCommandWebsocketImp(command);
} else {
#endif
2023-03-22 08:08:16 +00:00
shellRunSingleCommandImp(command);
#ifdef WEBSOCKET
}
#endif
return 0;
2019-07-11 08:36:16 +00:00
}
void shellRecordCommandToHistory(char *command) {
if (strncasecmp(command, "create user ", 12) == 0 || strncasecmp(command, "alter user ", 11) == 0) {
if (taosStrCaseStr(command, " pass ")) {
// have password command forbid record to history because security
return;
}
}
2022-04-21 13:09:43 +00:00
SShellHistory *pHistory = &shell.history;
if (pHistory->hstart == pHistory->hend ||
pHistory->hist[(pHistory->hend + SHELL_MAX_HISTORY_SIZE - 1) % SHELL_MAX_HISTORY_SIZE] == NULL ||
strcmp(command, pHistory->hist[(pHistory->hend + SHELL_MAX_HISTORY_SIZE - 1) % SHELL_MAX_HISTORY_SIZE]) != 0) {
if (pHistory->hist[pHistory->hend] != NULL) {
taosMemoryFreeClear(pHistory->hist[pHistory->hend]);
}
pHistory->hist[pHistory->hend] = taosStrdup(command);
2022-04-21 13:09:43 +00:00
pHistory->hend = (pHistory->hend + 1) % SHELL_MAX_HISTORY_SIZE;
if (pHistory->hend == pHistory->hstart) {
pHistory->hstart = (pHistory->hstart + 1) % SHELL_MAX_HISTORY_SIZE;
}
}
}
int32_t shellRunCommand(char *command, bool recordHistory) {
if (shellIsEmptyCommand(command)) {
return 0;
}
2023-09-01 05:24:47 +00:00
// add help or help;
if (strncasecmp(command, "help;", 5) == 0) {
showHelp();
return 0;
}
if (recordHistory) shellRecordCommandToHistory(command);
2022-04-27 13:29:25 +00:00
char quote = 0, *cmd = command;
for (char c = *command++; c != 0; c = *command++) {
2022-04-27 13:29:25 +00:00
if (c == '\\' && (*command == '\'' || *command == '"' || *command == '`')) {
2022-05-13 10:59:44 +00:00
command++;
continue;
}
if (quote == c) {
quote = 0;
2022-04-27 13:29:25 +00:00
} else if (quote == 0 && (c == '\'' || c == '"' || c == '`')) {
quote = c;
2022-04-27 13:29:25 +00:00
} else if (c == ';' && quote == 0) {
c = *command;
*command = 0;
2022-04-21 13:09:43 +00:00
if (shellRunSingleCommand(cmd) < 0) {
return -1;
}
2022-04-27 13:29:25 +00:00
*command = c;
cmd = command;
}
}
2022-04-21 13:09:43 +00:00
return shellRunSingleCommand(cmd);
2020-12-17 05:06:20 +00:00
}
char * strendG(const char* pstr) {
if(pstr == NULL) {
return NULL;
}
size_t len = strlen(pstr);
2024-01-07 07:10:57 +00:00
if(len < 4) {
return NULL;
}
2024-01-07 07:15:56 +00:00
char * p = (char *)pstr + len - 2;
if (strcmp(p, "\\G") == 0 ){
return p;
}
2024-01-07 07:10:57 +00:00
p = (char *)pstr + len - 3;
if (strcmp(p, "\\G;") == 0) {
return p;
}
return NULL;
}
2022-04-21 13:09:43 +00:00
void shellRunSingleCommandImp(char *command) {
2022-04-21 13:11:02 +00:00
int64_t st, et;
char *sptr = NULL;
char *cptr = NULL;
char *fname = NULL;
bool printMode = false;
2019-07-11 08:36:16 +00:00
if ((sptr = strstr(command, ">>")) != NULL) {
2022-04-21 13:09:43 +00:00
fname = sptr + 2;
2022-06-25 08:14:54 +00:00
while (*fname == ' ') fname++;
2019-07-11 08:36:16 +00:00
*sptr = '\0';
2023-11-10 06:21:41 +00:00
cptr = strstr(fname, ";");
if (cptr != NULL) {
*cptr = '\0';
}
2019-07-11 08:36:16 +00:00
}
if ((sptr = strendG(command)) != NULL) {
*sptr = '\0';
printMode = true; // When output to a file, the switch does not work.
}
2019-07-11 08:36:16 +00:00
st = taosGetTimestampUs();
2022-04-21 13:09:43 +00:00
TAOS_RES *pSql = taos_query(shell.conn, command);
2020-06-01 15:30:10 +00:00
if (taos_errno(pSql)) {
2022-04-20 11:44:25 +00:00
shellPrintError(pSql, st);
2019-07-11 08:36:16 +00:00
return;
}
2022-04-20 11:44:25 +00:00
if (shellRegexMatch(command, "^\\s*use\\s+[a-zA-Z0-9_]+\\s*;\\s*$", REG_EXTENDED | REG_ICASE)) {
2022-07-06 06:38:24 +00:00
fprintf(stdout, "Database changed.\r\n\r\n");
2019-07-11 08:36:16 +00:00
fflush(stdout);
2020-06-19 04:13:08 +00:00
2022-09-07 02:16:00 +00:00
// call back auto tab module
callbackAutoTab(command, pSql, true);
2022-04-18 13:14:32 +00:00
taos_free_result(pSql);
2019-07-11 08:36:16 +00:00
return;
}
// pre string
2023-09-01 05:24:47 +00:00
char *pre = "Query OK";
if (shellRegexMatch(command, "^\\s*delete\\s*from\\s*.*", REG_EXTENDED | REG_ICASE)) {
2022-12-02 10:27:18 +00:00
pre = "Delete OK";
2023-09-01 05:24:47 +00:00
} else if (shellRegexMatch(command, "^\\s*insert\\s*into\\s*.*", REG_EXTENDED | REG_ICASE)) {
2022-12-02 10:27:18 +00:00
pre = "Insert OK";
2023-09-01 05:24:47 +00:00
} else if (shellRegexMatch(command, "^\\s*create\\s*.*", REG_EXTENDED | REG_ICASE)) {
2022-12-02 10:27:18 +00:00
pre = "Create OK";
2023-09-01 05:24:47 +00:00
} else if (shellRegexMatch(command, "^\\s*drop\\s*.*", REG_EXTENDED | REG_ICASE)) {
2022-12-02 10:27:18 +00:00
pre = "Drop OK";
}
2022-04-18 13:14:32 +00:00
TAOS_FIELD *pFields = taos_fetch_fields(pSql);
2021-12-17 08:53:14 +00:00
if (pFields != NULL) { // select and show kinds of commands
2022-04-21 13:09:43 +00:00
int32_t error_no = 0;
int64_t numOfRows = shellDumpResult(pSql, fname, &error_no, printMode, command);
if (numOfRows < 0) return;
2019-07-11 08:36:16 +00:00
et = taosGetTimestampUs();
if (error_no == 0) {
printf("Query OK, %"PRId64 " row(s) in set (%.6fs)\r\n", numOfRows, (et - st) / 1E6);
2019-07-11 08:36:16 +00:00
} else {
2023-11-14 11:25:54 +00:00
terrno = error_no;
printf("Query interrupted (%s), %"PRId64 " row(s) in set (%.6fs)\r\n", taos_errstr(NULL), numOfRows, (et - st) / 1E6);
2019-07-11 08:36:16 +00:00
}
2022-04-18 13:14:32 +00:00
taos_free_result(pSql);
2019-07-11 08:36:16 +00:00
} else {
int64_t num_rows_affacted = taos_affected_rows64(pSql);
taos_free_result(pSql);
2019-07-11 08:36:16 +00:00
et = taosGetTimestampUs();
2022-12-02 09:15:51 +00:00
printf("%s, %" PRId64 " row(s) affected (%.6fs)\r\n", pre, num_rows_affacted, (et - st) / 1E6);
2022-09-07 02:16:00 +00:00
// call auto tab
2022-10-16 05:46:21 +00:00
callbackAutoTab(command, NULL, false);
2019-07-11 08:36:16 +00:00
}
2022-07-06 06:38:24 +00:00
printf("\r\n");
2019-07-11 08:36:16 +00:00
}
2022-04-21 13:09:43 +00:00
char *shellFormatTimestamp(char *buf, int64_t val, int32_t precision) {
if (shell.args.is_raw_time) {
sprintf(buf, "%" PRId64, val);
return buf;
}
2019-07-11 08:36:16 +00:00
2021-12-17 07:49:27 +00:00
time_t tt;
2021-02-06 10:12:56 +00:00
int32_t ms = 0;
if (precision == TSDB_TIME_PRECISION_NANO) {
tt = (time_t)(val / 1000000000);
ms = val % 1000000000;
} else if (precision == TSDB_TIME_PRECISION_MICRO) {
tt = (time_t)(val / 1000000);
2021-02-06 10:12:56 +00:00
ms = val % 1000000;
} else {
tt = (time_t)(val / 1000);
2021-02-06 10:12:56 +00:00
ms = val % 1000;
}
2021-03-25 02:59:50 +00:00
if (tt <= 0 && ms < 0) {
2021-02-06 10:12:56 +00:00
tt--;
if (precision == TSDB_TIME_PRECISION_NANO) {
ms += 1000000000;
} else if (precision == TSDB_TIME_PRECISION_MICRO) {
2021-02-06 10:12:56 +00:00
ms += 1000000;
} else {
ms += 1000;
}
}
2020-08-12 05:14:59 +00:00
struct tm ptm = {0};
if (taosLocalTime(&tt, &ptm, buf) == NULL) {
return buf;
}
2023-09-01 05:24:47 +00:00
size_t pos = strftime(buf, 35, "%Y-%m-%d %H:%M:%S", &ptm);
if (precision == TSDB_TIME_PRECISION_NANO) {
sprintf(buf + pos, ".%09d", ms);
} else if (precision == TSDB_TIME_PRECISION_MICRO) {
2021-02-06 10:12:56 +00:00
sprintf(buf + pos, ".%06d", ms);
} else {
2021-02-06 10:12:56 +00:00
sprintf(buf + pos, ".%03d", ms);
}
return buf;
}
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
char *shellDumpHexValue(char *buf, const char *val, int32_t length) {
for (int32_t i = 0; i < length; i++) {
sprintf(buf + (i * 2), "%02X", val[i]);
}
buf[length * 2] = 0;
return buf;
}
2022-08-30 09:21:38 +00:00
void shellDumpFieldToFile(TdFilePtr pFile, const char *val, TAOS_FIELD *field, int32_t length, int32_t precision) {
if (val == NULL) {
2022-10-20 10:18:07 +00:00
taosFprintfFile(pFile, "NULL");
return;
}
2023-09-01 05:24:47 +00:00
char quotationStr[2] ={'"', 0};
int32_t width;
2022-10-20 08:53:26 +00:00
2023-09-01 05:24:47 +00:00
int n = 0;
#define LENGTH 64
char buf[LENGTH] = {0};
switch (field->type) {
case TSDB_DATA_TYPE_BOOL:
2022-08-30 09:21:38 +00:00
taosFprintfFile(pFile, "%d", ((((int32_t)(*((char *)val))) == 1) ? 1 : 0));
break;
case TSDB_DATA_TYPE_TINYINT:
2022-08-30 09:21:38 +00:00
taosFprintfFile(pFile, "%d", *((int8_t *)val));
break;
2022-05-13 10:59:44 +00:00
case TSDB_DATA_TYPE_UTINYINT:
2022-08-30 09:21:38 +00:00
taosFprintfFile(pFile, "%u", *((uint8_t *)val));
2022-05-13 10:59:44 +00:00
break;
case TSDB_DATA_TYPE_SMALLINT:
2022-08-30 09:21:38 +00:00
taosFprintfFile(pFile, "%d", *((int16_t *)val));
break;
2022-05-13 10:59:44 +00:00
case TSDB_DATA_TYPE_USMALLINT:
2022-08-30 09:21:38 +00:00
taosFprintfFile(pFile, "%u", *((uint16_t *)val));
2022-05-13 10:59:44 +00:00
break;
case TSDB_DATA_TYPE_INT:
2022-08-30 09:21:38 +00:00
taosFprintfFile(pFile, "%d", *((int32_t *)val));
break;
2022-05-13 10:59:44 +00:00
case TSDB_DATA_TYPE_UINT:
2022-08-30 09:21:38 +00:00
taosFprintfFile(pFile, "%u", *((uint32_t *)val));
2022-05-13 10:59:44 +00:00
break;
case TSDB_DATA_TYPE_BIGINT:
2022-08-30 09:21:38 +00:00
taosFprintfFile(pFile, "%" PRId64, *((int64_t *)val));
break;
2022-05-13 10:59:44 +00:00
case TSDB_DATA_TYPE_UBIGINT:
2022-08-30 09:21:38 +00:00
taosFprintfFile(pFile, "%" PRIu64, *((uint64_t *)val));
2022-05-13 10:59:44 +00:00
break;
case TSDB_DATA_TYPE_FLOAT:
width = SHELL_FLOAT_WIDTH;
2023-04-13 08:40:38 +00:00
if (tsEnableScience) {
taosFprintfFile(pFile, "%*.7e", width, GET_FLOAT_VAL(val));
2023-04-13 08:40:38 +00:00
} else {
2023-09-01 05:24:47 +00:00
n = snprintf(buf, LENGTH, "%*.7f", width, GET_FLOAT_VAL(val));
if (n > SHELL_FLOAT_WIDTH) {
taosFprintfFile(pFile, "%*.7e", width, GET_FLOAT_VAL(val));
} else {
taosFprintfFile(pFile, "%s", buf);
}
2023-04-13 08:40:38 +00:00
}
break;
case TSDB_DATA_TYPE_DOUBLE:
width = SHELL_DOUBLE_WIDTH;
2023-04-13 08:40:38 +00:00
if (tsEnableScience) {
2023-09-01 05:24:47 +00:00
snprintf(buf, LENGTH, "%*.15e", width, GET_DOUBLE_VAL(val));
taosFprintfFile(pFile, "%s", buf);
2023-04-13 08:40:38 +00:00
} else {
2023-09-01 05:24:47 +00:00
n = snprintf(buf, LENGTH, "%*.15f", width, GET_DOUBLE_VAL(val));
if (n > SHELL_DOUBLE_WIDTH) {
taosFprintfFile(pFile, "%*.15e", width, GET_DOUBLE_VAL(val));
2023-04-13 08:40:38 +00:00
} else {
taosFprintfFile(pFile, "%s", buf);
2023-04-13 08:40:38 +00:00
}
}
break;
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR:
2023-09-01 05:24:47 +00:00
case TSDB_DATA_TYPE_JSON: {
int32_t bufIndex = 0;
char* tmp = (char*)taosMemoryCalloc(length * 2 + 1, 1);
if(tmp == NULL) break;
for (int32_t i = 0; i < length; i++) {
tmp[bufIndex] = val[i];
bufIndex++;
if (val[i] == '\"') {
tmp[bufIndex] = val[i];
2022-08-30 08:11:42 +00:00
bufIndex++;
}
}
2023-09-01 05:24:47 +00:00
tmp[bufIndex] = 0;
taosFprintfFile(pFile, "%s%s%s", quotationStr, tmp, quotationStr);
taosMemoryFree(tmp);
} break;
case TSDB_DATA_TYPE_VARBINARY:{
void* tmp = NULL;
uint32_t size = 0;
if(taosAscii2Hex(val, length, &tmp, &size) < 0){
break;
}
taosFprintfFile(pFile, "%s%s%s", quotationStr, tmp, quotationStr);
taosMemoryFree(tmp);
break;
2023-09-01 05:24:47 +00:00
}
case TSDB_DATA_TYPE_GEOMETRY:{
char* tmp = (char*)taosMemoryCalloc(length * 2 + 1, 1);
if(tmp == NULL) break;
shellDumpHexValue(tmp, val, length);
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
taosFprintfFile(pFile, "%s", buf);
2023-09-01 05:24:47 +00:00
taosMemoryFree(tmp);
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
break;
2023-09-01 05:24:47 +00:00
}
case TSDB_DATA_TYPE_TIMESTAMP:
2022-04-21 13:09:43 +00:00
shellFormatTimestamp(buf, *(int64_t *)val, precision);
2022-10-20 08:53:26 +00:00
taosFprintfFile(pFile, "%s%s%s", quotationStr, buf, quotationStr);
break;
default:
break;
}
}
int64_t shellDumpResultToFile(const char *fname, TAOS_RES *tres) {
2022-04-22 09:59:41 +00:00
char fullname[PATH_MAX] = {0};
if (taosExpandDir(fname, fullname, PATH_MAX) != 0) {
tstrncpy(fullname, fname, PATH_MAX);
}
2020-06-19 04:13:08 +00:00
TAOS_ROW row = taos_fetch_row(tres);
if (row == NULL) {
return 0;
}
2022-04-22 09:59:41 +00:00
TdFilePtr pFile = taosOpenFile(fullname, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_TRUNC | TD_FILE_STREAM);
if (pFile == NULL) {
2022-07-06 06:38:24 +00:00
fprintf(stderr, "failed to open file: %s\r\n", fullname);
return -1;
}
2020-06-19 04:13:08 +00:00
TAOS_FIELD *fields = taos_fetch_fields(tres);
2022-04-21 13:09:43 +00:00
int32_t num_fields = taos_num_fields(tres);
int32_t precision = taos_result_precision(tres);
2022-04-21 13:09:43 +00:00
for (int32_t col = 0; col < num_fields; col++) {
if (col > 0) {
taosFprintfFile(pFile, ",");
}
taosFprintfFile(pFile, "%s", fields[col].name);
}
2022-07-06 06:38:24 +00:00
taosFprintfFile(pFile, "\r\n");
int64_t numOfRows = 0;
do {
2021-12-17 07:49:27 +00:00
int32_t *length = taos_fetch_lengths(tres);
2022-04-21 13:09:43 +00:00
for (int32_t i = 0; i < num_fields; i++) {
if (i > 0) {
2022-06-30 07:04:54 +00:00
taosFprintfFile(pFile, ",");
}
2022-08-30 09:24:24 +00:00
shellDumpFieldToFile(pFile, (const char *)row[i], fields + i, length[i], precision);
2019-07-11 08:36:16 +00:00
}
2022-07-06 06:38:24 +00:00
taosFprintfFile(pFile, "\r\n");
numOfRows++;
2020-06-19 04:13:08 +00:00
row = taos_fetch_row(tres);
2021-12-17 07:49:27 +00:00
} while (row != NULL);
taosCloseFile(&pFile);
2020-06-19 04:13:08 +00:00
return numOfRows;
}
2022-04-21 13:09:43 +00:00
void shellPrintNChar(const char *str, int32_t length, int32_t width) {
2022-03-18 08:48:12 +00:00
TdWchar tail[3];
2022-04-21 13:09:43 +00:00
int32_t pos = 0, cols = 0, totalCols = 0, tailLen = 0;
while (pos < length) {
2022-03-18 08:48:12 +00:00
TdWchar wc;
2022-04-21 13:09:43 +00:00
int32_t bytes = taosMbToWchar(&wc, str + pos, MB_CUR_MAX);
2022-05-18 14:13:38 +00:00
if (bytes <= 0) {
break;
}
2022-05-18 14:13:38 +00:00
if (pos + bytes > length) {
break;
}
2022-05-18 14:13:38 +00:00
int w = 0;
2022-06-30 07:04:54 +00:00
if (*(str + pos) == '\t' || *(str + pos) == '\n' || *(str + pos) == '\r') {
2022-05-18 14:13:38 +00:00
w = bytes;
2022-06-30 07:04:54 +00:00
} else {
2022-05-18 14:13:38 +00:00
w = taosWcharWidth(wc);
}
pos += bytes;
if (w <= 0) {
continue;
}
if (width <= 0) {
printf("%lc", wc);
continue;
}
totalCols += w;
if (totalCols > width) {
break;
}
if (totalCols <= (width - 3)) {
printf("%lc", wc);
cols += w;
} else {
tail[tailLen] = wc;
tailLen++;
}
}
if (totalCols > width) {
// width could be 1 or 2, so printf("...") cannot be used
2022-04-21 13:09:43 +00:00
for (int32_t i = 0; i < 3; i++) {
if (cols >= width) {
break;
}
putchar('.');
++cols;
}
} else {
2022-04-21 13:09:43 +00:00
for (int32_t i = 0; i < tailLen; i++) {
printf("%lc", tail[i]);
}
cols = totalCols;
}
for (; cols < width; cols++) {
putchar(' ');
}
}
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
void shellPrintString(const char *str, int32_t width) {
int32_t len = strlen(str);
if (width == 0) {
printf("%s", str);
2023-09-01 05:24:47 +00:00
} else if (len > width) {
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
if (width <= 3) {
printf("%.*s.", width - 1, str);
2023-09-01 05:24:47 +00:00
} else {
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
printf("%.*s...", width - 3, str);
}
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
} else {
printf("%s%*.s", str, width - len, "");
}
}
void shellPrintGeometry(const unsigned char *val, int32_t length, int32_t width) {
2023-09-01 05:24:47 +00:00
if (length == 0) { // empty value
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
shellPrintString("", width);
return;
}
int32_t code = TSDB_CODE_FAILED;
code = initCtxAsText();
if (code != TSDB_CODE_SUCCESS) {
shellPrintString(getThreadLocalGeosCtx()->errMsg, width);
return;
}
char *outputWKT = NULL;
code = doAsText(val, length, &outputWKT);
if (code != TSDB_CODE_SUCCESS) {
2023-09-01 05:24:47 +00:00
shellPrintString(getThreadLocalGeosCtx()->errMsg, width); // should NOT happen
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
return;
}
shellPrintString(outputWKT, width);
geosFreeBuffer(outputWKT);
}
void shellPrintField(const char *val, TAOS_FIELD *field, int32_t width, int32_t length, int32_t precision) {
if (val == NULL) {
shellPrintString(TSDB_DATA_NULL_STR, width);
return;
}
2019-07-11 08:36:16 +00:00
2023-09-01 05:24:47 +00:00
int n = 0;
#define LENGTH 64
char buf[LENGTH] = {0};
switch (field->type) {
case TSDB_DATA_TYPE_BOOL:
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
shellPrintString(((((int32_t)(*((char *)val))) == 1) ? "true" : "false"), width);
break;
case TSDB_DATA_TYPE_TINYINT:
2020-09-29 06:28:02 +00:00
printf("%*d", width, *((int8_t *)val));
break;
case TSDB_DATA_TYPE_UTINYINT:
printf("%*u", width, *((uint8_t *)val));
break;
case TSDB_DATA_TYPE_SMALLINT:
2020-09-29 06:28:02 +00:00
printf("%*d", width, *((int16_t *)val));
break;
case TSDB_DATA_TYPE_USMALLINT:
printf("%*u", width, *((uint16_t *)val));
break;
case TSDB_DATA_TYPE_INT:
2020-09-29 06:28:02 +00:00
printf("%*d", width, *((int32_t *)val));
break;
case TSDB_DATA_TYPE_UINT:
printf("%*u", width, *((uint32_t *)val));
break;
case TSDB_DATA_TYPE_BIGINT:
printf("%*" PRId64, width, *((int64_t *)val));
break;
case TSDB_DATA_TYPE_UBIGINT:
printf("%*" PRIu64, width, *((uint64_t *)val));
break;
case TSDB_DATA_TYPE_FLOAT:
2023-04-13 08:40:38 +00:00
if (tsEnableScience) {
2023-09-01 05:24:47 +00:00
printf("%*.7e", width, GET_FLOAT_VAL(val));
2023-04-13 08:40:38 +00:00
} else {
2023-09-01 05:24:47 +00:00
n = snprintf(buf, LENGTH, "%*.7f", width, GET_FLOAT_VAL(val));
if (n > SHELL_FLOAT_WIDTH) {
2023-09-01 05:24:47 +00:00
printf("%*.7e", width, GET_FLOAT_VAL(val));
2023-05-06 02:24:42 +00:00
} else {
2023-09-01 05:24:47 +00:00
printf("%s", buf);
2023-05-06 02:24:42 +00:00
}
2023-04-13 08:40:38 +00:00
}
break;
case TSDB_DATA_TYPE_DOUBLE:
2023-04-13 08:40:38 +00:00
if (tsEnableScience) {
2023-09-01 05:24:47 +00:00
snprintf(buf, LENGTH, "%*.15e", width,GET_DOUBLE_VAL(val));
printf("%s", buf);
2023-04-13 08:40:38 +00:00
} else {
2023-09-01 05:24:47 +00:00
n = snprintf(buf, LENGTH, "%*.15f", width, GET_DOUBLE_VAL(val));
if (n > SHELL_DOUBLE_WIDTH) {
2023-09-01 05:24:47 +00:00
printf("%*.15e", width, GET_DOUBLE_VAL(val));
2023-04-13 08:40:38 +00:00
} else {
2023-09-01 05:24:47 +00:00
printf("%*s", width, buf);
2023-04-13 08:40:38 +00:00
}
}
break;
2023-09-01 05:24:47 +00:00
case TSDB_DATA_TYPE_VARBINARY:{
void* data = NULL;
uint32_t size = 0;
if(taosAscii2Hex(val, length, &data, &size) < 0){
break;
}
shellPrintNChar(data, size, width);
taosMemoryFree(data);
break;
}
case TSDB_DATA_TYPE_BINARY:
case TSDB_DATA_TYPE_NCHAR:
2022-05-18 14:13:38 +00:00
case TSDB_DATA_TYPE_JSON:
shellPrintNChar(val, length, width);
break;
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:
shellPrintGeometry(val, length, width);
break;
case TSDB_DATA_TYPE_TIMESTAMP:
2022-04-21 13:09:43 +00:00
shellFormatTimestamp(buf, *(int64_t *)val, precision);
printf("%s", buf);
break;
default:
break;
2019-07-11 08:36:16 +00:00
}
}
2019-07-11 08:36:16 +00:00
// show whole result for this query return true, like limit or describe
bool shellIsShowWhole(const char *sql) {
// limit
2022-05-14 02:43:00 +00:00
if (taosStrCaseStr(sql, " limit ") != NULL) {
2022-05-13 10:59:44 +00:00
return true;
}
// describe
if (taosStrCaseStr(sql, "describe ") != NULL) {
return true;
}
// show
if (taosStrCaseStr(sql, "show ") != NULL) {
return true;
}
2024-03-28 05:45:55 +00:00
// explain
if (taosStrCaseStr(sql, "explain ") != NULL) {
return true;
}
2022-05-13 10:59:44 +00:00
return false;
}
2022-06-22 09:18:39 +00:00
bool shellIsShowQuery(const char *sql) {
2022-06-30 07:04:54 +00:00
// todo refactor
2022-06-22 09:18:39 +00:00
if (taosStrCaseStr(sql, "show ") != NULL) {
return true;
}
return false;
}
2023-10-24 07:05:24 +00:00
void init_dump_info(tsDumpInfo *dump_info, TAOS_RES *tres, const char *sql, bool vertical) {
dump_info->sql = sql;
dump_info->vertical = vertical;
tsem_init(&dump_info->sem, 0, 0);
dump_info->numOfAllRows = 0;
2023-10-24 07:05:24 +00:00
dump_info->numFields = taos_num_fields(tres);
dump_info->fields = taos_fetch_fields(tres);
dump_info->precision = taos_result_precision(tres);
2023-10-24 07:05:24 +00:00
dump_info->resShowMaxNum = UINT64_MAX;
if (shell.args.commands == NULL && shell.args.file[0] == 0 && !shellIsShowWhole(dump_info->sql)) {
dump_info->resShowMaxNum = SHELL_DEFAULT_RES_SHOW_NUM;
}
if (vertical) {
dump_info->maxColNameLen = 0;
for (int32_t col = 0; col < dump_info->numFields; col++) {
int32_t len = (int32_t)strlen(dump_info->fields[col].name);
if (len > dump_info->maxColNameLen) {
dump_info->maxColNameLen = len;
}
}
} else {
for (int32_t col = 0; col < dump_info->numFields; col++) {
dump_info->width[col] = shellCalcColWidth(dump_info->fields + col, dump_info->precision);
}
}
2023-10-24 07:05:24 +00:00
}
2023-10-24 07:05:24 +00:00
void shellVerticalPrintResult(TAOS_RES *tres, tsDumpInfo *dump_info) {
TAOS_ROW row = taos_fetch_row(tres);
if (row == NULL) {
2023-10-24 07:15:39 +00:00
printf("\033[31mtaos_fetch_row failed.\033[0m\n");
2023-10-24 07:05:24 +00:00
return;
2021-02-24 10:43:48 +00:00
}
2023-10-24 07:05:24 +00:00
int64_t numOfPintRows = dump_info->numOfAllRows;
int numOfPrintRowsThisOne = 0;
2021-02-25 02:15:01 +00:00
2023-10-24 07:05:24 +00:00
while (row != NULL) {
printf("*************************** %" PRId64 ".row ***************************\r\n", numOfPintRows + 1);
2021-02-24 11:45:50 +00:00
2023-10-24 07:05:24 +00:00
int32_t *length = taos_fetch_lengths(tres);
2023-10-24 07:05:24 +00:00
for (int32_t i = 0; i < dump_info->numFields; i++) {
TAOS_FIELD *field = dump_info->fields + i;
2023-10-24 07:05:24 +00:00
int32_t padding = (int32_t)(dump_info->maxColNameLen - strlen(field->name));
printf("%*.s%s: ", padding, " ", field->name);
shellPrintField((const char *)row[i], field, 0, length[i], dump_info->precision);
putchar('\r');
putchar('\n');
}
numOfPintRows++;
numOfPrintRowsThisOne++;
if (numOfPintRows == dump_info->resShowMaxNum) {
2022-07-06 06:38:24 +00:00
printf("\r\n");
2023-10-24 23:15:29 +00:00
printf(" Notice: The result shows only the first %d rows.\r\n", SHELL_DEFAULT_RES_SHOW_NUM);
2022-07-06 06:38:24 +00:00
printf(" You can use the `LIMIT` clause to get fewer result to show.\r\n");
printf(" Or use '>>' to redirect the whole set of the result to a specified file.\r\n");
printf("\r\n");
printf(" You can use Ctrl+C to stop the underway fetching.\r\n");
printf("\r\n");
2023-10-24 07:05:24 +00:00
return;
}
2023-10-24 07:05:24 +00:00
if (numOfPrintRowsThisOne == dump_info->numOfRows) {
return;
}
2023-10-24 07:05:24 +00:00
row = taos_fetch_row(tres);
}
return;
}
2022-04-21 13:09:43 +00:00
int32_t shellCalcColWidth(TAOS_FIELD *field, int32_t precision) {
int32_t width = (int32_t)strlen(field->name);
switch (field->type) {
2022-05-28 05:38:58 +00:00
case TSDB_DATA_TYPE_NULL:
return TMAX(4, width); // null
case TSDB_DATA_TYPE_BOOL:
2022-01-24 04:53:17 +00:00
return TMAX(5, width); // 'false'
case TSDB_DATA_TYPE_TINYINT:
case TSDB_DATA_TYPE_UTINYINT:
2022-01-24 04:53:17 +00:00
return TMAX(4, width); // '-127'
case TSDB_DATA_TYPE_SMALLINT:
case TSDB_DATA_TYPE_USMALLINT:
2022-01-24 04:53:17 +00:00
return TMAX(6, width); // '-32767'
case TSDB_DATA_TYPE_INT:
case TSDB_DATA_TYPE_UINT:
2022-01-24 04:53:17 +00:00
return TMAX(11, width); // '-2147483648'
case TSDB_DATA_TYPE_BIGINT:
case TSDB_DATA_TYPE_UBIGINT:
2022-01-24 04:53:17 +00:00
return TMAX(21, width); // '-9223372036854775807'
case TSDB_DATA_TYPE_FLOAT:
return TMAX(SHELL_FLOAT_WIDTH, width);
case TSDB_DATA_TYPE_DOUBLE:
return TMAX(SHELL_DOUBLE_WIDTH, width);
case TSDB_DATA_TYPE_BINARY:
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-21 13:09:43 +00:00
if (field->bytes > shell.args.displayWidth) {
return TMAX(shell.args.displayWidth, width);
} else {
return TMAX(field->bytes + 2, width);
}
2023-09-01 05:24:47 +00:00
case TSDB_DATA_TYPE_VARBINARY:{
int32_t bytes = field->bytes * 2 + 2;
if (bytes > shell.args.displayWidth) {
return TMAX(shell.args.displayWidth, width);
} else {
return TMAX(bytes + 2, width);
}
}
2022-05-18 14:13:38 +00:00
case TSDB_DATA_TYPE_NCHAR:
case TSDB_DATA_TYPE_JSON: {
uint16_t bytes = field->bytes * TSDB_NCHAR_SIZE;
2022-04-21 13:09:43 +00:00
if (bytes > shell.args.displayWidth) {
return TMAX(shell.args.displayWidth, width);
} else {
return TMAX(bytes + 2, width);
}
}
case TSDB_DATA_TYPE_TIMESTAMP:
2022-04-21 13:09:43 +00:00
if (shell.args.is_raw_time) {
2022-01-24 04:53:17 +00:00
return TMAX(14, width);
2021-12-17 07:49:27 +00:00
}
if (precision == TSDB_TIME_PRECISION_NANO) {
2022-01-24 04:53:17 +00:00
return TMAX(29, width);
} else if (precision == TSDB_TIME_PRECISION_MICRO) {
2022-01-24 04:53:17 +00:00
return TMAX(26, width); // '2020-01-01 00:00:00.000000'
} else {
2022-01-24 04:53:17 +00:00
return TMAX(23, width); // '2020-01-01 00:00:00.000'
2019-11-07 10:12:26 +00:00
}
2019-07-11 08:36:16 +00:00
default:
ASSERT(false);
2019-07-11 08:36:16 +00:00
}
return 0;
}
2019-07-11 08:36:16 +00:00
2022-04-21 13:09:43 +00:00
void shellPrintHeader(TAOS_FIELD *fields, int32_t *width, int32_t num_fields) {
int32_t rowWidth = 0;
for (int32_t col = 0; col < num_fields; col++) {
2021-12-17 07:49:27 +00:00
TAOS_FIELD *field = fields + col;
2022-04-21 13:09:43 +00:00
int32_t padding = (int32_t)(width[col] - strlen(field->name));
int32_t left = padding / 2;
printf(" %*.s%s%*.s |", left, " ", field->name, padding - left, " ");
rowWidth += width[col] + 3;
}
2022-07-06 06:38:24 +00:00
putchar('\r');
putchar('\n');
2022-04-21 13:09:43 +00:00
for (int32_t i = 0; i < rowWidth; i++) {
putchar('=');
}
2022-07-06 06:38:24 +00:00
putchar('\r');
putchar('\n');
}
2023-10-24 07:05:24 +00:00
void shellHorizontalPrintResult(TAOS_RES *tres, tsDumpInfo *dump_info) {
2020-06-01 15:30:10 +00:00
TAOS_ROW row = taos_fetch_row(tres);
if (row == NULL) {
2023-10-24 07:15:39 +00:00
printf("\033[31mtaos_fetch_row failed.\033[0m\n");
2023-10-24 07:05:24 +00:00
return;
}
2023-10-24 07:05:24 +00:00
int64_t numOfPintRows = dump_info->numOfAllRows;
int numOfPrintRowsThisOne = 0;
if (numOfPintRows == 0) {
shellPrintHeader(dump_info->fields, dump_info->width, dump_info->numFields);
}
2023-10-24 07:05:24 +00:00
while (row != NULL) {
int32_t *length = taos_fetch_lengths(tres);
for (int32_t i = 0; i < dump_info->numFields; i++) {
putchar(' ');
shellPrintField((const char *)row[i], dump_info->fields + i, dump_info->width[i], length[i],
dump_info->precision);
putchar(' ');
putchar('|');
}
putchar('\r');
putchar('\n');
2021-02-24 10:43:48 +00:00
2023-10-24 07:05:24 +00:00
numOfPintRows++;
numOfPrintRowsThisOne++;
2023-10-24 07:05:24 +00:00
if (numOfPintRows == dump_info->resShowMaxNum) {
2022-07-06 06:38:24 +00:00
printf("\r\n");
2023-10-24 23:15:29 +00:00
printf(" Notice: The result shows only the first %d rows.\r\n", SHELL_DEFAULT_RES_SHOW_NUM);
2023-10-24 07:05:24 +00:00
if (shellIsShowQuery(dump_info->sql)) {
2022-07-21 09:05:06 +00:00
printf(" You can use '>>' to redirect the whole set of the result to a specified file.\r\n");
} else {
printf(" You can use the `LIMIT` clause to get fewer result to show.\r\n");
printf(" Or use '>>' to redirect the whole set of the result to a specified file.\r\n");
}
2022-07-06 06:38:24 +00:00
printf("\r\n");
printf(" You can use Ctrl+C to stop the underway fetching.\r\n");
printf("\r\n");
2023-10-24 07:05:24 +00:00
return;
}
if (numOfPrintRowsThisOne == dump_info->numOfRows) {
return;
}
2020-06-01 15:30:10 +00:00
row = taos_fetch_row(tres);
2023-10-24 07:05:24 +00:00
}
return;
}
2023-10-24 07:05:24 +00:00
void shellDumpResultCallback(void *param, TAOS_RES *tres, int num_of_rows) {
tsDumpInfo *dump_info = (tsDumpInfo *)param;
if (num_of_rows > 0) {
dump_info->numOfRows = num_of_rows;
2023-10-24 07:15:39 +00:00
if (dump_info->numOfAllRows < dump_info->resShowMaxNum) {
if (dump_info->vertical) {
shellVerticalPrintResult(tres, dump_info);
} else {
shellHorizontalPrintResult(tres, dump_info);
}
2023-10-24 07:05:24 +00:00
}
dump_info->numOfAllRows += num_of_rows;
2023-11-14 11:25:54 +00:00
if (!shellCmdkilled) {
taos_fetch_rows_a(tres, shellDumpResultCallback, param);
} else {
tsem_post(&dump_info->sem);
}
2023-10-24 07:05:24 +00:00
} else {
if (num_of_rows < 0) {
printf("\033[31masync retrieve failed, code: %d\033[0m\n", num_of_rows);
}
tsem_post(&dump_info->sem);
}
}
int64_t shellDumpResult(TAOS_RES *tres, char *fname, int32_t *error_no, bool vertical, const char *sql) {
2023-10-24 07:05:24 +00:00
int64_t num_of_rows = 0;
2019-07-11 08:36:16 +00:00
if (fname != NULL) {
2023-10-24 07:05:24 +00:00
num_of_rows = shellDumpResultToFile(fname, tres);
} else {
2023-10-24 07:05:24 +00:00
tsDumpInfo dump_info;
2023-11-14 11:25:54 +00:00
if (!shellCmdkilled) {
init_dump_info(&dump_info, tres, sql, vertical);
taos_fetch_rows_a(tres, shellDumpResultCallback, &dump_info);
tsem_wait(&dump_info.sem);
num_of_rows = dump_info.numOfAllRows;
}
2019-07-11 08:36:16 +00:00
}
2023-11-14 11:25:54 +00:00
*error_no = shellCmdkilled ? TSDB_CODE_TSC_QUERY_KILLED : taos_errno(tres);
2023-10-24 07:05:24 +00:00
return num_of_rows;
2019-07-11 08:36:16 +00:00
}
2022-04-20 11:44:25 +00:00
void shellReadHistory() {
2022-04-21 13:09:43 +00:00
SShellHistory *pHistory = &shell.history;
TdFilePtr pFile = taosOpenFile(pHistory->file, TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) return;
2019-07-11 08:36:16 +00:00
2023-09-01 05:24:47 +00:00
char *line = taosMemoryMalloc(TSDB_MAX_ALLOWED_SQL_LEN + 1);
2022-04-21 13:09:43 +00:00
int32_t read_size = 0;
while ((read_size = taosGetsFile(pFile, TSDB_MAX_ALLOWED_SQL_LEN, line)) > 0) {
2019-07-11 08:36:16 +00:00
line[read_size - 1] = '\0';
taosMemoryFree(pHistory->hist[pHistory->hend]);
pHistory->hist[pHistory->hend] = taosStrdup(line);
2019-07-11 08:36:16 +00:00
2022-04-21 13:09:43 +00:00
pHistory->hend = (pHistory->hend + 1) % SHELL_MAX_HISTORY_SIZE;
2019-07-11 08:36:16 +00:00
2022-04-21 13:09:43 +00:00
if (pHistory->hend == pHistory->hstart) {
pHistory->hstart = (pHistory->hstart + 1) % SHELL_MAX_HISTORY_SIZE;
2019-07-11 08:36:16 +00:00
}
}
2022-10-09 07:40:27 +00:00
taosMemoryFreeClear(line);
taosCloseFile(&pFile);
int64_t file_size;
2023-09-01 05:24:47 +00:00
if (taosStatFile(pHistory->file, &file_size, NULL, NULL) == 0 && file_size > SHELL_MAX_COMMAND_SIZE) {
TdFilePtr pFile = taosOpenFile(pHistory->file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_STREAM | TD_FILE_TRUNC);
if (pFile == NULL) return;
int32_t endIndex = pHistory->hstart;
if (endIndex != 0) {
endIndex = pHistory->hend;
}
for (int32_t i = (pHistory->hend + SHELL_MAX_HISTORY_SIZE - 1) % SHELL_MAX_HISTORY_SIZE; i != endIndex;) {
taosFprintfFile(pFile, "%s\n", pHistory->hist[i]);
i = (i + SHELL_MAX_HISTORY_SIZE - 1) % SHELL_MAX_HISTORY_SIZE;
}
taosFprintfFile(pFile, "%s\n", pHistory->hist[endIndex]);
/* coverity[+retval] */
taosFsyncFile(pFile);
taosCloseFile(&pFile);
}
2022-08-02 01:18:34 +00:00
pHistory->hstart = pHistory->hend;
2019-07-11 08:36:16 +00:00
}
2022-04-20 11:44:25 +00:00
void shellWriteHistory() {
2022-04-21 13:09:43 +00:00
SShellHistory *pHistory = &shell.history;
if (pHistory->hend == pHistory->hstart) return;
2023-09-01 05:24:47 +00:00
TdFilePtr pFile = taosOpenFile(pHistory->file, TD_FILE_CREATE | TD_FILE_WRITE | TD_FILE_STREAM | TD_FILE_APPEND);
2022-04-21 13:09:43 +00:00
if (pFile == NULL) return;
2019-07-11 08:36:16 +00:00
2022-04-21 13:09:43 +00:00
for (int32_t i = pHistory->hstart; i != pHistory->hend;) {
if (pHistory->hist[i] != NULL) {
taosFprintfFile(pFile, "%s\n", pHistory->hist[i]);
taosMemoryFree(pHistory->hist[i]);
pHistory->hist[i] = NULL;
2019-07-11 08:36:16 +00:00
}
2022-04-21 13:09:43 +00:00
i = (i + 1) % SHELL_MAX_HISTORY_SIZE;
2019-07-11 08:36:16 +00:00
}
taosCloseFile(&pFile);
2019-07-11 08:36:16 +00:00
}
void shellCleanupHistory() {
SShellHistory *pHistory = &shell.history;
for (int32_t i = 0; i < SHELL_MAX_HISTORY_SIZE; ++i) {
if (pHistory->hist[i] != NULL) {
taosMemoryFree(pHistory->hist[i]);
pHistory->hist[i] = NULL;
}
}
}
2022-04-20 11:44:25 +00:00
void shellPrintError(TAOS_RES *tres, int64_t st) {
2020-11-10 03:36:13 +00:00
int64_t et = taosGetTimestampUs();
2022-07-06 06:38:24 +00:00
fprintf(stderr, "\r\nDB error: %s (%.6fs)\r\n", taos_errstr(tres), (et - st) / 1E6);
2020-06-01 15:30:10 +00:00
taos_free_result(tres);
2019-07-11 08:36:16 +00:00
}
2022-04-21 13:09:43 +00:00
bool shellIsCommentLine(char *line) {
if (line == NULL) return true;
2022-04-20 11:44:25 +00:00
return shellRegexMatch(line, "^\\s*#.*", REG_EXTENDED);
2019-07-11 08:36:16 +00:00
}
2022-04-21 13:09:43 +00:00
void shellSourceFile(const char *file) {
int32_t read_len = 0;
char *cmd = taosMemoryCalloc(1, TSDB_MAX_ALLOWED_SQL_LEN + 1);
size_t cmd_len = 0;
2022-04-22 09:59:41 +00:00
char fullname[PATH_MAX] = {0};
char sourceFileCommand[PATH_MAX + 8] = {0};
2019-07-11 08:36:16 +00:00
2022-04-22 09:59:41 +00:00
if (taosExpandDir(file, fullname, PATH_MAX) != 0) {
tstrncpy(fullname, file, PATH_MAX);
2019-07-11 08:36:16 +00:00
}
2023-09-01 05:24:47 +00:00
sprintf(sourceFileCommand, "source %s;", fullname);
shellRecordCommandToHistory(sourceFileCommand);
2022-04-22 09:59:41 +00:00
TdFilePtr pFile = taosOpenFile(fullname, TD_FILE_READ | TD_FILE_STREAM);
if (pFile == NULL) {
2022-07-06 06:38:24 +00:00
fprintf(stderr, "failed to open file %s\r\n", fullname);
2022-03-25 16:29:53 +00:00
taosMemoryFree(cmd);
2019-07-11 08:36:16 +00:00
return;
}
2023-09-01 05:24:47 +00:00
char *line = taosMemoryMalloc(TSDB_MAX_ALLOWED_SQL_LEN + 1);
2022-10-09 07:40:27 +00:00
while ((read_len = taosGetsFile(pFile, TSDB_MAX_ALLOWED_SQL_LEN, line)) != -1) {
2023-12-07 11:24:19 +00:00
if ( cmd_len + read_len >= TSDB_MAX_ALLOWED_SQL_LEN) {
printf("read command line too long over 1M, ignore this line. cmd_len = %d read_len=%d \n", (int32_t)cmd_len, read_len);
cmd_len = 0;
memset(line, 0, TSDB_MAX_ALLOWED_SQL_LEN + 1);
continue;
}
2019-07-11 08:36:16 +00:00
line[--read_len] = '\0';
2022-04-21 13:09:43 +00:00
if (read_len == 0 || shellIsCommentLine(line)) { // line starts with #
2019-07-11 08:36:16 +00:00
continue;
}
if (line[read_len - 1] == '\\') {
line[read_len - 1] = ' ';
memcpy(cmd + cmd_len, line, read_len);
cmd_len += read_len;
continue;
}
if (line[read_len - 1] == '\r') {
line[read_len - 1] = ' ';
}
2019-07-11 08:36:16 +00:00
memcpy(cmd + cmd_len, line, read_len);
2022-07-06 06:38:24 +00:00
printf("%s%s\r\n", shell.info.promptHeader, cmd);
shellRunCommand(cmd, false);
2022-01-27 08:03:26 +00:00
memset(cmd, 0, TSDB_MAX_ALLOWED_SQL_LEN);
2019-07-11 08:36:16 +00:00
cmd_len = 0;
}
2022-03-25 16:29:53 +00:00
taosMemoryFree(cmd);
2022-10-09 07:40:27 +00:00
taosMemoryFreeClear(line);
taosCloseFile(&pFile);
2019-07-11 08:36:16 +00:00
}
2019-11-07 10:12:26 +00:00
2024-03-13 12:36:43 +00:00
bool shellGetGrantInfo(char* buf) {
2024-03-12 08:40:36 +00:00
bool community = true;
char sinfo[256] = {0};
2022-04-22 06:18:00 +00:00
tstrncpy(sinfo, taos_get_server_info(shell.conn), sizeof(sinfo));
2022-07-06 06:38:24 +00:00
strtok(sinfo, "\r\n");
2022-04-22 06:18:00 +00:00
2019-11-07 10:12:26 +00:00
char sql[] = "show grants";
2022-04-21 13:09:43 +00:00
TAOS_RES *tres = taos_query(shell.conn, sql);
2020-06-06 07:47:28 +00:00
2022-04-21 13:09:43 +00:00
int32_t code = taos_errno(tres);
2020-01-16 05:11:44 +00:00
if (code != TSDB_CODE_SUCCESS) {
2023-09-01 05:24:47 +00:00
if (code != TSDB_CODE_OPS_NOT_SUPPORT && code != TSDB_CODE_MND_NO_RIGHTS &&
code != TSDB_CODE_PAR_PERMISSION_DENIED) {
2022-07-06 06:38:24 +00:00
fprintf(stderr, "Failed to check Server Edition, Reason:0x%04x:%s\r\n\r\n", code, taos_errstr(tres));
2020-01-16 05:11:44 +00:00
}
2024-03-12 09:34:18 +00:00
return community;
2019-11-07 10:12:26 +00:00
}
2022-04-21 13:09:43 +00:00
int32_t num_fields = taos_field_count(tres);
2019-11-07 10:12:26 +00:00
if (num_fields == 0) {
2022-07-06 06:38:24 +00:00
fprintf(stderr, "\r\nInvalid grant information.\r\n");
2019-11-07 10:12:26 +00:00
exit(0);
} else {
2020-06-19 04:13:08 +00:00
if (tres == NULL) {
2022-07-06 06:38:24 +00:00
fprintf(stderr, "\r\nGrant information is null.\r\n");
2019-11-07 10:12:26 +00:00
exit(0);
}
2020-06-19 04:13:08 +00:00
TAOS_FIELD *fields = taos_fetch_fields(tres);
2022-04-21 13:09:43 +00:00
TAOS_ROW row = taos_fetch_row(tres);
2019-11-07 10:12:26 +00:00
if (row == NULL) {
2022-07-06 06:38:24 +00:00
fprintf(stderr, "\r\nFailed to get grant information from server. Abort.\r\n");
2019-11-07 10:12:26 +00:00
exit(0);
}
2024-05-16 09:30:03 +00:00
char serverVersion[64] = {0};
2019-11-07 10:12:26 +00:00
char expiretime[32] = {0};
char expired[32] = {0};
2024-05-16 09:30:03 +00:00
tstrncpy(serverVersion, row[0], 64);
2019-11-07 10:12:26 +00:00
memcpy(expiretime, row[1], fields[1].bytes);
memcpy(expired, row[2], fields[2].bytes);
if (strcmp(serverVersion, "community") == 0) {
2024-03-12 08:40:36 +00:00
community = true;
} else if (strcmp(expiretime, "unlimited") == 0) {
2024-03-12 08:40:36 +00:00
community = false;
2024-05-20 05:29:44 +00:00
sprintf(buf, "Server is %s, %s and will never expire.\r\n", serverVersion, sinfo);
2019-11-07 10:12:26 +00:00
} else {
2024-03-12 08:40:36 +00:00
community = false;
2024-05-20 05:29:44 +00:00
sprintf(buf, "Server is %s, %s and will expire at %s.\r\n", serverVersion, sinfo,
2023-09-01 05:24:47 +00:00
expiretime);
2019-11-07 10:12:26 +00:00
}
2020-06-19 04:13:08 +00:00
taos_free_result(tres);
2019-11-07 10:12:26 +00:00
}
2022-07-06 06:38:24 +00:00
fprintf(stdout, "\r\n");
2024-03-12 09:34:18 +00:00
return community;
2022-04-21 13:09:43 +00:00
}
#ifdef WINDOWS
BOOL shellQueryInterruptHandler(DWORD fdwCtrlType) {
tsem_post(&shell.cancelSem);
return TRUE;
2022-04-24 12:45:42 +00:00
}
#else
void shellQueryInterruptHandler(int32_t signum, void *sigInfo, void *context) { tsem_post(&shell.cancelSem); }
#endif
2022-04-24 12:45:42 +00:00
2022-04-21 13:09:43 +00:00
void shellCleanup(void *arg) { taosResetTerminalMode(); }
void *shellCancelHandler(void *arg) {
setThreadName("shellCancelHandler");
while (1) {
if (shell.exit == true) {
break;
}
2022-04-21 13:09:43 +00:00
if (tsem_wait(&shell.cancelSem) != 0) {
taosMsleep(10);
continue;
}
#ifdef WEBSOCKET
2023-03-22 08:08:16 +00:00
if (shell.args.restful || shell.args.cloud) {
shell.stop_query = true;
} else {
#endif
2023-03-22 08:08:16 +00:00
if (shell.conn) {
2023-11-14 11:25:54 +00:00
shellCmdkilled = true;
2023-03-22 08:08:16 +00:00
taos_kill_query(shell.conn);
}
#ifdef WEBSOCKET
2023-03-22 08:08:16 +00:00
}
#endif
2023-09-01 05:24:47 +00:00
#ifdef WINDOWS
printf("\n%s", shell.info.promptHeader);
2023-09-01 05:24:47 +00:00
#endif
2022-04-21 13:09:43 +00:00
}
return NULL;
}
void *shellThreadLoop(void *arg) {
setThreadName("shellThreadLoop");
taosGetOldTerminalMode();
taosThreadCleanupPush(shellCleanup, NULL);
do {
char *command = taosMemoryMalloc(SHELL_MAX_COMMAND_SIZE);
if (command == NULL) {
printf("failed to malloc command\r\n");
2022-04-21 13:09:43 +00:00
break;
}
do {
memset(command, 0, SHELL_MAX_COMMAND_SIZE);
taosSetTerminalMode();
if (shellReadCommand(command) != 0) {
break;
}
2022-04-21 13:09:43 +00:00
taosResetTerminalMode();
} while (shellRunCommand(command, true) == 0);
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
destroyThreadLocalGeosCtx();
taosMemoryFreeClear(command);
shellWriteHistory();
shellExit();
} while (0);
2022-04-21 13:29:21 +00:00
2022-04-21 13:09:43 +00:00
taosThreadCleanupPop(1);
return NULL;
}
int32_t shellExecute() {
2023-09-01 05:24:47 +00:00
printf(shell.info.clientVersion, shell.info.cusName, taos_get_client_info(), shell.info.cusName);
2022-04-21 13:09:43 +00:00
fflush(stdout);
SShellArgs *pArgs = &shell.args;
#ifdef WEBSOCKET
if (shell.args.restful || shell.args.cloud) {
2023-03-22 08:08:16 +00:00
if (shell_conn_ws_server(1)) {
return -1;
}
2022-04-21 13:09:43 +00:00
} else {
#endif
2023-03-22 08:08:16 +00:00
if (shell.args.auth == NULL) {
shell.conn = taos_connect(pArgs->host, pArgs->user, pArgs->password, pArgs->database, pArgs->port);
} else {
shell.conn = taos_connect_auth(pArgs->host, pArgs->user, pArgs->auth, pArgs->database, pArgs->port);
}
if (shell.conn == NULL) {
2023-04-25 01:00:41 +00:00
printf("failed to connect to server, reason: %s\n", taos_errstr(NULL));
2023-03-22 08:08:16 +00:00
fflush(stdout);
return -1;
}
#ifdef WEBSOCKET
2022-04-21 13:09:43 +00:00
}
#endif
2022-04-21 13:09:43 +00:00
bool runOnce = pArgs->commands != NULL || pArgs->file[0] != 0;
shellSetConn(shell.conn, runOnce);
2022-04-22 11:27:00 +00:00
shellReadHistory();
if(shell.args.is_bi_mode) {
2023-12-30 08:44:52 +00:00
// need set bi mode
2023-12-30 13:24:58 +00:00
printf("Set BI mode is true.\n");
#ifndef WEBSOCKET
2023-12-30 08:44:52 +00:00
taos_set_conn_mode(shell.conn, TAOS_CONN_MODE_BI, 1);
#endif
}
if (runOnce) {
2022-04-21 13:09:43 +00:00
if (pArgs->commands != NULL) {
2022-07-06 06:38:24 +00:00
printf("%s%s\r\n", shell.info.promptHeader, pArgs->commands);
char *cmd = taosStrdup(pArgs->commands);
shellRunCommand(cmd, true);
2022-04-21 13:09:43 +00:00
taosMemoryFree(cmd);
}
2022-04-22 09:59:41 +00:00
if (pArgs->file[0] != 0) {
2022-04-21 13:09:43 +00:00
shellSourceFile(pArgs->file);
}
#ifdef WEBSOCKET
2023-03-22 08:08:16 +00:00
if (shell.args.restful || shell.args.cloud) {
ws_close(shell.ws_conn);
} else {
#endif
2023-03-22 08:08:16 +00:00
taos_close(shell.conn);
#ifdef WEBSOCKET
2023-03-22 08:08:16 +00:00
}
#endif
2022-04-21 13:09:43 +00:00
shellWriteHistory();
shellCleanupHistory();
2022-04-21 13:09:43 +00:00
return 0;
}
if (tsem_init(&shell.cancelSem, 0, 0) != 0) {
2023-01-05 13:25:31 +00:00
printf("failed to create cancel semaphore\r\n");
2022-04-21 13:09:43 +00:00
return -1;
}
TdThread spid = {0};
taosThreadCreate(&spid, NULL, shellCancelHandler, NULL);
taosSetSignal(SIGTERM, shellQueryInterruptHandler);
taosSetSignal(SIGHUP, shellQueryInterruptHandler);
taosSetSignal(SIGINT, shellQueryInterruptHandler);
2023-09-01 05:24:47 +00:00
#ifdef WEBSOCKET
if (!shell.args.restful && !shell.args.cloud) {
#endif
char* buf = taosMemoryMalloc(512);
2024-03-13 12:36:43 +00:00
bool community = shellGetGrantInfo(buf);
#ifndef WINDOWS
2024-03-13 09:16:42 +00:00
printfIntroduction(community);
#else
2024-03-14 04:56:59 +00:00
#ifndef WEBSOCKET
2024-03-13 09:16:42 +00:00
if(community) {
2024-03-14 06:09:27 +00:00
showAD(false);
2024-03-13 09:16:42 +00:00
}
2024-03-14 04:56:59 +00:00
#endif
2023-09-01 05:24:47 +00:00
#endif
2024-03-13 12:36:43 +00:00
// printf version
if(!community) {
2024-03-13 12:43:03 +00:00
printf("%s\n", buf);
2024-03-13 12:36:43 +00:00
}
taosMemoryFree(buf);
2024-03-13 09:16:42 +00:00
#ifdef WEBSOCKET
}
#endif
2022-04-21 13:09:43 +00:00
while (1) {
taosThreadCreate(&shell.pid, NULL, shellThreadLoop, NULL);
2022-04-21 13:09:43 +00:00
taosThreadJoin(shell.pid, NULL);
taosThreadClear(&shell.pid);
if (shell.exit) {
tsem_post(&shell.cancelSem);
break;
}
2022-04-21 13:09:43 +00:00
}
2024-03-14 04:56:59 +00:00
#ifndef WEBSOCKET
2024-03-12 08:40:36 +00:00
// commnuity
if (community) {
2024-03-13 09:16:42 +00:00
showAD(true);
2024-03-12 08:40:36 +00:00
}
2024-03-14 04:56:59 +00:00
#endif
2024-03-12 08:40:36 +00:00
taosThreadJoin(spid, NULL);
2022-04-21 13:09:43 +00:00
shellCleanupHistory();
2023-02-15 03:27:44 +00:00
taos_kill_query(shell.conn);
taos_close(shell.conn);
2022-04-21 13:09:43 +00:00
return 0;
2019-11-07 10:12:26 +00:00
}