配置单元错误“函数if的第二个和第三个参数应该具有相同的类型,但它们不同:“timestamp”和“string”

xxls0lw8  于 2021-06-26  发布在  Hive
关注(0)|答案(1)|浏览(195)

我在配置单元中遇到以下错误:
函数if的第二个和第三个参数应具有相同的类型,但它们不同:“timestamp”和“string”
以下是查询:

with cte_fix_on_time AS (

SELECT 
	*, 
 	SPLIT(from_unixtime(unix_timestamp(CAST(timestamp AS STRING),'yyyyMMddHHmmss'),'yyyy-MM-dd HH:mm:ss'),' ')[0] as bl_date,
	SPLIT(from_unixtime(unix_timestamp(CAST(timestamp AS STRING),'yyyyMMddHHmmss'),'yyyy-MM-dd HH:mm:ss'),' ')[1] as bl_time
FROM 
	table
)

SELECT 
	*,
	SUM(baseline_visits) OVER(ORDER BY locale, CAST(timestamp AS INT) ROWS BETWEEN CURRENT ROW AND 4 FOLLOWING) as bl_ad_visits,
	IF(CAST(CONCAT(bl_date,' ',bl_time) AS STRING)<'2016-03-08 00:00:00'),to_utc_timestamp(CAST(CONCAT(bl_date,' ',bl_time) AS STRING), 'CET'),CAST(CONCAT(bl_date,' ',bl_time) AS STRING)) as utc_timestamp,
	SPLIT(CAST(IF((CAST(CONCAT(bl_date,' ',bl_time) AS STRING)< '2016-03-08 00:00:00'),to_utc_timestamp(CAST(CONCAT(bl_date,' ',bl_time) AS STRING), 'CET'),CAST(CONCAT(bl_date,' ',bl_time) AS STRING)) as STRING),' ')[0] as utc_date,
	SPLIT(CAST(IF((CAST(CONCAT(bl_date,' ',bl_time) AS STRING)< '2016-03-08 00:00:00'),to_utc_timestamp(CAST(CONCAT(bl_date,' ',bl_time) AS STRING), 'CET'),CAST(CONCAT(bl_date,' ',bl_time) AS STRING)) as STRING),' ')[1] as utc_time
FROM 
	cte_fix_on_time

非常感谢您的帮助

dgjrabp2

dgjrabp21#

第二个参数(“then”部分)是一个时间戳: to_utc_timestamp(CAST(CONCAT(bl_date,' ',bl_time) AS STRING) .
第三个参数(“else”部分)是一个字符串: CAST(CONCAT(bl_date,' ',bl_time) AS STRING) .
你需要使用 to_utc_timestamp 在你的第三个论点或停止使用它在你的第二个。

相关问题