shivadarshan-devadiga commented on code in PR #60756:
URL: https://github.com/apache/spark/pull/60756#discussion_r4643928551
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/plans/logical/basicLogicalOperators.scala:
##########
@@ -504,16 +504,26 @@ object Union {
Union (left :: right :: Nil)
}
- // updating nullability to make all the children consistent
- def mergeChildOutputs(childOutputs: Seq[Seq[Attribute]]): Seq[Attribute] = {
+ // updating nullability to make all the children consistent, and the CHAR
lengths of the raw
+ // types if the children have CHAR columns of different lengths, see
+ // CharVarcharUtils.widerCharRawType. ApplyCharTypePadding pads the values
of the shorter ones.
+ def mergeChildOutputs(childOutputs: Seq[Seq[Attribute]]): Seq[Attribute] =
+ mergeChildOutputs(childOutputs, widenCharLengths = true)
+
+ private[logical] def mergeChildOutputs(
+ childOutputs: Seq[Seq[Attribute]],
+ widenCharLengths: Boolean): Seq[Attribute] = {
childOutputs.transpose.map { attrs =>
val firstAttr = attrs.head
val nullable = attrs.exists(_.nullable)
val newDt = attrs.map(_.dataType).reduce(StructType.unionLikeMerge)
- if (firstAttr.dataType == newDt) {
+ val widerRawType = if (widenCharLengths)
CharVarcharUtils.widerCharRawType(attrs) else None
+ val metadata =
widerRawType.map(CharVarcharUtils.withRawType(firstAttr.metadata, _))
Review Comment:
Fixed without touching the stored schema. A view keeps the CHAR type it
stored. When that type is shorter than the type of its query's column, which
only happens for a view of a set operation created before this change,
`ApplyCharTypePadding` now narrows the values back to the stored length. It
removes the trailing spaces past it with a new
`CharVarcharCodegenUtils.charTypeNarrowing`, which, like `readSidePadding`,
keeps values that have other characters past the length. The view column keeps
its exprId and metadata. DESCRIBE, comparisons and V2 write checks all see the
stored CHAR(3), and the values agree with it. `SPARK-61972: a view of a union
that stores a shorter char length` sets the stored type back to CHAR(3) to
emulate such a view: `WHERE c = 'a'` returns both rows (it returned only the t3
row before this PR), and `'abcde'` is kept.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]