从 Azure Data Lake Gen 2 中删除未刷新的文件
Delete unflushed file from Azure Data Lake Gen 2
要先将文件上传到 ADL,您需要:
- 使用
?resource=file
参数执行放置请求(这会在 ADL 上创建一个文件)
- 使用
?action=append&position=<N>
参数将数据追加到文件中
- 最后,您需要使用
?action=flush&position=<FILE_SIZE>
刷新数据
我的问题是:
有没有办法告诉服务器如果数据没有刷新(写入),数据应该存在多长时间。
由于需要先创建一个文件来写入数据,因此可能会出现刷新不发生的情况,而您会卡在数据湖中的一个空文件中。
我在 Microsoft documentation 上找不到任何关于此的内容。
如有任何信息,我们将不胜感激。
更新 0219:
如果只调用append api
,不调用flush api
,那么未提交的数据会在7天内保存在azure中。
未提交的数据将在7天后自动删除,您端无法删除。
原文:
用于 Azure Datalake Storage Gen2 的 SDK 已经准备就绪,您可以使用它比使用 rest 更轻松地操作 ADLS Gen2 api。
如果您使用的是 .NET/c#,则有一个适用于 Azure Datalake Storage Gen2 的 SDK:Azure.Storage.Files.DataLake。
这里是关于如何使用这个SDK操作ADLS Gen2的官方文档,下面的c#代码用于ADLS Gen2的删除文件/上传文件:
static void Main(string[] args)
{
string accountName = "xxx";
string accountKey = "xxx";
StorageSharedKeyCredential sharedKeyCredential =
new StorageSharedKeyCredential(accountName, accountKey);
string dfsUri = "https://" + accountName + ".dfs.core.windows.net";
DataLakeServiceClient dataLakeServiceClient = new DataLakeServiceClient
(new Uri(dfsUri), sharedKeyCredential);
DataLakeFileSystemClient fileSystemClient = dataLakeServiceClient.GetFileSystemClient("w22");
DataLakeDirectoryClient directoryClient = fileSystemClient.GetDirectoryClient("t2");
// use this line of code to delete a file
//directoryClient.DeleteFile("22.txt");
//use the code below to upload a file
//DataLakeFileClient fileClient = directoryClient.CreateFile("22.txt");
//FileStream fileStream = File.OpenRead("d:\foo2.txt");
//long fileSize = fileStream.Length;
//fileClient.Append(fileStream, offset: 0);
//fileClient.Flush(position: fileSize);
Console.WriteLine("**completed**");
Console.ReadLine();
}
关于Java,参考这个doc。
关于Python,参考这个doc。
要先将文件上传到 ADL,您需要:
- 使用
?resource=file
参数执行放置请求(这会在 ADL 上创建一个文件) - 使用
?action=append&position=<N>
参数将数据追加到文件中 - 最后,您需要使用
?action=flush&position=<FILE_SIZE>
刷新数据
我的问题是:
有没有办法告诉服务器如果数据没有刷新(写入),数据应该存在多长时间。
由于需要先创建一个文件来写入数据,因此可能会出现刷新不发生的情况,而您会卡在数据湖中的一个空文件中。
我在 Microsoft documentation 上找不到任何关于此的内容。
如有任何信息,我们将不胜感激。
更新 0219:
如果只调用append api
,不调用flush api
,那么未提交的数据会在7天内保存在azure中。
未提交的数据将在7天后自动删除,您端无法删除。
原文:
用于 Azure Datalake Storage Gen2 的 SDK 已经准备就绪,您可以使用它比使用 rest 更轻松地操作 ADLS Gen2 api。
如果您使用的是 .NET/c#,则有一个适用于 Azure Datalake Storage Gen2 的 SDK:Azure.Storage.Files.DataLake。
这里是关于如何使用这个SDK操作ADLS Gen2的官方文档,下面的c#代码用于ADLS Gen2的删除文件/上传文件:
static void Main(string[] args)
{
string accountName = "xxx";
string accountKey = "xxx";
StorageSharedKeyCredential sharedKeyCredential =
new StorageSharedKeyCredential(accountName, accountKey);
string dfsUri = "https://" + accountName + ".dfs.core.windows.net";
DataLakeServiceClient dataLakeServiceClient = new DataLakeServiceClient
(new Uri(dfsUri), sharedKeyCredential);
DataLakeFileSystemClient fileSystemClient = dataLakeServiceClient.GetFileSystemClient("w22");
DataLakeDirectoryClient directoryClient = fileSystemClient.GetDirectoryClient("t2");
// use this line of code to delete a file
//directoryClient.DeleteFile("22.txt");
//use the code below to upload a file
//DataLakeFileClient fileClient = directoryClient.CreateFile("22.txt");
//FileStream fileStream = File.OpenRead("d:\foo2.txt");
//long fileSize = fileStream.Length;
//fileClient.Append(fileStream, offset: 0);
//fileClient.Flush(position: fileSize);
Console.WriteLine("**completed**");
Console.ReadLine();
}
关于Java,参考这个doc。
关于Python,参考这个doc。