2017-07-28 68 views
0

如何在Impala中插入Infinity和NaN。同樣的測試適用於Hive,但在Impala中發生錯誤。如何在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。

回答

0

根據Impala Mathematical Functions,您缺少CAST(x AS DOUBLE)

Infinity和NaN可以在文本數據文件中分別指定爲inf和nan,Impala將它們解釋爲這些特殊值。它們也可以由某些算術表達式產生;例如,1/0返回無窮大,pow(-1,0.5)返回NaN。或者您可以投射文字值,例如CAST('nan'AS DOUBLE)或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