.NET 用 Azure Storage Files Data Lake クライアント ライブラリ - バージョン 12.17.0

サーバー バージョン: 2021-02-12、2020-12-06、2020-10-02、 2020-08-04、2020-06-12、2020-04-08、2020-02-10、2019-12-12、2019-07-07、および 2019-02-02

Azure Data Lake には、開発者、データ サイエンティスト、アナリストが、さまざまなサイズ、形状、スピードのデータを容易に格納し、さまざまなプラットフォームと言語を使用したあらゆる種類の処理と分析を簡単に実行するために必要な機能がすべて組み込まれています。 すべてのデータの取り込みと保存に伴う複雑さを解消し、バッチ処理、ストリーミング、対話型の分析を迅速に立ち上げて実行することができます。

ソースコード | パッケージ (NuGet) | API リファレンス ドキュメント | REST API のドキュメント | 製品ドキュメント

作業の開始

パッケージをインストールする

NuGet を使用して .NET 用の Azure Storage Files Data Lake クライアント ライブラリをインストールします。

dotnet add package Azure.Storage.Files.DataLake

前提条件

このパッケージを使用するには、 Azure サブスクリプションストレージ アカウント が必要です。

新しいストレージ アカウントを作成するには、Azure PortalAzure PowerShell、または Azure CLI を使用できます。 Azure CLI を使う例を次に示します。

az storage account create --name MyStorageAccount --resource-group MyResourceGroup --location westus --sku Standard_LRS

主要な概念

DataLake Storage Gen2 は、次のように設計されています。

  • 数百ギガビットのスループットを維持しながら、複数のペタバイトの情報を提供する
  • 大量のデータを簡単に管理できます

DataLake Storage Gen2 の主な機能は次のとおりです。

  • Hadoop と互換性のあるアクセス
  • POSIX 権限のスーパーセット
  • 低コストのストレージ容量とトランザクションの観点からコスト効率が高い
  • ビッグ データ分析用に最適化されたドライバー

Data Lake Storage Gen2 の基礎部分は、BLOB ストレージに階層型名前空間を追加したものです。 階層型名前空間には、効率的なデータ アクセスのためにオブジェクトやファイルがディレクトリ階層に編成されています。

以前は、パフォーマンス、管理、およびセキュリティの領域では、クラウドベース分析は妥協する必要がありました。 Data Lake Storage Gen2 では、次の方法で各側面に対応しています。

  • パフォーマンス。分析の前提条件としてデータをコピーまたは変換する必要がないため、最適化されます。 階層型名前空間によってディレクトリ管理操作のパフォーマンスは大幅に向上し、その結果、全体的なジョブ パフォーマンスも向上します。
  • 管理。ディレクトリおよびサブディレクトリを利用してファイルを編成および操作できるため、簡単になりました。
  • セキュリティ。ディレクトリや個別のファイルに対して POSIX アクセス許可を定義できるので、セキュリティを確保できます。
  • コスト効率。Data Lake Storage Gen2 が低コストの Azure Blob ストレージの上位にビルドされていることで、実現されました。 さらに、追加の機能により、Azure 上でビッグ データ分析を実行するための総保有コストが低下しました。

Data Lake Storage Gen2には、次の 2 種類のリソースが用意されています。

  • 'DataLakeFileSystemClient' を介して使用されるファイルシステム
  • 'DataLakeFileClient' または 'DataLakeDirectoryClient' を介して使用されるパス
ADLS Gen2 BLOB
ファイルシステム コンテナー
パス (ファイルまたはディレクトリ) BLOB

注: このクライアント ライブラリでは、階層型名前空間 (HNS) が無効になっているストレージ アカウントはサポートされていません。

スレッド セーフ

すべてのクライアント インスタンス メソッドがスレッド セーフであり、相互に独立していることを保証します (ガイドライン)。 これにより、スレッド間であっても、クライアント インスタンスの再利用に関する推奨事項が常に安全になります。

その他の概念

クライアント オプション | 応答 | へのアクセス実行時間の長い操作 | エラーの | 処理診断 | あざける | クライアントの有効期間

DataLakeServiceClient を作成する

StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey);

// Create DataLakeServiceClient using StorageSharedKeyCredentials
DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential);

DataLakeFileSystemClient を作成する

StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey);

// Create DataLakeServiceClient using StorageSharedKeyCredentials
DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential);

// Create a DataLake Filesystem
DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient("sample-filesystem");
filesystem.Create();

DataLakeDirectoryClient を作成する

StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(storageAccountName, storageAccountKey);

// Create DataLakeServiceClient using StorageSharedKeyCredentials
DataLakeServiceClient serviceClient = new DataLakeServiceClient(serviceUri, sharedKeyCredential);

// Get a reference to a filesystem named "sample-filesystem-append" and then create it
DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient("sample-filesystem-append");
filesystem.Create();

// Create
DataLakeDirectoryClient directory = filesystem.GetDirectoryClient("sample-file");
directory.Create();

DataLakeFileClient を作成する

DataLakeDirectoryClient から DataLakeFileClient を作成する

// Create a DataLake Directory
DataLakeDirectoryClient directory = filesystem.CreateDirectory("sample-directory");
directory.Create();

// Create a DataLake File using a DataLake Directory
DataLakeFileClient file = directory.GetFileClient("sample-file");
file.Create();

DataLakeFileSystemClient から DataLakeFileClient を作成する

// Create a DataLake Filesystem
DataLakeFileSystemClient filesystem = serviceClient.GetFileSystemClient("sample-filesystem");
filesystem.Create();

// Create a DataLake file using a DataLake Filesystem
DataLakeFileClient file = filesystem.GetFileClient("sample-file");
file.Create();

DataLake ファイルへのデータの追加

// Create a file
DataLakeFileClient file = filesystem.GetFileClient("sample-file");
file.Create();

// Append data to the DataLake File
file.Append(File.OpenRead(sampleFilePath), 0);
file.Flush(SampleFileContent.Length);

DataLake ファイルからのデータの読み取り

Response<FileDownloadInfo> fileContents = file.Read();

DataLake ファイルシステムの一覧表示/走査

foreach (PathItem pathItem in filesystem.GetPaths())
{
    names.Add(pathItem.Name);
}

DataLake ファイルに対するアクセス許可を設定する

// Create a DataLake file so we can set the Access Controls on the files
DataLakeFileClient fileClient = filesystem.GetFileClient("sample-file");
fileClient.Create();

// Set the Permissions of the file
PathPermissions pathPermissions = PathPermissions.ParseSymbolicPermissions("rwxrwxrwx");
fileClient.SetPermissions(permissions: pathPermissions);

DataLake ファイルにアクセス制御 (ACL) を設定する

// Create a DataLake file so we can set the Access Controls on the files
DataLakeFileClient fileClient = filesystem.GetFileClient("sample-file");
fileClient.Create();

// Set Access Control List
IList<PathAccessControlItem> accessControlList
    = PathAccessControlExtensions.ParseAccessControlList("user::rwx,group::r--,mask::rwx,other::---");
fileClient.SetAccessControlList(accessControlList);

DataLake ファイルのアクセス制御 (ACL) を取得する

// Get Access Control List
PathAccessControl accessControlResponse = fileClient.GetAccessControl();

DataLake ファイルの名前を変更する

DataLakeFileClient renamedFileClient = fileClient.Rename("sample-file2");

DataLake ディレクトリの名前を変更する

DataLakeDirectoryClient renamedDirectoryClient = directoryClient.Rename("sample-directory2");

DataLake ファイルのプロパティを取得する

// Get Properties on a File
PathProperties filePathProperties = fileClient.GetProperties();

DataLake ディレクトリのプロパティを取得する

// Get Properties on a Directory
PathProperties directoryPathProperties = directoryClient.GetProperties();

トラブルシューティング

すべての File DataLake サービス操作では、失敗した場合に RequestFailedException がスローされ、役に立ちますErrorCode。 これらのエラーの多くは回復可能です。

次のステップ

DataLake サンプルの概要:

  1. Hello World: DataLake ファイルの追加、読み取り、および一覧表示 (または非同期)
  2. 認証: パブリック アクセス、共有キー、共有アクセス署名、Azure Active Directory を使用して認証します。

共同作成

このライブラリのビルド、テスト、および投稿の詳細については、「 Storage CONTRIBUTING.md 」を参照してください。

このプロジェクトでは、共同作成と提案を歓迎しています。 ほとんどの共同作成では、共同作成者使用許諾契約書 (CLA) にご同意いただき、ご自身の共同作成内容を使用する権利を Microsoft に供与する権利をお持ちであり、かつ実際に供与することを宣言していただく必要があります。 詳細については、「 cla.microsoft.com」を参照してください。

このプロジェクトでは、Microsoft オープン ソースの倫理規定を採用しています。 詳しくは、「Code of Conduct FAQ (倫理規定についてよくある質問)」を参照するか、opencode@microsoft.com 宛てに質問またはコメントをお送りください。

インプレッション数