|
8 | 8 | import java.io.IOException;
|
9 | 9 | import java.util.*;
|
10 | 10 |
|
| 11 | +import static com.xxdb.data.Entity.DATA_TYPE.DT_IOTANY; |
| 12 | +import static com.xxdb.data.Entity.DATA_TYPE.DT_VOID; |
| 13 | + |
11 | 14 | public class BasicIotAnyVectorTest {
|
12 | 15 | private DBConnection conn;
|
13 | 16 | static ResourceBundle bundle = ResourceBundle.getBundle("com/xxdb/setup/settings");
|
@@ -42,7 +45,7 @@ public void test_BasicIotAnyVector_Scalar() throws IOException {
|
42 | 45 | Scalar[] scalar = new Scalar[]{bbyte,bshort,bint,blong,bbool,bfloat,bdouble,bsting};
|
43 | 46 | BasicIotAnyVector BIV = new BasicIotAnyVector(scalar);
|
44 | 47 | Assert.assertEquals(Entity.DATA_CATEGORY.MIXED,BIV.getDataCategory());
|
45 |
| - Assert.assertEquals(Entity.DATA_TYPE.DT_IOTANY,BIV.getDataType()); |
| 48 | + Assert.assertEquals(DT_IOTANY,BIV.getDataType()); |
46 | 49 | Assert.assertEquals(8,BIV.rows());
|
47 | 50 | Assert.assertEquals(1,BIV.columns());
|
48 | 51 | System.out.println(BIV.getString());
|
@@ -159,20 +162,20 @@ public void test_BasicIotAnyVector_2() throws IOException {
|
159 | 162 | "sortColumns=[`deviceId, `location, `timestamp],\n" +
|
160 | 163 | "latestKeyCache=true;\n" +
|
161 | 164 | "pt = loadTable(\"dfs://testIOT222\",\"pt\");\n" +
|
162 |
| - "t = table([1] as deviceId,\n" + |
163 |
| - " [now()] as timestamp,\n" + |
164 |
| - " [`loc1] as location,\n" + |
165 |
| - " [long(233)] as value)\n" + |
| 165 | + "t = table([1,2] as deviceId,\n" + |
| 166 | + " [now(),now()] as timestamp,\n" + |
| 167 | + " [`loc1`loc2] as location,\n" + |
| 168 | + " [long(233),string(234)] as value)\n" + |
166 | 169 | "pt.append!(t)";
|
167 | 170 | conn.run(script);
|
168 | 171 | BasicTable entity1 = (BasicTable)conn.run("select * from loadTable( \"dfs://testIOT222\", `pt) ;");
|
169 | 172 | System.out.println(entity1.getString());
|
170 | 173 | BasicIotAnyVector BIV = (BasicIotAnyVector)entity1.getColumn("value");
|
171 | 174 | Assert.assertEquals(Entity.DATA_CATEGORY.MIXED,BIV.getDataCategory());
|
172 |
| - Assert.assertEquals(Entity.DATA_TYPE.DT_IOTANY,BIV.getDataType()); |
173 |
| - Assert.assertEquals(1,BIV.rows()); |
| 175 | + Assert.assertEquals(DT_IOTANY,BIV.getDataType()); |
| 176 | + Assert.assertEquals(2,BIV.rows()); |
174 | 177 | Assert.assertEquals(1,BIV.columns());
|
175 |
| - Assert.assertEquals("[233]",BIV.getString()); |
| 178 | + Assert.assertEquals("[233,234]",BIV.getString()); |
176 | 179 | Assert.assertEquals("233",BIV.get(0).getString());
|
177 | 180 | Assert.assertEquals("233",BIV.getString(0));
|
178 | 181 | String re = null;
|
@@ -591,4 +594,106 @@ public void test_iotAnyVector_allDateType_upload_null() throws IOException {
|
591 | 594 | System.out.println(iotAnyTable.getString());
|
592 | 595 | Assert.assertEquals(0, iotAnyTable.rows());
|
593 | 596 | }
|
| 597 | + |
| 598 | + @Test |
| 599 | + public void test_iotAnyVector_allDateType_void() throws IOException { |
| 600 | + String script = "if(existsDatabase(\"dfs://testIOT\")) dropDatabase(\"dfs://testIOT\")\n" + |
| 601 | + " create database \"dfs://testIOT\" partitioned by VALUE(1..20),RANGE(2020.01.01 2022.01.01 2025.01.01), engine='IOTDB'\n" + |
| 602 | + " create table \"dfs://testIOT\".\"pt\"(\n" + |
| 603 | + " deviceId INT,\n" + |
| 604 | + " timestamp TIMESTAMP,\n" + |
| 605 | + " location SYMBOL,\n" + |
| 606 | + " value IOTANY,\n" + |
| 607 | + " )\n" + |
| 608 | + "partitioned by deviceId, timestamp,\n" + |
| 609 | + "sortColumns=[`deviceId, `location, `timestamp],\n" + |
| 610 | + "latestKeyCache=true;\n" + |
| 611 | + "pt = loadTable(\"dfs://testIOT\",\"pt\");\n" + |
| 612 | + "t=table([1] as deviceId, [now()] as timestamp, [`loc1] as location, [char('Q')] as value)\n" + |
| 613 | + "pt.append!(t)\n" + |
| 614 | + "flushTSDBCache()\n" + |
| 615 | + "t=table([2] as deviceId, [now()] as timestamp, [`loc1] as location, [short(233)] as value)\n" + |
| 616 | + "pt.append!(t)\n" + |
| 617 | + "flushTSDBCache()\n" + |
| 618 | + "t=table([3] as deviceId, [now()] as timestamp, [`loc1] as location, [int(-233)] as value)\n" + |
| 619 | + "pt.append!(t)\n" + |
| 620 | + "flushTSDBCache()\n" + |
| 621 | + "t=table([4] as deviceId, [now()] as timestamp, [`loc1] as location, [long(233121)] as value)\n" + |
| 622 | + "pt.append!(t)\n" + |
| 623 | + "flushTSDBCache()\n" + |
| 624 | + "t=table([5] as deviceId, [now()] as timestamp, [`loc1] as location, [true] as value)\n" + |
| 625 | + "pt.append!(t)\n" + |
| 626 | + "flushTSDBCache()\n" + |
| 627 | + "t=table([6] as deviceId, [now()] as timestamp, [`loc1] as location, [233.34f] as value)\n" + |
| 628 | + "pt.append!(t)\n" + |
| 629 | + "flushTSDBCache()\n" + |
| 630 | + "t=table([7] as deviceId, [now()] as timestamp, [`loc1] as location, [233.34] as value)\n" + |
| 631 | + "pt.append!(t)\n" + |
| 632 | + "flushTSDBCache()\n" + |
| 633 | + "t=table([8] as deviceId, [now()] as timestamp, [`loc1] as location, [`loc1] as value)\n" + |
| 634 | + "pt.append!(t)\n" + |
| 635 | + "flushTSDBCache()\n" + |
| 636 | + "t=table(12..14 as deviceId, [now(),2022.06.13 13:30:10.008,2020.06.13 13:30:10.008] as timestamp, [`loc1`loc2`loc3] as location, [symbol(`AAA`bbb`xxx)] as value)\n" + |
| 637 | + "pt.append!(t)\n" + |
| 638 | + "flushTSDBCache()\n" ; |
| 639 | + conn.run(script); |
| 640 | + BasicIotAnyVector entity1 = (BasicIotAnyVector)conn.run("exec value from loadTable( \"dfs://testIOT\", `pt) order by deviceId;"); |
| 641 | + Assert.assertEquals("['Q',233,-233,233121,true,233.33999634,233.34,loc1,AAA,bbb,xxx]", entity1.getString()); |
| 642 | + BasicIotAnyVector entity2 = (BasicIotAnyVector)conn.run("pt = exec value from loadTable( \"dfs://testIOT\", `pt) order by deviceId; subarray(pt,0:20)"); |
| 643 | + System.out.println(entity2.getString()); |
| 644 | + Assert.assertEquals("['Q',233,-233,233121,true,233.33999634,233.34,loc1,AAA,bbb,xxx,,,,,,,,,]",entity2.getString()); |
| 645 | + Assert.assertEquals("", entity2.getString(11)); |
| 646 | + Assert.assertEquals(DT_VOID, entity2.get(11).getDataType()); |
| 647 | + Assert.assertEquals("", entity2.get(11).getString()); |
| 648 | + Assert.assertEquals("", entity2.get(19).getString()); |
| 649 | + Map<String, Entity> map = new HashMap<>(); |
| 650 | + map.put("iotAny1", entity2); |
| 651 | + conn.upload(map); |
| 652 | + Entity entity3 = conn.run("iotAny1"); |
| 653 | + System.out.println(entity3.getString()); |
| 654 | + Assert.assertEquals("['Q',233,-233,233121,true,233.33999634,233.34,loc1,AAA,bbb,xxx,,,,,,,,,]",entity3.getString()); |
| 655 | + BasicIotAnyVector entity4= (BasicIotAnyVector)conn.run("pt = exec value from loadTable( \"dfs://testIOT\", `pt) order by deviceId; subarray(pt,11:20)"); |
| 656 | + System.out.println(entity4.getString()); |
| 657 | + Assert.assertEquals("[,,,,,,,,]",entity4.getString()); |
| 658 | + } |
| 659 | + |
| 660 | + @Test |
| 661 | + public void test_iotAnyVector_allDateType_void_1() throws IOException { |
| 662 | + String script = "if(existsDatabase(\"dfs://IOTDB\")) dropDatabase(\"dfs://IOTDB\")\n" + |
| 663 | + "create database \"dfs://IOTDB\" partitioned by HASH([SYMBOL,10]),VALUE([today()]),engine = \"IOTDB\";\n" + |
| 664 | + "create table \"dfs://IOTDB\".\"data\" (\n" + |
| 665 | + " Time TIMESTAMP,\n" + |
| 666 | + " systemID SYMBOL,\n" + |
| 667 | + " TagName SYMBOL,\n" + |
| 668 | + " Value IOTANY,\n" + |
| 669 | + ")\n" + |
| 670 | + "partitioned by systemID, Time,\n" + |
| 671 | + "sortColumns = [\"systemID\",\"TagName\",\"Time\"],\n" + |
| 672 | + "latestKeyCache = true\n" + |
| 673 | + "pt = loadTable(\"dfs://IOTDB\",\"data\")\n" + |
| 674 | + "Time = take(2024.01.01T00:00:00,2)\n" + |
| 675 | + "systemID = `0x001`0x002\n" + |
| 676 | + "TagName = `value1`value1\n" + |
| 677 | + "Value = [4,6]\n" + |
| 678 | + "t = table(Time,systemID,TagName,Value)\n" + |
| 679 | + "pt.append!(t)\n" + |
| 680 | + "Time = take(2024.01.01T00:00:00,1)\n" + |
| 681 | + "systemID = [`0x001]\n" + |
| 682 | + "TagName = [`value2]\n" + |
| 683 | + "Value = [true]\n" + |
| 684 | + "t = table(Time,systemID,TagName,Value)\n" + |
| 685 | + "pt.append!(t)\n" ; |
| 686 | + conn.run(script); |
| 687 | + BasicTable entity1 = (BasicTable)conn.run("select Value from pt pivot by Time,sysTemID,TagName;"); |
| 688 | + Assert.assertEquals("[true,]", entity1.getColumn(3).getString()); |
| 689 | + Assert.assertEquals("", entity1.getColumn(3).get(1).getString()); |
| 690 | + Assert.assertEquals(DT_IOTANY, entity1.getColumn(3).getDataType()); |
| 691 | + Assert.assertEquals(DT_VOID, entity1.getColumn(3).get(1).getDataType()); |
| 692 | + Map<String, Entity> map = new HashMap<>(); |
| 693 | + map.put("iotAny1", entity1); |
| 694 | + conn.upload(map); |
| 695 | + Entity entity3 = conn.run("iotAny1"); |
| 696 | + System.out.println(entity3.getString()); |
| 697 | + Assert.assertEquals(entity1.getString(),entity3.getString()); |
| 698 | + } |
594 | 699 | }
|
0 commit comments