kelvinjian-db commented on code in PR #45871:
URL: https://github.com/apache/spark/pull/45871#discussion_r1551053861


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Between.scala:
##########
@@ -36,13 +38,17 @@ package org.apache.spark.sql.catalyst.expressions
 case class Between private(input: Expression, lower: Expression, upper: 
Expression, replacement: Expression)
   extends RuntimeReplaceable with InheritAnalysisRules  {
   def this(input: Expression, lower: Expression, upper: Expression) = {
-    this(input, lower, upper, {
-      val commonExpr = CommonExpressionDef(input)
-      val ref = new CommonExpressionRef(commonExpr)
-      val replacement = And(GreaterThanOrEqual(ref, lower), 
LessThanOrEqual(ref, upper))
-      With(replacement, Seq(commonExpr))
-    })
-  };
+    this(input, lower, upper,
+      if (!SQLConf.get.getConf(SQLConf.ALWAYS_INLINE_COMMON_EXPR_IN_WITH)) {
+        val commonExpr = CommonExpressionDef(input)
+        val ref = new CommonExpressionRef(commonExpr)
+        val replacement = And(GreaterThanOrEqual(ref, lower), 
LessThanOrEqual(ref, upper))
+        With(replacement, Seq(commonExpr))

Review Comment:
   nit: we can use the `With.apply()` to make this more concise?
   
   ```
   With(input) { case Seq(ref) =>
     And(GreaterThanOrEqual(ref, lower), LessThanOrEqual(ref, upper))
   }
   ```



##########
sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala:
##########
@@ -3390,13 +3390,13 @@ object SQLConf {
       .booleanConf
       .createWithDefault(true)
 
-  val REPLACE_NULLIF_USING_WITH_EXPR =
-    buildConf("spark.databricks.sql.replaceNullIfUsingWithExpr")
+  val ALWAYS_INLINE_COMMON_EXPR_IN_WITH =
+    buildConf("spark.sql.alwaysInlineCommonExprInWith")
       .internal()
-      .doc("When true, NullIf expressions are rewritten using With expressions 
to avoid " +
-        "expression duplication.")
+      .doc("When true, always inline common expressions inside WITH expression 
which may lead " +

Review Comment:
   when this config is true, we don't inline the common expressions IN the with 
expressions, rather we just inline the common expressions? should we remove 
"inside WITH expression"?



-- 
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]

Reply via email to