如何在 Impala 中的条件函数内连接字符串和整数

How to concatenate a string and an integer inside a conditional function in Impala

hive

select concat("Positive", 123);

Positive123
select if("Positive" in ('Negative', 'No', 'Sub-zero'), 123, concat("Positive",123));

Positive123

但在 Impala:

select concat("Positive", 123);

AnalysisException: No matching function with signature: concat(STRING, TINYINT).

使用 CAST 有效:

select concat("Positive", cast(123 as string));

Positive123

但是

select if("Positive" in ('Negative', 'No', 'Sub-zero'),
          123,
          concat("Positive", cast(123 as string))
          );

AnalysisException: No matching function with signature: if(BOOLEAN, TINYINT, STRING).

如果在 Impala 中,如何在条件函数中连接字符串和整数?

这是您遇到的错误。

No matching function with signature: if(BOOLEAN, TINYINT, STRING).

您需要将所有内容转换为一种单一类型的数据类型 - 例如字符串。因此,解决方案是将真实情况也转换为字符串。
所以这里是你如何重写 SQL.

select if("Positive" in ('Negative', 'No', 'Sub-zero'),
          cast(123 as string),  -- cast the true case to string.
          concat("Positive", cast(123 as string))
          );

Impala自动转换数据类型很糟糕