%jdbc(hive) set tez.queue.name=default; set hive.execution.engine=tez; SELECT '2022' AS year, Z.month, 'MIN + FULL' as kyc, Z.risk_catg , 'Hourly' as Frequency -- , 'Daily' as Frequency -- , 'Monthly' as Frequency , SUM(IF(Z.receivers >= Z.limit, 1, 0)) AS breaches , 'egvGiftReceiversHourly' as Rule -- , 'egvGiftReceiversDaily' as Rule -- , 'egvGiftReceiversMonthly' as Rule FROM (SELECT A.user_id, A.txn_id, month(A.txnTime) as month, COUNT(DISTINCT B.user_id) as receivers, IF(C.hml_category IS NOT NULL, C.hml_category, 'LOW RISK') AS risk_catg, CASE WHEN C.hml_category = 'HIGH RISK' THEN 5 WHEN C.hml_category = 'MEDIUM RISK' THEN 10 ELSE 15 END AS limit -- CASE WHEN C.hml_category = 'HIGH RISK' THEN 10 WHEN C.hml_category = 'MEDIUM RISK' THEN 20 ELSE 25 END AS limit -- CASE WHEN C.hml_category = 'HIGH RISK' THEN 100 WHEN C.hml_category = 'MEDIUM RISK' THEN 150 ELSE 200 END AS limit FROM (SELECT DISTINCT purchasing_user_id, user_id, phonepe_transaction_id AS txn_id, created_at as txnTime FROM egv.gift_cards WHERE year = 2022 AND month = 11 AND gift_card_status NOT IN ('BLOCKED', 'CANCELLED') AND card_link_state = 'LINKED')A INNER JOIN (SELECT DISTINCT purchasing_user_id, user_id, phonepe_transaction_id AS txn_id, created_at as txnTime FROM egv.gift_cards WHERE year = 2022 AND month = 11 AND gift_card_status NOT IN ('BLOCKED', 'CANCELLED') AND card_link_state = 'LINKED')B ON A.purchasing_user_id = B.purchasing_user_id AND A.user_id <> B.user_id AND A.txn_id <> B.txn_id 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 LEFT JOIN (SELECT DISTINCT senderuserid, hml_category FROM fraud.hml_classification)C ON A.user_id = C.senderuserid GROUP BY A.user_id, A.txn_id, month(A.txnTime), C.hml_category)Z GROUP BY Z.month, Z.risk_catg
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