首页 > 解决方案 > Pyspark 错误:“未定义函数:'from_timestamp'

问题描述

我正在尝试使用 spark.sql 从配置单元视图中获取 pyspark 中的一些数据,但每次它都会抛出以下错误:

pyspark.sql.utils.AnalysisException: u"Undefined function: 'from_timestamp'. This function is neither a registered temporary function nor a permanent function registered in the database 'default'.;

我在 SparkSession.builder 上的设置如下:

spark = SparkSession.builder.appName("home_office") \
    .config("hive.exec.dynamic.partition", "true") \
    .config("hive.exec.dynamic.partition.mode", "nonstrict") \
    .config("hive.exec.compress.output=false", "false") \
    .config("spark.unsafe.sorter.spill.read.ahead.enabled", "false") \
    .config("spark.debug.maxToStringFields", 1000)\
    .enableHiveSupport() \
    .getOrCreate()

标签: apache-sparkpysparkhiveapache-spark-sql

解决方案


Spark SQL中没有这样的功能from_timestamp。如果您指的是 Impala 中的函数,我相信 Spark SQL 中的等价物是date_format.

示例用法:

select date_format(current_timestamp(), 'dd/MM/yyyy hh:mm:ss a');

07/01/2021 08:37:11 AM

推荐阅读