@@ -12,28 +12,28 @@ import org.apache.spark.sql.catalyst.expressions._
1212import org .apache .spark .sql .types .{IntegerType , StringType , StructType }
1313
1414case class StringLengthCheck (
15- column : String ,
16- minLength : Option [Json ],
17- maxLength : Option [Json ],
18- threshold : Option [String ]
19- ) extends RowBased {
15+ column : String ,
16+ minLength : Option [Json ],
17+ maxLength : Option [Json ],
18+ threshold : Option [String ]
19+ ) extends RowBased {
2020
2121 override def substituteVariables (dict : VarSubstitution ): ValidatorBase = {
2222
2323 val ret = StringLengthCheck (
24- getVarSub(column, " column" , dict),
25- minLength.map(getVarSubJson(_, " minLength" , dict)),
26- maxLength.map(getVarSubJson(_, " maxLength" , dict)),
27- threshold.map(getVarSub(_, " threshold" , dict))
28- )
24+ getVarSub(column, " column" , dict),
25+ minLength.map(getVarSubJson(_, " minLength" , dict)),
26+ maxLength.map(getVarSubJson(_, " maxLength" , dict)),
27+ threshold.map(getVarSub(_, " threshold" , dict))
28+ )
2929 getEvents.foreach(ret.addEvent)
3030 ret
3131 }
3232
3333 private def cmpExpr (colExpr : Expression ,
34- value : Option [Json ],
35- cmp : (Expression , Expression ) => Expression
36- ): Option [Expression ] = {
34+ value : Option [Json ],
35+ cmp : (Expression , Expression ) => Expression
36+ ): Option [Expression ] = {
3737 value.map { v => cmp(colExpr, createLiteralOrUnresolvedAttribute(IntegerType , v)) }
3838 }
3939
@@ -57,20 +57,20 @@ case class StringLengthCheck(
5757 private def checkMinLessThanOrEqualToMax (values : List [Json ]): Unit = {
5858
5959 if (values.forall(_.isNumber)) {
60- values.flatMap(_.asNumber) match {
61- case mv :: xv :: Nil if mv.toDouble > xv.toDouble =>
62- addEvent(ValidatorError (s " min: ${minLength.get} must be less than or equal to max: ${maxLength.get}" ))
63- case _ =>
64- }
60+ values.flatMap(_.asNumber) match {
61+ case mv :: xv :: Nil if mv.toDouble > xv.toDouble =>
62+ addEvent(ValidatorError (s " min: ${minLength.get} must be less than or equal to max: ${maxLength.get}" ))
63+ case _ =>
64+ }
6565 } else if (values.forall(_.isString)) {
66- values.flatMap(_.asString) match {
67- case mv :: xv :: Nil if mv == xv =>
68- addEvent(ValidatorError (s " Min[String]: $mv must be less than max[String]: $xv" ))
69- case _ =>
70- }
66+ values.flatMap(_.asString) match {
67+ case mv :: xv :: Nil if mv == xv =>
68+ addEvent(ValidatorError (s " Min[String]: $mv must be less than max[String]: $xv" ))
69+ case _ =>
70+ }
7171 } else {
72- // Not Strings or Numbers
73- addEvent(ValidatorError (s " Unsupported type in ${values.map(debugJson).mkString(" , " )}" ))
72+ // Not Strings or Numbers
73+ addEvent(ValidatorError (s " Unsupported type in ${values.map(debugJson).mkString(" , " )}" ))
7474 }
7575 }
7676
@@ -89,7 +89,7 @@ case class StringLengthCheck(
8989 val colType = findColumnInDataFrame(df, column)
9090 if (colType.isDefined) {
9191 val dataType = colType.get.dataType
92- if (! ( dataType.isInstanceOf [StringType ]) ) {
92+ if (! dataType.isInstanceOf [StringType ]) {
9393 addEvent(ValidatorError (s " Data type of column ' $column' must be String, but was found to be $dataType" ))
9494 }
9595 }
@@ -123,8 +123,6 @@ object StringLengthCheck extends LazyLogging {
123123 logger.debug(s " minLength: $minLengthJ type: ${minLengthJ.getClass.getCanonicalName}" )
124124 logger.debug(s " maxLength: $maxLengthJ type: ${maxLengthJ.getClass.getCanonicalName}" )
125125 logger.debug(s " threshold: $threshold type: ${threshold.getClass.getCanonicalName}" )
126-
127- c.focus.foreach {f => logger.info(s " StringLengthCheckJson: ${f.spaces2}" )}
128126 scala.util.Right (StringLengthCheck (column, minLengthJ, maxLengthJ, threshold))
129127 }
130128}
0 commit comments