Skip to content

Commit

Permalink
[SPARK-23122][PYSPARK][FOLLOWUP] Replace registerTempTable by createO…
Browse files Browse the repository at this point in the history
…rReplaceTempView

## What changes were proposed in this pull request?
Replace `registerTempTable` by `createOrReplaceTempView`.

## How was this patch tested?
N/A

Author: gatorsmile <[email protected]>

Closes #20523 from gatorsmile/updateExamples.
  • Loading branch information
gatorsmile authored and HyukjinKwon committed Feb 7, 2018
1 parent c36fecc commit 9775df6
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/pyspark/sql/udf.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def registerJavaUDAF(self, name, javaClassName):
>>> spark.udf.registerJavaUDAF("javaUDAF", "test.org.apache.spark.sql.MyDoubleAvg")
>>> df = spark.createDataFrame([(1, "a"),(2, "b"), (3, "a")],["id", "name"])
>>> df.registerTempTable("df")
>>> df.createOrReplaceTempView("df")
>>> spark.sql("SELECT name, javaUDAF(id) as avg from df group by name").collect()
[Row(name=u'b', avg=102.0), Row(name=u'a', avg=102.0)]
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void tearDown() {
@SuppressWarnings("unchecked")
@Test
public void udf1Test() {
spark.range(1, 10).toDF("value").registerTempTable("df");
spark.range(1, 10).toDF("value").createOrReplaceTempView("df");
spark.udf().registerJavaUDAF("myDoubleAvg", MyDoubleAvg.class.getName());
Row result = spark.sql("SELECT myDoubleAvg(value) as my_avg from df").head();
Assert.assertEquals(105.0, result.getDouble(0), 1.0e-6);
Expand Down

0 comments on commit 9775df6

Please sign in to comment.