This is an automated email from the ASF dual-hosted git repository.
mingliang pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git
The following commit(s) were added to refs/heads/main by this push:
new aa256fa3e1 [VL] Support casting array element from more types to
varchar (#10270)
aa256fa3e1 is described below
commit aa256fa3e136eb32e906d1b52ddb3cf4a5130991
Author: Mingliang Zhu <[email protected]>
AuthorDate: Thu Jul 31 11:50:16 2025 +0800
[VL] Support casting array element from more types to varchar (#10270)
---
.../functions/ScalarFunctionsValidateSuite.scala | 19 ++++++
.../substrait/SubstraitToVeloxPlanValidator.cc | 3 +-
.../utils/clickhouse/ClickHouseTestSettings.scala | 5 --
.../sql/catalyst/expressions/GlutenCastSuite.scala | 72 +++-------------------
.../utils/clickhouse/ClickHouseTestSettings.scala | 5 --
.../sql/catalyst/expressions/GlutenCastSuite.scala | 72 +++-------------------
.../utils/clickhouse/ClickHouseTestSettings.scala | 5 --
.../sql/catalyst/expressions/GlutenCastSuite.scala | 72 +++-------------------
.../utils/clickhouse/ClickHouseTestSettings.scala | 5 --
.../sql/catalyst/expressions/GlutenCastSuite.scala | 72 +++-------------------
10 files changed, 57 insertions(+), 273 deletions(-)
diff --git
a/backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala
b/backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala
index 5fbbabe71a..38204daf4b 100644
---
a/backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala
+++
b/backends-velox/src/test/scala/org/apache/gluten/functions/ScalarFunctionsValidateSuite.scala
@@ -1156,6 +1156,25 @@ abstract class ScalarFunctionsValidateSuite extends
FunctionsValidateSuite {
runQueryAndCompare("select cast('123.0' AS INT)") {
checkGlutenOperatorMatch[ProjectExecTransformer]
}
+ // Cast Array as Array[String]
+ runQueryAndCompare("select cast(array(1, null) AS array<string>)") {
+ checkGlutenOperatorMatch[ProjectExecTransformer]
+ }
+ runQueryAndCompare("select cast(array(1L, null) AS array<string>)") {
+ checkGlutenOperatorMatch[ProjectExecTransformer]
+ }
+ runQueryAndCompare("select cast(array(1.1d, null) AS array<string>)") {
+ checkGlutenOperatorMatch[ProjectExecTransformer]
+ }
+ runQueryAndCompare("select cast(array(false, null) AS array<string>)") {
+ checkGlutenOperatorMatch[ProjectExecTransformer]
+ }
+ runQueryAndCompare("select cast(array(date'2024-01-01') AS
array<string>)") {
+ checkGlutenOperatorMatch[ProjectExecTransformer]
+ }
+ runQueryAndCompare("select cast(array(timestamp'2024-01-01 12:00:00') AS
array<string>)") {
+ checkGlutenOperatorMatch[ProjectExecTransformer]
+ }
}
testWithMinSparkVersion("equal_null", "3.4") {
diff --git a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
index 5a73132f2f..ebc0a0675b 100644
--- a/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
+++ b/cpp/velox/substrait/SubstraitToVeloxPlanValidator.cc
@@ -239,7 +239,8 @@ bool isSupportedArrayCast(const TypePtr& fromType, const
TypePtr& toType) {
// https://github.com/apache/incubator-gluten/issues/9392
// is currently WIP to add support for other types.
if (toType->isVarchar()) {
- return fromType->isDouble() || fromType->isBoolean() ||
fromType->isTimestamp();
+ return fromType->isDouble() || fromType->isBoolean() ||
fromType->isTimestamp()
+ || fromType->isInteger() || fromType->isBigint() || fromType->isDate();
}
if (toType->isDouble()) {
diff --git
a/gluten-ut/spark32/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
b/gluten-ut/spark32/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
index d3d5f8f923..c65e7dc54c 100644
---
a/gluten-ut/spark32/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
+++
b/gluten-ut/spark32/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
@@ -609,11 +609,6 @@ class ClickHouseTestSettings extends BackendTestSettings {
.exclude("SPARK-34727: cast from float II")
.exclude("SPARK-35720: cast invalid string input to timestamp without time
zone")
.exclude("Cast should output null for invalid strings when ANSI is not
enabled.")
- .exclude("cast array element from integer to string")
- .exclude("cast array element from double to string")
- .exclude("cast array element from bool to string")
- .exclude("cast array element from date to string")
- .exclude("cast array from timestamp to string")
.exclude("cast from boolean to timestamp")
enableSuite[GlutenCastSuiteWithAnsiModeOn]
.exclude("null cast")
diff --git
a/gluten-ut/spark32/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
b/gluten-ut/spark32/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
index a7caf79331..05ef3a3686 100644
---
a/gluten-ut/spark32/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
+++
b/gluten-ut/spark32/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
@@ -43,69 +43,6 @@ class GlutenCastSuite extends CastSuite with
GlutenTestsTrait {
UDTRegistration.register(classOf[IExampleBaseType].getName,
classOf[ExampleBaseTypeUDT].getName)
UDTRegistration.register(classOf[IExampleSubType].getName,
classOf[ExampleSubTypeUDT].getName)
- test("cast array element from integer to string") {
- val inputWithNull = Literal.create(Seq(1, null, 3), ArrayType(IntegerType))
- val expectedWithNull = Seq("1", null, "3")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val emptyInput = Literal.create(Seq.empty[Int], ArrayType(IntegerType))
- val expectedEmpty = Seq.empty[String]
- checkEvaluation(cast(emptyInput, ArrayType(StringType)), expectedEmpty)
-
- val inputNegative = Literal.create(Seq(-1, 0, 999999),
ArrayType(IntegerType))
- val expectedNegative = Seq("-1", "0", "999999")
- checkEvaluation(cast(inputNegative, ArrayType(StringType)),
expectedNegative)
- }
-
- test("cast array element from double to string") {
- val inputWithNull = Literal.create(Seq(1.1, null, 3.3),
ArrayType(DoubleType))
- val expectedWithNull = Seq("1.1", null, "3.3")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val inputScientific = Literal.create(Seq(1.23e4, -5.67e-3),
ArrayType(DoubleType))
- val expectedScientific = Seq("12300.0", "-0.00567")
- checkEvaluation(cast(inputScientific, ArrayType(StringType)),
expectedScientific)
- }
-
- test("cast array element from bool to string") {
- val inputWithNull = Literal.create(Seq(true, null, false),
ArrayType(BooleanType))
- val expectedWithNull = Seq("true", null, "false")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val emptyInput = Literal.create(Seq.empty[Boolean], ArrayType(BooleanType))
- val expectedEmpty = Seq.empty[String]
- checkEvaluation(cast(emptyInput, ArrayType(StringType)), expectedEmpty)
- }
-
- test("cast array element from date to string") {
- val inputWithNull = Literal.create(
- Seq(Date.valueOf("2024-01-01"), null, Date.valueOf("2024-01-03")),
- ArrayType(DateType)
- )
- val expectedWithNull = Seq("2024-01-01", null, "2024-01-03")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val inputLeapYear = Literal.create(
- Seq(Date.valueOf("2020-02-29")),
- ArrayType(DateType)
- )
- val expectedLeapYear = Seq("2020-02-29")
- checkEvaluation(cast(inputLeapYear, ArrayType(StringType)),
expectedLeapYear)
- }
-
- test("cast array from timestamp to string") {
- val inputWithNull = Literal.create(
- Seq(Timestamp.valueOf("2023-01-01 12:00:00"), null,
Timestamp.valueOf("2023-12-31 23:59:59")),
- ArrayType(TimestampType)
- )
- val expectedWithNull = Seq("2023-01-01 12:00:00", null, "2023-12-31
23:59:59")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val emptyInput = Literal.create(Seq.empty[Timestamp],
ArrayType(TimestampType))
- val expectedEmpty = Seq.empty[String]
- checkEvaluation(cast(emptyInput, ArrayType(StringType)), expectedEmpty)
- }
-
testGluten("missing cases - from boolean") {
(DataTypeTestUtils.numericTypeWithoutDecimal + BooleanType).foreach {
t =>
@@ -158,10 +95,19 @@ class GlutenCastSuite extends CastSuite with
GlutenTestsTrait {
Seq(Timestamp.valueOf("2023-01-01 12:00:00"), null),
ArrayType(TimestampType)
)
+ val integerArray = Literal.create(Seq(1, null, 2), ArrayType(IntegerType))
+ val longArray = Literal.create(Seq(1L, null, 2L), ArrayType(LongType))
+ val dateArray = Literal.create(
+ Seq(Date.valueOf("2024-01-01"), null, Date.valueOf("2024-01-03")),
+ ArrayType(DateType)
+ )
checkEvaluation(cast(doubleArray, ArrayType(StringType)), Seq("1.1", null,
"3.3"))
checkEvaluation(cast(boolArray, ArrayType(StringType)), Seq("true",
"false"))
checkEvaluation(cast(timestampArray, ArrayType(StringType)),
Seq("2023-01-01 12:00:00", null))
+ checkEvaluation(cast(integerArray, ArrayType(StringType)), Seq("1", null,
"2"))
+ checkEvaluation(cast(longArray, ArrayType(StringType)), Seq("1", null,
"2"))
+ checkEvaluation(cast(dateArray, ArrayType(StringType)), Seq("2024-01-01",
null, "2024-01-03"))
}
test("cast array of numeric types to array of boolean") {
diff --git
a/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
b/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
index 04f4b3baa3..36669039f1 100644
---
a/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
+++
b/gluten-ut/spark33/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
@@ -629,11 +629,6 @@ class ClickHouseTestSettings extends BackendTestSettings {
.exclude("SPARK-36924: Cast IntegralType to YearMonthIntervalType")
.exclude("Cast should output null for invalid strings when ANSI is not
enabled.")
.exclude("cast timestamp to Int64 with floor division")
- .exclude("cast array element from integer to string")
- .exclude("cast array element from double to string")
- .exclude("cast array element from bool to string")
- .exclude("cast array element from date to string")
- .exclude("cast array from timestamp to string")
.exclude("cast from boolean to timestamp")
enableSuite[GlutenCastSuiteWithAnsiModeOn]
.exclude("null cast")
diff --git
a/gluten-ut/spark33/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
b/gluten-ut/spark33/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
index 197b4f08c9..407e3e5ef4 100644
---
a/gluten-ut/spark33/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
+++
b/gluten-ut/spark33/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
@@ -43,69 +43,6 @@ class GlutenCastSuite extends CastSuite with
GlutenTestsTrait {
UDTRegistration.register(classOf[IExampleBaseType].getName,
classOf[ExampleBaseTypeUDT].getName)
UDTRegistration.register(classOf[IExampleSubType].getName,
classOf[ExampleSubTypeUDT].getName)
- test("cast array element from integer to string") {
- val inputWithNull = Literal.create(Seq(1, null, 3), ArrayType(IntegerType))
- val expectedWithNull = Seq("1", null, "3")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val emptyInput = Literal.create(Seq.empty[Int], ArrayType(IntegerType))
- val expectedEmpty = Seq.empty[String]
- checkEvaluation(cast(emptyInput, ArrayType(StringType)), expectedEmpty)
-
- val inputNegative = Literal.create(Seq(-1, 0, 999999),
ArrayType(IntegerType))
- val expectedNegative = Seq("-1", "0", "999999")
- checkEvaluation(cast(inputNegative, ArrayType(StringType)),
expectedNegative)
- }
-
- test("cast array element from double to string") {
- val inputWithNull = Literal.create(Seq(1.1, null, 3.3),
ArrayType(DoubleType))
- val expectedWithNull = Seq("1.1", null, "3.3")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val inputScientific = Literal.create(Seq(1.23e4, -5.67e-3),
ArrayType(DoubleType))
- val expectedScientific = Seq("12300.0", "-0.00567")
- checkEvaluation(cast(inputScientific, ArrayType(StringType)),
expectedScientific)
- }
-
- test("cast array element from bool to string") {
- val inputWithNull = Literal.create(Seq(true, null, false),
ArrayType(BooleanType))
- val expectedWithNull = Seq("true", null, "false")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val emptyInput = Literal.create(Seq.empty[Boolean], ArrayType(BooleanType))
- val expectedEmpty = Seq.empty[String]
- checkEvaluation(cast(emptyInput, ArrayType(StringType)), expectedEmpty)
- }
-
- test("cast array element from date to string") {
- val inputWithNull = Literal.create(
- Seq(Date.valueOf("2024-01-01"), null, Date.valueOf("2024-01-03")),
- ArrayType(DateType)
- )
- val expectedWithNull = Seq("2024-01-01", null, "2024-01-03")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val inputLeapYear = Literal.create(
- Seq(Date.valueOf("2020-02-29")), // Leap day
- ArrayType(DateType)
- )
- val expectedLeapYear = Seq("2020-02-29")
- checkEvaluation(cast(inputLeapYear, ArrayType(StringType)),
expectedLeapYear)
- }
-
- test("cast array from timestamp to string") {
- val inputWithNull = Literal.create(
- Seq(Timestamp.valueOf("2023-01-01 12:00:00"), null,
Timestamp.valueOf("2023-12-31 23:59:59")),
- ArrayType(TimestampType)
- )
- val expectedWithNull = Seq("2023-01-01 12:00:00", null, "2023-12-31
23:59:59")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val emptyInput = Literal.create(Seq.empty[Timestamp],
ArrayType(TimestampType))
- val expectedEmpty = Seq.empty[String]
- checkEvaluation(cast(emptyInput, ArrayType(StringType)), expectedEmpty)
- }
-
test("cast array of integer types to array of double") {
val intArray = Literal.create(Seq(1, 2, 3), ArrayType(IntegerType))
val bigintArray = Literal.create(Seq(10000000000L), ArrayType(LongType))
@@ -134,10 +71,19 @@ class GlutenCastSuite extends CastSuite with
GlutenTestsTrait {
Seq(Timestamp.valueOf("2023-01-01 12:00:00"), null),
ArrayType(TimestampType)
)
+ val integerArray = Literal.create(Seq(1, null, 2), ArrayType(IntegerType))
+ val longArray = Literal.create(Seq(1L, null, 2L), ArrayType(LongType))
+ val dateArray = Literal.create(
+ Seq(Date.valueOf("2024-01-01"), null, Date.valueOf("2024-01-03")),
+ ArrayType(DateType)
+ )
checkEvaluation(cast(doubleArray, ArrayType(StringType)), Seq("1.1", null,
"3.3"))
checkEvaluation(cast(boolArray, ArrayType(StringType)), Seq("true",
"false"))
checkEvaluation(cast(timestampArray, ArrayType(StringType)),
Seq("2023-01-01 12:00:00", null))
+ checkEvaluation(cast(integerArray, ArrayType(StringType)), Seq("1", null,
"2"))
+ checkEvaluation(cast(longArray, ArrayType(StringType)), Seq("1", null,
"2"))
+ checkEvaluation(cast(dateArray, ArrayType(StringType)), Seq("2024-01-01",
null, "2024-01-03"))
}
test("cast array of numeric types to array of boolean") {
diff --git
a/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
b/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
index 7ccf68e9e0..7e9737d9a3 100644
---
a/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
+++
b/gluten-ut/spark34/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
@@ -567,11 +567,6 @@ class ClickHouseTestSettings extends BackendTestSettings {
.exclude("SPARK-36924: Cast IntegralType to DayTimeIntervalType")
.exclude("SPARK-36924: Cast YearMonthIntervalType to IntegralType")
.exclude("SPARK-36924: Cast IntegralType to YearMonthIntervalType")
- .exclude("cast array element from integer to string")
- .exclude("cast array element from double to string")
- .exclude("cast array element from bool to string")
- .exclude("cast array element from date to string")
- .exclude("cast array from timestamp to string")
.exclude("cast from boolean to timestamp")
enableSuite[GlutenCollectionExpressionsSuite]
.exclude("ArraysZip") // wait for
https://github.com/ClickHouse/ClickHouse/pull/69576
diff --git
a/gluten-ut/spark34/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
b/gluten-ut/spark34/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
index eb347ffe9f..493a47c56b 100644
---
a/gluten-ut/spark34/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
+++
b/gluten-ut/spark34/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
@@ -44,56 +44,6 @@ class GlutenCastSuite extends CastWithAnsiOffSuite with
GlutenTestsTrait {
UDTRegistration.register(classOf[IExampleBaseType].getName,
classOf[ExampleBaseTypeUDT].getName)
UDTRegistration.register(classOf[IExampleSubType].getName,
classOf[ExampleSubTypeUDT].getName)
- test("cast array element from integer to string") {
- val inputWithNull = Literal.create(Seq(1, null, 3), ArrayType(IntegerType))
- val expectedWithNull = Seq("1", null, "3")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val emptyInput = Literal.create(Seq.empty[Int], ArrayType(IntegerType))
- val expectedEmpty = Seq.empty[String]
- checkEvaluation(cast(emptyInput, ArrayType(StringType)), expectedEmpty)
-
- val inputNegative = Literal.create(Seq(-1, 0, 999999),
ArrayType(IntegerType))
- val expectedNegative = Seq("-1", "0", "999999")
- checkEvaluation(cast(inputNegative, ArrayType(StringType)),
expectedNegative)
- }
-
- test("cast array element from double to string") {
- val inputWithNull = Literal.create(Seq(1.1, null, 3.3),
ArrayType(DoubleType))
- val expectedWithNull = Seq("1.1", null, "3.3")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val inputScientific = Literal.create(Seq(1.23e4, -5.67e-3),
ArrayType(DoubleType))
- val expectedScientific = Seq("12300.0", "-0.00567")
- checkEvaluation(cast(inputScientific, ArrayType(StringType)),
expectedScientific)
- }
-
- test("cast array element from bool to string") {
- val inputWithNull = Literal.create(Seq(true, null, false),
ArrayType(BooleanType))
- val expectedWithNull = Seq("true", null, "false")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val emptyInput = Literal.create(Seq.empty[Boolean], ArrayType(BooleanType))
- val expectedEmpty = Seq.empty[String]
- checkEvaluation(cast(emptyInput, ArrayType(StringType)), expectedEmpty)
- }
-
- test("cast array element from date to string") {
- val inputWithNull = Literal.create(
- Seq(Date.valueOf("2024-01-01"), null, Date.valueOf("2024-01-03")),
- ArrayType(DateType)
- )
- val expectedWithNull = Seq("2024-01-01", null, "2024-01-03")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val inputLeapYear = Literal.create(
- Seq(Date.valueOf("2020-02-29")),
- ArrayType(DateType)
- )
- val expectedLeapYear = Seq("2020-02-29")
- checkEvaluation(cast(inputLeapYear, ArrayType(StringType)),
expectedLeapYear)
- }
-
testGluten("missing cases - from boolean") {
(DataTypeTestUtils.numericTypeWithoutDecimal + BooleanType).foreach {
case t @ BooleanType =>
@@ -105,19 +55,6 @@ class GlutenCastSuite extends CastWithAnsiOffSuite with
GlutenTestsTrait {
}
}
- test("cast array from timestamp to string") {
- val inputWithNull = Literal.create(
- Seq(Timestamp.valueOf("2023-01-01 12:00:00"), null,
Timestamp.valueOf("2023-12-31 23:59:59")),
- ArrayType(TimestampType)
- )
- val expectedWithNull = Seq("2023-01-01 12:00:00", null, "2023-12-31
23:59:59")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val emptyInput = Literal.create(Seq.empty[Timestamp],
ArrayType(TimestampType))
- val expectedEmpty = Seq.empty[String]
- checkEvaluation(cast(emptyInput, ArrayType(StringType)), expectedEmpty)
- }
-
test("cast array of integer types to array of double") {
val intArray = Literal.create(Seq(1, 2, 3), ArrayType(IntegerType))
val bigintArray = Literal.create(Seq(10000000000L), ArrayType(LongType))
@@ -146,10 +83,19 @@ class GlutenCastSuite extends CastWithAnsiOffSuite with
GlutenTestsTrait {
Seq(Timestamp.valueOf("2023-01-01 12:00:00"), null),
ArrayType(TimestampType)
)
+ val integerArray = Literal.create(Seq(1, null, 2), ArrayType(IntegerType))
+ val longArray = Literal.create(Seq(1L, null, 2L), ArrayType(LongType))
+ val dateArray = Literal.create(
+ Seq(Date.valueOf("2024-01-01"), null, Date.valueOf("2024-01-03")),
+ ArrayType(DateType)
+ )
checkEvaluation(cast(doubleArray, ArrayType(StringType)), Seq("1.1", null,
"3.3"))
checkEvaluation(cast(boolArray, ArrayType(StringType)), Seq("true",
"false"))
checkEvaluation(cast(timestampArray, ArrayType(StringType)),
Seq("2023-01-01 12:00:00", null))
+ checkEvaluation(cast(integerArray, ArrayType(StringType)), Seq("1", null,
"2"))
+ checkEvaluation(cast(longArray, ArrayType(StringType)), Seq("1", null,
"2"))
+ checkEvaluation(cast(dateArray, ArrayType(StringType)), Seq("2024-01-01",
null, "2024-01-03"))
}
test("cast array of numeric types to array of boolean") {
diff --git
a/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
b/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
index dade07afff..71a83451d3 100644
---
a/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
+++
b/gluten-ut/spark35/src/test/scala/org/apache/gluten/utils/clickhouse/ClickHouseTestSettings.scala
@@ -382,11 +382,6 @@ class ClickHouseTestSettings extends BackendTestSettings {
.exclude("SPARK-39749: cast Decimal to string")
.exclude("SPARK-42176: cast boolean to timestamp")
.exclude("null cast #2")
- .exclude("cast array element from integer to string")
- .exclude("cast array element from double to string")
- .exclude("cast array element from bool to string")
- .exclude("cast array element from date to string")
- .exclude("cast array from timestamp to string")
.exclude("cast from boolean to timestamp")
enableSuite[GlutenCoalesceShufflePartitionsSuite]
.excludeByPrefix("determining the number of reducers")
diff --git
a/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
b/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
index bc086696a4..4332f704ef 100644
---
a/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
+++
b/gluten-ut/spark35/src/test/scala/org/apache/spark/sql/catalyst/expressions/GlutenCastSuite.scala
@@ -44,69 +44,6 @@ class GlutenCastSuite extends CastWithAnsiOffSuite with
GlutenTestsTrait {
UDTRegistration.register(classOf[IExampleBaseType].getName,
classOf[ExampleBaseTypeUDT].getName)
UDTRegistration.register(classOf[IExampleSubType].getName,
classOf[ExampleSubTypeUDT].getName)
- test("cast array element from integer to string") {
- val inputWithNull = Literal.create(Seq(1, null, 3), ArrayType(IntegerType))
- val expectedWithNull = Seq("1", null, "3")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val emptyInput = Literal.create(Seq.empty[Int], ArrayType(IntegerType))
- val expectedEmpty = Seq.empty[String]
- checkEvaluation(cast(emptyInput, ArrayType(StringType)), expectedEmpty)
-
- val inputNegative = Literal.create(Seq(-1, 0, 999999),
ArrayType(IntegerType))
- val expectedNegative = Seq("-1", "0", "999999")
- checkEvaluation(cast(inputNegative, ArrayType(StringType)),
expectedNegative)
- }
-
- test("cast array element from double to string") {
- val inputWithNull = Literal.create(Seq(1.1, null, 3.3),
ArrayType(DoubleType))
- val expectedWithNull = Seq("1.1", null, "3.3")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val inputScientific = Literal.create(Seq(1.23e4, -5.67e-3),
ArrayType(DoubleType))
- val expectedScientific = Seq("12300.0", "-0.00567")
- checkEvaluation(cast(inputScientific, ArrayType(StringType)),
expectedScientific)
- }
-
- test("cast array element from bool to string") {
- val inputWithNull = Literal.create(Seq(true, null, false),
ArrayType(BooleanType))
- val expectedWithNull = Seq("true", null, "false")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val emptyInput = Literal.create(Seq.empty[Boolean], ArrayType(BooleanType))
- val expectedEmpty = Seq.empty[String]
- checkEvaluation(cast(emptyInput, ArrayType(StringType)), expectedEmpty)
- }
-
- test("cast array element from date to string") {
- val inputWithNull = Literal.create(
- Seq(Date.valueOf("2024-01-01"), null, Date.valueOf("2024-01-03")),
- ArrayType(DateType)
- )
- val expectedWithNull = Seq("2024-01-01", null, "2024-01-03")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val inputLeapYear = Literal.create(
- Seq(Date.valueOf("2020-02-29")),
- ArrayType(DateType)
- )
- val expectedLeapYear = Seq("2020-02-29")
- checkEvaluation(cast(inputLeapYear, ArrayType(StringType)),
expectedLeapYear)
- }
-
- test("cast array from timestamp to string") {
- val inputWithNull = Literal.create(
- Seq(Timestamp.valueOf("2023-01-01 12:00:00"), null,
Timestamp.valueOf("2023-12-31 23:59:59")),
- ArrayType(TimestampType)
- )
- val expectedWithNull = Seq("2023-01-01 12:00:00", null, "2023-12-31
23:59:59")
- checkEvaluation(cast(inputWithNull, ArrayType(StringType)),
expectedWithNull)
-
- val emptyInput = Literal.create(Seq.empty[Timestamp],
ArrayType(TimestampType))
- val expectedEmpty = Seq.empty[String]
- checkEvaluation(cast(emptyInput, ArrayType(StringType)), expectedEmpty)
- }
-
test("cast array of integer types to array of double") {
val intArray = Literal.create(Seq(1, 2, 3), ArrayType(IntegerType))
val bigintArray = Literal.create(Seq(10000000000L), ArrayType(LongType))
@@ -135,10 +72,19 @@ class GlutenCastSuite extends CastWithAnsiOffSuite with
GlutenTestsTrait {
Seq(Timestamp.valueOf("2023-01-01 12:00:00"), null),
ArrayType(TimestampType)
)
+ val integerArray = Literal.create(Seq(1, null, 2), ArrayType(IntegerType))
+ val longArray = Literal.create(Seq(1L, null, 2L), ArrayType(LongType))
+ val dateArray = Literal.create(
+ Seq(Date.valueOf("2024-01-01"), null, Date.valueOf("2024-01-03")),
+ ArrayType(DateType)
+ )
checkEvaluation(cast(doubleArray, ArrayType(StringType)), Seq("1.1", null,
"3.3"))
checkEvaluation(cast(boolArray, ArrayType(StringType)), Seq("true",
"false"))
checkEvaluation(cast(timestampArray, ArrayType(StringType)),
Seq("2023-01-01 12:00:00", null))
+ checkEvaluation(cast(integerArray, ArrayType(StringType)), Seq("1", null,
"2"))
+ checkEvaluation(cast(longArray, ArrayType(StringType)), Seq("1", null,
"2"))
+ checkEvaluation(cast(dateArray, ArrayType(StringType)), Seq("2024-01-01",
null, "2024-01-03"))
}
test("cast array of numeric types to array of boolean") {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]