You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@spark.apache.org by "John Born (Jira)" <ji...@apache.org> on 2020/06/15 21:26:00 UTC

[jira] [Commented] (SPARK-14948) Exception when joining DataFrames derived form the same DataFrame

    [ https://issues.apache.org/jira/browse/SPARK-14948?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17136157#comment-17136157 ] 

John Born commented on SPARK-14948:
-----------------------------------

Alternative workaround (prettier code-wise, probably worse resource-wise). This creates a new instance of df based off of the rdd *after* creating the derived agg_df.
{code:java}
val rdd = sc.parallelize(List("a" -> 1, "b" -> 1, "a" -> 2))
val df = rdd.toDF(Seq("letter", "number"): _*)
val agg_df = df.groupBy("letter").agg(max("number")).withColumnRenamed("max(number)", "max")

// Error occurs:
agg_df.join(df, agg_df("letter") === df("letter") and agg_df("max") === df("number"), "inner").show()

// Re-create df instance:
val df = rdd.toDF(Seq("letter", "number"): _*)

// No error, exact same code that caused above error:
agg_df.join(df, agg_df("letter") === df("letter") and agg_df("max") === df("number"), "inner").show(){code}
 

> Exception when joining DataFrames derived form the same DataFrame
> -----------------------------------------------------------------
>
>                 Key: SPARK-14948
>                 URL: https://issues.apache.org/jira/browse/SPARK-14948
>             Project: Spark
>          Issue Type: Bug
>          Components: SQL
>    Affects Versions: 1.6.0
>            Reporter: Saurabh Santhosh
>            Priority: Major
>
> h2. Spark Analyser is throwing the following exception in a specific scenario :
> h2. Exception :
> org.apache.spark.sql.AnalysisException: resolved attribute(s) F1#3 missing from asd#5,F2#4,F1#6,F2#7 in operator !Project [asd#5,F1#3];
> 	at org.apache.spark.sql.catalyst.analysis.CheckAnalysis$class.failAnalysis(CheckAnalysis.scala:38)
> h2. Code :
> {code:title=SparkClient.java|borderStyle=solid}
>     StructField[] fields = new StructField[2];
>     fields[0] = new StructField("F1", DataTypes.StringType, true, Metadata.empty());
>     fields[1] = new StructField("F2", DataTypes.StringType, true, Metadata.empty());
>     JavaRDD<Row> rdd =
>         sparkClient.getJavaSparkContext().parallelize(Arrays.asList(RowFactory.create("a", "b")));
>     DataFrame df = sparkClient.getSparkHiveContext().createDataFrame(rdd, new StructType(fields));
>     sparkClient.getSparkHiveContext().registerDataFrameAsTable(df, "t1");
>     DataFrame aliasedDf = sparkClient.getSparkHiveContext().sql("select F1 as asd, F2 from t1");
>     sparkClient.getSparkHiveContext().registerDataFrameAsTable(aliasedDf, "t2");
>     sparkClient.getSparkHiveContext().registerDataFrameAsTable(df, "t3");
>     
>     DataFrame join = aliasedDf.join(df, aliasedDf.col("F2").equalTo(df.col("F2")), "inner");
>     DataFrame select = join.select(aliasedDf.col("asd"), df.col("F1"));
>     select.collect();
> {code}
> h2. Observations :
> * This issue is related to the Data Type of Fields of the initial Data Frame.(If the Data Type is not String, it will work.)
> * It works fine if the data frame is registered as a temporary table and an sql (select a.asd,b.F1 from t2 a inner join t3 b on a.F2=b.F2) is written.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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