【问题标题】:Pyspark: Getting current_timestamp in dynamic hive queryPyspark:在动态配置单元查询中获取 current_timestamp
【发布时间】:2016-06-29 00:19:14
【问题描述】:

我正在使用 python 程序准备 Spark,该程序根据连接从 2 个表中插入数据。目标表的最后一列有一个时间戳字段,其值为创建时间戳。

我尝试了 current_timestamp 和 from_unixtime(unix_timestamp())。这两个功能似乎都不起作用。我现在试过了()。

例如,HiveContext(sc).sql("SELECT " + from_unixtime(unix_timestamp()) + " ") 此语句在 pyspark 中出现“NameError: name 'from_unixtime' is not defined”错误我已经导入了 pyspark.sql.function

有没有办法将时间戳值插入目标表?我的查询包含从我在 HiveContext 中运行的 2 个表中选择的插入。

提前致谢!!!

【问题讨论】:

  • 我试过下面的代码,我得到: TypeError: 'Column' object is not callable import pyspark.sql.functions as func HiveContext(sc).sql("SELECT " + func.from_unixtime( func.unix_timestamp()) + "")。有人可以说这个查询有什么问题。谢谢!!!

标签: pyspark hivecontext


【解决方案1】:

在下面的双引号中使用并且有效:

HiveContext(sc).sql("SELECT from_unixtime(unix_timestamp())")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-23
    • 2016-05-30
    • 2020-09-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多