{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-@l10n/ja/sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":[]},"type":"markdown"},"seo":{"title":"カスタムスクリプト環境でDelta Sharing機能を使用する","description":"Treasure Data Product Documentation · Collect and Unify · Segment and Activate · Experiment and Analyze · Decisioning Automate with AI Scale and Trust.","siteUrl":"https://docs.treasuredata.com","lang":"en-US","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"カスタムスクリプト環境でdelta-sharing機能を使用する","__idx":0},"children":["カスタムスクリプト環境でDelta Sharing機能を使用する"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["以下は、カスタムPythonスクリプトでDelta Sharing機能を設定する方法の例です:"]},{"$$mdtype":"Tag","name":"ol","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Databricks上に共有データを作成します。"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["共有データの設定が完了したら、Delta Sharing認証情報ファイルをダウンロードできます。"," ","詳細については、",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.databricks.com/en/delta-sharing/share-data-open.html#delta-sharing-open-sharing-workflow"},"children":["Delta Sharingオープン共有ワークフロー"]},"を参照してください。"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["処理ニーズに基づいてワークフローを作成します。"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["ワークフローからカスタムスクリプト(pythonコード)を実行します。"]}]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Delta Sharing認証情報をワークフローシークレットに登録します。"]}]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Delta Sharing認証情報のJSONコンテンツを使用してシークレットキーを提供します。"]},{"$$mdtype":"Tag","name":"ol","attributes":{"start":6},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["カスタムPythonスクリプトを呼び出すワークフロータスクを定義します。"]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["以下の例では、次の点に注意してください。"]},{"$$mdtype":"Tag","name":"ul","attributes":{},"children":[{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Py>オペレーターは、Pythonプログラム内の特定のメソッドを呼び出すために使用されます。"]},{"$$mdtype":"Tag","name":"li","attributes":{},"children":["Delta Sharing認証情報は、${secret:configShare}環境変数を使用してワークフローシークレットからコンテナに渡されます。"]}]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"yaml","header":{"controls":{"copy":{}}},"source":"timezone: UTC\n+call_exmple:\n  docker:\n    image: 'digdag/digdag-python:3.10'\n  py>: delta_sharing_task.fetch_data\n  _env:\n    configShare: '${secret:configShare}'\n","lang":"yaml"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Pythonプログラムでは、PySparkを使用してDatabricks上の共有データにアクセスし、データを標準的なspark dataframeとして操作できます。"]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"data-language":"python","header":{"controls":{"copy":{}}},"source":"import sys\nimport os\nimport json\nfrom pyspark.sql import SparkSession\n\n\ndef fetch_data():\n  # Install and import delta-sharing package\n  os.system(f'{sys.executable} -m pip install delta-sharing')\n  import delta_sharing\n\n\n  # Prepare config.share file\n  with open(\"config.share\", \"w\") as outfile:\n    outfile.write(os.environ.get('configShare'))\n\n\n  # Fetch shared data on Databricks via Delta-Sharing server by PySpark\n  table_url = f\"./config.share#your_share.your_database.your_table\"\n  spark = SparkSession.builder \\\n    .appName(\"delta-sharing-app\") \\\n    .master(\"local[*]\") \\\n    .config('spark.jars.packages', 'org.apache.hadoop:hadoop-azure:3.3.1,io.delta:delta-core_2.12:2.2.0,io.delta:delta-sharing-spark_2.12:0.6.2') \\\n    .config('spark.sql.extensions', 'io.delta.sql.DeltaSparkSessionExtension') \\\n    .config('spark.sql.catalog.spark_catalog', 'org.apache.spark.sql.delta.catalog.DeltaCatalog') \\\n    .getOrCreate()\n  shared_df = spark.read.format(\"deltaSharing\").load(table_url).select(\"column1\", \"column2\", \"column3\").show()\n\n","lang":"python"},"children":[]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["これには、Delta Sharingライブラリがインストールされ、インポートされている必要があります。"]}]},"headings":[{"value":"カスタムスクリプト環境でDelta Sharing機能を使用する","id":"カスタムスクリプト環境でdelta-sharing機能を使用する","depth":1}],"frontmatter":{"seo":{"title":"カスタムスクリプト環境でDelta Sharing機能を使用する"}},"lastModified":"2026-03-09T03:12:50.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/ja/products/customer-data-platform/integration-hub/zero-copy/using-the-delta-sharing-capability-in-a-custom-script-environment","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}