如何在 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 中,如何在条件函数内连接字符串和整数?
In hive
select concat("Positive", 123);
Positive123
select if("Positive" in ('Negative', 'No', 'Sub-zero'), 123, concat("Positive",123));
Positive123
But in Impala
:
select concat("Positive", 123);
AnalysisException: No matching function with signature: concat(STRING, TINYINT).
Using CAST works:
select concat("Positive", cast(123 as string));
Positive123
But
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).
How can I concatenate a string and an integer inside a conditional function if in Impala?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

这就是您面临的错误。
您需要将所有内容转换为一种单一类型的数据类型 - 例如字符串。因此,解决方案是将真实情况也转换为字符串。
下面是重写 SQL 的方法。
Impala 在自动转换数据类型方面非常糟糕。
This is the error you are facing.
You need to convert everything to one single type of data type - like string. So, solution is to cast the true case to string as well.
So here is how you can rewrite the SQL.
Impala is very bad in converting data types automatically.