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我找不到任何示例。你能否詳細說明一下?謝謝 –