TDengine/source/libs/parser/src/parTokenizer.c

890 lines
27 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/>.
*/
2020-04-02 07:17:47 +00:00
#include "os.h"
2022-03-10 07:36:06 +00:00
#include "parToken.h"
2020-03-12 06:02:55 +00:00
#include "taosdef.h"
2022-04-26 03:50:35 +00:00
#include "thash.h"
#include "ttokendef.h"
2019-07-11 08:36:16 +00:00
2019-11-07 10:12:26 +00:00
// All the keywords of the SQL language are stored in a hash table
2019-07-11 08:36:16 +00:00
typedef struct SKeyword {
2019-11-07 10:12:26 +00:00
const char* name; // The keyword name
2020-08-08 09:48:08 +00:00
uint16_t type; // type
2019-11-07 10:12:26 +00:00
uint8_t len; // length
2019-07-11 08:36:16 +00:00
} SKeyword;
2022-04-30 03:40:12 +00:00
// clang-format off
2019-11-07 10:12:26 +00:00
// keywords in sql string
2019-07-11 08:36:16 +00:00
static SKeyword keywordTable[] = {
2022-07-27 03:55:19 +00:00
{"ACCOUNT", TK_ACCOUNT},
{"ACCOUNTS", TK_ACCOUNTS},
{"ADD", TK_ADD},
{"AGGREGATE", TK_AGGREGATE},
{"ALL", TK_ALL},
{"ALTER", TK_ALTER},
{"ANALYZE", TK_ANALYZE},
{"AND", TK_AND},
2023-11-27 12:01:00 +00:00
{"ANTI", TK_ANTI},
2024-10-15 02:00:38 +00:00
{"ANODE", TK_ANODE},
{"ANODES", TK_ANODES},
{"ANOMALY_WINDOW", TK_ANOMALY_WINDOW},
2023-12-19 03:17:39 +00:00
// {"ANY", TK_ANY},
2022-07-27 03:55:19 +00:00
{"APPS", TK_APPS},
{"AS", TK_AS},
{"ASC", TK_ASC},
2023-11-27 12:01:00 +00:00
{"ASOF", TK_ASOF},
2022-07-27 03:55:19 +00:00
{"BALANCE", TK_BALANCE},
2023-08-14 09:21:15 +00:00
{"BATCH_SCAN", TK_BATCH_SCAN},
2022-07-27 03:55:19 +00:00
{"BETWEEN", TK_BETWEEN},
{"BIGINT", TK_BIGINT},
2022-08-11 12:26:40 +00:00
{"BINARY", TK_BINARY},
2022-07-27 03:55:19 +00:00
{"BNODE", TK_BNODE},
{"BNODES", TK_BNODES},
{"BOOL", TK_BOOL},
{"BOTH", TK_BOTH},
2022-07-27 03:55:19 +00:00
{"BUFFER", TK_BUFFER},
{"BUFSIZE", TK_BUFSIZE},
{"BY", TK_BY},
{"CACHE", TK_CACHE},
{"CACHEMODEL", TK_CACHEMODEL},
{"CACHESIZE", TK_CACHESIZE},
{"CALC_NOTIFY_ONLY", TK_CALC_NOTIFY_ONLY},
2022-09-22 11:20:21 +00:00
{"CASE", TK_CASE},
2022-07-27 03:55:19 +00:00
{"CAST", TK_CAST},
2023-09-19 06:03:06 +00:00
{"CHILD", TK_CHILD},
2022-07-27 03:55:19 +00:00
{"CLIENT_VERSION", TK_CLIENT_VERSION},
{"CLUSTER", TK_CLUSTER},
{"COLUMN", TK_COLUMN},
{"COMMENT", TK_COMMENT},
{"COMP", TK_COMP},
2022-12-27 03:11:02 +00:00
{"COMPACT", TK_COMPACT},
2023-11-16 03:41:02 +00:00
{"COMPACTS", TK_COMPACTS},
2024-11-26 11:46:48 +00:00
{"COMPACT_INTERVAL", TK_COMPACT_INTERVAL},
{"COMPACT_TIME_OFFSET", TK_COMPACT_TIME_OFFSET},
{"COMPACT_TIME_RANGE", TK_COMPACT_TIME_RANGE},
2022-07-27 03:55:19 +00:00
{"CONNECTION", TK_CONNECTION},
{"CONNECTIONS", TK_CONNECTIONS},
2022-08-11 12:26:40 +00:00
{"CONNS", TK_CONNS},
2022-07-27 03:55:19 +00:00
{"CONSUMER", TK_CONSUMER},
{"CONSUMERS", TK_CONSUMERS},
{"CONTAINS", TK_CONTAINS},
{"COUNT", TK_COUNT},
2024-01-17 06:22:19 +00:00
{"COUNT_WINDOW", TK_COUNT_WINDOW},
2022-07-27 03:55:19 +00:00
{"CREATE", TK_CREATE},
2024-05-22 11:00:47 +00:00
{"CREATEDB", TK_CREATEDB},
2022-07-27 03:55:19 +00:00
{"CURRENT_USER", TK_CURRENT_USER},
{"DATABASE", TK_DATABASE},
{"DATABASES", TK_DATABASES},
{"DBS", TK_DBS},
feat(decimal): support decimal data type (#30060) * decimal: create table * decimal: add test case decimal.py * decimal: add decimal.c * support input decimal * decimal test * refactor svalue * fix test cases * add decimal unit test * add decimal test cmake * support insert and query decimal type * define wide integer, support decimal128 * support decimal128 divide * set decimal type expr res types * scalar decimal * convert to decimal * fix decimal64/128 from str and to str * fix decimal from str and decimal to str * decimal simple conversion * unit test for decimal * decimal conversion and unit tests * decimal + - * / * decimal scalar ops and comparision * start to refactor GET_TYPED_DATA * support decimal max func, cast func * refactor GET_TYPED_DATA interface * decimal scalar comparision * start to implement sum for decimal * support sum and avg for decimal type * decimal tests * add decimal test * decimal add test cases * decimal use int256/int128 * decimal testing * fix decimal table meta and add tests for decimal col streams * fix create stream and create tsma * test insert decimal values * decimal from str * test decimal input * test parse decimal from string * add taos_fetch_field_e api * decimal insert tests * test decimal operators * decimal operator test * feat:support decimal in raw block * decimal operator tests * decimal test * feat:support decimal in raw block * feat:support decimal in raw block * feat:add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * feat:remove add schemaExt to SMqDataRsp * decimal test operators * decimal operator test * test decimal operators * test decimal compare operators * decimal unary operator test * decimal col with decimal col oper test * test decimal col filtering * fix decimal float operator test * decimal test where filtering * fix decimal filtering * fix decimal order by * fix decimal op test * test decimal agg funcs * test decimal functions * remove assert * fix ci build for ret check * fix decimal windows build * fix ci ret check * skip decimal ret check * skip decimal ret check * fix decimal tests * fix decimal ci test * decimal test * fix(tmq): heap user after free * fix(tmq): double free * fix(tmq): double free * fix decimal tests * fix(decimal): decimal test ci build * fix(decimal): windows build * fix(decimal): decimal test build * fix(decimal): fix decimal build and tests * fix(decimal): fix decimal tests * fix(decimal): fix taos_fetch_fields_e api * fix(decimal): fix decimal taos_fetch_fields_e api * fix(decimal): rebase 3.0 * fix(decimal): fix decimal functions * fix(decimal): fix decimal test case memory leak * fix(decimal): fix decimal tests * fix(decimal): fix decimal test case * fix(decimal): fix decimal tests * feat(decimal): fix unit tests * feat(decimal): fix deicmal unit test --------- Co-authored-by: wangmm0220 <wangmm0220@gmail.com> Co-authored-by: yihaoDeng <yhdeng@taosdata.com>
2025-03-14 10:08:07 +00:00
{"DECIMAL", TK_DECIMAL},
2022-07-27 03:55:19 +00:00
{"DELETE", TK_DELETE},
{"DELETE_OUTPUT_TABLE", TK_DELETE_OUTPUT_TABLE},
{"DELETE_RECALC", TK_DELETE_RECALC},
2022-07-27 03:55:19 +00:00
{"DESC", TK_DESC},
{"DESCRIBE", TK_DESCRIBE},
{"DISTINCT", TK_DISTINCT},
{"DISTRIBUTED", TK_DISTRIBUTED},
{"DNODE", TK_DNODE},
{"DNODES", TK_DNODES},
{"DOUBLE", TK_DOUBLE},
{"DROP", TK_DROP},
{"DURATION", TK_DURATION},
2022-09-22 11:20:21 +00:00
{"ELSE", TK_ELSE},
2022-07-27 03:55:19 +00:00
{"ENABLE", TK_ENABLE},
2024-03-26 11:56:15 +00:00
{"ENCRYPTIONS", TK_ENCRYPTIONS},
{"ENCRYPT_ALGORITHM", TK_ENCRYPT_ALGORITHM},
{"ENCRYPT_KEY", TK_ENCRYPT_KEY},
2022-09-22 11:20:21 +00:00
{"END", TK_END},
2022-07-27 03:55:19 +00:00
{"EXISTS", TK_EXISTS},
{"EXPIRED_TIME", TK_EXPIRED_TIME},
2022-07-27 03:55:19 +00:00
{"EXPLAIN", TK_EXPLAIN},
{"EVENT_TYPE", TK_EVENT_TYPE},
2022-12-13 06:18:03 +00:00
{"EVENT_WINDOW", TK_EVENT_WINDOW},
2022-07-27 03:55:19 +00:00
{"EVERY", TK_EVERY},
{"FILE", TK_FILE},
{"FILL", TK_FILL},
{"FILL_HISTORY", TK_FILL_HISTORY},
{"FILL_HISTORY_FIRST", TK_FILL_HISTORY_FIRST},
2022-07-27 03:55:19 +00:00
{"FIRST", TK_FIRST},
{"FLOAT", TK_FLOAT},
{"FLUSH", TK_FLUSH},
{"FROM", TK_FROM},
{"FOR", TK_FOR},
{"FORCE", TK_FORCE},
{"FORCE_OUTPUT", TK_FORCE_OUTPUT},
2023-11-27 12:01:00 +00:00
{"FULL", TK_FULL},
2022-07-27 03:55:19 +00:00
{"FUNCTION", TK_FUNCTION},
{"FUNCTIONS", TK_FUNCTIONS},
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
{"GEOMETRY", TK_GEOMETRY},
2022-07-27 03:55:19 +00:00
{"GRANT", TK_GRANT},
{"GRANTS", TK_GRANTS},
2024-01-18 07:51:45 +00:00
{"FULL", TK_FULL},
2024-01-31 05:44:00 +00:00
{"LOGS", TK_LOGS},
2024-01-18 09:49:11 +00:00
{"MACHINES", TK_MACHINES},
2022-07-27 03:55:19 +00:00
{"GROUP", TK_GROUP},
2024-04-10 11:27:36 +00:00
{"HASH_JOIN", TK_HASH_JOIN},
2022-07-27 03:55:19 +00:00
{"HAVING", TK_HAVING},
2023-08-24 07:54:10 +00:00
{"HOST", TK_HOST},
2022-07-27 03:55:19 +00:00
{"IF", TK_IF},
{"IGNORE", TK_IGNORE},
{"IGNORE_DISORDER", TK_IGNORE_DISORDER},
2022-07-27 03:55:19 +00:00
{"IMPORT", TK_IMPORT},
{"IN", TK_IN},
{"INDEX", TK_INDEX},
{"INDEXES", TK_INDEXES},
{"INNER", TK_INNER},
{"INSERT", TK_INSERT},
2022-08-11 12:26:40 +00:00
{"INT", TK_INT},
2022-07-27 03:55:19 +00:00
{"INTEGER", TK_INTEGER},
{"INTERVAL", TK_INTERVAL},
{"INTO", TK_INTO},
{"IS", TK_IS},
2023-11-27 12:01:00 +00:00
{"JLIMIT", TK_JLIMIT},
2022-07-27 03:55:19 +00:00
{"JOIN", TK_JOIN},
{"JSON", TK_JSON},
{"KEEP", TK_KEEP},
2024-01-25 03:20:04 +00:00
{"KEY", TK_KEY},
2022-07-27 03:55:19 +00:00
{"KILL", TK_KILL},
{"LANGUAGE", TK_LANGUAGE},
2022-07-27 03:55:19 +00:00
{"LAST", TK_LAST},
{"LAST_ROW", TK_LAST_ROW},
{"LEADER", TK_LEADER},
{"LEADING", TK_LEADING},
2023-11-27 12:01:00 +00:00
{"LEFT", TK_LEFT},
2022-08-11 07:37:26 +00:00
{"LICENCES", TK_LICENCES},
2022-07-27 03:55:19 +00:00
{"LIKE", TK_LIKE},
{"LIMIT", TK_LIMIT},
{"LINEAR", TK_LINEAR},
{"LOCAL", TK_LOCAL},
{"LOW_LATENCY_CALC", TK_LOW_LATENCY_CALC},
2022-07-27 03:55:19 +00:00
{"MATCH", TK_MATCH},
{"MAXROWS", TK_MAXROWS},
{"MAX_DELAY", TK_MAX_DELAY},
{"BWLIMIT", TK_BWLIMIT},
2022-07-27 03:55:19 +00:00
{"MERGE", TK_MERGE},
{"META", TK_META},
2023-06-30 11:36:39 +00:00
{"ONLY", TK_ONLY},
2022-07-27 03:55:19 +00:00
{"MINROWS", TK_MINROWS},
{"MINUS", TK_MINUS},
{"MNODE", TK_MNODE},
{"MNODES", TK_MNODES},
{"MODIFY", TK_MODIFY},
{"MODULES", TK_MODULES},
2023-09-19 06:03:06 +00:00
{"NORMAL", TK_NORMAL},
2022-07-27 03:55:19 +00:00
{"NCHAR", TK_NCHAR},
{"NEXT", TK_NEXT},
2024-11-28 10:29:20 +00:00
{"NEAR", TK_NEAR},
2022-07-27 03:55:19 +00:00
{"NMATCH", TK_NMATCH},
{"NONE", TK_NONE},
{"NOT", TK_NOT},
{"NOW", TK_NOW},
{"NOTIFY_OPTIONS", TK_NOTIFY_OPTIONS},
2023-08-14 09:21:15 +00:00
{"NO_BATCH_SCAN", TK_NO_BATCH_SCAN},
2022-07-27 03:55:19 +00:00
{"NULL", TK_NULL},
2023-02-03 07:37:04 +00:00
{"NULL_F", TK_NULL_F},
2022-07-27 03:55:19 +00:00
{"NULLS", TK_NULLS},
{"OFFSET", TK_OFFSET},
{"ON", TK_ON},
{"ON_FAILURE_PAUSE", TK_ON_FAILURE_PAUSE},
{"OPTIONS", TK_OPTIONS},
2022-07-27 03:55:19 +00:00
{"OR", TK_OR},
{"ORDER", TK_ORDER},
2023-11-27 12:01:00 +00:00
{"OUTER", TK_OUTER},
2022-07-27 03:55:19 +00:00
{"OUTPUTTYPE", TK_OUTPUTTYPE},
{"OUTPUT_SUBTABLE", TK_OUTPUT_SUBTABLE},
2022-07-27 03:55:19 +00:00
{"PAGES", TK_PAGES},
{"PAGESIZE", TK_PAGESIZE},
{"PARA_TABLES_SORT", TK_PARA_TABLES_SORT},
2022-08-11 12:26:40 +00:00
{"PARTITION", TK_PARTITION},
{"PARTITION_FIRST", TK_PARTITION_FIRST},
2022-08-11 12:26:40 +00:00
{"PASS", TK_PASS},
2022-07-27 03:55:19 +00:00
{"PORT", TK_PORT},
{"POSITION", TK_POSITION},
2022-07-27 03:55:19 +00:00
{"PPS", TK_PPS},
2024-01-25 03:20:04 +00:00
{"PRIMARY", TK_PRIMARY},
{"PRE_FILTER", TK_PRE_FILTER},
{"COMPOSITE", TK_COMPOSITE},
2022-07-27 03:55:19 +00:00
{"PRECISION", TK_PRECISION},
{"PREV", TK_PREV},
{"PRIVILEGES", TK_PRIVILEGES},
2022-07-27 03:55:19 +00:00
{"QNODE", TK_QNODE},
{"QNODES", TK_QNODES},
{"QTIME", TK_QTIME},
{"QUERIES", TK_QUERIES},
{"QUERY", TK_QUERY},
{"PI", TK_PI},
{"RAND", TK_RAND},
2022-07-27 03:55:19 +00:00
{"RANGE", TK_RANGE},
{"RATIO", TK_RATIO},
{"PERIOD", TK_PERIOD},
2022-07-27 03:55:19 +00:00
{"READ", TK_READ},
2024-01-31 06:20:49 +00:00
{"RECURSIVE", TK_RECURSIVE},
2022-07-27 03:55:19 +00:00
{"REDISTRIBUTE", TK_REDISTRIBUTE},
{"RENAME", TK_RENAME},
{"REPLACE", TK_REPLACE},
{"REPLICAS", TK_REPLICAS},
2022-07-27 03:55:19 +00:00
{"REPLICA", TK_REPLICA},
{"RESET", TK_RESET},
2023-05-09 11:29:57 +00:00
{"RESTORE", TK_RESTORE},
2022-07-27 03:55:19 +00:00
{"RETENTIONS", TK_RETENTIONS},
{"REVOKE", TK_REVOKE},
2023-11-27 12:01:00 +00:00
{"RIGHT", TK_RIGHT},
2022-07-27 03:55:19 +00:00
{"ROLLUP", TK_ROLLUP},
{"SCHEMALESS", TK_SCHEMALESS},
{"SCORES", TK_SCORES},
{"SELECT", TK_SELECT},
2023-11-27 12:01:00 +00:00
{"SEMI", TK_SEMI},
2022-07-27 03:55:19 +00:00
{"SERVER_STATUS", TK_SERVER_STATUS},
{"SERVER_VERSION", TK_SERVER_VERSION},
{"SESSION", TK_SESSION},
{"SET", TK_SET},
{"SHOW", TK_SHOW},
{"SINGLE_STABLE", TK_SINGLE_STABLE},
{"SKIP_TSMA", TK_SKIP_TSMA},
2022-07-27 03:55:19 +00:00
{"SLIDING", TK_SLIDING},
{"SLIMIT", TK_SLIMIT},
{"SMA", TK_SMA},
{"SMALLDATA_TS_SORT", TK_SMALLDATA_TS_SORT},
2022-07-27 03:55:19 +00:00
{"SMALLINT", TK_SMALLINT},
{"SNODE", TK_SNODE},
{"SNODES", TK_SNODES},
{"SORT_FOR_GROUP", TK_SORT_FOR_GROUP},
2022-07-27 03:55:19 +00:00
{"SOFFSET", TK_SOFFSET},
{"SPLIT", TK_SPLIT},
{"STABLE", TK_STABLE},
{"STABLES", TK_STABLES},
2022-12-13 06:18:03 +00:00
{"START", TK_START},
2022-07-27 03:55:19 +00:00
{"STATE", TK_STATE},
{"STATE_WINDOW", TK_STATE_WINDOW},
{"STOP", TK_STOP},
2022-07-27 03:55:19 +00:00
{"STORAGE", TK_STORAGE},
{"STREAM", TK_STREAM},
{"STREAMS", TK_STREAMS},
{"STRICT", TK_STRICT},
2022-12-13 06:18:03 +00:00
{"STT_TRIGGER", TK_STT_TRIGGER},
{"SUBSCRIBE", TK_SUBSCRIBE},
2022-07-27 03:55:19 +00:00
{"SUBSCRIPTIONS", TK_SUBSCRIPTIONS},
{"SUBSTR", TK_SUBSTR},
{"SUBSTRING", TK_SUBSTRING},
2022-07-27 03:55:19 +00:00
{"SYSINFO", TK_SYSINFO},
2023-09-19 06:03:06 +00:00
{"SYSTEM", TK_SYSTEM},
2022-07-27 03:55:19 +00:00
{"TABLE", TK_TABLE},
{"TABLES", TK_TABLES},
{"TABLE_PREFIX", TK_TABLE_PREFIX},
{"TABLE_SUFFIX", TK_TABLE_SUFFIX},
2022-07-27 03:55:19 +00:00
{"TAG", TK_TAG},
{"TAGS", TK_TAGS},
{"TBNAME", TK_TBNAME},
2022-09-22 11:20:21 +00:00
{"THEN", TK_THEN},
2022-07-27 03:55:19 +00:00
{"TIMESTAMP", TK_TIMESTAMP},
{"TIMEZONE", TK_TIMEZONE},
{"TINYINT", TK_TINYINT},
{"TO", TK_TO},
{"TODAY", TK_TODAY},
{"TOPIC", TK_TOPIC},
{"TOPICS", TK_TOPICS},
{"TRAILING", TK_TRAILING},
2022-07-27 03:55:19 +00:00
{"TRANSACTION", TK_TRANSACTION},
{"TRANSACTIONS", TK_TRANSACTIONS},
{"TRIM", TK_TRIM},
{"TROWS", TK_TROWS},
2022-09-13 06:19:50 +00:00
{"TSDB_PAGESIZE", TK_TSDB_PAGESIZE},
2022-07-27 03:55:19 +00:00
{"TSERIES", TK_TSERIES},
2023-11-20 08:36:13 +00:00
{"TSMA", TK_TSMA},
{"TSMAS", TK_TSMAS},
2022-07-27 03:55:19 +00:00
{"TTL", TK_TTL},
{"UNION", TK_UNION},
2023-05-16 01:50:10 +00:00
{"UNSAFE", TK_UNSAFE},
2022-07-27 03:55:19 +00:00
{"UNSIGNED", TK_UNSIGNED},
{"UNTREATED", TK_UNTREATED},
{"UPDATE", TK_UPDATE},
2022-07-27 03:55:19 +00:00
{"USE", TK_USE},
{"USER", TK_USER},
{"USERS", TK_USERS},
{"USING", TK_USING},
{"VALUE", TK_VALUE},
2023-02-03 07:37:04 +00:00
{"VALUE_F", TK_VALUE_F},
2022-07-27 03:55:19 +00:00
{"VALUES", TK_VALUES},
{"VARCHAR", TK_VARCHAR},
{"VARIABLES", TK_VARIABLES},
{"VERBOSE", TK_VERBOSE},
{"VGROUP", TK_VGROUP},
{"VGROUPS", TK_VGROUPS},
2023-09-21 11:28:07 +00:00
{"VIEW", TK_VIEW},
2023-10-09 09:19:36 +00:00
{"VIEWS", TK_VIEWS},
{"VIRTUAL", TK_VIRTUAL},
2023-05-10 01:07:52 +00:00
{"VNODE", TK_VNODE},
{"VNODES", TK_VNODES},
{"VTABLE", TK_VTABLE},
2022-07-27 03:55:19 +00:00
{"WAL_FSYNC_PERIOD", TK_WAL_FSYNC_PERIOD},
{"WAL_LEVEL", TK_WAL_LEVEL},
2022-07-25 13:09:06 +00:00
{"WAL_RETENTION_PERIOD", TK_WAL_RETENTION_PERIOD},
{"WAL_RETENTION_SIZE", TK_WAL_RETENTION_SIZE},
{"WAL_ROLL_PERIOD", TK_WAL_ROLL_PERIOD},
{"WAL_SEGMENT_SIZE", TK_WAL_SEGMENT_SIZE},
2022-07-27 03:55:19 +00:00
{"WATERMARK", TK_WATERMARK},
2022-09-22 11:20:21 +00:00
{"WHEN", TK_WHEN},
2022-07-27 03:55:19 +00:00
{"WHERE", TK_WHERE},
2023-11-27 12:01:00 +00:00
{"WINDOW", TK_WINDOW},
{"WINDOW_OPEN", TK_WINDOW_OPEN},
2022-07-27 03:55:19 +00:00
{"WINDOW_CLOSE", TK_WINDOW_CLOSE},
2023-11-27 12:01:00 +00:00
{"WINDOW_OFFSET", TK_WINDOW_OFFSET},
2022-07-27 03:55:19 +00:00
{"WITH", TK_WITH},
{"WRITE", TK_WRITE},
{"_C0", TK_ROWTS},
{"_IROWTS", TK_IROWTS},
2024-11-28 10:29:20 +00:00
{"_IROWTS_ORIGIN", TK_IROWTS_ORIGIN},
{"_ISFILLED", TK_ISFILLED},
2022-07-27 03:55:19 +00:00
{"_QDURATION", TK_QDURATION},
{"_QEND", TK_QEND},
{"_QSTART", TK_QSTART},
{"_ROWTS", TK_ROWTS},
{"_TAGS", TK_QTAGS},
2022-07-27 03:55:19 +00:00
{"_WDURATION", TK_WDURATION},
{"_WEND", TK_WEND},
{"_WSTART", TK_WSTART},
2024-10-15 02:00:38 +00:00
{"_FLOW", TK_FLOW},
{"_FHIGH", TK_FHIGH},
{"_FROWTS", TK_FROWTS},
{"_TCURRENT_TS", TK_TCURRENT_TS},
{"_TWSTART", TK_TWSTART},
{"_TWEND", TK_TWEND},
{"_TWDURATION", TK_TWDURATION},
{"_TWROWNUM", TK_TWROWNUM},
{"_TWLOCALTIME", TK_TLOCALTIME},
{"_TGRPID", TK_TGRPID},
{"ALIVE", TK_ALIVE},
2023-08-15 05:57:05 +00:00
{"VARBINARY", TK_VARBINARY},
{"S3_CHUNKPAGES", TK_S3_CHUNKPAGES},
2024-04-08 02:31:26 +00:00
{"S3_KEEPLOCAL", TK_S3_KEEPLOCAL},
{"S3_COMPACT", TK_S3_COMPACT},
{"S3MIGRATE", TK_S3MIGRATE},
{"KEEP_TIME_OFFSET", TK_KEEP_TIME_OFFSET},
{"ARBGROUPS", TK_ARBGROUPS},
2024-06-17 06:31:39 +00:00
{"IS_IMPORT", TK_IS_IMPORT},
2024-11-02 13:36:08 +00:00
{"DISK_INFO", TK_DISK_INFO},
{"AUTO", TK_AUTO},
2024-12-09 08:21:14 +00:00
{"COLS", TK_COLS},
{"NOTIFY", TK_NOTIFY},
{"NOTIFY_HISTORY", TK_NOTIFY_HISTORY},
2025-02-06 07:14:38 +00:00
{"REGEXP", TK_REGEXP},
2025-02-12 08:20:56 +00:00
{"ASSIGN", TK_ASSIGN},
2025-02-25 08:48:43 +00:00
{"TRUE_FOR", TK_TRUE_FOR},
feat(stream): add new trigger continuous_window_close (#30125) * opt stream build twa result * opt force window close memory * feat(stream):optimize new interval and scan operator * adj log * opt code * opt code * fill history * fix issue for fill history * add ci * feat(stream): add new stream nonblock interval operator * adjust code * use new scan operator * use new scan operator * add log * fix issue * recover stream scan next function * fix issue * fix issue * fix issue * ignore disorder data * fix issue * fix issue for interval sliding * fix issue * fix ci issue * fix ci issue * fix ci issue * add semi && final nonblock interval operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * refactor(stream): track the msgId for each upstream tasks. * fix(stream): fix race condition. * fix(stream): update the task last msgId when putting into input queue succ. * fix issue * fix issue * put recalculate data to rocksdb * fix issue * fix issue * enh(query)[TD-33071]: add support for saving and restoring tsdbReader scan progress - Implement functionality to save scan progress during tsdbReader operations - Enable resuming scans from the last saved position * fix issue * fix issue * fix issue * fix issue * fix issue * add rec interval check * enh(stream):add recalculate tasks. * enh(stream): support the re-calculate the tasks. * fix issue && do refactor * do refactor * fix issue * fix issue * update backend opt * add new interface * add new session operator * support blob * add new session operator * fix issue * add rec state for rec task * fix invalid read * add new session window * enh(stream): update the stream tasks backend. * new session operator * add pull data * fix(stream): fix error in expand stream backend. * fix issue * fix issue * fix issue * merge code * fix issue * fix(stream): check for null ptr. * fix(stream): add more check. * fix issue * fix issue * fix issue * add debug code * fix issue * fix issue * fix issue * set rec end flag * fix(stream): opt re-calculate stream tasks. * fix issue * fix issue * add new operator * enh(stream): dispatch recalculate block to agg tasks. * fix issue * fix issue * fix(stream): adjust filter. * fix issue * refactor * refactor(stream): adjust the recalculate end block. * fix issue * fix(stream): set correct create trigger block. * fix issue * fix(stream): fix error in build recalculate end block. * fix(stream): check null ptr. * add stream client && fix issue * fix mem leak * fix(stream): free msg. * add stream client * fix(stream): fix error. * add stream client && fix issue * add stream client * refactor(stream): set the recalculate task complete. * add wend and group_id for session window dest table * feat(stream): refactor and set the recalcul agg task complete. * add cfg for adapter * fix issue * add state && event operator * feat(stream): support fill-history task. * add new fill operator * fix(stream): set correct backend when updating fill-history task to recalculate task. * add new fill operator * fix(stream): s2025-03-06 11:10:31.272 et ops always open in scan tsdb * fix(stream):set the correct taskType for sink task. * new fill operator * adj stream fill operator * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * fix issue * adj test * fix issue * fix(stream): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(steam): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix(stream): fix issue * fix: ut com error * fix(stream): fix mem leak and adjust operator type check rule * fix(stream): fix mem leak and adjust test case * refactor code * fix(stream): free items. * fix(stream): free fix memory leak. * fix(stream): fix syntax error. * fix: ignore unexpect block * fix: adjust op type --------- Co-authored-by: Haojun Liao <hjliao@taosdata.com> Co-authored-by: Jinqing Kuang <kuangjinqingcn@gmail.com> Co-authored-by: yihaoDeng <luomoxyz@126.com>
2025-03-14 12:14:01 +00:00
{"META_ONLY", TK_META_ONLY},
{"VTABLES", TK_VTABLES},
{"META_ONLY", TK_META_ONLY}
2019-07-11 08:36:16 +00:00
};
2022-04-30 03:40:12 +00:00
// clang-format on
2019-07-11 08:36:16 +00:00
static const char isIdChar[] = {
/* x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 xA xB xC xD xE xF */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 1x */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 2x */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, /* 3x */
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 4x */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, /* 5x */
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 6x */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, /* 7x */
};
2020-10-27 09:34:28 +00:00
static void* keywordHashTable = NULL;
2019-07-11 08:36:16 +00:00
2024-07-23 07:59:10 +00:00
static int32_t doInitKeywordsTable(void) {
int numOfEntries = tListLen(keywordTable);
2022-04-26 03:50:35 +00:00
2020-10-27 09:34:28 +00:00
keywordHashTable = taosHashInit(numOfEntries, MurmurHash3_32, true, false);
for (int32_t i = 0; i < numOfEntries; i++) {
2020-08-06 05:53:53 +00:00
keywordTable[i].len = (uint8_t)strlen(keywordTable[i].name);
void* ptr = &keywordTable[i];
2024-07-23 07:59:10 +00:00
int32_t code = taosHashPut(keywordHashTable, keywordTable[i].name, keywordTable[i].len, (void*)&ptr, POINTER_BYTES);
if (TSDB_CODE_SUCCESS != code) {
taosHashCleanup(keywordHashTable);
return code;
}
2019-07-11 08:36:16 +00:00
}
2024-07-23 07:59:10 +00:00
return TSDB_CODE_SUCCESS;
}
static int32_t tKeywordCode(const char* z, int n) {
2020-05-07 15:15:35 +00:00
char key[512] = {0};
2022-04-26 03:50:35 +00:00
if (n > tListLen(key)) { // too long token, can not be any other token type
return TK_NK_ID;
2020-05-08 04:10:33 +00:00
}
2022-04-26 03:50:35 +00:00
2019-07-11 08:36:16 +00:00
for (int32_t j = 0; j < n; ++j) {
if (z[j] >= 'a' && z[j] <= 'z') {
2020-05-08 04:10:33 +00:00
key[j] = (char)(z[j] & 0xDF); // to uppercase and set the null-terminated
2019-07-11 08:36:16 +00:00
} else {
key[j] = z[j];
}
}
2021-06-09 08:00:37 +00:00
if (keywordHashTable == NULL) {
2022-03-05 23:12:08 +00:00
return TK_NK_ILLEGAL;
2021-06-09 08:00:37 +00:00
}
2021-07-06 15:22:37 +00:00
2020-10-27 09:34:28 +00:00
SKeyword** pKey = (SKeyword**)taosHashGet(keywordHashTable, key, n);
2022-04-26 03:50:35 +00:00
return (pKey != NULL) ? (*pKey)->type : TK_NK_ID;
2019-07-11 08:36:16 +00:00
}
2019-07-25 06:14:38 +00:00
/*
* Return the length of the token that begins at z[0].
* Store the token type in *type before returning.
*/
uint32_t tGetToken(const char* z, uint32_t* tokenId) {
uint32_t i;
2019-07-11 08:36:16 +00:00
switch (*z) {
case ' ':
case '\t':
case '\n':
case '\f':
case '\r': {
for (i = 1; isspace(z[i]); i++) {
}
2022-03-05 23:12:08 +00:00
*tokenId = TK_NK_SPACE;
2019-07-11 08:36:16 +00:00
return i;
}
case ':': {
*tokenId = TK_NK_COLON;
2019-07-11 08:36:16 +00:00
return 1;
}
case '-': {
if (z[1] == '-') {
for (i = 2; z[i] && z[i] != '\n'; i++) {
}
*tokenId = TK_NK_COMMENT;
2019-07-11 08:36:16 +00:00
return i;
} else if (z[1] == '>') {
*tokenId = TK_NK_ARROW;
return 2;
2019-07-11 08:36:16 +00:00
}
2022-03-22 03:50:27 +00:00
*tokenId = TK_NK_MINUS;
2019-07-11 08:36:16 +00:00
return 1;
}
case '(': {
*tokenId = TK_NK_LP;
2019-07-11 08:36:16 +00:00
return 1;
}
case ')': {
*tokenId = TK_NK_RP;
2019-07-11 08:36:16 +00:00
return 1;
}
case ';': {
*tokenId = TK_NK_SEMI;
2019-07-11 08:36:16 +00:00
return 1;
}
case '+': {
*tokenId = TK_NK_PLUS;
2019-07-11 08:36:16 +00:00
return 1;
}
case '*': {
*tokenId = TK_NK_STAR;
2019-07-11 08:36:16 +00:00
return 1;
}
case '/': {
if (z[1] != '*' || z[2] == 0) {
*tokenId = TK_NK_SLASH;
2019-07-11 08:36:16 +00:00
return 1;
}
2023-08-11 09:39:41 +00:00
bool isHint = false;
if (z[2] == '+') {
2023-08-16 06:28:39 +00:00
isHint = true;
2023-08-11 09:39:41 +00:00
}
2019-07-11 08:36:16 +00:00
for (i = 3; z[i] && (z[i] != '/' || z[i - 1] != '*'); i++) {
}
if (z[i]) i++;
2023-08-16 06:28:39 +00:00
*tokenId = isHint ? TK_NK_HINT : TK_NK_COMMENT;
2019-07-11 08:36:16 +00:00
return i;
}
case '%': {
if (z[1] == '%') {
*tokenId = TK_NK_PH;
return 2;
} else {
*tokenId = TK_NK_REM;
return 1;
}
2019-07-11 08:36:16 +00:00
return 1;
}
case '=': {
*tokenId = TK_NK_EQ;
2019-07-11 08:36:16 +00:00
return 1 + (z[1] == '=');
}
case '<': {
if (z[1] == '=') {
*tokenId = TK_NK_LE;
2019-07-11 08:36:16 +00:00
return 2;
} else if (z[1] == '>') {
*tokenId = TK_NK_NE;
2019-07-11 08:36:16 +00:00
return 2;
} else if (z[1] == '<') {
*tokenId = TK_NK_LSHIFT;
2019-07-11 08:36:16 +00:00
return 2;
} else {
*tokenId = TK_NK_LT;
2019-07-11 08:36:16 +00:00
return 1;
}
}
case '>': {
if (z[1] == '=') {
*tokenId = TK_NK_GE;
2019-07-11 08:36:16 +00:00
return 2;
} else if (z[1] == '>') {
*tokenId = TK_NK_RSHIFT;
2019-07-11 08:36:16 +00:00
return 2;
} else {
*tokenId = TK_NK_GT;
2019-07-11 08:36:16 +00:00
return 1;
}
}
case '!': {
if (z[1] != '=') {
2022-03-05 23:12:08 +00:00
*tokenId = TK_NK_ILLEGAL;
2019-07-11 08:36:16 +00:00
return 2;
} else {
*tokenId = TK_NK_NE;
2019-07-11 08:36:16 +00:00
return 2;
}
}
case '|': {
if (z[1] != '|') {
*tokenId = TK_NK_BITOR;
2019-07-11 08:36:16 +00:00
return 1;
} else {
*tokenId = TK_NK_CONCAT;
2019-07-11 08:36:16 +00:00
return 2;
}
}
case ',': {
*tokenId = TK_NK_COMMA;
2019-07-11 08:36:16 +00:00
return 1;
}
case '&': {
*tokenId = TK_NK_BITAND;
2019-07-11 08:36:16 +00:00
return 1;
}
case '~': {
*tokenId = TK_NK_BITNOT;
2019-07-11 08:36:16 +00:00
return 1;
}
2019-11-07 10:12:26 +00:00
case '?': {
2022-03-05 23:12:08 +00:00
*tokenId = TK_NK_QUESTION;
2019-11-07 10:12:26 +00:00
return 1;
}
case '`':
2019-07-11 08:36:16 +00:00
case '\'':
case '"': {
2019-11-07 10:12:26 +00:00
int delim = z[0];
bool strEnd = false;
2019-07-11 08:36:16 +00:00
for (i = 1; z[i]; i++) {
if (delim != '`' && z[i] == '\\') { // ignore the escaped character that follows this backslash
2019-12-05 09:28:15 +00:00
i++;
continue;
}
2022-04-26 03:50:35 +00:00
if (z[i] == delim) {
2019-07-11 08:36:16 +00:00
if (z[i + 1] == delim) {
i++;
} else {
2019-07-25 06:14:38 +00:00
strEnd = true;
2019-07-11 08:36:16 +00:00
break;
}
}
}
2022-04-26 03:50:35 +00:00
2019-07-11 08:36:16 +00:00
if (z[i]) i++;
2019-07-25 06:14:38 +00:00
2019-11-07 10:12:26 +00:00
if (strEnd) {
2022-04-26 03:50:35 +00:00
*tokenId = (delim == '`') ? TK_NK_ID : TK_NK_STRING;
2019-11-07 10:12:26 +00:00
return i;
}
2019-07-25 06:14:38 +00:00
2019-11-07 10:12:26 +00:00
break;
2019-07-11 08:36:16 +00:00
}
case '.': {
2019-11-07 10:12:26 +00:00
/*
* handle the the float number with out integer part
* .123
* .123e4
*/
if (isdigit(z[1])) {
for (i = 2; isdigit(z[i]); i++) {
}
if ((z[i] == 'e' || z[i] == 'E') &&
(isdigit(z[i + 1]) || ((z[i + 1] == '+' || z[i + 1] == '-') && isdigit(z[i + 2])))) {
i += 2;
while (isdigit(z[i])) {
i++;
}
}
*tokenId = TK_NK_FLOAT;
2019-11-07 10:12:26 +00:00
return i;
} else {
*tokenId = TK_NK_DOT;
2019-11-07 10:12:26 +00:00
return 1;
}
}
case '0': {
char next = z[1];
2022-04-26 03:50:35 +00:00
if (next == 'b') { // bin number
2022-03-05 23:12:08 +00:00
*tokenId = TK_NK_BIN;
2019-11-07 10:12:26 +00:00
for (i = 2; (z[i] == '0' || z[i] == '1'); ++i) {
}
if (i == 2) {
break;
}
return i;
2022-04-26 03:50:35 +00:00
} else if (next == 'x') { // hex number
2022-03-05 23:12:08 +00:00
*tokenId = TK_NK_HEX;
2023-08-25 07:43:45 +00:00
for (i = 2; isxdigit(z[i]) != 0; ++i) {
2019-11-07 10:12:26 +00:00
}
if (i == 2) {
break;
}
return i;
}
2019-07-11 08:36:16 +00:00
}
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9': {
*tokenId = TK_NK_INTEGER;
2019-07-11 08:36:16 +00:00
for (i = 1; isdigit(z[i]); i++) {
}
2020-07-11 06:27:30 +00:00
/* here is the 1u/1a/2s/3m/9y */
2022-04-26 03:50:35 +00:00
if ((z[i] == 'b' || z[i] == 'u' || z[i] == 'a' || z[i] == 's' || z[i] == 'm' || z[i] == 'h' || z[i] == 'd' ||
z[i] == 'n' || z[i] == 'y' || z[i] == 'w' || z[i] == 'B' || z[i] == 'U' || z[i] == 'A' || z[i] == 'S' ||
z[i] == 'M' || z[i] == 'H' || z[i] == 'D' || z[i] == 'N' || z[i] == 'Y' || z[i] == 'W') &&
2019-12-08 18:09:17 +00:00
(isIdChar[(uint8_t)z[i + 1]] == 0)) {
*tokenId = TK_NK_VARIABLE;
2019-07-11 08:36:16 +00:00
i += 1;
return i;
}
int32_t seg = 1;
while (z[i] == '.' && isdigit(z[i + 1])) {
i += 2;
while (isdigit(z[i])) {
i++;
}
*tokenId = TK_NK_FLOAT;
2019-07-11 08:36:16 +00:00
seg++;
}
if (seg == 4) { // ip address
*tokenId = TK_NK_IPTOKEN;
2019-07-11 08:36:16 +00:00
return i;
2022-05-09 12:20:05 +00:00
} else if (seg > 2) {
break;
2019-07-11 08:36:16 +00:00
}
2023-12-01 15:44:05 +00:00
// support float with no decimal part after the decimal point
if (z[i] == '.' && seg == 1) {
*tokenId = TK_NK_FLOAT;
i++;
}
2019-07-11 08:36:16 +00:00
if ((z[i] == 'e' || z[i] == 'E') &&
(isdigit(z[i + 1]) || ((z[i + 1] == '+' || z[i + 1] == '-') && isdigit(z[i + 2])))) {
i += 2;
while (isdigit(z[i])) {
i++;
}
*tokenId = TK_NK_FLOAT;
2019-07-11 08:36:16 +00:00
}
return i;
}
2022-05-25 13:20:11 +00:00
// case '[': {
// for (i = 1; z[i] && z[i - 1] != ']'; i++) {
// }
// *tokenId = TK_NK_ID;
// return i;
// }
2019-07-11 08:36:16 +00:00
case 'T':
case 't':
case 'F':
case 'f': {
bool hasNonAsciiChars = false;
for (i = 1;; i++) {
if ((z[i] & 0x80) != 0) {
// utf-8 characters
// currently, we support using utf-8 characters only in alias
hasNonAsciiChars = true;
} else if (isIdChar[(uint8_t)z[i]]) {
} else {
break;
}
}
if (hasNonAsciiChars) {
*tokenId = TK_NK_ALIAS; // must be alias
return i;
2019-07-11 08:36:16 +00:00
}
2024-03-13 07:32:36 +00:00
if (IS_TRUE_STR(z, i) || IS_FALSE_STR(z, i)) {
*tokenId = TK_NK_BOOL;
2019-07-11 08:36:16 +00:00
return i;
}
2022-10-17 07:43:42 +00:00
*tokenId = tKeywordCode(z, i);
return i;
2019-07-11 08:36:16 +00:00
}
default: {
if ((*z & 0x80) == 0 && !isIdChar[(uint8_t)*z]) {
2019-07-11 08:36:16 +00:00
break;
}
bool hasNonAsciiChars = false;
for (i = 1;; i++) {
if ((z[i] & 0x80) != 0) {
hasNonAsciiChars = true;
} else if (isIdChar[(uint8_t)z[i]]) {
} else {
break;
}
}
if (hasNonAsciiChars) {
*tokenId = TK_NK_ALIAS;
return i;
2019-07-11 08:36:16 +00:00
}
*tokenId = tKeywordCode(z, i);
2019-07-11 08:36:16 +00:00
return i;
}
}
2022-03-05 23:12:08 +00:00
*tokenId = TK_NK_ILLEGAL;
2019-07-11 08:36:16 +00:00
return 0;
}
2023-02-05 02:11:26 +00:00
SToken tStrGetToken(const char* str, int32_t* i, bool isPrevOptr, bool* pIgnoreComma) {
2021-10-08 12:33:46 +00:00
SToken t0 = {0};
2019-11-07 10:12:26 +00:00
2019-07-11 08:36:16 +00:00
// here we reach the end of sql string, null-terminated string
if (str[*i] == 0) {
2019-11-07 10:12:26 +00:00
t0.n = 0;
return t0;
2019-07-11 08:36:16 +00:00
}
2022-03-05 23:12:08 +00:00
// IGNORE TK_NK_SPACE, TK_NK_COMMA, and specified tokens
2019-11-07 10:12:26 +00:00
while (1) {
*i += t0.n;
2020-05-21 05:54:18 +00:00
int32_t numOfComma = 0;
2022-04-26 03:50:35 +00:00
char t = str[*i];
2020-05-21 05:54:18 +00:00
while (t == ' ' || t == '\n' || t == '\r' || t == '\t' || t == '\f' || t == ',') {
if (t == ',' && (++numOfComma > 1)) { // comma only allowed once
t0.n = 0;
return t0;
2019-11-07 10:12:26 +00:00
}
2022-04-26 03:50:35 +00:00
2023-02-05 02:11:26 +00:00
if (NULL != pIgnoreComma && t == ',') {
*pIgnoreComma = true;
}
2020-05-21 05:56:42 +00:00
t = str[++(*i)];
2019-11-07 10:12:26 +00:00
}
2019-07-11 08:36:16 +00:00
t0.n = tGetToken(&str[*i], &t0.type);
2021-04-02 03:18:36 +00:00
break;
2019-11-07 10:12:26 +00:00
2021-04-02 03:18:36 +00:00
// not support user specfied ignored symbol list
#if 0
2020-05-21 05:54:18 +00:00
bool ignore = false;
2019-11-07 10:12:26 +00:00
for (uint32_t k = 0; k < numOfIgnoreToken; k++) {
if (t0.type == ignoreTokenTypes[k]) {
2020-05-21 05:54:18 +00:00
ignore = true;
2019-11-07 10:12:26 +00:00
break;
}
}
2020-05-21 05:54:18 +00:00
if (!ignore) {
2019-11-07 10:12:26 +00:00
break;
}
2021-04-02 03:18:36 +00:00
#endif
2019-07-11 08:36:16 +00:00
}
if (t0.type == TK_NK_SEMI) {
2019-11-07 10:12:26 +00:00
t0.n = 0;
2022-05-21 13:59:04 +00:00
t0.type = 0;
2019-11-07 10:12:26 +00:00
return t0;
}
uint32_t type = 0;
int32_t len;
// support parse the 'db.tbl' format, notes: There should be no space on either side of the dot!
if ('.' == str[*i + t0.n]) {
len = tGetToken(&str[*i + t0.n + 1], &type);
2019-11-07 10:12:26 +00:00
2024-06-25 08:16:32 +00:00
// only id、string and ? are valid
if (((TK_NK_STRING != t0.type) && (TK_NK_ID != t0.type)) ||
((TK_NK_STRING != type) && (TK_NK_ID != type) && (TK_NK_QUESTION != type))) {
2022-03-05 23:12:08 +00:00
t0.type = TK_NK_ILLEGAL;
2019-11-07 10:12:26 +00:00
t0.n = 0;
return t0;
}
// check the table name is '?', db.?asf is not valid.
if (TK_NK_QUESTION == type) {
2024-07-23 07:59:10 +00:00
(void)tGetToken(&str[*i + t0.n + 2], &type);
if (TK_NK_SPACE != type) {
t0.type = TK_NK_ILLEGAL;
t0.n = 0;
return t0;
}
}
2019-11-07 10:12:26 +00:00
t0.n += len + 1;
} else {
// support parse the -/+number format
2022-03-22 03:50:27 +00:00
if ((isPrevOptr) && (t0.type == TK_NK_MINUS || t0.type == TK_NK_PLUS)) {
len = tGetToken(&str[*i + t0.n], &type);
2023-12-01 15:44:05 +00:00
if (type == TK_NK_INTEGER || type == TK_NK_FLOAT || type == TK_NK_BIN || type == TK_NK_HEX) {
2019-11-07 10:12:26 +00:00
t0.type = type;
t0.n += len;
}
2019-07-11 08:36:16 +00:00
}
}
2022-04-26 03:50:35 +00:00
t0.z = (char*)str + (*i);
2019-11-07 10:12:26 +00:00
*i += t0.n;
return t0;
2019-07-11 08:36:16 +00:00
}
2022-04-26 03:50:35 +00:00
bool taosIsKeyWordToken(const char* z, int32_t len) { return (tKeywordCode((char*)z, len) != TK_NK_ID); }
2020-08-08 09:48:08 +00:00
int32_t taosInitKeywordsTable() { return doInitKeywordsTable(); }
2024-07-23 07:59:10 +00:00
2020-08-08 09:48:08 +00:00
void taosCleanupKeywordsTable() {
2020-10-27 09:34:28 +00:00
void* m = keywordHashTable;
if (m != NULL && atomic_val_compare_exchange_ptr(&keywordHashTable, m, 0) == m) {
taosHashCleanup(m);
}
2020-09-21 17:17:31 +00:00
}