如何在视图中添加新列?

How to add a new column in a view?

我有这样的看法:

CREATE VIEW VW_my_table_test AS
select
extract_dt,
path,
split_part(`path`, '/', 5) `DataBAse`,
modificationtime,
to_timestamp(accesstime, 'yyyy-MM-dd HH:mm') as accesstime ,
"replication",
datediff(from_unixtime(unix_timestamp(now()),'yyyy-MM-dd'),to_timestamp(accesstime, 'yyyy-MM-dd HH:mm'))AS QT_DIAS_SEM_ACESSO,
CASE WHEN datediff(from_unixtime(unix_timestamp(now()),'yyyy-MM-dd'),to_timestamp(accesstime, 'yyyy-MM-dd HH:mm')) < 31 then '1' ELSE '0' END AS IN_INF_HOT_ACESSO,
CASE WHEN datediff(from_unixtime(unix_timestamp(now()),'yyyy-MM-dd'),to_timestamp(accesstime, 'yyyy-MM-dd HH:mm')) > 30 and datediff(from_unixtime(unix_timestamp(now()),'yyyy-MM-dd'),to_timestamp(accesstime, 'yyyy-MM-dd HH:mm')) < 121 then '1' ELSE '0' END AS IN_INF_COLD_ACESSO,
CASE WHEN datediff(from_unixtime(unix_timestamp(now()),'yyyy-MM-dd'),to_timestamp(accesstime, 'yyyy-MM-dd HH:mm')) > 120 then '1' ELSE '0' END AS IN_INF_FROZEN_ACESSO,
CASE WHEN datediff(from_unixtime(unix_timestamp(now()),'yyyy-MM-dd'),to_timestamp(modificationtime, 'yyyy-MM-dd HH:mm')) < 31 then '1' ELSE '0' END AS IN_INF_HOT_MODIFICACAO,
CASE WHEN datediff(from_unixtime(unix_timestamp(now()),'yyyy-MM-dd'),to_timestamp(modificationtime, 'yyyy-MM-dd HH:mm')) > 30 and datediff(from_unixtime(unix_timestamp(now()),'yyyy-MM-dd'),to_timestamp(accesstime, 'yyyy-MM-dd HH:mm')) < 121 then '1' ELSE '0' END AS IN_INF_COLD_IN_INF_HOT_MODIFICACAO,
CASE WHEN datediff(from_unixtime(unix_timestamp(now()),'yyyy-MM-dd'),to_timestamp(modificationtime, 'yyyy-MM-dd HH:mm')) > 120 then '1' ELSE '0' END AS IN_INF_FROZEN_IN_INF_HOT_MODIFICACAO,

from_unixtime(unix_timestamp(now()),'yyyy-MM-dd')
from my_table_test

而且我想添加一个具有以下复制代码的新列:

datediff(from_unixtime(unix_timestamp(now()),'yyyy-MM-dd'),to_timestamp(accesstime, 'yyyy-MM-dd HH:mm'))AS QT_DIAS_SEM_MODIFICACAO,

但是他returns错误:

AnalysisException: Table already exists: dbdl_sbox_dados.VW_my_table_test

我想删除这个已经存在的table,但我不知道这是否是最好的方法。

我该怎么做?

我设法使用 DROP 解决了它:

DROP VIEW VW_my_table_test

然后我运行代码已经有了变化。

您可以使用更改视图。它更好,因为如果脚本不正确,它将失败。但是如果您遗漏了脚本中的某些内容并且无法快速解决问题,则其他一些过程可能会失败。

ALTER VIEW dbdl_sbox_dados.VW_my_table_test 
AS
SQL WITH NEW COL