feat(opcua): HistoryReadEvents projects EventType, ConditionName, SourceNode; honours the where-clause (lmxopcua#746)
HistoryReadEvents projected only EventId / SourceName / Time / ReceiveTime / Message / Severity: a select clause asking for EventType, ConditionName or SourceNode (what most generic alarm viewers ask for) got nulls, and the event filter's where-clause (an OfType) was ignored. - HistoricalEvent gains optional EventTypeName, ConditionName and AlarmId. SqlServer, QuestDB and Gateway event reads fill them from what their alarm writers already store (AlarmTypeName / AlarmName / AlarmId; the gateway event Type and its AlarmName / AlarmId properties). - The node manager maps the type name to its Part 9 event type (unknown or non-event => AlarmConditionType), projects ConditionName, and resolves SourceNode to the materialised condition the alarm id names (the live events' SourceNode), else null. - The where-clause is evaluated per event with the SDK content filter through an IFilterTarget (OfType via the type tree; other operators against the projected fields), after the page's cursor is taken, so paging is unchanged. Tested in the node manager, over a real client session (the Client.CLI has no `historyread --events` mode yet; filed as a follow-up), and by alarm writer -> event read round trips on SqlServer and QuestDB. Rebased from the unpushed remed/lane-H2 branch (originally authored 2026-10-22 in session_01Ub9hGmYLQvn9XETzw7CMsT) onto current master. Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
+20
@@ -7,6 +7,26 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.Historian.Gateway.Tests.Mapping;
|
||||
|
||||
public sealed class EventMapperTests
|
||||
{
|
||||
[Fact]
|
||||
public void Carries_the_alarm_type_condition_name_and_alarm_id_the_writer_sent()
|
||||
{
|
||||
// The round trip of AlarmEventMapper's shape: Type = AlarmTypeName, Properties AlarmName / AlarmId.
|
||||
var sent = AlarmEventMapper.ToHistorianEvent(new ZB.MOM.WW.OtOpcUa.Core.AlarmHistorian.AlarmHistorianEvent(
|
||||
"Plant/Modbus/dev1/temp_hi", "Area/Line/Eq", "HiTemp", "LimitAlarm", ZB.MOM.WW.OtOpcUa.Core.Abstractions.AlarmSeverity.High,
|
||||
"Activated", "high", "u", null, new DateTime(2026, 1, 1, 0, 0, 0, DateTimeKind.Utc)));
|
||||
var h = EventMapper.ToHistoricalEvent(sent);
|
||||
Assert.Equal("LimitAlarm", h.EventTypeName);
|
||||
Assert.Equal("HiTemp", h.ConditionName);
|
||||
Assert.Equal("Plant/Modbus/dev1/temp_hi", h.AlarmId);
|
||||
|
||||
// A gateway row without them (e.g. an event another writer produced) maps to nulls, never throws.
|
||||
var bare = new HistorianEvent { Id = "E", EventTime = Ts(2026, 1, 1, 0, 0, 0), ReceivedTime = Ts(2026, 1, 1, 0, 0, 0) };
|
||||
var b = EventMapper.ToHistoricalEvent(bare);
|
||||
Assert.Null(b.EventTypeName);
|
||||
Assert.Null(b.ConditionName);
|
||||
Assert.Null(b.AlarmId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Maps_core_fields_and_times()
|
||||
{
|
||||
|
||||
+19
@@ -32,6 +32,25 @@ public sealed class AlarmWriterTests(QuestDbFixture fx)
|
||||
return Convert.ToInt64(await cmd.ExecuteScalarAsync());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task An_event_reads_back_with_its_type_name_condition_name_and_alarm_id()
|
||||
{
|
||||
fx.SkipIfUnavailable();
|
||||
var o = fx.Options(fx.UniquePrefix());
|
||||
var c = new QuestDbConnection(o);
|
||||
var boot = new QuestDbSchemaBootstrapper(c, o);
|
||||
var wal = new QuestDbWalVisibility(c, o.VisibilityTimeout);
|
||||
var w = new QuestDbAlarmHistorianWriter(c, boot, wal);
|
||||
(await w.WriteBatchAsync([Ev()], CancellationToken.None)).ShouldBe([HistorianWriteOutcome.Ack]);
|
||||
|
||||
var src = new QuestDbHistorianDataSource(c, boot, new QuestDbTagCatalog(c, boot, wal));
|
||||
var e = (await src.ReadEventsAsync("Plant/Line/Eq", T.AddMinutes(-1), T.AddMinutes(1), 0, CancellationToken.None))
|
||||
.Events.ShouldHaveSingleItem();
|
||||
e.EventTypeName.ShouldBe("LimitAlarm");
|
||||
e.ConditionName.ShouldBe("HiTemp");
|
||||
e.AlarmId.ShouldBe("alarm-1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_batch_is_one_insert_per_chunk_and_a_redelivery_converges()
|
||||
{
|
||||
|
||||
+19
@@ -63,6 +63,25 @@ public sealed class AlarmWriterTests(SqlHistorianFixture fx)
|
||||
r.ShouldBe([HistorianWriteOutcome.Ack, HistorianWriteOutcome.PermanentFail, HistorianWriteOutcome.Ack]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task An_event_reads_back_with_its_type_name_condition_name_and_alarm_id()
|
||||
{
|
||||
fx.SkipIfUnavailable();
|
||||
var s = SqlHistorianFixture.UniqueSchema();
|
||||
var o = new SqlServerHistorianOptions { ConnectionString = fx.ConnectionString, Schema = s };
|
||||
var c = new SqlHistorianConnection(o);
|
||||
var boot = new SqlServerSchemaBootstrapper(c, o);
|
||||
var w = new SqlServerAlarmHistorianWriter(c, boot);
|
||||
(await w.WriteBatchAsync([Ev()], CancellationToken.None)).ShouldBe([HistorianWriteOutcome.Ack]);
|
||||
|
||||
using var src = new SqlServerHistorianDataSource(c, boot, new SqlServerTagCatalog(c, boot));
|
||||
var e = (await src.ReadEventsAsync("Plant/Line/Eq", T.AddMinutes(-1), T.AddMinutes(1), 0, CancellationToken.None))
|
||||
.Events.ShouldHaveSingleItem();
|
||||
e.EventTypeName.ShouldBe("LimitAlarm");
|
||||
e.ConditionName.ShouldBe("HiTemp");
|
||||
e.AlarmId.ShouldBe("alarm-1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task A_batch_is_one_statement_per_chunk_and_a_redelivery_converges()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user