diff --git a/src/.vuepress/sidebar/V1.3.x/en.ts b/src/.vuepress/sidebar/V1.3.x/en.ts index f206fdce5..be4b7b289 100644 --- a/src/.vuepress/sidebar/V1.3.x/en.ts +++ b/src/.vuepress/sidebar/V1.3.x/en.ts @@ -212,7 +212,7 @@ export const enSidebar = { text: 'Syntax-Rule', collapsible: true, children: [ - { text: 'Reserved Words&Identifiers', link: 'Syntax-Rule' }, + { text: 'Identifiers', link: 'Syntax-Rule' }, { text: 'Keywords', link: 'Keywords' }, ], }, diff --git a/src/.vuepress/sidebar/V1.3.x/zh.ts b/src/.vuepress/sidebar/V1.3.x/zh.ts index a9196422c..84f2ab313 100644 --- a/src/.vuepress/sidebar/V1.3.x/zh.ts +++ b/src/.vuepress/sidebar/V1.3.x/zh.ts @@ -205,14 +205,14 @@ export const zhSidebar = { collapsible: true, children: [ { text: 'UDF函数库', link: 'UDF-Libraries_apache' }, - { text: '函数和操作符', link: 'Operator-and-Expression' }, + { text: '函数与运算符', link: 'Operator-and-Expression' }, ], }, { text: '语法约定', collapsible: true, children: [ - { text: '保留字&标识符', link: 'Syntax-Rule' }, + { text: '标识符', link: 'Syntax-Rule' }, { text: '关键字', link: 'Keywords' }, ], }, diff --git a/src/.vuepress/sidebar_timecho/V1.3.x/en.ts b/src/.vuepress/sidebar_timecho/V1.3.x/en.ts index 06b649391..253b4a38c 100644 --- a/src/.vuepress/sidebar_timecho/V1.3.x/en.ts +++ b/src/.vuepress/sidebar_timecho/V1.3.x/en.ts @@ -225,7 +225,7 @@ export const enSidebar = { text: 'Syntax-Rule', collapsible: true, children: [ - { text: 'Reserved Words&Identifiers', link: 'Syntax-Rule' }, + { text: 'Identifiers', link: 'Syntax-Rule' }, { text: 'Keywords', link: 'Keywords' }, ], }, diff --git a/src/.vuepress/sidebar_timecho/V1.3.x/zh.ts b/src/.vuepress/sidebar_timecho/V1.3.x/zh.ts index 9737b7965..f97f79c0f 100644 --- a/src/.vuepress/sidebar_timecho/V1.3.x/zh.ts +++ b/src/.vuepress/sidebar_timecho/V1.3.x/zh.ts @@ -218,14 +218,14 @@ export const zhSidebar = { collapsible: true, children: [ { text: 'UDF函数库', link: 'UDF-Libraries_timecho' }, - { text: '函数和操作符', link: 'Operator-and-Expression' }, + { text: '函数与运算符', link: 'Operator-and-Expression' }, ], }, { text: '语法约定', collapsible: true, children: [ - { text: '保留字&标识符', link: 'Syntax-Rule' }, + { text: '标识符', link: 'Syntax-Rule' }, { text: '关键字', link: 'Keywords' }, ], }, diff --git a/src/UserGuide/Master/Tree/Reference/Operator-and-Expression.md b/src/UserGuide/Master/Tree/Reference/Operator-and-Expression.md index 0f094c982..438cd2431 100644 --- a/src/UserGuide/Master/Tree/Reference/Operator-and-Expression.md +++ b/src/UserGuide/Master/Tree/Reference/Operator-and-Expression.md @@ -252,31 +252,6 @@ For details and examples, see the document [Sample Functions](../Reference/Funct For details and examples, see the document [Time-Series](../Reference/Function-and-Expression.md#time-series-processing). -## DATA QUALITY FUNCTION LIBRARY - -### About - -For applications based on time series data, data quality is vital. **UDF Library** is IoTDB User Defined Functions (UDF) about data quality, including data profiling, data quality evalution and data repairing. It effectively meets the demand for data quality in the industrial field. - -### Quick Start - -The functions in this function library are not built-in functions, and must be loaded into the system before use. - -1. [Download](https://archive.apache.org/dist/iotdb/1.0.1/apache-iotdb-1.0.1-library-udf-bin.zip) the JAR with all dependencies and the script of registering UDF. -2. Copy the JAR package to `ext\udf` under the directory of IoTDB system (Please put JAR to this directory of all DataNodes if you use Cluster). -3. Run `sbin\start-confignode.bat` and then `sbin\start-datanode.bat` (for Windows) or `sbin\start-confignode.sh` and `sbin\start-datanode.sh` (for Linux or MacOS) to start IoTDB server. -4. Copy the script to the directory of IoTDB system (under the root directory, at the same level as `sbin`), modify the parameters in the script if needed and run it to register UDF. - -### Implemented Functions - -1. Data Quality related functions, such as `Completeness`. For details and examples, see the document [Data-Quality](../Reference/UDF-Libraries.md#data-quality). -2. Data Profiling related functions, such as `ACF`. For details and examples, see the document [Data-Profiling](../Reference/UDF-Libraries.md#data-profiling). -3. Anomaly Detection related functions, such as `IQR`. For details and examples, see the document [Anomaly-Detection](../Reference/UDF-Libraries.md#anomaly-detection). -4. Frequency Domain Analysis related functions, such as `Conv`. For details and examples, see the document [Frequency-Domain](../Reference/UDF-Libraries.md#frequency-domain-analysis). -5. Data Matching related functions, such as `DTW`. For details and examples, see the document [Data-Matching](../Reference/UDF-Libraries.md#data-matching). -6. Data Repairing related functions, such as `TimestampRepair`. For details and examples, see the document [Data-Repairing](../Reference/UDF-Libraries.md#timestamprepair). -7. Series Discovery related functions, such as `ConsecutiveSequences`. For details and examples, see the document [Series-Discovery](../Reference/UDF-Libraries.md). -8. Machine Learning related functions, such as `AR`. For details and examples, see the document [Machine-Learning](../Reference/UDF-Libraries.md#machine-learning). ## LAMBDA EXPRESSION diff --git a/src/UserGuide/Master/Tree/User-Manual/Syntax-Rule.md b/src/UserGuide/Master/Tree/Reference/Syntax-Rule.md similarity index 94% rename from src/UserGuide/Master/Tree/User-Manual/Syntax-Rule.md rename to src/UserGuide/Master/Tree/Reference/Syntax-Rule.md index 30ac234cc..f427b7079 100644 --- a/src/UserGuide/Master/Tree/User-Manual/Syntax-Rule.md +++ b/src/UserGuide/Master/Tree/Reference/Syntax-Rule.md @@ -19,7 +19,7 @@ --> -# Syntax Rule +# Identifiers ## Literal Values @@ -278,16 +278,3 @@ Examples of case in which quoted identifier is used : - Nodes except database in the path are allowed to contain the "*" symbol, when using this symbol it is required to enclose the node in backquotes, e.g., root.db.`*`, but this usage is only recommended when the path cannot avoid containing the "*" symbol. -## KeyWords Words - -Keywords are words that have significance in SQL. Keywords can be used as an identifier. Certain keywords, such as TIME/TIMESTAMP and ROOT, are reserved and cannot use as identifiers. - -[Keywords](../Reference/Keywords.md) shows the keywords in IoTDB. - -## Detailed Definitions of Lexical and Grammar - -Please read the lexical and grammar description files in our code repository: - -Lexical file: `antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlLexer.g4` - -Grammer file: `antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4` diff --git a/src/UserGuide/Master/Tree/User-Manual/Database-Programming.md b/src/UserGuide/Master/Tree/User-Manual/Database-Programming.md index 940ee444f..e5dfd4949 100644 --- a/src/UserGuide/Master/Tree/User-Manual/Database-Programming.md +++ b/src/UserGuide/Master/Tree/User-Manual/Database-Programming.md @@ -19,17 +19,16 @@ --> -# Database Programming +# CONTINUOUS QUERY(CQ) -## CONTINUOUS QUERY (CQ) -### Introduction +## Introduction Continuous queries(CQ) are queries that run automatically and periodically on realtime data and store query results in other specified time series. Users can implement sliding window streaming computing through continuous query, such as calculating the hourly average temperature of a sequence and writing it into a new sequence. Users can customize the `RESAMPLE` clause to create different sliding windows, which can achieve a certain degree of tolerance for out-of-order data. -### Syntax +## Syntax ```sql CREATE (CONTINUOUS QUERY | CQ) @@ -58,7 +57,7 @@ END > 2. GROUP BY TIME CLAUSE is different, it doesn't contain its original first display window parameter which is [start_time, end_time). It's still because IoTDB will automatically generate a time range for the query each time it's executed. > 3. If there is no group by time clause in query, EVERY clause is required, otherwise IoTDB will throw an error. -#### Descriptions of parameters in CQ syntax +### Descriptions of parameters in CQ syntax - `` specifies the globally unique id of CQ. - `` specifies the query execution time interval. We currently support the units of ns, us, ms, s, m, h, d, w, and its value should not be lower than the minimum threshold configured by the user, which is `continuous_query_min_every_interval`. It's an optional parameter, default value is set to `group_by_interval` in group by clause. @@ -80,19 +79,19 @@ END > - If `` is less than ``, there may be uncovered data between each query window. > - `start_time_offset` should be larger than `end_time_offset`, otherwise the system will throw an error. -##### `` == `` +#### `` == `` ![1](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic1.png?raw=true) -##### `` > `` +#### `` > `` ![2](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic2.png?raw=true) -##### `` < `` +#### `` < `` ![3](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic3.png?raw=true) -##### `` is not zero +#### `` is not zero ![](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic4.png?raw=true) @@ -102,7 +101,7 @@ END - `DISCARD` means that we just discard the current cq execution task and wait for the next execution time and do the next time interval cq task. If using `DISCARD` policy, some time intervals won't be executed when the execution time of one cq task is longer than the ``. However, once a cq task is executed, it will use the latest time interval, so it can catch up at the sacrifice of some time intervals being discarded. -### Examples of CQ +## Examples of CQ The examples below use the following sample data. It's a real time data stream and we can assume that the data arrives on time. @@ -122,7 +121,7 @@ The examples below use the following sample data. It's a real time data stream a +-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+ ```` -#### Configuring execution intervals +### Configuring execution intervals Use an `EVERY` interval in the `RESAMPLE` clause to specify the CQ’s execution interval, if not specific, default value is equal to `group_by_interval`. @@ -180,7 +179,7 @@ At **2021-05-11T22:19:00.000+08:00**, `cq1` executes a query within the time ran +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### Configuring time range for resampling +### Configuring time range for resampling Use `start_time_offset` in the `RANGE` clause to specify the start time of the CQ’s time range, if not specific, default value is equal to `EVERY` interval. @@ -255,7 +254,7 @@ At **2021-05-11T22:19:00.000+08:00**, `cq2` executes a query within the time ran +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### Configuring execution intervals and CQ time ranges +### Configuring execution intervals and CQ time ranges Use an `EVERY` interval and `RANGE` interval in the `RESAMPLE` clause to specify the CQ’s execution interval and the length of the CQ’s time range. And use `fill()` to change the value reported for time intervals with no data. @@ -320,7 +319,7 @@ Notice that `cq3` will calculate the results for some time interval many times, +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### Configuring end_time_offset for CQ time range +### Configuring end_time_offset for CQ time range Use an `EVERY` interval and `RANGE` interval in the RESAMPLE clause to specify the CQ’s execution interval and the length of the CQ’s time range. And use `fill()` to change the value reported for time intervals with no data. @@ -379,7 +378,7 @@ Notice that `cq4` will calculate the results for all time intervals only once af +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### CQ without group by clause +### CQ without group by clause Use an `EVERY` interval in the `RESAMPLE` clause to specify the CQ’s execution interval and the length of the CQ’s time range. @@ -485,9 +484,9 @@ At **2021-05-11T22:19:00.000+08:00**, `cq5` executes a query within the time ran +-----------------------------+-------------------------------+-----------+ ```` -### CQ Management +## CQ Management -#### Listing continuous queries +### Listing continuous queries List every CQ on the IoTDB Cluster with: @@ -497,7 +496,7 @@ SHOW (CONTINUOUS QUERIES | CQS) `SHOW (CONTINUOUS QUERIES | CQS)` order results by `cq_id`. -##### Examples +#### Examples ```sql SHOW CONTINUOUS QUERIES; @@ -510,7 +509,7 @@ we will get: | s1_count_cq | CREATE CQ s1_count_cq
BEGIN
SELECT count(s1)
INTO root.sg_count.d.count_s1
FROM root.sg.d
GROUP BY(30m)
END | active | -#### Dropping continuous queries +### Dropping continuous queries Drop a CQ with a specific `cq_id`: @@ -520,7 +519,7 @@ DROP (CONTINUOUS QUERY | CQ) DROP CQ returns an empty result. -##### Examples +#### Examples Drop the CQ named `s1_count_cq`: @@ -528,28 +527,28 @@ Drop the CQ named `s1_count_cq`: DROP CONTINUOUS QUERY s1_count_cq; ``` -#### Altering continuous queries +### Altering continuous queries CQs can't be altered once they're created. To change a CQ, you must `DROP` and re`CREATE` it with the updated settings. -### CQ Use Cases +## CQ Use Cases -#### Downsampling and Data Retention +### Downsampling and Data Retention Use CQs with `TTL` set on database in IoTDB to mitigate storage concerns. Combine CQs and `TTL` to automatically downsample high precision data to a lower precision and remove the dispensable, high precision data from the database. -#### Recalculating expensive queries +### Recalculating expensive queries Shorten query runtimes by pre-calculating expensive queries with CQs. Use a CQ to automatically downsample commonly-queried, high precision data to a lower precision. Queries on lower precision data require fewer resources and return faster. > Pre-calculate queries for your preferred graphing tool to accelerate the population of graphs and dashboards. -#### Substituting for sub-query +### Substituting for sub-query IoTDB does not support sub queries. We can get the same functionality by creating a CQ as a sub query and store its result into other time series and then querying from those time series again will be like doing nested sub query. -##### Example +#### Example IoTDB does not accept the following query with a nested sub query. The query calculates the average number of non-null values of `s1` at 30 minute intervals: @@ -584,7 +583,7 @@ SELECT avg(count_s1) from root.sg_count.d; ``` -### System Parameter Configuration +## System Parameter Configuration | Name | Description | Data Type | Default Value | | :------------------------------------------ | ------------------------------------------------------------ | --------- | ------------- | diff --git a/src/UserGuide/latest/Reference/Operator-and-Expression.md b/src/UserGuide/latest/Reference/Operator-and-Expression.md index 0f094c982..438cd2431 100644 --- a/src/UserGuide/latest/Reference/Operator-and-Expression.md +++ b/src/UserGuide/latest/Reference/Operator-and-Expression.md @@ -252,31 +252,6 @@ For details and examples, see the document [Sample Functions](../Reference/Funct For details and examples, see the document [Time-Series](../Reference/Function-and-Expression.md#time-series-processing). -## DATA QUALITY FUNCTION LIBRARY - -### About - -For applications based on time series data, data quality is vital. **UDF Library** is IoTDB User Defined Functions (UDF) about data quality, including data profiling, data quality evalution and data repairing. It effectively meets the demand for data quality in the industrial field. - -### Quick Start - -The functions in this function library are not built-in functions, and must be loaded into the system before use. - -1. [Download](https://archive.apache.org/dist/iotdb/1.0.1/apache-iotdb-1.0.1-library-udf-bin.zip) the JAR with all dependencies and the script of registering UDF. -2. Copy the JAR package to `ext\udf` under the directory of IoTDB system (Please put JAR to this directory of all DataNodes if you use Cluster). -3. Run `sbin\start-confignode.bat` and then `sbin\start-datanode.bat` (for Windows) or `sbin\start-confignode.sh` and `sbin\start-datanode.sh` (for Linux or MacOS) to start IoTDB server. -4. Copy the script to the directory of IoTDB system (under the root directory, at the same level as `sbin`), modify the parameters in the script if needed and run it to register UDF. - -### Implemented Functions - -1. Data Quality related functions, such as `Completeness`. For details and examples, see the document [Data-Quality](../Reference/UDF-Libraries.md#data-quality). -2. Data Profiling related functions, such as `ACF`. For details and examples, see the document [Data-Profiling](../Reference/UDF-Libraries.md#data-profiling). -3. Anomaly Detection related functions, such as `IQR`. For details and examples, see the document [Anomaly-Detection](../Reference/UDF-Libraries.md#anomaly-detection). -4. Frequency Domain Analysis related functions, such as `Conv`. For details and examples, see the document [Frequency-Domain](../Reference/UDF-Libraries.md#frequency-domain-analysis). -5. Data Matching related functions, such as `DTW`. For details and examples, see the document [Data-Matching](../Reference/UDF-Libraries.md#data-matching). -6. Data Repairing related functions, such as `TimestampRepair`. For details and examples, see the document [Data-Repairing](../Reference/UDF-Libraries.md#timestamprepair). -7. Series Discovery related functions, such as `ConsecutiveSequences`. For details and examples, see the document [Series-Discovery](../Reference/UDF-Libraries.md). -8. Machine Learning related functions, such as `AR`. For details and examples, see the document [Machine-Learning](../Reference/UDF-Libraries.md#machine-learning). ## LAMBDA EXPRESSION diff --git a/src/UserGuide/latest/User-Manual/Syntax-Rule.md b/src/UserGuide/latest/Reference/Syntax-Rule.md similarity index 94% rename from src/UserGuide/latest/User-Manual/Syntax-Rule.md rename to src/UserGuide/latest/Reference/Syntax-Rule.md index 30ac234cc..9dcb1848a 100644 --- a/src/UserGuide/latest/User-Manual/Syntax-Rule.md +++ b/src/UserGuide/latest/Reference/Syntax-Rule.md @@ -19,7 +19,7 @@ --> -# Syntax Rule +# Identifiers ## Literal Values @@ -277,17 +277,3 @@ Examples of case in which quoted identifier is used : - The key/value of an attribute can be String Literal and identifier, more details can be found at **key-value pair** part. - Nodes except database in the path are allowed to contain the "*" symbol, when using this symbol it is required to enclose the node in backquotes, e.g., root.db.`*`, but this usage is only recommended when the path cannot avoid containing the "*" symbol. - -## KeyWords Words - -Keywords are words that have significance in SQL. Keywords can be used as an identifier. Certain keywords, such as TIME/TIMESTAMP and ROOT, are reserved and cannot use as identifiers. - -[Keywords](../Reference/Keywords.md) shows the keywords in IoTDB. - -## Detailed Definitions of Lexical and Grammar - -Please read the lexical and grammar description files in our code repository: - -Lexical file: `antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlLexer.g4` - -Grammer file: `antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4` diff --git a/src/UserGuide/latest/User-Manual/Database-Programming.md b/src/UserGuide/latest/User-Manual/Database-Programming.md index 940ee444f..e5dfd4949 100644 --- a/src/UserGuide/latest/User-Manual/Database-Programming.md +++ b/src/UserGuide/latest/User-Manual/Database-Programming.md @@ -19,17 +19,16 @@ --> -# Database Programming +# CONTINUOUS QUERY(CQ) -## CONTINUOUS QUERY (CQ) -### Introduction +## Introduction Continuous queries(CQ) are queries that run automatically and periodically on realtime data and store query results in other specified time series. Users can implement sliding window streaming computing through continuous query, such as calculating the hourly average temperature of a sequence and writing it into a new sequence. Users can customize the `RESAMPLE` clause to create different sliding windows, which can achieve a certain degree of tolerance for out-of-order data. -### Syntax +## Syntax ```sql CREATE (CONTINUOUS QUERY | CQ) @@ -58,7 +57,7 @@ END > 2. GROUP BY TIME CLAUSE is different, it doesn't contain its original first display window parameter which is [start_time, end_time). It's still because IoTDB will automatically generate a time range for the query each time it's executed. > 3. If there is no group by time clause in query, EVERY clause is required, otherwise IoTDB will throw an error. -#### Descriptions of parameters in CQ syntax +### Descriptions of parameters in CQ syntax - `` specifies the globally unique id of CQ. - `` specifies the query execution time interval. We currently support the units of ns, us, ms, s, m, h, d, w, and its value should not be lower than the minimum threshold configured by the user, which is `continuous_query_min_every_interval`. It's an optional parameter, default value is set to `group_by_interval` in group by clause. @@ -80,19 +79,19 @@ END > - If `` is less than ``, there may be uncovered data between each query window. > - `start_time_offset` should be larger than `end_time_offset`, otherwise the system will throw an error. -##### `` == `` +#### `` == `` ![1](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic1.png?raw=true) -##### `` > `` +#### `` > `` ![2](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic2.png?raw=true) -##### `` < `` +#### `` < `` ![3](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic3.png?raw=true) -##### `` is not zero +#### `` is not zero ![](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic4.png?raw=true) @@ -102,7 +101,7 @@ END - `DISCARD` means that we just discard the current cq execution task and wait for the next execution time and do the next time interval cq task. If using `DISCARD` policy, some time intervals won't be executed when the execution time of one cq task is longer than the ``. However, once a cq task is executed, it will use the latest time interval, so it can catch up at the sacrifice of some time intervals being discarded. -### Examples of CQ +## Examples of CQ The examples below use the following sample data. It's a real time data stream and we can assume that the data arrives on time. @@ -122,7 +121,7 @@ The examples below use the following sample data. It's a real time data stream a +-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+ ```` -#### Configuring execution intervals +### Configuring execution intervals Use an `EVERY` interval in the `RESAMPLE` clause to specify the CQ’s execution interval, if not specific, default value is equal to `group_by_interval`. @@ -180,7 +179,7 @@ At **2021-05-11T22:19:00.000+08:00**, `cq1` executes a query within the time ran +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### Configuring time range for resampling +### Configuring time range for resampling Use `start_time_offset` in the `RANGE` clause to specify the start time of the CQ’s time range, if not specific, default value is equal to `EVERY` interval. @@ -255,7 +254,7 @@ At **2021-05-11T22:19:00.000+08:00**, `cq2` executes a query within the time ran +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### Configuring execution intervals and CQ time ranges +### Configuring execution intervals and CQ time ranges Use an `EVERY` interval and `RANGE` interval in the `RESAMPLE` clause to specify the CQ’s execution interval and the length of the CQ’s time range. And use `fill()` to change the value reported for time intervals with no data. @@ -320,7 +319,7 @@ Notice that `cq3` will calculate the results for some time interval many times, +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### Configuring end_time_offset for CQ time range +### Configuring end_time_offset for CQ time range Use an `EVERY` interval and `RANGE` interval in the RESAMPLE clause to specify the CQ’s execution interval and the length of the CQ’s time range. And use `fill()` to change the value reported for time intervals with no data. @@ -379,7 +378,7 @@ Notice that `cq4` will calculate the results for all time intervals only once af +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### CQ without group by clause +### CQ without group by clause Use an `EVERY` interval in the `RESAMPLE` clause to specify the CQ’s execution interval and the length of the CQ’s time range. @@ -485,9 +484,9 @@ At **2021-05-11T22:19:00.000+08:00**, `cq5` executes a query within the time ran +-----------------------------+-------------------------------+-----------+ ```` -### CQ Management +## CQ Management -#### Listing continuous queries +### Listing continuous queries List every CQ on the IoTDB Cluster with: @@ -497,7 +496,7 @@ SHOW (CONTINUOUS QUERIES | CQS) `SHOW (CONTINUOUS QUERIES | CQS)` order results by `cq_id`. -##### Examples +#### Examples ```sql SHOW CONTINUOUS QUERIES; @@ -510,7 +509,7 @@ we will get: | s1_count_cq | CREATE CQ s1_count_cq
BEGIN
SELECT count(s1)
INTO root.sg_count.d.count_s1
FROM root.sg.d
GROUP BY(30m)
END | active | -#### Dropping continuous queries +### Dropping continuous queries Drop a CQ with a specific `cq_id`: @@ -520,7 +519,7 @@ DROP (CONTINUOUS QUERY | CQ) DROP CQ returns an empty result. -##### Examples +#### Examples Drop the CQ named `s1_count_cq`: @@ -528,28 +527,28 @@ Drop the CQ named `s1_count_cq`: DROP CONTINUOUS QUERY s1_count_cq; ``` -#### Altering continuous queries +### Altering continuous queries CQs can't be altered once they're created. To change a CQ, you must `DROP` and re`CREATE` it with the updated settings. -### CQ Use Cases +## CQ Use Cases -#### Downsampling and Data Retention +### Downsampling and Data Retention Use CQs with `TTL` set on database in IoTDB to mitigate storage concerns. Combine CQs and `TTL` to automatically downsample high precision data to a lower precision and remove the dispensable, high precision data from the database. -#### Recalculating expensive queries +### Recalculating expensive queries Shorten query runtimes by pre-calculating expensive queries with CQs. Use a CQ to automatically downsample commonly-queried, high precision data to a lower precision. Queries on lower precision data require fewer resources and return faster. > Pre-calculate queries for your preferred graphing tool to accelerate the population of graphs and dashboards. -#### Substituting for sub-query +### Substituting for sub-query IoTDB does not support sub queries. We can get the same functionality by creating a CQ as a sub query and store its result into other time series and then querying from those time series again will be like doing nested sub query. -##### Example +#### Example IoTDB does not accept the following query with a nested sub query. The query calculates the average number of non-null values of `s1` at 30 minute intervals: @@ -584,7 +583,7 @@ SELECT avg(count_s1) from root.sg_count.d; ``` -### System Parameter Configuration +## System Parameter Configuration | Name | Description | Data Type | Default Value | | :------------------------------------------ | ------------------------------------------------------------ | --------- | ------------- | diff --git a/src/zh/UserGuide/Master/Tree/Reference/Operator-and-Expression.md b/src/zh/UserGuide/Master/Tree/Reference/Operator-and-Expression.md index 2818fd7cd..6afc120a6 100644 --- a/src/zh/UserGuide/Master/Tree/Reference/Operator-and-Expression.md +++ b/src/zh/UserGuide/Master/Tree/Reference/Operator-and-Expression.md @@ -19,7 +19,7 @@ --> -# 运算符、函数和表达式 +# 函数与运算符 ## 运算符 ### 算数运算符 @@ -243,31 +243,6 @@ OR, |, || 详细说明及示例见文档 [时间序列处理](../Reference/Function-and-Expression.md#时间序列处理)。 -## 数据质量函数库 - -### 关于 - -对基于时序数据的应用而言,数据质量至关重要。基于用户自定义函数能力,IoTDB 提供了一系列关于数据质量的函数,包括数据画像、数据质量评估与修复等,能够满足工业领域对数据质量的需求。 - -### 快速上手 - -**该函数库中的函数不是内置函数,使用前要先加载到系统中。** 操作流程如下: - -1. 下载包含全部依赖的 jar 包和注册脚本 [【点击下载】](https://archive.apache.org/dist/iotdb/1.0.1/apache-iotdb-1.0.1-library-udf-bin.zip) ; -2. 将 jar 包复制到 IoTDB 程序目录的 `ext\udf` 目录下 (若您使用的是集群,请将jar包复制到所有DataNode的该目录下); -3. 启动 IoTDB; -4. 将注册脚本复制到 IoTDB 的程序目录下(与`sbin`目录同级的根目录下),修改脚本中的参数(如果需要)并运行注册脚本以注册 UDF。 - -### 已经实现的函数 - -1. [Data-Quality](../Reference/UDF-Libraries.md#数据质量) 数据质量 -2. [Data-Profiling](../Reference/UDF-Libraries.md#数据画像) 数据画像 -3. [Anomaly-Detection](../Reference/UDF-Libraries.md#异常检测) 异常检测 -4. [Frequency-Domain](../Reference/UDF-Libraries.md#频域分析) 频域分析 -5. [Data-Matching](../Reference/UDF-Libraries.md#数据匹配) 数据匹配 -6. [Data-Repairing](../Reference/UDF-Libraries.md#数据修复) 数据修复 -7. [Series-Discovery](../Reference/UDF-Libraries.md#序列发现) 序列发现 -8. [Machine-Learning](../Reference/UDF-Libraries.md#机器学习) 机器学习 ## Lambda 表达式 diff --git a/src/zh/UserGuide/Master/Tree/Reference/Syntax-Rule.md b/src/zh/UserGuide/Master/Tree/Reference/Syntax-Rule.md index 379bc26cf..0442ffeb1 100644 --- a/src/zh/UserGuide/Master/Tree/Reference/Syntax-Rule.md +++ b/src/zh/UserGuide/Master/Tree/Reference/Syntax-Rule.md @@ -19,7 +19,7 @@ --> -# 语法约定 +# 标识符 ## 字面值常量 该部分对 IoTDB 中支持的字面值常量进行说明,包括字符串常量、数值型常量、时间戳常量、布尔型常量和空值。 @@ -274,16 +274,3 @@ create device template `t1't"t` - 路径中非database的节点允许含有“*”符号,在使用时需要把该节点用反引号括起来,如root.db.`*`,但是此种用法只建议在路径中不可避免含有“*”时使用。 -## 关键字 - -关键字是在 SQL 具有特定含义的词,可以作为标识符。保留字是关键字的一个子集,保留字不能用于标识符。 - -关于 IoTDB 的关键字列表,可以查看 [关键字](../Reference/Keywords.md) 。 - -## 词法与文法详细定义 - -请阅读代码仓库中的词法和语法描述文件: - -词法文件:`antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlLexer.g4` - -语法文件:`antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4` diff --git a/src/zh/UserGuide/Master/Tree/User-Manual/Database-Programming.md b/src/zh/UserGuide/Master/Tree/User-Manual/Database-Programming.md index b3b1af76a..72b9570b4 100644 --- a/src/zh/UserGuide/Master/Tree/User-Manual/Database-Programming.md +++ b/src/zh/UserGuide/Master/Tree/User-Manual/Database-Programming.md @@ -19,16 +19,14 @@ --> -# 数据库编程 +# 连续查询 -## 连续查询(Continuous Query, CQ) - -### 简介 +## 简介 连续查询(Continuous queries, aka CQ) 是对实时数据周期性地自动执行的查询,并将查询结果写入指定的时间序列中。 用户可以通过连续查询实现滑动窗口流式计算,如计算某个序列每小时平均温度,并写入一个新序列中。用户可以自定义 `RESAMPLE` 子句去创建不同的滑动窗口,可以实现对于乱序数据一定程度的容忍。 -### 语法 +## 语法 ```sql CREATE (CONTINUOUS QUERY | CQ) @@ -56,7 +54,7 @@ END > 2. GROUP BY TIME CLAUSE在连续查询中的语法稍有不同,它不能包含原来的第一个参数,即 [start_time, end_time),IoTDB会自动填充这个缺失的参数。如果指定,IoTDB将会抛出异常。 > 3. 如果连续查询中既没有GROUP BY TIME子句,也没有指定EVERY子句,IoTDB将会抛出异常。 -#### 连续查询语法中参数含义的描述 +### 连续查询语法中参数含义的描述 - `` 为连续查询指定一个全局唯一的标识。 - `` 指定了连续查询周期性执行的间隔。现在支持的时间单位有:ns, us, ms, s, m, h, d, w, 并且它的值不能小于用户在`iotdb-system.properties`配置文件中指定的`continuous_query_min_every_interval`。这是一个可选参数,默认等于group by子句中的`group_by_interval`。 @@ -78,19 +76,19 @@ END > - 如果小于,在连续的两次查询执行的时间窗口中间将会有未覆盖的时间范围 > - start_time_offset 应该大于end_time_offset -##### ``等于`` +#### ``等于`` ![1](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic1.png?raw=true) -##### ``大于`` +#### ``大于`` ![2](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic2.png?raw=true) -##### ``小于`` +#### ``小于`` ![3](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic3.png?raw=true) -##### ``不为0 +#### ``不为0 ![4](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic4.png?raw=true) @@ -99,7 +97,7 @@ END - `DISCARD`意味着如果前一个时间窗口还未执行完,我们会直接丢弃下一个窗口的执行时间。如果使用`DISCARD`策略,可能会有部分时间窗口得不到执行。但是一旦前一个查询执行完后,它将会使用最新的时间窗口,所以它的执行结果总能赶上最新的时间窗口范围,当然是以部分时间窗口得不到执行为代价。 -### 连续查询的用例 +## 连续查询的用例 下面是用例数据,这是一个实时的数据流,我们假设数据都按时到达。 @@ -119,7 +117,7 @@ END +-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+ ```` -#### 配置连续查询执行的周期性间隔 +### 配置连续查询执行的周期性间隔 在`RESAMPLE`子句中使用`EVERY`参数指定连续查询的执行间隔,如果没有指定,默认等于`group_by_interval`。 @@ -177,7 +175,7 @@ At **2021-05-11T22:19:00.000+08:00**, `cq1` executes a query within the time ran +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### 配置连续查询的时间窗口大小 +### 配置连续查询的时间窗口大小 使用`RANGE`子句中的`start_time_offset`参数指定连续查询每次执行的时间窗口的开始时间偏移,如果没有指定,默认值等于`EVERY`参数。 @@ -252,7 +250,7 @@ At **2021-05-11T22:19:00.000+08:00**, `cq2` executes a query within the time ran +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### 同时配置连续查询执行的周期性间隔和时间窗口大小 +### 同时配置连续查询执行的周期性间隔和时间窗口大小 使用`RESAMPLE`子句中的`EVERY`参数和`RANGE`参数分别指定连续查询的执行间隔和窗口大小。并且使用`fill()`来填充没有值的时间区间。 @@ -317,7 +315,7 @@ At **2021-05-11T22:19:00.000+08:00**, `cq3` executes a query within the time ran +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### 配置连续查询每次查询执行时间窗口的结束时间 +### 配置连续查询每次查询执行时间窗口的结束时间 使用`RESAMPLE`子句中的`EVERY`参数和`RANGE`参数分别指定连续查询的执行间隔和窗口大小。并且使用`fill()`来填充没有值的时间区间。 @@ -376,7 +374,7 @@ At **2021-05-11T22:19:00.000+08:00**, `cq4` executes a query within the time ran +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### 没有GROUP BY TIME子句的连续查询 +### 没有GROUP BY TIME子句的连续查询 不使用`GROUP BY TIME`子句,并在`RESAMPLE`子句中显式使用`EVERY`参数指定连续查询的执行间隔。 @@ -482,9 +480,9 @@ At **2021-05-11T22:19:00.000+08:00**, `cq5` executes a query within the time ran +-----------------------------+-------------------------------+-----------+ ```` -### 连续查询的管理 +## 连续查询的管理 -#### 查询系统已有的连续查询 +### 查询系统已有的连续查询 展示集群中所有的已注册的连续查询 @@ -494,7 +492,7 @@ SHOW (CONTINUOUS QUERIES | CQS) `SHOW (CONTINUOUS QUERIES | CQS)`会将结果集按照`cq_id`排序。 -##### 例子 +#### 例子 ```sql SHOW CONTINUOUS QUERIES; @@ -507,7 +505,7 @@ SHOW CONTINUOUS QUERIES; | s1_count_cq | CREATE CQ s1_count_cq
BEGIN
SELECT count(s1)
INTO root.sg_count.d.count_s1
FROM root.sg.d
GROUP BY(30m)
END | active | -#### 删除已有的连续查询 +### 删除已有的连续查询 删除指定的名为cq_id的连续查询: @@ -517,7 +515,7 @@ DROP (CONTINUOUS QUERY | CQ) DROP CQ并不会返回任何结果集。 -##### 例子 +#### 例子 删除名为s1_count_cq的连续查询: @@ -525,28 +523,28 @@ DROP CQ并不会返回任何结果集。 DROP CONTINUOUS QUERY s1_count_cq; ``` -#### 修改已有的连续查询 +### 修改已有的连续查询 目前连续查询一旦被创建就不能再被修改。如果想要修改某个连续查询,只能先用`DROP`命令删除它,然后再用`CREATE`命令重新创建。 -### 连续查询的使用场景 +## 连续查询的使用场景 -#### 对数据进行降采样并对降采样后的数据使用不同的保留策略 +### 对数据进行降采样并对降采样后的数据使用不同的保留策略 可以使用连续查询,定期将高频率采样的原始数据(如每秒1000个点),降采样(如每秒仅保留一个点)后保存到另一个 database 的同名序列中。高精度的原始数据所在 database 的`TTL`可能设置的比较短,比如一天,而低精度的降采样后的数据所在的 database `TTL`可以设置的比较长,比如一个月,从而达到快速释放磁盘空间的目的。 -#### 预计算代价昂贵的查询 +### 预计算代价昂贵的查询 我们可以通过连续查询对一些重复的查询进行预计算,并将查询结果保存在某些目标序列中,这样真实查询并不需要真的再次去做计算,而是直接查询目标序列的结果,从而缩短了查询的时间。 > 预计算查询结果尤其对一些可视化工具渲染时序图和工作台时有很大的加速作用。 -#### 作为子查询的替代品 +### 作为子查询的替代品 IoTDB现在不支持子查询,但是我们可以通过创建连续查询得到相似的功能。我们可以将子查询注册为一个连续查询,并将子查询的结果物化到目标序列中,外层查询再直接查询哪个目标序列。 -##### 例子 +#### 例子 IoTDB并不会接收如下的嵌套子查询。这个查询会计算s1序列每隔30分钟的非空值数量的平均值: @@ -581,7 +579,7 @@ SELECT avg(count_s1) from root.sg_count.d; ``` -### 连续查询相关的配置参数 +## 连续查询相关的配置参数 | 参数名 | 描述 | 类型 | 默认值 | | :---------------------------------- |----------------------|----------|---------------| | `continuous_query_submit_thread` | 用于周期性提交连续查询执行任务的线程数 | int32 | 2 | diff --git a/src/zh/UserGuide/latest/Reference/Operator-and-Expression.md b/src/zh/UserGuide/latest/Reference/Operator-and-Expression.md index 2818fd7cd..6afc120a6 100644 --- a/src/zh/UserGuide/latest/Reference/Operator-and-Expression.md +++ b/src/zh/UserGuide/latest/Reference/Operator-and-Expression.md @@ -19,7 +19,7 @@ --> -# 运算符、函数和表达式 +# 函数与运算符 ## 运算符 ### 算数运算符 @@ -243,31 +243,6 @@ OR, |, || 详细说明及示例见文档 [时间序列处理](../Reference/Function-and-Expression.md#时间序列处理)。 -## 数据质量函数库 - -### 关于 - -对基于时序数据的应用而言,数据质量至关重要。基于用户自定义函数能力,IoTDB 提供了一系列关于数据质量的函数,包括数据画像、数据质量评估与修复等,能够满足工业领域对数据质量的需求。 - -### 快速上手 - -**该函数库中的函数不是内置函数,使用前要先加载到系统中。** 操作流程如下: - -1. 下载包含全部依赖的 jar 包和注册脚本 [【点击下载】](https://archive.apache.org/dist/iotdb/1.0.1/apache-iotdb-1.0.1-library-udf-bin.zip) ; -2. 将 jar 包复制到 IoTDB 程序目录的 `ext\udf` 目录下 (若您使用的是集群,请将jar包复制到所有DataNode的该目录下); -3. 启动 IoTDB; -4. 将注册脚本复制到 IoTDB 的程序目录下(与`sbin`目录同级的根目录下),修改脚本中的参数(如果需要)并运行注册脚本以注册 UDF。 - -### 已经实现的函数 - -1. [Data-Quality](../Reference/UDF-Libraries.md#数据质量) 数据质量 -2. [Data-Profiling](../Reference/UDF-Libraries.md#数据画像) 数据画像 -3. [Anomaly-Detection](../Reference/UDF-Libraries.md#异常检测) 异常检测 -4. [Frequency-Domain](../Reference/UDF-Libraries.md#频域分析) 频域分析 -5. [Data-Matching](../Reference/UDF-Libraries.md#数据匹配) 数据匹配 -6. [Data-Repairing](../Reference/UDF-Libraries.md#数据修复) 数据修复 -7. [Series-Discovery](../Reference/UDF-Libraries.md#序列发现) 序列发现 -8. [Machine-Learning](../Reference/UDF-Libraries.md#机器学习) 机器学习 ## Lambda 表达式 diff --git a/src/zh/UserGuide/latest/Reference/Syntax-Rule.md b/src/zh/UserGuide/latest/Reference/Syntax-Rule.md index 379bc26cf..0442ffeb1 100644 --- a/src/zh/UserGuide/latest/Reference/Syntax-Rule.md +++ b/src/zh/UserGuide/latest/Reference/Syntax-Rule.md @@ -19,7 +19,7 @@ --> -# 语法约定 +# 标识符 ## 字面值常量 该部分对 IoTDB 中支持的字面值常量进行说明,包括字符串常量、数值型常量、时间戳常量、布尔型常量和空值。 @@ -274,16 +274,3 @@ create device template `t1't"t` - 路径中非database的节点允许含有“*”符号,在使用时需要把该节点用反引号括起来,如root.db.`*`,但是此种用法只建议在路径中不可避免含有“*”时使用。 -## 关键字 - -关键字是在 SQL 具有特定含义的词,可以作为标识符。保留字是关键字的一个子集,保留字不能用于标识符。 - -关于 IoTDB 的关键字列表,可以查看 [关键字](../Reference/Keywords.md) 。 - -## 词法与文法详细定义 - -请阅读代码仓库中的词法和语法描述文件: - -词法文件:`antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlLexer.g4` - -语法文件:`antlr/src/main/antlr4/org/apache/iotdb/db/qp/sql/IoTDBSqlParser.g4` diff --git a/src/zh/UserGuide/latest/User-Manual/Database-Programming.md b/src/zh/UserGuide/latest/User-Manual/Database-Programming.md index b3b1af76a..72b9570b4 100644 --- a/src/zh/UserGuide/latest/User-Manual/Database-Programming.md +++ b/src/zh/UserGuide/latest/User-Manual/Database-Programming.md @@ -19,16 +19,14 @@ --> -# 数据库编程 +# 连续查询 -## 连续查询(Continuous Query, CQ) - -### 简介 +## 简介 连续查询(Continuous queries, aka CQ) 是对实时数据周期性地自动执行的查询,并将查询结果写入指定的时间序列中。 用户可以通过连续查询实现滑动窗口流式计算,如计算某个序列每小时平均温度,并写入一个新序列中。用户可以自定义 `RESAMPLE` 子句去创建不同的滑动窗口,可以实现对于乱序数据一定程度的容忍。 -### 语法 +## 语法 ```sql CREATE (CONTINUOUS QUERY | CQ) @@ -56,7 +54,7 @@ END > 2. GROUP BY TIME CLAUSE在连续查询中的语法稍有不同,它不能包含原来的第一个参数,即 [start_time, end_time),IoTDB会自动填充这个缺失的参数。如果指定,IoTDB将会抛出异常。 > 3. 如果连续查询中既没有GROUP BY TIME子句,也没有指定EVERY子句,IoTDB将会抛出异常。 -#### 连续查询语法中参数含义的描述 +### 连续查询语法中参数含义的描述 - `` 为连续查询指定一个全局唯一的标识。 - `` 指定了连续查询周期性执行的间隔。现在支持的时间单位有:ns, us, ms, s, m, h, d, w, 并且它的值不能小于用户在`iotdb-system.properties`配置文件中指定的`continuous_query_min_every_interval`。这是一个可选参数,默认等于group by子句中的`group_by_interval`。 @@ -78,19 +76,19 @@ END > - 如果小于,在连续的两次查询执行的时间窗口中间将会有未覆盖的时间范围 > - start_time_offset 应该大于end_time_offset -##### ``等于`` +#### ``等于`` ![1](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic1.png?raw=true) -##### ``大于`` +#### ``大于`` ![2](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic2.png?raw=true) -##### ``小于`` +#### ``小于`` ![3](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic3.png?raw=true) -##### ``不为0 +#### ``不为0 ![4](https://alioss.timecho.com/docs/img/UserGuide/Process-Data/Continuous-Query/pic4.png?raw=true) @@ -99,7 +97,7 @@ END - `DISCARD`意味着如果前一个时间窗口还未执行完,我们会直接丢弃下一个窗口的执行时间。如果使用`DISCARD`策略,可能会有部分时间窗口得不到执行。但是一旦前一个查询执行完后,它将会使用最新的时间窗口,所以它的执行结果总能赶上最新的时间窗口范围,当然是以部分时间窗口得不到执行为代价。 -### 连续查询的用例 +## 连续查询的用例 下面是用例数据,这是一个实时的数据流,我们假设数据都按时到达。 @@ -119,7 +117,7 @@ END +-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+ ```` -#### 配置连续查询执行的周期性间隔 +### 配置连续查询执行的周期性间隔 在`RESAMPLE`子句中使用`EVERY`参数指定连续查询的执行间隔,如果没有指定,默认等于`group_by_interval`。 @@ -177,7 +175,7 @@ At **2021-05-11T22:19:00.000+08:00**, `cq1` executes a query within the time ran +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### 配置连续查询的时间窗口大小 +### 配置连续查询的时间窗口大小 使用`RANGE`子句中的`start_time_offset`参数指定连续查询每次执行的时间窗口的开始时间偏移,如果没有指定,默认值等于`EVERY`参数。 @@ -252,7 +250,7 @@ At **2021-05-11T22:19:00.000+08:00**, `cq2` executes a query within the time ran +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### 同时配置连续查询执行的周期性间隔和时间窗口大小 +### 同时配置连续查询执行的周期性间隔和时间窗口大小 使用`RESAMPLE`子句中的`EVERY`参数和`RANGE`参数分别指定连续查询的执行间隔和窗口大小。并且使用`fill()`来填充没有值的时间区间。 @@ -317,7 +315,7 @@ At **2021-05-11T22:19:00.000+08:00**, `cq3` executes a query within the time ran +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### 配置连续查询每次查询执行时间窗口的结束时间 +### 配置连续查询每次查询执行时间窗口的结束时间 使用`RESAMPLE`子句中的`EVERY`参数和`RANGE`参数分别指定连续查询的执行间隔和窗口大小。并且使用`fill()`来填充没有值的时间区间。 @@ -376,7 +374,7 @@ At **2021-05-11T22:19:00.000+08:00**, `cq4` executes a query within the time ran +-----------------------------+---------------------------------+---------------------------------+---------------------------------+---------------------------------+ ```` -#### 没有GROUP BY TIME子句的连续查询 +### 没有GROUP BY TIME子句的连续查询 不使用`GROUP BY TIME`子句,并在`RESAMPLE`子句中显式使用`EVERY`参数指定连续查询的执行间隔。 @@ -482,9 +480,9 @@ At **2021-05-11T22:19:00.000+08:00**, `cq5` executes a query within the time ran +-----------------------------+-------------------------------+-----------+ ```` -### 连续查询的管理 +## 连续查询的管理 -#### 查询系统已有的连续查询 +### 查询系统已有的连续查询 展示集群中所有的已注册的连续查询 @@ -494,7 +492,7 @@ SHOW (CONTINUOUS QUERIES | CQS) `SHOW (CONTINUOUS QUERIES | CQS)`会将结果集按照`cq_id`排序。 -##### 例子 +#### 例子 ```sql SHOW CONTINUOUS QUERIES; @@ -507,7 +505,7 @@ SHOW CONTINUOUS QUERIES; | s1_count_cq | CREATE CQ s1_count_cq
BEGIN
SELECT count(s1)
INTO root.sg_count.d.count_s1
FROM root.sg.d
GROUP BY(30m)
END | active | -#### 删除已有的连续查询 +### 删除已有的连续查询 删除指定的名为cq_id的连续查询: @@ -517,7 +515,7 @@ DROP (CONTINUOUS QUERY | CQ) DROP CQ并不会返回任何结果集。 -##### 例子 +#### 例子 删除名为s1_count_cq的连续查询: @@ -525,28 +523,28 @@ DROP CQ并不会返回任何结果集。 DROP CONTINUOUS QUERY s1_count_cq; ``` -#### 修改已有的连续查询 +### 修改已有的连续查询 目前连续查询一旦被创建就不能再被修改。如果想要修改某个连续查询,只能先用`DROP`命令删除它,然后再用`CREATE`命令重新创建。 -### 连续查询的使用场景 +## 连续查询的使用场景 -#### 对数据进行降采样并对降采样后的数据使用不同的保留策略 +### 对数据进行降采样并对降采样后的数据使用不同的保留策略 可以使用连续查询,定期将高频率采样的原始数据(如每秒1000个点),降采样(如每秒仅保留一个点)后保存到另一个 database 的同名序列中。高精度的原始数据所在 database 的`TTL`可能设置的比较短,比如一天,而低精度的降采样后的数据所在的 database `TTL`可以设置的比较长,比如一个月,从而达到快速释放磁盘空间的目的。 -#### 预计算代价昂贵的查询 +### 预计算代价昂贵的查询 我们可以通过连续查询对一些重复的查询进行预计算,并将查询结果保存在某些目标序列中,这样真实查询并不需要真的再次去做计算,而是直接查询目标序列的结果,从而缩短了查询的时间。 > 预计算查询结果尤其对一些可视化工具渲染时序图和工作台时有很大的加速作用。 -#### 作为子查询的替代品 +### 作为子查询的替代品 IoTDB现在不支持子查询,但是我们可以通过创建连续查询得到相似的功能。我们可以将子查询注册为一个连续查询,并将子查询的结果物化到目标序列中,外层查询再直接查询哪个目标序列。 -##### 例子 +#### 例子 IoTDB并不会接收如下的嵌套子查询。这个查询会计算s1序列每隔30分钟的非空值数量的平均值: @@ -581,7 +579,7 @@ SELECT avg(count_s1) from root.sg_count.d; ``` -### 连续查询相关的配置参数 +## 连续查询相关的配置参数 | 参数名 | 描述 | 类型 | 默认值 | | :---------------------------------- |----------------------|----------|---------------| | `continuous_query_submit_thread` | 用于周期性提交连续查询执行任务的线程数 | int32 | 2 |