MrPowers/spark-daria

View on GitHub

Showing 21 of 21 total issues

functions has 30 methods (exceeds 20 allowed). Consider refactoring.
Open

object functions {

  //////////////////////////////////////////////////////////////////////////////////////////////
  // String functions
  //////////////////////////////////////////////////////////////////////////////////////////////
Severity: Minor
Found in src/main/scala/com/github/mrpowers/spark/daria/sql/functions.scala - About 3 hrs to fix

    Function trans has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def trans(customTransform: CustomTransform): DataFrame = {
          // make sure df doesn't already have the columns that will be added
          if (df.columns.toSeq.exists((c: String) => customTransform.addedColumns.contains(c))) {
            throw DataFrameColumnsException(
              s"The DataFrame already contains the columns your transformation will add. The DataFrame has these columns: [${df.columns

      Function bucketFinder has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        ): Column = {
      
          val inclusiveBoundriesCol = lit(inclusiveBoundries)
          val lowerBoundLteCol      = lit(lowestBoundLte)
          val upperBoundGteCol      = lit(highestBoundGte)
      Severity: Minor
      Found in src/main/scala/com/github/mrpowers/spark/daria/sql/functions.scala - About 1 hr to fix

        Function run has 29 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def run(): Unit = {
        
            lazy val spark: SparkSession = {
              SparkSession
                .builder()

          Similar blocks of code found in 4 locations. Consider refactoring.
          Open

                when(
                  col.isNull,
                  lit(null)
                ).when(
                  lowerBoundLteCol === false && lit(res._1).isNull && lit(res._2).isNotNull && col < lit(res._2),
          src/main/scala/com/github/mrpowers/spark/daria/sql/functions.scala on lines 339..348
          src/main/scala/com/github/mrpowers/spark/daria/sql/functions.scala on lines 339..351
          src/main/scala/com/github/mrpowers/spark/daria/sql/functions.scala on lines 339..354

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 85.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              def withColumnCast(columnName: String, newType: DataType): DataFrame =
                df.select((df.columns.map {
                  case c if c == columnName => col(c).cast(newType).as(c)
                  case c                    => col(c)
                }): _*)
          src/main/scala/com/github/mrpowers/spark/daria/sql/DataFrameExt.scala on lines 22..26

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 80.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              def withColumnCast(columnName: String, newType: String): DataFrame =
                df.select((df.columns.map {
                  case c if c == columnName => col(c).cast(newType).as(c)
                  case c                    => col(c)
                }): _*)
          src/main/scala/com/github/mrpowers/spark/daria/sql/DataFrameExt.scala on lines 35..39

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 80.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Method writeThenMerge has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                df: DataFrame,
                format: String = "csv",                // csv, parquet
                sc: SparkContext,                      // pass in spark.sparkContext
                tmpFolder: String,                     // will be deleted, so make sure it doesn't already exist
                filename: String,                      // the full filename you want outputted
          Severity: Minor
          Found in src/main/scala/com/github/mrpowers/spark/daria/sql/DariaWriters.scala - About 45 mins to fix

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

                            case _ =>
                              struct(loop(l.map {
                                case (column, _ :: tail) => (column, tail)
                                case (column, h :: Nil)  => (column, List(h))
                              }): _*).alias(structColumn)
            src/main/scala/com/github/mrpowers/spark/daria/sql/DataFrameExt.scala on lines 296..301

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 75.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Method writeSingleFile has 6 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                  df: DataFrame,             // must be small
                  format: String = "csv",    // csv, parquet
                  sc: SparkContext,          // pass in spark.sparkContext
                  tmpFolder: String,         // will be deleted, so make sure it doesn't already exist
                  filename: String,          // the full filename you want outputted
            Severity: Minor
            Found in src/main/scala/com/github/mrpowers/spark/daria/sql/DariaWriters.scala - About 45 mins to fix

              Identical blocks of code found in 2 locations. Consider refactoring.
              Open

                          case (structColumn, l) if l.length > 1 =>
                            struct(loop(l.map {
                              case (column, _ :: tail) => (column, tail)
                              case (column, h :: Nil)  => (column, List(h))
                            }): _*).alias(structColumn)
              src/main/scala/com/github/mrpowers/spark/daria/sql/DataFrameExt.scala on lines 304..308

              Duplicated Code

              Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

              Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

              When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

              Tuning

              This issue has a mass of 75.

              We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

              The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

              If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

              See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

              Refactorings

              Further Reading

              Method withColBucket has 6 arguments (exceeds 4 allowed). Consider refactoring.
              Open

                    colName: String,
                    outputColName: String,
                    buckets: Array[(Any, Any)],
                    inclusiveBoundries: Boolean = false,
                    lowestBoundLte: Boolean = false,
              Severity: Minor
              Found in src/main/scala/com/github/mrpowers/spark/daria/sql/transformations.scala - About 45 mins to fix

                Constructor has 5 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    transform: (DataFrame => DataFrame),
                    requiredColumns: Seq[String] = Seq.empty[String],
                    addedColumns: Seq[String] = Seq.empty[String],
                    removedColumns: Seq[String] = Seq.empty[String],
                    skipWhenPossible: Boolean = true
                Severity: Minor
                Found in src/main/scala/com/github/mrpowers/spark/daria/sql/CustomTransform.scala - About 35 mins to fix

                  Method bucketFinder has 5 arguments (exceeds 4 allowed). Consider refactoring.
                  Open

                        col: Column,
                        buckets: Array[(Any, Any)],
                        inclusiveBoundries: Boolean = false,
                        lowestBoundLte: Boolean = false,
                        highestBoundGte: Boolean = false
                  Severity: Minor
                  Found in src/main/scala/com/github/mrpowers/spark/daria/sql/functions.scala - About 35 mins to fix

                    Identical blocks of code found in 2 locations. Consider refactoring.
                    Open

                        private def asSchema[U <: Product](fields: List[U]): List[StructField] = {
                          fields.map {
                            case x: StructField => x.asInstanceOf[StructField]
                            case (name: String, dataType: DataType, nullable: Boolean) =>
                              StructField(
                    src/main/scala/com/github/mrpowers/spark/daria/sql/types/StructTypeHelpers.scala on lines 12..22

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 65.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Function dariaCopyMerge has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                      def dariaCopyMerge(
                          srcPath: String,
                          dstPath: String,
                          sc: SparkContext,
                          deleteSource: Boolean = true
                    Severity: Minor
                    Found in src/main/scala/com/github/mrpowers/spark/daria/hadoop/FsHelpers.scala - About 35 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Identical blocks of code found in 2 locations. Consider refactoring.
                    Open

                      def build[U <: Product](fields: U*) = {
                        fields.map {
                          case x: StructField => x.asInstanceOf[StructField]
                          case (name: String, dataType: DataType, nullable: Boolean) =>
                            StructField(
                    src/main/scala/com/github/mrpowers/spark/daria/sql/SparkSessionExt.scala on lines 18..28

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 65.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                          if (!actualColumnsAdded.equals(customTransform.addedColumns)) {
                            throw DataFrameColumnsException(
                              s"The [${actualColumnsAdded.mkString(", ")}] columns were actually added, but you specified that these columns should have been added [${customTransform.addedColumns
                                .mkString(", ")}]"
                            )
                    src/main/scala/com/github/mrpowers/spark/daria/sql/DataFrameExt.scala on lines 254..259

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 60.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Similar blocks of code found in 2 locations. Consider refactoring.
                    Open

                          if (!actualColumnsRemoved.equals(customTransform.removedColumns)) {
                            throw DataFrameColumnsException(
                              s"The [${actualColumnsRemoved.mkString(", ")}] columns were actually removed, but you specified that these columns should have been removed [${customTransform.removedColumns
                                .mkString(", ")}]"
                            )
                    src/main/scala/com/github/mrpowers/spark/daria/sql/DataFrameExt.scala on lines 245..250

                    Duplicated Code

                    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                    Tuning

                    This issue has a mass of 60.

                    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                    Refactorings

                    Further Reading

                    Function isLuhn has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                    Open

                      private[sql] def isLuhn(str: String): Option[Boolean] = {
                        val s = Option(str).getOrElse(return None)
                        if (s.isEmpty()) {
                          return Some(false)
                        }
                    Severity: Minor
                    Found in src/main/scala/com/github/mrpowers/spark/daria/sql/functions.scala - About 25 mins to fix

                    Cognitive Complexity

                    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                    A method's cognitive complexity is based on a few simple rules:

                    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                    • Code is considered more complex for each "break in the linear flow of the code"
                    • Code is considered more complex when "flow breaking structures are nested"

                    Further reading

                    Severity
                    Category
                    Status
                    Source
                    Language