Ruby でODBC 経由でAzure Data Catalog に接続して、モダンなクラウド連携アプリを開発。
CData ODBC Driver for Azure Data Catalog を使うと、簡単にRuby アプリケーションにリアルタイムAzure Data Catalog データを連携・統合できます。 Tこの記事では、Azure Data Catalog] データにリアルタイムに連携するRuby アプリケーションを構築して、クエリを実行し、結果を表示してみます。
Azure Data Catalog データのODBC 接続を設定
通常はCData ODBC Driver のインストール後にODBC DSN 接続ウィザードが立ち上がり、設定を行うことができます。 もしODBC DSN 接続が未済の場合には、Microsoft ODBC データソースアドミニストレータでODBC DSN を作成および設定することができます。
You can optionally set the following to read the different catalog data returned from Azure Data Catalog.
- CatalogName: Set this to the CatalogName associated with your Azure Data Catalog. To get your Catalog name, navigate to your Azure Portal home page > Data Catalog > Catalog Name
Connect Using OAuth Authentication
You must use OAuth to authenticate with Azure Data Catalog. OAuth requires the authenticating user to interact with Azure Data Catalog using the browser. For more information, refer to the OAuth section in the help documentation.
Ruby および必要なGem のインストール
If you do not have Ruby installed, refer to the Ruby インストールページ. Ruby をインストールしたら、次にruby-dbi、dbd-odbc、ruby-odbc gems をインストールします:
gem install dbi
gem install dbd-odbc
gem install ruby-odbc
Azure Data Catalog データに連携するRuby アプリケーションの作成
Ruby ファイル (例: AzureDataCatalogSelect.rb) を作成し、テキストエディタで開きます。ファイルに次のコードをコピーします:
#connect to the DSN
require 'DBI'
cnxn = DBI.connect('DBI:ODBC:CData AzureDataCatalog Source','','')
#execute a SELECT query and store the result set
resultSet = cnxn.execute("SELECT DslAddressDatabase, Type FROM Tables WHERE Name = 'FactProductInventory'")
#display the names of the columns
resultSet.column_names.each do |name|
print name, "\t"
end
puts
#display the results
while row = resultSet.fetch do
(0..resultSet.column_names.size - 1).each do |n|
print row[n], "\t"
end
puts
end
resultSet.finish
#close the connection
cnxn.disconnect if cnxn
これで、Ruby で Azure Data Catalog データが接続できるようになります。簡単にコマンドラインからファイルを叩いて接続を確認してみましょう。:
ruby AzureDataCatalogSelect.rb
Azure Data Catalog へのSQL-92 企画のSQL を使って、Ruby に簡単にAzure Data Catalog を連携できます。是非、トライアルで試してみてください。