To extract the DateTime from the name of file(ex. “vga_20171201.txt”) in U-SQL

牧云@^-^@ 提交于 2019-12-24 07:58:57

问题


I want to extract the filename string as a DateTime column. The code for it as follows: @data = EXTRACT ... filename_date DateTime FROM "/input/vga_{filename_date}.txt" USING Extractors.Tsv(skipFirstNRows:1);

filename = vga_20171201.txt

whenever i have used datatype as string or int, it's work for me.


回答1:


You have to specify .net date format strings along with the virtual column name to get that behaviour, like this:

@data =
    EXTRACT someData string,
            filename_date DateTime
    FROM "/input/vga_{filename_date:yyyy}{filename_date:MM}{filename_date:dd}.txt"
    USING Extractors.Tsv(skipFirstNRows : 1);



回答2:


I have a series of files that are named like 1601.gz to represent January of 2016. {date:yyMM}.gz or {date:yy}{date:MM}.gz don't seem to



来源:https://stackoverflow.com/questions/50345848/to-extract-the-datetime-from-the-name-of-fileex-vga-20171201-txt-in-u-sql

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