Apache Drill SQL:当分子>时,除法失败分母

时间:2016-12-08 13:03:28

标签: sql apache-drill

我正面临着这个奇怪但基本的apache-drill SQL问题,操作的简单划分给出了错误的结果,如下所示:

0: jdbc:drill:drillbit=localhost> SELECT 'Test' FROM (VALUES(1));
+---------+
| EXPR$0  |
+---------+
| Test    |
+---------+
1 row selected (1.027 seconds)
0: jdbc:drill:drillbit=localhost> select 10/100 from (VALUES(1));
+---------+
| EXPR$0  |
+---------+
| 0       |
+---------+
1 row selected (0.67 seconds)
0: jdbc:drill:drillbit=localhost> select 100/10 from (VALUES(1));
+---------+
| EXPR$0  |
+---------+
| 10      |
+---------+
1 row selected (0.662 seconds)
0: jdbc:drill:drillbit=localhost> select 10/11 from (VALUES(1));
+---------+
| EXPR$0  |
+---------+
| 0       |
+---------+
1 row selected (0.649 seconds)
0: jdbc:drill:drillbit=localhost> select cast(10/11 as float) from (VALUES(1));
+---------+
| EXPR$0  |
+---------+
| 0.0     |
+---------+
1 row selected (0.74 seconds)
0: jdbc:drill:drillbit=localhost> select cast(10/11 as double) from (VALUES(1));
+---------+
| EXPR$0  |
+---------+
| 0.0     |
+---------+
1 row selected (0.691 seconds)
0: jdbc:drill:drillbit=localhost> select cast(10*100/11 as double) from (VALUES(1));
+---------+
| EXPR$0  |
+---------+
| 90.0    |
+---------+
1 row selected (0.72 seconds)
0: jdbc:drill:drillbit=localhost> select cast(10*100/11 as double)/100 from (VALUES(1));
+---------+
| EXPR$0  |
+---------+
| 0.9     |
+---------+

钻取版本为1.6和1.8(两者都试过)。即使round也无济于事。有什么工作吗?

1 个答案:

答案 0 :(得分:0)

这是整数运算 11/4 = 2(和提醒= 3)

您必须将其中一个值转换为请求的类型。

select cast(x as float)/y