在使用Hive'Order By'查询时获取无序输出 [英] Getting unordered output while using Hive 'Order By' query

查看:296
本文介绍了在使用Hive'Order By'查询时获取无序输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试使用'Order by',如下所示:

 从testfilter中选择fieldA,fieldB,fieldC,fieldD where fieldA ='000009000002'按字段A,fieldB,fieldC,fieldD排序; 

但是,这会导致一个无序的输出,如下所示:

  000009000002 7212 023 653 
000009000002 9999 058 159
000009000002 9999 058 159
000009000002 9999 058 159
000009000002 9999 058 159
000009000002 9999 058 159
000009000002 9999 058 24
000009000002 9999 058 25
000009000002 9999 058 299
000009000002 9999 058 399
000009000002 9999 058 99
000009000002 9999 058 99
000009000002 9999 058 99
000009000002 9999 058 99

可能是什么原因?



注意:我使用Hive 0.10。

解决方案

如果我没有错,好像你将所有列的数据类型保存为 String

所以排序的数据正在发生,但因为它很受欢迎

  000009000002 7212 023 653 

// one group

  000009000002 9999 058 159 
000009000002 9999 058 159
000009000002 9999 058 159
000009000002 9999 058 159
000009000002 9999 058 159
000009000002 9999 058 24
000009000002 9999 058 25
000009000002 9999 058 299
000009000002 9999 058 399
000009000002 9999 058 99
000009000002 9999 058 99
000009000002 9999 058 99
000009000002 9999 058 99

//第二组



这里前三列是相同的值,但是

因为1小于2,所以159先来,然后是24来,等等。



因此您可以修改数据类型es to int



希望它有帮助... !!


I have tried using the 'Order by' as follows:

select fieldA,fieldB,fieldC,fieldD from testfilter where fieldA ='000009000002'order by fieldA,fieldB,fieldC,fieldD;

But, this results in a unordered output like this:

000009000002    7212    023     653
000009000002    9999    058     159
000009000002    9999    058     159
000009000002    9999    058     159
000009000002    9999    058     159
000009000002    9999    058     159
000009000002    9999    058     24
000009000002    9999    058     25
000009000002    9999    058     299
000009000002    9999    058     399
000009000002    9999    058     99
000009000002    9999    058     99
000009000002    9999    058     99
000009000002    9999    058     99

What could be the reason?

Note: I'm using Hive 0.10.

解决方案

If I am not wrong, seems like you kept the data types of all the columns as String.

So ordering of data is happening but as it happens for strings i.e lexicographically.

000009000002    7212    023     653

//one group

000009000002    9999    058     159
000009000002    9999    058     159
000009000002    9999    058     159
000009000002    9999    058     159
000009000002    9999    058     159
000009000002    9999    058     24
000009000002    9999    058     25
000009000002    9999    058     299
000009000002    9999    058     399
000009000002    9999    058     99
000009000002    9999    058     99
000009000002    9999    058     99
000009000002    9999    058     99

//second group

Here the first three columns are same value, but the last column is organized lexicographically.

As 1 is smaller than 2, so 159 comes first and 24 comes next and so on..

So you can modify the data types to int

Hope it helps...!!

这篇关于在使用Hive'Order By'查询时获取无序输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆