我们知道U-SQL在提取文件时支持目录和文件名模式匹配。我想知道的是,它是否支持基于ADLS中文件创建日期的模式匹配(无需实现自定义提取器)。
假设一个文件夹包含跨月份创建的文件(文件名中没有日期),有没有办法只提取特定月份的文件。
U-SQL 数据提取运算符不知道有关文件的任何元数据(如创建日期),只有文件名。
您可以使用 .NET SDK 生成解决方案。 对于相当简单的事情,您可以使用PowerShell创建一个文件,其中包含符合日期时间条件的所有文件。 然后根据需要使用内容。
# Log in to your Azure account
Login-AzureRmAccount
# Modify variables as required
$DataLakeStoreAccount = "<yourDataLakeStoreAccountNameHere>";
$DataLakeAnalyticsAccount = <yourDataLakeAnalyticsAccountNameHere>";
$DataLakeStorePath = "/Samples/Data/AmbulanceData/"; #modify as desired
$outputFile = "Samples/Outputs/ReferenceGuide/filteredFiles.csv"; #modify as desired
$filterDate = "2016-11-22";
$jobName = "GetFiles";
# Query directory and build main body of script. Note, there is a csv filter.
[string]$body =
"@initial =
SELECT * FROM
(VALUES
" +
(Get-AzureRmDataLakeStoreChildItem -Account $DataLakeStoreAccount -Path $DataLakeStorePath |
Where {$_.Name -like "*.csv" -and $_.Type -eq "FILE"} | foreach {
"(""" + $DataLakeStorePath + $_.Name + """, (DateTime)FILE.CREATED(""" + $DataLakeStorePath + $_.Name + """)), `r`n" });
# formattig, add column names
$body =
$body.Substring(0,$body.Length-4) + "
) AS T(fileName, createDate);";
# U-SQL query and OUTPUT statement
[string]$output =
"
// filter results based on desired time frame
@filtered =
SELECT fileName
FROM @initial
WHERE createDate.ToString(""yyyy-MM-dd"") == ""$filterDate"";
OUTPUT @filtered
TO ""$outputFile""
USING Outputters.Csv();";
# bring it all together
$script = $body + $output;
#Execute job
$jobInfo = Submit-AzureRmDataLakeAnalyticsJob -Account $DataLakeAnalyticsAccount -Name $jobName -Script $script -DegreeOfParallelism 1
#check job progress
Get-AzureRmDataLakeAnalyticsJob -Account $DataLakeAnalyticsAccount -JobId $jobInfo.JobId -ErrorAction SilentlyContinue;
Write-Host "You now have a list of desired files to check @ " $outputFile
目前无法访问或使用文件元数据属性。请将您的投票和用例添加到以下反馈项中: https://feedback.azure.com/forums/327234-data-lake/suggestions/10948392-support-functionality-to-handle-file-properties-fr
自从提出这个问题以来已经有一段时间了,我不确定这是否是您最初要寻找的,但现在您可以使用 FILE.MODIFIED
U-SQL 函数:
DECLARE @watermark string = "2018-08-16T18:12:03";
SET @@FeaturePreviews="InputFileGrouping:on";
DECLARE @file_set_path string = "adl://adls.azuredatalakestore.net/stage/InputSample.tsv";
@input =
EXTRACT [columnA] int?,
[columnB] string
FROM @file_set_path
USING Extractors.Tsv(skipFirstNRows : 1, silent : true);
@result =
SELECT *, FILE.MODIFIED(@file_set_path) AS FileModifiedDate
FROM @input
WHERE FILE.MODIFIED(@file_set_path) > DateTime.ParseExact(@watermark, "yyyy-MM-ddTHH:mm:ss", NULL);
OUTPUT @result TO "adl://ADLS.azuredatalakestore.net/stage/OutputSample.tsv" USING Outputters.Tsv(outputHeader:true);
此处记录了 U-SQL 内置函数:https://msdn.microsoft.com/en-us/azure/data-lake-analytics/u-sql/file-modified-u-sql