U-SQL从模式获取文件路径 [英] U-SQL get file paths from pattern

查看:62
本文介绍了U-SQL从模式获取文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取文件列表,然后过滤此集合

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}

如果可能的话...

推荐答案

方法是在文件集中定义虚拟列.然后,您可以提取和操作这些虚拟列,就像它们是从文件中提取的数据字段一样.示例:

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甚至不会读取与WHERE子句不匹配的文件,从而为您节省了一些时间. (此外,虚拟列名称中的下划线不是必需的,而是记住哪些列来自文件以及哪些列来自路径的有用方法).希望这会有所帮助!

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!

这篇关于U-SQL从模式获取文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆