Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
remove one function in Expression
  • Loading branch information
Eric5553 committed Apr 9, 2020
commit c7daaa6543a51dbd83d56b56030d0d0b4755cb56
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,20 @@ abstract class Expression extends TreeNode[Expression] {
case single => single :: Nil
}

protected def flatArgumentStrings: Iterator[String] = flatArguments.map {
case e: Expression => e.argumentString
case arg => s"$arg"
}

// Marks this as final, Expression.verboseString should never be called, and thus shouldn't be
// overridden by concrete classes.
final override def verboseString(maxFields: Int): String = simpleString(maxFields)

override def simpleString(maxFields: Int): String = toString

override def toString: String = prettyName + truncatedString(
flatArgumentStrings.toSeq, "(", ", ", ")", SQLConf.get.maxToStringFields)
override def toString: String = {
val argumentStrings = flatArguments.map {
case e: Expression => e.argumentString
case arg => s"$arg"
}
prettyName + truncatedString(
argumentStrings.toSeq, "(", ", ", ")", SQLConf.get.maxToStringFields)
}

def argumentString: String = toString
Copy link
Contributor

@cloud-fan cloud-fan Mar 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it possible to only add one method? I'm worried about adding to many methods to the framework.

Copy link
Contributor Author

@Eric5553 Eric5553 Mar 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, the argumentString is needed because AttributeReference already overwrite toString, thus we need the new abstract string function to switch to non-exprid format. For flatArgumentStrings, it only have two callers. I refactored the toAggString of AggregateFunction, then we don't need to add the method flatArgumentStrings in Expression but just implement it within toString. See commit b74c500.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ abstract class AggregateFunction extends Expression {

/** String representation used in explain plans. */
def toAggString(isDistinct: Boolean): String = {
val start = if (isDistinct) "(distinct " else "("
prettyName + flatArgumentStrings.mkString(start, ", ", ")")
if (isDistinct) {
toString.patch(prettyName.size + 1, "distinct ", 0)
} else {
toString
}
}
}

Expand Down