This is an automated email from the ASF dual-hosted git repository. critas pushed a commit to branch wx_fix_bitmap in repository https://gitbox.apache.org/repos/asf/iotdb-client-csharp.git
commit b05d56a7e7d35d1f2c10f1d772b4b9219a43d7e2 Author: CritasWang <[email protected]> AuthorDate: Tue Apr 1 15:52:20 2025 +0800 fix: bitmap error --- .../Apache.IoTDB.Samples/TableSessionPoolTest.cs | 85 +++++++++++++++++++++- src/Apache.IoTDB/DataStructure/BitMap.cs | 4 +- src/Apache.IoTDB/DataStructure/Tablet.cs | 4 +- 3 files changed, 89 insertions(+), 4 deletions(-) diff --git a/samples/Apache.IoTDB.Samples/TableSessionPoolTest.cs b/samples/Apache.IoTDB.Samples/TableSessionPoolTest.cs index 36d2b88..764d129 100644 --- a/samples/Apache.IoTDB.Samples/TableSessionPoolTest.cs +++ b/samples/Apache.IoTDB.Samples/TableSessionPoolTest.cs @@ -39,7 +39,8 @@ public class TableSessionPoolTest await TestSelectAndInsert(); await TestUseDatabase(); - // await TestCleanup(); + await TestInsertWithNull(); + await TestCleanup(); } @@ -161,6 +162,88 @@ public class TableSessionPoolTest await tableSessionPool.Close(); } + public async Task TestInsertWithNull() + { + var tableName = "t1"; + + var tableSessionPool = new TableSessionPool.Builder() + .SetNodeUrls(sessionPoolTest.nodeUrls) + .SetUsername(sessionPoolTest.username) + .SetPassword(sessionPoolTest.password) + .SetFetchSize(1024) + .SetDatabase("test1") + .Build(); + + await tableSessionPool.Open(false); + + if (sessionPoolTest.debug) tableSessionPool.OpenDebugMode(); + + await tableSessionPool.ExecuteNonQueryStatementAsync( + "create table " + tableName + "(" + + "t1 STRING TAG," + + "f1 DATE FIELD)"); + + List<string> columnNames = + new List<string> { + "t1", + "f1" }; + List<TSDataType> dataTypes = + new List<TSDataType>{ + TSDataType.STRING, + TSDataType.DATE}; + List<ColumnCategory> columnCategories = + new List<ColumnCategory>{ + ColumnCategory.TAG, + ColumnCategory.FIELD}; + var timestamps = new List<long> + { + 0L, + 1L, + 2L, + 3L, + 4L, + 5L, + 6L, + 7L, + 8L, + 9L + }; + var values = new List<List<object>> { }; + values.Add(new List<object> { "t1", DateTime.Parse("2024-08-15") }); + values.Add(new List<object> { "t1", DateTime.Parse("2024-08-15") }); + values.Add(new List<object> { "t1", DateTime.Parse("2024-08-15") }); + values.Add(new List<object> { "t1", DateTime.Parse("2024-08-15") }); + values.Add(new List<object> { "t1", DateTime.Parse("2024-08-15") }); + values.Add(new List<object> { "t1", null }); + values.Add(new List<object> { "t1", null }); + values.Add(new List<object> { "t1", null }); + values.Add(new List<object> { "t1", null }); + values.Add(new List<object> { "t1", null }); + var tablet = new Tablet(tableName, columnNames, columnCategories, dataTypes, values, timestamps); + + await tableSessionPool.InsertAsync(tablet); + + + var res = await tableSessionPool.ExecuteQueryStatementAsync("select count(*) from " + tableName + " where f1 is null"); + // 断言 value == 5 + while (res.HasNext()) + { + var row = res.Next(); + Console.WriteLine(row); + var value = row.Values[0]; + if (value is long longValue) + { + if (longValue != 5) + { + throw new Exception("Expected value is 5, but got " + longValue); + } + } + } + await res.Close(); + + await tableSessionPool.Close(); + } + public async Task TestCleanup() { var tableSessionPool = new TableSessionPool.Builder() diff --git a/src/Apache.IoTDB/DataStructure/BitMap.cs b/src/Apache.IoTDB/DataStructure/BitMap.cs index 5a1b607..75b2d58 100644 --- a/src/Apache.IoTDB/DataStructure/BitMap.cs +++ b/src/Apache.IoTDB/DataStructure/BitMap.cs @@ -23,7 +23,7 @@ using Grax32.Extensions; #endif public class BitMap { - private static byte[] BIT_UTIL = new byte[] { 1, 2, 4, 8, 16, 32, 64, 255 }; + private static byte[] BIT_UTIL = new byte[] { 1, 2, 4, 8, 16, 32, 64, unchecked((byte)-128) }; private static byte[] UNMARK_BIT_UTIL = new byte[] { (byte) 0XFE, // 11111110 @@ -94,7 +94,7 @@ public class BitMap public void reset() { #if NET461_OR_GREATER || NETSTANDARD2_0 - bits.Fill((byte)0xFF); + bits.Fill((byte)0); #else Array.Fill(bits, (byte)0); #endif diff --git a/src/Apache.IoTDB/DataStructure/Tablet.cs b/src/Apache.IoTDB/DataStructure/Tablet.cs index 34007ee..bf67ddc 100644 --- a/src/Apache.IoTDB/DataStructure/Tablet.cs +++ b/src/Apache.IoTDB/DataStructure/Tablet.cs @@ -44,6 +44,8 @@ namespace Apache.IoTDB.DataStructure */ public class Tablet { + + private static int EMPTY_DATE_INT = 10000101; private readonly List<long> _timestamps; private readonly List<List<object>> _values; @@ -434,7 +436,7 @@ namespace Apache.IoTDB.DataStructure for (int j = 0; j < RowNumber; j++) { var value = _values[j][i]; - buffer.AddInt(value != null ? Utils.ParseDateToInt((DateTime)value) : int.MinValue); + buffer.AddInt(value != null ? Utils.ParseDateToInt((DateTime)value) : EMPTY_DATE_INT); } break; }
