U-SQL get file paths from pattern

孤者浪人 提交于 2019-12-25 00:45:32

问题


I need to get a list of files to then filter this set

DECLARE @input_file string = @"\data\{*}\{*}\{*}.avro";

@filenames = SELECT filename
FROM @input_file;

@filtered = SELECT filename FROM @filenames WHERE {condition}

Something like this if it's possible...


回答1:


The way to do that is define virtual columns in your fileset. You can then extract and manipulate these virtual columns like they were data fields extracted from your file. Example:

DECLARE @input_file string = "/data/{_partition1}/{_partition2}/{filename}.avro";
@rowset = 
    EXTRACT column1     string,
            column2     int,
            columnN     string,
            _partition1 string,
            _partition2 int,
            _filename   string
     FROM @input_file
     USING <Avro extractor>

@filtered = 
    SELECT column1, column2, columnN, _partition1, _partition2, _filename
    WHERE  filename <your condition>

U-SQL will also not even read files that don't match the WHERE clause, saving you some time. (Also, the underscore in the virtual column name is not necessary, but a useful way to remember which columns came from the file and which from the path). Hope this helps!



来源:https://stackoverflow.com/questions/51523207/u-sql-get-file-paths-from-pattern

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!