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