Skip to content

Commit 4955136

Browse files
committed
Fix SessionDataSet: row count, async dispose, and null measurement issues (#53, #54, #55)
修复 SessionDataSet 行数统计、异步释放及空值测点问题 - Fix CurrentBatchRowCount() always returning 0 by eagerly constructing the first TsBlock in RpcDataSet constructor when initial data is available 修复 CurrentBatchRowCount() 始终返回 0 的问题,在构造函数中预先反序列化首个 TsBlock - Add IAsyncDisposable to SessionDataSet and RpcDataSet, providing DisposeAsync() that properly awaits Close() to avoid sync-over-async deadlocks 为 SessionDataSet 和 RpcDataSet 添加 IAsyncDisposable 接口,支持 await using 语法 - Fix GetRow() including null-valued columns in RowRecord by using IsNull() check before calling type-specific getters, instead of relying on value type null checks which always pass for int/bool/float/etc. 修复 GetRow() 中值类型默认值绕过 null 检查导致空值列被错误包含的问题
1 parent 9fd7a9c commit 4955136

2 files changed

Lines changed: 49 additions & 10 deletions

File tree

src/Apache.IoTDB/DataStructure/RpcDataSet.cs

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
namespace Apache.IoTDB.DataStructure
2828
{
29-
public class RpcDataSet : System.IDisposable
29+
public class RpcDataSet : System.IDisposable, System.IAsyncDisposable
3030
{
3131
private const string TimestampColumnName = "Time";
3232
private const string DefaultTimeFormat = "yyyy-MM-dd HH:mm:ss.fff";
@@ -140,6 +140,11 @@ public RpcDataSet(string sql, List<string> columnNameList, List<string> columnTy
140140
_tsBlockSize = 0;
141141
_tsBlockIndex = -1;
142142

143+
if (HasCachedByteBuffer())
144+
{
145+
ConstructOneTsBlock();
146+
}
147+
143148
_zoneId = FindTimeZoneSafe(zoneId);
144149

145150
if (columnIndex2TsBlockColumnIndexList.Count != _columnNameList.Count)
@@ -172,6 +177,22 @@ public void Dispose()
172177
GC.SuppressFinalize(this);
173178
}
174179

180+
public async ValueTask DisposeAsync()
181+
{
182+
if (!disposedValue)
183+
{
184+
try
185+
{
186+
await Close().ConfigureAwait(false);
187+
}
188+
catch
189+
{
190+
}
191+
disposedValue = true;
192+
}
193+
GC.SuppressFinalize(this);
194+
}
195+
175196
public async Task Close()
176197
{
177198
if (_isClosed) return;
@@ -634,11 +655,9 @@ public RowRecord GetRow()
634655
long timestamp = 0;
635656
foreach (string columnName in columns)
636657
{
637-
object localfield;
638658
string typeStr = _columnTypeList[i];
639659
TSDataType dataType = Client.GetDataTypeByStr(typeStr);
640660

641-
// Identify the real time column by tsBlock index, not by data type
642661
int tsBlockColumnIndex = GetTsBlockColumnIndexForColumnName(columnName);
643662
if (tsBlockColumnIndex == -1)
644663
{
@@ -647,6 +666,13 @@ public RowRecord GetRow()
647666
continue;
648667
}
649668

669+
if (IsNull(tsBlockColumnIndex, _tsBlockIndex))
670+
{
671+
i += 1;
672+
continue;
673+
}
674+
675+
object localfield;
650676
switch (dataType)
651677
{
652678
case TSDataType.BOOLEAN:
@@ -682,12 +708,9 @@ public RowRecord GetRow()
682708
string err_msg = "value format not supported";
683709
throw new TException(err_msg, null);
684710
}
685-
if (localfield != null)
686-
{
687-
fieldList.Add(localfield);
688-
measurementList.Add(columnName);
689-
dataTypeList.Add(dataType);
690-
}
711+
fieldList.Add(localfield);
712+
measurementList.Add(columnName);
713+
dataTypeList.Add(dataType);
691714
i += 1;
692715
}
693716
return new RowRecord(timestamp, fieldList, measurementList, dataTypeList);

src/Apache.IoTDB/DataStructure/SessionDataSet.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
namespace Apache.IoTDB.DataStructure
2727
{
28-
public class SessionDataSet : System.IDisposable
28+
public class SessionDataSet : System.IDisposable, System.IAsyncDisposable
2929
{
3030
private readonly long _queryId;
3131
private readonly long _statementId;
@@ -184,5 +184,21 @@ public void Dispose()
184184
Dispose(disposing: true);
185185
GC.SuppressFinalize(this);
186186
}
187+
188+
public async ValueTask DisposeAsync()
189+
{
190+
if (!disposedValue)
191+
{
192+
try
193+
{
194+
await this.Close().ConfigureAwait(false);
195+
}
196+
catch
197+
{
198+
}
199+
disposedValue = true;
200+
}
201+
GC.SuppressFinalize(this);
202+
}
187203
}
188204
}

0 commit comments

Comments
 (0)