You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "zhengruifeng (via GitHub)" <gi...@apache.org> on 2024/04/03 09:41:38 UTC
[PR] [WIP][SQL][CONNECT] Fix a self-join case with depth [spark]
zhengruifeng opened a new pull request, #45846:
URL: https://github.com/apache/spark/pull/45846
<!--
Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, please read our contributor guidelines: https://spark.apache.org/contributing.html
2. Ensure you have added or run the appropriate tests for your PR: https://spark.apache.org/developer-tools.html
3. If the PR is unfinished, add '[WIP]' in your PR title, e.g., '[WIP][SPARK-XXXX] Your PR title ...'.
4. Be sure to keep the PR description updated to reflect all changes.
5. Please write your PR title to summarize what this PR proposes.
6. If possible, provide a concise example to reproduce the issue for a faster review.
7. If you want to add a new configuration, please read the guideline first for naming configurations in
'core/src/main/scala/org/apache/spark/internal/config/ConfigEntry.scala'.
8. If you want to add or modify an error type or message, please read the guideline first in
'common/utils/src/main/resources/error/README.md'.
-->
### What changes were proposed in this pull request?
<!--
Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue.
If possible, please consider writing useful notes for better and faster reviews in your PR. See the examples below.
1. If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
2. If you fix some SQL features, you can provide some references of other DBMSes.
3. If there is design documentation, please add the link.
4. If there is a discussion in the mailing list, please add the link.
-->
### Why are the changes needed?
<!--
Please clarify why the changes are needed. For instance,
1. If you propose a new API, clarify the use case for a new API.
2. If you fix a bug, you can clarify why it is a bug.
-->
### Does this PR introduce _any_ user-facing change?
<!--
Note that it means *any* user-facing change including all aspects such as the documentation fix.
If yes, please clarify the previous behavior and the change this PR proposes - provide the console output, description and/or an example to show the behavior difference if possible.
If possible, please also clarify if this is a user-facing change compared to the released Spark versions or within the unreleased branches such as master.
If no, write 'No'.
-->
### How was this patch tested?
<!--
If tests were added, say they were added here. Please make sure to add some test cases that check the changes thoroughly including negative and positive cases if possible.
If it was tested in a way different from regular unit tests, please clarify how you tested step by step, ideally copy and paste-able, so that other reviewers can test and check, and descendants can verify in the future.
If tests were not added, please describe why they were not added and/or why it was difficult to add.
If benchmark tests were added, please run the benchmarks in GitHub Actions for the consistent environment, and the instructions could accord to: https://spark.apache.org/developer-tools.html#github-workflow-benchmarks.
-->
### Was this patch authored or co-authored using generative AI tooling?
<!--
If generative AI tooling has been used in the process of authoring this patch, please include the
phrase: 'Generated-by: ' followed by the name of the tool and its version.
If no, write 'No'.
Please refer to the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
-->
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1549635330
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala:
##########
@@ -527,13 +527,15 @@ trait ColumnResolutionHelper extends Logging with DataTypeErrorsBase {
logDebug(s"Extract plan_id $planId from $u")
val isMetadataAccess = u.getTagValue(LogicalPlan.IS_METADATA_COL).nonEmpty
- val (resolved, matched) = resolveDataFrameColumnByPlanId(u, planId, isMetadataAccess, q)
- if (!matched) {
- // Can not find the target plan node with plan id, e.g.
- // df1 = spark.createDataFrame([Row(a = 1, b = 2, c = 3)]])
- // df2 = spark.createDataFrame([Row(a = 1, b = 2)]])
- // df1.select(df2.a) <- illegal reference df2.a
- throw QueryCompilationErrors.cannotResolveDataFrameColumn(u)
+ val resolved = resolveDataFrameColumnByPlanId(u, planId, isMetadataAccess, q, 0).map(_._1)
+ if (resolved.isEmpty) {
+ if (!q.exists(_.exists(_.getTagValue(LogicalPlan.PLAN_ID_TAG).contains(planId)))) {
Review Comment:
when this condition can be false if `resolved.isEmpty` is true?
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [WIP][SQL][CONNECT] Fix a self-join case with depth [spark]
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1549547958
##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/ClientE2ETestSuite.scala:
##########
@@ -938,11 +938,14 @@ class ClientE2ETestSuite extends RemoteSparkSession with SQLHelper with PrivateM
}
assert(e3.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
- val e4 = intercept[AnalysisException] {
- // df1("i") is ambiguous as df1 appears in both join sides (df1_filter contains df1).
- df1.join(df1_filter, df1("i") === 1).collect()
- }
- assert(e4.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
+ // val e4 = intercept[AnalysisException] {
+ // // df1("i") is ambiguous as df1 appears in both join sides (df1_filter contains df1).
+ // df1.join(df1_filter, df1("i") === 1).collect()
+ // }
+ // assert(e4.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
+ //
+ // "[AMBIGUOUS_COLUMN_OR_FIELD] Column or field `i` is ambiguous and has 2 matches.
Review Comment:
ok, the reason it that spark connect scala client can not `collect` duplicated column names:
```
+---+---+---+---+
| i| j| i| j|
+---+---+---+---+
| 1| a| 1| a|
+---+---+---+---+
```
```
[info] - SPARK-45509: ambiguous column reference *** FAILED *** (2 seconds, 869 milliseconds)
[info] org.apache.spark.sql.AnalysisException: [AMBIGUOUS_COLUMN_OR_FIELD] Column or field `i` is ambiguous and has 2 matches. SQLSTATE: 42702
[info] at org.apache.spark.sql.errors.CompilationErrors.ambiguousColumnOrFieldError(CompilationErrors.scala:28)
[info] at org.apache.spark.sql.errors.CompilationErrors.ambiguousColumnOrFieldError$(CompilationErrors.scala:23)
[info] at org.apache.spark.sql.errors.CompilationErrors$.ambiguousColumnOrFieldError(CompilationErrors.scala:54)
[info] at org.apache.spark.sql.connect.client.arrow.ArrowDeserializers$.$anonfun$createFieldLookup$1(ArrowDeserializer.scala:460)
[info] at org.apache.spark.sql.connect.client.arrow.ArrowDeserializers$.$anonfun$createFieldLookup$1$adapted(ArrowDeserializer.scala:454)
[info] at scala.collection.immutable.List.foreach(List.scala:334)
[info] at org.apache.spark.sql.connect.client.arrow.ArrowDeserializers$.createFieldLookup(ArrowDeserializer.scala:454)
[info] at org.apache.spark.sql.connect.client.arrow.ArrowDeserializers$.deserializerFor(ArrowDeserializer.scala:328)
[info] at org.apache.spark.sql.connect.client.arrow.ArrowDeserializers$.deserializerFor(ArrowDeserializer.scala:86)
[info] at org.apache.spark.sql.connect.client.arrow.ArrowDeserializingIterator.<init>(ArrowDeserializer.scala:542)
```
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on PR #45846:
URL: https://github.com/apache/spark/pull/45846#issuecomment-2041822893
thanks, merging to master!
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1554792991
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala:
##########
@@ -527,13 +527,15 @@ trait ColumnResolutionHelper extends Logging with DataTypeErrorsBase {
logDebug(s"Extract plan_id $planId from $u")
val isMetadataAccess = u.getTagValue(LogicalPlan.IS_METADATA_COL).nonEmpty
- val (resolved, matched) = resolveDataFrameColumnByPlanId(u, planId, isMetadataAccess, q)
- if (!matched) {
- // Can not find the target plan node with plan id, e.g.
- // df1 = spark.createDataFrame([Row(a = 1, b = 2, c = 3)]])
- // df2 = spark.createDataFrame([Row(a = 1, b = 2)]])
- // df1.select(df2.a) <- illegal reference df2.a
- throw QueryCompilationErrors.cannotResolveDataFrameColumn(u)
+ val resolved = resolveDataFrameColumnByPlanId(u, planId, isMetadataAccess, q, 0).map(_._1)
+ if (resolved.isEmpty) {
+ if (!q.exists(_.exists(_.getTagValue(LogicalPlan.PLAN_ID_TAG).contains(planId)))) {
Review Comment:
ok, let me restore `matched`
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1550678886
##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/ClientE2ETestSuite.scala:
##########
@@ -938,11 +938,11 @@ class ClientE2ETestSuite extends RemoteSparkSession with SQLHelper with PrivateM
}
assert(e3.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
- val e4 = intercept[AnalysisException] {
- // df1("i") is ambiguous as df1 appears in both join sides (df1_filter contains df1).
- df1.join(df1_filter, df1("i") === 1).collect()
- }
- assert(e4.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
+ // df1.join(df1_filter, df1("i") === 1) fails in classic spark due to:
+ // org.apache.spark.sql.AnalysisException: Column i#24 are ambiguous
+ assert(
Review Comment:
we can not use it here, since there is another Scala Client issue
https://github.com/apache/spark/pull/45846#discussion_r1549547958
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1554762717
##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/ClientE2ETestSuite.scala:
##########
@@ -938,11 +938,11 @@ class ClientE2ETestSuite extends RemoteSparkSession with SQLHelper with PrivateM
}
assert(e3.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
- val e4 = intercept[AnalysisException] {
- // df1("i") is ambiguous as df1 appears in both join sides (df1_filter contains df1).
- df1.join(df1_filter, df1("i") === 1).collect()
- }
- assert(e4.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
+ // df1.join(df1_filter, df1("i") === 1) fails in classic spark due to:
+ // org.apache.spark.sql.AnalysisException: Column i#24 are ambiguous
+ assert(
Review Comment:
done
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1550693431
##########
python/pyspark/sql/tests/connect/test_connect_basic.py:
##########
@@ -1155,6 +1155,15 @@ def test_crossjoin(self):
set(spark_df.select("id").crossJoin(other=spark_df.select("name")).toPandas()),
)
+ def test_self_join(self):
+ # SPARK-47713: this query fails in classic spark
+ df1 = self.connect.createDataFrame([(1, "a")], schema=["i", "j"])
+ df1_filter = df1.filter(df1.i > 0)
+ df2 = df1.join(df1_filter, df1.i == 1)
+ self.assertEqual(df2.count(), 1)
+ self.assertEqual(df2.columns, ["i", "j", "i", "j"])
+ self.assertEqual(list(df2.first()), [1, "a", 1, "a"])
Review Comment:
`Row` constructor doesn't accept duplicated names, so test in this way
<img width="271" alt="image" src="https://github.com/apache/spark/assets/7322292/80528560-dd47-4413-b80a-17a83b310b53">
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1549621444
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala:
##########
@@ -542,23 +544,24 @@ trait ColumnResolutionHelper extends Logging with DataTypeErrorsBase {
u: UnresolvedAttribute,
id: Long,
isMetadataAccess: Boolean,
- q: Seq[LogicalPlan]): (Option[NamedExpression], Boolean) = {
- q.iterator.map(resolveDataFrameColumnRecursively(u, id, isMetadataAccess, _))
- .foldLeft((Option.empty[NamedExpression], false)) {
- case ((r1, m1), (r2, m2)) =>
- if (r1.nonEmpty && r2.nonEmpty) {
- throw QueryCompilationErrors.ambiguousColumnReferences(u)
- }
- (if (r1.nonEmpty) r1 else r2, m1 | m2)
+ q: Seq[LogicalPlan],
+ d: Int): Option[(NamedExpression, Int)] = {
Review Comment:
```suggestion
currentDepth: Int): Option[(NamedExpression, Int)] = {
```
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1549619803
##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/ClientE2ETestSuite.scala:
##########
@@ -938,11 +938,11 @@ class ClientE2ETestSuite extends RemoteSparkSession with SQLHelper with PrivateM
}
assert(e3.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
- val e4 = intercept[AnalysisException] {
- // df1("i") is ambiguous as df1 appears in both join sides (df1_filter contains df1).
- df1.join(df1_filter, df1("i") === 1).collect()
- }
- assert(e4.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
+ // df1.join(df1_filter, df1("i") === 1) fails in classic spark due to:
+ // org.apache.spark.sql.AnalysisException: Column i#24 are ambiguous
+ assert(
Review Comment:
shall we use `checkSameResult`?
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan closed pull request #45846: [SPARK-47713][SQL][CONNECT] Fix a self-join failure
URL: https://github.com/apache/spark/pull/45846
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [WIP][SQL][CONNECT] Fix a self-join case with depth [spark]
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1549365091
##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/ClientE2ETestSuite.scala:
##########
@@ -938,11 +938,14 @@ class ClientE2ETestSuite extends RemoteSparkSession with SQLHelper with PrivateM
}
assert(e3.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
- val e4 = intercept[AnalysisException] {
- // df1("i") is ambiguous as df1 appears in both join sides (df1_filter contains df1).
- df1.join(df1_filter, df1("i") === 1).collect()
- }
- assert(e4.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
+ // val e4 = intercept[AnalysisException] {
+ // // df1("i") is ambiguous as df1 appears in both join sides (df1_filter contains df1).
+ // df1.join(df1_filter, df1("i") === 1).collect()
+ // }
+ // assert(e4.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
+ //
+ // "[AMBIGUOUS_COLUMN_OR_FIELD] Column or field `i` is ambiguous and has 2 matches.
Review Comment:
can not reproduce this failure with python client:
```
In [5]: df1 = spark.createDataFrame([(1, "a")], schema=["i", "j"])
In [6]: df1_filter = df1.filter(df1.i > 0)
In [7]: df2 = spark.createDataFrame([(2, "b")], schema=["i", "y"])
In [8]: df1.join(df1_filter, df1.i == 1).collect()
Out[8]: [Row(i=1, j='a', i=1, j='a')]
```
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1549622671
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala:
##########
@@ -542,23 +544,24 @@ trait ColumnResolutionHelper extends Logging with DataTypeErrorsBase {
u: UnresolvedAttribute,
id: Long,
isMetadataAccess: Boolean,
- q: Seq[LogicalPlan]): (Option[NamedExpression], Boolean) = {
- q.iterator.map(resolveDataFrameColumnRecursively(u, id, isMetadataAccess, _))
- .foldLeft((Option.empty[NamedExpression], false)) {
- case ((r1, m1), (r2, m2)) =>
- if (r1.nonEmpty && r2.nonEmpty) {
- throw QueryCompilationErrors.ambiguousColumnReferences(u)
- }
- (if (r1.nonEmpty) r1 else r2, m1 | m2)
+ q: Seq[LogicalPlan],
+ d: Int): Option[(NamedExpression, Int)] = {
+ q.flatMap(resolveDataFrameColumnRecursively(u, id, isMetadataAccess, _, d))
+ .sortBy(_._2) // make sure 0-depth result is on the left side (avoid depths like: 1, 2, 0)
+ .foldLeft(Option.empty[(NamedExpression, Int)]) {
+ case (None, (r2, d2)) => Some((r2, d2))
+ case (Some((r1, 0)), (r2, d2)) if d2 != 0 => Some((r1, 0))
+ case _ => throw QueryCompilationErrors.ambiguousColumnReferences(u)
}
}
private def resolveDataFrameColumnRecursively(
u: UnresolvedAttribute,
id: Long,
isMetadataAccess: Boolean,
- p: LogicalPlan): (Option[NamedExpression], Boolean) = {
- val (resolved, matched) = if (p.getTagValue(LogicalPlan.PLAN_ID_TAG).contains(id)) {
+ p: LogicalPlan,
+ d: Int): Option[(NamedExpression, Int)] = {
Review Comment:
ditto
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1550682214
##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/ClientE2ETestSuite.scala:
##########
@@ -938,11 +938,11 @@ class ClientE2ETestSuite extends RemoteSparkSession with SQLHelper with PrivateM
}
assert(e3.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
- val e4 = intercept[AnalysisException] {
- // df1("i") is ambiguous as df1 appears in both join sides (df1_filter contains df1).
- df1.join(df1_filter, df1("i") === 1).collect()
- }
- assert(e4.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
+ // df1.join(df1_filter, df1("i") === 1) fails in classic spark due to:
+ // org.apache.spark.sql.AnalysisException: Column i#24 are ambiguous
+ assert(
Review Comment:
I am going to add it additionally in the python test
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "xinrong-meng (via GitHub)" <gi...@apache.org>.
xinrong-meng commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1552164467
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala:
##########
@@ -527,13 +527,15 @@ trait ColumnResolutionHelper extends Logging with DataTypeErrorsBase {
logDebug(s"Extract plan_id $planId from $u")
val isMetadataAccess = u.getTagValue(LogicalPlan.IS_METADATA_COL).nonEmpty
- val (resolved, matched) = resolveDataFrameColumnByPlanId(u, planId, isMetadataAccess, q)
- if (!matched) {
- // Can not find the target plan node with plan id, e.g.
- // df1 = spark.createDataFrame([Row(a = 1, b = 2, c = 3)]])
- // df2 = spark.createDataFrame([Row(a = 1, b = 2)]])
- // df1.select(df2.a) <- illegal reference df2.a
- throw QueryCompilationErrors.cannotResolveDataFrameColumn(u)
+ val resolved = resolveDataFrameColumnByPlanId(u, planId, isMetadataAccess, q, 0).map(_._1)
+ if (resolved.isEmpty) {
+ if (!q.exists(_.exists(_.getTagValue(LogicalPlan.PLAN_ID_TAG).contains(planId)))) {
Review Comment:
A comment in code would be very helpful
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "zhengruifeng (via GitHub)" <gi...@apache.org>.
zhengruifeng commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1550680953
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala:
##########
@@ -527,13 +527,15 @@ trait ColumnResolutionHelper extends Logging with DataTypeErrorsBase {
logDebug(s"Extract plan_id $planId from $u")
val isMetadataAccess = u.getTagValue(LogicalPlan.IS_METADATA_COL).nonEmpty
- val (resolved, matched) = resolveDataFrameColumnByPlanId(u, planId, isMetadataAccess, q)
- if (!matched) {
- // Can not find the target plan node with plan id, e.g.
- // df1 = spark.createDataFrame([Row(a = 1, b = 2, c = 3)]])
- // df2 = spark.createDataFrame([Row(a = 1, b = 2)]])
- // df1.select(df2.a) <- illegal reference df2.a
- throw QueryCompilationErrors.cannotResolveDataFrameColumn(u)
+ val resolved = resolveDataFrameColumnByPlanId(u, planId, isMetadataAccess, q, 0).map(_._1)
+ if (resolved.isEmpty) {
+ if (!q.exists(_.exists(_.getTagValue(LogicalPlan.PLAN_ID_TAG).contains(planId)))) {
Review Comment:
I think there are two cases:
1, analyzer rules supporting missing column resolution
https://github.com/apache/spark/blob/923f04606fe6bee5913f8fce7aaa643984f79756/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala#L583-L607
2, plan id missed in some way (should be bugs)
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1550962195
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ColumnResolutionHelper.scala:
##########
@@ -527,13 +527,15 @@ trait ColumnResolutionHelper extends Logging with DataTypeErrorsBase {
logDebug(s"Extract plan_id $planId from $u")
val isMetadataAccess = u.getTagValue(LogicalPlan.IS_METADATA_COL).nonEmpty
- val (resolved, matched) = resolveDataFrameColumnByPlanId(u, planId, isMetadataAccess, q)
- if (!matched) {
- // Can not find the target plan node with plan id, e.g.
- // df1 = spark.createDataFrame([Row(a = 1, b = 2, c = 3)]])
- // df2 = spark.createDataFrame([Row(a = 1, b = 2)]])
- // df1.select(df2.a) <- illegal reference df2.a
- throw QueryCompilationErrors.cannotResolveDataFrameColumn(u)
+ val resolved = resolveDataFrameColumnByPlanId(u, planId, isMetadataAccess, q, 0).map(_._1)
+ if (resolved.isEmpty) {
+ if (!q.exists(_.exists(_.getTagValue(LogicalPlan.PLAN_ID_TAG).contains(planId)))) {
Review Comment:
Shall we still have the `matched` flag? The new code is confusing and I can't understand it even after reading your comment.
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
Re: [PR] [SPARK-47713][SQL][CONNECT] Fix a self-join failure [spark]
Posted by "cloud-fan (via GitHub)" <gi...@apache.org>.
cloud-fan commented on code in PR #45846:
URL: https://github.com/apache/spark/pull/45846#discussion_r1550951145
##########
connector/connect/client/jvm/src/test/scala/org/apache/spark/sql/ClientE2ETestSuite.scala:
##########
@@ -938,11 +938,11 @@ class ClientE2ETestSuite extends RemoteSparkSession with SQLHelper with PrivateM
}
assert(e3.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
- val e4 = intercept[AnalysisException] {
- // df1("i") is ambiguous as df1 appears in both join sides (df1_filter contains df1).
- df1.join(df1_filter, df1("i") === 1).collect()
- }
- assert(e4.getMessage.contains("AMBIGUOUS_COLUMN_REFERENCE"))
+ // df1.join(df1_filter, df1("i") === 1) fails in classic spark due to:
+ // org.apache.spark.sql.AnalysisException: Column i#24 are ambiguous
+ assert(
Review Comment:
Can we create a JIRA ticket to report this bug and leave a TODO here?
--
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.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org