未验证 提交 e0aaab3a 编写于 作者: sangshuduo's avatar sangshuduo 提交者: GitHub

[TD-14360]<docs>: remove stream api (#11063)

* [TD-14360]<docs>: remove stream api

* remove examples/c/stream.c

* remove stream test
上级 c682aa85
......@@ -486,26 +486,6 @@ int main() {
}
```
### 连续查询接口
TDengine 提供时间驱动的实时流式计算 API。可以每隔一指定的时间段,对一张或多张数据库的表(数据流)进行各种实时聚合计算操作。操作简单,仅有打开、关闭流的 API。具体如下:
- `TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), int64_t stime, void *param, void (*callback)(void *))`
该 API 用来创建数据流,其中:
* taos:已经建立好的数据库连接。
* sql:SQL查询语句(仅能使用查询语句)。
* fp:用户定义的回调函数指针,每次流式计算完成后,TDengine将查询的结果(TAOS_ROW)、查询状态(TAOS_RES)、用户定义参数(PARAM)传递给回调函数,在回调函数内,用户可以使用taos_num_fields获取结果集列数,taos_fetch_fields获取结果集每列数据的类型。
* stime:是流式计算开始的时间。如果是“64位整数最小值”,表示从现在开始;如果不为“64位整数最小值”,表示从指定的时间开始计算(UTC时间从1970/1/1算起的毫秒数)。
* param:是应用提供的用于回调的一个参数,回调时,提供给应用。
* callback: 第二个回调函数,会在连续查询自动停止时被调用。
返回值为 NULL,表示创建失败;返回值不为空,表示成功。
- `void taos_close_stream (TAOS_STREAM *tstr)`
关闭数据流,其中提供的参数是 taos_open_stream 的返回值。用户停止流式计算的时候,务必关闭该数据流。
### 数据订阅接口
订阅 API 目前支持订阅一张或多张表,并通过定期轮询的方式不断获取写入表中的最新数据。
......
......@@ -420,7 +420,7 @@ In addition to writing data using SQL or using the parameter binding API, writin
#include <stdlib.h>
#include <stdio.h>
#include <taos.h>
int main() {
const char* host = "127.0.0.1";
const char* user = "root";
......@@ -428,48 +428,27 @@ int main() {
// connect to server
TAOS* taos = taos_connect(host, user, passwd, "test", 0);
// prepare the line string
char* lines1[] = {
"stg,t1=3i64,t2=4f64,t3=\"t3\" c1=3i64,c3=L\"passit\",c2=false,c4=4f64 1626006833639000000",
"stg,t1=4i64,t3=\"t4\",t2=5f64,t4=5f64 c1=3i64,c3=L\"passitagin\",c2=true,c4=5f64,c5=5f64 1626006833641000000"
};
// schema-less insert
TAOS_RES* res = taos_schemaless_insert(taos, lines1, 2, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_NANO_SECONDS);
if (taos_errno(res) != 0) {
printf("failed to insert schema-less data, reason: %s\n", taos_errstr(res));
}
taos_free_result(res);
// close the connection
taos_close(taos);
return (code);
}
```
### Continuous query interface
TDengine provides time-driven real-time stream computing APIs. You can perform various real-time aggregation calculation operations on tables (data streams) of one or more databases at regular intervals. The operation is simple, only APIs for opening and closing streams. The details are as follows:
- `TAOS_STREAM *taos_open_stream(TAOS *taos, const char *sql, void (*fp)(void *param, TAOS_RES *, TAOS_ROW row), int64_t stime, void *param, void (*callback)(void *))`
This API is used to create data streams where:
* taos: Database connection established
* sql: SQL query statement (query statement only)
* fp: user-defined callback function pointer. After each stream computing is completed, TDengine passes the query result (TAOS_ROW), query status (TAOS_RES), and user-defined parameters (PARAM) to the callback function. In the callback function, the user can use `taos_num_fields()` to obtain the number of columns in the result set, and `taos_fetch_fields()` to obtain the type of data in each column of the result set.
* stime: The time when stream computing starts. If it is 0, it means starting from now. If it is not zero, it means starting from the specified time (the number of milliseconds from 1970/1/1 UTC time).
* param: It is a parameter provided by the application for callback. During callback, the parameter is provided to the application
* callback: The second callback function is called when the continuous query stop automatically.
The return value is NULL, indicating creation failed; the return value is not NULL, indicating creation successful.
- `void taos_close_stream (TAOS_STREAM *tstr)`
Close the data flow, where the parameter provided is the return value of `taos_open_stream()`. When the user stops stream computing, be sure to close the data flow.
### Data subscription interface
The subscription API currently supports subscribing to one or more tables and continuously obtaining the latest data written to the tables through regular polling.
......
......@@ -262,32 +262,6 @@ void verify_async(TAOS* taos) {
usleep(1000000);
}
void stream_callback(void* param, TAOS_RES* res, TAOS_ROW row) {
if (res == NULL || row == NULL) {
return;
}
int num_fields = taos_num_fields(res);
TAOS_FIELD* fields = taos_fetch_fields(res);
printf("got one row from stream_callback\n");
char temp[256] = {0};
taos_print_row(temp, row, fields, num_fields);
puts(temp);
}
void verify_stream(TAOS* taos) {
prepare_data(taos);
TAOS_STREAM* strm =
taos_open_stream(taos, "select count(*) from meters interval(1m)", stream_callback, 0, NULL, NULL);
printf("waiting for stream data\n");
usleep(100000);
TAOS_RES* result = taos_query(taos, "insert into t0 values(now, 0)(now+5s,1)(now+10s, 2);");
taos_free_result(result);
usleep(200000000);
taos_close_stream(strm);
}
void verify_schema_less(TAOS* taos) {
TAOS_RES* result;
result = taos_query(taos, "drop database if exists test;");
......@@ -447,8 +421,6 @@ int main(int argc, char* argv[]) {
printf("*********** verify subscribe ************\n");
verify_subscribe(taos);
printf("************ verify stream *************\n");
// verify_stream(taos);
printf("done\n");
taos_close(taos);
taos_cleanup();
......
/*
* 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/>.
*/
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <taos.h> // include TDengine header file
#include <unistd.h>
typedef struct {
char server_ip[64];
char db_name[64];
char tbl_name[64];
} param;
int g_thread_exit_flag = 0;
void *insert_rows(void *sarg);
void streamCallBack(void *param, TAOS_RES *res, TAOS_ROW row) {
// in this simple demo, it just print out the result
char temp[128];
TAOS_FIELD *fields = taos_fetch_fields(res);
int numFields = taos_num_fields(res);
taos_print_row(temp, row, fields, numFields);
printf("\n%s\n", temp);
}
int main(int argc, char *argv[]) {
TAOS *taos;
char db_name[64];
char tbl_name[64];
char sql[1024] = {0};
if (argc != 4) {
printf("usage: %s server-ip dbname tblname\n", argv[0]);
exit(0);
}
strcpy(db_name, argv[2]);
strcpy(tbl_name, argv[3]);
// create pthread to insert into row per second for stream calc
param *t_param = (param *)malloc(sizeof(param));
if (NULL == t_param) {
printf("failed to malloc\n");
exit(1);
}
memset(t_param, 0, sizeof(param));
strcpy(t_param->server_ip, argv[1]);
strcpy(t_param->db_name, db_name);
strcpy(t_param->tbl_name, tbl_name);
pthread_t pid;
pthread_create(&pid, NULL, (void *(*)(void *))insert_rows, t_param);
sleep(3); // waiting for database is created.
// open connection to database
taos = taos_connect(argv[1], "root", "taosdata", db_name, 0);
if (taos == NULL) {
printf("failed to connet to server:%s\n", argv[1]);
free(t_param);
exit(1);
}
// starting stream calc,
printf("please input stream SQL:[e.g., select count(*) from tblname interval(5s) sliding(2s);]\n");
fgets(sql, sizeof(sql), stdin);
if (sql[0] == 0) {
printf("input NULL stream SQL, so exit!\n");
free(t_param);
exit(1);
}
// param is set to NULL in this demo, it shall be set to the pointer to app context
TAOS_STREAM *pStream = taos_open_stream(taos, sql, streamCallBack, 0, NULL, NULL);
if (NULL == pStream) {
printf("failed to create stream\n");
free(t_param);
exit(1);
}
printf("press any key to exit\n");
getchar();
taos_close_stream(pStream);
g_thread_exit_flag = 1;
pthread_join(pid, NULL);
taos_close(taos);
free(t_param);
return 0;
}
void *insert_rows(void *sarg) {
TAOS * taos;
char command[1024] = {0};
param *winfo = (param *)sarg;
if (NULL == winfo) {
printf("para is null!\n");
exit(1);
}
taos = taos_connect(winfo->server_ip, "root", "taosdata", NULL, 0);
if (taos == NULL) {
printf("failed to connet to server:%s\n", winfo->server_ip);
exit(1);
}
// drop database
sprintf(command, "drop database %s;", winfo->db_name);
if (taos_query(taos, command) != 0) {
printf("failed to drop database, reason:%s\n", taos_errstr(taos));
exit(1);
}
// create database
sprintf(command, "create database %s;", winfo->db_name);
if (taos_query(taos, command) != 0) {
printf("failed to create database, reason:%s\n", taos_errstr(taos));
exit(1);
}
// use database
sprintf(command, "use %s;", winfo->db_name);
if (taos_query(taos, command) != 0) {
printf("failed to use database, reason:%s\n", taos_errstr(taos));
exit(1);
}
// create table
sprintf(command, "create table %s (ts timestamp, speed int);", winfo->tbl_name);
if (taos_query(taos, command) != 0) {
printf("failed to create table, reason:%s\n", taos_errstr(taos));
exit(1);
}
// insert data
int64_t begin = (int64_t)time(NULL);
int index = 0;
while (1) {
if (g_thread_exit_flag) break;
index++;
sprintf(command, "insert into %s values (%ld, %d)", winfo->tbl_name, (begin + index) * 1000, index);
if (taos_query(taos, command)) {
printf("failed to insert row [%s], reason:%s\n", command, taos_errstr(taos));
}
sleep(1);
}
taos_close(taos);
return 0;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册