简体   繁体   English

PySpark-遍历数据帧的每一行并运行配置单元查询

[英]PySpark - loop through each row of dataframe and run a hive query

I have a dataframe with 100 rows [ name, age, date, hour] . 我有一个包含100行[名称,年龄,日期,小时]的数据框。 I need to partition this dataframe with distinct values of date. 我需要用不同的日期值对该数据框进行分区。 Let's say there are 20 distinct date values in these 100 rows , then i need to spawn up 20 parallel hive queries where each hive QL will join each of these partitions with a hive table . 假设在这100行中有20个不同的日期值,那么我需要产生20个并行的配置单元查询,其中每个配置单元QL将使用配置单元表将这些分区中的每一个连接起来。 Hive table - [dept, couse , date] is partitioned by date field. 配置单元表-[部门,原因,日期]按日期字段划分。

Hive table is huge and hence I need to optimize these joins in to multiple smaller joins and then aggregate these results. Hive表很大,因此我需要将这些连接优化为多个较小的连接,然后汇总这些结果。 Any recommendations on how can I achieve this ? 关于如何实现此目标的任何建议?

You can do this in single query. 您可以在单个查询中执行此操作。 Partition both df on date and join. 在日期和加入上对df进行分区。 During join broadcast you first table which have small data (~10MB). 在加入广播期间,您的第一个表的数据很小(〜10MB)。 Here is example:- 这是示例:-

df3 = df1.repartition("date").join(
F.broadcast(df2.repartition("date")), 
"date"
)
#df2 is your dataframe smaller dataframe in your case it is name, age, date, ,hour.
#Now perform any operation on df3  

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 pyspark:优化 pandas udf,对 Z6A8064B5DF47945550DZ?53C7 中的每一行执行 sql 查询 - pyspark: optimize pandas udf that performs sql query for each row in dataframe? 来自 Hive 查询的持久性 PySpark 数据帧 - Persistent PySpark Dataframe from a Hive query 运行 SQL 查询 UPDATE 语句以循环遍历结果集中的每一行并更新列的 Python 脚本 - Python Script to run SQL query UPDATE statement to loop through each row in result set and update columns 循环遍历分组火花 dataframe 中的每一行并解析为函数 - Loop through each row in a grouped spark dataframe and parse to functions 如何遍历 pandas dataframe 中的列中的每一行 - How to loop through each row in a column in a pandas dataframe 使用熊猫,如何逐行遍历数据帧,但每一行都是其自己的数据帧 - Using pandas, how do I loop through a dataframe row by row but with each row being its own dataframe 如何循环通过 pandas dataframe 为每个变量运行独立的测试? - How to loop through a pandas dataframe to run an independent ttest for each of the variables? 将值列表添加到 PySpark 数据框中的每一行 - Add a list of values to each row in a PySpark dataframe 从Hive查询深层复制过滤的PySpark数据帧 - Deep copy a filtered PySpark dataframe from a Hive query 为数据框中的每一行运行函数 - Run functions for each row in dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM