airbnb/caravel

View on GitHub
superset/sql_parse.py

Summary

Maintainability
F
1 wk
Test Coverage

File sql_parse.py has 1208 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
Severity: Major
Found in superset/sql_parse.py - About 3 days to fix

    Function is_select has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
    Open

        def is_select(self) -> bool:
            # make sure we strip comments; prevents a bug with comments in the CTE
            parsed = sqlparse.parse(self.strip_comments())
            seen_select = False
    
    
    Severity: Minor
    Found in superset/sql_parse.py - About 4 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 insert_rls_in_predicate has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

    def insert_rls_in_predicate(
        token_list: TokenList,
        database_id: int,
        default_schema: str | None,
    ) -> TokenList:
    Severity: Minor
    Found in superset/sql_parse.py - About 4 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 extract_table_references has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

    def extract_table_references(
        sql_text: str, sqla_dialect: str, show_warning: bool = True
    ) -> set[Table]:
        """
        Return all the dependencies from a SQL sql_text.
    Severity: Minor
    Found in superset/sql_parse.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 insert_rls_as_subquery has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
    Open

    def insert_rls_as_subquery(
        token_list: TokenList,
        database_id: int,
        default_schema: str | None,
    ) -> TokenList:
    Severity: Minor
    Found in superset/sql_parse.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 sanitize_clause has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

    def sanitize_clause(clause: str) -> str:
        # clause = sqlparse.format(clause, strip_comments=True)
        statements = sqlparse.parse(clause)
        if len(statements) != 1:
            raise QueryClauseValidationException("Clause contains multiple statements")
    Severity: Minor
    Found in superset/sql_parse.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

    ParsedQuery has 23 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ParsedQuery:
        def __init__(
            self,
            sql_statement: str,
            strip_comments: bool = False,
    Severity: Minor
    Found in superset/sql_parse.py - About 2 hrs to fix

      Function split_kql has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

      def split_kql(kql: str) -> list[str]:
          """
          Custom function for splitting KQL statements.
          """
          statements = []
      Severity: Minor
      Found in superset/sql_parse.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 has_table_query has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

      def has_table_query(token_list: TokenList) -> bool:
          """
          Return if a statement has a query reading from a table.
      
              >>> has_table_query(sqlparse.parse("COUNT(*)")[0])
      Severity: Minor
      Found in superset/sql_parse.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

      Consider simplifying this complex logical expression.
      Open

              if imt(token, m=[(Keyword, "FROM"), (Keyword, "JOIN")]):
                  state = InsertRLSState.SEEN_SOURCE
      
              # Found identifier/keyword after FROM/JOIN, test for table
              elif state == InsertRLSState.SEEN_SOURCE and (
      Severity: Critical
      Found in superset/sql_parse.py - About 1 hr to fix

        Function get_inner_cte_expression has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

            def get_inner_cte_expression(self, tokens: TokenList) -> TokenList | None:
                for token in tokens:
                    if self._is_identifier(token):
                        for identifier_token in token.tokens:
                            if (
        Severity: Minor
        Found in superset/sql_parse.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 extract_tables_from_statement has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        def extract_tables_from_statement(
            statement: exp.Expression,
            dialect: Dialects | None,
        ) -> set[Table]:
            """
        Severity: Minor
        Found in superset/sql_parse.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 _extract_limit_from_query has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

        def _extract_limit_from_query(statement: TokenList) -> int | None:
            """
            Extract limit clause from SQL statement.
        
            :param statement: SQL statement
        Severity: Minor
        Found in superset/sql_parse.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 _extract_tables_from_statement has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def _extract_tables_from_statement(self, statement: exp.Expression) -> set[Table]:
                """
                Extract all table references in a single statement.
        
                Please not that this is not trivial; consider the following queries:
        Severity: Minor
        Found in superset/sql_parse.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

        Consider simplifying this complex logical expression.
        Open

                if state == KQLSplitState.OUTSIDE_STRING:
                    if character == ";":
                        statements.append(query[statement_start:i])
                        statement_start = i + 1
                    elif character == "'":
        Severity: Major
        Found in superset/sql_parse.py - About 1 hr to fix

          Function _check_cte_is_select has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def _check_cte_is_select(self, oxide_parse: list[dict[str, Any]]) -> bool:
                  """
                  Check if a oxide parsed CTE contains only SELECT statements
          
                  :param oxide_parse: parsed CTE
          Severity: Minor
          Found in superset/sql_parse.py - About 45 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 set_or_update_query_limit has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              def set_or_update_query_limit(self, new_limit: int, force: bool = False) -> str:
                  """Returns the query with the specified limit.
          
                  Does not change the underlying query if user did not apply the limit,
                  otherwise replaces the limit with the lower value between existing limit
          Severity: Minor
          Found in superset/sql_parse.py - About 45 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 too many return statements within this function.
          Open

                          return False
          Severity: Major
          Found in superset/sql_parse.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                    return seen_select
            Severity: Major
            Found in superset/sql_parse.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                              return False
              Severity: Major
              Found in superset/sql_parse.py - About 30 mins to fix

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

                    def get_statements(self) -> list[str]:
                        """Returns a list of SQL statements as strings, stripped"""
                        statements = []
                        for statement in self._parsed:
                            if statement:
                Severity: Minor
                Found in superset/sql_parse.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 extract_top_from_query has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                def extract_top_from_query(statement: TokenList, top_keywords: set[str]) -> int | None:
                    """
                    Extract top clause value from SQL statement.
                
                    :param statement: SQL statement
                Severity: Minor
                Found in superset/sql_parse.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 extract_tables_from_jinja_sql has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                def extract_tables_from_jinja_sql(sql: str, database: Database) -> set[Table]:
                    """
                    Extract all table references in the Jinjafied SQL statement.
                
                    Due to Jinja templating, a multiphase approach is necessary as the Jinjafied SQL
                Severity: Minor
                Found in superset/sql_parse.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

                There are no issues that match your filters.

                Category
                Status