itholic commented on a change in pull request #32053:
URL: https://github.com/apache/spark/pull/32053#discussion_r608390983



##########
File path: 
examples/src/main/scala/org/apache/spark/examples/sql/SQLDataSourceExample.scala
##########
@@ -309,6 +310,53 @@ object SQLDataSourceExample {
     // $example off:csv_dataset$
   }
 
+  private def runTextDatasetExample(spark: SparkSession): Unit = {
+    // $example on:text_dataset$
+    // A text dataset is pointed to by path.
+    // The path can be either a single text file or a directory of text files
+    val path = "examples/src/main/resources/people.txt"
+
+    val df1 = spark.read.text(path)
+    df1.show()
+    // +-----------+
+    // |      value|
+    // +-----------+
+    // |Michael, 29|
+    // |   Andy, 30|
+    // | Justin, 19|
+    // +-----------+
+
+    // You can use 'lineSep' option to define the line separator.
+    // The line separator handles all `\r`, `\r\n` and `\n` by default.
+    val df2 = spark.read.option("lineSep", ",").text(path)
+    df2.show()
+    // +-----------+
+    // |      value|
+    // +-----------+
+    // |    Michael|
+    // |   29\nAndy|
+    // | 30\nJustin|
+    // |       19\n|
+    // +-----------+
+
+    // You can also use 'wholetext' option to read each input file as a single 
row.
+    val df3 = spark.read.option("wholetext", "true").text(path)

Review comment:
       Sure, let me change this to `option("wholetext", true)` to show more 
example cases.
   
   Thanks!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to