Apache Solr にAzure Data Catalog のデータをインポートする方法

Jerod Johnson
Jerod Johnson
Senior Technology Evangelist
CData JDBC Driver for Azure Data Catalog をData Import Handler で使用して、Azure Data Catalog のデータをApache Solr エンタープライズサーチプラットフォームに自動インポートできます。

Apache Solr は、Apache Lucene 上に構築された人気のある高速なオープンソースのエンタープライズサーチソリューションです。

Apache Solr には、データベースやXML、CSV、JSON ファイルからデータをインポートできるData Import Handler(DIH)が搭載されています。CData JDBC Driver for Azure Data Catalog と組み合わせることで、Azure Data Catalog のデータを簡単にApache Solr にインポートできます。この記事では、CData JDBC Driver をApache Solr のData Import Handler で使用し、エンタープライズサーチ用にAzure Data Catalog のデータをインポートする方法をステップバイステップで解説します。

Azure Data Catalog インポート用のApache Solr コアとスキーマを作成する

  1. Apache Solr を起動し、コアを作成します。
    > solr create -c CDataCore
    この記事では、Solr はローカル環境でスタンドアロンインスタンスとして実行されており、次のURL でコアにアクセスできます:http://localhost:8983/solr/#/CDataCore/core-overview
  2. インポートするAzure Data Catalog のデータのカラムを表す「field」オブジェクトと、エンティティの一意キーで構成されるスキーマを作成します。Azure Data Catalog にLastModifiedDate が存在する場合は、増分更新に使用されます。存在しない場合は、後述のdeltaquery を実行できません。スキーマはApache Solr が作成したmanaged-schema ファイルに保存します。
  3. 	AzureDataCatalogUniqueKey
    	
    	
    	
    	
    	
    	
    	
    	
    	
  4. CData Azure Data Catalog JDBC Driver をインストールします。JAR ファイルとライセンスファイル(cdata.azuredatacatalog.jarcdata.jdbc.azuredatacatalog.lic)をSolr ディレクトリにコピーします。
    • CData JDBC JAR ファイル:C:\Program Files\CData\CData JDBC Driver for Azure Data Catalog ####\lib
    • Apache Solr:solr-8.5.2\server\lib

これで、Solr でAzure Data Catalog のデータを使用する準備が整いました。

Azure Data Catalog からApache Solr へのインポートを定義する

このセクションでは、Data Import Handler の設定手順を説明します。

  1. 作成したコアのConfig ファイルを編集します。JAR ファイルの参照を追加し、DIH RequestHandler の定義を追加します。
    	
    
    	<lib dir="${solr.install.dir:../../../..}/dist/" regex="solr-dataimporthandler-.*\.jar" />
    
    	<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    		<lst name="defaults">
    			<str name="config">solr-data-config.xml</str>
    		</lst>
    	</requestHandler>
  2. 次に、同じ階層にsolr-data-config.xml を作成します。この記事ではAzure Data Catalog からテーブルを取得しますが、カスタムSQL クエリを使用してデータをリクエストすることもできます。Driver クラスとサンプルJDBC 接続文字列は以下のサンプルコードにあります。
    	
    	<dataConfig>
    		<dataSource driver="cdata.jdbc.azuredatacatalog.AzureDataCatalogDriver" url="jdbc:azuredatacatalog:">
    		</dataSource>
    		<document>
    			<entity name="Tables"
    				query="SELECT Id,AzureDataCatalogColumn1,AzureDataCatalogColumn2,AzureDataCatalogColumn3,AzureDataCatalogColumn4,AzureDataCatalogColumn5,AzureDataCatalogColumn6,AzureDataCatalogColumn7,LastModifiedDate FROM Tables"
    				deltaQuery="SELECT Id FROM Tables where LastModifiedDate >= '${dataimporter.last_index_time}'"
    				deltaImportQuery="SELECT Id,AzureDataCatalogColumn1,AzureDataCatalogColumn2,AzureDataCatalogColumn3,AzureDataCatalogColumn4,AzureDataCatalogColumn5,AzureDataCatalogColumn6,AzureDataCatalogColumn7,LastModifiedDate FROM Tables where Id=${dataimporter.delta.Id}">
    				<field column="Id" name="Id" ></field>
    				<field column="AzureDataCatalogColumn1" name="AzureDataCatalogColumn1" ></field>
    				<field column="AzureDataCatalogColumn2" name="AzureDataCatalogColumn2" ></field>
    				<field column="AzureDataCatalogColumn3" name="AzureDataCatalogColumn3" ></field>
    				<field column="AzureDataCatalogColumn4" name="AzureDataCatalogColumn4" ></field>
    				<field column="AzureDataCatalogColumn5" name="AzureDataCatalogColumn5" ></field>
    				<field column="AzureDataCatalogColumn6" name="AzureDataCatalogColumn6" ></field>
    				<field column="AzureDataCatalogColumn7" name="AzureDataCatalogColumn7" ></field>
    				<field column="LastModifiedDate" name="LastModifiedDate" ></field>
    			</entity>
    		</document>
    	</dataConfig>
  3. query セクションで、Azure Data Catalog からデータを選択するSQL クエリを設定します。deltaQuerydeltaImportquery は、同じエンティティの2回目以降のインポートで増分更新を使用する際のID と条件を定義します。
  4. すべての設定が完了したら、Solr を再起動します。
    	> solr stop -all
    	> solr start
    	

Azure Data Catalog のデータのDataImport を実行する

  1. 以下のURL からDataImport を実行します:
    http://localhost:8983/solr/#/CDataCore/dataimport//dataimport
  2. 「full-import」コマンドを選択し、Entity からテーブルを選択して、「Execute」をクリックします。
  3. Query からインポート結果を確認します。
  4. deltaQuery を使用した増分更新を試してみましょう。元のAzure Data Catalog データセットのデータを変更します。DataImport ウィンドウから今度は「delta-import」コマンドを選択し、「Execute」をクリックします。
  5. 増分更新の結果を確認します。

CData JDBC Driver for Azure Data Catalog を使用することで、Azure Data Catalog のデータのApache Solr への自動インポートを作成できます。250+ のCData JDBC Driver の無料30日間トライアルをダウンロードして、今すぐ始めましょう。

はじめる準備はできましたか?

Azure Data Catalog Driver の無料トライアルをダウンロードしてお試しください:

 ダウンロード

詳細:

Azure Data Catalog Icon Azure Data Catalog JDBC Driver お問い合わせ

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