首页 文章

如何在不使用ADF的情况下参数化USQL输入文件

提问于
浏览
1

我在ADLS中有一个输入文件夹,格式为年/月/日,例如:2017/07/11 . 我想将此输入文件夹作为参数传递给我的usql脚本 . 我没有使用ADF . 我不想从Usql脚本中生成当前日期,因为我不确定输入文件夹是否是当前日期 . 如何有效地做到这一点?

我想到的一种方法是在我的所有输入文件夹上传到ADLS帐户后上传“完成”文件,并且“完成”文件将包含日期 . 但我无法使用该日期来形成我的输入数据路径 . 请帮忙 .

1 回答

  • 1

    假设您的文件夹结构中有几个csv文件(结构为yyyy / MM / dd),并且您想要提取特定日期的文件夹中的所有文件 . 您可以通过两种方式执行此操作(具体取决于您是否需要具有确切的日期时间语义,或者您是否可以使用路径连接) .

    首先是路径连接示例:

    DECLARE EXTERNAL @folder = "2017/07/11"; // Script parameter with default value. 
                                             // You can specify the value also with constant-foldable expression on Datetime.Now.
    
    DECLARE @path = "/constantpath/"+@folder+"/{*.csv}";
    
    @data = EXTRACT I int, s string // or whatever your schema is...
            FROM @path
            USING Extractors.Csv();
    ...
    

    以下是文件集虚拟列的示例:

    DECLARE EXTERNAL @date = "2017/07/11"; // Script parameter with default value. 
                                             // You can specify the value also with constant-foldable expression on Datetime.Now and string serialization (I am not sure if the ADF parameter model supports DateTime values).
    
    DECLARE @path = "/constantpath/{date:yyyy}/{date:MM}/{date:dd}/{*.csv}";
    
    @data = EXTRACT I int, s string // or whatever your schema is...
                  , date DateTime // virtual column for the date pattern
            FROM @path
            USING Extractors.Csv();
    
    // Now apply the requested filter to reduce the files to the requested set
    @data = SELECT * FROM @data WHERE date == DateTime.Parse(@date);
    ...
    

    在这两种情况下,您都可以通过ADF参数化模型传递参数,然后您可以决定将代码包装到Bob建议的U-SQL存储过程或TVF中 .

相关问题