For AI agents: the complete documentation index is available at https://docs.dataplatform.ovh.net/ja/llms.txt, the full documentation bundle is available at https://docs.dataplatform.ovh.net/ja/llms-full.txt, and this page is available as Markdown at https://docs.dataplatform.ovh.net/ja/developers-python-sdk-quick-start-bucket.md.
  • 🇯🇵 日本語
  • Data Platform バケットを使用したカスタムアクション

    時には、当社のLoad Actionの機能を超えた複雑なファイル形式を処理する必要があります

    目的

    時には、当社のLoad Actionの機能を超えた複雑なファイル形式を処理する必要があります。 この場合、当社は、プロジェクト内のData Platform Bucketsにファイルを保存して操作することをお勧めします。

    Info

    Data Platform Python SDKでは、Datastore コネクタが使用され、Data Platform Bucketsと相互作用します。 Datastoreを単純にバケットコンテナと考えることができます。

    以下のサンプルはCustom Actionのコンテキストで記述されています。 必要に応じて適宜変更してください。

    import sys
    import pandas as pd
    from logging import getLogger
    
    from forepaas.dwh import connect
    from forepaas.dwh import bulk_insert
    
    logger = getLogger(__name__)
    def extract_func(event):
        try:
            # we get data from a bucket and we will archive them in another bucket
            bucket_source_name = "your_source_bucket_name_here"
            bucket_archives_name = "your_source_bucket_name_here"
    
            # create a connector to handle bucket   
            bucket_connector = connect("data_store/{}".format(bucket_source_name))
    
            # list files from bucket
            files = bucket_connector.list()
    
            # retrieve a file from Data Store bucket to temporary local folder
            bucket_filepath = "stations_rides.csv"
            local_filepath = "/tmp/stations_rides.csv"
            bucket_connector.fget(bucket_filepath, local_filepath)
    
            # read then transform the file as you need
            # here the date column format is simply adjusted for compatibility reasons 
            df = pd.read_csv(local_filepath, sep=';')
            df['date'] = pd.to_datetime(df['date'])
    
            # load the dataframe into a project table named 'raw_file'
            cn = connect("dwh/default_dataset/")
            bulk_insert(cn, "stations_rides_artur", df)
            del cn
            
            # option 1 : copy the file into the archives bucket
            bucket_archive_filepath = "archives/stations_rides.csv"
            bucket_connector.fcopy_to(bucket_archives_name, bucket_archive_filepath, bucket_filepath)
           
            # option 2 : put a file into the archives
            bucket_archives = connect("data_store/{}".format(bucket_archives_name))
            bucket_archives.fput(bucket_archive_filepath, local_filepath)
            del bucket_archives
    
            # delete file from source bucket
            bucket_connector.delete(bucket_filepath)
    
            # disconnect from datastore
            del bucket_connector
        except Exception as err: 
            raise Exception("err:{} L:{}".format(err,sys.exc_info()[2].tb_lineno))
    Tip

    これは、S31互換ソースとしてConnectorsに定義した任意のObject Storeでも動作します。

    別の例

    以下は、単純なURLからバケットに画像をアップロードする例コードです。

    from forepaas.dwh import connect
    
    data_store = connect('data_store')
    
    # Get bucket and upload image from URL to path forepaas/test.jpg.
    # And finally get the image from the bucket
    bucket_test = data_store.get_bucket('test')
    
    lists = bucket_test.list(recursive=True)
    
    bucket_test.put_request("https://i.stack.imgur.com/r8jTK.jpg", path='forepaas/test.jpg')
    data = bucket.get('hello/test.jpg')
    
    # Create a bucket if it does not already exists
    if data_store.bucket_exists('test-exists') is False:
        data_store.create_bucket('test-exists')
    
    # Connect directly to the bucket test and remove the file
    bucket_test2 = connect('data_store/test')
    bucket_test2.delete('hello/test.jpg')

    さらに詳しく

    当社のソリューションを実装するためのトレーニングや技術サポートが必要な場合は、営業担当者にお問い合わせください。 または、このリンクをクリックして、当社のプロフェッショナルサービスの専門家にカスタム分析を依頼し、見積もりを取得してください。

    Data Platformを構築するチームと直接、質問をしたり、フィードバックを送信したり、交流したりするには、専用のDiscord チャネルをご利用ください。

    OVHcloudサービスについてサポートが必要な場合は、当社のヘルプセンターでリクエストを作成してください。

    当社のユーザーコミュニティに参加してください。

    1: S3はAmazon Technologies, Inc.の商標です。OVHcloudのサービスは、Amazon Technologies, Inc.によってスポンサーされ、推奨され、またはその他の方法で提携されていません。