File size: 5,069 Bytes
84d6b28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
standardize job title, employment type, location, company (department still figuring out how to standardize)
salary min and max format is edited to ensure able to become INT type 
flag potential duplicate jobs
*/

WITH standardized_jobs AS (

    SELECT
        source,
        job_id,
        search_term,
        url,
        collection_timestamp,
        job_title AS job_title_raw,
        -- standardize job_title
        CASE
            WHEN job_title ILIKE '%Data Analyst%' THEN 'Data Analyst'
            WHEN job_title ILIKE '%Data Analytic%' THEN 'Data Analyst'
            WHEN job_title ILIKE '%Data Engineer%' THEN 'Data Engineer'
            WHEN job_title ILIKE '%Data Scientist%' THEN 'Data Scientist'
            WHEN job_title ILIKE '%Data Science%' THEN 'Data Scientist'
            WHEN job_title ILIKE '%AI Engineer%' THEN 'AI Engineer'
            WHEN job_title ILIKE '%Machine Learning Engineer%' THEN 'ML Engineer'
            WHEN job_title ILIKE '%ML Engineer%' THEN 'ML Engineer'
            WHEN job_title ILIKE '%data warehouse developer%' THEN 'Data Warehouse Developer'
            WHEN job_title ILIKE '%database administrator%' THEN 'Database Administrator'
            WHEN job_title ILIKE '%finance analyst%' THEN 'Finance Analyst'
            WHEN job_title ILIKE '%business intelligence analyst%' THEN 'BI Analyst'
            WHEN job_title ILIKE '%bi analyst%' THEN 'BI Analyst'
            WHEN job_title ILIKE '%bi developer%' THEN 'BI Developer'
            WHEN job_title ILIKE '%business analyst%' THEN 'Business Analyst'
            WHEN job_title ILIKE '%analytics engineer%'THEN 'Analytics Engineer'
            ELSE job_title
        END AS job_title_standardized,
        -- standardize company names
        CASE 
            WHEN company ILIKE '%pwc%' THEN 'PwC Malaysia'
            WHEN company ILIKE '%hong leong%' THEN 'Hong Leong'
            WHEN company ILIKE '%luxoft%' THEN 'Luxoft'
            WHEN company ILIKE '%accenture%' THEN 'Accenture'
            WHEN company ILIKE '%shopee%' THEN 'Shopee'
            WHEN company ILIKE '%uob%' THEN 'UOB'
            WHEN company ILIKE '%maybank%' THEN 'Maybank'
            WHEN company ILIKE '%aia%' THEN 'AIA'
            WHEN company ILIKE '%ocbc%' THEN 'OCBC'
            WHEN company ILIKE '%alliance bank%' THEN 'Alliance Bank'
            WHEN company ILIKE '%deloitte%' THEN 'Deloitte'
            ELSE company
        END AS company,
        -- standardize locations
        CASE
            WHEN location ILIKE '%kuala lumpur%' THEN 'Kuala Lumpur'
            ELSE split_part(location, ',', 1)
        END AS location,
        -- standardize employement type 
        CASE
            WHEN job_title ILIKE '%intern%' THEN 'Internship'
            WHEN employment_type ILIKE '%full%time%' THEN 'Full-time'
            WHEN employment_type ILIKE '%part%time%' THEN 'Part-time'
            WHEN employment_type ILIKE '%contract%' THEN 'Contract'
            ELSE employment_type
        END AS employment_type,
        -- no changes for now to department
        department,
        -- edit salary min to reflect correctly
        CAST(
            CASE 
                WHEN salary_min LIKE 'RM%–%per month' 
                THEN NULLIF(TRIM(REPLACE(REPLACE(RIGHT(split_part(salary_min, '–', 1), -3), ',', ''), chr(160), '')), '')
                ELSE NULL 
            END AS INTEGER
        ) AS salary_min,
        -- edit salary max to reflect correctly
        CAST(
            CASE 
                WHEN salary_max LIKE 'RM%–%per month' 
                THEN NULLIF(TRIM(REPLACE(REPLACE(LEFT(RIGHT(split_part(salary_max, '–', -1), -3), -10), ',', ''), chr(160), '')), '')
                ELSE NULL 
            END AS INTEGER
        ) AS salary_max,
        CAST(posting_date AS DATE),
        job_description
    FROM stg_jobs
)

INSERT INTO silver_jobs (

    source,
    job_id,
    search_term,
    url,
    collection_timestamp,
    job_title_raw,
    job_title_standardized,
    company,
    location,
    duplicate_status,
    employment_type,
    department,
    salary_min,
    salary_max,
    posting_date,
    job_description

)

SELECT
    source,
    job_id,
    search_term,
    url,
    collection_timestamp,
    job_title_raw,
    job_title_standardized,
    company,
    location,
    CASE
        -- Same source, same standardized job details
        WHEN COUNT(*) OVER (
            PARTITION BY
                source,
                company,
                job_title_raw,
                location
        ) > 1
        THEN 'Potential Duplicate'
        -- Same job characteristics, but listed on different websites
        WHEN COUNT(*) OVER (
            PARTITION BY
                company,
                job_title_raw,
                location
        ) > 1
        THEN 'Cross-source Match'
        ELSE 'Unique'
    END AS duplicate_status,
    employment_type,
    department,
    salary_min,
    salary_max,
    posting_date,
    job_description

FROM standardized_jobs;
ON CONFLICT 
DO NOTHING;