Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,16 @@ abstract class Expression extends TreeNode[Expression] {

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

override def toString: String = prettyName + truncatedString(
flatArguments.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.


/**
* Returns SQL representation of this expression. For expressions extending [[NonSQLExpression]],
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 + flatArguments.mkString(start, ", ", ")")
if (isDistinct) {
toString.patch(prettyName.size + 1, "distinct ", 0)
} else {
toString
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,15 @@ case class AttributeReference(

override def toString: String = s"$name#${exprId.id}$typeSuffix$delaySuffix"

override def argumentString: String = {
val endingMsg = s"$typeSuffix$delaySuffix"
if (endingMsg.nonEmpty) {
s"${name}#$endingMsg"
} else {
name
}
}

// Since the expression id is not in the first constructor it is missing from the default
// tree string.
override def simpleString(maxFields: Int): String = {
Expand Down
Loading