test: change city name
This commit is contained in:
parent
c03ea81bcf
commit
e82afdb035
|
@ -36,10 +36,10 @@ int main() {
|
||||||
executeSQL(taos, "CREATE DATABASE power");
|
executeSQL(taos, "CREATE DATABASE power");
|
||||||
executeSQL(taos, "USE power");
|
executeSQL(taos, "USE power");
|
||||||
executeSQL(taos, "CREATE STABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)");
|
executeSQL(taos, "CREATE STABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)");
|
||||||
executeSQL(taos, "INSERT INTO d1001 USING meters TAGS(Beijing.Chaoyang, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)"
|
executeSQL(taos, "INSERT INTO d1001 USING meters TAGS(California.SanFrancisco, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)"
|
||||||
"d1002 USING meters TAGS(Beijing.Chaoyang, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)"
|
"d1002 USING meters TAGS(California.SanFrancisco, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)"
|
||||||
"d1003 USING meters TAGS(Beijing.Haidian, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)"
|
"d1003 USING meters TAGS(California.LosAngeles, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)"
|
||||||
"d1004 USING meters TAGS(Beijing.Haidian, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)");
|
"d1004 USING meters TAGS(California.LosAngeles, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)");
|
||||||
taos_close(taos);
|
taos_close(taos);
|
||||||
taos_cleanup();
|
taos_cleanup();
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,11 +29,11 @@ int main() {
|
||||||
executeSQL(taos, "USE test");
|
executeSQL(taos, "USE test");
|
||||||
char *line =
|
char *line =
|
||||||
"[{\"metric\": \"meters.current\", \"timestamp\": 1648432611249, \"value\": 10.3, \"tags\": {\"location\": "
|
"[{\"metric\": \"meters.current\", \"timestamp\": 1648432611249, \"value\": 10.3, \"tags\": {\"location\": "
|
||||||
"\"Beijing.Chaoyang\", \"groupid\": 2}},{\"metric\": \"meters.voltage\", \"timestamp\": 1648432611249, "
|
"\"California.SanFrancisco\", \"groupid\": 2}},{\"metric\": \"meters.voltage\", \"timestamp\": 1648432611249, "
|
||||||
"\"value\": 219, \"tags\": {\"location\": \"Beijing.Haidian\", \"groupid\": 1}},{\"metric\": \"meters.current\", "
|
"\"value\": 219, \"tags\": {\"location\": \"California.LosAngeles\", \"groupid\": 1}},{\"metric\": \"meters.current\", "
|
||||||
"\"timestamp\": 1648432611250, \"value\": 12.6, \"tags\": {\"location\": \"Beijing.Chaoyang\", \"groupid\": "
|
"\"timestamp\": 1648432611250, \"value\": 12.6, \"tags\": {\"location\": \"California.SanFrancisco\", \"groupid\": "
|
||||||
"2}},{\"metric\": \"meters.voltage\", \"timestamp\": 1648432611250, \"value\": 221, \"tags\": {\"location\": "
|
"2}},{\"metric\": \"meters.voltage\", \"timestamp\": 1648432611250, \"value\": 221, \"tags\": {\"location\": "
|
||||||
"\"Beijing.Haidian\", \"groupid\": 1}}]";
|
"\"California.LosAngeles\", \"groupid\": 1}}]";
|
||||||
|
|
||||||
char *lines[] = {line};
|
char *lines[] = {line};
|
||||||
TAOS_RES *res = taos_schemaless_insert(taos, lines, 1, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
|
TAOS_RES *res = taos_schemaless_insert(taos, lines, 1, TSDB_SML_JSON_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
|
||||||
|
|
|
@ -27,10 +27,10 @@ int main() {
|
||||||
executeSQL(taos, "DROP DATABASE IF EXISTS test");
|
executeSQL(taos, "DROP DATABASE IF EXISTS test");
|
||||||
executeSQL(taos, "CREATE DATABASE test");
|
executeSQL(taos, "CREATE DATABASE test");
|
||||||
executeSQL(taos, "USE test");
|
executeSQL(taos, "USE test");
|
||||||
char *lines[] = {"meters,location=Beijing.Haidian,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249",
|
char *lines[] = {"meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249",
|
||||||
"meters,location=Beijing.Haidian,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611250",
|
"meters,location=California.LosAngeles,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611250",
|
||||||
"meters,location=Beijing.Haidian,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249",
|
"meters,location=California.LosAngeles,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249",
|
||||||
"meters,location=Beijing.Haidian,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611250"};
|
"meters,location=California.LosAngeles,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611250"};
|
||||||
TAOS_RES *res = taos_schemaless_insert(taos, lines, 4, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
TAOS_RES *res = taos_schemaless_insert(taos, lines, 4, TSDB_SML_LINE_PROTOCOL, TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||||
if (taos_errno(res) != 0) {
|
if (taos_errno(res) != 0) {
|
||||||
printf("failed to insert schema-less data, reason: %s\n", taos_errstr(res));
|
printf("failed to insert schema-less data, reason: %s\n", taos_errstr(res));
|
||||||
|
|
|
@ -52,7 +52,7 @@ void insertData(TAOS *taos) {
|
||||||
checkErrorCode(stmt, code, "failed to execute taos_stmt_prepare");
|
checkErrorCode(stmt, code, "failed to execute taos_stmt_prepare");
|
||||||
// bind table name and tags
|
// bind table name and tags
|
||||||
TAOS_BIND tags[2];
|
TAOS_BIND tags[2];
|
||||||
char *location = "Beijing.Chaoyang";
|
char *location = "California.SanFrancisco";
|
||||||
int groupId = 2;
|
int groupId = 2;
|
||||||
tags[0].buffer_type = TSDB_DATA_TYPE_BINARY;
|
tags[0].buffer_type = TSDB_DATA_TYPE_BINARY;
|
||||||
tags[0].buffer_length = strlen(location);
|
tags[0].buffer_length = strlen(location);
|
||||||
|
|
|
@ -139,5 +139,5 @@ int main() {
|
||||||
|
|
||||||
// output:
|
// output:
|
||||||
// ts current voltage phase location groupid
|
// ts current voltage phase location groupid
|
||||||
// 1648432611249 10.300000 219 0.310000 Beijing.Chaoyang 2
|
// 1648432611249 10.300000 219 0.310000 California.SanFrancisco 2
|
||||||
// 1648432611749 12.600000 218 0.330000 Beijing.Chaoyang 2
|
// 1648432611749 12.600000 218 0.330000 California.SanFrancisco 2
|
|
@ -59,7 +59,7 @@ void insertData(TAOS *taos) {
|
||||||
checkErrorCode(stmt, code, "failed to execute taos_stmt_prepare");
|
checkErrorCode(stmt, code, "failed to execute taos_stmt_prepare");
|
||||||
// bind table name and tags
|
// bind table name and tags
|
||||||
TAOS_BIND tags[2];
|
TAOS_BIND tags[2];
|
||||||
char* location = "Beijing.Chaoyang";
|
char* location = "California.SanFrancisco";
|
||||||
int groupId = 2;
|
int groupId = 2;
|
||||||
tags[0].buffer_type = TSDB_DATA_TYPE_BINARY;
|
tags[0].buffer_type = TSDB_DATA_TYPE_BINARY;
|
||||||
tags[0].buffer_length = strlen(location);
|
tags[0].buffer_length = strlen(location);
|
||||||
|
|
|
@ -28,14 +28,14 @@ int main() {
|
||||||
executeSQL(taos, "CREATE DATABASE test");
|
executeSQL(taos, "CREATE DATABASE test");
|
||||||
executeSQL(taos, "USE test");
|
executeSQL(taos, "USE test");
|
||||||
char *lines[] = {
|
char *lines[] = {
|
||||||
"meters.current 1648432611249 10.3 location=Beijing.Chaoyang groupid=2",
|
"meters.current 1648432611249 10.3 location=California.SanFrancisco groupid=2",
|
||||||
"meters.current 1648432611250 12.6 location=Beijing.Chaoyang groupid=2",
|
"meters.current 1648432611250 12.6 location=California.SanFrancisco groupid=2",
|
||||||
"meters.current 1648432611249 10.8 location=Beijing.Haidian groupid=3",
|
"meters.current 1648432611249 10.8 location=California.LosAngeles groupid=3",
|
||||||
"meters.current 1648432611250 11.3 location=Beijing.Haidian groupid=3",
|
"meters.current 1648432611250 11.3 location=California.LosAngeles groupid=3",
|
||||||
"meters.voltage 1648432611249 219 location=Beijing.Chaoyang groupid=2",
|
"meters.voltage 1648432611249 219 location=California.SanFrancisco groupid=2",
|
||||||
"meters.voltage 1648432611250 218 location=Beijing.Chaoyang groupid=2",
|
"meters.voltage 1648432611250 218 location=California.SanFrancisco groupid=2",
|
||||||
"meters.voltage 1648432611249 221 location=Beijing.Haidian groupid=3",
|
"meters.voltage 1648432611249 221 location=California.LosAngeles groupid=3",
|
||||||
"meters.voltage 1648432611250 217 location=Beijing.Haidian groupid=3",
|
"meters.voltage 1648432611250 217 location=California.LosAngeles groupid=3",
|
||||||
};
|
};
|
||||||
TAOS_RES *res = taos_schemaless_insert(taos, lines, 8, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
|
TAOS_RES *res = taos_schemaless_insert(taos, lines, 8, TSDB_SML_TELNET_PROTOCOL, TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
|
||||||
if (taos_errno(res) != 0) {
|
if (taos_errno(res) != 0) {
|
||||||
|
|
|
@ -9,10 +9,10 @@ namespace TDengineExample
|
||||||
IntPtr conn = GetConnection();
|
IntPtr conn = GetConnection();
|
||||||
PrepareDatabase(conn);
|
PrepareDatabase(conn);
|
||||||
string[] lines = {
|
string[] lines = {
|
||||||
"meters,location=Beijing.Haidian,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249",
|
"meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249",
|
||||||
"meters,location=Beijing.Haidian,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611250",
|
"meters,location=California.LosAngeles,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611250",
|
||||||
"meters,location=Beijing.Haidian,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249",
|
"meters,location=California.LosAngeles,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249",
|
||||||
"meters,location=Beijing.Haidian,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611250"
|
"meters,location=California.LosAngeles,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611250"
|
||||||
};
|
};
|
||||||
IntPtr res = TDengine.SchemalessInsert(conn, lines, lines.Length, (int)TDengineSchemalessProtocol.TSDB_SML_LINE_PROTOCOL, (int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
IntPtr res = TDengine.SchemalessInsert(conn, lines, lines.Length, (int)TDengineSchemalessProtocol.TSDB_SML_LINE_PROTOCOL, (int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_MILLI_SECONDS);
|
||||||
if (TDengine.ErrorNo(res) != 0)
|
if (TDengine.ErrorNo(res) != 0)
|
||||||
|
|
|
@ -8,10 +8,10 @@ namespace TDengineExample
|
||||||
{
|
{
|
||||||
IntPtr conn = GetConnection();
|
IntPtr conn = GetConnection();
|
||||||
PrepareDatabase(conn);
|
PrepareDatabase(conn);
|
||||||
string[] lines = { "[{\"metric\": \"meters.current\", \"timestamp\": 1648432611249, \"value\": 10.3, \"tags\": {\"location\": \"Beijing.Chaoyang\", \"groupid\": 2}}," +
|
string[] lines = { "[{\"metric\": \"meters.current\", \"timestamp\": 1648432611249, \"value\": 10.3, \"tags\": {\"location\": \"California.SanFrancisco\", \"groupid\": 2}}," +
|
||||||
" {\"metric\": \"meters.voltage\", \"timestamp\": 1648432611249, \"value\": 219, \"tags\": {\"location\": \"Beijing.Haidian\", \"groupid\": 1}}, " +
|
" {\"metric\": \"meters.voltage\", \"timestamp\": 1648432611249, \"value\": 219, \"tags\": {\"location\": \"California.LosAngeles\", \"groupid\": 1}}, " +
|
||||||
"{\"metric\": \"meters.current\", \"timestamp\": 1648432611250, \"value\": 12.6, \"tags\": {\"location\": \"Beijing.Chaoyang\", \"groupid\": 2}}," +
|
"{\"metric\": \"meters.current\", \"timestamp\": 1648432611250, \"value\": 12.6, \"tags\": {\"location\": \"California.SanFrancisco\", \"groupid\": 2}}," +
|
||||||
" {\"metric\": \"meters.voltage\", \"timestamp\": 1648432611250, \"value\": 221, \"tags\": {\"location\": \"Beijing.Haidian\", \"groupid\": 1}}]"
|
" {\"metric\": \"meters.voltage\", \"timestamp\": 1648432611250, \"value\": 221, \"tags\": {\"location\": \"California.LosAngeles\", \"groupid\": 1}}]"
|
||||||
};
|
};
|
||||||
|
|
||||||
IntPtr res = TDengine.SchemalessInsert(conn, lines, 1, (int)TDengineSchemalessProtocol.TSDB_SML_JSON_PROTOCOL, (int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
|
IntPtr res = TDengine.SchemalessInsert(conn, lines, 1, (int)TDengineSchemalessProtocol.TSDB_SML_JSON_PROTOCOL, (int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
|
||||||
|
|
|
@ -9,14 +9,14 @@ namespace TDengineExample
|
||||||
IntPtr conn = GetConnection();
|
IntPtr conn = GetConnection();
|
||||||
PrepareDatabase(conn);
|
PrepareDatabase(conn);
|
||||||
string[] lines = {
|
string[] lines = {
|
||||||
"meters.current 1648432611249 10.3 location=Beijing.Chaoyang groupid=2",
|
"meters.current 1648432611249 10.3 location=California.SanFrancisco groupid=2",
|
||||||
"meters.current 1648432611250 12.6 location=Beijing.Chaoyang groupid=2",
|
"meters.current 1648432611250 12.6 location=California.SanFrancisco groupid=2",
|
||||||
"meters.current 1648432611249 10.8 location=Beijing.Haidian groupid=3",
|
"meters.current 1648432611249 10.8 location=California.LosAngeles groupid=3",
|
||||||
"meters.current 1648432611250 11.3 location=Beijing.Haidian groupid=3",
|
"meters.current 1648432611250 11.3 location=California.LosAngeles groupid=3",
|
||||||
"meters.voltage 1648432611249 219 location=Beijing.Chaoyang groupid=2",
|
"meters.voltage 1648432611249 219 location=California.SanFrancisco groupid=2",
|
||||||
"meters.voltage 1648432611250 218 location=Beijing.Chaoyang groupid=2",
|
"meters.voltage 1648432611250 218 location=California.SanFrancisco groupid=2",
|
||||||
"meters.voltage 1648432611249 221 location=Beijing.Haidian groupid=3",
|
"meters.voltage 1648432611249 221 location=California.LosAngeles groupid=3",
|
||||||
"meters.voltage 1648432611250 217 location=Beijing.Haidian groupid=3",
|
"meters.voltage 1648432611250 217 location=California.LosAngeles groupid=3",
|
||||||
};
|
};
|
||||||
IntPtr res = TDengine.SchemalessInsert(conn, lines, lines.Length, (int)TDengineSchemalessProtocol.TSDB_SML_TELNET_PROTOCOL, (int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
|
IntPtr res = TDengine.SchemalessInsert(conn, lines, lines.Length, (int)TDengineSchemalessProtocol.TSDB_SML_TELNET_PROTOCOL, (int)TDengineSchemalessPrecision.TSDB_SML_TIMESTAMP_NOT_CONFIGURED);
|
||||||
if (TDengine.ErrorNo(res) != 0)
|
if (TDengine.ErrorNo(res) != 0)
|
||||||
|
|
|
@ -158,5 +158,5 @@ namespace TDengineExample
|
||||||
// Connect to TDengine success
|
// Connect to TDengine success
|
||||||
// fieldCount=6
|
// fieldCount=6
|
||||||
// ts current voltage phase location groupid
|
// ts current voltage phase location groupid
|
||||||
// 1648432611249 10.3 219 0.31 Beijing.Chaoyang 2
|
// 1648432611249 10.3 219 0.31 California.SanFrancisco 2
|
||||||
// 1648432611749 12.6 218 0.33 Beijing.Chaoyang 2
|
// 1648432611749 12.6 218 0.33 California.SanFrancisco 2
|
|
@ -15,10 +15,10 @@ namespace TDengineExample
|
||||||
CheckRes(conn, res, "failed to change database");
|
CheckRes(conn, res, "failed to change database");
|
||||||
res = TDengine.Query(conn, "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)");
|
res = TDengine.Query(conn, "CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)");
|
||||||
CheckRes(conn, res, "failed to create stable");
|
CheckRes(conn, res, "failed to create stable");
|
||||||
var sql = "INSERT INTO d1001 USING meters TAGS(Beijing.Chaoyang, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000) " +
|
var sql = "INSERT INTO d1001 USING meters TAGS(California.SanFrancisco, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000) " +
|
||||||
"d1002 USING power.meters TAGS(Beijing.Chaoyang, 3) VALUES('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000) " +
|
"d1002 USING power.meters TAGS(California.SanFrancisco, 3) VALUES('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000) " +
|
||||||
"d1003 USING power.meters TAGS(Beijing.Haidian, 2) VALUES('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000)('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000) " +
|
"d1003 USING power.meters TAGS(California.LosAngeles, 2) VALUES('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000)('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000) " +
|
||||||
"d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000)('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)";
|
"d1004 USING power.meters TAGS(California.LosAngeles, 3) VALUES('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000)('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)";
|
||||||
res = TDengine.Query(conn, sql);
|
res = TDengine.Query(conn, sql);
|
||||||
CheckRes(conn, res, "failed to insert data");
|
CheckRes(conn, res, "failed to insert data");
|
||||||
int affectedRows = TDengine.AffectRows(res);
|
int affectedRows = TDengine.AffectRows(res);
|
||||||
|
|
|
@ -21,7 +21,7 @@ namespace TDengineExample
|
||||||
CheckStmtRes(res, "failed to prepare stmt");
|
CheckStmtRes(res, "failed to prepare stmt");
|
||||||
|
|
||||||
// 2. bind table name and tags
|
// 2. bind table name and tags
|
||||||
TAOS_BIND[] tags = new TAOS_BIND[2] { TaosBind.BindBinary("Beijing.Chaoyang"), TaosBind.BindInt(2) };
|
TAOS_BIND[] tags = new TAOS_BIND[2] { TaosBind.BindBinary("California.SanFrancisco"), TaosBind.BindInt(2) };
|
||||||
res = TDengine.StmtSetTbnameTags(stmt, "d1001", tags);
|
res = TDengine.StmtSetTbnameTags(stmt, "d1001", tags);
|
||||||
CheckStmtRes(res, "failed to bind table name and tags");
|
CheckStmtRes(res, "failed to bind table name and tags");
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,10 @@ func main() {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
prepareDatabase(conn)
|
prepareDatabase(conn)
|
||||||
|
|
||||||
payload := `[{"metric": "meters.current", "timestamp": 1648432611249, "value": 10.3, "tags": {"location": "Beijing.Chaoyang", "groupid": 2}},
|
payload := `[{"metric": "meters.current", "timestamp": 1648432611249, "value": 10.3, "tags": {"location": "California.SanFrancisco", "groupid": 2}},
|
||||||
{"metric": "meters.voltage", "timestamp": 1648432611249, "value": 219, "tags": {"location": "Beijing.Haidian", "groupid": 1}},
|
{"metric": "meters.voltage", "timestamp": 1648432611249, "value": 219, "tags": {"location": "California.LosAngeles", "groupid": 1}},
|
||||||
{"metric": "meters.current", "timestamp": 1648432611250, "value": 12.6, "tags": {"location": "Beijing.Chaoyang", "groupid": 2}},
|
{"metric": "meters.current", "timestamp": 1648432611250, "value": 12.6, "tags": {"location": "California.SanFrancisco", "groupid": 2}},
|
||||||
{"metric": "meters.voltage", "timestamp": 1648432611250, "value": 221, "tags": {"location": "Beijing.Haidian", "groupid": 1}}]`
|
{"metric": "meters.voltage", "timestamp": 1648432611250, "value": 221, "tags": {"location": "California.LosAngeles", "groupid": 1}}]`
|
||||||
|
|
||||||
err = conn.OpenTSDBInsertJsonPayload(payload)
|
err = conn.OpenTSDBInsertJsonPayload(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -25,10 +25,10 @@ func main() {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
prepareDatabase(conn)
|
prepareDatabase(conn)
|
||||||
var lines = []string{
|
var lines = []string{
|
||||||
"meters,location=Beijing.Haidian,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249",
|
"meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249",
|
||||||
"meters,location=Beijing.Haidian,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611250",
|
"meters,location=California.LosAngeles,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611250",
|
||||||
"meters,location=Beijing.Haidian,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249",
|
"meters,location=California.LosAngeles,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249",
|
||||||
"meters,location=Beijing.Haidian,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611250",
|
"meters,location=California.LosAngeles,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611250",
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.InfluxDBInsertLines(lines, "ms")
|
err = conn.InfluxDBInsertLines(lines, "ms")
|
||||||
|
|
|
@ -19,10 +19,10 @@ func createStable(taos *sql.DB) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func insertData(taos *sql.DB) {
|
func insertData(taos *sql.DB) {
|
||||||
sql := `INSERT INTO power.d1001 USING power.meters TAGS(Beijing.Chaoyang, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
|
sql := `INSERT INTO power.d1001 USING power.meters TAGS(California.SanFrancisco, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
|
||||||
power.d1002 USING power.meters TAGS(Beijing.Chaoyang, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
|
power.d1002 USING power.meters TAGS(California.SanFrancisco, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
|
||||||
power.d1003 USING power.meters TAGS(Beijing.Haidian, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
|
power.d1003 USING power.meters TAGS(California.LosAngeles, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
|
||||||
power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)`
|
power.d1004 USING power.meters TAGS(California.LosAngeles, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)`
|
||||||
result, err := taos.Exec(sql)
|
result, err := taos.Exec(sql)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("failed to insert, err:", err)
|
fmt.Println("failed to insert, err:", err)
|
||||||
|
|
|
@ -37,7 +37,7 @@ func main() {
|
||||||
checkErr(err, "failed to create prepare statement")
|
checkErr(err, "failed to create prepare statement")
|
||||||
|
|
||||||
// bind table name and tags
|
// bind table name and tags
|
||||||
tagParams := param.NewParam(2).AddBinary([]byte("Beijing.Chaoyang")).AddInt(2)
|
tagParams := param.NewParam(2).AddBinary([]byte("California.SanFrancisco")).AddInt(2)
|
||||||
err = stmt.SetTableNameWithTags("d1001", tagParams)
|
err = stmt.SetTableNameWithTags("d1001", tagParams)
|
||||||
checkErr(err, "failed to execute SetTableNameWithTags")
|
checkErr(err, "failed to execute SetTableNameWithTags")
|
||||||
|
|
||||||
|
|
|
@ -25,14 +25,14 @@ func main() {
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
prepareDatabase(conn)
|
prepareDatabase(conn)
|
||||||
var lines = []string{
|
var lines = []string{
|
||||||
"meters.current 1648432611249 10.3 location=Beijing.Chaoyang groupid=2",
|
"meters.current 1648432611249 10.3 location=California.SanFrancisco groupid=2",
|
||||||
"meters.current 1648432611250 12.6 location=Beijing.Chaoyang groupid=2",
|
"meters.current 1648432611250 12.6 location=California.SanFrancisco groupid=2",
|
||||||
"meters.current 1648432611249 10.8 location=Beijing.Haidian groupid=3",
|
"meters.current 1648432611249 10.8 location=California.LosAngeles groupid=3",
|
||||||
"meters.current 1648432611250 11.3 location=Beijing.Haidian groupid=3",
|
"meters.current 1648432611250 11.3 location=California.LosAngeles groupid=3",
|
||||||
"meters.voltage 1648432611249 219 location=Beijing.Chaoyang groupid=2",
|
"meters.voltage 1648432611249 219 location=California.SanFrancisco groupid=2",
|
||||||
"meters.voltage 1648432611250 218 location=Beijing.Chaoyang groupid=2",
|
"meters.voltage 1648432611250 218 location=California.SanFrancisco groupid=2",
|
||||||
"meters.voltage 1648432611249 221 location=Beijing.Haidian groupid=3",
|
"meters.voltage 1648432611249 221 location=California.LosAngeles groupid=3",
|
||||||
"meters.voltage 1648432611250 217 location=Beijing.Haidian groupid=3",
|
"meters.voltage 1648432611250 217 location=California.LosAngeles groupid=3",
|
||||||
}
|
}
|
||||||
|
|
||||||
err = conn.OpenTSDBInsertTelnetLines(lines)
|
err = conn.OpenTSDBInsertTelnetLines(lines)
|
||||||
|
|
|
@ -23,10 +23,10 @@ public class JSONProtocolExample {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getJSONData() {
|
private static String getJSONData() {
|
||||||
return "[{\"metric\": \"meters.current\", \"timestamp\": 1648432611249, \"value\": 10.3, \"tags\": {\"location\": \"Beijing.Chaoyang\", \"groupid\": 2}}," +
|
return "[{\"metric\": \"meters.current\", \"timestamp\": 1648432611249, \"value\": 10.3, \"tags\": {\"location\": \"California.SanFrancisco\", \"groupid\": 2}}," +
|
||||||
" {\"metric\": \"meters.voltage\", \"timestamp\": 1648432611249, \"value\": 219, \"tags\": {\"location\": \"Beijing.Haidian\", \"groupid\": 1}}, " +
|
" {\"metric\": \"meters.voltage\", \"timestamp\": 1648432611249, \"value\": 219, \"tags\": {\"location\": \"California.LosAngeles\", \"groupid\": 1}}, " +
|
||||||
"{\"metric\": \"meters.current\", \"timestamp\": 1648432611250, \"value\": 12.6, \"tags\": {\"location\": \"Beijing.Chaoyang\", \"groupid\": 2}}," +
|
"{\"metric\": \"meters.current\", \"timestamp\": 1648432611250, \"value\": 12.6, \"tags\": {\"location\": \"California.SanFrancisco\", \"groupid\": 2}}," +
|
||||||
" {\"metric\": \"meters.voltage\", \"timestamp\": 1648432611250, \"value\": 221, \"tags\": {\"location\": \"Beijing.Haidian\", \"groupid\": 1}}]";
|
" {\"metric\": \"meters.voltage\", \"timestamp\": 1648432611250, \"value\": 221, \"tags\": {\"location\": \"California.LosAngeles\", \"groupid\": 1}}]";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws SQLException {
|
public static void main(String[] args) throws SQLException {
|
||||||
|
|
|
@ -12,11 +12,11 @@ import java.sql.Statement;
|
||||||
public class LineProtocolExample {
|
public class LineProtocolExample {
|
||||||
// format: measurement,tag_set field_set timestamp
|
// format: measurement,tag_set field_set timestamp
|
||||||
private static String[] lines = {
|
private static String[] lines = {
|
||||||
"meters,location=Beijing.Haidian,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249000", // micro
|
"meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249000", // micro
|
||||||
// seconds
|
// seconds
|
||||||
"meters,location=Beijing.Haidian,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611249500",
|
"meters,location=California.LosAngeles,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611249500",
|
||||||
"meters,location=Beijing.Haidian,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249300",
|
"meters,location=California.LosAngeles,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249300",
|
||||||
"meters,location=Beijing.Haidian,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611249800",
|
"meters,location=California.LosAngeles,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611249800",
|
||||||
};
|
};
|
||||||
|
|
||||||
private static Connection getConnection() throws SQLException {
|
private static Connection getConnection() throws SQLException {
|
||||||
|
|
|
@ -16,28 +16,28 @@ public class RestInsertExample {
|
||||||
|
|
||||||
private static List<String> getRawData() {
|
private static List<String> getRawData() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
"d1001,2018-10-03 14:38:05.000,10.30000,219,0.31000,Beijing.Chaoyang,2",
|
"d1001,2018-10-03 14:38:05.000,10.30000,219,0.31000,California.SanFrancisco,2",
|
||||||
"d1001,2018-10-03 14:38:15.000,12.60000,218,0.33000,Beijing.Chaoyang,2",
|
"d1001,2018-10-03 14:38:15.000,12.60000,218,0.33000,California.SanFrancisco,2",
|
||||||
"d1001,2018-10-03 14:38:16.800,12.30000,221,0.31000,Beijing.Chaoyang,2",
|
"d1001,2018-10-03 14:38:16.800,12.30000,221,0.31000,California.SanFrancisco,2",
|
||||||
"d1002,2018-10-03 14:38:16.650,10.30000,218,0.25000,Beijing.Chaoyang,3",
|
"d1002,2018-10-03 14:38:16.650,10.30000,218,0.25000,California.SanFrancisco,3",
|
||||||
"d1003,2018-10-03 14:38:05.500,11.80000,221,0.28000,Beijing.Haidian,2",
|
"d1003,2018-10-03 14:38:05.500,11.80000,221,0.28000,California.LosAngeles,2",
|
||||||
"d1003,2018-10-03 14:38:16.600,13.40000,223,0.29000,Beijing.Haidian,2",
|
"d1003,2018-10-03 14:38:16.600,13.40000,223,0.29000,California.LosAngeles,2",
|
||||||
"d1004,2018-10-03 14:38:05.000,10.80000,223,0.29000,Beijing.Haidian,3",
|
"d1004,2018-10-03 14:38:05.000,10.80000,223,0.29000,California.LosAngeles,3",
|
||||||
"d1004,2018-10-03 14:38:06.500,11.50000,221,0.35000,Beijing.Haidian,3"
|
"d1004,2018-10-03 14:38:06.500,11.50000,221,0.35000,California.LosAngeles,3"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The generated SQL is:
|
* The generated SQL is:
|
||||||
* INSERT INTO power.d1001 USING power.meters TAGS(Beijing.Chaoyang, 2) VALUES('2018-10-03 14:38:05.000',10.30000,219,0.31000)
|
* INSERT INTO power.d1001 USING power.meters TAGS(California.SanFrancisco, 2) VALUES('2018-10-03 14:38:05.000',10.30000,219,0.31000)
|
||||||
* power.d1001 USING power.meters TAGS(Beijing.Chaoyang, 2) VALUES('2018-10-03 14:38:15.000',12.60000,218,0.33000)
|
* power.d1001 USING power.meters TAGS(California.SanFrancisco, 2) VALUES('2018-10-03 14:38:15.000',12.60000,218,0.33000)
|
||||||
* power.d1001 USING power.meters TAGS(Beijing.Chaoyang, 2) VALUES('2018-10-03 14:38:16.800',12.30000,221,0.31000)
|
* power.d1001 USING power.meters TAGS(California.SanFrancisco, 2) VALUES('2018-10-03 14:38:16.800',12.30000,221,0.31000)
|
||||||
* power.d1002 USING power.meters TAGS(Beijing.Chaoyang, 3) VALUES('2018-10-03 14:38:16.650',10.30000,218,0.25000)
|
* power.d1002 USING power.meters TAGS(California.SanFrancisco, 3) VALUES('2018-10-03 14:38:16.650',10.30000,218,0.25000)
|
||||||
* power.d1003 USING power.meters TAGS(Beijing.Haidian, 2) VALUES('2018-10-03 14:38:05.500',11.80000,221,0.28000)
|
* power.d1003 USING power.meters TAGS(California.LosAngeles, 2) VALUES('2018-10-03 14:38:05.500',11.80000,221,0.28000)
|
||||||
* power.d1003 USING power.meters TAGS(Beijing.Haidian, 2) VALUES('2018-10-03 14:38:16.600',13.40000,223,0.29000)
|
* power.d1003 USING power.meters TAGS(California.LosAngeles, 2) VALUES('2018-10-03 14:38:16.600',13.40000,223,0.29000)
|
||||||
* power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES('2018-10-03 14:38:05.000',10.80000,223,0.29000)
|
* power.d1004 USING power.meters TAGS(California.LosAngeles, 3) VALUES('2018-10-03 14:38:05.000',10.80000,223,0.29000)
|
||||||
* power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES('2018-10-03 14:38:06.500',11.50000,221,0.35000)
|
* power.d1004 USING power.meters TAGS(California.LosAngeles, 3) VALUES('2018-10-03 14:38:06.500',11.50000,221,0.35000)
|
||||||
*/
|
*/
|
||||||
private static String getSQL() {
|
private static String getSQL() {
|
||||||
StringBuilder sb = new StringBuilder("INSERT INTO ");
|
StringBuilder sb = new StringBuilder("INSERT INTO ");
|
||||||
|
|
|
@ -51,5 +51,5 @@ public class RestQueryExample {
|
||||||
|
|
||||||
// possible output:
|
// possible output:
|
||||||
// avg(voltage) location
|
// avg(voltage) location
|
||||||
// 222.0 Beijing.Haidian
|
// 222.0 California.LosAngeles
|
||||||
// 219.0 Beijing.Chaoyang
|
// 219.0 California.SanFrancisco
|
||||||
|
|
|
@ -30,14 +30,14 @@ public class StmtInsertExample {
|
||||||
|
|
||||||
private static List<String> getRawData() {
|
private static List<String> getRawData() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(
|
||||||
"d1001,2018-10-03 14:38:05.000,10.30000,219,0.31000,Beijing.Chaoyang,2",
|
"d1001,2018-10-03 14:38:05.000,10.30000,219,0.31000,California.SanFrancisco,2",
|
||||||
"d1001,2018-10-03 14:38:15.000,12.60000,218,0.33000,Beijing.Chaoyang,2",
|
"d1001,2018-10-03 14:38:15.000,12.60000,218,0.33000,California.SanFrancisco,2",
|
||||||
"d1001,2018-10-03 14:38:16.800,12.30000,221,0.31000,Beijing.Chaoyang,2",
|
"d1001,2018-10-03 14:38:16.800,12.30000,221,0.31000,California.SanFrancisco,2",
|
||||||
"d1002,2018-10-03 14:38:16.650,10.30000,218,0.25000,Beijing.Chaoyang,3",
|
"d1002,2018-10-03 14:38:16.650,10.30000,218,0.25000,California.SanFrancisco,3",
|
||||||
"d1003,2018-10-03 14:38:05.500,11.80000,221,0.28000,Beijing.Haidian,2",
|
"d1003,2018-10-03 14:38:05.500,11.80000,221,0.28000,California.LosAngeles,2",
|
||||||
"d1003,2018-10-03 14:38:16.600,13.40000,223,0.29000,Beijing.Haidian,2",
|
"d1003,2018-10-03 14:38:16.600,13.40000,223,0.29000,California.LosAngeles,2",
|
||||||
"d1004,2018-10-03 14:38:05.000,10.80000,223,0.29000,Beijing.Haidian,3",
|
"d1004,2018-10-03 14:38:05.000,10.80000,223,0.29000,California.LosAngeles,3",
|
||||||
"d1004,2018-10-03 14:38:06.500,11.50000,221,0.35000,Beijing.Haidian,3"
|
"d1004,2018-10-03 14:38:06.500,11.50000,221,0.35000,California.LosAngeles,3"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,14 @@ import java.sql.Statement;
|
||||||
|
|
||||||
public class TelnetLineProtocolExample {
|
public class TelnetLineProtocolExample {
|
||||||
// format: <metric> <timestamp> <value> <tagk_1>=<tagv_1>[ <tagk_n>=<tagv_n>]
|
// format: <metric> <timestamp> <value> <tagk_1>=<tagv_1>[ <tagk_n>=<tagv_n>]
|
||||||
private static String[] lines = { "meters.current 1648432611249 10.3 location=Beijing.Chaoyang groupid=2",
|
private static String[] lines = { "meters.current 1648432611249 10.3 location=California.SanFrancisco groupid=2",
|
||||||
"meters.current 1648432611250 12.6 location=Beijing.Chaoyang groupid=2",
|
"meters.current 1648432611250 12.6 location=California.SanFrancisco groupid=2",
|
||||||
"meters.current 1648432611249 10.8 location=Beijing.Haidian groupid=3",
|
"meters.current 1648432611249 10.8 location=California.LosAngeles groupid=3",
|
||||||
"meters.current 1648432611250 11.3 location=Beijing.Haidian groupid=3",
|
"meters.current 1648432611250 11.3 location=California.LosAngeles groupid=3",
|
||||||
"meters.voltage 1648432611249 219 location=Beijing.Chaoyang groupid=2",
|
"meters.voltage 1648432611249 219 location=California.SanFrancisco groupid=2",
|
||||||
"meters.voltage 1648432611250 218 location=Beijing.Chaoyang groupid=2",
|
"meters.voltage 1648432611250 218 location=California.SanFrancisco groupid=2",
|
||||||
"meters.voltage 1648432611249 221 location=Beijing.Haidian groupid=3",
|
"meters.voltage 1648432611249 221 location=California.LosAngeles groupid=3",
|
||||||
"meters.voltage 1648432611250 217 location=Beijing.Haidian groupid=3",
|
"meters.voltage 1648432611250 217 location=California.LosAngeles groupid=3",
|
||||||
};
|
};
|
||||||
|
|
||||||
private static Connection getConnection() throws SQLException {
|
private static Connection getConnection() throws SQLException {
|
||||||
|
|
|
@ -23,16 +23,16 @@ public class TestAll {
|
||||||
String jdbcUrl = "jdbc:TAOS://localhost:6030?user=root&password=taosdata";
|
String jdbcUrl = "jdbc:TAOS://localhost:6030?user=root&password=taosdata";
|
||||||
try (Connection conn = DriverManager.getConnection(jdbcUrl)) {
|
try (Connection conn = DriverManager.getConnection(jdbcUrl)) {
|
||||||
try (Statement stmt = conn.createStatement()) {
|
try (Statement stmt = conn.createStatement()) {
|
||||||
String sql = "INSERT INTO power.d1001 USING power.meters TAGS(Beijing.Chaoyang, 2) VALUES('2018-10-03 14:38:05.000',10.30000,219,0.31000)\n" +
|
String sql = "INSERT INTO power.d1001 USING power.meters TAGS(California.SanFrancisco, 2) VALUES('2018-10-03 14:38:05.000',10.30000,219,0.31000)\n" +
|
||||||
" power.d1001 USING power.meters TAGS(Beijing.Chaoyang, 2) VALUES('2018-10-03 15:38:15.000',12.60000,218,0.33000)\n" +
|
" power.d1001 USING power.meters TAGS(California.SanFrancisco, 2) VALUES('2018-10-03 15:38:15.000',12.60000,218,0.33000)\n" +
|
||||||
" power.d1001 USING power.meters TAGS(Beijing.Chaoyang, 2) VALUES('2018-10-03 15:38:16.800',12.30000,221,0.31000)\n" +
|
" power.d1001 USING power.meters TAGS(California.SanFrancisco, 2) VALUES('2018-10-03 15:38:16.800',12.30000,221,0.31000)\n" +
|
||||||
" power.d1002 USING power.meters TAGS(Beijing.Chaoyang, 3) VALUES('2018-10-03 15:38:16.650',10.30000,218,0.25000)\n" +
|
" power.d1002 USING power.meters TAGS(California.SanFrancisco, 3) VALUES('2018-10-03 15:38:16.650',10.30000,218,0.25000)\n" +
|
||||||
" power.d1003 USING power.meters TAGS(Beijing.Haidian, 2) VALUES('2018-10-03 15:38:05.500',11.80000,221,0.28000)\n" +
|
" power.d1003 USING power.meters TAGS(California.LosAngeles, 2) VALUES('2018-10-03 15:38:05.500',11.80000,221,0.28000)\n" +
|
||||||
" power.d1003 USING power.meters TAGS(Beijing.Haidian, 2) VALUES('2018-10-03 15:38:16.600',13.40000,223,0.29000)\n" +
|
" power.d1003 USING power.meters TAGS(California.LosAngeles, 2) VALUES('2018-10-03 15:38:16.600',13.40000,223,0.29000)\n" +
|
||||||
" power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES('2018-10-03 15:38:05.000',10.80000,223,0.29000)\n" +
|
" power.d1004 USING power.meters TAGS(California.LosAngeles, 3) VALUES('2018-10-03 15:38:05.000',10.80000,223,0.29000)\n" +
|
||||||
" power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES('2018-10-03 15:38:06.000',10.80000,223,0.29000)\n" +
|
" power.d1004 USING power.meters TAGS(California.LosAngeles, 3) VALUES('2018-10-03 15:38:06.000',10.80000,223,0.29000)\n" +
|
||||||
" power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES('2018-10-03 15:38:07.000',10.80000,223,0.29000)\n" +
|
" power.d1004 USING power.meters TAGS(California.LosAngeles, 3) VALUES('2018-10-03 15:38:07.000',10.80000,223,0.29000)\n" +
|
||||||
" power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES('2018-10-03 15:38:08.500',11.50000,221,0.35000)";
|
" power.d1004 USING power.meters TAGS(California.LosAngeles, 3) VALUES('2018-10-03 15:38:08.500',11.50000,221,0.35000)";
|
||||||
|
|
||||||
stmt.execute(sql);
|
stmt.execute(sql);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,10 +13,10 @@ function createDatabase() {
|
||||||
|
|
||||||
function insertData() {
|
function insertData() {
|
||||||
const lines = [
|
const lines = [
|
||||||
"meters,location=Beijing.Haidian,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249",
|
"meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249",
|
||||||
"meters,location=Beijing.Haidian,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611250",
|
"meters,location=California.LosAngeles,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611250",
|
||||||
"meters,location=Beijing.Haidian,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249",
|
"meters,location=California.LosAngeles,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249",
|
||||||
"meters,location=Beijing.Haidian,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611250",
|
"meters,location=California.LosAngeles,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611250",
|
||||||
];
|
];
|
||||||
cursor.schemalessInsert(
|
cursor.schemalessInsert(
|
||||||
lines,
|
lines,
|
||||||
|
|
|
@ -11,10 +11,10 @@ try {
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"CREATE STABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)"
|
"CREATE STABLE meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)"
|
||||||
);
|
);
|
||||||
var sql = `INSERT INTO power.d1001 USING power.meters TAGS(Beijing.Chaoyang, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
|
var sql = `INSERT INTO power.d1001 USING power.meters TAGS(California.SanFrancisco, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
|
||||||
power.d1002 USING power.meters TAGS(Beijing.Chaoyang, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
|
power.d1002 USING power.meters TAGS(California.SanFrancisco, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
|
||||||
power.d1003 USING power.meters TAGS(Beijing.Haidian, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
|
power.d1003 USING power.meters TAGS(California.LosAngeles, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
|
||||||
power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)`;
|
power.d1004 USING power.meters TAGS(California.LosAngeles, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)`;
|
||||||
cursor.execute(sql);
|
cursor.execute(sql);
|
||||||
} finally {
|
} finally {
|
||||||
cursor.close();
|
cursor.close();
|
||||||
|
|
|
@ -25,7 +25,7 @@ function insertData() {
|
||||||
|
|
||||||
// bind table name and tags
|
// bind table name and tags
|
||||||
let tagBind = new taos.TaosBind(2);
|
let tagBind = new taos.TaosBind(2);
|
||||||
tagBind.bindBinary("Beijing.Chaoyang");
|
tagBind.bindBinary("California.SanFrancisco");
|
||||||
tagBind.bindInt(2);
|
tagBind.bindInt(2);
|
||||||
cursor.stmtSetTbnameTags("d1001", tagBind.getBind());
|
cursor.stmtSetTbnameTags("d1001", tagBind.getBind());
|
||||||
|
|
||||||
|
|
|
@ -17,25 +17,25 @@ function insertData() {
|
||||||
metric: "meters.current",
|
metric: "meters.current",
|
||||||
timestamp: 1648432611249,
|
timestamp: 1648432611249,
|
||||||
value: 10.3,
|
value: 10.3,
|
||||||
tags: { location: "Beijing.Chaoyang", groupid: 2 },
|
tags: { location: "California.SanFrancisco", groupid: 2 },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
metric: "meters.voltage",
|
metric: "meters.voltage",
|
||||||
timestamp: 1648432611249,
|
timestamp: 1648432611249,
|
||||||
value: 219,
|
value: 219,
|
||||||
tags: { location: "Beijing.Haidian", groupid: 1 },
|
tags: { location: "California.LosAngeles", groupid: 1 },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
metric: "meters.current",
|
metric: "meters.current",
|
||||||
timestamp: 1648432611250,
|
timestamp: 1648432611250,
|
||||||
value: 12.6,
|
value: 12.6,
|
||||||
tags: { location: "Beijing.Chaoyang", groupid: 2 },
|
tags: { location: "California.SanFrancisco", groupid: 2 },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
metric: "meters.voltage",
|
metric: "meters.voltage",
|
||||||
timestamp: 1648432611250,
|
timestamp: 1648432611250,
|
||||||
value: 221,
|
value: 221,
|
||||||
tags: { location: "Beijing.Haidian", groupid: 1 },
|
tags: { location: "California.LosAngeles", groupid: 1 },
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -13,14 +13,14 @@ function createDatabase() {
|
||||||
|
|
||||||
function insertData() {
|
function insertData() {
|
||||||
const lines = [
|
const lines = [
|
||||||
"meters.current 1648432611249 10.3 location=Beijing.Chaoyang groupid=2",
|
"meters.current 1648432611249 10.3 location=California.SanFrancisco groupid=2",
|
||||||
"meters.current 1648432611250 12.6 location=Beijing.Chaoyang groupid=2",
|
"meters.current 1648432611250 12.6 location=California.SanFrancisco groupid=2",
|
||||||
"meters.current 1648432611249 10.8 location=Beijing.Haidian groupid=3",
|
"meters.current 1648432611249 10.8 location=California.LosAngeles groupid=3",
|
||||||
"meters.current 1648432611250 11.3 location=Beijing.Haidian groupid=3",
|
"meters.current 1648432611250 11.3 location=California.LosAngeles groupid=3",
|
||||||
"meters.voltage 1648432611249 219 location=Beijing.Chaoyang groupid=2",
|
"meters.voltage 1648432611249 219 location=California.SanFrancisco groupid=2",
|
||||||
"meters.voltage 1648432611250 218 location=Beijing.Chaoyang groupid=2",
|
"meters.voltage 1648432611250 218 location=California.SanFrancisco groupid=2",
|
||||||
"meters.voltage 1648432611249 221 location=Beijing.Haidian groupid=3",
|
"meters.voltage 1648432611249 221 location=California.LosAngeles groupid=3",
|
||||||
"meters.voltage 1648432611250 217 location=Beijing.Haidian groupid=3",
|
"meters.voltage 1648432611250 217 location=California.LosAngeles groupid=3",
|
||||||
];
|
];
|
||||||
cursor.schemalessInsert(
|
cursor.schemalessInsert(
|
||||||
lines,
|
lines,
|
||||||
|
|
|
@ -24,7 +24,7 @@ function insertData() {
|
||||||
|
|
||||||
// bind table name and tags
|
// bind table name and tags
|
||||||
let tagBind = new taos.TaosBind(2);
|
let tagBind = new taos.TaosBind(2);
|
||||||
tagBind.bindBinary("Beijing.Chaoyang");
|
tagBind.bindBinary("California.SanFrancisco");
|
||||||
tagBind.bindInt(2);
|
tagBind.bindInt(2);
|
||||||
cursor.stmtSetTbnameTags("d1001", tagBind.getBind());
|
cursor.stmtSetTbnameTags("d1001", tagBind.getBind());
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use TDengine\Connection;
|
||||||
use TDengine\Exception\TDengineException;
|
use TDengine\Exception\TDengineException;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 实例化
|
// instantiate
|
||||||
$host = 'localhost';
|
$host = 'localhost';
|
||||||
$port = 6030;
|
$port = 6030;
|
||||||
$username = 'root';
|
$username = 'root';
|
||||||
|
@ -12,9 +12,9 @@ try {
|
||||||
$dbname = null;
|
$dbname = null;
|
||||||
$connection = new Connection($host, $port, $username, $password, $dbname);
|
$connection = new Connection($host, $port, $username, $password, $dbname);
|
||||||
|
|
||||||
// 连接
|
// connect
|
||||||
$connection->connect();
|
$connection->connect();
|
||||||
} catch (TDengineException $e) {
|
} catch (TDengineException $e) {
|
||||||
// 连接失败捕获异常
|
// throw exception
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use TDengine\Connection;
|
||||||
use TDengine\Exception\TDengineException;
|
use TDengine\Exception\TDengineException;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 实例化
|
// instantiate
|
||||||
$host = 'localhost';
|
$host = 'localhost';
|
||||||
$port = 6030;
|
$port = 6030;
|
||||||
$username = 'root';
|
$username = 'root';
|
||||||
|
@ -12,22 +12,22 @@ try {
|
||||||
$dbname = 'power';
|
$dbname = 'power';
|
||||||
$connection = new Connection($host, $port, $username, $password, $dbname);
|
$connection = new Connection($host, $port, $username, $password, $dbname);
|
||||||
|
|
||||||
// 连接
|
// connect
|
||||||
$connection->connect();
|
$connection->connect();
|
||||||
|
|
||||||
// 插入
|
// insert
|
||||||
$connection->query('CREATE DATABASE if not exists power');
|
$connection->query('CREATE DATABASE if not exists power');
|
||||||
$connection->query('CREATE STABLE if not exists meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)');
|
$connection->query('CREATE STABLE if not exists meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)');
|
||||||
$resource = $connection->query(<<<'SQL'
|
$resource = $connection->query(<<<'SQL'
|
||||||
INSERT INTO power.d1001 USING power.meters TAGS(Beijing.Chaoyang, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
|
INSERT INTO power.d1001 USING power.meters TAGS(California.SanFrancisco, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
|
||||||
power.d1002 USING power.meters TAGS(Beijing.Chaoyang, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
|
power.d1002 USING power.meters TAGS(California.SanFrancisco, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
|
||||||
power.d1003 USING power.meters TAGS(Beijing.Haidian, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
|
power.d1003 USING power.meters TAGS(California.LosAngeles, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
|
||||||
power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)
|
power.d1004 USING power.meters TAGS(California.LosAngeles, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)
|
||||||
SQL);
|
SQL);
|
||||||
|
|
||||||
// 影响行数
|
// get affected rows
|
||||||
var_dump($resource->affectedRows());
|
var_dump($resource->affectedRows());
|
||||||
} catch (TDengineException $e) {
|
} catch (TDengineException $e) {
|
||||||
// 捕获异常
|
// throw exception
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use TDengine\Connection;
|
||||||
use TDengine\Exception\TDengineException;
|
use TDengine\Exception\TDengineException;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 实例化
|
// instantiate
|
||||||
$host = 'localhost';
|
$host = 'localhost';
|
||||||
$port = 6030;
|
$port = 6030;
|
||||||
$username = 'root';
|
$username = 'root';
|
||||||
|
@ -12,18 +12,18 @@ try {
|
||||||
$dbname = 'power';
|
$dbname = 'power';
|
||||||
$connection = new Connection($host, $port, $username, $password, $dbname);
|
$connection = new Connection($host, $port, $username, $password, $dbname);
|
||||||
|
|
||||||
// 连接
|
// connect
|
||||||
$connection->connect();
|
$connection->connect();
|
||||||
|
|
||||||
// 插入
|
// insert
|
||||||
$connection->query('CREATE DATABASE if not exists power');
|
$connection->query('CREATE DATABASE if not exists power');
|
||||||
$connection->query('CREATE STABLE if not exists meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)');
|
$connection->query('CREATE STABLE if not exists meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)');
|
||||||
$stmt = $connection->prepare('INSERT INTO ? USING meters TAGS(?, ?) VALUES(?, ?, ?, ?)');
|
$stmt = $connection->prepare('INSERT INTO ? USING meters TAGS(?, ?) VALUES(?, ?, ?, ?)');
|
||||||
|
|
||||||
// 设置表名和标签
|
// set table name and tags
|
||||||
$stmt->setTableNameTags('d1001', [
|
$stmt->setTableNameTags('d1001', [
|
||||||
// 支持格式同参数绑定
|
// 支持格式同参数绑定
|
||||||
[TDengine\TSDB_DATA_TYPE_BINARY, 'Beijing.Chaoyang'],
|
[TDengine\TSDB_DATA_TYPE_BINARY, 'California.SanFrancisco'],
|
||||||
[TDengine\TSDB_DATA_TYPE_INT, 2],
|
[TDengine\TSDB_DATA_TYPE_INT, 2],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
@ -41,9 +41,9 @@ try {
|
||||||
]);
|
]);
|
||||||
$resource = $stmt->execute();
|
$resource = $stmt->execute();
|
||||||
|
|
||||||
// 影响行数
|
// get affected rows
|
||||||
var_dump($resource->affectedRows());
|
var_dump($resource->affectedRows());
|
||||||
} catch (TDengineException $e) {
|
} catch (TDengineException $e) {
|
||||||
// 捕获异常
|
// throw exception
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use TDengine\Connection;
|
||||||
use TDengine\Exception\TDengineException;
|
use TDengine\Exception\TDengineException;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 实例化
|
// instantiate
|
||||||
$host = 'localhost';
|
$host = 'localhost';
|
||||||
$port = 6030;
|
$port = 6030;
|
||||||
$username = 'root';
|
$username = 'root';
|
||||||
|
@ -12,12 +12,12 @@ try {
|
||||||
$dbname = 'power';
|
$dbname = 'power';
|
||||||
$connection = new Connection($host, $port, $username, $password, $dbname);
|
$connection = new Connection($host, $port, $username, $password, $dbname);
|
||||||
|
|
||||||
// 连接
|
// connect
|
||||||
$connection->connect();
|
$connection->connect();
|
||||||
|
|
||||||
$resource = $connection->query('SELECT ts, current FROM meters LIMIT 2');
|
$resource = $connection->query('SELECT ts, current FROM meters LIMIT 2');
|
||||||
var_dump($resource->fetch());
|
var_dump($resource->fetch());
|
||||||
} catch (TDengineException $e) {
|
} catch (TDengineException $e) {
|
||||||
// 捕获异常
|
// throw exception
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,14 +2,14 @@ import taos
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
# note: lines have already been sorted by table name
|
# note: lines have already been sorted by table name
|
||||||
lines = [('d1001', '2018-10-03 14:38:05.000', 10.30000, 219, 0.31000, 'Beijing.Chaoyang', 2),
|
lines = [('d1001', '2018-10-03 14:38:05.000', 10.30000, 219, 0.31000, 'California.SanFrancisco', 2),
|
||||||
('d1001', '2018-10-03 14:38:15.000', 12.60000, 218, 0.33000, 'Beijing.Chaoyang', 2),
|
('d1001', '2018-10-03 14:38:15.000', 12.60000, 218, 0.33000, 'California.SanFrancisco', 2),
|
||||||
('d1001', '2018-10-03 14:38:16.800', 12.30000, 221, 0.31000, 'Beijing.Chaoyang', 2),
|
('d1001', '2018-10-03 14:38:16.800', 12.30000, 221, 0.31000, 'California.SanFrancisco', 2),
|
||||||
('d1002', '2018-10-03 14:38:16.650', 10.30000, 218, 0.25000, 'Beijing.Chaoyang', 3),
|
('d1002', '2018-10-03 14:38:16.650', 10.30000, 218, 0.25000, 'California.SanFrancisco', 3),
|
||||||
('d1003', '2018-10-03 14:38:05.500', 11.80000, 221, 0.28000, 'Beijing.Haidian', 2),
|
('d1003', '2018-10-03 14:38:05.500', 11.80000, 221, 0.28000, 'California.LosAngeles', 2),
|
||||||
('d1003', '2018-10-03 14:38:16.600', 13.40000, 223, 0.29000, 'Beijing.Haidian', 2),
|
('d1003', '2018-10-03 14:38:16.600', 13.40000, 223, 0.29000, 'California.LosAngeles', 2),
|
||||||
('d1004', '2018-10-03 14:38:05.000', 10.80000, 223, 0.29000, 'Beijing.Haidian', 3),
|
('d1004', '2018-10-03 14:38:05.000', 10.80000, 223, 0.29000, 'California.LosAngeles', 3),
|
||||||
('d1004', '2018-10-03 14:38:06.500', 11.50000, 221, 0.35000, 'Beijing.Haidian', 3)]
|
('d1004', '2018-10-03 14:38:06.500', 11.50000, 221, 0.35000, 'California.LosAngeles', 3)]
|
||||||
|
|
||||||
|
|
||||||
def get_ts(ts: str):
|
def get_ts(ts: str):
|
||||||
|
|
|
@ -16,10 +16,10 @@ cursor.execute("CREATE DATABASE power")
|
||||||
cursor.execute("CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)")
|
cursor.execute("CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)")
|
||||||
|
|
||||||
# insert data
|
# insert data
|
||||||
cursor.execute("""INSERT INTO power.d1001 USING power.meters TAGS(Beijing.Chaoyang, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
|
cursor.execute("""INSERT INTO power.d1001 USING power.meters TAGS(California.SanFrancisco, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
|
||||||
power.d1002 USING power.meters TAGS(Beijing.Chaoyang, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
|
power.d1002 USING power.meters TAGS(California.SanFrancisco, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
|
||||||
power.d1003 USING power.meters TAGS(Beijing.Haidian, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
|
power.d1003 USING power.meters TAGS(California.LosAngeles, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
|
||||||
power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)""")
|
power.d1004 USING power.meters TAGS(California.LosAngeles, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)""")
|
||||||
print("inserted row count:", cursor.rowcount)
|
print("inserted row count:", cursor.rowcount)
|
||||||
|
|
||||||
# query data
|
# query data
|
||||||
|
|
|
@ -3,12 +3,12 @@ import json
|
||||||
import taos
|
import taos
|
||||||
from taos import SmlProtocol, SmlPrecision
|
from taos import SmlProtocol, SmlPrecision
|
||||||
|
|
||||||
lines = [{"metric": "meters.current", "timestamp": 1648432611249, "value": 10.3, "tags": {"location": "Beijing.Chaoyang", "groupid": 2}},
|
lines = [{"metric": "meters.current", "timestamp": 1648432611249, "value": 10.3, "tags": {"location": "California.SanFrancisco", "groupid": 2}},
|
||||||
{"metric": "meters.voltage", "timestamp": 1648432611249, "value": 219,
|
{"metric": "meters.voltage", "timestamp": 1648432611249, "value": 219,
|
||||||
"tags": {"location": "Beijing.Haidian", "groupid": 1}},
|
"tags": {"location": "California.LosAngeles", "groupid": 1}},
|
||||||
{"metric": "meters.current", "timestamp": 1648432611250, "value": 12.6,
|
{"metric": "meters.current", "timestamp": 1648432611250, "value": 12.6,
|
||||||
"tags": {"location": "Beijing.Chaoyang", "groupid": 2}},
|
"tags": {"location": "California.SanFrancisco", "groupid": 2}},
|
||||||
{"metric": "meters.voltage", "timestamp": 1648432611250, "value": 221, "tags": {"location": "Beijing.Haidian", "groupid": 1}}]
|
{"metric": "meters.voltage", "timestamp": 1648432611250, "value": 221, "tags": {"location": "California.LosAngeles", "groupid": 1}}]
|
||||||
|
|
||||||
|
|
||||||
def get_connection():
|
def get_connection():
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import taos
|
import taos
|
||||||
from taos import SmlProtocol, SmlPrecision
|
from taos import SmlProtocol, SmlPrecision
|
||||||
|
|
||||||
lines = ["meters,location=Beijing.Haidian,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249000",
|
lines = ["meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249000",
|
||||||
"meters,location=Beijing.Haidian,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611249500",
|
"meters,location=California.LosAngeles,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611249500",
|
||||||
"meters,location=Beijing.Haidian,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249300",
|
"meters,location=California.LosAngeles,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249300",
|
||||||
"meters,location=Beijing.Haidian,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611249800",
|
"meters,location=California.LosAngeles,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611249800",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,10 +3,10 @@ from datetime import datetime
|
||||||
|
|
||||||
# ANCHOR: bind_batch
|
# ANCHOR: bind_batch
|
||||||
table_tags = {
|
table_tags = {
|
||||||
"d1001": ('Beijing.Chaoyang', 2),
|
"d1001": ('California.SanFrancisco', 2),
|
||||||
"d1002": ('Beijing.Chaoyang', 3),
|
"d1002": ('California.SanFrancisco', 3),
|
||||||
"d1003": ('Beijing.Haidian', 2),
|
"d1003": ('California.LosAngeles', 2),
|
||||||
"d1004": ('Beijing.Haidian', 3)
|
"d1004": ('California.LosAngeles', 3)
|
||||||
}
|
}
|
||||||
|
|
||||||
table_values = {
|
table_values = {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
import taos
|
import taos
|
||||||
|
|
||||||
lines = ["d1001,2018-10-03 14:38:05.000,10.30000,219,0.31000,Beijing.Chaoyang,2",
|
lines = ["d1001,2018-10-03 14:38:05.000,10.30000,219,0.31000,California.SanFrancisco,2",
|
||||||
"d1004,2018-10-03 14:38:05.000,10.80000,223,0.29000,Beijing.Haidian,3",
|
"d1004,2018-10-03 14:38:05.000,10.80000,223,0.29000,California.LosAngeles,3",
|
||||||
"d1003,2018-10-03 14:38:05.500,11.80000,221,0.28000,Beijing.Haidian,2",
|
"d1003,2018-10-03 14:38:05.500,11.80000,221,0.28000,California.LosAngeles,2",
|
||||||
"d1004,2018-10-03 14:38:06.500,11.50000,221,0.35000,Beijing.Haidian,3",
|
"d1004,2018-10-03 14:38:06.500,11.50000,221,0.35000,California.LosAngeles,3",
|
||||||
"d1002,2018-10-03 14:38:16.650,10.30000,218,0.25000,Beijing.Chaoyang,3",
|
"d1002,2018-10-03 14:38:16.650,10.30000,218,0.25000,California.SanFrancisco,3",
|
||||||
"d1001,2018-10-03 14:38:15.000,12.60000,218,0.33000,Beijing.Chaoyang,2",
|
"d1001,2018-10-03 14:38:15.000,12.60000,218,0.33000,California.SanFrancisco,2",
|
||||||
"d1001,2018-10-03 14:38:16.800,12.30000,221,0.31000,Beijing.Chaoyang,2",
|
"d1001,2018-10-03 14:38:16.800,12.30000,221,0.31000,California.SanFrancisco,2",
|
||||||
"d1003,2018-10-03 14:38:16.600,13.40000,223,0.29000,Beijing.Haidian,2"]
|
"d1003,2018-10-03 14:38:16.600,13.40000,223,0.29000,California.LosAngeles,2"]
|
||||||
|
|
||||||
|
|
||||||
def get_connection() -> taos.TaosConnection:
|
def get_connection() -> taos.TaosConnection:
|
||||||
|
@ -25,10 +25,10 @@ def create_stable(conn: taos.TaosConnection):
|
||||||
|
|
||||||
|
|
||||||
# The generated SQL is:
|
# The generated SQL is:
|
||||||
# INSERT INTO d1001 USING meters TAGS(Beijing.Chaoyang, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
|
# INSERT INTO d1001 USING meters TAGS(California.SanFrancisco, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
|
||||||
# d1002 USING meters TAGS(Beijing.Chaoyang, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
|
# d1002 USING meters TAGS(California.SanFrancisco, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
|
||||||
# d1003 USING meters TAGS(Beijing.Haidian, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
|
# d1003 USING meters TAGS(California.LosAngeles, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
|
||||||
# d1004 USING meters TAGS(Beijing.Haidian, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)
|
# d1004 USING meters TAGS(California.LosAngeles, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)
|
||||||
|
|
||||||
def get_sql():
|
def get_sql():
|
||||||
global lines
|
global lines
|
||||||
|
|
|
@ -14,8 +14,8 @@ def query_api_demo(conn: taos.TaosConnection):
|
||||||
# field count: 7
|
# field count: 7
|
||||||
# meta of files[1]: {name: ts, type: 9, bytes: 8}
|
# meta of files[1]: {name: ts, type: 9, bytes: 8}
|
||||||
# ======================Iterate on result=========================
|
# ======================Iterate on result=========================
|
||||||
# ('d1001', datetime.datetime(2018, 10, 3, 14, 38, 5), 10.300000190734863, 219, 0.3100000023841858, 'Beijing.Chaoyang', 2)
|
# ('d1001', datetime.datetime(2018, 10, 3, 14, 38, 5), 10.300000190734863, 219, 0.3100000023841858, 'California.SanFrancisco', 2)
|
||||||
# ('d1001', datetime.datetime(2018, 10, 3, 14, 38, 15), 12.600000381469727, 218, 0.33000001311302185, 'Beijing.Chaoyang', 2)
|
# ('d1001', datetime.datetime(2018, 10, 3, 14, 38, 15), 12.600000381469727, 218, 0.33000001311302185, 'California.SanFrancisco', 2)
|
||||||
# ANCHOR_END: iter
|
# ANCHOR_END: iter
|
||||||
|
|
||||||
# ANCHOR: fetch_all
|
# ANCHOR: fetch_all
|
||||||
|
|
|
@ -2,14 +2,14 @@ import taos
|
||||||
from taos import SmlProtocol, SmlPrecision
|
from taos import SmlProtocol, SmlPrecision
|
||||||
|
|
||||||
# format: <metric> <timestamp> <value> <tagk_1>=<tagv_1>[ <tagk_n>=<tagv_n>]
|
# format: <metric> <timestamp> <value> <tagk_1>=<tagv_1>[ <tagk_n>=<tagv_n>]
|
||||||
lines = ["meters.current 1648432611249 10.3 location=Beijing.Chaoyang groupid=2",
|
lines = ["meters.current 1648432611249 10.3 location=California.SanFrancisco groupid=2",
|
||||||
"meters.current 1648432611250 12.6 location=Beijing.Chaoyang groupid=2",
|
"meters.current 1648432611250 12.6 location=California.SanFrancisco groupid=2",
|
||||||
"meters.current 1648432611249 10.8 location=Beijing.Haidian groupid=3",
|
"meters.current 1648432611249 10.8 location=California.LosAngeles groupid=3",
|
||||||
"meters.current 1648432611250 11.3 location=Beijing.Haidian groupid=3",
|
"meters.current 1648432611250 11.3 location=California.LosAngeles groupid=3",
|
||||||
"meters.voltage 1648432611249 219 location=Beijing.Chaoyang groupid=2",
|
"meters.voltage 1648432611249 219 location=California.SanFrancisco groupid=2",
|
||||||
"meters.voltage 1648432611250 218 location=Beijing.Chaoyang groupid=2",
|
"meters.voltage 1648432611250 218 location=California.SanFrancisco groupid=2",
|
||||||
"meters.voltage 1648432611249 221 location=Beijing.Haidian groupid=3",
|
"meters.voltage 1648432611249 221 location=California.LosAngeles groupid=3",
|
||||||
"meters.voltage 1648432611250 217 location=Beijing.Haidian groupid=3",
|
"meters.voltage 1648432611250 217 location=California.LosAngeles groupid=3",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ async fn main() -> Result<(), Error> {
|
||||||
stmt.set_tbname_tags(
|
stmt.set_tbname_tags(
|
||||||
"d1001",
|
"d1001",
|
||||||
[
|
[
|
||||||
Field::Binary(BString::from("Beijing.Chaoyang")),
|
Field::Binary(BString::from("California.SanFrancisco")),
|
||||||
Field::Int(2),
|
Field::Int(2),
|
||||||
],
|
],
|
||||||
)?;
|
)?;
|
||||||
|
|
|
@ -5,10 +5,10 @@ async fn main() -> Result<(), Error> {
|
||||||
let taos = TaosCfg::default().connect().expect("fail to connect");
|
let taos = TaosCfg::default().connect().expect("fail to connect");
|
||||||
taos.create_database("power").await?;
|
taos.create_database("power").await?;
|
||||||
taos.exec("CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)").await?;
|
taos.exec("CREATE STABLE power.meters (ts TIMESTAMP, current FLOAT, voltage INT, phase FLOAT) TAGS (location BINARY(64), groupId INT)").await?;
|
||||||
let sql = "INSERT INTO power.d1001 USING power.meters TAGS(Beijing.Chaoyang, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
|
let sql = "INSERT INTO power.d1001 USING power.meters TAGS(California.SanFrancisco, 2) VALUES ('2018-10-03 14:38:05.000', 10.30000, 219, 0.31000) ('2018-10-03 14:38:15.000', 12.60000, 218, 0.33000) ('2018-10-03 14:38:16.800', 12.30000, 221, 0.31000)
|
||||||
power.d1002 USING power.meters TAGS(Beijing.Chaoyang, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
|
power.d1002 USING power.meters TAGS(California.SanFrancisco, 3) VALUES ('2018-10-03 14:38:16.650', 10.30000, 218, 0.25000)
|
||||||
power.d1003 USING power.meters TAGS(Beijing.Haidian, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
|
power.d1003 USING power.meters TAGS(California.LosAngeles, 2) VALUES ('2018-10-03 14:38:05.500', 11.80000, 221, 0.28000) ('2018-10-03 14:38:16.600', 13.40000, 223, 0.29000)
|
||||||
power.d1004 USING power.meters TAGS(Beijing.Haidian, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)";
|
power.d1004 USING power.meters TAGS(California.LosAngeles, 3) VALUES ('2018-10-03 14:38:05.000', 10.80000, 223, 0.29000) ('2018-10-03 14:38:06.500', 11.50000, 221, 0.35000)";
|
||||||
let result = taos.query(sql).await?;
|
let result = taos.query(sql).await?;
|
||||||
println!("{:?}", result);
|
println!("{:?}", result);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -5,10 +5,10 @@ fn main() {
|
||||||
let taos = TaosCfg::default().connect().expect("fail to connect");
|
let taos = TaosCfg::default().connect().expect("fail to connect");
|
||||||
taos.raw_query("CREATE DATABASE test").unwrap();
|
taos.raw_query("CREATE DATABASE test").unwrap();
|
||||||
taos.raw_query("USE test").unwrap();
|
taos.raw_query("USE test").unwrap();
|
||||||
let lines = ["meters,location=Beijing.Haidian,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249",
|
let lines = ["meters,location=California.LosAngeles,groupid=2 current=11.8,voltage=221,phase=0.28 1648432611249",
|
||||||
"meters,location=Beijing.Haidian,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611250",
|
"meters,location=California.LosAngeles,groupid=2 current=13.4,voltage=223,phase=0.29 1648432611250",
|
||||||
"meters,location=Beijing.Haidian,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249",
|
"meters,location=California.LosAngeles,groupid=3 current=10.8,voltage=223,phase=0.29 1648432611249",
|
||||||
"meters,location=Beijing.Haidian,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611250"];
|
"meters,location=California.LosAngeles,groupid=3 current=11.3,voltage=221,phase=0.35 1648432611250"];
|
||||||
let affected_rows = taos
|
let affected_rows = taos
|
||||||
.schemaless_insert(
|
.schemaless_insert(
|
||||||
&lines,
|
&lines,
|
||||||
|
|
|
@ -6,10 +6,10 @@ fn main() {
|
||||||
taos.raw_query("CREATE DATABASE test").unwrap();
|
taos.raw_query("CREATE DATABASE test").unwrap();
|
||||||
taos.raw_query("USE test").unwrap();
|
taos.raw_query("USE test").unwrap();
|
||||||
let lines = [
|
let lines = [
|
||||||
r#"[{"metric": "meters.current", "timestamp": 1648432611249, "value": 10.3, "tags": {"location": "Beijing.Chaoyang", "groupid": 2}},
|
r#"[{"metric": "meters.current", "timestamp": 1648432611249, "value": 10.3, "tags": {"location": "California.SanFrancisco", "groupid": 2}},
|
||||||
{"metric": "meters.voltage", "timestamp": 1648432611249, "value": 219, "tags": {"location": "Beijing.Haidian", "groupid": 1}},
|
{"metric": "meters.voltage", "timestamp": 1648432611249, "value": 219, "tags": {"location": "California.LosAngeles", "groupid": 1}},
|
||||||
{"metric": "meters.current", "timestamp": 1648432611250, "value": 12.6, "tags": {"location": "Beijing.Chaoyang", "groupid": 2}},
|
{"metric": "meters.current", "timestamp": 1648432611250, "value": 12.6, "tags": {"location": "California.SanFrancisco", "groupid": 2}},
|
||||||
{"metric": "meters.voltage", "timestamp": 1648432611250, "value": 221, "tags": {"location": "Beijing.Haidian", "groupid": 1}}]"#,
|
{"metric": "meters.voltage", "timestamp": 1648432611250, "value": 221, "tags": {"location": "California.LosAngeles", "groupid": 1}}]"#,
|
||||||
];
|
];
|
||||||
|
|
||||||
let affected_rows = taos
|
let affected_rows = taos
|
||||||
|
|
|
@ -6,14 +6,14 @@ fn main() {
|
||||||
taos.raw_query("CREATE DATABASE test").unwrap();
|
taos.raw_query("CREATE DATABASE test").unwrap();
|
||||||
taos.raw_query("USE test").unwrap();
|
taos.raw_query("USE test").unwrap();
|
||||||
let lines = [
|
let lines = [
|
||||||
"meters.current 1648432611249 10.3 location=Beijing.Chaoyang groupid=2",
|
"meters.current 1648432611249 10.3 location=California.SanFrancisco groupid=2",
|
||||||
"meters.current 1648432611250 12.6 location=Beijing.Chaoyang groupid=2",
|
"meters.current 1648432611250 12.6 location=California.SanFrancisco groupid=2",
|
||||||
"meters.current 1648432611249 10.8 location=Beijing.Haidian groupid=3",
|
"meters.current 1648432611249 10.8 location=California.LosAngeles groupid=3",
|
||||||
"meters.current 1648432611250 11.3 location=Beijing.Haidian groupid=3",
|
"meters.current 1648432611250 11.3 location=California.LosAngeles groupid=3",
|
||||||
"meters.voltage 1648432611249 219 location=Beijing.Chaoyang groupid=2",
|
"meters.voltage 1648432611249 219 location=California.SanFrancisco groupid=2",
|
||||||
"meters.voltage 1648432611250 218 location=Beijing.Chaoyang groupid=2",
|
"meters.voltage 1648432611250 218 location=California.SanFrancisco groupid=2",
|
||||||
"meters.voltage 1648432611249 221 location=Beijing.Haidian groupid=3",
|
"meters.voltage 1648432611249 221 location=California.LosAngeles groupid=3",
|
||||||
"meters.voltage 1648432611250 217 location=Beijing.Haidian groupid=3",
|
"meters.voltage 1648432611250 217 location=California.LosAngeles groupid=3",
|
||||||
];
|
];
|
||||||
let affected_rows = taos
|
let affected_rows = taos
|
||||||
.schemaless_insert(
|
.schemaless_insert(
|
||||||
|
|
Loading…
Reference in New Issue