aboutsummaryrefslogtreecommitdiff
path: root/examples/src/main/python/sql/datasource.py
diff options
context:
space:
mode:
authorCheng Lian <lian@databricks.com>2016-08-02 15:02:40 +0800
committerWenchen Fan <wenchen@databricks.com>2016-08-02 15:02:40 +0800
commit10e1c0e638774f5d746771b6dd251de2480f94eb (patch)
tree9aa40fef6c863aceb18243bc0ff8c7a824818cf7 /examples/src/main/python/sql/datasource.py
parent5184df06b347f86776c8ac87415b8002a5942a35 (diff)
downloadspark-10e1c0e638774f5d746771b6dd251de2480f94eb.tar.gz
spark-10e1c0e638774f5d746771b6dd251de2480f94eb.tar.bz2
spark-10e1c0e638774f5d746771b6dd251de2480f94eb.zip
[SPARK-16734][EXAMPLES][SQL] Revise examples of all language bindings
## What changes were proposed in this pull request? This PR makes various minor updates to examples of all language bindings to make sure they are consistent with each other. Some typos and missing parts (JDBC example in Scala/Java/Python) are also fixed. ## How was this patch tested? Manually tested. Author: Cheng Lian <lian@databricks.com> Closes #14368 from liancheng/revise-examples.
Diffstat (limited to 'examples/src/main/python/sql/datasource.py')
-rw-r--r--examples/src/main/python/sql/datasource.py32
1 files changed, 23 insertions, 9 deletions
diff --git a/examples/src/main/python/sql/datasource.py b/examples/src/main/python/sql/datasource.py
index 0bdc3d66ff..b36c901d2b 100644
--- a/examples/src/main/python/sql/datasource.py
+++ b/examples/src/main/python/sql/datasource.py
@@ -92,14 +92,14 @@ def parquet_schema_merging_example(spark):
# The final schema consists of all 3 columns in the Parquet files together
# with the partitioning column appeared in the partition directory paths.
# root
- # |-- double: long (nullable = true)
- # |-- single: long (nullable = true)
- # |-- triple: long (nullable = true)
- # |-- key: integer (nullable = true)
+ # |-- double: long (nullable = true)
+ # |-- single: long (nullable = true)
+ # |-- triple: long (nullable = true)
+ # |-- key: integer (nullable = true)
# $example off:schema_merging$
-def json_dataset_examplg(spark):
+def json_dataset_example(spark):
# $example on:json_dataset$
# spark is from the previous example.
sc = spark.sparkContext
@@ -112,8 +112,8 @@ def json_dataset_examplg(spark):
# The inferred schema can be visualized using the printSchema() method
peopleDF.printSchema()
# root
- # |-- age: long (nullable = true)
- # |-- name: string (nullable = true)
+ # |-- age: long (nullable = true)
+ # |-- name: string (nullable = true)
# Creates a temporary view using the DataFrame
peopleDF.createOrReplaceTempView("people")
@@ -140,15 +140,29 @@ def json_dataset_examplg(spark):
# +---------------+----+
# $example off:json_dataset$
+
+def jdbc_dataset_example(spark):
+ # $example on:jdbc_dataset$
+ jdbcDF = spark.read \
+ .format("jdbc") \
+ .option("url", "jdbc:postgresql:dbserver") \
+ .option("dbtable", "schema.tablename") \
+ .option("user", "username") \
+ .option("password", "password") \
+ .load()
+ # $example off:jdbc_dataset$
+
+
if __name__ == "__main__":
spark = SparkSession \
.builder \
- .appName("PythonSQL") \
+ .appName("Python Spark SQL data source example") \
.getOrCreate()
basic_datasource_example(spark)
parquet_example(spark)
parquet_schema_merging_example(spark)
- json_dataset_examplg(spark)
+ json_dataset_example(spark)
+ jdbc_dataset_example(spark)
spark.stop()