简体   繁体   English

Azure 数据湖 - 条件

[英]Azure Data Lake - Conditions

I would like to use if-else statement to decide at what location I have to export data.我想使用 if-else 语句来决定我必须在哪个位置导出数据。 My case is:我的情况是:

  1. I extract several files from the azure blob storage ( it's possible that there are no files!! ).我从 azure blob 存储中提取了几个文件(可能没有文件!! )。
  2. I calculate count of records in file set.我计算文件集中的记录数。
  3. If count of records is > 20 then I export files into specific report location如果记录数 > 20,那么我将文件导出到特定的报告位置
  4. If in file set are no records, I have to output dummy empty file into different location, because I don't want replace existing report by empty report.如果文件集中没有记录,我必须将虚拟空文件输出到不同的位置,因为我不想用空报告替换现有报告。

The solution may be IF..ELSE confition.解决方案可能是 IF..ELSE 配置。 The problem is that if I calculate count of records I got rowset variable and I cannot compare it with scalar variable.问题是,如果我计算记录数,我得到了行集变量,我无法将它与标量变量进行比较。

@RECORDS =
SELECT COUNT(id) AS IdsCount
FROM @final; 


IF @RECORDS <= 20 THEN //generate dummy empty file 
    OUTPUT @final_result
    TO @EMPTY_OUTPUT_FILE
    USING Outputters.Text(delimiter : '\t', quoting : true, encoding : Encoding.UTF8, outputHeader : true, dateTimeFormat : "s", nullEscape : "NULL");
ELSE 
    OUTPUT @final_result
    TO @OUTPUT_FILE
    USING Outputters.Text(delimiter : '\t', quoting : true, encoding : Encoding.UTF8, outputHeader : true, dateTimeFormat : "s", nullEscape : "NULL");
END;

U-SQL's IF statement is currently only used during compilation time. U-SQL 的 IF 语句目前只在编译时使用。 So you can do something like所以你可以做类似的事情

IF FILE.EXIST() THEN

But if you want to output different files depending on the number of records you would have to write it at the SDK/CLI level:但是,如果您想根据记录数输出不同的文件,则必须在 SDK/CLI 级别编写它:

The first job writes a temp file output (and maybe a status file that contains number of rows).第一个作业写入一个临时文件输出(可能还有一个包含行数的状态文件)。 Then you check (for example in Powershell) whether the file is empty (or whatever criteria you want to use) and if not, copy the result over otherwise create the empty output file.然后您检查(例如在 Powershell 中)文件是否为空(或您想要使用的任何标准),如果不是,则复制结果,否则创建空输出文件。

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

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