我有一个 HiveQL 查询,看起来像:
SELECT ID,
CASE WHEN col_a = 0 THEN 0
ELSE (col_b / col_a) END AS math_is_fun
FROM (/* derived query*/) AS x ;
当我在 Hive 中执行此操作时,我最近开始收到错误FAILED: Error in semantic analysis: Line X:Y ArgumentTypeMismatch 'col_a': The expression after ELSE should have the same type as those after THEN: "int" is expected but "double" is found.
虽然我知道文字0
和 的结果之间存在数据类型不匹配(col_a / col_b)
,但我不清楚 Hive 为何对此感到窒息,更重要的是,解决此错误的最佳行动方案是什么。我应该将文字转换0
为 adouble
还是有更好的方法?
这是在 Amazon EMR 中运行的 Hive 0.8.1。