%jdbc(hive)
set tez.queue.name=default;
set hive.execution.engine=tez;
SELECT '2022' AS year, monthNo, 'MIN + FULL' as kyc, P.catg as risk_catg
, 'Hourly' as Frequency
-- , 'Daily' as Frequency
-- , 'Monthly' as Frequency
, P.breaches
, 'WalletTopupTxnCntHourly' as rule
-- , 'WalletTopupTxnCntDaily' as rule
-- , 'WalletTopupTxnCntMonthly' as rule
FROM
(SELECT Z.monthNo, Z.catg, SUM(IF(Z.txns >= Z.limit, 1, 0)) AS breaches FROM
(SELECT A.monthNo, A.senderuserid, A.transaction_id, COUNT(DISTINCT B.transaction_id) as txns,
IF(C.hml_category IS NOT NULL, C.hml_category, 'LOW RISK') AS catg,
CASE WHEN C.hml_category = 'HIGH RISK' THEN 2 WHEN C.hml_category = 'MEDIUM RISK' THEN 3 ELSE 5 END AS limit
-- CASE WHEN C.hml_category = 'HIGH RISK' THEN 5 WHEN C.hml_category = 'MEDIUM RISK' THEN 8 ELSE 10 END AS limit
-- CASE WHEN C.hml_category = 'HIGH RISK' THEN 60 WHEN C.hml_category = 'MEDIUM RISK' THEN 80 ELSE 100 END AS limit
FROM
(SELECT DISTINCT senderuserid, transaction_id, transaction_time AS txnTime, month(updated_date) as monthNo
from fraud.transaction_details_v3
where year(updated_date) = 2022 and month(updated_date) = 11
and sendertype = 'INTERNAL_USER' AND workflowtype = 'CONSUMER_TO_MERCHANT'
and pay_transaction_status = 'COMPLETED' AND errorcode = 'SUCCESS'
and receiveruser in ('PHONEPEWALLETTOPUP','NEXUSWALLETTOPUP'))A
LEFT JOIN
(SELECT DISTINCT senderuserid, transaction_id, transaction_time AS txnTime, month(updated_date) as monthNo
from fraud.transaction_details_v3
where year(updated_date) = 2022 and month(updated_date) IN (11-1,11)
and sendertype = 'INTERNAL_USER' AND workflowtype = 'CONSUMER_TO_MERCHANT'
and pay_transaction_status = 'COMPLETED' AND errorcode = 'SUCCESS'
and receiveruser in ('PHONEPEWALLETTOPUP','NEXUSWALLETTOPUP'))B
ON A.senderuserid = B.senderuserid AND A.monthNo >= B.monthNo
AND ((UNIX_TIMESTAMP(A.txnTime) - UNIX_TIMESTAMP(B.txnTime))/3600) BETWEEN 0 AND 1
-- AND ((UNIX_TIMESTAMP(A.txnTime) - UNIX_TIMESTAMP(B.txnTime))/86400) BETWEEN 0 AND 1
-- AND ((UNIX_TIMESTAMP(A.txnTime) - UNIX_TIMESTAMP(B.txnTime))/2592000) BETWEEN 0 AND 1
AND A.txnTime > B.txnTime
LEFT JOIN
(SELECT DISTINCT senderuserid, hml_category
FROM fraud.hml_classification)C
ON A.senderuserid = C.senderuserid
GROUP BY A.senderuserid, A.transaction_id, C.hml_category, A.monthNo
HAVING txns >= 5)Z
GROUP BY Z.catg, Z.monthNo)P
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter