update maps for first 20, get rid of pretty and tag on summary of mappings

This commit is contained in:
Paul Trowbridge 2017-10-19 23:57:03 -04:00
parent 085f794693
commit ea0084ed75
3 changed files with 34 additions and 136 deletions

Binary file not shown.

View File

@ -8,6 +8,7 @@ SELECT
m.srce, m.srce,
m.target, m.target,
t.id, t.id,
t.rec,
jsonb_build_object( jsonb_build_object(
e.v ->> 'key', e.v ->> 'key',
(t.rec #> ((e.v ->> 'key')::text[])) (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 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 LEFT JOIN LATERAL regexp_matches(t.rec #>> ((e.v ->> 'key')::text[]), e.v ->> 'regex'::text) WITH ORDINALITY mt(mt, rn) ON true
WHERE WHERE
t.srce = 'PNCC' t.srce = 'DCARD'
ORDER BY ORDER BY
m.srce, m.srce,
m.seq, m.seq,
m.target, m.target,
t.id, t.id,
t.rec,
e.rn e.rn
), ),
@ -47,6 +49,7 @@ agg_rx AS (
rx.srce, rx.srce,
rx.target, rx.target,
rx.id, rx.id,
rx.rec,
tps.jsonb_concat_obj(rx.rkey) rkey, tps.jsonb_concat_obj(rx.rkey) rkey,
tps.jsonb_concat_obj(rx.retval) AS retval, tps.jsonb_concat_obj(rx.retval) AS retval,
tps.jsonb_concat_obj(CASE rx.retain WHEN 'y' THEN rx.retval ELSE '{}'::jsonb END) retain, 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.srce,
rx.target, rx.target,
rx.id, rx.id,
rx.rec,
rx.seq rx.seq
) )
-------------aggregate all targets back to row level (id)------------------------------------------------------------------------------------------------ -------------aggregate all targets back to row level (id)------------------------------------------------------------------------------------------------
,agg_orig AS (
SELECT SELECT
u.srce, u.srce,
u.id, u.id,
u.rec,
string_agg(u.target,',') target, string_agg(u.target,',') target,
jsonb_pretty(tps.jsonb_concat_obj(coalesce(v.map,'{}'::jsonb) ORDER BY seq )) map, 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, 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(u.retain||coalesce(v.map,'{}'::jsonb) ORDER BY seq) retain
FROM FROM
--re-aggregate return values and explude any records where one or more regex failed with a null result --re-aggregate return values and explude any records where one or more regex failed with a null result
agg_rx u agg_rx u
@ -81,5 +87,20 @@ agg_rx AS (
v.retval <@ u.retval v.retval <@ u.retval
GROUP BY GROUP BY
u.srce, u.srce,
u.id u.id,
LIMIT 1000 u.rec
)
SELECT
retain->>'f20',
rec->>'Description',
COUNT(*)
FROM
agg_orig
GROUP BY
retain->>'f20',
rec->>'Description'
ORDER BY
retain->>'f20',
rec->>'Description'

View File

@ -1,71 +1,35 @@
DELETE FROM tps.map_rm;
INSERT INTO INSERT INTO
tps.map_rm tps.map_rm
SELECT * SELECT *
FROM FROM
(VALUES (VALUES
('PNCC', 'ACH Debits', ('DCARD', 'First 20',
$j$ $j$
{ {
"defn": [ "defn": [
{ {
"key": "{Description}", "key": "{Description}",
"field": "ini", "field": "f20",
"regex": "([\\w].*?)(?=$| -|\\s[0-9].*?|\\s[\\w/]+?:)" "regex": ".{1,20}"
,"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+?:)"
,"retain":"y" ,"retain":"y"
} }
], ],
"where": [ "where": [
{ {
"Transaction": "ACH Debits"
} }
] ]
} }
$j$::jsonb $j$::jsonb
, 2) , 2)
,('PNCC', 'Trans Type', ,('HUNT', 'First 20',
$j$ $j$
{ {
"defn": [ "defn": [
{
"key": "{AccountName}",
"field": "acctn",
"regex": "(.*)"
,"retain":"n"
},
{
"key": "{Transaction}",
"field": "trans",
"regex": "(.*)"
,"retain":"n"
},
{ {
"key": "{Description}", "key": "{Description}",
"field": "ini", "field": "f20",
"regex": "([\\w].*?)(?=$| -|\\s[0-9].*?|\\s[\\w/]+?:)" "regex": ".{1,20}"
,"retain":"y" ,"retain":"y"
} }
], ],
@ -76,91 +40,4 @@ FROM
} }
$j$::jsonb $j$::jsonb
, 1) , 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 ) x