spark-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sean Owen (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (SPARK-19895) Spark SQL could not output a correct result
Date Wed, 15 Mar 2017 08:28:41 GMT

     [ https://issues.apache.org/jira/browse/SPARK-19895?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Sean Owen resolved SPARK-19895.
-------------------------------
    Resolution: Not A Problem

> Spark SQL could not output a correct result
> -------------------------------------------
>
>                 Key: SPARK-19895
>                 URL: https://issues.apache.org/jira/browse/SPARK-19895
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 2.0.0, 2.1.0
>            Reporter: Bin Wu
>            Priority: Minor
>              Labels: beginner
>
> I'm rewriting pagerank algorithm with Spark SQL, following code can output a correct
result for large data set, but fails on the small data set as I provided. 
> from pyspark.sql.functions import *
> from pyspark.sql import SparkSession
> spark = SparkSession \
>         .builder \
>         .appName("Python Spark SQL basic example") \
>         .config("spark.some.config.option", "some-value") \
>         .getOrCreate()
> numOfIterations = 5                                                                 
           
> lines = spark.read.text("pagerank_data.txt")
> a = lines.select(split(lines[0],' '))
> links = a.select(a[0][0].alias('src'), a[0][1].alias('dst'))
> outdegrees = links.groupBy('src').count()
> ranks = outdegrees.select('src', lit(1).alias('rank'))
> for iteration in range(numOfIterations):
>     contribs = links.join(ranks, 'src').join(outdegrees, 'src').select('dst', (ranks['rank']/outdegrees['count']).alias('contrib'))
>     #ranks = contribs.groupBy('dst').sum('contrib').select(column('dst').alias('src'),
(column('sum(contrib)')*0.85+0.15).alias('rank'))
>     ranks = contribs.withColumnRenamed('dst','dst').groupBy('dst').sum('contrib').select(column('dst').alias('src'),
(column('sum(contrib)')*0.85+0.15).alias('rank'))
> ranks.orderBy(desc('rank')).show()
> pagerank_data.txt:
> 1 2
> 1 3
> 1 4
> 2 1
> 3 1
> 4 1
> expected result:
> +---+------------------+
> |src|              rank|
> +---+------------------+
> |  1|2.3266481249999997|
> |  3|0.5577839583333333|
> |  2|0.5577839583333333|
> |  4|0.5577839583333333|
> +---+------------------+
> Wrong result (without "withColumnRenamed")
> +---+-------------------+
> |src|               rank|
> +---+-------------------+
> |  1| 2.3266481249999997|
> |  4|0.31426131944444446|
> |  3|0.31426131944444446|
> |  2|0.31426131944444446|
> |  4|0.31426131944444446|
> |  4|0.31426131944444446|
> |  3|0.31426131944444446|
> |  2|0.31426131944444446|
> |  3|0.31426131944444446|
> |  2|0.31426131944444446|
> +---+-------------------+
> It cannot output correct rank for each node for this small graph only if I use the "withColumnRenamed".
However, on large data set, the line without withColumnRenamed works correctly.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@spark.apache.org
For additional commands, e-mail: issues-help@spark.apache.org


Mime
View raw message