maropu commented on a change in pull request #28420:
URL: https://github.com/apache/spark/pull/28420#discussion_r418346518



##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
##########
@@ -323,6 +323,20 @@ trait RuntimeReplaceable extends UnaryExpression with 
Unevaluable {
   // two `RuntimeReplaceable` are considered to be semantically equal if their 
"child" expressions
   // are semantically equal.
   override lazy val canonicalized: Expression = child.canonicalized
+
+  override def innerChildren: Seq[Expression] = sys.error("RuntimeReplaceable 
must implement" +
+    " innerChildren with the original parameters")
+
+  protected val sqlStrSeparator: String = ", "

Review comment:
       We need this variable? It seems only `Extract` uses this.

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
##########
@@ -323,6 +323,20 @@ trait RuntimeReplaceable extends UnaryExpression with 
Unevaluable {
   // two `RuntimeReplaceable` are considered to be semantically equal if their 
"child" expressions
   // are semantically equal.
   override lazy val canonicalized: Expression = child.canonicalized
+
+  override def innerChildren: Seq[Expression] = sys.error("RuntimeReplaceable 
must implement" +

Review comment:
       Since compilers cannot catch the case where one forget to override this, 
how about it like this?
   ```
     // RuntimeReplaceable
     def exprsReplaced: Seq[Expression]
     override def innerChildren: Seq[Expression] = exprsReplaced
   
     // e.g., ParseToTimestamp
     override def exprsReplaced: Seq[Expression] = Seq(Some(left), 
format).flatten
   
   ```

##########
File path: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/Expression.scala
##########
@@ -323,6 +323,20 @@ trait RuntimeReplaceable extends UnaryExpression with 
Unevaluable {
   // two `RuntimeReplaceable` are considered to be semantically equal if their 
"child" expressions
   // are semantically equal.
   override lazy val canonicalized: Expression = child.canonicalized
+
+  override def innerChildren: Seq[Expression] = sys.error("RuntimeReplaceable 
must implement" +
+    " innerChildren with the original parameters")
+
+  protected val sqlStrSeparator: String = ", "
+
+  override def sql: String = RuntimeReplaceable.this.prettyName +
+    prettyChildren.map(_.sql).mkString("(", sqlStrSeparator, ")")
+
+  protected var prettyChildren: Seq[Expression] = innerChildren

Review comment:
       I think its better to user `var` where possible, so how about it like 
this?
   ```
     // RuntimeReplaceable
     def newInstance(innerChildren: Seq[Expression]): RuntimeReplaceable
   
     // e.g., ParseToTimestamp
     override def newInstance(innerChildren: Seq[Expression]): ParseToTimestamp 
= {
       innerChildren match {
         case Seq(left) => ParseToTimestamp(left, None, child)
         case Seq(left, format) => ParseToTimestamp(left, Some(format), child)
       }
     }
   ```
   Then, update the `toPrettySQL` in `utils.package`;
   ```
     def toPrettySQL(e: Expression): String = e match {
       case r: RuntimeReplaceable =>
         r.newInstance(r.innerChildren.map(usePrettyExpression)).sql
       case _ => usePrettyExpression(e).sql
     }
   ```




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

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