diff options
author | Cheng Lian <lian@databricks.com> | 2016-06-29 22:50:53 -0700 |
---|---|---|
committer | Xiangrui Meng <meng@databricks.com> | 2016-06-29 22:50:53 -0700 |
commit | bde1d6a61593aeb62370f526542cead94919b0c0 (patch) | |
tree | 8630ee0675f1be8b45b8f4d72a9ced10f6d2eb80 /examples | |
parent | d3af6731fa270842818ed91d6b4d14708ddae2db (diff) | |
download | spark-bde1d6a61593aeb62370f526542cead94919b0c0.tar.gz spark-bde1d6a61593aeb62370f526542cead94919b0c0.tar.bz2 spark-bde1d6a61593aeb62370f526542cead94919b0c0.zip |
[SPARK-16294][SQL] Labelling support for the include_example Jekyll plugin
## What changes were proposed in this pull request?
This PR adds labelling support for the `include_example` Jekyll plugin, so that we may split a single source file into multiple line blocks with different labels, and include them in multiple code snippets in the generated HTML page.
## How was this patch tested?
Manually tested.
<img width="923" alt="screenshot at jun 29 19-53-21" src="https://cloud.githubusercontent.com/assets/230655/16451099/66a76db2-3e33-11e6-84fb-63104c2f0688.png">
Author: Cheng Lian <lian@databricks.com>
Closes #13972 from liancheng/include-example-with-labels.
Diffstat (limited to 'examples')
3 files changed, 18 insertions, 2 deletions
diff --git a/examples/src/main/java/org/apache/spark/examples/sql/JavaSparkSQL.java b/examples/src/main/java/org/apache/spark/examples/sql/JavaSparkSQL.java index e512979ac7..7fc6c007b6 100644 --- a/examples/src/main/java/org/apache/spark/examples/sql/JavaSparkSQL.java +++ b/examples/src/main/java/org/apache/spark/examples/sql/JavaSparkSQL.java @@ -26,7 +26,9 @@ import org.apache.spark.api.java.function.Function; import org.apache.spark.sql.Dataset; import org.apache.spark.sql.Row; +// $example on:init_session$ import org.apache.spark.sql.SparkSession; +// $example off:init_session$ public class JavaSparkSQL { public static class Person implements Serializable { @@ -51,10 +53,13 @@ public class JavaSparkSQL { } public static void main(String[] args) throws Exception { + // $example on:init_session$ SparkSession spark = SparkSession .builder() .appName("JavaSparkSQL") + .config("spark.some.config.option", "some-value") .getOrCreate(); + // $example off:init_session$ System.out.println("=== Data source: RDD ==="); // Load a text file and convert each line to a Java Bean. diff --git a/examples/src/main/python/sql.py b/examples/src/main/python/sql.py index ac7246938d..ea11d2c4c7 100644 --- a/examples/src/main/python/sql.py +++ b/examples/src/main/python/sql.py @@ -20,15 +20,20 @@ from __future__ import print_function import os import sys +# $example on:init_session$ from pyspark.sql import SparkSession +# $example off:init_session$ from pyspark.sql.types import Row, StructField, StructType, StringType, IntegerType if __name__ == "__main__": + # $example on:init_session$ spark = SparkSession\ .builder\ .appName("PythonSQL")\ + .config("spark.some.config.option", "some-value")\ .getOrCreate() + # $example off:init_session$ # A list of Rows. Infer schema from the first row, create a DataFrame and print the schema rows = [Row(name="John", age=19), Row(name="Smith", age=23), Row(name="Sarah", age=18)] diff --git a/examples/src/main/scala/org/apache/spark/examples/sql/RDDRelation.scala b/examples/src/main/scala/org/apache/spark/examples/sql/RDDRelation.scala index 1b019fbb51..deaa9f252b 100644 --- a/examples/src/main/scala/org/apache/spark/examples/sql/RDDRelation.scala +++ b/examples/src/main/scala/org/apache/spark/examples/sql/RDDRelation.scala @@ -18,7 +18,10 @@ // scalastyle:off println package org.apache.spark.examples.sql -import org.apache.spark.sql.{SaveMode, SparkSession} +import org.apache.spark.sql.SaveMode +// $example on:init_session$ +import org.apache.spark.sql.SparkSession +// $example off:init_session$ // One method for defining the schema of an RDD is to make a case class with the desired column // names and types. @@ -26,13 +29,16 @@ case class Record(key: Int, value: String) object RDDRelation { def main(args: Array[String]) { + // $example on:init_session$ val spark = SparkSession .builder - .appName("RDDRelation") + .appName("Spark Examples") + .config("spark.some.config.option", "some-value") .getOrCreate() // Importing the SparkSession gives access to all the SQL functions and implicit conversions. import spark.implicits._ + // $example off:init_session$ val df = spark.createDataFrame((1 to 100).map(i => Record(i, s"val_$i"))) // Any RDD containing case classes can be used to create a temporary view. The schema of the |