|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Threading; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using Apache.IoTDB; |
| 6 | +using Apache.IoTDB.DataStructure; |
| 7 | + |
| 8 | +namespace Apache.IoTDB.UserCase |
| 9 | +{ |
| 10 | + class Program |
| 11 | + { |
| 12 | + static string host = "localhost"; |
| 13 | + static int port = 6667; |
| 14 | + static int pool_size = 2; |
| 15 | + |
| 16 | + |
| 17 | + static async Task OpenAndCloseSessionPool() |
| 18 | + { |
| 19 | + var session_pool = new SessionPool(host, port, pool_size); |
| 20 | + await session_pool.Open(false); |
| 21 | + if (session_pool.IsOpen()) |
| 22 | + { |
| 23 | + Console.WriteLine("SessionPool open success"); |
| 24 | + } |
| 25 | + else |
| 26 | + { |
| 27 | + Console.WriteLine("SessionPool open failed"); |
| 28 | + } |
| 29 | + await session_pool.Close(); |
| 30 | + } |
| 31 | + |
| 32 | + static async Task CreateTimeseries() |
| 33 | + { |
| 34 | + var session_pool = new SessionPool(host, port, pool_size); |
| 35 | + await session_pool.Open(false); |
| 36 | + |
| 37 | + await session_pool.DeleteStorageGroupAsync("root.ln.wf01.wt01"); |
| 38 | + var status = await session_pool.CreateTimeSeries("root.ln.wf01.wt01.status", TSDataType.BOOLEAN, TSEncoding.PLAIN, Compressor.SNAPPY); |
| 39 | + status = await session_pool.CreateTimeSeries("root.ln.wf01.wt01.temperature", TSDataType.DOUBLE, TSEncoding.PLAIN, Compressor.SNAPPY); |
| 40 | + status = await session_pool.CreateTimeSeries("root.ln.wf01.wt01.hardware", TSDataType.TEXT, TSEncoding.PLAIN, Compressor.SNAPPY); |
| 41 | + |
| 42 | + await session_pool.Close(); |
| 43 | + } |
| 44 | + |
| 45 | + static async Task InsertRecord() |
| 46 | + { |
| 47 | + var session_pool = new SessionPool(host, port, pool_size); |
| 48 | + await session_pool.Open(false); |
| 49 | + long timestamp = 1; |
| 50 | + var values = new List<object> { true, (double)1.1, "test" }; |
| 51 | + var measures = new List<string> { "status", "temperature", "hardware" }; |
| 52 | + var rowRecord = new RowRecord(timestamp, values, measures); |
| 53 | + var status = await session_pool.InsertRecordAsync("root.ln.wf01.wt01", rowRecord); |
| 54 | + |
| 55 | + await session_pool.Close(); |
| 56 | + } |
| 57 | + |
| 58 | + static async Task InsertTablet() |
| 59 | + { |
| 60 | + var session_pool = new SessionPool(host, port, pool_size); |
| 61 | + await session_pool.Open(false); |
| 62 | + var device_id = "root.ln.wf01.wt01"; |
| 63 | + var measurement_lst = new List<string> { "status", "temperature", "hardware" }; |
| 64 | + var value_lst = new List<List<object>> |
| 65 | + { |
| 66 | + new() {true, (double)1.1, "test"}, |
| 67 | + new() {false, (double)2.2, "test2"}, |
| 68 | + new() {true, (double)3.3, "test3"} |
| 69 | + }; |
| 70 | + var timestamp_lst = new List<long> { 1, 2, 3 }; |
| 71 | + var datatype_lst = new List<TSDataType> { TSDataType.BOOLEAN, TSDataType.DOUBLE, TSDataType.TEXT }; |
| 72 | + var tablet = new Tablet(device_id, measurement_lst, datatype_lst, value_lst, timestamp_lst); |
| 73 | + var status = await session_pool.InsertTabletAsync(tablet); |
| 74 | + await session_pool.Close(); |
| 75 | + } |
| 76 | + |
| 77 | + static async Task ExecuteQueryStatement() |
| 78 | + { |
| 79 | + var session_pool = new SessionPool(host, port, pool_size); |
| 80 | + await session_pool.Open(false); |
| 81 | + var res = await session_pool.ExecuteQueryStatementAsync("select * from root.ln.wf01.wt01"); |
| 82 | + res.ShowTableNames(); |
| 83 | + while (res.HasNext()) |
| 84 | + { |
| 85 | + Console.WriteLine(res.Next()); |
| 86 | + } |
| 87 | + await res.Close(); |
| 88 | + await session_pool.Close(); |
| 89 | + } |
| 90 | + |
| 91 | + static async Task Main(string[] args) |
| 92 | + { |
| 93 | + await OpenAndCloseSessionPool(); |
| 94 | + await CreateTimeseries(); |
| 95 | + await InsertRecord(); |
| 96 | + await InsertTablet(); |
| 97 | + await ExecuteQueryStatement(); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | +} |
| 102 | + |
0 commit comments