ADO.NET Provider for Google BigQuery

Build 23.0.8839

DataAdapter を使用したクエリ

CData ADO.NET Provider for Google BigQuery では、次の2つのネイティブ.NET インターフェースを使用して、Google BigQuery からデータを取得できます。GoogleBigQueryDataAdapter オブジェクトおよびGoogleBigQueryDataReader オブジェクト。各オブジェクトは同じタスク(データの取得)を実行しますが、実行方法が異なります。GoogleBigQueryDataAdapter オブジェクトはクエリに一致するすべてのデータを取得しますが、GoogleBigQueryDataReader オブジェクトは必要に応じてインクリメントしながら一部のデータだけをフェッチします。

GoogleBigQueryDataAdapter の使用

アダプターのFill メソッドを使用して、データソースからデータを取得します。空のDataTable インスタンスがFill メソッドへの引数として渡されます。このメソッドが戻ってきたとき、DataTable インスタンスにはクエリされたデータが設定されています。Fill メソッドは、戻る前にデータソースからすべてのデータを取得する必要があるため、GoogleBigQueryDataAdapter はGoogleBigQueryDataReader よりも時間がかかります。

次の例は、github_nested テーブルのactor.attributes.email カラムとrepository.name カラムを選択します。

C#

string connectionString = "InitiateOAuth=GETANDREFRESH;ProjectId=NameOfProject;DatasetId=NameOfDataset;";

using (GoogleBigQueryConnection connection = new GoogleBigQueryConnection(connectionString)) {
  GoogleBigQueryDataAdapter dataAdapter = new GoogleBigQueryDataAdapter(
  "SELECT actor.attributes.email, repository.name FROM [publicdata].[samples].github_nested", connection);

  DataTable table = new DataTable();
  dataAdapter.Fill(table);

  Console.WriteLine("Contents of github_nested.");

  foreach (DataRow row in table.Rows) {
    Console.WriteLine("{0}: {1}", row["actor.attributes.email"], row["repository.name"]);
  }
}

VB.NET

Dim connectionString As String = "InitiateOAuth=GETANDREFRESH;ProjectId=NameOfProject;DatasetId=NameOfDataset;"

Using connection As New GoogleBigQueryConnection(connectionString)
  Dim dataAdapter As New GoogleBigQueryDataAdapter("SELECT actor.attributes.email, repository.name FROM [publicdata].[samples].github_nested", connection)

  Dim table As New DataTable()
  dataAdapter.Fill(table)

  Console.WriteLine("Contents of github_nested.")

  For Each row As DataRow In table.Rows
    Console.WriteLine("{0}: {1}", row("actor.attributes.email"), row("repository.name"))
  Next
End Using

Copyright (c) 2024 CData Software, Inc. - All rights reserved.
Build 23.0.8839