ADO.NET Provider for HDFS

Build 23.0.8839

DataAdapter を使用したクエリ

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

HDFSDataAdapter の使用

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

次の例は、Files テーブルのFileId カラムとChildrenNum カラムを選択します。

C#

string connectionString = "Host=sandbox-hdp.hortonworks.com;Port=50070;Path=/user/root;";

using (HDFSConnection connection = new HDFSConnection(connectionString)) {
  HDFSDataAdapter dataAdapter = new HDFSDataAdapter(
  "SELECT FileId, ChildrenNum FROM Files", connection);

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

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

  foreach (DataRow row in table.Rows) {
    Console.WriteLine("{0}: {1}", row["FileId"], row["ChildrenNum"]);
  }
}

VB.NET

Dim connectionString As String = "Host=sandbox-hdp.hortonworks.com;Port=50070;Path=/user/root;"

Using connection As New HDFSConnection(connectionString)
  Dim dataAdapter As New HDFSDataAdapter("SELECT FileId, ChildrenNum FROM Files", connection)

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

  Console.WriteLine("Contents of Files.")

  For Each row As DataRow In table.Rows
    Console.WriteLine("{0}: {1}", row("FileId"), row("ChildrenNum"))
  Next
End Using

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