fqaiser94 commented on a change in pull request #27066: [SPARK-31317][SQL] Add
withField method to Column class
URL: https://github.com/apache/spark/pull/27066#discussion_r403768584
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/Column.scala
##########
@@ -879,6 +879,17 @@ class Column(val expr: Expression) extends Logging {
*/
def getItem(key: Any): Column = withExpr { UnresolvedExtractValue(expr,
Literal(key)) }
+ /**
+ * An expression that adds/replaces a field by name in a `StructType`.
+ * If schema contains multiple fields with fieldName, they will all be
replaced with fieldValue.
+ *
+ * @group expr_ops
+ * @since 3.1.0
+ */
+ def withField(fieldName: String, fieldValue: Column): Column = withExpr {
Review comment:
Personally, `Column.withColumn` doesn't make as much sense as
`Column.withField`. Given that a `StructType` dataType consists of a collection
of `StructFields`, `Column.withField` clearly communicates to me that this
method operates only on `StructType` dataType columns. Additionally,
`Column.withField` nicely complements the existing `Column.getField` method.
I'm not saying I'm opposed to making this change. Frankly, both names have
their merits. I am only slightly in favour of `Column.withField`.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]