Python Spark从IBM Informix数据库读取数据;在日期值的字符串表示形式中没有指定足够的标记;

Python Spark从IBM Informix数据库读取数据;在日期值的字符串表示形式中没有指定足够的标记;,python,apache-spark,apache-spark-sql,spark-dataframe,informix,Python,Apache Spark,Apache Spark Sql,Spark Dataframe,Informix,我尝试使用以下语法连接到spark中的Informix数据库 jdbcDF = sqlContext.read.format("jdbc").option("url", "jdbc:informix-sqli://192.168.x.xx:xxxx/INFORMIXSERVER=online").option("dbtable", "informix.detail").option("user", "user").option("password", "xxxxxx").option('driv

我尝试使用以下语法连接到spark中的Informix数据库

jdbcDF = sqlContext.read.format("jdbc").option("url", "jdbc:informix-sqli://192.168.x.xx:xxxx/INFORMIXSERVER=online").option("dbtable", "informix.detail").option("user", "user").option("password", "xxxxxx").option('driver','com.informix.jdbc.IfxDriver').load()
连接成功,我可以看到数据帧的模式

jdbcDF.printSchema() 

   root
 |-- mobile_no: string (nullable = false)
 |-- subscriber_code: string (nullable = false)
 |-- connected_date: date (nullable = true)
 |-- disconnected_on: date (nullable = true)
 |-- att0: string (nullable = true)
但是当从数据帧中检索数据时

jdbcDF.show()
我得到以下错误

在字符串表示形式中没有指定足够的标记 日期值。“已断开连接”

我在网上发现了同样的问题, 它说我需要更改Informix数据库中的数据库列,但在我的情况下,这是不可能的


在从informix表加载之前,我是否可以将“disconnected_on”字段强制转换为数据帧中的字符串?

为了强制转换列,可以使用
cast()

您可以使用
drop()

下降(*cols)

结合这两个功能,您可以添加一个新列
disconnected\u on_str
,即
disconnected\u on
cast
成为
string
,并
删除
旧列
disconnected\u on

jdbcDF_cast = jdbcDF.withColumn("disconnected_on_str", jdbcDF["disconnected_on"].cast("string")).drop("disconnected_on")
Returns a new DataFrame that drops the specified column. This is a no-op if schema doesn’t contain the given column name(s).
Parameters: cols – a string name of the column to drop, or a Column to drop, or a list of string name of the columns to drop.

>>> df.drop('age').collect()
[Row(name=u'Alice'), Row(name=u'Bob')]

>>> df.drop(df.age).collect()
[Row(name=u'Alice'), Row(name=u'Bob')]
jdbcDF_cast = jdbcDF.withColumn("disconnected_on_str", jdbcDF["disconnected_on"].cast("string")).drop("disconnected_on")