环境:Spark 1.6;阶
简单的问题,但我没有得到准确的答案。我有一个数据帧DF
val DF2= DF.select ($"cr_Date".cast("timestamp").minusMinutes(5))
我需要从cr_date减去5分钟。我试过了
class ResPartner(models.Model):
_inherit = 'res.partner'
vat = fields...(required=True) //just specify the required attributes
# but here i don't think it will work because the framework will not be able
# to add this constrains because it has some duplicated value all ready like null
# in order to make this work you need to run a query to modify old values then restart the server than odoo should be able to add this constraint check log message to see if the constraint is added
_sql_constraints = [
('vat_company_uniq', 'unique(company_id, vat)', '¡ El RIF debe ser único por compañia !'),
]
//无效
有什么建议吗? 感谢
答案 0 :(得分:3)
df.select(from_unixtime(unix_timestamp(col("cr_dt")).minus(5 * 60), "YYYY-MM-dd HH:mm:ss"))
spark中没有这样的minusMinutes
方法。
上面的代码应该返回预期的结果。
答案 1 :(得分:0)
万一有人遇到同一问题,我发现使用上述方法可以保留年份。例如,在应用时,我有一个时间戳为“ 2015-01-01 00:00:00”的数据框:
df.select(from_unixtime(unix_timestamp(col("cr_dt")).minus(5 * 60), "YYYY-MM-dd HH:mm:ss"))
我得到的结果是“ 2015-12-31 23:55:00”,但是我的预期结果是“ 2014-12-31 23:55:00”。 似乎这是由于具有“ YYYY”而不是“ yyyy”。进行更改:
df.select(from_unixtime(unix_timestamp(col("cr_dt")).minus(5 * 60), "yyyy-MM-dd HH:mm:ss"))
给出我想要的结果。