如何在 Impala Table 中插入无穷大
How to insert infinity in Impala Table
如何在 Impala 中插入无穷大和 NaN。相同的测试适用于 Hive,但在 Impala.
中抛出错误
> create table z2 (x double);
> insert into z2 values (1),("NaN"),("Infinity"),("-Infinity");
Query: insert into z1 values (1),("NaN"),("Infinity"),("-Infinity")
ERROR: AnalysisException: Incompatible return types 'TINYINT' and 'STRING' of
exprs '1' and ''NaN''.
谁能告诉我如何为 Impala 解决这个问题。
根据 Impala Mathematical Functions,您缺少 CAST(x AS DOUBLE)
。
Infinity and NaN can be specified in text data files as inf and nan respectively, and Impala interprets them as these special values. They can also be produced by certain arithmetic expressions; for example, 1/0 returns Infinity and pow(-1, 0.5) returns NaN. Or you can cast the literal values, such as CAST('nan' AS DOUBLE) or CAST('inf' AS DOUBLE).
因此您的插入内容应为:
> insert into z2 values (1), (CAST ('nan' AS DOUBLE)),
(CAST ('inf' AS DOUBLE)), (- CAST ('inf' AS DOUBLE));
然后你会看到:
> select * from z2;
+-----------+
| x |
+-----------+
| 1 |
| NaN |
| Infinity |
| -Infinity |
+-----------+
Fetched 4 row(s) in 0.12s
如何在 Impala 中插入无穷大和 NaN。相同的测试适用于 Hive,但在 Impala.
中抛出错误> create table z2 (x double);
> insert into z2 values (1),("NaN"),("Infinity"),("-Infinity");
Query: insert into z1 values (1),("NaN"),("Infinity"),("-Infinity")
ERROR: AnalysisException: Incompatible return types 'TINYINT' and 'STRING' of
exprs '1' and ''NaN''.
谁能告诉我如何为 Impala 解决这个问题。
根据 Impala Mathematical Functions,您缺少 CAST(x AS DOUBLE)
。
Infinity and NaN can be specified in text data files as inf and nan respectively, and Impala interprets them as these special values. They can also be produced by certain arithmetic expressions; for example, 1/0 returns Infinity and pow(-1, 0.5) returns NaN. Or you can cast the literal values, such as CAST('nan' AS DOUBLE) or CAST('inf' AS DOUBLE).
因此您的插入内容应为:
> insert into z2 values (1), (CAST ('nan' AS DOUBLE)),
(CAST ('inf' AS DOUBLE)), (- CAST ('inf' AS DOUBLE));
然后你会看到:
> select * from z2;
+-----------+
| x |
+-----------+
| 1 |
| NaN |
| Infinity |
| -Infinity |
+-----------+
Fetched 4 row(s) in 0.12s