You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Docs Update; Completed async functionality for Node.js connector, updated to 1.2.0
Docs
- Docs updated
- include third party connectors links
- local docs updated to web versions and fixed for compatability
Node
- Async added
- Deleted uncessary code
- Docs updated
To start the TDengine server, run the command below in terminal:
50
-
```cmd
50
+
```cmd
51
51
./build/bin/taosd -c test/cfg
52
52
```
53
53
In another terminal, use the TDengine shell to connect the server:
@@ -88,7 +88,9 @@ drop database db;
88
88
```
89
89
90
90
# Developing with TDengine
91
-
TDengine provides abundant developing tools for users to develop on TDengine. Follow the links below to find your desired connectors.
91
+
### Official Connectors
92
+
93
+
TDengine provides abundant developing tools for users to develop on TDengine. Follow the links below to find your desired connectors and relevant documentation.
<p>Continuous Query is a query executed by TDengine periodically with a sliding window, it is a simplified stream computing driven by timers, not by events. Continuous query can be applied to a table or a STable, and the result set can be passed to the application directly via call back function, or written into a new table in TDengine. The query is always executed on a specified time window (window size is specified by parameter interval), and this window slides forward while time flows (the sliding period is specified by parameter sliding). </p>
4
4
<p>Continuous query is defined by TAOS SQL, there is nothing special. One of the best applications is downsampling. Once it is defined, at the end of each cycle, the system will execute the query, pass the result to the application or write it to a database. </p>
5
-
<p>If historical data pints are inserted into the stream, the query won't be re-executed, and the result set won't be updated. If the result set is passed to the application, the application needs to keep the status of continuous query, the server won't maintain it. If application re-starts, it needs to decide the time where the stream computing shall be started.</p>
5
+
<p>If historical data pints are inserted into the stream, the query won't be re-executed, and the result set won't be updated. If the result set is passed to the application, the application needs to keep the status of continuous query, the server won't maintain it. If application re-starts, it needs to decide the time where the stream computing shall be started.</p>
6
6
<h4>How to use continuous query</h4>
7
7
<ul>
8
8
<li><p>Pass result set to application</p>
9
9
<p>Application shall use API taos_stream (details in connector section) to start the stream computing. Inside the API, the SQL syntax is:</p>
10
-
<pre><codeclass='language-sql' lang='sql'>SELECT aggregation FROM [table_name | stable_name]
10
+
<pre><codeclass="sql language-sql">SELECT aggregation FROM [table_name | stable_name]
<p>where the new keyword INTERVAL specifies the window size, and SLIDING specifies the sliding period. If parameter sliding is not specified, the sliding period will be the same as window size. The minimum window size is 10ms. The sliding period shall not be larger than the window size. If you set a value larger than the window size, the system will adjust it to window size automatically.</p>
13
13
<p>For example:</p>
14
-
<pre><codeclass='language-sql' lang='sql'>SELECT COUNT(*) FROM FOO_TABLE
14
+
<pre><codeclass="sql language-sql">SELECT COUNT(*) FROM FOO_TABLE
15
15
INTERVAL(1M) SLIDING(30S)</code></pre>
16
-
<p>The above SQL statement will count the number of records for the past 1-minute window every 30 seconds.</p>
17
-
</li>
16
+
<p>The above SQL statement will count the number of records for the past 1-minute window every 30 seconds.</p></li>
18
17
<li><p>Save the result into a database</p>
19
18
<p>If you want to save the result set of stream computing into a new table, the SQL shall be: </p>
20
-
<pre><codeclass='language-sql' lang='sql'>CREATE TABLE table_name AS
19
+
<pre><codeclass="sql language-sql">CREATE TABLE table_name AS
21
20
SELECT aggregation from [table_name | stable_name]
<p>Also, you can set the time range to execute the continuous query. If no range is specified, the continuous query will be executed forever. For example, the following continuous query will be executed from now and will stop in one hour.</p>
24
-
<pre><codeclass='language-sql' lang='sql'>CREATE TABLE QUERY_RES AS
23
+
<pre><codeclass="sql language-sql">CREATE TABLE QUERY_RES AS
25
24
SELECT COUNT(*) FROM FOO_TABLE
26
25
WHERE TS > NOW AND TS <= NOW + 1H
27
-
INTERVAL(1M) SLIDING(30S) </code></pre>
28
-
</li>
29
-
26
+
INTERVAL(1M) SLIDING(30S) </code></pre></li>
30
27
</ul>
31
28
<aclass='anchor' id='Manage-the-Continuous-Query'></a><h3>Manage the Continuous Query</h3>
32
-
<p>Inside TDengine shell, you can use the command "show streams" to list the ongoing continuous queries, the command "kill stream" to kill a specific continuous query. </p>
29
+
<p>Inside TDengine shell, you can use the command "show streams" to list the ongoing continuous queries, the command "kill stream" to kill a specific continuous query. </p>
33
30
<p>If you drop a table generated by the continuous query, the query will be removed too.</p>
<p>Time series data is a sequence of data points over time. Inside a table, the data points are stored in order of timestamp. Also, there is a data retention policy, the data points will be removed once their lifetime is passed. From another view, a table in DTengine is just a standard message queue. </p>
36
33
<p>To reduce the development complexity and improve data consistency, TDengine provides the pub/sub functionality. To publish a message, you simply insert a record into a table. Compared with popular messaging tool Kafka, you subscribe to a table or a SQL query statement, instead of a topic. Once new data points arrive, TDengine will notify the application. The process is just like Kafka. </p>
37
-
<p>The detailed API will be introduced in the <ahref=''>connectors</a> section. </p>
34
+
<p>The detailed API will be introduced in the <ahref="https://www.taosdata.com/en/documentation/advanced-features/">connectors</a> section. </p>
<p>TDengine allocates a fixed-size buffer in memory, the newly arrived data will be written into the buffer first. Every device or table gets one or more memory blocks. For typical IoT scenarios, the hot data shall always be newly arrived data, they are more important for timely analysis. Based on this observation, TDengine manages the cache blocks in First-In-First-Out strategy. If no enough space in the buffer, the oldest data will be saved into hard disk first, then be overwritten by newly arrived data. TDengine also guarantees every device can keep at least one block of data in the buffer. </p>
40
37
<p>By this design, the application can retrieve the latest data from each device super-fast, since they are all available in memory. You can use last or last_row function to return the last data record. If the super table is used, it can be used to return the last data records of all or a subset of devices. For example, to retrieve the latest temperature from thermometers in located Beijing, execute the following SQL </p>
41
-
<pre><codeclass='language-mysql' lang='mysql'>select last(*) from thermometers where location=’beijing’</code></pre>
38
+
<pre><codeclass="mysql language-mysql">select last(*) from thermometers where location=’beijing’</code></pre>
42
39
<p>By this design, caching tool, like Redis, is not needed in the system. It will reduce the complexity of the system. </p>
43
40
<p>TDengine creates one or more virtual nodes(vnode) in each data node. Each vnode contains data for multiple tables and has its own buffer. The buffer of a vnode is fully separated from the buffer of another vnode, not shared. But the tables in a vnode share the same buffer. </p>
44
-
<p>System configuration parameter cacheBlockSize configures the cache block size in bytes, and another parameter cacheNumOfBlocks configures the number of cache blocks. The total memory for the buffer of a vnode is cacheBlockSize \times cacheNumOfBlocks. Another system parameter numOfBlocksPerMeter configures the maximum number of cache blocks a table can use. When you create a database, you can specify these parameters. </p>
<p>System configuration parameter cacheBlockSize configures the cache block size in bytes, and another parameter cacheNumOfBlocks configures the number of cache blocks. The total memory for the buffer of a vnode is $cacheBlockSize \times cacheNumOfBlocks$. Another system parameter numOfBlocksPerMeter configures the maximum number of cache blocks a table can use. When you create a database, you can specify these parameters. </p><ahref='../index.html'>Back</a></section></main></div><?php include($s.'/footer.php'); ?><script>$('pre').addClass('prettyprint linenums');PR.prettyPrint()</script><scriptsrc='lib/docs/liner.js'></script></body></html>
<p>The async API to fetch a result row. <em>res</em> is the result handle. <em>fp</em> is the callback function. <em>param</em> is a user-defined structure to pass to <em>fp</em>. The third parameter of the callback function is a single result row, which is different from that of <em>taos_fetch_rows_a</em> API. With this API, it is not necessary to call <em>taos_fetch_row</em> to retrieve each result row, which is handier than <em>taos_fetch_rows_a</em> but less efficient.</p></li>
49
49
</ul>
50
-
<p>Applications may apply operations on multiple tables. However, <strong>it is important to make sure the operations on the same table are serialized</strong>. That means after sending an insert request in a table to the server, no operations on the table are allowed before a request is received.</p>
50
+
<p>Applications may apply operations on multiple tables. However, <strong>it is important to make sure the operations on the same table are serialized</strong>. That means after sending an insert request in a table to the server, no operations on the table are allowed before a response is received.</p>
<p>TDengine provides APIs for continuous query driven by time, which run queries periodically in the background. There are only two APIs:</p>
53
53
<ul>
@@ -268,17 +268,26 @@ <h4>Queries</h4>
268
268
result.pretty(); //logs the results to the console as if you were in the taos shell
269
269
});</code></pre>
270
270
<p>You can also query by binding parameters to a query by filling in the question marks in a string as so. The query will automatically parse what was binded and convert it to the proper format for use with TDengine</p>
271
-
<pre><codeclass="javascript language-javascript">var query = cursor.query('select * from meterinfo.meters where ts <= ? and areaid = ?').bind(new Date(), 5);
271
+
<pre><codeclass="javascript language-javascript">var query = cursor.query('select * from meterinfo.meters where ts <= ? and areaid = ?;').bind(new Date(), 5);
272
272
query.execute().then(function(result) {
273
273
result.pretty();
274
274
})</code></pre>
275
275
<p>The TaosQuery object can also be immediately executed upon creation by passing true as the second argument, returning a promise instead of a TaosQuery.</p>
276
-
<pre><codeclass="javascript language-javascript">var promise = cursor.query('select * from meterinfo.meters where v1 = 30', true)
276
+
<pre><codeclass="javascript language-javascript">var promise = cursor.query('select * from meterinfo.meters where v1 = 30;', true)
277
277
promise.then(function(result) {
278
278
result.pretty();
279
279
})</code></pre>
280
280
<h4>Async functionality</h4>
281
-
<p>Coming soon</p>
281
+
<p>Async queries can be performed using the same functions such as <code>cursor.execute</code>, <code>cursor.query</code>, but now with <code>_a</code> appended to them.</p>
282
+
<p>Say you want to execute an two async query on two seperate tables, using <code>cursor.query_a</code>, you can do that and get a TaosQuery object, which upon executing with the <code>execute_a</code> function, returns a promise that resolves with a TaosResult object.</p>
283
+
<pre><codeclass="javascript language-javascript">var promise1 = cursor.query_a('select count(*), avg(v1), avg(v2) from meter1;').execute_a()
284
+
var promise2 = cursor.query_a('select count(*), avg(v1), avg(v2) from meter2;').execute_a();
285
+
promise1.then(function(result) {
286
+
result.pretty();
287
+
})
288
+
promise2.then(function(result) {
289
+
result.pretty();
290
+
})</code></pre>
282
291
<h3>Example</h3>
283
292
<p>An example of using the NodeJS connector to create a table with weather data and create and execute queries can be found <ahref="https://github.com/taosdata/TDengine/tree/master/tests/examples/nodejs/node-example.js">here</a> (The preferred method for using the connector)</p>
284
293
<p>An example of using the NodeJS connector to achieve the same things but without all the object wrappers that wrap around the data returned to achieve higher functionality can be found <ahref="https://github.com/taosdata/TDengine/tree/master/tests/examples/nodejs/node-example-raw.js">here</a></p><ahref='../index.html'>Back</a></section></main></div><?php include($s.'/footer.php'); ?><script>$('pre').addClass('prettyprint linenums');PR.prettyPrint()</script><scriptsrc='lib/docs/liner.js'></script></body></html>
0 commit comments