简体   繁体   English

Azure Data Lake Loop

[英]Azure Data Lake Loop

Does Azure Data Lake Analytics and U-SQL support use While or For to Loop and create multiple outputs? Azure Data Lake Analytics和U-SQL支持使用While或For循环并创建多个输出吗? I want output to multiple files using one USQL execution. 我希望使用一个USQL执行输出到多个文件。

This is what i want: 这就是我要的:

Foreach @day in @days
    @dataToSave = 
        SELECT    day AS day,
                  company AS Company,      
        FROM @data
        WHERE @day = @day

    @out = @day + ".txt"

    OUTPUT @dataToSave
    TO @out
    USING Outputters.Text();
Next

I know i can use a powershell, but i think that will cost performance prepairing the execution. 我知道我可以使用powershell,但我认为这会耗费性能来准备执行。

U-SQL does not support While or For loops. U-SQL不支持While或For循环。 You can use WHERE statements to filter extracted data, and virtual columns to filter based on file paths/names ( example ). 您可以使用WHERE语句过滤提取的数据,并使用虚拟列根据文件路径/名称进行过滤( 示例 )。

To output to multiple files, you can write a unique rowset and WHERE clause for each output if its a reasonable number of files. 要输出到多个文件,如果每个输出的文件数量合理,则可以为其创建唯一的rowset和WHERE子句。

As you said, you could also script this with Powershell or U-SQL ( example ). 正如您所说,您也可以使用Powershell或U-SQL编写脚本( 示例 )。

Dynamic output to multiple files is currently in a limited private preview. 动态输出到多个文件目前处于有限的私人预览中。 Please send an email to usql at microsoft dot com with your scenario if you're interested in this feature, as it could work for your scenario based on your description. 如果您对此功能感兴趣,请发送电子邮件至microsoft dot com的usql,因为它可以根据您的描述适用于您的场景。

Hope this helps, and let me know if you have more questions about implementing any of these solutions. 希望这会有所帮助,如果您对实施任何这些解决方案有更多疑问,请告诉我。

You can try create a custom outputter and ignore the output file and write on your own file! 您可以尝试创建自定义输出器并忽略输出文件并在您自己的文件上写入! public override void Output (IRow row, IUnstructuredWriter output) public override void Output(IRow行,IUnstructuredWriter输出)

Try this, using outputter too: 试试这个,也使用输出器:

public override void Output(IRow input, IUnstructuredWriter output)
    {
       using (System.IO.StreamWriter streamWriter = new StreamWriter(address + _file, true))
    //Save on file!
    }

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM