配置单元脚本-如何根据一个列名称转换表/查找某些记录的平均值?

a14dhokn  于 2021-06-02  发布在  Hadoop
关注(0)|答案(1)|浏览(336)

我想通过基于平均值的聚合来转换配置单元表。但是,我不想要整列的平均值,我想要该列中另一列中具有相同类型的记录的平均值。
下面是一个比试图解释更简单的例子:

表一:

时间戳    副名    反价值    最大计数器值    最小值
00:00            计数器1            三                        三                            1
00:00            计数器2            4                        5                            2
00:00            计数器3            1                        4                            1
00:00            计数器4            6                        6                            1
00:05            计数器1            三                        5                            2
00:05            计数器2            2                        2                            2
00:05            计数器3            4                        5                            4
00:05            计数器4            6                        6                            5
.......

我想要的table:

副名    平均计数器值    最大计数器值    最小值
计数器1            三                            5                                1
计数器2            三                            5                                2
计数器3            2.5                         5                                1
计数器4            6                            6                                1
所以我有一个计数器列表,每个计数器都有多个记录(每5分钟一个)。每次记录每个计数器时,它都有一个值、5分钟内的最大值和最小值。我想聚合这个巨大的表,这样每个计数器就只有一条记录,记录表中所有记录中该计数器的总体平均值,然后是表中计数器的总体最小/最大值。
之所以这样做很困难,是因为所有文档都说明了如何按一个表中一列的平均值进行聚合—我不知道如何将其分组。
以下是我开始的脚本:

FROM HighCounters INSERT OVERWRITE TABLE MdsHighCounters
SELECT 
    HighCounters.CounterName AS CounterName,
    HighCounters.CounterValue AS CounterValue
    HighCounters.MaxCounterValue AS MaxCounterValue,
    HighCounters.MinCounterValue AS MinCounterValue
GROUP BY HighCounters.CounterName;

我不知道从那里去哪里。。。有什么想法吗?谢谢!!

ppcbkaq5

ppcbkaq51#

我想我解决了自己的问题: FROM HighCounters INSERT OVERWRITE TABLE MdsHighCounters SELECT HighCounters.CounterName AS CounterName, AVG(HighCounters.CounterValue) AS CounterValue, MAX(HighCounters.MaxCounterValue) AS MaxCounterValue, MIN(HighCounters.MinCounterValue) AS MinCounterValue GROUP BY HighCounters.CounterName; 你觉得这个合适吗?

相关问题