- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我有 2 个表,sample_table1
,下面有两列
C1 C2
001 a
001 b
001 e
002 c
002 b
003 a
003 c
和 sample_table2
两列为
C3 C4
a 0
b 1
c 0
d 1
e 0
我想得到这样的输出
F1 F2
001 1 <as 001 -> [a, b, e] -> [0, 1, 0] -> 1 (if one of the items in the collection ([a, b, e] in this case) is 1, then Column F2 should be 1 )>
002 1 <as 002 -> [c, b] -> [0, 1] -> 1>
003 0 <as 003 -> [a, c] -> [0, 0] -> 0>
我尝试了很多 Hive 的内置聚合函数 collect_set
,但无法解决。我想知道我是否可以在不编写任何自定义 UDF 的情况下做到这一点?
最佳答案
不需要collect_set
select t1.c1 as f1
,max(t2.c4) as f2
from sample_table1 t1
join sample_table2 t2
on t1.c2 = t2.c3
group by t1.c1
;
+-----+----+
| f1 | f2 |
+-----+----+
| 001 | 1 |
| 002 | 1 |
| 003 | 0 |
+-----+----+
关于sql - 使用 collect_set 的 Hive 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42896875/
我想在使用 hive 时删除数组中的连续重复项。 collect_list()保留所有重复项,而 collect_set()只保留不同的条目。我有点需要一些中间立场。 例如,从下表: id | n
我有这张表: ╔═════════╦═════════╦══════════════╗ ║ user_id ║ item_id ║ date_visited ║ ╠═════════╬════════
假设我有一个包含 3 行的配置单元表:merchant_id、week_id、acc_id。我的目标是每周收集前 4 周内的唯一客户,我正在使用移动窗口来执行此操作。 我的代码: 创建测试表: CRE
我有下表: hive> describe tv_counter_stats; OK day string event string query_id string user
我正在处理大型数据集上的配置单元,我有一个包含列数组的表,列的内容如下。 ["20190302Prod4" "20190303Prod1" "20190303Prod4" "20190304Prod4
我正在尝试在配置单元查询中使用 collect_set 按条件对组中的列进行分组。每行都有空格作为分隔符,而不是“,”之类的。在这种情况下如何将分隔符更改为“,”或任何其他分隔符? 提前致谢。 问候,
我正在尝试使用 collect_set 获取类别名称字符串列表 不是 groupby 的一部分。 我的代码是 from pyspark import SparkContext from pyspark
我在 hive 中有一个表,如下所示 id name sal 1 sam 2000 2 Ram 3000 3 Tim 4000 4 Ash 5000 我想
一些测试数据,有两列:第一列二进制(在此示例中使用字母数字字节),第二列是整数: from pyspark.sql.types import * from pyspark.sql import fun
如何重写这些查询以避免在 reduce 阶段使用单个 reducer?它需要永远,我失去了使用它的并行性的好处。 select id , count(distinct locations) AS un
我刚刚了解了 Hive 中的 collect_set() 函数,并开始从事开发 3 节点集群的工作。 我只有大约 10 GB 需要处理。然而,这项工作确实需要永远。我认为 collect_set()
有没有办法将重复项保存在 Hive 的收集集中,或者使用其他方法模拟 Hive 提供的那种聚合集合?我想将列中具有相同键的所有项目聚合到一个数组中,并带有重复项。 IE: hash_id | num_
嗨,我在任何地方都找不到这个。 如何在 Google BigQuery 中执行 collect_set? 我有一个已经用大查询编写的查询 选择用户身份,脚步,从表 我需要将每个 user_id 的所有
如果我的目标是将列中的不同值收集为列表,使用其中任何一个是否存在性能差异或优缺点? df.select(column).distinct().collect()... 对比 df.select(col
我有 2 个表,sample_table1,下面有两列 C1 C2 001 a 001 b 001 e 002 c 002 b 003 a 003 c 和 sample_table2
我有下表,其中包含 id 的重复项以及每个 id 的值数组,我想找出每个 id 的唯一值,该怎么做? CREATE TABLE test( id string, values array) 当我运行以
在表 1 中,我有 customer_id、item_id 和 item_rank(根据一些销售额的项目排名)。我想为每个 customer_id 收集一个项目列表,并根据 item_rank 排列它
我有一个聚合 DataFrame,其中有一列是使用 collect_set 创建的。我现在需要再次聚合此 DataFrame,并再次将 collect_set 应用于该列的值。问题是我需要应用 col
Hive 查询 - select ...MYUDF(collect_set(col1))..from tableN 这里的 col1 是字符串类型。我想对传递的 collect_set 数据执行某些逻
我正在处理一个大型 spark DataFrame 中的一列数字,我想创建一个新列来存储出现在该列中的唯一数字的聚合列表。 基本上正是 functions.collect_set 所做的。但是,我只需
我是一名优秀的程序员,十分优秀!