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-dataset.md.
  • 🇯🇵 日本語
  • Lakehouse Managerテーブルを使用したカスタムアクション

    この短い例では、Lakehouse Managerのテーブルからデータを抽出し、変換した後、Lakehouse Managerに挿入または更新する方法を示します

    目的

    この短い例では、Lakehouse Managerのテーブルからデータを抽出し、変換した後、Lakehouse Managerに挿入または更新する方法を示します。

    このコードはCustom Actionコンテキストで記述されており、stations_ridesテーブルをGetting Startedチュートリアルから使用しています。チュートリアルを実施した場合は、以下のコードをコピーして貼り付けるだけでテストできます。それ以外の場合は、テーブルとデータソースに合わせてコードを適応させる必要があります。

    Info

    DMで使用するテーブルを構築し、DPE Load Actionでロードすることを忘れないでください。以下のコードを使用する前にテーブルをロードする必要があります。それ以外の場合は動作しません。

    import sys
    import pandas as pd
    import logging
    
    from forepaas.dwh import connect
    from forepaas.dwh import bulk_insert
    
    logger = logging.getLogger(__name__)
    def customfunc(event):
        try:
            logger.notice("Begin function")
    
            # make connection to the default dataset
            cn = connect("dwh/default_dataset/")
    
            # option 1 : extract data from the table with no SQL required
            df = cn.select("stations_rides")
    
            # option 2 : extract data with custom SQL
            df = cn.query("SELECT station_id, date, rides, station_name FROM stations_rides")
    
            # perform your custom transform in the dataframe
            df.loc[df["station_name"] == 'Harlem-Lake', "rides"] = 0
    
            # reinsert your dataframe in the destination table
            stats = bulk_insert(cn, "stations_rides", df) 
    
            # show insertion statistics (if DBMS compatible) 
            logger.info(stats)
    
            # delete rows where station name is "Davis"
            cn.delete("stations_rides", {"station_name":"Davis"})
    
            # update rows set rides to 0 where station_id=40040
            cn.update("stations_rides", {"rides":0}, {"station_id":40040})
    
            # when finished, disconnect cn
            del cn    
            logger.notice("END function")
        except Exception as err: 
            raise Exception("err:{} L:{}".format(err,sys.exc_info()[2].tb_lineno))

    さらに詳しく

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

    専用DiscordチャネルでData Platformを構築するチームと直接質問し、フィードバックを共有し、交流してください。

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

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