Skip to content
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

[SPARK-47504][SQL] Resolve AbstractDataType simpleStrings for StringTypeCollated #45694

Closed
wants to merge 11 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import org.apache.spark.sql.types.{AbstractDataType, DataType, StringType}
*/
abstract class StringTypeCollated extends AbstractDataType {
override private[sql] def defaultConcreteType: DataType = StringType
override private[sql] def simpleString: String = "string"
}

/**
* Use StringTypeBinary for expressions supporting only binary collation.
*/
case object StringTypeBinary extends StringTypeCollated {
override private[sql] def simpleString: String = "string_binary"
override private[sql] def acceptsType(other: DataType): Boolean =
other.isInstanceOf[StringType] && other.asInstanceOf[StringType].supportsBinaryEquality
}
Expand All @@ -39,7 +39,6 @@ case object StringTypeBinary extends StringTypeCollated {
* Use StringTypeBinaryLcase for expressions supporting only binary and lowercase collation.
*/
case object StringTypeBinaryLcase extends StringTypeCollated {
override private[sql] def simpleString: String = "string_binary_lcase"
override private[sql] def acceptsType(other: DataType): Boolean =
other.isInstanceOf[StringType] && (other.asInstanceOf[StringType].supportsBinaryEquality ||
other.asInstanceOf[StringType].isUTF8BinaryLcaseCollation)
Expand All @@ -49,6 +48,5 @@ case object StringTypeBinaryLcase extends StringTypeCollated {
* Use StringTypeAnyCollation for expressions supporting all possible collation types.
*/
case object StringTypeAnyCollation extends StringTypeCollated {
override private[sql] def simpleString: String = "string_any_collation"
override private[sql] def acceptsType(other: DataType): Boolean = other.isInstanceOf[StringType]
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class StringExpressionsSuite extends SparkFunSuite with ExpressionEvalHelper {
errorSubClass = "UNEXPECTED_INPUT_TYPE",
messageParameters = Map(
"paramIndex" -> ordinalNumber(0),
"requiredType" -> "(\"STRING_ANY_COLLATION\" or \"BINARY\" or \"ARRAY\")",
"requiredType" -> "(\"STRING\" or \"BINARY\" or \"ARRAY\")",
"inputSql" -> "\"1\"",
"inputType" -> "\"INT\""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class CollationSuite extends DatasourceV2SQLBase with AdaptiveSparkPlanHelper {
"paramIndex" -> "first",
"inputSql" -> "\"1\"",
"inputType" -> "\"INT\"",
"requiredType" -> "\"STRING_ANY_COLLATION\""),
"requiredType" -> "\"STRING\""),
context = ExpectedContext(
fragment = s"collate(1, 'UTF8_BINARY')", start = 7, stop = 31))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1713,7 +1713,7 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSparkSession {
"paramIndex" -> "second",
"inputSql" -> "\"1\"",
"inputType" -> "\"INT\"",
"requiredType" -> "\"STRING_ANY_COLLATION\""
"requiredType" -> "\"STRING\""
),
queryContext = Array(ExpectedContext("", "", 0, 15, "array_join(x, 1)"))
)
Expand All @@ -1727,7 +1727,7 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSparkSession {
"paramIndex" -> "third",
"inputSql" -> "\"1\"",
"inputType" -> "\"INT\"",
"requiredType" -> "\"STRING_ANY_COLLATION\""
"requiredType" -> "\"STRING\""
),
queryContext = Array(ExpectedContext("", "", 0, 21, "array_join(x, ', ', 1)"))
)
Expand Down Expand Up @@ -1987,7 +1987,7 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSparkSession {
"paramIndex" -> "first",
"inputSql" -> "\"struct(1, a)\"",
"inputType" -> "\"STRUCT<col1: INT NOT NULL, col2: STRING NOT NULL>\"",
"requiredType" -> "(\"STRING_ANY_COLLATION\" or \"ARRAY\")"
"requiredType" -> "(\"STRING\" or \"ARRAY\")"
),
queryContext = Array(ExpectedContext("", "", 7, 29, "reverse(struct(1, 'a'))"))
)
Expand All @@ -2002,7 +2002,7 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSparkSession {
"paramIndex" -> "first",
"inputSql" -> "\"map(1, a)\"",
"inputType" -> "\"MAP<INT, STRING>\"",
"requiredType" -> "(\"STRING_ANY_COLLATION\" or \"ARRAY\")"
"requiredType" -> "(\"STRING\" or \"ARRAY\")"
),
queryContext = Array(ExpectedContext("", "", 7, 26, "reverse(map(1, 'a'))"))
)
Expand Down Expand Up @@ -2552,7 +2552,7 @@ class DataFrameFunctionsSuite extends QueryTest with SharedSparkSession {
parameters = Map(
"sqlExpr" -> "\"concat(map(1, 2), map(3, 4))\"",
"paramIndex" -> "first",
"requiredType" -> "(\"STRING_ANY_COLLATION\" or \"BINARY\" or \"ARRAY\")",
"requiredType" -> "(\"STRING\" or \"BINARY\" or \"ARRAY\")",
"inputSql" -> "\"map(1, 2)\"",
"inputType" -> "\"MAP<INT, INT>\""
),
Expand Down