2

When I perform the following actions.I met this problem in centos 7.0 and spark 2.1.0. I am a freshman in spark. How to fix it?

>>> from pyspark.sql import SQLContext
>>> ssc = SQLContext(sc)
>>> df = ssc.jsonFile('file:///root/work/person.json')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'SQLContext' object has no attribute 'jsonFile'
7
  • 1
    SQLContext.jsonFile() is deprecated, you should try SQLContext.read.json() Commented May 24, 2017 at 9:32
  • yeah.but i met another quesiton.... >>> df = sqlContext.read.json('file:///root/work/person.json') pyspark.sql.utils.AnalysisException: u'Path does not exist: file:/root/work/person.json;' Commented May 24, 2017 at 9:42
  • my path is wrong? [root@localhost word]# ls person.json person.txt [root@localhost word]# pwd /root/word Commented May 24, 2017 at 9:43
  • then check your path Commented May 24, 2017 at 9:46
  • haha.thank you very much! It's my fault. Commented May 24, 2017 at 9:56

2 Answers 2

2

Use SparkSession with the newer version of Spark and read using df = spark.read.json('path to json).

Sign up to request clarification or add additional context in comments.

Comments

0

jsonFile has been deprecated, please use sqlContext.read.json

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.