1
我的电脑上有一个本地PSQL数据库。一些列将数据包含在数组中。 (下面的例子)从Postgres DB读取一个数组类型的火花数据帧
+--------------------+
| _authors|
+--------------------+
|[u'Miller, Roger ...|
|[u'Noyes, H.Pierre']|
|[u'Berman, S.M.',...|
+--------------------+
only showing top 3 rows
root
|-- _authors: string (nullable = true)
我需要读取它们作为数组/包装数组。我如何实现这一目标?
val sqlContext: SQLContext = new SQLContext(sc)
val df_records = sqlContext.read.format("jdbc").option("url", "jdbc:postgresql://localhost:5432/dbname")
.option("driver", "org.postgresql.Driver")
.option("dbtable", "public.records")
.option("user", "name")
.option("password", "pwd").load().select("_authors")
df_records.printSchema()
我需要在我的管道的后期爆炸这个数组/扁平化。
感谢,
您是否试过向读者添加'.schema(s:StructType)'?您必须将完整模式作为StructType对象来传递 –
@DanieldePaula我找不到任何示例。你能否详细说明一下?谢谢 –