You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/userguide/advanced_data_comparison.md
+135-3Lines changed: 135 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ utPLSQL expectations incorporates advanced data comparison options when comparin
7
7
- nested table and varray
8
8
9
9
Advanced data-comparison options are available for the [`equal`](expectations.md#equal) matcher.
10
-
10
+
11
11
## Syntax
12
12
13
13
```
@@ -23,6 +23,9 @@ Advanced data-comparison options are available for the [`equal`](expectations.md
23
23
-`exclude(a_items varchar2)` - item or comma separated list of items to exclude
24
24
-`include(a_items ut_varchar2_list)` - table of items to include
25
25
-`exclude(a_items ut_varchar2_list)` - table of items to exclude
26
+
-`unordered` - perform compare on unordered set of data, return only missing or actual
27
+
-`join_by(a_columns varchar2)` - columns or comma seperated list of columns to join two cursors by
28
+
-`join_by(a_columns ut_varchar2_list)` - table of columns to join two cursors by
26
29
27
30
Each item in the comma separated list can be:
28
31
- a column name of cursor to be compared
@@ -55,7 +58,7 @@ Columns 'ignore_me' and "ADate" will get excluded from cursor comparison.
55
58
The cursor data is equal, when those columns are excluded.
56
59
57
60
This option is useful in scenarios, when you need to exclude incomparable/unpredictable column data like CREATE_DATE of a record that is maintained by default value on a table column.
58
-
61
+
59
62
## Selecting columns for data comparison
60
63
61
64
Consider the following example
@@ -92,6 +95,135 @@ Only the columns 'RN', "A_Column" will be compared. Column 'SOME_COL' is exclude
92
95
93
96
This option can be useful in scenarios where you need to narrow-down the scope of test so that the test is only focused on very specific data.
94
97
98
+
##Unordered
99
+
100
+
Unordered option allows for quick comparison of two cursors without need of ordering them in any way.
101
+
102
+
Result of such comparison will be limited to only information about row existing or not existing in given set without actual information about exact differences.
103
+
104
+
105
+
106
+
```sql
107
+
procedure unordered_tst is
108
+
l_actual sys_refcursor;
109
+
l_expected sys_refcursor;
110
+
begin
111
+
open l_expected for select username, user_id from all_users
112
+
union all
113
+
select'TEST' username, -600 user_id from dual
114
+
order by1desc;
115
+
open l_actual for select username, user_id from all_users
You can now join two cursors by defining a primary key or composite key that will be used to uniquely identify and compare rows. This option allows us to exactly show which rows are missing, extra and which are different without ordering clause. In the situation where the join key is not unique, join will partition set over rows with a same key and join on row number as well as given join key. The extra rows or missing will be presented to user as well as not matching rows.
143
+
144
+
Join by option can be used in conjunction with include or exclude options. However if any of the join keys is part of exclude set, comparison will fail and report to user that sets could not be joined on specific key (excluded).
145
+
146
+
```sql
147
+
procedure join_by_username is
148
+
l_actual sys_refcursor;
149
+
l_expected sys_refcursor;
150
+
begin
151
+
open l_expected for select username, user_id from all_users
152
+
union all
153
+
select'TEST' username, -600 user_id from dual
154
+
order by1desc;
155
+
open l_actual for select username, user_id from all_users
In case when a there is detected collection inside cursor and we cannot join key. Comparison will present a failed joins and also a message about collection being detected.
211
+
212
+
```sql
213
+
Actual: refcursor [ count =1 ] was expected to equal: refcursor [ count =1 ]
214
+
Diff:
215
+
Unable to join sets:
216
+
Join key NESTED_TABLE/ANNOTATIONS/TEXT does not exists in expected
217
+
Join key NESTED_TABLE/ANNOTATIONS/TEXT does not exists in actual
218
+
Please make sure that your join clause is not refferring to collection element
219
+
```
220
+
221
+
222
+
223
+
224
+
225
+
**Please note that .join_by option will take longer to process due to need of parsing via primary keys.**
226
+
95
227
## Defining item as XPath
96
228
When using XPath expression, keep in mind the following:
97
229
@@ -109,4 +241,4 @@ begin
109
241
open l_actual for select rownum as rn, 'a'as"A_Column", 'x' SOME_COL, a.*from all_objects a where rownum <4;
0 commit comments