我試圖在HiveQL中翻譯不同的PL/SQL腳本。將PL/SQL ETL過程轉換爲HiveQL
這些differents scrip fts用於ETL過程,用於從不同表格導入數據。
我'試圖做同樣的事情在Hadoop的/蜂房,使用HiveQL
但是,這個腳本的人給我一些問題。
這裏是我的PL/SQL腳本:
BEGIN
-- Mise a jour au niveau magasin et famille
MERGE INTO KPI.THM_CA_RGRP_PRODUITS_JOUR cible USING (
SELECT
in_co_societe as CO_SOCIETE,
in_dt_jour as DT_JOUR,
'MAG' as TYPE_ENTITE,
m.co_magasin as CODE_ENTITE,
'FAM' as TYPE_RGRP_PRODUITS,
sourceunion.CO_RGRP_PRODUITS as CO_RGRP_PRODUITS,
SUM(MT_CA_NET_TTC) as MT_CA_NET_TTC,
SUM(MT_OBJ_CA_NET_TTC) as MT_OBJ_CA_NET_TTC,
SUM(NB_CLIENTS) as NB_CLIENTS,
SUM(MT_CA_NET_TTC_COMP) as MT_CA_NET_TTC_COMP,
SUM(MT_OBJ_CA_NET_TTC_COMP) as MT_OBJ_CA_NET_TTC_COMP,
SUM(NB_CLIENTS_COMP) as NB_CLIENTS_COMP
FROM (
-- Mise a jour du CA
SELECT
mtransf.id_mag_transfere as ID_MAGASIN,
v.co_famille as CO_RGRP_PRODUITS,
sum(v.mt_ca_net_ttc) as MT_CA_NET_TTC,
0 as MT_OBJ_CA_NET_TTC,
0 as NB_CLIENTS,
sum(v.mt_ca_net_ttc * DECODE(mtransf.flag_mag_comp, 'NC', 0, 1))
as MT_CA_NET_TTC_COMP,
0 as MT_OBJ_CA_NET_TTC_COMP,
0 as NB_CLIENTS_COMP
FROM themis.VENTES_FAM v
INNER JOIN kpi.kpi_magasin mtransf
ON mtransf.co_societe = CASE WHEN v.co_societe = 1 THEN 1 ELSE 2 END
AND mtransf.id_magasin = v.id_magasin
WHERE
mtransf.co_societe = in_co_societe
AND v.dt_jour = in_dt_jour
GROUP BY
mtransf.id_mag_transfere,
v.co_famille
UNION
-- Mise a jour des Objectifs ->Non car les objectifs ne sont pas d¿¿finis ¿¿ la famille
-- Mise a jour du Nombre de clients
SELECT
mtransf.id_mag_transfere as ID_MAGASIN,
v.co_famille as CO_RGRP_PRODUITS,
0 as MT_CA_NET_TTC,
0 as MT_OBJ_CA_NET_TTC,
sum(nb_client) as NB_CLIENTS,
0 as MT_CA_NET_TTC_COMP,
0 as MT_OBJ_CA_NET_TTC_COMP,
sum(nb_client * DECODE(mtransf.flag_mag_comp, 'NC', 0, 1))
as NB_CLIENTS_COMP
FROM ods.nb_clients_mag_fam_j v
INNER JOIN kpi.kpi_magasin mtransf
ON mtransf.co_societe = CASE WHEN v.co_societe = 1 THEN 1 ELSE 2 END
AND mtransf.id_magasin = v.id_magasin
WHERE
mtransf.co_societe = in_co_societe
AND v.dt_jour = in_dt_jour
GROUP BY
mtransf.id_mag_transfere,
v.co_famille
) sourceunion
INNER JOIN kpi.kpi_magasin m
ON m.co_societe = in_co_societe
AND m.id_magasin = sourceunion.id_magasin
GROUP BY
m.co_magasin,
sourceunion.CO_RGRP_PRODUITS
) source
ON (
cible.co_societe = source.co_societe
and cible.dt_jour = source.dt_jour
and cible.type_entite = source.type_entite
and cible.code_entite = source.code_entite
and cible.type_rgrp_produits = source.type_rgrp_produits
and cible.co_rgrp_produits = source.co_rgrp_produits
)
WHEN NOT MATCHED THEN
INSERT (
cible.CO_SOCIETE,
cible.DT_JOUR,
cible.TYPE_ENTITE,
cible.CODE_ENTITE,
cible.TYPE_RGRP_PRODUITS,
cible.CO_RGRP_PRODUITS,
cible.MT_CA_NET_TTC,
cible.MT_OBJ_CA_NET_TTC,
cible.NB_CLIENTS,
cible.MT_CA_NET_TTC_COMP,
cible.MT_OBJ_CA_NET_TTC_COMP,
cible.NB_CLIENTS_COMP
)
VALUES (
source.CO_SOCIETE,
source.DT_JOUR,
source.TYPE_ENTITE,
source.CODE_ENTITE,
source.TYPE_RGRP_PRODUITS,
source.CO_RGRP_PRODUITS,
source.MT_CA_NET_TTC,
source.MT_OBJ_CA_NET_TTC,
source.NB_CLIENTS,
source.MT_CA_NET_TTC_COMP,
source.MT_OBJ_CA_NET_TTC_COMP,
source.NB_CLIENTS_COMP
);
有沒有辦法用蜂巢做到這一點?
感謝您的幫助。
我建議你開始簡單的例子..它會幫助你理解問題。您給出的例子很複雜..將無法直接回答。 – Sanjiv