【发布时间】:2019-10-02 18:40:55
【问题描述】:
我们使用自定义 USQL 提取器来扁平化 json 结构。如果 json 的 line(json object) 小于 4 MB,则以下示例代码可以正常工作。如果行大小超过 4 MB,那么我们得到错误 “输入文件中的记录长于 4194304 字节。” 类似的代码在 C# 独立应用程序中尝试超过 4 MB 的行,它工作正常。使用 usql 自定义提取器对 json 大小有任何限制吗?我们如何处理大小超过 4 MB 的 json 消息?
错误是从下面代码
string line = lineReader.ReadToEnd();
自定义提取器示例代码
使用 Microsoft.Analytics.Interfaces;
使用 System.Collections.Generic;
使用 System.IO;
使用 System.Text;
使用 Microsoft.Analytics.Types.Sql;
使用 Newtonsoft.Json;
命名空间 Company.DataLakeAnalytics
{
[SqlUserDefinedExtractor(AtomicFileProcessing = false)]
公共类 CustomJSONExtractor : IExtractor
{
私有只读编码_encoding;
私有只读字节[] _row_delim;
私有字符串 DELIMITER = "~";
public CustomJSONExtractor(Encoding encoding = null, string row_delim = "\r\n")
{
_encoding = 编码.UTF8;
_row_delim = _encoding.GetBytes(row_delim);
}
//原始文件中的每一个json行都被转换成一个扁平结构
公共覆盖 IEnumerable 提取(IUnstructuredReader 输入,IUpdatableRow 输出)
{
//逐行读取输入
foreach(输入中的流电流。Split(_row_delim))
{
使用 (StreamReader lineReader = new StreamReader(current, this._encoding))
{
//读取整行
字符串 line = lineReader.ReadToEnd();
//将行换成多个变量
output.Set(1, "A~1");
产生返回输出.AsReadOnly();
}
}
}
}
}
示例 USQL 代码
声明 @INPUT_FILE="sample-data.txt"; @jsonDatafile = EXTRACT key string, jsonObjStr string FROM @INPUT_FILE USING new Damen.DataLakeAnalytics.CustomJSONExtractor(null,row_delim:"\n") ; @dataJsonObject = 从 @dataAsStrings 中选择 jsonObjStr 作为 rawData; 输出 @dataJsonObject 到 @flattenedOutputFile 使用 Outputters.Text(outputHeader:false,quoting: false,delimiter:'~');
【问题讨论】:
-
我能够在(本地机器)ADLS 上处理更大的文件。请更具体一点,或者发送一个您说正在独立 C# 应用程序上工作的 sn-p。
-
@Milan-below 代码有效,正如我提到的 lineReader.ReadToEnd() 在 ADLA 中失败,但它在下面的程序中有效,你在天蓝色的云中尝试过吗?公共类实用程序 { public static string ProcessData() { using (StreamReader lineReader = new StreamReader("{pathToaFile}test-data-1.txt")) { string line = lineReader.ReadToEnd(); int a = line.Length; Console.WriteLine("字符长度:" + a); } } }
标签: azure-data-lake u-sql