Github user andrewor14 commented on a diff in the pull request:
https://github.com/apache/spark/pull/12860#discussion_r61928851
--- Diff: examples/src/main/python/sql.py ---
@@ -57,24 +52,22 @@
else:
path = sys.argv[1]
# Create a DataFrame from the file(s) pointed to by path
- people = sqlContext.jsonFile(path)
+ people = spark.read.json(path)
# root
# |-- person_name: string (nullable = false)
# |-- person_age: integer (nullable = false)
# The inferred schema can be visualized using the printSchema() method.
people.printSchema()
# root
- # |-- age: IntegerType
- # |-- name: StringType
+ # |-- age: long (nullable = true)
+ # |-- name: string (nullable = true)
# Register this DataFrame as a table.
- people.registerAsTable("people")
+ people.registerTempTable("people")
# SQL statements can be run by using the sql methods provided by
sqlContext
- teenagers = sqlContext.sql("SELECT name FROM people WHERE age >= 13
AND age <= 19")
+ teenagers = spark.sql("SELECT name FROM people WHERE age >= 13 AND age
<= 19")
for each in teenagers.collect():
print(each[0])
-
- sc.stop()
--- End diff --
we still need to do this. Once we merge #12873 we'll have a `spark.stop()`
method available in scala.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]