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

※製品について詳しい情報をご希望の方は以下からお進みください。
- XML にほかのBI、ETL、開発ツールから接続したい:XML データ連携ガイドおよびチュートリアルのリストへ
- XML Drivers について詳細を知りたい:ドライバー詳細情報ページへ
- ほかのデータソースに連携したい:CData Drivers 一覧へ
- ドライバーの30日の無償トライアル版を使いたい:トライアル版ダウンロードページへ
- 製品の利用やライセンスについて相談したい:sales@cdata.co.jp までメールにてご相談ください。
Embulk でCData JDBC Driver for XML データをロード
- CData JDBC Driver for XML をEmbulk と同じマシンにインストールします。
-
以下のパスにJDBC Driver がインストールされます。後ほどこのパスを使います。
C:\Program Files\CData\CData JDBC Driver for XML 2019J\lib\cdata.jdbc.xml.jar
- 次に、EmbulkとCData JDBC Driverをつなぎこむための、JDBC Input Plugin をインストールします。
https://github.com/embulk/embulk-input-jdbc/tree/master/embulk-input-jdbc - 今回はロード先DB としてMySQL を使います。ほかにもSQL Server、PostgreSQL、Google BigQuery などを使うことも可能です。
https://github.com/embulk/embulk-output-jdbc/tree/master/embulk-output-mysqlembulk gem install embulk-output-mysql
- config ファイルを作成し、XML -> MySQL のジョブを作成します。xml-mysql.yml というファイル名で作成しました。
embulk gem install embulk-input-jdbc
in:
type: jdbc
driver_path: C:\Program Files\CData\CData JDBC Driver for XML 2019J\lib\cdata.jdbc.xml.jar
driver_class: cdata.jdbc.xml.XMLDriver
url: jdbc:xml:URI=C:\people.xml;DataModel=Relational;
table: "people"
out:
type: mysql
host: localhost
database: DatabaseName
user: UserId
password: UserPassword
table: "people"
mode: insert
See the Getting Started chapter in the data provider documentation to authenticate to your data source: The data provider models XML APIs as bidirectional database tables and XML files as read-only views (local files, files stored on popular cloud services, and FTP servers). The major authentication schemes are supported, including HTTP Basic, Digest, NTLM, OAuth, and FTP. See the Getting Started chapter in the data provider documentation for authentication guides.
After setting the URI and providing any authentication values, set DataModel to more closely match the data representation to the structure of your data.
The DataModel property is the controlling property over how your data is represented into tables and toggles the following basic configurations.
- Document (default): Model a top-level, document view of your XML data. The data provider returns nested elements as aggregates of data.
- FlattenedDocuments: Implicitly join nested documents and their parents into a single table.
- Relational: Return individual, related tables from hierarchical data. The tables contain a primary key and a foreign key that links to the parent document.
See the Modeling XML Data chapter for more information on configuring the relational representation. You will also find the sample data used in the following examples. The data includes entries for people, the cars they own, and various maintenance services performed on those cars.
embulk run xml-mysql.yml
クエリ条件でフィルタリングしたデータのロード
ちなみに、上記の例ではテーブル名を直接指定しましたが、以下のようにSQL Queryを書いてもいいです。 Where句で作成日や修正日を指定すれば、最新のデータだけを対象にすることも可能です。
in:
type: jdbc
driver_path: C:\Program Files\CData\CData JDBC Driver for XML 2019J\lib\cdata.jdbc.xml.jar
driver_class: cdata.jdbc.xml.XMLDriver
url: jdbc:xml:URI=C:\people.xml;DataModel=Relational;
query: "SELECT [ personal.name.first ], [ personal.name.last ] FROM people WHERE [RecordId] = 1"
out:
type: mysql
host: localhost
database: DatabaseName
user: UserId
password: UserPassword
table: "people"
mode: insert
CData JDBC Driver for XML をEmbulk で使うことで、XML コネクタとして機能し、簡単にデータを取得して同期することができました。ぜひ、30日の無償評価版 をお試しください。