给出nullEscape参数时,U-SQL中的NULL值替换零长度字符串

时间:2017-08-09 12:39:59

标签: azure-data-lake u-sql

我在U-SQL查询中使用了nullEscape参数。它将\ N替换为零长度字符串。有没有办法将\ N转换为" \ N"使用U-SQL查询。

  

Value1,(零长度字符串),value2,value3,(零长度字符串),(零长度字符串)

我还怀疑我想要\ N而且不需要在提取器中将\ N更改为零长度字符串,同时滑动空值,如\ N吗

I have tried the following but it didn't worked,
USING Extractors.Csv(nullEscape:"\N");

示例CSV数据:

  

名称,,,"",地址,引脚

\ N已被零长度字符串替换。

1 个答案:

答案 0 :(得分:1)

您可以使用条件表达式来转换值,例如

DECLARE @path string = "input/input81.csv";

@data =
    EXTRACT
        a string,
        b string,
        c string,
        d string,
        e string,
        f string
    FROM  @path
    USING 
        Extractors.Csv();


// Convert string \N to zero-length string for selected columns
@output =
    SELECT a,
           b == "\\N"? "" : b AS b,
           c,
           d == "\\N"? "" : d AS d,
           e == "\\N"? "" : d AS e
    FROM @data;


OUTPUT @output
TO "output.csv"
USING Outputters.Csv(quoting : true, outputHeader: true);

我的输入文件是here,这些是我的结果:

U-SQL results