18F/rdbms-subsetter

View on GitHub

Showing 13 of 15 total issues

File subsetter.py has 569 lines of code (exceeds 250 allowed). Consider refactoring.
Open

"""
Generate a random sample of rows from a relational database that preserves
referential integrity - so long as constraints are defined, all parent rows
will exist for child rows.

Severity: Major
Found in rdbms_subsetter/subsetter.py - About 1 day to fix

    Function create_row_in has a Cognitive Complexity of 56 (exceeds 5 allowed). Consider refactoring.
    Open

        def create_row_in(self, source_row, target_db, target, prioritized=False):
            logging.debug('create_row_in %s:%s ' %
                          (target.name, target.pk_val(source_row)))
    
            pks = hashable((source_row[key] for key in target.pk))
    Severity: Minor
    Found in rdbms_subsetter/subsetter.py - About 1 day 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 __init__ has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, sqla_conn, args, schemas=[None]):
            self.args = args
            self.sqla_conn = sqla_conn
            self.schemas = schemas
            self.engine = sa.create_engine(sqla_conn)
    Severity: Minor
    Found in rdbms_subsetter/subsetter.py - About 3 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 create_subset_in has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def create_subset_in(self, target_db):
    
            for (tbl_name, pks) in self.args.force_rows.items():
                if '.' in tbl_name:
                    (tbl_schema, tbl_name) = tbl_name.split('.', 1)
    Severity: Minor
    Found in rdbms_subsetter/subsetter.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 _random_row_gen_fn has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

    def _random_row_gen_fn(self):
        """
        Random sample of *approximate* size n
        """
        if self.n_rows:
    Severity: Minor
    Found in rdbms_subsetter/subsetter.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 assign_target has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def assign_target(self, target_db):
            for ((tbl_schema, tbl_name), tbl) in self.tables.items():
                tbl._random_row_gen_fn = types.MethodType(_random_row_gen_fn, tbl)
                tbl.random_rows = tbl._random_row_gen_fn()
                tbl.next_row = types.MethodType(_next_row, tbl)
    Severity: Minor
    Found in rdbms_subsetter/subsetter.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 _find_n_rows has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def _find_n_rows(self, estimate=False):
        self.n_rows = 0
        if estimate:
            try:
                if self.db.engine.driver in ('psycopg2', 'pg8000', ):
    Severity: Minor
    Found in rdbms_subsetter/subsetter.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 fix_postgres_array_of_enum has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

    def fix_postgres_array_of_enum(connection, tbl):
        "Change type of ENUM[] columns to a custom type"
    
        for col in tbl.c:
            col_str = str(col.type)
    Severity: Minor
    Found in dialects/postgres.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 update_sequences has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def update_sequences(source, target, schemas, tables, exclude_tables):
        """Set database sequence values to match the source db
    
           Needed to avoid subsequent unique key violations after DB build.
           Currently only implemented for postgresql -> postgresql."""
    Severity: Minor
    Found in rdbms_subsetter/subsetter.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 _completeness_score has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def _completeness_score(self):
        """Scores how close a target table is to being filled enough to quit"""
        table = (self.schema if self.schema else "") + self.name
        fetch_all = self.fetch_all
        requested = len(self.requested)
    Severity: Minor
    Found in rdbms_subsetter/subsetter.py - About 55 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

    Avoid deeply nested control flow statements.
    Open

                            if source_referred_row:
                                self.create_row_in(source_referred_row, target_db,
                                                   target_referred)
    
    
    Severity: Major
    Found in rdbms_subsetter/subsetter.py - About 45 mins to fix

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

      def update_sequences(source, target, schemas, tables, exclude_tables):
      Severity: Minor
      Found in rdbms_subsetter/subsetter.py - About 35 mins to fix

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

        def generate():
            args = argparser.parse_args()
            _import_modules(args.import_list)
            args.force_rows = {}
            for force_row in (args.force or []):
        Severity: Minor
        Found in rdbms_subsetter/subsetter.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

        Severity
        Category
        Status
        Source
        Language