У меня есть SQL-запрос, к которому я должен получить доступ в PySpark (DataBricks).из-за сложного запроса PySpark не может прочитать то же самое.Может ли кто-нибудь проверить мой запрос и помочь мне записать этот запрос в одном операторе «SELECT», не используя оператор «WITH».
promotions = """
(WITH VCTE_Promotions as
(SELECT v.Shortname,
v.Employee_ID_ALT, v.Job_Level,
v.Management_Level,
CAST(sysdatetime() AS date) AS PIT_Date,
v.Employee_Status_Alt as Employee_Status,
v.Work_Location_Region, v.Work_Location_Country_Desc, v.HML,
dbo.T_Mngmt_Level_IsManager_Mapping.IsManager
FROM Worker_CUR as v LEFT OUTER JOIN
dbo.T_Mngmt_Level_IsManager_Mapping ON v.Management_Level = dbo.T_Mngmt_Level_IsManager_Mapping.Management_Level),
VCTE_Promotion_v2_Eval as (
SELECT Employee_ID_ALT,
(SELECT MAX(PIT_Date) AS prior_data
FROM dbo.V_Worker_PIT_with_IsManager AS t
WHERE (employee_id_alt = a.Employee_ID_ALT) AND (PIT_Date < a.PIT_Date) AND (IsManager <> a.IsManager) OR
(employee_id_alt = a.Employee_ID_ALT) AND (PIT_Date < a.PIT_Date) AND (Job_Level <> a.Job_Level)) AS prev_job_change_date, IsManager
FROM VCTE_Promotions AS a)
SELECT VCTE_Promotion_v2_Eval.Employee_ID_ALT,
COALESCE (v_cur.Employee_Type, N'') AS Curr_Employee_Type,
v_cur.Review_Rating_Current
FROM VCTE_Promotion_v2_Eval INNER JOIN
[DM_GlobalStaff].[dbo].[V_Worker_CUR] as v_cur ON VCTE_Promotion_v2_Eval.Employee_ID_ALT = v_cur.Employee_ID_ALT LEFT OUTER JOIN
dbo.V_Worker_PIT_with_IsManager as v_m ON VCTE_Promotion_v2_Eval.prev_job_change_date = v_m.PIT_Date AND
VCTE_Promotion_v2_Eval.Employee_ID_ALT = v_m.employee_id_alt ) as promotions
"""
promotions = spark.read.jdbc(url=jdbcUrl, table=promotions, properties=connectionProperties)
Ваша помощь по подсказкам будет высоко оценена.