简体   繁体   English

Read CSV From Azure Data lake storage Gen 1 in c# .net API

[英]Read CSV From Azure Data lake storage Gen 1 in c# .net API

We need to read a CSV File of around 2 GB which is stored in Azure Data lake storage Gen1 .The purpose is like we have to render the data in Grid format (UI ) with high performance when user request.我们需要读取一个大约2 GB的 CSV 文件,该文件存储在Azure 数据湖存储 Gen1中。目的就像我们必须在用户请求时以高性能的网格格式 (UI) 呈现数据。 We are using .Net Core 2.1 (c#) for doing API for the same.我们使用.Net Core 2.1 (c#)来做同样的事情 API。

        var creds = new ClientCredential(applicationId, clientSecret);
        var clientCreds = ApplicationTokenProvider.LoginSilentAsync(tenantId, creds).GetAwaiter().GetResult();

        // Create ADLS client object
        AdlsClient client = AdlsClient.CreateClient(adlsAccountFQDN, clientCreds);

        string fileName = "/cchbc/sources/MVP/Data.csv";

        using (var readStream = new StreamReader(client.GetReadStream(fileName)))
        {

            while ((line = readStream.ReadLine()) != null)
            {
                content = content + line;
            }
        }

I have tried the above code but failed with an error GETFILESTATUS failed with HttpStatus:Forbidden RemoteException: AccessControlException GETFILESTATUS failed with error 0x83090aa2 (Forbidden. ACL verification failed. Either the resource does not exist or the user is not authorized to perform the requested operation.)我已经尝试了上面的代码,但失败并出现错误GETFILESTATUS failed with HttpStatus:Forbidden RemoteException: AccessControlException GETFILESTATUS failed with error 0x83090aa2 (Forbidden. ACL 验证失败。资源不存在或用户无权执行请求的操作。 )

Any suggestion will be very beneficial.Thanks in advance任何建议都会非常有益。在此先感谢

If you want to use a service principal to access files storing in Azure data lake gen 1, we need to configure ACL for the service principal.如果要使用服务主体访问存储在 Azure 数据湖 gen 1 中的文件,我们需要为服务主体配置ACL The ACL has three permissions Read(read the contents of a file) Write(write or append to a file) and Execute(traverse the child items of a folder). ACL 具有三个权限读取(读取文件的内容)写入(写入或 append 到文件)和执行(遍历文件夹的子项)。

for example I access file /test/test.csv例如我访问文件 /test/test.csv

  1. Configure ACL as below如下配置ACL
Opreation    Object        /        test/      test.csv
Read         tets.csv      --X      --X        R-- 

在此处输入图像描述 在此处输入图像描述

  1. Code代码
string appId = "service principal appId";
            string appSecret = "service principal appSecret";
            string domain = "service principal domain";

            var serviceSettings = ActiveDirectoryServiceSettings.Azure;
            serviceSettings.TokenAudience = new Uri(@"https://datalake.azure.net/");
            
            var creds = await ApplicationTokenProvider.LoginSilentAsync(domain, appId, appSecret, serviceSettings);

            string accountName = "testadls02";
            AdlsClient client = AdlsClient.CreateClient($"{accountName}.azuredatalakestore.net", creds);
            string fileName = "/test/test.csv";
            string line = null;
            using (var readStream = new StreamReader(client.GetReadStream(fileName)))
            {
                while ((line =  await readStream.ReadLineAsync()) != null) {

                    Console.WriteLine(line);
                }
               
            }

在此处输入图像描述

For more details, please refer to here更多详情,请参考这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过 Azure 函数中的 C# 将文件从一个 DataLake Gen2 复制到另一个 Data Lake Gen 2 - Copy file from one DataLake Gen2 to another Data Lake Gen 2 via C# in Azure Functions Azure Data Lake Gen2 - 如何使用 C# 将文件从文件夹移动到另一个文件夹 - Azure Data Lake Gen2 - How do I move files from folder to another folder using C# Azure Data Lake Gen 2 - 如何选择加入“Azure Data Lake Storage 上的多协议访问” - Azure Data Lake Gen 2 - How to opt in to “Multi-protocol access on Azure Data Lake Storage” 从 Azure 数据湖中读取和查询 Parquet 文件 - Read and Query Parquet files from Azure Data Lake Using Azure Function without downloading locally C# 从 azure 函数连接到 Azure 数据湖 Gen 2 - Connection to Azure data lake Gen 2 from azure function 从 C# 中的 Azure 数据湖读取数据 - Reading data from Azure Data Lake in C# 如何在 C# 中使用服务主体(clientId 和 clientSecret)为 Azure Data Lake Store(Gen-2)创建 SAS 令牌? - How to create SAS token for Azure Data Lake Store (Gen-2) using service principals (clientId and clientSecret) in C#? Data Lake Gen 2 的 Azure Blob 触发器函数 - Azure Blob Trigger Function for Data Lake Gen 2 如何创建文件或将文件上传到Azure Data Lake Storage Gen2 - How to create a file or upload a file to Azure Data Lake Storage Gen2 使用Azure Functions调用REST API并将结果保存在Azure Data Lake gen2中 - Using Azure Functions to call REST API and save results in Azure Data Lake gen2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM