-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-46538][ML] Fix the ambiguous column reference issue in ALSModel.transform
#44526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| model.write().overwrite().save(d) | ||
| loaded_model = ALSModel().load(d) | ||
|
|
||
| with self.sql_conf({"spark.sql.analyzer.failAmbiguousSelfJoin": False}): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before this PR, fails with [MISSING_ATTRIBUTES.RESOLVED_ATTRIBUTE_APPEAR_IN_OPERATION]
| predictions = loaded_model.transform(users.crossJoin(items)) | ||
| self.assertTrue(predictions.count() > 0) | ||
|
|
||
| with self.sql_conf({"spark.sql.analyzer.failAmbiguousSelfJoin": True}): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before this PR, fails with org.apache.spark.sql.AnalysisException: Column features#50, features#46 are ambiguous
ALSModel.transformALSModel.transform
|
cc @cloud-fan and @WeichenXu123 |
| validatedItems === itemFactors("id"), "left") | ||
| .select(dataset("*"), | ||
| predict(userFactors("features"), itemFactors("features")).as($(predictionCol))) | ||
| .withColumns(Map($(userCol) -> validatedUsers, $(itemCol) -> validatedItems)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shall we use the Seq version of withColumns? So that the column order is deterministic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need a withColumns now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It maybe not needed, I want to use withColumns to validate the columns first (while keep the column name) and then reference the validated column by s"${validatedInputAlias}.${$(itemCol)}"
| validatedItems === itemFactors("id"), "left") | ||
| .select(dataset("*"), | ||
| predict(userFactors("features"), itemFactors("features")).as($(predictionCol))) | ||
| .withColumns(Seq($(userCol), $(itemCol)), Seq(validatedUsers, validatedItems)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, previously validatedUsers was directly used in the join condition, now we materialize it first and reference only columns in the join condition.
|
merged to master |
What changes were proposed in this pull request?
the column references in
ALSModel.transformmaybe ambiguous in some caseWhy are the changes needed?
to fix a bug
before this fix, the test fails with:
and
Does this PR introduce any user-facing change?
yes, bug fix
How was this patch tested?
added ut
Was this patch authored or co-authored using generative AI tooling?
no