使用从文件名中提取日期
input_file_name()
那么功能呢
split
+
regexp_extract
(为了得到唯一的日期)最后
to_date
yyyy-MM-dd
.
-
过滤使用
date_sub(current_date(),21)
函数获取21天前的日期。
Example:
from pyspark.sql.functions import *
#reading directory
spark.read.parquet("wasbs://mydata@mine.blob.core.windows.net/first_folder/").\
withColumn("date",\
to_date(\
regexp_extract(\
split(input_file_name(),"-")[0]\
,"_(.*)",1),\
"yyyy_MM_dd")).\
filter(col("date") > date_sub(current_date(),21)).\
show(10,False)