更新的数据框列值无法在Hive中覆盖

问题描述 投票:0回答:1

考虑具有列tblaid的配置单元表bid

|  aid | bid  |
---------------
|      |  12  |
|  24  |  13  |
|  18  |   3  |
|      |   7  |
---------------

要求是当aid为空或空字符串时,aid应该被bid的值覆盖

|  aid | bid  |
---------------
|  12  |  12  |
|  24  |  13  |
|  18  |   3  |
|   7  |   7  |
---------------

代码很简单

val df01 = spark.sql("select * from db.tbl")
val df02 = df01.withColumn("aid", when(col("aid").isNull || col("aid") <=>  "", col("bid")) otherwise(col("aid")))

并且在spark-shell中运行时,df02.show就像上表一样显示正确的数据

问题是将数据写回配置单元时

df02.write
  .format("orc")
  .mode("Overwrite")
  .option("header", "false")
  .option("orc.compress", "snappy")
  .insertInto(tbl)

没有错误,但是当我验证数据时

select * from db.tbl where aid is null or aid= '' limit 10;

我仍然可以看到查询返回了多行,并且帮助为null

如果像以前的示例那样以前更新列值,如何将数据覆盖回配置单元?

apache-spark hive
1个回答
0
投票

我将尝试如下

df02.write
  .orc
  .mode(SaveMode.Overwrite)
  .option("compression", "snappy")
  .insertInto(tbl)
© www.soinside.com 2019 - 2024. All rights reserved.