这可能听起来很基本,但问题困扰了我一段时间。
假设我有以下查询
Set Nocount On;
Select t.ShouldRegistered
,t.Registered
,t.Region
----- Isnull(,0) will cause of divide by zero error if null
,Cast((t.Registered / (Case When Isnull(t.ShouldRegistered,0) = 0 Then 1 Else t.ShouldRegistered) * 100) As Decimal(12,8)) As Percentmet
,[AdjPercentmet condition] As AdjPercentmet
From (
Select tb.Region
,Sum(Case When [tb.Field1.....Condition] And [tb.Field2.....Condition] And [tb.Field3....Condition] Then 1 Else 0 End) As ShouldRegistered
,Sum(Case When [tb.Field1.....Condition] And [tb.Field2.....Condition] And [tb.Field3....Condition] Then 1 Else 0 End) As Registered
From dbo.TABLE As tb With (Nolock)
Group By tb.Region
) As t
Group By t.ShouldRegistered
,t.Registered
,t.Region
Order By t.Region
在这种情况下,如果数据在符号列上具有良好的扩展,则基于符号列进行分发是有意义的,这样所有减少器都可以获得良好的数据共享;将查询更改为以下将提供更好的性能
SELECT s.ymd, s.symbol, s.price_close FROM stocks s
SORT BY s.symbol ASC;
如果我没有指定distribute by子句,会有什么影响?在第一个查询中选择的默认地图输出键列是什么,即它所分配的列是什么?
答案 0 :(得分:1)
我自己找到了答案。使用排序依据时,映射器的输出键不是应用排序依据的列。密钥可以是记录的文件偏移量。 reducers的输出按reducer排序,但列值相同的排序可以出现在多个reducer的输出中。这意味着减速器的输出之间存在重叠。 Distribute by确保数据在reducers之间基于按列分布进行分割,从而确保相同的列值转到同一个reducer,因此输出相同的文件。
答案 1 :(得分:0)
详细信息可供使用。我想这就是你要找的答案。 https://cwiki.apache.org/confluence/display/Hive/LanguageManual+SortBy