AnalysisException:没有带签名的匹配函数:rtrim(VARCHAR(40), STRING)

AnalysisException: No matching function with signature: rtrim(VARCHAR(40), STRING)

我在 table(包括 % 字符)中的值为 58.3308%,我需要输出 0.583308,并且下面的 SQL 查询在 SQL 控制台中工作正常

select to_char((rtrim('58.3308%', '%') /100), '0.999999') from dual;

但是我在 python 代码中遇到了这个错误,这是一个 hive/impala 问题,对吗?

AnalysisException: No matching function with signature: rtrim(VARCHAR(40), STRING)

非常感谢您的建议

根据 Hive manual,rtrim 仅删除空格,因此不采用第二个参数。如果要删除其他字符,请考虑使用 regexp_replace,如 regexp_replace('58.3308%', '%', '')

根据文档:

rtrim(string A)

Returns the string resulting from trimming spaces from the end(right hand side) of A. For example, rtrim(' foobar ') results in ' foobar'.

regexp_replace(string INITIAL_STRING, string PATTERN, string REPLACEMENT)

Returns the string resulting from replacing all substrings in INITIAL_STRING that match the java regular expression syntax defined in PATTERN with instances of REPLACEMENT. For example, regexp_replace("foobar", "oo|ar", "") returns 'fb.' Note that some care is necessary in using predefined character classes: using '\s' as the second argument will match the letter s; '\s' is necessary to match whitespace, etc.

顺便说一下,这个操作的结果是一个字符串,所以为了安全起见,你应该把它转换成浮点数。

你可以使用 split

select split('58.3308%', '%')[0] /100 as v
+--------+
|       v|
+--------+
|0.583308|
+--------+