Skip to content

Commit f4c72fd

Browse files
authored
chore: Improve Initcap test and docs (#2387)
1 parent d9c2b3a commit f4c72fd

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

docs/source/user-guide/latest/expressions.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ natively in Comet and provide the same results as Spark, or will fall back to Sp
2424
be compatible.
2525

2626
All expressions are enabled by default, but can be disabled by setting
27-
`spark.comet.expression.EXPRNAME.enabled=false`, where `EXPRNAME` is the expression name as specified in
27+
`spark.comet.expression.EXPRNAME.enabled=false`, where `EXPRNAME` is the expression name as specified in
2828
the following tables, such as `Length`, or `StartsWith`.
2929

3030
Expressions that are not Spark-compatible will fall back to Spark by default and can be enabled by setting
3131
`spark.comet.expression.EXPRNAME.allowIncompatible=true`.
3232

33-
It is also possible to specify `spark.comet.expression.allowIncompatible=true` to enable all
33+
It is also possible to specify `spark.comet.expression.allowIncompatible=true` to enable all
3434
incompatible expressions.
3535

3636
## Conditional Expressions
@@ -68,7 +68,7 @@ incompatible expressions.
6868
| ConcatWs | Yes | |
6969
| Contains | Yes | |
7070
| EndsWith | Yes | |
71-
| InitCap | No | Requires `spark.comet.exec.initCap.enabled=true` |
71+
| InitCap | No | Behavior is different in some cases, such as hyphenated names. |
7272
| Length | Yes | |
7373
| Like | Yes | |
7474
| Lower | No | Results can vary depending on locale and character set. Requires `spark.comet.caseConversion.enabled=true` |

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,26 @@ class CometStringExpressionSuite extends CometTestBase {
9595
}
9696
}
9797

98-
test("InitCap") {
98+
test("InitCap compatible cases") {
9999
val table = "names"
100100
withTable(table) {
101101
sql(s"create table $table(id int, name varchar(20)) using parquet")
102-
sql(
103-
s"insert into $table values(1, 'james smith'), (2, 'michael rose'), " +
104-
"(3, 'robert williams'), (4, 'rames rose'), (5, 'james smith'), " +
105-
"(6, 'robert rose-smith'), (7, 'james ähtäri')")
102+
withSQLConf(CometConf.getExprAllowIncompatConfigKey("InitCap") -> "true") {
103+
sql(
104+
s"insert into $table values(1, 'james smith'), (2, 'michael rose'), " +
105+
"(3, 'robert williams'), (4, 'rames rose'), (5, 'james smith'), " +
106+
"(7, 'james ähtäri')")
107+
checkSparkAnswerAndOperator(s"SELECT initcap(name) FROM $table")
108+
}
109+
}
110+
}
111+
112+
test("InitCap incompatible cases") {
113+
val table = "names"
114+
withTable(table) {
115+
sql(s"create table $table(id int, name varchar(20)) using parquet")
116+
// Comet and Spark differ on hyphenated names
117+
sql(s"insert into $table values(6, 'robert rose-smith')")
106118
checkSparkAnswer(s"SELECT initcap(name) FROM $table")
107119
}
108120
}

0 commit comments

Comments
 (0)