From b79adc4aa450f9315f1493ffa83f9dca00118d16 Mon Sep 17 00:00:00 2001 From: Tuan Pham Date: Tue, 19 Nov 2024 22:00:55 +1100 Subject: [PATCH] put magic number in constant --- .../github/mrpowers/spark/fast/tests/SchemaComparer.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/core/src/main/scala/com/github/mrpowers/spark/fast/tests/SchemaComparer.scala b/core/src/main/scala/com/github/mrpowers/spark/fast/tests/SchemaComparer.scala index 7a003f4..bd3aa09 100644 --- a/core/src/main/scala/com/github/mrpowers/spark/fast/tests/SchemaComparer.scala +++ b/core/src/main/scala/com/github/mrpowers/spark/fast/tests/SchemaComparer.scala @@ -7,6 +7,8 @@ import org.apache.spark.sql.Dataset import org.apache.spark.sql.types._ object SchemaComparer { + private val INDENT_GAP = 5 + private val DESCRIPTION_GAP = 21 case class DatasetSchemaMismatch(smth: String) extends Exception(smth) private def betterSchemaMismatchMessage(actualSchema: StructType, expectedSchema: StructType): String = { showProductDiff( @@ -20,8 +22,7 @@ object SchemaComparer { private def treeSchemaMismatchMessage[T](actualSchema: StructType, expectedSchema: StructType): String = { def flattenStrucType(s: StructType, indent: Int): (Seq[(Int, StructField)], Int) = s .foldLeft((Seq.empty[(Int, StructField)], Int.MinValue)) { case ((fieldPair, maxWidth), f) => - // 5 char for each level of indentation, 21 char for gap, and description words - val gap = indent * 5 + 21 + f.name.length + f.dataType.typeName.length + f.nullable.toString.length + val gap = indent * INDENT_GAP + DESCRIPTION_GAP + f.name.length + f.dataType.typeName.length + f.nullable.toString.length val pair = fieldPair :+ (indent, f) val newMaxWidth = scala.math.max(maxWidth, gap) f.dataType match {