MaxGekk commented on code in PR #45064:
URL: https://github.com/apache/spark/pull/45064#discussion_r1485603308
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala:
##########
@@ -520,6 +520,8 @@ object FunctionRegistry {
expression[Ascii]("ascii"),
expression[Chr]("char", true),
expression[Chr]("chr"),
+ expression[Collate]("collate"),
Review Comment:
Are the any tests where you check it as a regular function via the call
`collate()`? Sorry, I haven't found them.
##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/collationExpressions.scala:
##########
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.catalyst.expressions
+
+import org.apache.spark.sql.catalyst.InternalRow
+import org.apache.spark.sql.catalyst.expressions.codegen._
+import org.apache.spark.sql.catalyst.util.CollationFactory
+import org.apache.spark.sql.types._
+
+/**
+ * A function that marks a given expression with specified collation.
Review Comment:
Technically, this is an expression not a function.
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/CollationExpressionSuite.scala:
##########
@@ -0,0 +1,80 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.sql.catalyst.expressions
+
+import scala.jdk.CollectionConverters.MapHasAsScala
+
+import org.apache.spark.{SparkException, SparkFunSuite}
+import org.apache.spark.sql.catalyst.util.CollationFactory
+import org.apache.spark.sql.types._
+
+class CollationExpressionSuite extends SparkFunSuite with ExpressionEvalHelper
{
+ test("validate default collation") {
+ val collationId = CollationFactory.collationNameToId("UCS_BASIC")
+ assert(collationId == 0)
+ val collateExpr = Collate(Literal("abc"), "UCS_BASIC")
+ assert(collateExpr.dataType === StringType(collationId))
+ collateExpr.dataType.asInstanceOf[StringType].collationId == 0
+ checkEvaluation(collateExpr, "abc")
+ }
+
+ test("collate against literal") {
+ val collateExpr = Collate(Literal("abc"), "UCS_BASIC_LCASE")
+ val collationId = CollationFactory.collationNameToId("UCS_BASIC_LCASE")
+ assert(collateExpr.dataType == StringType(collationId))
+ checkEvaluation(collateExpr, "abc")
+ }
+
+ test("check input types") {
+ val collateExpr = Collate(Literal("abc"), "UCS_BASIC")
+ assert(collateExpr.checkInputDataTypes().isSuccess)
+
+ val collateExprExplicitDefault =
+ Collate(Literal.create("abc", StringType(0)), "UCS_BASIC")
+ assert(collateExprExplicitDefault.checkInputDataTypes().isSuccess)
+
+ val collateExprExplicitNonDefault =
+ Collate(Literal.create("abc", StringType(1)), "UCS_BASIC")
+ assert(collateExprExplicitNonDefault.checkInputDataTypes().isSuccess)
+
+ val collateOnNull = Collate(Literal.create(null, StringType(1)),
"UCS_BASIC")
+ assert(collateOnNull.checkInputDataTypes().isSuccess)
+
+ val collateOnInt = Collate(Literal(1), "UCS_BASIC")
+ assert(collateOnInt.checkInputDataTypes().isFailure)
+ }
+
+ test("collate on non existing collation") {
+ val error = intercept[SparkException] {
+ Collate(Literal("abc"), "UCS_BASIS")
+ }
+ assert(error.getErrorClass === "COLLATION_INVALID_NAME")
Review Comment:
Could you use `checkError()`, please. It should be available in
`sql/catalyst`.
--
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]