tra*_*cer 168 dataframe output-formatting apache-spark spark-csv
我使用spark-csv将数据加载到DataFrame中.我想做一个简单的查询并显示内容:
val df = sqlContext.read.format("com.databricks.spark.csv").option("header", "true").load("my.csv")
df.registerTempTable("tasks")
results = sqlContext.sql("select col from tasks");
results.show()
Run Code Online (Sandbox Code Playgroud)
col似乎被截断了:
scala> results.show();
+--------------------+
| col|
+--------------------+
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:15:...|
|2015-11-06 07:15:...|
|2015-11-16 07:15:...|
|2015-11-16 07:21:...|
|2015-11-16 07:21:...|
|2015-11-16 07:21:...|
+--------------------+
Run Code Online (Sandbox Code Playgroud)
如何显示列的完整内容?
Tom*_*101 317
results.show(20, false)
不会截断.检查来源
Nar*_*mar 31
如果你放results.show(false)
,结果不会被截断
cod*_*ure 14
其他解决方案都很好.如果这些是你的目标:
这两行很有用......
df.persist
df.show(df.count, false) // in Scala or 'False' in Python
Run Code Online (Sandbox Code Playgroud)
通过持久化,在执行程序中使用persist
或cache
维护临时基础数据框结构时,2执行程序操作(计数和显示)更快,更高效.查看有关persist和cache的更多信息.
小智 11
在Pyspark中我们可以使用
df.show(truncate=False) 这将显示列的完整内容而不截断。
df.show(5,truncate=False) 这将显示前五行的完整内容。
The following answer applies to a Spark Streaming application.
By setting the "truncate" option to false, you can tell the output sink to display the full column.
val query = out.writeStream
.outputMode(OutputMode.Update())
.format("console")
.option("truncate", false)
.trigger(Trigger.ProcessingTime("5 seconds"))
.start()
Run Code Online (Sandbox Code Playgroud)
小智 6
在 Spark Pythonic 方式中,请记住:
show(truncate=False)
方法。writeStream.format("console").option("truncate", False).start()
带有选项的方法。希望它可以帮助别人。
归档时间: |
|
查看次数: |
146187 次 |
最近记录: |