From 7ad577042527b44821719213285a1e8525d556e2 Mon Sep 17 00:00:00 2001 From: Ganlin Zhao Date: Fri, 4 Aug 2023 10:41:51 +0800 Subject: [PATCH] enh: optimize error message --- docs/en/12-taos-sql/06-select.md | 1 + docs/zh/12-taos-sql/06-select.md | 4 ++++ source/libs/parser/src/parUtil.c | 2 +- source/util/src/terror.c | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/en/12-taos-sql/06-select.md b/docs/en/12-taos-sql/06-select.md index b28d5acb18..3741e5e941 100644 --- a/docs/en/12-taos-sql/06-select.md +++ b/docs/en/12-taos-sql/06-select.md @@ -404,6 +404,7 @@ SELECT ... FROM (SELECT ... FROM ...) ...; - If the result set returned by the inner query doesn't contain timestamp column, then functions relying on timestamp can't be used in the outer query, like INTERP,DERIVATIVE, IRATE, LAST_ROW, FIRST, LAST, TWA, STATEDURATION, TAIL, UNIQUE. - If the result set returned by the inner query are not sorted in order by timestamp, then functions relying on data ordered by timestamp can't be used in the outer query, like LEASTSQUARES, ELAPSED, INTERP, DERIVATIVE, IRATE, TWA, DIFF, STATECOUNT, STATEDURATION, CSUM, MAVG, TAIL, UNIQUE. - Functions that need to scan the data twice can't be used in the outer query, like PERCENTILE. +- If time window query is used in outer query, the returned result of inner query need to be sorted according to primary timestamp column. ::: diff --git a/docs/zh/12-taos-sql/06-select.md b/docs/zh/12-taos-sql/06-select.md index 5bc67755f0..d2010be510 100644 --- a/docs/zh/12-taos-sql/06-select.md +++ b/docs/zh/12-taos-sql/06-select.md @@ -403,6 +403,10 @@ SELECT ... FROM (SELECT ... FROM ...) ...; - 如果内层查询的结果数据未提供时间戳,那么计算过程隐式依赖时间戳的函数在外层会无法正常工作。例如:INTERP, DERIVATIVE, IRATE, LAST_ROW, FIRST, LAST, TWA, STATEDURATION, TAIL, UNIQUE。 - 如果内层查询的结果数据不是按时间戳有序,那么计算过程依赖数据按时间有序的函数在外层会无法正常工作。例如:LEASTSQUARES, ELAPSED, INTERP, DERIVATIVE, IRATE, TWA, DIFF, STATECOUNT, STATEDURATION, CSUM, MAVG, TAIL, UNIQUE。 - 计算过程需要两遍扫描的函数,在外层查询中无法正常工作。例如:此类函数包括:PERCENTILE。 +- 如果在外层查询中使用时间窗口查询,内层查询返回结果应按照主键时间戳列排序。例如: +``` +SELECT count(*) FROM (SELECT * FROM tb ORDER BY ts) interval(1d); +``` ::: diff --git a/source/libs/parser/src/parUtil.c b/source/libs/parser/src/parUtil.c index 1c292b1ec4..c3f9aeabdb 100644 --- a/source/libs/parser/src/parUtil.c +++ b/source/libs/parser/src/parUtil.c @@ -149,7 +149,7 @@ static char* getSyntaxErrFormat(int32_t errCode) { return "Some functions are allowed only in the SELECT list of a query. " "And, cannot be mixed with other non scalar functions or columns."; case TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY: - return "Window query not supported, since the result of subquery not include valid timestamp column"; + return "Window query not supported, since the result of subquery not include valid or unordered timestamp column"; case TSDB_CODE_PAR_INVALID_DROP_COL: return "No columns can be dropped"; case TSDB_CODE_PAR_INVALID_COL_JSON: diff --git a/source/util/src/terror.c b/source/util/src/terror.c index b0b407e2a5..01bc9ffd87 100644 --- a/source/util/src/terror.c +++ b/source/util/src/terror.c @@ -550,7 +550,7 @@ TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_FUNCTION_NAME, "Invalid function na TAOS_DEFINE_ERROR(TSDB_CODE_PAR_COMMENT_TOO_LONG, "Comment too long") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_ALLOWED_FUNC, "Some functions are allowed only in the SELECT list of a query. " "And, cannot be mixed with other non scalar functions or columns.") -TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY, "Window query not supported, since the result of subquery not include valid timestamp column") +TAOS_DEFINE_ERROR(TSDB_CODE_PAR_NOT_ALLOWED_WIN_QUERY, "Window query not supported, since the result of subquery not include valid or unordered timestamp column") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_DROP_COL, "No columns can be dropped") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_INVALID_COL_JSON, "Only tag can be json type") TAOS_DEFINE_ERROR(TSDB_CODE_PAR_VALUE_TOO_LONG, "Value too long for column/tag") -- GitLab