mihailom-db commented on code in PR #45643:
URL: https://github.com/apache/spark/pull/45643#discussion_r1537161627
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringExpressions.scala:
##########
@@ -1377,17 +1394,34 @@ case class StringInstr(str: Expression, substr:
Expression)
override def left: Expression = str
override def right: Expression = substr
override def dataType: DataType = IntegerType
- override def inputTypes: Seq[DataType] = Seq(StringType, StringType)
+ override def inputTypes: Seq[AbstractDataType] =
+ Seq(StringTypeAnyCollation, StringTypeAnyCollation)
override def nullSafeEval(string: Any, sub: Any): Any = {
- string.asInstanceOf[UTF8String].indexOf(sub.asInstanceOf[UTF8String], 0) +
1
+ val collationId = left.dataType.asInstanceOf[StringType].collationId
+ string.asInstanceOf[UTF8String].indexOf(sub.asInstanceOf[UTF8String], 0,
collationId) + 1
+ }
+
+ override def checkInputDataTypes(): TypeCheckResult = {
+ val defaultCheck = super.checkInputDataTypes()
+ if (defaultCheck.isFailure) {
+ return defaultCheck
+ }
+
+ val collationId = left.dataType.asInstanceOf[StringType].collationId
+ CollationTypeConstraints.checkCollationCompatibility(collationId,
children.map(_.dataType))
Review Comment:
+1 I believe this check should be removed after merging implicit casting.
One problem with the check is that in future it does not take into account the
fact that we can have indeterminate collation and blindly calls fetchCollation
which can fail to return a collator. This PR
https://github.com/apache/spark/pull/45383 will remove it, as implicit casting
should make sure all collations are the same and that they are not
indeterminate if that is needed.
--
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]