如何在 U-SQL 查询中获取文件的完整路径

How to get Full Path of file in U-SQL query

是否可以从下面的 u-sql 代码中获取文件 "full path",就像文件名列一样?

DECLARE @in = "D:/Sample/Data/{FileName}";

@drivers =
    EXTRACT id string,
            first_name string,
            last_name string,
            address string,
            FileName string
    FROM @in
    USING USING Extractors.Csv();

OUTPUT @drivers
TO "/ReferenceGuide/DML/QSE/Extract/Drivers.txt"
USING Outputters.Csv();

从上面的 u-sql 查询我可以得到文件名,但我也想要文件的完整路径。喜欢"D:/Sample/Data"

好吧,您已经在脚本顶部的变量中有了输入路径,因此只需将其添加到输出数据集中即可。像这样:

DECLARE @in = "D:/Sample/Data/{FileName}";

@drivers =
    EXTRACT id string,
            first_name string,
            last_name string,
            address string,
            FileName string
    FROM @in
    USING USING Extractors.Csv();


@driverswithpath =
    SELECT
        *,
        @in AS 'InputPath'
    FROM
        @drivers;

OUTPUT @driverswithpath
TO "/ReferenceGuide/DML/QSE/Extract/Drivers.txt"
USING Outputters.Csv();

正如您可以在 U-SQL 中的字符串上使用 .net 方法一样,您可以使用 Replace 方法来重建整个文件路径,如下所示:

DECLARE @in string = "input/{FileName}";

@drivers =
    EXTRACT id string,
            first_name string,
            last_name string,
            address string,
            FileName string
    FROM @in
    USING Extractors.Csv();


@driverswithpath =
    SELECT
        *,
        @in.Replace("{FileName}", FileName) AS InputPath
    FROM
        @drivers;

OUTPUT @driverswithpath TO "/output/output.csv"
USING Outputters.Csv();