airbnb/caravel

View on GitHub
superset/common/query_context_processor.py

Summary

Maintainability
F
3 days
Test Coverage

File query_context_processor.py has 694 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/common/query_context_processor.py - About 1 day to fix

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

        def processing_time_offsets(  # pylint: disable=too-many-locals,too-many-statements
            self,
            df: pd.DataFrame,
            query_object: QueryObject,
        ) -> CachedTimeOffset:
    Severity: Minor
    Found in superset/common/query_context_processor.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 get_viz_annotation_data has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_viz_annotation_data(
            annotation_layer: dict[str, Any], force: bool
        ) -> dict[str, Any]:
            # pylint: disable=import-outside-toplevel
            from superset.commands.chart.data.get_data_command import ChartDataCommand
    Severity: Minor
    Found in superset/common/query_context_processor.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 join_offset_dfs has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def join_offset_dfs(
            self,
            df: pd.DataFrame,
            offset_dfs: dict[str, pd.DataFrame],
            time_grain: str | None,
    Severity: Minor
    Found in superset/common/query_context_processor.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 generate_join_column has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def generate_join_column(
            row: pd.Series,
            column_index: int,
            time_grain: str,
            time_offset: str | None = None,
    Severity: Minor
    Found in superset/common/query_context_processor.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 get_df_payload has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def get_df_payload(
            self, query_obj: QueryObject, force_cached: bool | None = False
        ) -> dict[str, Any]:
            """Handles caching around the df payload retrieval"""
            cache_key = self.query_cache_key(query_obj)
    Severity: Minor
    Found in superset/common/query_context_processor.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

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

        def normalize_df(self, df: pd.DataFrame, query_object: QueryObject) -> pd.DataFrame:
            # todo: should support "python_date_format" and "get_column" in each datasource
            def _get_timestamp_format(
                source: BaseDatasource, column: str | None
            ) -> str | None:
    Severity: Minor
    Found in superset/common/query_context_processor.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 add_offset_join_column has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def add_offset_join_column(
    Severity: Minor
    Found in superset/common/query_context_processor.py - About 35 mins to fix

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

          def get_query_result(self, query_object: QueryObject) -> QueryResult:
              """Returns a pandas dataframe based on the query object"""
              query_context = self._query_context
              # Here, we assume that all the queries will use the same datasource, which is
              # a valid assumption for current setting. In the long term, we may
      Severity: Minor
      Found in superset/common/query_context_processor.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_data has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          def get_data(
              self, df: pd.DataFrame, coltypes: list[GenericDataType]
          ) -> str | list[dict[str, Any]]:
              if self._query_context.result_format in ChartDataResultFormat.table_like():
                  include_index = not isinstance(df.index, pd.RangeIndex)
      Severity: Minor
      Found in superset/common/query_context_processor.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

      Avoid too many return statements within this function.
      Open

                      return value.strftime("%Y")
      Severity: Major
      Found in superset/common/query_context_processor.py - About 30 mins to fix

        Avoid too many return statements within this function.
        Open

                return str(value)
        Severity: Major
        Found in superset/common/query_context_processor.py - About 30 mins to fix

          There are no issues that match your filters.

          Category
          Status