You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by "mihailom-db (via GitHub)" <gi...@apache.org> on 2025/01/03 14:47:45 UTC
Re: [PR] [SPARK-50707][SQL] Enable casting to/from char/varchar [spark]
mihailom-db commented on code in PR #49340:
URL: https://github.com/apache/spark/pull/49340#discussion_r1901853840
##########
sql/api/src/main/scala/org/apache/spark/sql/types/StringType.scala:
##########
@@ -129,6 +130,60 @@ case object StringType
sealed trait StringConstraint
+case object StringHelper extends PartialOrdering[StringConstraint] {
+ override def tryCompare(x: StringConstraint, y: StringConstraint): Option[Int] = {
+ (x, y) match {
+ case (NoConstraint, NoConstraint) => Some(0)
+ case (NoConstraint, _) => Some(-1)
+ case (_, NoConstraint) => Some(1)
+ case (FixedLength(l1), FixedLength(l2)) => Some(l2.compareTo(l1))
+ case (FixedLength(l1), MaxLength(l2)) if l1 <= l2 => Some(1)
+ case (MaxLength(l1), FixedLength(l2)) if l1 >= l2 => Some(-1)
+ case (MaxLength(l1), MaxLength(l2)) => Some(l2.compareTo(l1))
+ case _ => None
+ }
+ }
+
+ override def lteq(x: StringConstraint, y: StringConstraint): Boolean = {
+ tryCompare(x, y).exists(_ <= 0)
+ }
+
+ override def gteq(x: StringConstraint, y: StringConstraint): Boolean = {
+ tryCompare(x, y).exists(_ >= 0)
+ }
+
+ override def equiv(x: StringConstraint, y: StringConstraint): Boolean = {
+ tryCompare(x, y).contains(0)
+ }
+
+ def isPlainString(s: StringType): Boolean = equiv(s.constraint, NoConstraint)
+
+ def isMoreConstrained(a: StringType, b: StringType): Boolean =
+ gteq(a.constraint, b.constraint)
+
+ def tightestCommonString(s1: StringType, s2: StringType): Option[StringType] = {
+ if (s1.collationId != s2.collationId) {
+ return None
+ }
+ if (!SqlApiConf.get.preserveCharVarcharTypeInfo) {
+ return Some(StringType(s1.collationId))
Review Comment:
Why not just return s2 as previous behaviour 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