Skip to content

Commit b05d56a

Browse files
committed
fix: bitmap error
1 parent 4c12f52 commit b05d56a

File tree

3 files changed

+89
-4
lines changed

3 files changed

+89
-4
lines changed

samples/Apache.IoTDB.Samples/TableSessionPoolTest.cs

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public async Task Test()
3939

4040
await TestSelectAndInsert();
4141
await TestUseDatabase();
42-
// await TestCleanup();
42+
await TestInsertWithNull();
43+
await TestCleanup();
4344
}
4445

4546

@@ -161,6 +162,88 @@ public async Task TestUseDatabase()
161162
await tableSessionPool.Close();
162163
}
163164

165+
public async Task TestInsertWithNull()
166+
{
167+
var tableName = "t1";
168+
169+
var tableSessionPool = new TableSessionPool.Builder()
170+
.SetNodeUrls(sessionPoolTest.nodeUrls)
171+
.SetUsername(sessionPoolTest.username)
172+
.SetPassword(sessionPoolTest.password)
173+
.SetFetchSize(1024)
174+
.SetDatabase("test1")
175+
.Build();
176+
177+
await tableSessionPool.Open(false);
178+
179+
if (sessionPoolTest.debug) tableSessionPool.OpenDebugMode();
180+
181+
await tableSessionPool.ExecuteNonQueryStatementAsync(
182+
"create table " + tableName + "(" +
183+
"t1 STRING TAG," +
184+
"f1 DATE FIELD)");
185+
186+
List<string> columnNames =
187+
new List<string> {
188+
"t1",
189+
"f1" };
190+
List<TSDataType> dataTypes =
191+
new List<TSDataType>{
192+
TSDataType.STRING,
193+
TSDataType.DATE};
194+
List<ColumnCategory> columnCategories =
195+
new List<ColumnCategory>{
196+
ColumnCategory.TAG,
197+
ColumnCategory.FIELD};
198+
var timestamps = new List<long>
199+
{
200+
0L,
201+
1L,
202+
2L,
203+
3L,
204+
4L,
205+
5L,
206+
6L,
207+
7L,
208+
8L,
209+
9L
210+
};
211+
var values = new List<List<object>> { };
212+
values.Add(new List<object> { "t1", DateTime.Parse("2024-08-15") });
213+
values.Add(new List<object> { "t1", DateTime.Parse("2024-08-15") });
214+
values.Add(new List<object> { "t1", DateTime.Parse("2024-08-15") });
215+
values.Add(new List<object> { "t1", DateTime.Parse("2024-08-15") });
216+
values.Add(new List<object> { "t1", DateTime.Parse("2024-08-15") });
217+
values.Add(new List<object> { "t1", null });
218+
values.Add(new List<object> { "t1", null });
219+
values.Add(new List<object> { "t1", null });
220+
values.Add(new List<object> { "t1", null });
221+
values.Add(new List<object> { "t1", null });
222+
var tablet = new Tablet(tableName, columnNames, columnCategories, dataTypes, values, timestamps);
223+
224+
await tableSessionPool.InsertAsync(tablet);
225+
226+
227+
var res = await tableSessionPool.ExecuteQueryStatementAsync("select count(*) from " + tableName + " where f1 is null");
228+
// 断言 value == 5
229+
while (res.HasNext())
230+
{
231+
var row = res.Next();
232+
Console.WriteLine(row);
233+
var value = row.Values[0];
234+
if (value is long longValue)
235+
{
236+
if (longValue != 5)
237+
{
238+
throw new Exception("Expected value is 5, but got " + longValue);
239+
}
240+
}
241+
}
242+
await res.Close();
243+
244+
await tableSessionPool.Close();
245+
}
246+
164247
public async Task TestCleanup()
165248
{
166249
var tableSessionPool = new TableSessionPool.Builder()

src/Apache.IoTDB/DataStructure/BitMap.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#endif
2424
public class BitMap
2525
{
26-
private static byte[] BIT_UTIL = new byte[] { 1, 2, 4, 8, 16, 32, 64, 255 };
26+
private static byte[] BIT_UTIL = new byte[] { 1, 2, 4, 8, 16, 32, 64, unchecked((byte)-128) };
2727
private static byte[] UNMARK_BIT_UTIL =
2828
new byte[] {
2929
(byte) 0XFE, // 11111110
@@ -94,7 +94,7 @@ public void mark(int position)
9494
public void reset()
9595
{
9696
#if NET461_OR_GREATER || NETSTANDARD2_0
97-
bits.Fill((byte)0xFF);
97+
bits.Fill((byte)0);
9898
#else
9999
Array.Fill(bits, (byte)0);
100100
#endif

src/Apache.IoTDB/DataStructure/Tablet.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ namespace Apache.IoTDB.DataStructure
4444
*/
4545
public class Tablet
4646
{
47+
48+
private static int EMPTY_DATE_INT = 10000101;
4749
private readonly List<long> _timestamps;
4850
private readonly List<List<object>> _values;
4951

@@ -434,7 +436,7 @@ public byte[] GetBinaryValues()
434436
for (int j = 0; j < RowNumber; j++)
435437
{
436438
var value = _values[j][i];
437-
buffer.AddInt(value != null ? Utils.ParseDateToInt((DateTime)value) : int.MinValue);
439+
buffer.AddInt(value != null ? Utils.ParseDateToInt((DateTime)value) : EMPTY_DATE_INT);
438440
}
439441
break;
440442
}

0 commit comments

Comments
 (0)