2017-05-29 62 views
2

是否可以像下面的u-sql代碼一樣獲取文件「完整路徑」,就像文件名列一樣?如何在U-SQL查詢中獲取文件的完整路徑

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」

回答

3

那麼你已經在腳本的頂部有一個變量的輸入路徑,所以只需將其添加到輸出數據集。就像這樣:

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

它的工作。謝謝。 :) –

1

您也可以使用在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(); 
相關問題