Search code examples
c#.netazure-data-lakeu-sql

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


Is it possible to get file "full path" from following u-sql code, just like file name column?

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();

From the above u-sql query I am able to get file name but I want file full path also. Like "D:/Sample/Data"


Solution

  • Well you already have the input path in a variable at the top of your script so just add that to the output dataset. Like this:

    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();