diff --git a/build_json.xlsx b/build_json.xlsx index 6330b1b..7524e1b 100644 Binary files a/build_json.xlsx and b/build_json.xlsx differ diff --git a/do_map.pgsql b/do_map.pgsql index 5767e93..2c9bae2 100644 --- a/do_map.pgsql +++ b/do_map.pgsql @@ -8,6 +8,7 @@ SELECT m.srce, m.target, t.id, + t.rec, jsonb_build_object( e.v ->> 'key', (t.rec #> ((e.v ->> 'key')::text[])) @@ -30,12 +31,13 @@ FROM LEFT JOIN LATERAL jsonb_array_elements(m.regex->'defn') WITH ORDINALITY e(v, rn) ON true LEFT JOIN LATERAL regexp_matches(t.rec #>> ((e.v ->> 'key')::text[]), e.v ->> 'regex'::text) WITH ORDINALITY mt(mt, rn) ON true WHERE - t.srce = 'PNCC' + t.srce = 'DCARD' ORDER BY m.srce, m.seq, m.target, t.id, + t.rec, e.rn ), @@ -47,6 +49,7 @@ agg_rx AS ( rx.srce, rx.target, rx.id, + rx.rec, tps.jsonb_concat_obj(rx.rkey) rkey, tps.jsonb_concat_obj(rx.retval) AS retval, tps.jsonb_concat_obj(CASE rx.retain WHEN 'y' THEN rx.retval ELSE '{}'::jsonb END) retain, @@ -59,19 +62,22 @@ agg_rx AS ( rx.srce, rx.target, rx.id, + rx.rec, rx.seq ) -------------aggregate all targets back to row level (id)------------------------------------------------------------------------------------------------ +,agg_orig AS ( SELECT u.srce, u.id, + u.rec, string_agg(u.target,',') target, - jsonb_pretty(tps.jsonb_concat_obj(coalesce(v.map,'{}'::jsonb) ORDER BY seq )) map, - jsonb_pretty(tps.jsonb_concat_obj(u.retval||coalesce(v.map,'{}'::jsonb) ORDER BY seq)) comb, - jsonb_pretty(tps.jsonb_concat_obj(u.retain||coalesce(v.map,'{}'::jsonb) ORDER BY seq)) retain + tps.jsonb_concat_obj(coalesce(v.map,'{}'::jsonb) ORDER BY seq ) map, + tps.jsonb_concat_obj(u.retval||coalesce(v.map,'{}'::jsonb) ORDER BY seq) comb, + tps.jsonb_concat_obj(u.retain||coalesce(v.map,'{}'::jsonb) ORDER BY seq) retain FROM --re-aggregate return values and explude any records where one or more regex failed with a null result agg_rx u @@ -81,5 +87,20 @@ agg_rx AS ( v.retval <@ u.retval GROUP BY u.srce, - u.id - LIMIT 1000 \ No newline at end of file + u.id, + u.rec +) + + +SELECT + retain->>'f20', + rec->>'Description', + COUNT(*) +FROM + agg_orig +GROUP BY + retain->>'f20', + rec->>'Description' +ORDER BY + retain->>'f20', + rec->>'Description' diff --git a/map_rm.pgsql b/map_rm.pgsql index f116884..99a3900 100644 --- a/map_rm.pgsql +++ b/map_rm.pgsql @@ -1,71 +1,35 @@ +DELETE FROM tps.map_rm; INSERT INTO tps.map_rm SELECT * FROM (VALUES - ('PNCC', 'ACH Debits', + ('DCARD', 'First 20', $j$ { "defn": [ { "key": "{Description}", - "field": "ini", - "regex": "([\\w].*?)(?=$| -|\\s[0-9].*?|\\s[\\w/]+?:)" - ,"retain":"y" - }, - { - "key": "{Description}", - "field": "compn", - "regex": "Comp Name:(.+?)(?=$| Comp|\\w+?:)" - ,"retain":"y" - }, - { - "key": "{Description}", - "field": "adp_comp", - "regex": "Cust ID:.*?(B3X|UDV|U7E|U7C|U7H|U7J).*?(?=$|\\w+?:)" - ,"retain":"y" - }, - { - "key": "{Description}", - "field": "desc", - "regex": "Desc:(.+?) Comp" - ,"retain":"y" - }, - { - "key": "{Description}", - "field": "discr", - "regex": "Discr:(.+?)(?=$| SEC:|\\w+?:)" + "field": "f20", + "regex": ".{1,20}" ,"retain":"y" } ], "where": [ { - "Transaction": "ACH Debits" } ] } $j$::jsonb , 2) - ,('PNCC', 'Trans Type', + ,('HUNT', 'First 20', $j$ { "defn": [ - { - "key": "{AccountName}", - "field": "acctn", - "regex": "(.*)" - ,"retain":"n" - }, - { - "key": "{Transaction}", - "field": "trans", - "regex": "(.*)" - ,"retain":"n" - }, { "key": "{Description}", - "field": "ini", - "regex": "([\\w].*?)(?=$| -|\\s[0-9].*?|\\s[\\w/]+?:)" + "field": "f20", + "regex": ".{1,20}" ,"retain":"y" } ], @@ -76,91 +40,4 @@ FROM } $j$::jsonb , 1) - ,('PNCC', 'Wires Out', - $j$ - { - "defn": [ - { - "key": "{Description}", - "field": "ini", - "regex": "([\\w].*?)(?=$| -|\\s[0-9].*?|\\s[\\w/]+?:)" - ,"retain":"y" - }, - { - "key": "{Description}", - "field": "bene", - "regex": "BENEFICIARY:(.+?) AC/" - ,"retain":"y" - }, - { - "key": "{Description}", - "field": "accts", - "regex": "AC/(\\w*) .*AC/(\\w*) " - ,"retain":"y" - } - ], - "where": [ - { - "Transaction": "Intl Money Transfer Debits" - }, - { - "Transaction": "Money Transfer DB - Wire" - } - ] - } - $j$::jsonb - , 2) - ,('PNCC', 'Currency', - $j$ - { - "defn": [ - { - "key": "{Description}", - "field": "ini", - "regex": "([\\w].*?)(?=$| -|\\s[0-9].*?|\\s[\\w/]+?:)" - ,"retain":"y" - }, - { - "key": "{Description}", - "field": "curr1", - "regex": ".*(DEBIT|CREDIT).*(USD|CAD).*(?=DEBIT|CREDIT).*(?=USD|CAD).*" - ,"retain":"y" - }, - { - "key": "{Description}", - "field": "curr2", - "regex": ".*(?=DEBIT|CREDIT).*(?=USD|CAD).*(DEBIT|CREDIT).*(USD|CAD).*" - ,"retain":"y" - } - ], - "where": [ - { - "Transaction": "Miscellaneous Credits" - }, - { - "Transaction": "Miscellaneous Debits" - } - ] - } - $j$::jsonb - , 2) - ,('PNCC', 'Check Number', - $j$ - { - "defn": [ - { - "key": "{Description}", - "field": "checkn", - "regex": "[^0-9]*([0-9]*)\\s|$" - ,"retain":"y" - } - ], - "where": [ - { - "Transaction": "Checks Paid" - } - ] - } - $j$::jsonb - , 2) ) x \ No newline at end of file