-
Notifications
You must be signed in to change notification settings - Fork 29.1k
[SQL] Add collations support to split regex expression #45856
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f684c4b
5b27a25
2bed330
ecb5e30
7f337fd
d336245
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,8 +33,9 @@ import org.apache.spark.sql.catalyst.expressions.codegen._ | |
| import org.apache.spark.sql.catalyst.expressions.codegen.Block._ | ||
| import org.apache.spark.sql.catalyst.trees.BinaryLike | ||
| import org.apache.spark.sql.catalyst.trees.TreePattern.{LIKE_FAMLIY, REGEXP_EXTRACT_FAMILY, REGEXP_REPLACE, TreePattern} | ||
| import org.apache.spark.sql.catalyst.util.{GenericArrayData, StringUtils} | ||
| import org.apache.spark.sql.catalyst.util.{CollationSupport, GenericArrayData, StringUtils} | ||
| import org.apache.spark.sql.errors.QueryExecutionErrors | ||
| import org.apache.spark.sql.internal.types.{StringTypeAnyCollation, StringTypeBinaryLcase} | ||
| import org.apache.spark.sql.types._ | ||
| import org.apache.spark.unsafe.types.UTF8String | ||
|
|
||
|
|
@@ -543,25 +544,28 @@ case class RLike(left: Expression, right: Expression) extends StringRegexExpress | |
| case class StringSplit(str: Expression, regex: Expression, limit: Expression) | ||
| extends TernaryExpression with ImplicitCastInputTypes with NullIntolerant { | ||
|
|
||
| override def dataType: DataType = ArrayType(StringType, containsNull = false) | ||
| override def inputTypes: Seq[DataType] = Seq(StringType, StringType, IntegerType) | ||
| override def dataType: DataType = ArrayType(str.dataType, containsNull = false) | ||
| override def inputTypes: Seq[AbstractDataType] = | ||
| Seq(StringTypeBinaryLcase, StringTypeAnyCollation, IntegerType) | ||
|
||
| override def first: Expression = str | ||
| override def second: Expression = regex | ||
| override def third: Expression = limit | ||
|
|
||
| final lazy val collationId: Int = str.dataType.asInstanceOf[StringType].collationId | ||
|
|
||
| def this(exp: Expression, regex: Expression) = this(exp, regex, Literal(-1)) | ||
|
|
||
| override def nullSafeEval(string: Any, regex: Any, limit: Any): Any = { | ||
| val strings = string.asInstanceOf[UTF8String].split( | ||
| regex.asInstanceOf[UTF8String], limit.asInstanceOf[Int]) | ||
| val strings = CollationSupport.StringSplit.exec(string.asInstanceOf[UTF8String], | ||
| regex.asInstanceOf[UTF8String], limit.asInstanceOf[Int], collationId) | ||
| new GenericArrayData(strings.asInstanceOf[Array[Any]]) | ||
| } | ||
|
|
||
| override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = { | ||
| val arrayClass = classOf[GenericArrayData].getName | ||
| nullSafeCodeGen(ctx, ev, (str, regex, limit) => { | ||
| defineCodeGen(ctx, ev, (str, regex, limit) => { | ||
| // Array in java is covariant, so we don't need to cast UTF8String[] to Object[]. | ||
| s"""${ev.value} = new $arrayClass($str.split($regex,$limit));""".stripMargin | ||
| s"new $arrayClass(${CollationSupport.StringSplit.genCode(str, regex, limit, collationId)})" | ||
| }) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is no
execICUfor this operation?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's not supported yet, we should add
assert(collation.supportsLowercaseEquality)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
final lazy val collationId: Int = str.dataType.asInstanceOf[StringType].collationIdforStringTypeBinaryLcasewon't allow that to happen. But an additional assert in the else branch couldn't hurt too