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

发布于 01-11 20:08 字数 958 浏览 3 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港小镇2025-01-18 20:08:39

这就是您面临的错误。

没有符合签名的函数: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 在自动转换数据类型方面非常糟糕。

This is the error you are facing.

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

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.

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 is very bad in converting data types automatically.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文