LP#1379815 Fetch tag data as a table using tag/xpath combo
authorDan Wells <dbw2@calvin.edu>
Mon, 6 Oct 2014 15:52:27 +0000 (11:52 -0400)
committerDan Wells <dbw2@calvin.edu>
Mon, 13 Oct 2014 19:47:38 +0000 (15:47 -0400)
commitcb9bc278ee2b0731413b29a2ae0818063bcc4044
treea920622602076a20375d59aec3c37903468eb6f3
parent18ef1cef2adb0beffe1758690bc8afc8e1189917
LP#1379815 Fetch tag data as a table using tag/xpath combo

New function: oils_xpath_tag_to_table()

This function is adapted from oils_xpath_table() with the goal of being
more targeted and simpler to use.

The main issue with oils_xpath_table() is that it relies on peer
UNNEST() functions, and that leads to unexpected behavior whenever the
xpath arguments result in uneven or "gapped" selections.  In the first
type of case, the resulting table includes rows representing the least
common multiple of the underlying xpath selections.  In the second
type, though the xpaths may sometimes return the same number of values,
those values are not correlated except by order in the marc, which does
not account for the real possibility of null values in the set.

Crude Example:

999 $d ABC $e 123
999 $d DEF
999 $d GHI
999 $e 456

We need a table representing subfields 'd' and 'e' of the '999' fields,
so we might try an xpath like:

//*[@tag="999"]/*[@code="d"]|//*[@tag="999"]/*[@code="e"]

We want:

 d  |  e
---------
ABC | 123
DEF |
GHI |
    | 456

but we get:

 d  |  e
---------
ABC | 123
DEF | 456
GHI | 123
ABC | 456
DEF | 123
GHI | 456

This example illustrates both negative behaviors (non-correlated fields
and least-common-multiple row multiplication).

The new method, while internally quite similar, has a different
signature, with the most significant change being a 'tag' argument
which serves as a common base element for the xpaths (now an array
rather than a pipe-delimited string).

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/sql/Pg/002.functions.config.sql
Open-ILS/src/sql/Pg/upgrade/XXXX.function.vandelay-oils_xpath_tag_to_table.sql [new file with mode: 0644]