我们知道U-SQL在提取文件时支持目录和文件名模式匹配。我想知道它是否支持基于ADLS中文件创建日期的模式匹配(不实现自定义提取器)。
假设一个文件夹包含跨月创建的文件(文件名没有日期作为文件名的一部分),是否有办法只提取特定月份的文件。
答案 0 :(得分:1)
U-SQL EXTRACT运算符不知道有关文件的任何元数据(例如创建日期) - 只知道文件名。
答案 1 :(得分:1)
您可以使用.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
答案 2 :(得分:0)
目前无法访问或使用文件元数据属性。请将您的投票和用例添加到以下反馈项:https://feedback.azure.com/forums/327234-data-lake/suggestions/10948392-support-functionality-to-handle-file-properties-fr
答案 3 :(得分:0)
问这个问题已经有一段时间了,我不确定这是否是您最初要寻找的东西,但是现在您可以使用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