过滤根据日期火花数据框 [英] Filtering a spark dataframe based on date
本文介绍了过滤根据日期火花数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个数据帧
date, string, string
我要选择一定时期之前的日期。我曾尝试以下,没有运气
I want to select dates before a certain period. I have tried the following with no luck
data.filter(data("date") < new java.sql.Date(format.parse("2015-03-14").getTime))
我得到一个错误,说明以下
I'm getting an error stating the following
org.apache.spark.sql.AnalysisException: resolved attribute(s) date#75 missing from date#72,uid#73,iid#74 in operator !Filter (date#75 < 16508);
据我可以猜到查询不正确。谁能告诉我查询应采用什么方式?
As far as I can guess the query is incorrect. Can anyone show me what way the query should be formatted?
我查了一下,在数据帧的所有enteries有价值观 - 他们这样做。
I checked that all enteries in the dataframe have values - they do.
推荐答案
这个API是不断变化的,但这里是一个解决方案星火1.5:
The API is changing constantly but here is a solution with Spark 1.5 :
有关低于:
data.filter(data("date")).lt("2015-03-14"))
有关大于
data.filter(data("date")).lt("2015-03-14"))
是您的数据框日期列是一个字符串类型,你可以用它转换 TO_DATE
功能:
data.filter(to_date(data("date")).gt("2015-03-14"))
我希望这有助于!
I hope this helps!
这篇关于过滤根据日期火花数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文