implement sequence of target, and insure that the link to the map does not return duplicates

This commit is contained in:
Paul Trowbridge 2017-10-27 13:06:44 -04:00
parent 6b08ea8fb8
commit 4a62ca84b1
2 changed files with 14 additions and 8 deletions

View File

@ -9,6 +9,7 @@ SELECT
t.id, t.id,
t.rec, t.rec,
m.target, m.target,
m.seq,
regex->>'map' map_intention, regex->>'map' map_intention,
regex->>'function' regex_function, regex->>'function' regex_function,
e.v ->> 'field' result_key_name, e.v ->> 'field' result_key_name,
@ -75,9 +76,9 @@ FROM
m.regex->>'function' = 'extract' m.regex->>'function' = 'extract'
LEFT JOIN LATERAL regexp_replace(t.rec #>> ((e.v ->> 'key')::text[]), e.v ->> 'regex'::text, e.v ->> 'replace'::text,e.v ->> 'flag') WITH ORDINALITY rp(rp, rn) ON LEFT JOIN LATERAL regexp_replace(t.rec #>> ((e.v ->> 'key')::text[]), e.v ->> 'regex'::text, e.v ->> 'replace'::text,e.v ->> 'flag') WITH ORDINALITY rp(rp, rn) ON
m.regex->>'function' = 'replace' m.regex->>'function' = 'replace'
WHERE --WHERE
--t.srce = 'PNCC' --t.srce = 'PNCC'
rec @> '{"Transaction":"ACH Credits","Transaction":"ACH Debits"}' --rec @> '{"Transaction":"ACH Credits","Transaction":"ACH Debits"}'
--rec @> '{"Description":"CHECK 93013270 086129935"}'::jsonb --rec @> '{"Description":"CHECK 93013270 086129935"}'::jsonb
ORDER BY ORDER BY
t.id DESC, t.id DESC,
@ -93,6 +94,7 @@ SELECT
srce srce
,id ,id
,target ,target
,seq
,map_intention ,map_intention
,regex_function ,regex_function
,target_item_number ,target_item_number
@ -132,6 +134,7 @@ GROUP BY
srce srce
,id ,id
,target ,target
,seq
,map_intention ,map_intention
,regex_function ,regex_function
,target_item_number ,target_item_number
@ -148,6 +151,7 @@ SELECT
srce srce
,id ,id
,target ,target
,seq
,map_intention ,map_intention
,tps.jsonb_concat_obj(COALESCE(map_val,'{}'::JSONB)) map_val ,tps.jsonb_concat_obj(COALESCE(map_val,'{}'::JSONB)) map_val
,jsonb_strip_nulls(tps.jsonb_concat_obj(COALESCE(retain_val,'{}'::JSONB))) retain_val ,jsonb_strip_nulls(tps.jsonb_concat_obj(COALESCE(retain_val,'{}'::JSONB))) retain_val
@ -157,6 +161,7 @@ GROUP BY
srce srce
,id ,id
,target ,target
,seq
,map_intention ,map_intention
ORDER BY ORDER BY
id id
@ -171,6 +176,7 @@ SELECT
a.srce a.srce
,a.id ,a.id
,a.target ,a.target
,a.seq
,a.map_intention ,a.map_intention
,a.map_val ,a.map_val
,a.retain_val retain_value ,a.retain_val retain_value
@ -189,7 +195,7 @@ FROM
SELECT SELECT
srce srce
,id ,id
,tps.jsonb_concat_obj(COALESCE(retain_value,'{}'::jsonb)) retain_val ,tps.jsonb_concat_obj(COALESCE(retain_value,'{}'::jsonb) ORDER BY seq DESC) retain_val
,tps.jsonb_concat_obj(COALESCE(map,'{}'::jsonb)) map ,tps.jsonb_concat_obj(COALESCE(map,'{}'::jsonb)) map
FROM FROM
link_map link_map
@ -198,9 +204,10 @@ GROUP BY
,id ,id
) )
SELECT srce, id, jsonb_pretty(retain_val), jsonb_pretty(map) FROM agg_to_id --SELECT agg_to_id.srce, agg_to_id.id, jsonb_pretty(agg_to_id.retain_val) , jsonb_pretty(agg_to_id.map) FROM agg_to_id ORDER BY id desc LIMIT 100
/*
UPDATE UPDATE
tps.trans t tps.trans t
SET SET
@ -211,4 +218,3 @@ FROM
agg_to_id o agg_to_id o
WHERE WHERE
o.id = t.id; o.id = t.id;
*/

View File

@ -17,8 +17,8 @@ applied mappings are in associated jsonb documents
1. regular expressions are used to extract pieces of the json objects 1. regular expressions are used to extract pieces of the json objects
2. the results of the regular expressions are bumped up against a list of basic mappings and written to an associated jsonb document 2. the results of the regular expressions are bumped up against a list of basic mappings and written to an associated jsonb document
a target represents a whole scenario that needs matched. it can contain several regex expressions. if one fails, then no match is attempted because it coudl result in a false positive based on the @> oeprator used at join time each regex expression within a targeted pattern can be set to map or not. then the mapping items should be joined to map_rv with an `=` as opposed to `@>` to avoid duplication of rows
`this probably isn't correctly implemented`
## Transformation tools ## Transformation tools
* `COPY` * `COPY`