HyukjinKwon opened a new pull request #27614: [SPARK-30861][PYTHON][SQL] 
Deprecate constructor of SQLContext and getOrCreate in SQLContext at PySpark
URL: https://github.com/apache/spark/pull/27614
 
 
   ### What changes were proposed in this pull request?
   
   This PR proposes to deprecate the APIs at `SQLContext` removed in 
SPARK-25908. We should remove equivalent APIs; however, seems we missed to 
deprecate.
   
   While I am here, I fix one more issue. After SPARK-25908, 
`sc._jvm.SQLContext.getOrCreate` dose not exist anymore. So,
   
   ```python
   from pyspark.sql import SQLContext
   from pyspark import SparkContext
   sc = SparkContext.getOrCreate()
   SQLContext.getOrCreate(sc).range(10).show()
   ```
   
   throws an exception as below:
   
   ```
   Traceback (most recent call last):
     File "<stdin>", line 1, in <module>
     File "/.../spark/python/pyspark/sql/context.py", line 110, in getOrCreate
       jsqlContext = sc._jvm.SQLContext.getOrCreate(sc._jsc.sc())
     File "/.../spark/python/lib/py4j-0.10.8.1-src.zip/py4j/java_gateway.py", 
line 1516, in __getattr__
   py4j.protocol.Py4JError: org.apache.spark.sql.SQLContext.getOrCreate does 
not exist in the JVM
   ```
   
   After this PR:
   
   ```
   /.../spark/python/pyspark/sql/context.py:113: DeprecationWarning: Deprecated 
in 3.0.0. Use SparkSession.builder.getOrCreate() instead.
     DeprecationWarning)
   +---+
   | id|
   +---+
   |  0|
   |  1|
   |  2|
   |  3|
   |  4|
   |  5|
   |  6|
   |  7|
   |  8|
   |  9|
   +---+
   ```
   
   In case of the constructor of `SQLContext`, after this PR:
   
   
   ```python
   from pyspark.sql import SQLContext
   sc = SparkContext.getOrCreate()
   SQLContext(sc)
   ```
   
   ```
   /.../spark/python/pyspark/sql/context.py:77: DeprecationWarning: Deprecated 
in 3.0.0. Use SparkSession.builder.getOrCreate() instead.
     DeprecationWarning)
   ```
   
   ### Why are the changes needed?
   
   To promote to use SparkSession, and keep the API party consistent with Scala 
side.
   
   ### Does this PR introduce any user-facing change?
   
   Yes, it will show deprecation warning to users.
   
   ### How was this patch tested?
   
   Manually tested as described above. Unittests were also added.

----------------------------------------------------------------
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]


With regards,
Apache Git Services

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

Reply via email to