ADO.NET Provider for Apache Hive

Build 22.0.8479

DataAdapter を使用したクエリ

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

ApacheHiveDataAdapter の使用

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

次の例は、Customers テーブルのCity カラムとCompanyName カラムを選択します。

C#

string connectionString = "Server=127.0.0.1;Port=10000;TransportMode=BINARY";

using (ApacheHiveConnection connection = new ApacheHiveConnection(connectionString)) {
  ApacheHiveDataAdapter dataAdapter = new ApacheHiveDataAdapter(
  "SELECT City, CompanyName FROM [CData].[Default].Customers", connection);

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

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

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

VB.NET

Dim connectionString As String = "Server=127.0.0.1;Port=10000;TransportMode=BINARY"

Using connection As New ApacheHiveConnection(connectionString)
  Dim dataAdapter As New ApacheHiveDataAdapter("SELECT City, CompanyName FROM [CData].[Default].Customers", connection)

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

  Console.WriteLine("Contents of Customers.")

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

Copyright (c) 2023 CData Software, Inc. - All rights reserved.
Build 22.0.8479