製品をチェック

無償トライアル:

無償トライアルへ

製品の情報と無償トライアルへ:

Azure Data Lake Storage JDBC Driver

Azure Data Lake Storage データに連携するJava アプリケーションを素早く、簡単に開発できる便利なドライバー。

データ連携でお困りですか?

お問い合わせ

ETL/ELT のEmbulk を使ってAzure Data Lake Storage データをDB にロードする方法


OSS のETL/ELT ツールEmbulk のJDBC Plugin を使って、Azure Data Lake Storage データを簡単にDM に同期する方法。


azuredatalake ロゴ画像
jdbc ロゴ画像

JDBC

Embulk ロゴ画像

Embulk は、大量のデータをDB、クラウドデータストア、DWH にロードできるオープンソースETL ツールです。近頃のトレンドでは、1社で複数のオンプレアプリやSaaS を使っており、データ分析にはETL/ELT ツールを使ってデータを丸ごとDB/DWH にロードしてから、分析やビジュアライズをすることが主流になっています。Embulk には、いろいろなプラグインがあり、多様なInput とOutput 処理をサポートしています。この記事では、Embulk のJDBC Input Plugin と CData Driver for ADLS を使って、Azure Data Lake Storage のデータを簡単にDB にロードします。この例ではロード先のDB にはMySQL を使います。

Embulk でCData JDBC Driver for ADLS データをロード

  • CData JDBC Driver for ADLS をEmbulk と同じマシンにインストールします。
  • 以下のパスにJDBC Driver がインストールされます。後ほどこのパスを使います。
    C:\Program Files\CData\CData JDBC Driver for ADLS 2019J\lib\cdata.jdbc.adls.jar
  • 次に、EmbulkとCData JDBC Driverをつなぎこむための、JDBC Input Plugin をインストールします。
    https://github.com/embulk/embulk-input-jdbc/tree/master/embulk-input-jdbc
  • embulk gem install embulk-input-jdbc
  • 今回はロード先DB としてMySQL を使います。ほかにもSQL Server、PostgreSQL、Google BigQuery などを使うことも可能です。
    https://github.com/embulk/embulk-output-jdbc/tree/master/embulk-output-mysql embulk gem install embulk-output-mysql
  • config ファイルを作成し、Azure Data Lake Storage -> MySQL のジョブを作成します。adls-mysql.yml というファイル名で作成しました。
  •             
                    in:
                        type: jdbc
                        driver_path: C:\Program Files\CData\CData JDBC Driver for ADLS 2019J\lib\cdata.jdbc.adls.jar
                        driver_class: cdata.jdbc.adls.ADLSDriver
                        url: jdbc:adls:Schema=ADLSGen2;Account=myAccount;FileSystem=myFileSystem;AccessKey=myAccessKey;InitiateOAuth=REFRESH
                        table: "Resources"
                    out: 
                        type: mysql
                        host: localhost
                        database: DatabaseName
                        user: UserId
                        password: UserPassword
                        table: "Resources"
                        mode: insert
                
            
  • ポイントはJDBC URLです。

    Authenticating to a Gen 1 DataLakeStore Account

    Gen 1 uses OAuth 2.0 in Azure AD for authentication.

    For this, an Active Directory web application is required. You can create one as follows:

    1. Sign in to your Azure Account through the .
    2. Select "Azure Active Directory".
    3. Select "App registrations".
    4. Select "New application registration".
    5. Provide a name and URL for the application. Select Web app for the type of application you want to create.
    6. Select "Required permissions" and change the required permissions for this app. At a minimum, "Azure Data Lake" and "Windows Azure Service Management API" are required.
    7. Select "Key" and generate a new key. Add a description, a duration, and take note of the generated key. You won't be able to see it again.

    To authenticate against a Gen 1 DataLakeStore account, the following properties are required:

    • Schema: Set this to ADLSGen1.
    • Account: Set this to the name of the account.
    • OAuthClientId: Set this to the application Id of the app you created.
    • OAuthClientSecret: Set this to the key generated for the app you created.
    • TenantId: Set this to the tenant Id. See the property for more information on how to acquire this.
    • Directory: Set this to the path which will be used to store the replicated file. If not specified, the root directory will be used.

    Authenticating to a Gen 2 DataLakeStore Account

    To authenticate against a Gen 2 DataLakeStore account, the following properties are required:

    • Schema: Set this to ADLSGen2.
    • Account: Set this to the name of the account.
    • FileSystem: Set this to the file system which will be used for this account.
    • AccessKey: Set this to the access key which will be used to authenticate the calls to the API. See the property for more information on how to acquire this.
    • Directory: Set this to the path which will be used to store the replicated file. If not specified, the root directory will be used.
  • テーブル名は取得したいテーブル名を入れます。
  • これで準備完了です。あとは「embulk run」で実行するだけです。
  • embulk run adls-mysql.yml
  • 実行後、MySQL Workbenchからテーブルを確認してみると、データが取得できているはずです。

クエリ条件でフィルタリングしたデータのロード

ちなみに、上記の例ではテーブル名を直接指定しましたが、以下のようにSQL Queryを書いてもいいです。 Where句で作成日や修正日を指定すれば、最新のデータだけを対象にすることも可能です。

        
            in:
            type: jdbc
            driver_path: C:\Program Files\CData\CData JDBC Driver for ADLS 2019J\lib\cdata.jdbc.adls.jar
            driver_class: cdata.jdbc.adls.ADLSDriver
            url: jdbc:adls:Schema=ADLSGen2;Account=myAccount;FileSystem=myFileSystem;AccessKey=myAccessKey;InitiateOAuth=REFRESH
                query: "SELECT FullPath, Permission FROM Resources WHERE [RecordId] = 1"
            out: 
                type: mysql
                host: localhost
                database: DatabaseName
                user: UserId
                password: UserPassword
                table: "Resources"
                mode: insert
        
    

CData JDBC Driver for ADLS をEmbulk で使うことで、Azure Data Lake Storage コネクタとして機能し、簡単にデータを取得して同期することができました。ぜひ、30日の無償評価版をお試しください。