Github user HuJiayin commented on a diff in the pull request:
https://github.com/apache/spark/pull/7186#discussion_r33927820
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/stringOperations.scala
---
@@ -211,6 +211,77 @@ case class EndsWith(left: Expression, right:
Expression)
}
/**
+ * A function that returns the index (1-based) of the given string (left)
in the comma-
+ * delimited list (right). Returns -1, if the string wasn't found and 0 if
the given
+ * string (left) contains a comma.
+ */
+case class FindInSet(left: Expression, right: Expression) extends
BinaryExpression
+ with ExpectsInputTypes {
+
+ override def checkInputDataTypes(): TypeCheckResult = {
+ (left.dataType, right.dataType) match {
+ case (_, NullType) | (NullType, _) | (StringType, StringType) =>
+ TypeCheckResult.TypeCheckSuccess
+ case _ =>
+ TypeCheckResult.TypeCheckFailure(s"FindInSet expects two strings
as argument, not " +
+ s"(${left.dataType}, ${right.dataType})")
+ }
+ }
+
+ override def inputTypes: Seq[Any] = Seq(StringType, StringType)
+
+ override def eval(input: InternalRow): Any = {
+ val valueLeft = left.eval(input)
+ if (valueLeft != null) {
+ val strLeft = valueLeft.asInstanceOf[UTF8String]
+ if (!strLeft.contains(UTF8String.fromString(","))) {
+ val valueRight = right.eval(input)
+ if (valueRight != null) {
+ val splits =
valueRight.asInstanceOf[UTF8String].toString.split(",")
+ var i = 0
--- End diff --
You don't need to implement a split in this issue. That is not the point.
The point is you don't need to split.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]