Skip to content

Commit 2e66014

Browse files
author
Kazantsev Maksim
committed
Fix PR issues
1 parent 8e3f482 commit 2e66014

2 files changed

Lines changed: 11 additions & 25 deletions

File tree

spark/src/main/scala/org/apache/comet/serde/strings.scala

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -295,24 +295,6 @@ object CometElt extends CometScalarFunction[Elt]("elt") {
295295
if (expr.failOnError) {
296296
return Unsupported(Some("ANSI mode not supported"))
297297
}
298-
if (expr.children.length < 2) {
299-
return Unsupported(Some("The `elt` requires > 1 parameters but the actual number is 1"))
300-
}
301-
val idxDataType = expr.children.head.dataType
302-
if (idxDataType != IntegerType) {
303-
return Unsupported(Some(s"Parameter 1 requires the int type, but got: $idxDataType"))
304-
}
305-
if (!expr.children.tail.forall(_.dataType == StringType)) {
306-
val unsupportedTypes =
307-
expr.children.tail
308-
.filter(_.dataType != StringType)
309-
.map(_.dataType)
310-
.distinct
311-
.mkString(", ")
312-
return Unsupported(
313-
Some(
314-
s"Parameters 2 and onwards require the string type, but contains: $unsupportedTypes"))
315-
}
316298
Compatible(None)
317299
}
318300
}

spark/src/test/scala/org/apache/comet/CometStringExpressionSuite.scala

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,18 @@ package org.apache.comet
2121

2222
import scala.util.Random
2323

24+
import org.apache.hadoop.fs.Path
2425
import org.apache.parquet.hadoop.ParquetOutputFormat
2526
import org.apache.spark.sql.{CometTestBase, DataFrame}
2627
import org.apache.spark.sql.functions.lit
2728
import org.apache.spark.sql.internal.SQLConf
2829
import org.apache.spark.sql.types.{DataTypes, StringType, StructField, StructType}
2930

31+
import org.apache.comet.serde.CometElt
3032
import org.apache.comet.testing.{DataGenOptions, FuzzDataGenerator}
3133

3234
class CometStringExpressionSuite extends CometTestBase {
3335

34-
private val WRONG_NUM_ARGS_WITHOUT_SUGGESTION_EXCEPTION_MSG =
35-
"[WRONG_NUM_ARGS.WITHOUT_SUGGESTION] The `elt` requires > 1 parameters but the actual number is 1."
36-
3736
test("lpad string") {
3837
testStringPadding("lpad")
3938
}
@@ -396,7 +395,12 @@ class CometStringExpressionSuite extends CometTestBase {
396395
}
397396

398397
test("elt") {
399-
withSQLConf(SQLConf.ANSI_ENABLED.key -> "false") {
398+
val wrongNumArgsWithoutSuggestionExceptionMsg =
399+
"[WRONG_NUM_ARGS.WITHOUT_SUGGESTION] The `elt` requires > 1 parameters but the actual number is 1."
400+
withSQLConf(
401+
SQLConf.ANSI_ENABLED.key -> "false",
402+
SQLConf.OPTIMIZER_EXCLUDED_RULES.key ->
403+
"org.apache.spark.sql.catalyst.optimizer.ConstantFolding") {
400404
val r = new Random(42)
401405
val fieldsCount = 10
402406
val indexes = Seq.range(1, fieldsCount)
@@ -420,13 +424,13 @@ class CometStringExpressionSuite extends CometTestBase {
420424
sql(s"SELECT elt(cast(null as int), ${schema.fieldNames.mkString(",")}) FROM t1"))
421425
checkSparkAnswerMaybeThrows(sql("SELECT elt(1) FROM t1")) match {
422426
case (Some(spark), Some(comet)) =>
423-
assert(spark.getMessage.contains(WRONG_NUM_ARGS_WITHOUT_SUGGESTION_EXCEPTION_MSG))
424-
assert(comet.getMessage.contains(WRONG_NUM_ARGS_WITHOUT_SUGGESTION_EXCEPTION_MSG))
427+
assert(spark.getMessage.contains(wrongNumArgsWithoutSuggestionExceptionMsg))
428+
assert(comet.getMessage.contains(wrongNumArgsWithoutSuggestionExceptionMsg))
425429
case (spark, comet) =>
426430
fail(
427431
s"Expected Spark and Comet to throw exception, but got\nSpark: $spark\nComet: $comet")
428432
}
433+
checkSparkAnswerAndOperator("SELECT elt(2, 'a', 'b', 'c')")
429434
}
430435
}
431-
432436
}

0 commit comments

Comments
 (0)