daemonslayer/tests-airflow

View on GitHub
src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py

Summary

Maintainability
F
4 days
Test Coverage

File hive_hooks.py has 664 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# -*- coding: utf-8 -*-
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
Severity: Major
Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py - About 1 day to fix

    Function test_hql has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

        def test_hql(self, hql):
            """
            Test an hql statement using the hive cli and EXPLAIN
    
            """
    Severity: Minor
    Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py - About 2 hrs 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

    Function _prepare_cli_cmd has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

        def _prepare_cli_cmd(self):
            """
            This function creates the command list from available information
            """
            conn = self.conn
    Severity: Minor
    Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py - About 2 hrs 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

    Function run_cli has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def run_cli(self, hql, schema=None, verbose=True, hive_conf=None):
            """
            Run an hql statement using the hive cli. If hive_conf is specified
            it should be a dict and the entries will be set as key/value pairs
            in HiveConf
    Severity: Minor
    Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py - About 1 hr 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

    Function load_df has 9 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def load_df(
    Severity: Major
    Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py - About 1 hr to fix

      Function load_file has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
      Open

          def load_file(
                  self,
                  filepath,
                  table,
                  delimiter=",",
      Severity: Minor
      Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py - About 1 hr 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

      Function load_file has 8 arguments (exceeds 4 allowed). Consider refactoring.
      Open

          def load_file(
      Severity: Major
      Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py - About 1 hr to fix

        Function to_csv has 7 arguments (exceeds 4 allowed). Consider refactoring.
        Open

            def to_csv(
        Severity: Major
        Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py - About 50 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if not rows:
                                      break
          
          
          Severity: Major
          Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py - About 45 mins to fix

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

                def __init__(
            Severity: Minor
            Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py - About 35 mins to fix

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

                  def transfer_data_file(self, filepath, verbose=True):
                          filename = os.path.basename(filepath)
                          destination_path = '/user/cloudera/{0}'.format(filename)
              
                          hdfs_cmd = ['hdfs','dfs','-put',filepath,destination_path]
              Severity: Minor
              Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py - 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

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

                  def get_results(self, hql, schema='default', arraysize=1000):
                      from impala.error import ProgrammingError
                      with self.get_conn(schema) as conn:
                          if isinstance(hql, basestring):
                              hql = [hql]
              Severity: Minor
              Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py - 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

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

                  def get_metastore_client(self):
                      """
                      Returns a Hive thrift client.
                      """
                      from thrift.transport import TSocket, TTransport
              Severity: Minor
              Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py - 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

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

                              while True:
                                  line = sp.stdout.readline()
                                  if not line:
                                      break
                                  stdout += line.decode('UTF-8')
              Severity: Major
              Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py and 1 other location - About 2 hrs to fix
              src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py on lines 243..249

              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

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

                          while True:
                              line = sp.stdout.readline()
                              if not line:
                                  break
                              stdout += line.decode('UTF-8')
              Severity: Major
              Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py and 1 other location - About 2 hrs to fix
              src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py on lines 216..222

              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 configuration.get('core', 'security') == 'kerberos':
                          auth_mechanism = db.extra_dejson.get('authMechanism', 'GSSAPI')
                          kerberos_service_name = db.extra_dejson.get('kerberos_service_name', 'hive')
              Severity: Major
              Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py and 1 other location - About 1 hr to fix
              src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py on lines 475..477

              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 45.

              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 configuration.get('core', 'security') == 'kerberos':
                          auth_mechanism = ms.extra_dejson.get('authMechanism', 'GSSAPI')
                          kerberos_service_name = ms.extra_dejson.get('kerberos_service_name', 'hive')
              Severity: Major
              Found in src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py and 1 other location - About 1 hr to fix
              src/etl/examples/hive-example/dags/acme/hooks/hive_hooks.py on lines 683..685

              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 45.

              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

              There are no issues that match your filters.

              Category
              Status