-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
[SPARK-49025] Make Column implementation agnostic #3913
Changes from all commits
29c81a8
7769b02
3cd4522
1e42d57
96b744e
5f4b78e
a790e70
ebfc764
57aed4e
5b096ad
14f9145
839b53e
51b19ba
237324b
2686ffc
930ff3a
f509464
4c28389
bb00621
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (2021) The Delta Lake Project Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.delta | ||
|
||
import org.apache.spark.sql.Column | ||
import org.apache.spark.sql.catalyst.expressions.Expression | ||
|
||
/** | ||
* Conversions from a [[org.apache.spark.sql.Column]] to an | ||
* [[org.apache.spark.sql.catalyst.expressions.Expression]], and vice versa. | ||
*/ | ||
object ClassicColumnConversions { | ||
def expression(c: Column): Expression = c.expr | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (2021) The Delta Lake Project Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.spark.sql.delta | ||
|
||
import org.apache.spark.sql.classic.ClassicConversions | ||
import org.apache.spark.sql.classic.ColumnConversions | ||
|
||
/** | ||
* Conversions from a [[org.apache.spark.sql.Column]] to an | ||
* [[org.apache.spark.sql.catalyst.expressions.Expression]], and vice versa. | ||
* | ||
* @note [[org.apache.spark.sql.internal.ExpressionUtils#expression]] is a cheap alternative for | ||
* [[org.apache.spark.sql.Column]] to [[org.apache.spark.sql.catalyst.expressions.Expression]] | ||
* conversions. However this can only be used when the produced expression is used in a Column | ||
* later on. | ||
*/ | ||
object ClassicColumnConversions | ||
extends ClassicConversions | ||
with ColumnConversions |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ package org.apache.spark.sql.delta.commands.merge | |
import scala.collection.mutable | ||
|
||
import org.apache.spark.sql.delta.{RowCommitVersion, RowId} | ||
import org.apache.spark.sql.delta.ClassicColumnConversions._ | ||
import org.apache.spark.sql.delta.commands.MergeIntoCommandBase | ||
import org.apache.spark.sql.delta.commands.cdc.CDCReader | ||
|
||
|
@@ -164,8 +165,8 @@ trait MergeOutputGeneration { self: MergeIntoCommandBase => | |
// That is, conditionally invokes them based on whether there was a match in the outer join. | ||
|
||
// Predicates to check whether there was a match in the full outer join. | ||
val ifSourceRowNull = col(SOURCE_ROW_PRESENT_COL).isNull.expr | ||
val ifTargetRowNull = col(TARGET_ROW_PRESENT_COL).isNull.expr | ||
val ifSourceRowNull = expression(col(SOURCE_ROW_PRESENT_COL).isNull) | ||
val ifTargetRowNull = expression(col(TARGET_ROW_PRESENT_COL).isNull) | ||
Comment on lines
-167
to
+169
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we make this change sometimes? (using Other times it seems we use the implicit conversion to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Gotcha. Could you maybe add this in docs to |
||
|
||
val outputCols = targetWriteColNames.zipWithIndex.map { case (name, i) => | ||
// Coupled with the clause conditions, the resultant possibly-nested CaseWhens can | ||
|
@@ -213,7 +214,8 @@ trait MergeOutputGeneration { self: MergeIntoCommandBase => | |
Column(Alias(caseWhen, name)()) | ||
} | ||
} | ||
logDebug("writeAllChanges: join output expressions\n\t" + seqToString(outputCols.map(_.expr))) | ||
logDebug("writeAllChanges: join output expressions\n\t" + seqToString( | ||
outputCols.map(expression))) | ||
outputCols | ||
}.toIndexedSeq | ||
|
||
|
@@ -421,36 +423,36 @@ trait MergeOutputGeneration { self: MergeIntoCommandBase => | |
|
||
val cdcTypeCol = outputCols.last | ||
val cdcArray = Column(CaseWhen(Seq( | ||
EqualNullSafe(cdcTypeCol.expr, Literal(CDC_TYPE_INSERT)) -> array( | ||
struct(outputCols: _*)).expr, | ||
EqualNullSafe(expression(cdcTypeCol), Literal(CDC_TYPE_INSERT)) -> expression(array( | ||
struct(outputCols: _*))), | ||
|
||
EqualNullSafe(cdcTypeCol.expr, Literal(CDC_TYPE_UPDATE_POSTIMAGE)) -> array( | ||
EqualNullSafe(expression(cdcTypeCol), Literal(CDC_TYPE_UPDATE_POSTIMAGE)) -> expression(array( | ||
struct(updatePreimageCdcOutput: _*), | ||
struct(outputCols: _*)).expr, | ||
struct(outputCols: _*))), | ||
|
||
EqualNullSafe(cdcTypeCol.expr, CDC_TYPE_DELETE) -> array( | ||
struct(deleteCdcOutput: _*)).expr), | ||
EqualNullSafe(expression(cdcTypeCol), CDC_TYPE_DELETE) -> expression(array( | ||
struct(deleteCdcOutput: _*)))), | ||
|
||
// If none of the CDC cases apply (true for purely rewritten target rows, dropped source | ||
// rows, etc.) just stick to the normal output. | ||
array(struct(mainDataOutput: _*)).expr | ||
expression(array(struct(mainDataOutput: _*))) | ||
)) | ||
|
||
val cdcToMainDataArray = Column(If( | ||
Or( | ||
EqualNullSafe(col(s"packedCdc.$CDC_TYPE_COLUMN_NAME").expr, | ||
EqualNullSafe(expression(col(s"packedCdc.$CDC_TYPE_COLUMN_NAME")), | ||
Literal(CDC_TYPE_INSERT)), | ||
EqualNullSafe(col(s"packedCdc.$CDC_TYPE_COLUMN_NAME").expr, | ||
EqualNullSafe(expression(col(s"packedCdc.$CDC_TYPE_COLUMN_NAME")), | ||
Literal(CDC_TYPE_UPDATE_POSTIMAGE))), | ||
array( | ||
expression(array( | ||
col("packedCdc"), | ||
struct( | ||
outputColNames | ||
.dropRight(1) | ||
.map { n => col(s"packedCdc.`$n`") } | ||
:+ Column(CDC_TYPE_NOT_CDC).as(CDC_TYPE_COLUMN_NAME): _*) | ||
).expr, | ||
array(col("packedCdc")).expr | ||
)), | ||
expression(array(col("packedCdc"))) | ||
)) | ||
|
||
if (deduplicateDeletes.enabled) { | ||
|
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.
@allisonport-db here is the comment you asked for.