Skip to content

Commit 9fe5420

Browse files
fix: disable initCap by default (#1276)
* fix: disable initCap by default * Update spark/src/main/scala/org/apache/comet/serde/QueryPlanSerde.scala Co-authored-by: Andy Grove <[email protected]> * address review comments --------- Co-authored-by: Andy Grove <[email protected]>
1 parent 1eb932a commit 9fe5420

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

common/src/main/scala/org/apache/comet/CometConf.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ object CometConf extends ShimCometConf {
189189
createExecEnabledConfig("window", defaultValue = true)
190190
val COMET_EXEC_TAKE_ORDERED_AND_PROJECT_ENABLED: ConfigEntry[Boolean] =
191191
createExecEnabledConfig("takeOrderedAndProject", defaultValue = true)
192+
val COMET_EXEC_INITCAP_ENABLED: ConfigEntry[Boolean] =
193+
createExecEnabledConfig("initCap", defaultValue = false)
192194

193195
val COMET_EXEC_SORT_MERGE_JOIN_WITH_JOIN_FILTER_ENABLED: ConfigEntry[Boolean] =
194196
conf("spark.comet.exec.sortMergeJoinWithJoinFilter.enabled")

docs/source/user-guide/configs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Comet provides the following configuration settings.
4646
| spark.comet.exec.filter.enabled | Whether to enable filter by default. | true |
4747
| spark.comet.exec.globalLimit.enabled | Whether to enable globalLimit by default. | true |
4848
| spark.comet.exec.hashJoin.enabled | Whether to enable hashJoin by default. | true |
49+
| spark.comet.exec.initCap.enabled | Whether to enable initCap by default. | false |
4950
| spark.comet.exec.localLimit.enabled | Whether to enable localLimit by default. | true |
5051
| spark.comet.exec.memoryPool | The type of memory pool to be used for Comet native execution. Available memory pool types are 'greedy', 'fair_spill', 'greedy_task_shared', 'fair_spill_task_shared', 'greedy_global' and 'fair_spill_global', By default, this config is 'greedy_task_shared'. | greedy_task_shared |
5152
| spark.comet.exec.project.enabled | Whether to enable project by default. | true |

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,10 +1795,19 @@ object QueryPlanSerde extends Logging with ShimQueryPlanSerde with CometExprShim
17951795
optExprWithInfo(optExpr, expr, child)
17961796

17971797
case InitCap(child) =>
1798-
val castExpr = Cast(child, StringType)
1799-
val childExpr = exprToProtoInternal(castExpr, inputs)
1800-
val optExpr = scalarExprToProto("initcap", childExpr)
1801-
optExprWithInfo(optExpr, expr, castExpr)
1798+
if (CometConf.COMET_EXEC_INITCAP_ENABLED.get()) {
1799+
val castExpr = Cast(child, StringType)
1800+
val childExpr = exprToProtoInternal(castExpr, inputs)
1801+
val optExpr = scalarExprToProto("initcap", childExpr)
1802+
optExprWithInfo(optExpr, expr, castExpr)
1803+
} else {
1804+
withInfo(
1805+
expr,
1806+
"Comet initCap is not compatible with Spark yet. " +
1807+
"See https://github.com/apache/datafusion-comet/issues/1052 ." +
1808+
s"Set ${CometConf.COMET_EXEC_INITCAP_ENABLED.key}=true to enable it anyway.")
1809+
None
1810+
}
18021811

18031812
case Length(child) =>
18041813
val castExpr = Cast(child, StringType)

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,8 +1364,14 @@ class CometExpressionSuite extends CometTestBase with AdaptiveSparkPlanHelper {
13641364
sql(s"create table $table(id int, name varchar(20)) using parquet")
13651365
sql(
13661366
s"insert into $table values(1, 'james smith'), (2, 'michael rose'), " +
1367-
"(3, 'robert williams'), (4, 'rames rose'), (5, 'james smith')")
1368-
checkSparkAnswerAndOperator(s"SELECT initcap(name) FROM $table")
1367+
"(3, 'robert williams'), (4, 'rames rose'), (5, 'james smith'), " +
1368+
"(6, 'robert rose-smith'), (7, 'james ähtäri')")
1369+
if (CometConf.COMET_EXEC_INITCAP_ENABLED.get()) {
1370+
// TODO: remove this if clause https://github.com/apache/datafusion-comet/issues/1052
1371+
checkSparkAnswerAndOperator(s"SELECT initcap(name) FROM $table")
1372+
} else {
1373+
checkSparkAnswer(s"SELECT initcap(name) FROM $table")
1374+
}
13691375
}
13701376
}
13711377
}

0 commit comments

Comments
 (0)