我试图用(select,join)查询将数据添加到impala的新列中,一旦我将数据添加到新列中,我将丢失其他列的所有数据(它们将变为null)。
我在这里创建第一个表:
CREATE TABLE mng_exp.KPI_LATENCE_JOUR
(
CODEINSEE INT,
IMEI BIGINT,
SEMAINE INT,
MOYENNE_LATENCE INT,
MAXIMUM_LATENCE INT,
MINIMUM_LATENCE INT
)
我将数据添加到表中:
INSERT INTO mng_exp.KPI_LATENCE_JOUR (CODEINSEE,IMEI, SEMAINE, MOYENNE_LATENCE,MAXIMUM_LATENCE,MINIMUM_LATENCE,TRANCHE_DE_LATENCE)
SELECT codeinsee, device_dim__imei as IMEI,weekofyear(jour) as SEMAINE, cast(round(avg(rtt_avg_ms)) as integer) as MOYENNE_LATENCE,
cast(round(avg(rtt_max_ms)) as integer) as MAXIMUM_LATENCE, cast(round(avg(rtt_min_ms)) as integer) as MINIMUM_LATENCE ,
CASE WHEN ( round(avg(rtt_avg_ms)) > 0 and round(avg(rtt_avg_ms)) <= 10 ) THEN 0
WHEN ( round(avg(rtt_avg_ms)) > 10 and round(avg(rtt_avg_ms)) <= 20 ) THEN 1
WHEN ( round(avg(rtt_avg_ms)) > 20 and round(avg(rtt_avg_ms)) <= 30 ) THEN 2
WHEN ( round(avg(rtt_avg_ms)) > 30 ) THEN 3 END AS Tranche_de_latence
FROM mscore.mscore where operateur = 'BT_HZ' and year(jour) = 2019 group by device_dim__imei,weekofyear(jour),codeinsee
# I Add a new column
ALTER TABLE mng_exp.kpi_latence_jour ADD COLUMNS (srv_id BIGINT)
# Here data is good and new column srv_id is NULL
我将数据添加到新列:
INSERT INTO mng_exp.KPI_LATENCE_jour (srv_id)
SELECT CAST(dng_fai_cli_eqt_iad.srv_id AS BIGINT)
FROM msf_exploratoire.dng_fai_cli_eqt_iad
INNER JOIN mng_exp.kpi_latence_jour ON (dng_fai_cli_eqt_iad.num_serie = kpi_latence_jour.imei);
问题是: srv_id
则旧列变为空。
我没有查询错误,但是我丢失了所有的旧数据
2条答案
按热度按时间mefy6pfw1#
是否确实丢失了所有旧数据或执行了以下操作:
select * from mng_exp.KPI_LATENCE_JOUR
您还将看到:第一组行(srv\u id为空的行);
第二组行-其中唯一填充的列是srv\u id?
您需要的是更新第一组行的srv\u id。
您可以在imapala中看到有关更新的更多详细信息。
dgjrabp22#
您只能插入一列。使用“插入”“覆盖”并添加所有其他列: