Skip to content

Commit

Permalink
PostgreSQL: Group summaries: Fix type resolution for UNION
Browse files Browse the repository at this point in the history
Type resolution for UNION (CASE and related constructs) in PostgreSQL
works by taking the UNIONed queries 2 at a time, i.e. the first TWO
queries are resolved, then it takes the result and resolves it with the
next query and so on.

Previously, when using Hostgroup as the first query and Host (or
Service) as the next query, PostgreSQL encounters two NULL values for
the host_handled (or service_handled) column, resulting in the type
text. This leads to the following error:

UNION types text and boolenum cannot be matched.

Now Hostgroup is the last query that ensures there are not two
consecutive NULL values for host_handled (or service_handled).

NOTE: BREAKING: This change breaks other code that extracts the "base
query" which depends on Hostgroup or Servicegroup being the first query
in the getUnions() array, which has yet to be fixed.  In preparation for
a possible fix that could simply use the last query instead of the
first, the Servicegroup query has also been moved to the end.
  • Loading branch information
lippserd committed Apr 13, 2022
1 parent 4b80e06 commit 75952ee
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
32 changes: 16 additions & 16 deletions library/Icingadb/Model/Hostgroupsummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,22 +99,6 @@ public function getDefaultSort()
public function getUnions()
{
$unions = [
[
Hostgroup::class,
[],
[
'hostgroup_id' => 'hostgroup.id',
'hostgroup_name' => 'hostgroup.name',
'hostgroup_display_name' => 'hostgroup.display_name',
'host_id' => new Expression('NULL'),
'host_state' => new Expression('NULL'),
'host_handled' => new Expression('NULL'),
'host_severity' => new Expression('0'),
'service_id' => new Expression('NULL'),
'service_state' => new Expression('NULL'),
'service_handled' => new Expression('NULL')
]
],
[
Host::class,
[
Expand Down Expand Up @@ -152,6 +136,22 @@ public function getUnions()
'service_state' => 'state.soft_state',
'service_handled' => 'state.is_handled'
]
],
[
Hostgroup::class,
[],
[
'hostgroup_id' => 'hostgroup.id',
'hostgroup_name' => 'hostgroup.name',
'hostgroup_display_name' => 'hostgroup.display_name',
'host_id' => new Expression('NULL'),
'host_state' => new Expression('NULL'),
'host_handled' => new Expression('NULL'),
'host_severity' => new Expression('0'),
'service_id' => new Expression('NULL'),
'service_state' => new Expression('NULL'),
'service_handled' => new Expression('NULL')
]
]
];

Expand Down
26 changes: 13 additions & 13 deletions library/Icingadb/Model/ServicegroupSummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,6 @@ public function getDefaultSort()
public function getUnions()
{
$unions = [
[
Servicegroup::class,
[],
[
'servicegroup_id' => 'servicegroup.id',
'servicegroup_name' => 'servicegroup.name',
'servicegroup_display_name' => 'servicegroup.display_name',
'service_id' => new Expression('NULL'),
'service_state' => new Expression('NULL'),
'service_handled' => new Expression('NULL'),
'service_severity' => new Expression('0')
]
],
[
Service::class,
[
Expand All @@ -103,6 +90,19 @@ public function getUnions()
'service_handled' => 'state.is_handled',
'service_severity' => 'state.severity'
]
],
[
Servicegroup::class,
[],
[
'servicegroup_id' => 'servicegroup.id',
'servicegroup_name' => 'servicegroup.name',
'servicegroup_display_name' => 'servicegroup.display_name',
'service_id' => new Expression('NULL'),
'service_state' => new Expression('NULL'),
'service_handled' => new Expression('NULL'),
'service_severity' => new Expression('0')
]
]
];

Expand Down

0 comments on commit 75952ee

Please sign in to comment.