0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【メモ】Microsoft Fabric Sparkでの 他クラウドデータレイクへの書き込み

Last updated at Posted at 2024-06-20

はじめに

他クラウドとのショートカットは読み取り専用なんで、書き込みのサンプルを載せます。

ネットワークレベルのアクセスポリシーはなしの状態でやってるので、エンプラ的には厳しそうですが、Managed vnet → Privatelink service 的な流れで多分ネットワークの問題も解消できる気がしますが、それはまた別機会で。

GCS

Fabric spark runtimeにはコネクタが入ってます。

Runtime 1.2

ライブラリの一覧
image.png

https://github.com/GoogleCloudDataproc/hadoop-connectors

準備

サービスアカウント作成後、キーファイルを出力し、権限付与

権限:ストレージオブジェクト管理者

キーファイル:
image.png

実行

  1. Fabric ノートブックリソースにキーファイルアップロード
    image.png
  2. spark 実行
spark

data = [("John", "Doe", 30), ("Jane", "Doe", 25), ("Mike", "Jordan", 50)] 
df = spark.createDataFrame(data, ["FirstName", "LastName", "Age"])  

key_file_name="キーファイル名"
gcs_backet_name ="バケット名"

spark._jsc.hadoopConfiguration().set('fs.gs.auth.service.account.enable', 'true')
spark._jsc.hadoopConfiguration().set('google.cloud.auth.service.account.json.keyfile', f"{mssparkutils.nbResPath}/builtin/{key_file_name}")
## 環境使う場合は f"{mssparkutils.nbResPath}/env/{key_file_name}" 

gcs_route_path=f"gs://{gcs_backet_name}"
output_path = f"{gcs_route_path}/qiita-output/"
df.write.mode("overwrite").format("delta").save(output_path)

  1. 確認
    image.png

S3

準備

IAMユーザーとアクセスキーを作成して、権限付与
image.png

権限:以下のようなポリシーで作成

json
"Action": [
                "s3:PutObject",
                "s3:GetObject",
                "s3:ListBucket",
                "s3:DeleteObject"
            ]

実行

  1. spark 実行
spark

data = [("John", "Doe", 30), ("Jane", "Doe", 25), ("Mike", "Jordan", 50)] 
df = spark.createDataFrame(data, ["FirstName", "LastName", "Age"])  


s3_backet_name ="バケット名"
access_key_id="アクセスキーID"
accecc_key_secret="アクセスキーシークレット"

sc._jsc.hadoopConfiguration().set("fs.s3a.access.key", access_key_id)
sc._jsc.hadoopConfiguration().set("fs.s3a.secret.key", accecc_key_secret)

s3_route_path=f's3a://{s3_backet_name}'
output_path = f"{s3_route_path}/qiita-output/"
df.write.mode("overwrite").format("delta").save(output_path)

  1. 確認
    image.png
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?