I need to generate a segment array using the segment values and their thresholds in 2 different datasets. Is there a simple way to do this in pyspark or hive sql?
Segment values dataset:
--------------------------------------------------
| user_id | seg1 | seg2 | seg3 | seg4 | seg5 |
------------------------------------------------
| 100 | 90 | 20 | 76 | 100 | 30 |
| 200 | 56 | 15 | 67 | 99 | 25 |
| 300 | 87 | 38 | 45 | 97 | 40 |
--------------------------------------------------
segment threshold dataset:
---------------------------
|seg_name | seg_threshold |
---------------------------
| seg1 | 83 |
| seg2 | 25 |
| seg3 | 60 |
| seg4 | 98 |
| seg5 | 35 |
---------------------------
If the value for a segment is higher than the threshold, the user should be considered to be part of the segment. Segment array for that user should include the segment names(column headers).
Expected output:
-------------------------------------
| user_id| segment_array |
-------------------------------------
| 100 | [seg1, seg3, seg4] |
| 200 | [seg3, seg4] |
| 300 | [seg1, seg2, seg5] |
-------------------------------------
Please note that this is just an indicative dataset. I have several hundreds of segments like these.
Thank you for your help!