Cmdlets for HDFS

Build 20.0.7654

SELECT INTO ステートメント

SELECT INTO ステートメントを使って、書式付きデータをファイルにエクスポートできます。

SQL クエリを使ったデータのエクスポート

次のクエリは、comma-separated values(CSV)ファイルフォーマットにデータをエクスポートします。

C#

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

using (HDFSConnection connection = new HDFSConnection(connectionString)) {
  HDFSCommand cmd = new HDFSCommand("SELECT FileId, ChildrenNum INTO [csv://Files.txt] FROM [Files] WHERE FileId = '119116' ", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

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

Using connection As New HDFSConnection(connectionString)
  Dim cmd As New HDFSCommand("SELECT FileId, ChildrenNum INTO [csv://Files.txt] FROM [Files] WHERE FileId = '119116'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using
URI で他のファイルフォーマットを指定できます。以下の例は、tab-separated values(TSV)にエクスポートします。

C#

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

using (HDFSConnection connection = new HDFSConnection(connectionString)) {
  HDFSCommand cmd = new HDFSCommand("SELECT * INTO [Files] IN [csv://filename=c:/Files.csv;delimiter=tab] FROM [Files] WHERE FileId = '119116'", connection);
  int rowsAffected = cmd.ExecuteNonQuery();
} 

VB.NET

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

Using connection As New HDFSConnection(connectionString)
  Dim cmd As New HDFSCommand("SELECT * INTO [Files] IN [csv://filename=c:/Files.csv;delimiter=tab] FROM [Files] WHERE FileId = '119116'", connection)
  Dim rowsAffected As Integer = cmd.ExecuteNonQuery()
End Using

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7654