55using Apache . IoTDB . Data ;
66using Apache . IoTDB . DataStructure ;
77using ConsoleTableExt ;
8+ using System . Net . Sockets ;
89
910namespace Apache . IoTDB . Samples
1011{
@@ -39,11 +40,24 @@ public SessionPoolTest(string _host = "localhost")
3940
4041 public async Task Test ( )
4142 {
43+ await TestInsertOneRecord ( ) ;
4244
4345 await TestInsertAlignedRecord ( ) ;
4446
4547 await TestInsertAlignedRecords ( ) ;
4648
49+ await TestInsertAlignedStringRecords ( ) ;
50+
51+ await TestInsertAlignedStringRecordsOfOneDevice ( ) ;
52+
53+ await TestInsertStringRecord ( ) ;
54+
55+ await TestInsertAlignedStringRecord ( ) ;
56+
57+ await TestInsertStringRecords ( ) ;
58+
59+ await TestInsertStringRecordsOfOneDevice ( ) ;
60+
4761 await TestInsertAlignedRecordsOfOneDevice ( ) ;
4862
4963 await TestInsertAlignedTablet ( ) ;
@@ -66,18 +80,12 @@ public async Task Test()
6680
6781 await TestInsertTablets ( ) ;
6882
69- await TestAddAlignedMeasurements ( ) ;
70-
71- await TestAddUnalignedMeasurements ( ) ;
72-
7383 await TestSetAndUnsetSchemaTemplate ( ) ;
7484
7585 await TestCreateAlignedTimeseries ( ) ;
7686
7787 await TestCreateAndDropSchemaTemplate ( ) ;
7888
79- await TestDeleteNodeInTemplate ( ) ;
80-
8189 await TestGetTimeZone ( ) ;
8290
8391 await TestSetAndDeleteStorageGroup ( ) ;
@@ -96,12 +104,32 @@ public async Task Test()
96104
97105 await TestNonSql ( ) ;
98106
107+ await TestRawDataQuery ( ) ;
108+
109+ await TestLastDataQuery ( ) ;
99110
100111 await TestSqlQuery ( ) ;
101112
102113 await TestNonSqlBy_ADO ( ) ;
103114 }
104-
115+ public async Task TestInsertOneRecord ( )
116+ {
117+ var session_pool = new SessionPool ( host , port , 1 ) ;
118+ await session_pool . Open ( false ) ;
119+ if ( debug ) session_pool . OpenDebugMode ( ) ;
120+ await session_pool . DeleteStorageGroupAsync ( test_group_name ) ;
121+ var status = await session_pool . CreateTimeSeries (
122+ string . Format ( "{0}.{1}.{2}" , test_group_name , test_device , test_measurements [ 0 ] ) ,
123+ TSDataType . TEXT , TSEncoding . PLAIN , Compressor . SNAPPY ) ;
124+ status = await session_pool . CreateTimeSeries (
125+ string . Format ( "{0}.{1}.{2}" , test_group_name , test_device , test_measurements [ 1 ] ) ,
126+ TSDataType . TEXT , TSEncoding . PLAIN , Compressor . SNAPPY ) ;
127+ status = await session_pool . CreateTimeSeries (
128+ string . Format ( "{0}.{1}.{2}" , test_group_name , test_device , test_measurements [ 2 ] ) ,
129+ TSDataType . TEXT , TSEncoding . PLAIN , Compressor . SNAPPY ) ;
130+ var rowRecord = new RowRecord ( 1668404120807 , new ( ) { "1111111" , "22222" , "333333" } , new ( ) { test_measurements [ 0 ] , test_measurements [ 1 ] , test_measurements [ 2 ] } ) ;
131+ status = await session_pool . InsertRecordsAsync ( new List < string > ( ) { string . Format ( "{0}.{1}" , test_group_name , test_device ) } , new List < RowRecord > ( ) { rowRecord } ) ;
132+ }
105133 public async Task TestGetTimeZone ( )
106134 {
107135 var session_pool = new SessionPool ( host , port , pool_size ) ;
@@ -275,7 +303,7 @@ public async Task TestNonSqlBy_ADO()
275303 {
276304 var cnts = new IoTDB . Data . IoTDBConnectionStringBuilder ( ) ;
277305 cnts . DataSource = host ;
278- cnts . TimeOut = ( int ) TimeSpan . FromSeconds ( 20 ) . TotalMilliseconds ;
306+ cnts . TimeOut = ( int ) TimeSpan . FromSeconds ( 20 ) . TotalMilliseconds ;
279307 var cnt = new IoTDB . Data . IoTDBConnection ( cnts . ConnectionString ) ;
280308 await cnt . OpenAsync ( ) ;
281309 var session_pool = cnt . SessionPool ;
@@ -303,7 +331,7 @@ await cnt.CreateCommand(
303331 "insert into " + string . Format ( "{0}.{1}" , test_group_name , test_device ) + "(timestamp, status, hardware) VALUES (7, true,'lz')" ) . ExecuteNonQueryAsync ( ) ;
304332 var reader = await cnt . CreateCommand (
305333 "select * from " + string . Format ( "{0}.{1}" , test_group_name , test_device ) + " where time<10" ) . ExecuteReaderAsync ( ) ;
306- ConsoleTableBuilder . From ( reader . ToDataTable ( ) ) . WithFormatter ( 0 , fc => $ "{ fc : yyyy-MM-dd HH:mm:ss.fff} " ) . WithFormat ( ConsoleTableBuilderFormat . Default ) . ExportAndWriteLine ( ) ;
334+ ConsoleTableBuilder . From ( reader . ToDataTable ( ) ) . WithFormatter ( 0 , fc => $ "{ fc : yyyy-MM-dd HH:mm:ss.fff} ") . WithFormat ( ConsoleTableBuilderFormat . Default ) . ExportAndWriteLine ( ) ;
307335 status = await session_pool . DeleteStorageGroupAsync ( test_group_name ) ;
308336 await cnt . CloseAsync ( ) ;
309337
@@ -373,5 +401,100 @@ await session_pool.ExecuteNonQueryStatementAsync(
373401 await session_pool . Close ( ) ;
374402 Console . WriteLine ( "SELECT sql Passed" ) ;
375403 }
404+ public async Task TestRawDataQuery ( )
405+ {
406+ var session_pool = new SessionPool ( host , port , pool_size ) ;
407+ var status = 0 ;
408+ await session_pool . Open ( false ) ;
409+ if ( debug ) session_pool . OpenDebugMode ( ) ;
410+
411+ System . Diagnostics . Debug . Assert ( session_pool . IsOpen ( ) ) ;
412+ status = await session_pool . DeleteStorageGroupAsync ( test_group_name ) ;
413+
414+ var device_id = string . Format ( "{0}.{1}" , test_group_name , test_device ) ;
415+ var measurements = new List < string > { test_measurements [ 0 ] , test_measurements [ 1 ] } ;
416+ var data_type_lst = new List < TSDataType > { TSDataType . BOOLEAN , TSDataType . FLOAT } ;
417+ var encoding_lst = new List < TSEncoding > { TSEncoding . PLAIN , TSEncoding . PLAIN } ;
418+ var compressor_lst = new List < Compressor > { Compressor . SNAPPY , Compressor . SNAPPY } ;
419+ status = await session_pool . CreateAlignedTimeseriesAsync ( device_id , measurements , data_type_lst , encoding_lst , compressor_lst ) ;
420+
421+ var records = new List < RowRecord > ( ) ;
422+ var values = new List < object > ( ) { true , 20.0f } ;
423+ var device_id_lst = new List < string > ( ) { } ;
424+ for ( int i = 1 ; i <= fetch_size * processed_size ; i ++ )
425+ {
426+ var record = new RowRecord ( i , values , measurements ) ;
427+ records . Add ( record ) ;
428+ device_id_lst . Add ( device_id ) ;
429+ }
430+ status = await session_pool . InsertAlignedRecordsAsync ( device_id_lst , records ) ;
431+ System . Diagnostics . Debug . Assert ( status == 0 ) ;
432+
433+ var paths = new List < string > ( ) { string . Format ( "{0}.{1}" , device_id , test_measurements [ 0 ] ) , string . Format ( "{0}.{1}" , device_id , test_measurements [ 1 ] ) } ;
434+
435+ var res = await session_pool . ExecuteRawDataQuery ( paths , 10 , fetch_size * processed_size ) ;
436+ var count = 0 ;
437+ while ( res . HasNext ( ) )
438+ {
439+ var record = res . Next ( ) ;
440+ count ++ ;
441+ }
442+ Console . WriteLine ( count + " " + ( fetch_size * processed_size - 10 ) ) ;
443+ System . Diagnostics . Debug . Assert ( count == fetch_size * processed_size - 10 ) ;
444+ await res . Close ( ) ;
445+
446+ status = await session_pool . DeleteStorageGroupAsync ( test_group_name ) ;
447+ System . Diagnostics . Debug . Assert ( status == 0 ) ;
448+ await session_pool . Close ( ) ;
449+ Console . WriteLine ( "RawDataQuery Passed" ) ;
450+ }
451+ public async Task TestLastDataQuery ( )
452+ {
453+ var session_pool = new SessionPool ( host , port , pool_size ) ;
454+ var status = 0 ;
455+ await session_pool . Open ( false ) ;
456+ if ( debug ) session_pool . OpenDebugMode ( ) ;
457+
458+ System . Diagnostics . Debug . Assert ( session_pool . IsOpen ( ) ) ;
459+ status = await session_pool . DeleteStorageGroupAsync ( test_group_name ) ;
460+
461+ var device_id = string . Format ( "{0}.{1}" , test_group_name , test_device ) ;
462+ var measurements = new List < string > { test_measurements [ 0 ] , test_measurements [ 1 ] } ;
463+ var data_type_lst = new List < TSDataType > { TSDataType . BOOLEAN , TSDataType . FLOAT } ;
464+ var encoding_lst = new List < TSEncoding > { TSEncoding . PLAIN , TSEncoding . PLAIN } ;
465+ var compressor_lst = new List < Compressor > { Compressor . SNAPPY , Compressor . SNAPPY } ;
466+ status = await session_pool . CreateAlignedTimeseriesAsync ( device_id , measurements , data_type_lst , encoding_lst , compressor_lst ) ;
467+
468+ var records = new List < RowRecord > ( ) ;
469+ var values = new List < object > ( ) { true , 20.0f } ;
470+ var device_id_lst = new List < string > ( ) { } ;
471+ for ( int i = 1 ; i <= fetch_size * processed_size ; i ++ )
472+ {
473+ var record = new RowRecord ( i , values , measurements ) ;
474+ records . Add ( record ) ;
475+ device_id_lst . Add ( device_id ) ;
476+ }
477+ status = await session_pool . InsertAlignedRecordsAsync ( device_id_lst , records ) ;
478+ System . Diagnostics . Debug . Assert ( status == 0 ) ;
479+
480+ var paths = new List < string > ( ) { string . Format ( "{0}.{1}" , device_id , test_measurements [ 0 ] ) , string . Format ( "{0}.{1}" , device_id , test_measurements [ 1 ] ) } ;
481+
482+ var res = await session_pool . ExecuteLastDataQueryAsync ( paths , fetch_size * processed_size - 10 ) ;
483+ var count = 0 ;
484+ while ( res . HasNext ( ) )
485+ {
486+ var record = res . Next ( ) ;
487+ Console . WriteLine ( record ) ;
488+ count ++ ;
489+ }
490+ Console . WriteLine ( count + " " + ( fetch_size * processed_size - 10 ) ) ;
491+ System . Diagnostics . Debug . Assert ( count == 2 ) ;
492+ await res . Close ( ) ;
493+
494+ status = await session_pool . DeleteStorageGroupAsync ( test_group_name ) ;
495+ System . Diagnostics . Debug . Assert ( status == 0 ) ;
496+ await session_pool . Close ( ) ;
497+ Console . WriteLine ( "LastDataQuery Passed" ) ;
498+ }
376499 }
377500}
0 commit comments