我正在嘗試使用 pyspark 執行以下操作來更新紅移集群表的內容:
content= spark.read \
.format("com.databricks.spark.redshift") \
.option("aws_iam_role", role_arn) \
.option("url", host) \
.option("dbtable", "schema.table") \
.option("user", user) \
.option("password", pass) \
.option("tempdir", aws_bucket_name) \
.load()
content = content.withColumn('column', lit("test"))
content.write \
.format("com.databricks.spark.redshift") \
.option("aws_iam_role", role_arn) \
.option("url", host) \
.option("user", user) \
.option("password", pass) \
.option("dbtable", "schema.table") \
.option("tempdir", aws_bucket_name) \
.mode("overwrite") \
.save()
表內容已正確保存,但在覆寫操作后,redshift 集群的其余用戶失去了對表的權限(他們無法選擇、更新等...)
我讀過這是因為內部火花洗掉并創建了一個新表。有什么方法可以從不洗掉權限的 spark 更新表的內容?
uj5u.com熱心網友回復:
這是由于覆寫操作也洗掉了表的元資料造成的。
閱讀spark 檔案有 2 個選項有幫助:
preactions您可以使用它來截斷表,然后只附加資料而不是覆寫它。
postactions在覆寫操作后重新授予權限。
uj5u.com熱心網友回復:
Loren 的建議是正確的,但您還可以采取其他措施。您可以在 Redshift 中設定用戶的默認權限,以便該用戶創建的任何物件自動擁有權限。這只需要為該用戶執行一次,并且不會影響您當前的代碼。
要設定用戶的默認權限,您可以在 Redshift 上使用 ALTER_DEFAUL_PRIVILEGES 命令。用戶可以更改自己的默認權限,也可以由超級用戶(管理員)完成。看:
https://docs.aws.amazon.com/redshift/latest/dg/r_ALTER_DEFAULT_PRIVILEGES.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/494570.html
