usable tsma
This commit is contained in:
parent
384efdc185
commit
cb008f18dc
|
@ -28,9 +28,9 @@ In the function list, you can only specify supported aggregate functions (see be
|
|||
|
||||
Since the output of TSMA is a super table, the row length of the output table is subject to the maximum row length limit. The size of the `intermediate results of different functions` varies, but they are generally larger than the original data size. If the row length of the output table exceeds the maximum row length limit, an error `Row length exceeds max length` will be reported. In this case, you need to reduce the number of functions or split commonly used functions groups into multiple TSMA objects.
|
||||
|
||||
The window size is limited to [1ms ~ 1h]. The unit of INTERVAL is the same as the INTERVAL clause in the query, such as a (milliseconds), b (nanoseconds), h (hours), m (minutes), s (seconds), u (microseconds).
|
||||
The window size is limited to [1m ~ 1h]. The unit of INTERVAL is the same as the INTERVAL clause in the query, such as a (milliseconds), b (nanoseconds), h (hours), m (minutes), s (seconds), u (microseconds).
|
||||
|
||||
TSMA is a database-level object, but it is globally unique. The number of TSMA that can be created in the cluster is limited by the parameter `maxTsmaNum`, with a default value of 8 and a range of [0-12]. Note that since TSMA background calculation uses stream computing, creating a TSMA will create a stream. Therefore, the number of TSMA that can be created is also limited by the number of existing streams and the maximum number of streams that can be created.
|
||||
TSMA is a database-level object, but it is globally unique. The number of TSMA that can be created in the cluster is limited by the parameter `maxTsmaNum`, with a default value of 3 and a range of [0-3]. Note that since TSMA background calculation uses stream computing, creating a TSMA will create a stream. Therefore, the number of TSMA that can be created is also limited by the number of existing streams and the maximum number of streams that can be created.
|
||||
|
||||
## Supported Functions
|
||||
| function | comments |
|
||||
|
@ -44,7 +44,6 @@ TSMA is a database-level object, but it is globally unique. The number of TSMA t
|
|||
|count| If you want to use count(*), you should create the count(ts) function|
|
||||
|spread||
|
||||
|stddev||
|
||||
|hyperloglog||
|
||||
|||
|
||||
|
||||
## Drop TSMA
|
||||
|
@ -65,6 +64,8 @@ Client configuration parameter: `querySmaOptimize`, used to control whether to u
|
|||
|
||||
Client configuration parameter: `maxTsmaCalcDelay`, in seconds, is used to control the acceptable TSMA calculation delay for users. If the calculation progress of a TSMA is within this range from the latest time, the TSMA will be used. If it exceeds this range, it will not be used. The default value is 600 (10 minutes), with a minimum value of 600 (10 minutes) and a maximum value of 86400 (1 day).
|
||||
|
||||
Client configuration parameter: `tsmaDataDeleteMark`, in milliseconds, consistent with the stream computing parameter `deleteMark`, is used to control the retention time of intermediate results in stream computing. The default value is 1 day, with a minimum value of 1 hour. Therefore, historical data that is older than the configuration parameter will not have the intermediate results saved in stream computing. If you modify the data within these time windows, the TSMA calculation results will not include the updated results. This means that the TSMA results will be inconsistent with querying the original data.
|
||||
|
||||
### Using TSMA Duraing Query
|
||||
|
||||
The aggregate functions defined in TSMA can be directly used in most query scenarios. If multiple TSMA are available, the one with the larger window size is preferred. For unclosed windows, the calculation can be done using smaller window TSMA or the original data. However, there are certain scenarios where TSMA cannot be used (see below). In such cases, the entire query will be calculated using the original data.
|
||||
|
@ -131,4 +132,4 @@ SHOW [db_name.]TSMAS;
|
|||
SELECT * FROM information_schema.ins_tsma;
|
||||
```
|
||||
|
||||
If more functions are specified during creation, and the column names are longer, the function list may be truncated when displayed (currently supports a maximum output of 256KB)
|
||||
If more functions are specified during creation, and the column names are longer, the function list may be truncated when displayed (currently supports a maximum output of 256KB)
|
||||
|
|
|
@ -250,6 +250,15 @@ Please note the `taoskeeper` needs to be installed and running to create the `lo
|
|||
| Value Range | 600s - 86400s, 10 minutes to 1 hour |
|
||||
| Default value | 600s |
|
||||
|
||||
### tsmaDataDeleteMark
|
||||
|
||||
| Attribute | Description |
|
||||
| -------- | --------------------------- |
|
||||
| Applicable | Client only |
|
||||
| Meaning | The duration for which the intermediate results of TSMA calculations are saved, in milliseconds |
|
||||
| Value Range | >= 3600000, greater than or equal to 1 hour |
|
||||
| Default value | 86400000, 1d |
|
||||
|
||||
|
||||
## Locale Parameters
|
||||
|
||||
|
@ -776,8 +785,8 @@ The charset that takes effect is UTF-8.
|
|||
| --------- | ----------------------------- |
|
||||
| Applicable | Server Only |
|
||||
| Meaning | Max num of TSMAs |
|
||||
| Value Range | 0-12 |
|
||||
| Default Value | 8 |
|
||||
| Value Range | 0-3 |
|
||||
| Default Value | 3 |
|
||||
|
||||
## 3.0 Parameters
|
||||
|
||||
|
|
|
@ -28,9 +28,9 @@ TSMA只能基于超级表和普通表创建, 不能基于子表创建.
|
|||
|
||||
由于TSMA输出为一张超级表, 因此输出表的行长度受最大行长度限制, 不同函数的`中间结果`大小各异, 一般都大于原始数据大小, 若输出表的行长度大于最大行长度限制, 将会报`Row length exceeds max length`错误. 此时需要减少函数个数或者将常用的函数进行分组拆分到多个TSMA中.
|
||||
|
||||
窗口大小的限制为[1ms ~ 1h]. INTERVAL 的单位与查询中INTERVAL字句相同, 如 a (毫秒), b (纳秒), h (小时), m (分钟), s (秒), u (微妙).
|
||||
窗口大小的限制为[1m ~ 1h]. INTERVAL 的单位与查询中INTERVAL子句相同, 如 a (毫秒), b (纳秒), h (小时), m (分钟), s (秒), u (微妙).
|
||||
|
||||
TSMA为库内对象, 但名字全局唯一. 集群内一共可创建TSMA个数受参数`maxTsmaNum`限制, 参数默认值为8, 范围: [0-12]. 注意, 由于TSMA后台计算使用流计算, 因此每创建一条TSMA, 将会创建一条流, 因此能够创建的TSMA条数也受当前已经存在的流条数和最大可创建流条数限制.
|
||||
TSMA为库内对象, 但名字全局唯一. 集群内一共可创建TSMA个数受参数`maxTsmaNum`限制, 参数默认值为3, 范围: [0-3]. 注意, 由于TSMA后台计算使用流计算, 因此每创建一条TSMA, 将会创建一条流, 因此能够创建的TSMA条数也受当前已经存在的流条数和最大可创建流条数限制.
|
||||
|
||||
## 支持的函数列表
|
||||
| 函数| 备注 |
|
||||
|
@ -44,7 +44,6 @@ TSMA为库内对象, 但名字全局唯一. 集群内一共可创建TSMA个数
|
|||
|count| 若想使用count(*), 则应创建count(ts)函数|
|
||||
|spread||
|
||||
|stddev||
|
||||
|hyperloglog||
|
||||
|||
|
||||
|
||||
## 删除TSMA
|
||||
|
@ -64,6 +63,8 @@ TSMA的计算结果为与原始表相同库下的一张超级表, 此表用户
|
|||
|
||||
客户端配置参数:`maxTsmaCalcDelay`,单位 s,用于控制用户可以接受的 TSMA 计算延迟,若 TSMA 的计算进度与最新时间差距在此范围内, 则该 TSMA 将会被使用, 若超出该范围, 则不使用, 默认值: 600(10 分钟), 最小值: 600(10 分钟), 最大值: 86400(1 天).
|
||||
|
||||
客户端配置参数: `tsmaDataDeleteMark`, 单位毫秒, 与流计算参数`deleteMark`一致, 用于控制流计算中间结果的保存时间, 默认值为: 1d, 最小值为1h. 因此那些距最后一条数据时间大于配置参数的历史数据将不保存流计算中间结果, 因此若修改这些时间窗口内的数据, TSMA的计算结果中将不包含更新的结果. 即与查询原始数据结果将不一致.
|
||||
|
||||
### 查询时使用TSMA
|
||||
|
||||
已在 TSMA 中定义的 agg 函数在大部分查询场景下都可直接使用, 若存在多个可用的 TSMA, 优先使用大窗口的 TSMA, 未闭合窗口通过查询小窗口TSMA或者原始数据计算。 同时也有某些场景不能使用 TSMA(见下文)。 不可用时整个查询将使用原始数据进行计算。
|
||||
|
@ -129,4 +130,4 @@ SELECT COUNT(*), MIN(c1) FROM stable where c2 > 0; ---- can't use tsma1 or tsam2
|
|||
SHOW [db_name.]TSMAS;
|
||||
SELECT * FROM information_schema.ins_tsma;
|
||||
```
|
||||
若创建时指定的较多的函数, 且列名较长, 在显示函数列表时可能会被截断(目前最大支持输出256KB).
|
||||
若创建时指定的较多的函数, 且列名较长, 在显示函数列表时可能会被截断(目前最大支持输出256KB).
|
||||
|
|
|
@ -249,6 +249,15 @@ taos -C
|
|||
| 取值范围 | 600s - 86400s, 即10分钟-1小时 |
|
||||
| 缺省值 | 600s |
|
||||
|
||||
### tsmaDataDeleteMark
|
||||
|
||||
| 属性 | 说明 |
|
||||
| -------- | --------------------------- |
|
||||
| 适用范围 | 仅客户端适用 |
|
||||
| 含义 | TSMA计算的历史数据中间结果保存时间, 单位为毫秒 |
|
||||
| 取值范围 | >= 3600000, 即大于等于1h |
|
||||
| 缺省值 | 86400000, 即1d |
|
||||
|
||||
|
||||
## 区域相关
|
||||
|
||||
|
@ -761,8 +770,8 @@ charset 的有效值是 UTF-8。
|
|||
| -------- | --------------------------- |
|
||||
| 适用范围 | 仅服务端适用 |
|
||||
| 含义 | 集群内可创建的TSMA个数 |
|
||||
| 取值范围 | 0-12 |
|
||||
| 缺省值 | 8 |
|
||||
| 取值范围 | 0-3 |
|
||||
| 缺省值 | 3 |
|
||||
|
||||
## 压缩参数
|
||||
|
||||
|
|
|
@ -223,6 +223,7 @@ extern int32_t tmqMaxTopicNum;
|
|||
extern int32_t tmqRowSize;
|
||||
extern int32_t tsMaxTsmaNum;
|
||||
extern int32_t tsMaxTsmaCalcDelay;
|
||||
extern int64_t tsmaDataDeleteMark;
|
||||
|
||||
// wal
|
||||
extern int64_t tsWalFsyncDataSizeLimit;
|
||||
|
|
|
@ -308,8 +308,9 @@ int32_t tsS3UploadDelaySec = 60;
|
|||
|
||||
bool tsExperimental = true;
|
||||
|
||||
int32_t tsMaxTsmaNum = 8;
|
||||
int32_t tsMaxTsmaNum = 3;
|
||||
int32_t tsMaxTsmaCalcDelay = 600;
|
||||
int64_t tsmaDataDeleteMark = 1000 * 60 * 60 * 24; // in ms, default to 1d
|
||||
|
||||
#ifndef _STORAGE
|
||||
int32_t taosSetTfsCfg(SConfig *pCfg) {
|
||||
|
@ -571,6 +572,9 @@ static int32_t taosAddClientCfg(SConfig *pCfg) {
|
|||
if (cfgAddInt32(pCfg, "maxTsmaCalcDelay", tsMaxTsmaCalcDelay, 600, 86400, CFG_SCOPE_CLIENT, CFG_DYN_CLIENT) !=
|
||||
0)
|
||||
return -1;
|
||||
if (cfgAddInt32(pCfg, "tsmaDataDeleteMark", tsmaDataDeleteMark, 60 * 60 * 1000, INT64_MAX, CFG_SCOPE_CLIENT,
|
||||
CFG_DYN_CLIENT) != 0)
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -751,7 +755,7 @@ static int32_t taosAddServerCfg(SConfig *pCfg) {
|
|||
if (cfgAddInt32(pCfg, "tmqRowSize", tmqRowSize, 1, 1000000, CFG_SCOPE_SERVER, CFG_DYN_ENT_SERVER) != 0)
|
||||
return -1;
|
||||
|
||||
if (cfgAddInt32(pCfg, "maxTsmaNum", tsMaxTsmaNum, 0, 12, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "maxTsmaNum", tsMaxTsmaNum, 0, 3, CFG_SCOPE_SERVER, CFG_DYN_SERVER) != 0) return -1;
|
||||
if (cfgAddInt32(pCfg, "transPullupInterval", tsTransPullupInterval, 1, 10000, CFG_SCOPE_SERVER, CFG_DYN_ENT_SERVER) !=
|
||||
0)
|
||||
return -1;
|
||||
|
@ -1144,6 +1148,7 @@ static int32_t taosSetClientCfg(SConfig *pCfg) {
|
|||
|
||||
tsMultiResultFunctionStarReturnTags = cfgGetItem(pCfg, "multiResultFunctionStarReturnTags")->bval;
|
||||
tsMaxTsmaCalcDelay = cfgGetItem(pCfg, "maxTsmaCalcDelay")->i32;
|
||||
tsmaDataDeleteMark = cfgGetItem(pCfg, "tsmaDataDeleteMark")->i32;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1810,7 +1815,8 @@ static int32_t taosCfgDynamicOptionsForClient(SConfig *pCfg, const char *name) {
|
|||
{"useAdapter", &tsUseAdapter},
|
||||
{"experimental", &tsExperimental},
|
||||
{"multiResultFunctionStarReturnTags", &tsMultiResultFunctionStarReturnTags},
|
||||
{"maxTsmaCalcDelay", &tsMaxTsmaCalcDelay}};
|
||||
{"maxTsmaCalcDelay", &tsMaxTsmaCalcDelay},
|
||||
{"tsmaDataDeleteMark", &tsmaDataDeleteMark}};
|
||||
|
||||
if (taosCfgSetOption(debugOptions, tListLen(debugOptions), pItem, true) != 0) {
|
||||
taosCfgSetOption(options, tListLen(options), pItem, false);
|
||||
|
|
|
@ -1455,6 +1455,7 @@ static void mndCreateTSMABuildCreateStreamReq(SCreateTSMACxt *pCxt) {
|
|||
pCxt->pCreateStreamReq->targetStbUid = 0;
|
||||
pCxt->pCreateStreamReq->fillNullCols = NULL;
|
||||
pCxt->pCreateStreamReq->igUpdate = 0;
|
||||
pCxt->pCreateStreamReq->deleteMark = pCxt->pCreateSmaReq->deleteMark;
|
||||
pCxt->pCreateStreamReq->lastTs = pCxt->pCreateSmaReq->lastTs;
|
||||
pCxt->pCreateStreamReq->smaId = pCxt->pSma->uid;
|
||||
pCxt->pCreateStreamReq->ast = taosStrdup(pCxt->pCreateSmaReq->ast);
|
||||
|
|
|
@ -4216,7 +4216,10 @@ static int32_t mndProcessFetchTtlExpiredTbs(SRpcMsg *pRsp) {
|
|||
SMnode *pMnode = pRsp->info.node;
|
||||
SVFetchTtlExpiredTbsRsp rsp = {0};
|
||||
SMndDropTbsWithTsmaCtx *pCtx = NULL;
|
||||
if (pRsp->code != TSDB_CODE_SUCCESS) goto _end;
|
||||
if (pRsp->code != TSDB_CODE_SUCCESS) {
|
||||
terrno = pRsp->code;
|
||||
goto _end;
|
||||
}
|
||||
if (pRsp->contLen == 0) {
|
||||
code = 0;
|
||||
goto _end;
|
||||
|
|
|
@ -3169,7 +3169,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
{
|
||||
.name = "hyperloglog",
|
||||
.type = FUNCTION_TYPE_HYPERLOGLOG,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_COUNT_LIKE_FUNC | FUNC_MGT_TSMA_FUNC,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_COUNT_LIKE_FUNC,
|
||||
.translateFunc = translateHLL,
|
||||
.getEnvFunc = getHLLFuncEnv,
|
||||
.initFunc = functionSetup,
|
||||
|
@ -3181,7 +3181,6 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
#endif
|
||||
.combineFunc = hllCombine,
|
||||
.pPartialFunc = "_hyperloglog_partial",
|
||||
.pStateFunc = "_hyperloglog_state",
|
||||
.pMergeFunc = "_hyperloglog_merge"
|
||||
},
|
||||
{
|
||||
|
@ -3211,7 +3210,6 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.invertFunc = NULL,
|
||||
#endif
|
||||
.combineFunc = hllCombine,
|
||||
.pPartialFunc = "_hyperloglog_state_merge",
|
||||
.pMergeFunc = "_hyperloglog_merge",
|
||||
},
|
||||
{
|
||||
|
@ -4087,8 +4085,7 @@ const SBuiltinFuncDefinition funcMgtBuiltins[] = {
|
|||
.processFunc = lastFunctionMerge,
|
||||
.finalizeFunc = firstLastPartialFinalize,
|
||||
},
|
||||
{
|
||||
.name = "_hyperloglog_state",
|
||||
{ .name = "_hyperloglog_state",
|
||||
.type = FUNCTION_TYPE_HYPERLOGLOG_STATE,
|
||||
.classification = FUNC_MGT_AGG_FUNC | FUNC_MGT_COUNT_LIKE_FUNC | FUNC_MGT_TSMA_FUNC,
|
||||
.translateFunc = translateHLLState,
|
||||
|
|
|
@ -10928,7 +10928,7 @@ static int32_t buildCreateTSMAReq(STranslateContext* pCxt, SCreateTSMAStmt* pStm
|
|||
pReq->interval = ((SValueNode*)pStmt->pOptions->pInterval)->datum.i;
|
||||
pReq->intervalUnit = TIME_UNIT_MILLISECOND;
|
||||
|
||||
#define TSMA_MIN_INTERVAL_MS 1 // 1ms
|
||||
#define TSMA_MIN_INTERVAL_MS 1000 * 60 // 1m
|
||||
#define TSMA_MAX_INTERVAL_MS (60 * 60 * 1000) // 1h
|
||||
if (pReq->interval > TSMA_MAX_INTERVAL_MS || pReq->interval < TSMA_MIN_INTERVAL_MS) {
|
||||
return TSDB_CODE_TSMA_INVALID_INTERVAL;
|
||||
|
@ -10989,6 +10989,7 @@ static int32_t buildCreateTSMAReq(STranslateContext* pCxt, SCreateTSMAStmt* pStm
|
|||
}
|
||||
|
||||
if (TSDB_CODE_SUCCESS == code) {
|
||||
pReq->deleteMark = convertTimePrecision(tsmaDataDeleteMark, TSDB_TIME_PRECISION_MILLI, pTableMeta->tableInfo.precision);
|
||||
code = getSmaIndexSql(pCxt, &pReq->sql, &pReq->sqlLen);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,8 @@ from util.common import *
|
|||
|
||||
ROUND = 1000
|
||||
|
||||
ignore_some_tests: int = 1
|
||||
|
||||
class TSMA:
|
||||
def __init__(self):
|
||||
self.tsma_name = ''
|
||||
|
@ -601,7 +603,7 @@ class TSMATestSQLGenerator:
|
|||
|
||||
|
||||
class TDTestCase:
|
||||
updatecfgDict = {'asynclog': 0, 'ttlUnit': 1, 'ttlPushInterval': 5, 'ratioOfVnodeStreamThrea': 4, 'maxTsmaNum': 8}
|
||||
updatecfgDict = {'asynclog': 0, 'ttlUnit': 1, 'ttlPushInterval': 5, 'ratioOfVnodeStreamThrea': 4, 'maxTsmaNum': 3}
|
||||
|
||||
def __init__(self):
|
||||
self.vgroups = 4
|
||||
|
@ -802,7 +804,8 @@ class TDTestCase:
|
|||
|
||||
self.test_query_with_tsma_interval()
|
||||
self.test_query_with_tsma_agg()
|
||||
self.test_recursive_tsma()
|
||||
if not ignore_some_tests:
|
||||
self.test_recursive_tsma()
|
||||
self.test_query_interval_sliding()
|
||||
self.test_union()
|
||||
self.test_query_child_table()
|
||||
|
@ -812,7 +815,8 @@ class TDTestCase:
|
|||
self.test_add_tag_col()
|
||||
self.test_modify_col_name_value()
|
||||
self.test_alter_tag_val()
|
||||
self.test_ins_tsma()
|
||||
if not ignore_some_tests:
|
||||
self.test_ins_tsma()
|
||||
|
||||
def test_ins_tsma(self):
|
||||
tdSql.execute('use performance_schema')
|
||||
|
@ -862,17 +866,17 @@ class TDTestCase:
|
|||
.should_query_with_tsma('tsma2', '2018-09-17 09:30:00', '2018-09-17 09:59:59.999')
|
||||
.should_query_with_table('meters', '2018-09-17 10:00:00.000', '2018-09-17 10:23:19.800').get_qc())
|
||||
self.check(ctxs)
|
||||
|
||||
tdSql.execute('create database db2')
|
||||
tdSql.execute('use db2')
|
||||
tdSql.execute('create table db2.norm_tb(ts timestamp, c2 int)')
|
||||
tdSql.execute('insert into db2.norm_tb values(now, 1)')
|
||||
tdSql.execute('insert into db2.norm_tb values(now, 2)')
|
||||
self.create_tsma('tsma_db2_norm_t', 'db2', 'norm_tb', ['avg(c2)', 'last(ts)'], '10m')
|
||||
sql = 'select avg(c1) as avg_c1 from test.meters union select avg(c2) from db2.norm_tb order by avg_c1'
|
||||
self.check([TSMAQCBuilder().with_sql(sql).should_query_with_tsma('tsma2').should_query_with_tsma_ctb('db2', 'tsma_db2_norm_t', 'norm_tb').get_qc()])
|
||||
tdSql.execute('drop database db2')
|
||||
tdSql.execute('use test')
|
||||
if not ignore_some_tests:
|
||||
tdSql.execute('create database db2')
|
||||
tdSql.execute('use db2')
|
||||
tdSql.execute('create table db2.norm_tb(ts timestamp, c2 int)')
|
||||
tdSql.execute('insert into db2.norm_tb values(now, 1)')
|
||||
tdSql.execute('insert into db2.norm_tb values(now, 2)')
|
||||
self.create_tsma('tsma_db2_norm_t', 'db2', 'norm_tb', ['avg(c2)', 'last(ts)'], '10m')
|
||||
sql = 'select avg(c1) as avg_c1 from test.meters union select avg(c2) from db2.norm_tb order by avg_c1'
|
||||
self.check([TSMAQCBuilder().with_sql(sql).should_query_with_tsma('tsma2').should_query_with_tsma_ctb('db2', 'tsma_db2_norm_t', 'norm_tb').get_qc()])
|
||||
tdSql.execute('drop database db2')
|
||||
tdSql.execute('use test')
|
||||
|
||||
def test_modify_col_name_value(self):
|
||||
tdSql.error('alter table test.norm_tb rename column c1 c1_new', -2147471088) ## tsma must be dropped
|
||||
|
@ -898,8 +902,11 @@ class TDTestCase:
|
|||
return result_str
|
||||
|
||||
def test_long_tsma_name(self):
|
||||
self.drop_tsma('tsma2', 'test')
|
||||
name = self.generate_random_string(178)
|
||||
tsma_func_list = ['avg(c2)', 'avg(c3)', 'min(c4)', 'max(c3)', 'sum(c2)', 'count(ts)', 'count(c2)', 'first(c5)', 'last(c5)', 'spread(c2)', 'stddev(c3)', 'hyperloglog(c5)', 'last(ts)']
|
||||
tsma_func_list = ['avg(c2)', 'avg(c3)', 'min(c4)', 'max(c3)', 'sum(c2)', 'count(ts)', 'count(c2)', 'first(c5)', 'last(c5)', 'spread(c2)', 'stddev(c3)', 'last(ts)']
|
||||
if not ignore_some_tests:
|
||||
tsma_func_list.append('hyperloglog(c2)')
|
||||
self.create_tsma(name, 'test', 'meters', tsma_func_list, '55m')
|
||||
sql = 'select last(c5), spread(c2) from test.meters interval(55m)'
|
||||
ctx = TSMAQCBuilder().with_sql(sql).should_query_with_tsma(name).get_qc()
|
||||
|
@ -953,7 +960,9 @@ class TDTestCase:
|
|||
|
||||
def test_recursive_tsma(self):
|
||||
tdSql.execute('drop tsma test.tsma2')
|
||||
tsma_func_list = ['last(ts)', 'avg(c2)', 'avg(c3)', 'min(c4)', 'max(c3)', 'sum(c2)', 'count(ts)', 'count(c2)', 'first(c5)', 'last(c5)', 'spread(c2)', 'stddev(c3)', 'hyperloglog(c5)']
|
||||
tsma_func_list = ['last(ts)', 'avg(c2)', 'avg(c3)', 'min(c4)', 'max(c3)', 'sum(c2)', 'count(ts)', 'count(c2)', 'first(c5)', 'last(c5)', 'spread(c2)', 'stddev(c3)']
|
||||
if not ignore_some_tests:
|
||||
tsma_func_list.append('hyperloglog(c2)')
|
||||
select_func_list: List[str] = tsma_func_list.copy()
|
||||
select_func_list.append('count(*)')
|
||||
self.create_tsma('tsma3', 'test', 'meters', tsma_func_list, '5m')
|
||||
|
@ -1388,37 +1397,39 @@ class TDTestCase:
|
|||
'create tsma tsma_error_interval on nsdb.meters function(count(c2)) interval(10s,10m)')
|
||||
tdSql.error(
|
||||
'create tsma tsma_error_interval on nsdb.meters function(count(c2)) interval(10s) sliding(1m)')
|
||||
|
||||
# max tsma num 8
|
||||
self.create_tsma('tsma2', 'nsdb', 'meters', ['avg(c1)', 'avg(c2)'], '10s')
|
||||
self.create_tsma('tsma_test3', 'test', 'meters', ['avg(c1)', 'avg(c2)'], '100s')
|
||||
self.create_tsma('tsma4', 'nsdb', 'meters', ['avg(c1)', 'avg(c2)'], '101s')
|
||||
self.create_tsma('tsma5', 'nsdb', 'meters', ['avg(c1)', 'count(ts)'], '102s')
|
||||
self.create_tsma('tsma6', 'nsdb', 'meters', ['avg(c1)', 'avg(c2)'], '103s')
|
||||
self.create_tsma('tsma7', 'nsdb', 'meters', ['avg(c1)', 'count(c2)'], '104s')
|
||||
self.create_tsma('tsma8', 'test', 'meters', ['avg(c1)', 'sum(c2)'], '105s')
|
||||
tdSql.error('create tsma tsma9 on nsdb.meters function(count(ts), count(c1), sum(c2)) interval(99s)', -2147482490)
|
||||
tdSql.error('create recursive tsma tsma9 on test.tsma8 interval(210s)', -2147482490)
|
||||
|
||||
# modify maxTsmaNum para
|
||||
tdSql.error('alter dnode 1 "maxTsmaNum" "13";')
|
||||
tdSql.error('alter dnode 1 "maxTsmaNum" "-1";')
|
||||
|
||||
# tdSql.error('alter dnode 1 "maxTsmaNum" "abc";')
|
||||
# tdSql.error('alter dnode 1 "maxTsmaNum" "1.2";')
|
||||
|
||||
tdSql.execute("alter dnode 1 'maxTsmaNum' '0';", queryTimes=1)
|
||||
tdSql.error('create tsma tsma9 on nsdb.meters function(count(ts), count(c1), sum(c2)) interval(99s)', -2147482490)
|
||||
tdSql.execute("alter dnode 1 'maxTsmaNum' '12';", queryTimes=1)
|
||||
tdSql.execute('create tsma tsma9 on nsdb.meters function(count(ts), count(c1), sum(c2)) interval(109s)')
|
||||
tdSql.execute('create tsma tsma10 on nsdb.meters function(count(ts), count(c1), sum(c2)) interval(110s)')
|
||||
tdSql.execute('create tsma tsma11 on nsdb.meters function(count(ts), count(c1), sum(c2)) interval(111s)')
|
||||
tdSql.execute('create tsma tsma12 on nsdb.meters function(count(ts), count(c1), sum(c2)) interval(112s)')
|
||||
tdSql.query("show nsdb.tsmas", queryTimes=1)
|
||||
print(tdSql.queryResult)
|
||||
tdSql.query("show test.tsmas", queryTimes=1)
|
||||
print(tdSql.queryResult)
|
||||
tdSql.error('create tsma tsma13 on nsdb.meters function(count(ts), count(c1), sum(c2)) interval(113s)', -2147482490)
|
||||
|
||||
if not ignore_some_tests:
|
||||
# max tsma num 8
|
||||
self.create_tsma('tsma2', 'nsdb', 'meters', ['avg(c1)', 'avg(c2)'], '10s')
|
||||
self.create_tsma('tsma_test3', 'test', 'meters', ['avg(c1)', 'avg(c2)'], '100s')
|
||||
self.create_tsma('tsma4', 'nsdb', 'meters', ['avg(c1)', 'avg(c2)'], '101s')
|
||||
self.create_tsma('tsma5', 'nsdb', 'meters', ['avg(c1)', 'count(ts)'], '102s')
|
||||
self.create_tsma('tsma6', 'nsdb', 'meters', ['avg(c1)', 'avg(c2)'], '103s')
|
||||
self.create_tsma('tsma7', 'nsdb', 'meters', ['avg(c1)', 'count(c2)'], '104s')
|
||||
self.create_tsma('tsma8', 'test', 'meters', ['avg(c1)', 'sum(c2)'], '105s')
|
||||
tdSql.error('create tsma tsma9 on nsdb.meters function(count(ts), count(c1), sum(c2)) interval(99s)', -2147482490)
|
||||
tdSql.error('create recursive tsma tsma9 on test.tsma8 interval(210s)', -2147482490)
|
||||
|
||||
# modify maxTsmaNum para
|
||||
tdSql.error('alter dnode 1 "maxTsmaNum" "13";')
|
||||
tdSql.error('alter dnode 1 "maxTsmaNum" "-1";')
|
||||
|
||||
# tdSql.error('alter dnode 1 "maxTsmaNum" "abc";')
|
||||
# tdSql.error('alter dnode 1 "maxTsmaNum" "1.2";')
|
||||
|
||||
tdSql.execute("alter dnode 1 'maxTsmaNum' '0';", queryTimes=1)
|
||||
tdSql.error('create tsma tsma9 on nsdb.meters function(count(ts), count(c1), sum(c2)) interval(99s)', -2147482490)
|
||||
tdSql.execute("alter dnode 1 'maxTsmaNum' '12';", queryTimes=1)
|
||||
tdSql.execute('create tsma tsma9 on nsdb.meters function(count(ts), count(c1), sum(c2)) interval(109s)')
|
||||
tdSql.execute('create tsma tsma10 on nsdb.meters function(count(ts), count(c1), sum(c2)) interval(110s)')
|
||||
tdSql.execute('create tsma tsma11 on nsdb.meters function(count(ts), count(c1), sum(c2)) interval(111s)')
|
||||
tdSql.execute('create tsma tsma12 on nsdb.meters function(count(ts), count(c1), sum(c2)) interval(112s)')
|
||||
tdSql.query("show nsdb.tsmas", queryTimes=1)
|
||||
print(tdSql.queryResult)
|
||||
tdSql.query("show test.tsmas", queryTimes=1)
|
||||
print(tdSql.queryResult)
|
||||
tdSql.error('create tsma tsma13 on nsdb.meters function(count(ts), count(c1), sum(c2)) interval(113s)', -2147482490)
|
||||
|
||||
|
||||
# drop tsma
|
||||
|
@ -1525,6 +1536,7 @@ class TDTestCase:
|
|||
tdSql.error("CREATE TSMA T*\-sma129_ ON test.meters FUNCTION(count(c1)) INTERVAL(5m); ", -2147473920)
|
||||
tdSql.error("CREATE TSMA Tsma_repeat ON test.meters FUNCTION(count(c1)) INTERVAL(5m); ", -2147482496)
|
||||
|
||||
self.drop_tsma('tsma_repeat', 'test')
|
||||
# tsma name include escape character
|
||||
|
||||
tdSql.execute("CREATE TSMA `129_tsma` ON test.meters FUNCTION(count(c3)) INTERVAL(5m); ")
|
||||
|
@ -1534,9 +1546,6 @@ class TDTestCase:
|
|||
tdSql.execute("drop tsma test.`129_Tsma`")
|
||||
tdSql.execute("drop tsma test.`129_T*\-sma`")
|
||||
|
||||
self.drop_tsma('tsma_repeat', 'test')
|
||||
|
||||
|
||||
def test_create_and_drop_tsma(self, tsma_name: str, db_name: str = 'test', table_name: str = 'meters', func_list: List = ['avg(c1)', 'avg(c2)'], interval: str = '5m'):
|
||||
function_name = sys._getframe().f_code.co_name
|
||||
tdLog.debug(f'-----{function_name}------')
|
||||
|
|
Loading…
Reference in New Issue