apache-spark - 基于 Spark Scala 中的 3 个场景在 Hive 表中插入/更新记录
问题描述
我有一个源表,我想根据以下场景将数据更新/插入到输出表中。
源表:
Name|age|dept|sal |school|college|deg|blood_group
aaa |10 |ece |1000|svv |sas |be |0+
bbb |20 |it |2000|svv |sas |be |A+
scenario 1: If value name,age,dept doesn't exists on output table,create new record
scenario 2: If value name,age,dept exists on output table , if no changes in school,college then do nothing
scenario 3: If value name,age,dept exists on output table , if changes in school,college then do nothing then create new record
I want to insert data's into output table based on above scenario using either spark sql or spark scala dataframe.
Please suggest me.
解决方案
我不确定这是否可行
尝试在编写之前先在代码中调用 Hive 表,然后从中创建一个 Table /Dataframe 并将其命名为prior_df
from pyspark.sql import HiveContext hive_context = HiveContext(sc) bank = hive_context.table("default.bank") bank.show()
bank.registerTempTable("bank_temp") hive_context.sql("select * from bank_temp").show()
现在,加入prior_df 表,因为您已经有了使用withColumn 的条件,并且当条件同样为“无操作/过滤”事务创建一个新列时。prior_df 将帮助您获得先前的值
将新的 DF 写入配置单元表位置
推荐阅读
- google-colaboratory - 如何在 Google Colab 中显示 Vega 可视化
- typescript - Angular8/typescript - 有没有更好的方法来返回 Promise
在 .then() 内,而不是一个空的对象块 - python - 使用不是符号张量的输入调用图层。收货类型:
- vector - rust 是否可以为不同的数据结构提供统一的 Iterator 接口?
- anylogic - 使用多个级别的 PedGoTo 动态目标
- reinforcement-learning - 将 Q 表保存到文件的最佳方法是什么?
- python - 如何在 Python 中创建类似的方法,例如使用冒号运算符 (:) 在 R 中创建数据框?
- javascript - WPBakery Post grid:如何在另一个窗口(_blank)中打开 post grid 的元素?
- java - 内联内容处置
- python - PyTables 警告“在注册表中找到一个关闭的节点”是什么意思?