tps/sample_discovercard/mapping.md

169 lines
8.4 KiB
Markdown
Raw Normal View History

2018-02-21 00:41:46 -05:00
regular expression screen
---------------------------------------------
```
+------------------------+----+
source | DCARD | \/ |
+-----------------------------+
+-----------------------------+
new name |First 20 |
+-----------------------------+
+-----------------------------+
function | extract(replace) | \/ |
+------------------------+----+
(each block is a regex, all blocks are concatenated into an array and linked to mapped ^alues)
first 20 characters
+----------------------------------+
+----------------------------------------------------------------------------------------------------+
+ | +-----------------------------+ |
| | Field Name| Description | \/| expressed as jsonb path "{Description}") |
+-------+ | +-----------------------------+ |
| | +-------------------------+ |
+ |label of return ^alue |f20 | |
| +-------------------------+ |
| +-------------------------+ |
| regular expression |.{1,20} | supply test run ^alues |
| +-------------------------+ |
| +-------------------------+ |
| replace wit | | |
| +-------------------------+ |
| +---+ |
| Map Results|Y/N| |
| +---+ |
| +---+ |
| Find All Matches| g | |
| +---+ |
| filter(s) |
| +-------------------------------------------+ |
| +----------------+ +----------------+ |
| |Category | |Restaurantes | |
| +----------------+ +----------------+ |
| +----------------+ +----------------+ |
| |Category | |Services | |
| +----------------+ +----------------+ |
| |
+----------------------------------------------------------------------------------------------------+
```
2018-02-17 13:57:14 -05:00
map definition
----------------------------------------------------------
{
"defn": [
{
"key": "{Description}",
"map": "y",
2018-02-21 00:41:46 -05:00
"flag": "g",
2018-02-17 13:57:14 -05:00
"field": "f20",
"regex": ".{1,20}",
"retain": "y"
}
],
"name": "First 20",
"where": [
2018-02-21 00:41:46 -05:00
{"Category":"Restaurantes"},
{"Category":"Services"}
2018-02-17 13:57:14 -05:00
],
"function": "extract",
"description": "pull first 20 characters from description for mapping"
}
2018-02-26 15:22:38 -05:00
SQL
---------------------------------------------
SELECT
2018-03-01 01:22:59 -05:00
x.x
FROM
tps.srce_map_def_set(
2018-03-01 01:22:59 -05:00
'DCARD'::text,
'First 20'::text,
2018-02-26 15:22:38 -05:00
$$ {
"defn": [
{
"key": "{Description}",
"map": "y",
"flag": "",
2018-02-26 15:22:38 -05:00
"field": "f20",
"regex": ".{1,20}",
"retain": "y"
}
],
"name": "First 20",
"where": [
2018-03-10 14:03:52 -05:00
{}
2018-02-26 15:22:38 -05:00
],
"function": "extract",
"description": "pull first 20 characters from description for mapping"
} $$::jsonb,
2018-03-01 01:22:59 -05:00
1::int
) x(x)
2018-02-17 13:57:14 -05:00
2018-02-21 00:41:46 -05:00
assign new key/values to the results of the regular expression, and then back to the underlying row it came from
-----------------------------------------------------------------------------------------------------------------
2018-02-26 16:50:34 -05:00
| returned from expression | party | reason | city | provice | |
| ------------------------------- | ----------------- | ------------- | ------ | ------- | --- |
| {"f20": "BIG LOTS #00453 STOW"} | Big Lots | Home Supplies | Stow | Ohio | |
| {"f20": "1794MOTHERHOOD #1794"} | Motherhood | Clothes | | | |
| {"f20": "3 PALMS HUDSON OH"} | 3 Palms | Restaurantes | Hudson | Ohio | |
| {"f20": "36241 7-ELEVEN STOW "} | 7-Eleven | Gasoline | Stow | Ohio | |
| {"f20": "7-ELEVEN 36241 STOW "} | 7-Eleven | Gasoline | Stow | Ohio | |
| {"f20": "98626 - 200 PUBLIC S"} | Public Sq Parking | Recreation | | | |
| {"f20": "ACE HARDWARE HUDSON "} | Ace Hardware | Home Maint | Hudson | Ohio | |
| {"f20": "ACH CAFE AND STARBUC"} | Starbucks | Restaurantes | | | |
function call to setup a a new map value
---------------------------------------------
SELECT
x.message
FROM
tps.srce_map_val_set(
'DCARD'
,'First 20'
,'{"f20": "DISCOUNT DRUG MART 3"}'::JSONB
,'{"party":"Discount Drug Mart","reason":"groceries"}'::JSONB
) x(message);
function call to re-run all the maps for a source
----------------------------------------------------
SELECT
x.message
FROM
tps.srce_map_overwrite('DCARD') x(message);
mass insert
------------------------------------------------------
INSERT INTO
tps.map_rv
SELECT
*
FROM
(
VALUES
('DCARD','First 20','{"f20": "DISCOUNT DRUG MART 3"}','{"party":"Discount Drug Mart","reason":"groceries"}'),
('DCARD','First 20','{"f20": "TARGET STOW OH"}','{"party":"Target","reason":"groceries"}'),
('DCARD','First 20','{"f20": "WALMART GROCERY 800-"}','{"party":"Walmart","reason":"groceries"}'),
('DCARD','First 20','{"f20": "CIRCLE K 05416 STOW "}','{"party":"Circle K","reason":"gasoline"}'),
('DCARD','First 20','{"f20": "TARGET.COM * 800-591"}','{"party":"Target","reason":"home supplies"}'),
('DCARD','First 20','{"f20": "ACME NO. 17 STOW OH"}','{"party":"Acme","reason":"groceries"}'),
('DCARD','First 20','{"f20": "AT&T *PAYMENT 800-28"}','{"party":"AT&T","reason":"internet"}'),
('DCARD','First 20','{"f20": "AUTOZONE #0722 STOW "}','{"party":"Autozone","reason":"auto maint"}'),
('DCARD','First 20','{"f20": "BESTBUYCOM8055267948"}','{"party":"BestBuy","reason":"home supplies"}'),
('DCARD','First 20','{"f20": "BUFFALO WILD WINGS K"}','{"party":"Buffalo Wild Wings","reason":"restaurante"}'),
('DCARD','First 20','{"f20": "CASHBACK BONUS REDEM"}','{"party":"Discover Card","reason":"financing"}'),
('DCARD','First 20','{"f20": "CLE CLINIC PT PMTS 2"}','{"party":"Cleveland Clinic","reason":"medical"}')
) x