Skip to content

Commit

Permalink
Adding maxField parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxGekk committed Nov 27, 2018
1 parent 7562421 commit e9e7893
Show file tree
Hide file tree
Showing 41 changed files with 187 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ class Analyzer(
a.mapExpressions(resolve(_, appendColumns))

case q: LogicalPlan =>
logTrace(s"Attempting to resolve ${q.simpleString}")
logTrace(s"Attempting to resolve ${q.simpleString(SQLConf.get.maxToStringFields)}")
q.mapExpressions(resolve(_, q))
}

Expand Down Expand Up @@ -1742,7 +1742,7 @@ class Analyzer(

case p if p.expressions.exists(hasGenerator) =>
throw new AnalysisException("Generators are not supported outside the SELECT clause, but " +
"got: " + p.simpleString)
"got: " + p.simpleString((SQLConf.get.maxToStringFields)))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.apache.spark.sql.catalyst.expressions.aggregate.AggregateExpression
import org.apache.spark.sql.catalyst.optimizer.BooleanSimplification
import org.apache.spark.sql.catalyst.plans._
import org.apache.spark.sql.catalyst.plans.logical._
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._

/**
Expand Down Expand Up @@ -308,7 +309,7 @@ trait CheckAnalysis extends PredicateHelper {
val missingAttributes = o.missingInput.mkString(",")
val input = o.inputSet.mkString(",")
val msgForMissingAttributes = s"Resolved attribute(s) $missingAttributes missing " +
s"from $input in operator ${operator.simpleString}."
s"from $input in operator ${operator.simpleString((SQLConf.get.maxToStringFields))}."

val resolver = plan.conf.resolver
val attrsWithSameName = o.missingInput.filter { missing =>
Expand Down Expand Up @@ -373,7 +374,7 @@ trait CheckAnalysis extends PredicateHelper {
s"""nondeterministic expressions are only allowed in
|Project, Filter, Aggregate or Window, found:
| ${o.expressions.map(_.sql).mkString(",")}
|in operator ${operator.simpleString}
|in operator ${operator.simpleString((SQLConf.get.maxToStringFields))}
""".stripMargin)

case _: UnresolvedHint =>
Expand All @@ -385,7 +386,8 @@ trait CheckAnalysis extends PredicateHelper {
}
extendedCheckRules.foreach(_(plan))
plan.foreachUp {
case o if !o.resolved => failAnalysis(s"unresolved operator ${o.simpleString}")
case o if !o.resolved =>
failAnalysis(s"unresolved operator ${o.simpleString((SQLConf.get.maxToStringFields))}")
case _ =>
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1038,8 +1038,8 @@ trait TypeCoercionRule extends Rule[LogicalPlan] with Logging {
// Leave the same if the dataTypes match.
case Some(newType) if a.dataType == newType.dataType => a
case Some(newType) =>
logDebug(
s"Promoting $a from ${a.dataType} to ${newType.dataType} in ${q.simpleString}")
logDebug(s"Promoting $a from ${a.dataType} to ${newType.dataType} in " +
s" ${q.simpleString((SQLConf.get.maxToStringFields))}")
newType
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.apache.spark.sql.catalyst.expressions.codegen.{GenerateSafeProjection
import org.apache.spark.sql.catalyst.expressions.objects.{AssertNotNull, InitializeJavaBean, Invoke, NewInstance}
import org.apache.spark.sql.catalyst.optimizer.SimplifyCasts
import org.apache.spark.sql.catalyst.plans.logical.{CatalystSerde, DeserializeToObject, LocalRelation}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types.{ObjectType, StringType, StructField, StructType}
import org.apache.spark.unsafe.types.UTF8String
import org.apache.spark.util.Utils
Expand Down Expand Up @@ -323,8 +324,8 @@ case class ExpressionEncoder[T](
extractProjection(inputRow)
} catch {
case e: Exception =>
throw new RuntimeException(
s"Error while encoding: $e\n${serializer.map(_.simpleString).mkString("\n")}", e)
throw new RuntimeException(s"Error while encoding: $e\n" +
s"${serializer.map(_.simpleString(SQLConf.get.maxToStringFields)).mkString("\n")}", e)
}

/**
Expand All @@ -336,7 +337,8 @@ case class ExpressionEncoder[T](
constructProjection(row).get(0, ObjectType(clsTag.runtimeClass)).asInstanceOf[T]
} catch {
case e: Exception =>
throw new RuntimeException(s"Error while decoding: $e\n${deserializer.simpleString}", e)
throw new RuntimeException(s"Error while decoding: $e\n" +
s"${deserializer.simpleString(SQLConf.get.maxToStringFields)}", e)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,12 @@ abstract class Expression extends TreeNode[Expression] {

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

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

override def toString: String = prettyName + truncatedString(
flatArguments.toSeq, "(", ", ", ")")
flatArguments.toSeq, "(", ", ", ")", SQLConf.get.maxToStringFields)

/**
* Returns SQL representation of this expression. For expressions extending [[NonSQLExpression]],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ trait Block extends TreeNode[Block] with JavaCode {
case _ => code"$this\n$other"
}

override def verboseString: String = toString
override def verboseString(maxFields: Int): String = toString
}

object Block {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.apache.spark.sql.catalyst.analysis.TypeCheckResult
import org.apache.spark.sql.catalyst.expressions.codegen._
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
import org.apache.spark.sql.catalyst.util.{ArrayData, MapData}
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._

/**
Expand Down Expand Up @@ -101,7 +102,7 @@ case class UserDefinedGenerator(
inputRow = new InterpretedProjection(children)
convertToScala = {
val inputSchema = StructType(children.map { e =>
StructField(e.simpleString, e.dataType, nullable = true)
StructField(e.simpleString(SQLConf.get.maxToStringFields), e.dataType, nullable = true)
})
CatalystTypeConverters.createToScalaConverter(inputSchema)
}.asInstanceOf[InternalRow => Row]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ case class NamedLambdaVariable(

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

override def simpleString: String = s"lambda $name#${exprId.id}: ${dataType.simpleString}"
override def simpleString(maxFields: Int): String = {
s"lambda $name#${exprId.id}: ${dataType.simpleString(maxFields)}"
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import org.apache.spark.sql.catalyst.InternalRow
import org.apache.spark.sql.catalyst.expressions.codegen._
import org.apache.spark.sql.catalyst.expressions.codegen.Block._
import org.apache.spark.sql.catalyst.util.RandomUUIDGenerator
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._
import org.apache.spark.unsafe.types.UTF8String

Expand All @@ -40,7 +41,7 @@ case class PrintToStderr(child: Expression) extends UnaryExpression {
input
}

private val outputPrefix = s"Result of ${child.simpleString} is "
private val outputPrefix = s"Result of ${child.simpleString(SQLConf.get.maxToStringFields)} is "

override def doGenCode(ctx: CodegenContext, ev: ExprCode): ExprCode = {
val outputPrefixField = ctx.addReferenceObj("outputPrefix", outputPrefix)
Expand Down Expand Up @@ -72,7 +73,7 @@ case class AssertTrue(child: Expression) extends UnaryExpression with ImplicitCa

override def prettyName: String = "assert_true"

private val errMsg = s"'${child.simpleString}' is not true!"
private val errMsg = s"'${child.simpleString(SQLConf.get.maxToStringFields)}' is not true!"

override def eval(input: InternalRow) : Any = {
val v = child.eval(input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,9 @@ case class AttributeReference(

// Since the expression id is not in the first constructor it is missing from the default
// tree string.
override def simpleString: String = s"$name#${exprId.id}: ${dataType.simpleString}"
override def simpleString(maxFields: Int): String = {
s"$name#${exprId.id}: ${dataType.simpleString(maxFields)}"
}

override def sql: String = {
val qualifierPrefix = if (qualifier.nonEmpty) qualifier.mkString(".") + "." else ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,9 +172,9 @@ abstract class QueryPlan[PlanType <: QueryPlan[PlanType]] extends TreeNode[PlanT
*/
protected def statePrefix = if (missingInput.nonEmpty && children.nonEmpty) "!" else ""

override def simpleString: String = statePrefix + super.simpleString
override def simpleString(maxFields: Int): String = statePrefix + super.simpleString(maxFields)

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

/**
* All the subqueries of current plan.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ abstract class LogicalPlan
/** Returns true if this subtree has data from a streaming data source. */
def isStreaming: Boolean = children.exists(_.isStreaming == true)

override def verboseStringWithSuffix: String = {
super.verboseString + statsCache.map(", " + _.toString).getOrElse("")
override def verboseStringWithSuffix(maxFields: Int): String = {
super.verboseString(maxFields) + statsCache.map(", " + _.toString).getOrElse("")
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ case class View(

override def newInstance(): LogicalPlan = copy(output = output.map(_.newInstance()))

override def simpleString: String = {
override def simpleString(maxFields: Int): String = {
s"View (${desc.identifier}, ${output.mkString("[", ",", "]")})"
}
}
Expand All @@ -484,8 +484,8 @@ case class View(
case class With(child: LogicalPlan, cteRelations: Seq[(String, SubqueryAlias)]) extends UnaryNode {
override def output: Seq[Attribute] = child.output

override def simpleString: String = {
val cteAliases = truncatedString(cteRelations.map(_._1), "[", ", ", "]")
override def simpleString(maxFields: Int): String = {
val cteAliases = truncatedString(cteRelations.map(_._1), "[", ", ", "]", maxFields)
s"CTE $cteAliases"
}

Expand Down Expand Up @@ -557,7 +557,7 @@ case class Range(

override def newInstance(): Range = copy(output = output.map(_.newInstance()))

override def simpleString: String = {
override def simpleString(maxFields: Int): String = {
s"Range ($start, $end, step=$step, splits=$numSlices)"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import org.apache.spark.sql.catalyst.expressions._
import org.apache.spark.sql.catalyst.plans.JoinType
import org.apache.spark.sql.catalyst.plans.physical.{BroadcastMode, Partitioning}
import org.apache.spark.sql.catalyst.util.truncatedString
import org.apache.spark.sql.internal.SQLConf
import org.apache.spark.sql.types._
import org.apache.spark.storage.StorageLevel

Expand Down Expand Up @@ -433,17 +434,17 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
private lazy val allChildren: Set[TreeNode[_]] = (children ++ innerChildren).toSet[TreeNode[_]]

/** Returns a string representing the arguments to this node, minus any children */
def argString: String = stringArgs.flatMap {
def argString(maxFields: Int): String = stringArgs.flatMap {
case tn: TreeNode[_] if allChildren.contains(tn) => Nil
case Some(tn: TreeNode[_]) if allChildren.contains(tn) => Nil
case Some(tn: TreeNode[_]) => tn.simpleString :: Nil
case tn: TreeNode[_] => tn.simpleString :: Nil
case Some(tn: TreeNode[_]) => tn.simpleString(maxFields) :: Nil
case tn: TreeNode[_] => tn.simpleString(maxFields) :: Nil
case seq: Seq[Any] if seq.toSet.subsetOf(allChildren.asInstanceOf[Set[Any]]) => Nil
case iter: Iterable[_] if iter.isEmpty => Nil
case seq: Seq[_] => truncatedString(seq, "[", ", ", "]") :: Nil
case set: Set[_] => truncatedString(set.toSeq, "{", ", ", "}") :: Nil
case seq: Seq[_] => truncatedString(seq, "[", ", ", "]", maxFields) :: Nil
case set: Set[_] => truncatedString(set.toSeq, "{", ", ", "}", maxFields) :: Nil
case array: Array[_] if array.isEmpty => Nil
case array: Array[_] => truncatedString(array, "[", ", ", "]") :: Nil
case array: Array[_] => truncatedString(array, "[", ", ", "]", maxFields) :: Nil
case null => Nil
case None => Nil
case Some(null) => Nil
Expand All @@ -456,24 +457,33 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
case other => other :: Nil
}.mkString(", ")

/** ONE line description of this node. */
def simpleString: String = s"$nodeName $argString".trim
/**
* ONE line description of this node.
* @param maxFields Maximum number of fields that will be converted to strings.
* Any elements beyond the limit will be dropped.
*/
def simpleString(maxFields: Int): String = {
s"$nodeName ${argString(maxFields)}".trim
}

/** ONE line description of this node with more information */
def verboseString: String
def verboseString(maxFields: Int): String

/** ONE line description of this node with some suffix information */
def verboseStringWithSuffix: String = verboseString
def verboseStringWithSuffix(maxFields: Int): String = verboseString(maxFields)

override def toString: String = treeString

/** Returns a string representation of the nodes in this tree */
def treeString: String = treeString(verbose = true)

def treeString(verbose: Boolean, addSuffix: Boolean = false): String = {
def treeString(
verbose: Boolean,
addSuffix: Boolean = false,
maxFields: Int = SQLConf.get.maxToStringFields): String = {
val writer = new StringBuilderWriter()
try {
treeString(writer, verbose, addSuffix)
treeString(writer, verbose, addSuffix, maxFields)
writer.toString
} finally {
writer.close()
Expand All @@ -483,8 +493,9 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
def treeString(
writer: Writer,
verbose: Boolean,
addSuffix: Boolean): Unit = {
generateTreeString(0, Nil, writer, verbose, "", addSuffix)
addSuffix: Boolean,
maxFields: Int): Unit = {
generateTreeString(0, Nil, writer, verbose, "", addSuffix, maxFields)
}

/**
Expand Down Expand Up @@ -550,7 +561,8 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
writer: Writer,
verbose: Boolean,
prefix: String = "",
addSuffix: Boolean = false): Unit = {
addSuffix: Boolean = false,
maxFields: Int): Unit = {

if (depth > 0) {
lastChildren.init.foreach { isLast =>
Expand All @@ -560,9 +572,9 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
}

val str = if (verbose) {
if (addSuffix) verboseStringWithSuffix else verboseString
if (addSuffix) verboseStringWithSuffix(maxFields) else verboseString(maxFields)
} else {
simpleString
simpleString(maxFields)
}
writer.write(prefix)
writer.write(str)
Expand All @@ -571,17 +583,17 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
if (innerChildren.nonEmpty) {
innerChildren.init.foreach(_.generateTreeString(
depth + 2, lastChildren :+ children.isEmpty :+ false, writer, verbose,
addSuffix = addSuffix))
addSuffix = addSuffix, maxFields = maxFields))
innerChildren.last.generateTreeString(
depth + 2, lastChildren :+ children.isEmpty :+ true, writer, verbose,
addSuffix = addSuffix)
addSuffix = addSuffix, maxFields = maxFields)
}

if (children.nonEmpty) {
children.init.foreach(_.generateTreeString(
depth + 1, lastChildren :+ false, writer, verbose, prefix, addSuffix))
depth + 1, lastChildren :+ false, writer, verbose, prefix, addSuffix, maxFields))
children.last.generateTreeString(
depth + 1, lastChildren :+ true, writer, verbose, prefix, addSuffix)
depth + 1, lastChildren :+ true, writer, verbose, prefix, addSuffix, maxFields)
}
}

Expand Down Expand Up @@ -664,7 +676,7 @@ abstract class TreeNode[BaseType <: TreeNode[BaseType]] extends Product {
t.forall(_.isInstanceOf[Partitioning]) || t.forall(_.isInstanceOf[DataType]) =>
JArray(t.map(parseToJson).toList)
case t: Seq[_] if t.length > 0 && t.head.isInstanceOf[String] =>
JString(truncatedString(t, "[", ", ", "]"))
JString(truncatedString(t, "[", ", ", "]", SQLConf.get.maxToStringFields))
case t: Seq[_] => JNull
case m: Map[_, _] => JNull
// if it's a scala object, we can simply keep the full class path.
Expand Down
Loading

0 comments on commit e9e7893

Please sign in to comment.