Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Feature/cursor pk join #666

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 36 commits into from
May 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b9ca972
Initial check in of unordered comparision
lwasylow Apr 23, 2018
41ae0ff
Added methods for join_by
lwasylow Apr 24, 2018
bcab19c
Merge branch 'develop' of github.com:lwasylow/utPLSQL into feature/cu…
lwasylow May 1, 2018
a3406ee
Updated JoinBy query
lwasylow May 3, 2018
3ca16f7
Updated JoinBy query
lwasylow May 3, 2018
d1b4fe0
Merge branch 'feature/cursor_pk_join' of github.com:lwasylow/utPLSQL …
lwasylow May 4, 2018
a5e6aae
fixes to test name length
lwasylow May 4, 2018
8a33c25
Update documentation
lwasylow May 4, 2018
0fc68d1
Update order by to be done before max row nums are pulled
lwasylow May 5, 2018
7f3d12e
Updated join by
lwasylow May 5, 2018
b8840a1
Updated join by
lwasylow May 5, 2018
8133f11
Merge branch 'feature/cursor_pk_join' of github.com:lwasylow/utPLSQL …
lwasylow May 6, 2018
aaa0cc4
Update to sort random order cause of optimizer
lwasylow May 7, 2018
784c509
Update pk join cursor
lwasylow May 9, 2018
fdff62a
Merge branch 'develop' of github.com:lwasylow/utPLSQL into feature/cu…
lwasylow May 9, 2018
ac042d0
Added failure on missing join by key in cursor.
lwasylow May 10, 2018
38aba43
Added unique key name as part of compare results
lwasylow May 10, 2018
66974e0
Added unique key name as part of compare results
lwasylow May 10, 2018
0fd8be8
Revert "Initial check in of unordered comparision"
lwasylow May 11, 2018
1bf5bad
Update blank line
lwasylow May 11, 2018
278dc68
Merge branch 'feature/cursor_pk_join' of github.com:lwasylow/utPLSQL …
lwasylow May 11, 2018
ec258dc
Merge branch 'develop' of github.com:lwasylow/utPLSQL into feature/cu…
lwasylow May 12, 2018
5eeb7f6
Merge branch 'develop' of github.com:lwasylow/utPLSQL into feature/cu…
lwasylow May 12, 2018
ad345f1
Merge branch 'develop' of https://github.com/utPLSQL/utPLSQL into fea…
lwasylow May 12, 2018
5c894c6
Merge branch 'develop' of https://github.com/utPLSQL/utPLSQL into fea…
lwasylow May 12, 2018
44cbcc8
Merge branch 'feature/cursor_pk_join' of github.com:lwasylow/utPLSQL …
lwasylow May 13, 2018
cc718d9
Added changes to cater for nested tables
lwasylow May 17, 2018
61a334a
Merge branch 'develop' of github.com:utPLSQL/utPLSQL into feature/cur…
lwasylow May 17, 2018
77e4468
Updated code with a new display
lwasylow May 22, 2018
a7f167c
Update to handle new line in xmltype that caused pk value being retur…
lwasylow May 22, 2018
b457d69
Updates to the ordering of sets to get consistent results.
lwasylow May 23, 2018
7577a95
Revert "Updates to the ordering of sets to get consistent results."
lwasylow May 23, 2018
890c1d2
Refactoring to simplify code
lwasylow May 23, 2018
4d8b964
Revert "Revert "Updates to the ordering of sets to get consistent res…
lwasylow May 23, 2018
f77f13a
Update to test and docs
lwasylow May 24, 2018
2f662ed
Merge branch 'develop' into feature/cursor_pk_join
jgebal May 24, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 86 additions & 3 deletions docs/userguide/advanced_data_comparison.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ utPLSQL expectations incorporates advanced data comparison options when comparin
- nested table and varray

Advanced data-comparison options are available for the [`equal`](expectations.md#equal) matcher.

## Syntax

```
Expand All @@ -23,6 +23,9 @@ Advanced data-comparison options are available for the [`equal`](expectations.md
- `exclude(a_items varchar2)` - item or comma separated list of items to exclude
- `include(a_items ut_varchar2_list)` - table of items to include
- `exclude(a_items ut_varchar2_list)` - table of items to exclude
- `unordered` - perform compare on unordered set of data, return only missing or actual
- `join_by(a_columns varchar2)` - columns or comma seperated list of columns to join two cursors by
- `join_by(a_columns ut_varchar2_list)` - table of columns to join two cursors by

Each item in the comma separated list can be:
- a column name of cursor to be compared
Expand Down Expand Up @@ -55,7 +58,7 @@ Columns 'ignore_me' and "ADate" will get excluded from cursor comparison.
The cursor data is equal, when those columns are excluded.

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.

## Selecting columns for data comparison

Consider the following example
Expand Down Expand Up @@ -92,6 +95,86 @@ Only the columns 'RN', "A_Column" will be compared. Column 'SOME_COL' is exclude

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.

##Unordered

Unordered option allows for quick comparison of two cursors without need of ordering them in any way.

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.



```sql
procedure unordered_tst is
l_actual sys_refcursor;
l_expected sys_refcursor;
begin
open l_expected for select username, user_id from all_users
union all
select 'TEST' username, -600 user_id from dual
order by 1 desc;
open l_actual for select username, user_id from all_users
union all
select 'TEST' username, -610 user_id from dual
order by 1 asc;
ut.expect( l_actual ).to_equal( l_expected ).unordered;
end;
```



Above test will result in two differences of one row extra and one row missing.



```sql
Diff:
Rows: [ 2 differences ]
Missing: <ROW><USERNAME>TEST</USERNAME><USER_ID>-600</USER_ID></ROW>
Extra: <ROW><USERNAME>TEST</USERNAME><USER_ID>-610</USER_ID></ROW>
```





## Join By option

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.

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).

Join by options currently doesn't support nested table inside cursor.

```sql
procedure join_by_username is
l_actual sys_refcursor;
l_expected sys_refcursor;
begin
open l_expected for select username, user_id from all_users
union all
select 'TEST' username, -600 user_id from dual
order by 1 desc;
open l_actual for select username, user_id from all_users
union all
select 'TEST' username, -610 user_id from dual
order by 1 asc;
ut.expect( l_actual ).to_equal( l_expected ).join_by('USERNAME');
end;
```
This will show you difference in row 'TEST' regardless of order.

```sql
Rows: [ 1 differences ]
PK <USERNAME>TEST</USERNAME> - Expected: <USER_ID>-600</USER_ID>
PK <USERNAME>TEST</USERNAME> - Actual: <USER_ID>-610</USER_ID>
```

Assumption is that join by is made by column name so that what will be displayed as part of results.



**Please note that .join_by option will take longer to process due to need of parsing via primary keys.**

## Defining item as XPath
When using XPath expression, keep in mind the following:

Expand All @@ -109,4 +192,4 @@ begin
open l_actual for select rownum as rn, 'a' as "A_Column", 'x' SOME_COL, a.* from all_objects a where rownum < 4;
ut.expect( l_actual ).to_equal( l_expected ).include( '/ROW/RN|/ROW/A_Column|/ROW/SOME_COL' );
end;
```
```
2 changes: 1 addition & 1 deletion source/core/types/ut_key_value_pair.tps
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
create or replace type ut_key_value_pair as object(
create or replace type ut_key_value_pair force as object(
/*
utPLSQL - Version 3
Copyright 2016 - 2017 utPLSQL Project
Expand Down
2 changes: 0 additions & 2 deletions source/create_synonyms_and_grants_for_public.sql
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,6 @@ create public synonym ut_file_mapping for &&ut3_owner..ut_file_mapping;
create public synonym ut_file_mapper for &&ut3_owner..ut_file_mapper;
create public synonym ut_key_value_pairs for &&ut3_owner..ut_key_value_pairs;
create public synonym ut_key_value_pair for &&ut3_owner..ut_key_value_pair;
create public synonym ut_compound_data_tmp for &&ut3_owner..ut_compound_data_tmp;
create public synonym ut_compound_data_diff_tmp for &&ut3_owner..ut_compound_data_diff_tmp;
create public synonym ut_sonar_test_reporter for &&ut3_owner..ut_sonar_test_reporter;
begin
$if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then
Expand Down
1 change: 0 additions & 1 deletion source/create_user_synonyms.sql
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ create or replace synonym &ut3_user..ut_file_mapper for &&ut3_owner..ut_file_map
create or replace synonym &ut3_user..ut_key_value_pairs for &&ut3_owner..ut_key_value_pairs;
create or replace synonym &ut3_user..ut_key_value_pair for &&ut3_owner..ut_key_value_pair;
create or replace synonym &ut3_user..ut_compound_data_tmp for &&ut3_owner..ut_cursor_data;
create or replace synonym &ut3_user..ut_compound_data_diff_tmp for &&ut3_owner..ut_compound_data_diff_tmp;
create or replace synonym &ut3_user..ut_sonar_test_reporter for &&ut3_owner..ut_sonar_test_reporter;
begin
$if dbms_db_version.version = 12 and dbms_db_version.release >= 2 or dbms_db_version.version > 12 $then
Expand Down
10 changes: 9 additions & 1 deletion source/expectations/data_values/ut_compound_data_diff_tmp.sql
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,13 @@ create global temporary table ut_compound_data_diff_tmp(
*/
diff_id raw(128),
item_no integer,
constraint ut_compound_data_diff_tmp_pk primary key(diff_id,item_no)
pk_hash raw(128),
item_hash raw(128),
duplicate_no integer,
constraint ut_compound_data_diff_tmp_uk1 unique (diff_id,duplicate_no,item_no,item_hash, pk_hash),
constraint ut_compound_data_diff_tmp_chk check(
item_no is not null and pk_hash is null and duplicate_no is null
or item_no is null and item_hash is not null and duplicate_no is not null
or item_no is null and pk_hash is not null and duplicate_no is not null
)
) on commit preserve rows;
Loading