简体   繁体   English

无法使用 PySpark 与 Databricks 上的 apache spark function to_timestamp() 连接并添加一列

[英]Unable to concatenate with apache spark function to_timestamp() on Databricks using PySpark and add a column

I'm trying to using concatenate with the to_timestamp() on a Apache Spark table and add a columns using the.withColumn function but it won't work.我正在尝试在 Apache Spark 表上使用与 to_timestamp() 的连接,并使用 the.withColumn function 添加列,但它不起作用。

The code is as follows:代码如下:

DIM_WORK_ORDER.withColumn("LAST_MODIFICATION_DT", to_timestamp(concat(col('LAST_MOD_DATE'), lit(' '), col('LAST_MOD_TIME')), 'yyyyMMdd HHmmss'))

The result I would expect to see is something like我希望看到的结果是这样的

LAST_MODIFICATION_DT | LAST_MODIFICATION_DT | WORK_ORDER工作指示

However, I'm getting the following result:但是,我得到以下结果:

在此处输入图像描述

Some data to work with:要使用的一些数据:

WORK_ORDER LAST_MOD_TIME 10000008 null 11358186 142254 10000007 193402 10000009 null WORK_ORDER LAST_MOD_TIME 10000008 null 11358186 142254 10000007 193402 10000009 null

Any thoughts?有什么想法吗?

As far as I know in Spark, dataframes are immutable.据我所知,在 Spark 中,数据帧是不可变的。 Hence, once you have created a dataframe, it can't change.因此,一旦您创建了 dataframe,它就无法更改。

%python
import pyspark
from pyspark.sql.functions import *
df = spark.read.option("header","true").csv("<input file path>")
df1 = df.withColumn("LAST_MODIFICATION_DT", to_timestamp(concat(col('LAST_MOD_DATE'), lit(' '), col('LAST_MOD_TIME')), 'yyyyMMdd HHmmss'))
display(df1)

I am getting below output as expected.正如预期的那样,我低于 output。 If this is not what you expect, please provide more info如果这不是您所期望的,请提供更多信息

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Apache Spark function to_timestamp() 无法在 Databricks 上使用 PySpark - Apache Spark function to_timestamp() not working with PySpark on Databricks 如何使用 Databricks 在 Apache Spark 上编译 PySpark 中的 While 循环语句 - How to Compile a While Loop statement in PySpark on Apache Spark with Databricks 试图写一个 pyspark function 连接到 SQL 服务器与 Databricks 在 Apache Spart - Attempting to write a pyspark function to connect to SQL Server with Databricks on Apache Spart 使用 Databricks(和 Apache Spark)从 AWS Redshift 读取 - Read from AWS Redshift using Databricks (and Apache Spark) 使用 Apache Spark 在 Databricks 中使用 SQL 查询进行 CASTING 问题 - CASTING issue with SQL query in Databricks with Apache Spark Redshift to_timestamp 与时区偏移量 - Redshift to_timestamp with timezone offset 使用 Databricks 上的 Apache Spark 将文件写入 delta lake 会产生与读取 Data Frame 不同的结果 - Writing out file to delta lake produces different results from Data Frame read using Apache Spark on Databricks 使用 Databricks 将数据写入 Bigquery 时出错 Pyspark - Error writing data to Bigquery using Databricks Pyspark 无法使用数据块连接从 Windows 连接到数据块集群 - Unable to connect to databricks cluster from Windows using databricks-connect 无法使用 Apache Spark 在 AWS Glue 中读取 json 个文件 - Unable to read json files in AWS Glue using Apache Spark
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM