You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "michael-s-molina (via GitHub)" <gi...@apache.org> on 2023/05/22 16:50:37 UTC

[GitHub] [superset] michael-s-molina opened a new pull request, #24176: fix: Time shifts with different granularity for ECharts

michael-s-molina opened a new pull request, #24176:
URL: https://github.com/apache/superset/pull/24176

   ### SUMMARY
   TODO
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   <img width="1774" alt="Screenshot 2023-05-22 at 13 24 36" src="https://github.com/apache/superset/assets/70410625/e2bc854a-2f4b-4e5c-846b-fad2d2e1d711">
   <img width="1777" alt="Screenshot 2023-05-22 at 13 26 02" src="https://github.com/apache/superset/assets/70410625/9b9d385b-5a9f-4bab-9481-6a7fa8327d1a">
   
   ### TESTING INSTRUCTIONS
   1 - Choose a dataset with plenty of temporal data available
   2 - Create a Line Chart (ECharts)
   3 - Play with different Time Grains and Time Shifts
   4 - Make sure the offsets are correctly calculated
   
   ### ADDITIONAL INFORMATION
   - [ ] Has associated issue:
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] Migration is atomic, supports rollback & is backwards-compatible
     - [ ] Confirm DB migration upgrade and downgrade tested
     - [ ] Runtime estimates and downtime expectations provided
   - [ ] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1223101908


##########
tests/unit_tests/common/test_get_aggregated_join_column.py:
##########
@@ -0,0 +1,73 @@
+# 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
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from pandas import DataFrame, Series, Timestamp
+from pandas.testing import assert_frame_equal
+from pytest import mark
+
+from superset.common.chart_data import ChartDataResultFormat, ChartDataResultType
+from superset.common.query_context import QueryContext
+from superset.common.query_context_processor import (
+    AGGREGATED_JOIN_COLUMN,
+    QueryContextProcessor,
+)
+from superset.connectors.base.models import BaseDatasource
+from superset.constants import TimeGrain
+
+query_context_processor = QueryContextProcessor(
+    QueryContext(
+        datasource=BaseDatasource(),
+        queries=[],
+        result_type=ChartDataResultType.COLUMNS,
+        form_data={},
+        slice_=None,
+        result_format=ChartDataResultFormat.CSV,
+        cache_values={},
+    )
+)
+
+
+def join_column_producer(row: Series, column_index: int) -> str:
+    return "CUSTOM_FORMAT"

Review Comment:
   Done



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1223052717


##########
superset/db_engine_specs/base.py:
##########
@@ -80,25 +81,25 @@ class TimeGrain(NamedTuple):
 
 
 builtin_time_grains: dict[str | None, str] = {
-    "PT1S": __("Second"),

Review Comment:
   Check this [comment](https://github.com/apache/superset/pull/24176#discussion_r1214443954)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1214443954


##########
superset/common/query_context_processor.py:
##########
@@ -444,10 +467,48 @@ def processing_time_offsets(  # pylint: disable=too-many-locals,too-many-stateme
                 datasource_uid=query_context.datasource.uid,
                 region=CacheRegion.DATA,
             )
-            rv_dfs.append(offset_slice)
+            offset_dfs.append(offset_metrics_df)
+
+        if offset_dfs:
+            # iterate on offset_dfs, left join each with df
+            for offset_df in offset_dfs:
+                df = dataframe_utils.left_join_df(
+                    left_df=df,
+                    right_df=offset_df,
+                    join_keys=join_keys,
+                    rsuffix="_right",
+                )
+
+        # remove AGGREGATED_JOIN_COLUMN from df
+        if use_aggregated_join_column:
+            df.drop(columns=[AGGREGATED_JOIN_COLUMN], inplace=True)
 
-        rv_df = pd.concat(rv_dfs, axis=1, copy=False) if time_offsets else df
-        return CachedTimeOffset(df=rv_df, queries=queries, cache_keys=cache_keys)
+        return CachedTimeOffset(df=df, queries=queries, cache_keys=cache_keys)
+
+    @staticmethod
+    def get_aggregated_join_column(
+        row: pd.Series, column_index: int, time_grain: str

Review Comment:
   `TimeGrain` is a `string` because we have some configurations defined as strings and changing them would constitute breaking changes and the window is already closed.
   
   ```
   TIME_GRAIN_DENYLIST: list[str] = []
   TIME_GRAIN_ADDONS: dict[str, str] = {}
   TIME_GRAIN_ADDON_EXPRESSIONS: dict[str, dict[str, str]] = {}
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] zhaoyongjie commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "zhaoyongjie (via GitHub)" <gi...@apache.org>.
zhaoyongjie commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1204715910


##########
superset/common/query_context_processor.py:
##########
@@ -444,10 +460,47 @@ def processing_time_offsets(  # pylint: disable=too-many-locals,too-many-stateme
                 datasource_uid=query_context.datasource.uid,
                 region=CacheRegion.DATA,
             )
-            rv_dfs.append(offset_slice)
+            offset_dfs.append(offset_metrics_df)
+
+        if offset_dfs:
+            # iterate on offset_dfs, left join each with df
+            for offset_df in offset_dfs:
+                df = dataframe_utils.left_join_df(
+                    left_df=df,
+                    right_df=offset_df,
+                    join_keys=join_keys,
+                    rsuffix="_right",
+                )
+
+        # remove AGGREGATED_JOIN_COLUMN from df
+        if use_aggregated_join_column:
+            df = df.drop(columns=[self.AGGREGATED_JOIN_COLUMN])
+
+        return CachedTimeOffset(df=df, queries=queries, cache_keys=cache_keys)
+
+    def get_aggregated_join_column(
+        self, row: pd.Series, column_index: int, time_grain: str
+    ) -> str:
+        # weekly time grain
+        if "P1W" in time_grain:
+            if time_grain in (
+                WeeklyTimeGrain.WEEK_STARTING_SUNDAY,
+                WeeklyTimeGrain.WEEK_ENDING_SATURDAY,
+            ):
+                return row[column_index].strftime("%Y-W%U")
+            else:
+                return row[column_index].strftime("%Y-W%W")
+
+        # monthly time grain
+        elif "P1M" in time_grain:
+            return row[column_index].strftime("%Y-%m")
+
+        # quarterly time grain
+        elif "P3M" in time_grain:
+            return row[column_index].strftime("%Y-Q") + str(row[column_index].quarter)
 
-        rv_df = pd.concat(rv_dfs, axis=1, copy=False) if time_offsets else df
-        return CachedTimeOffset(df=rv_df, queries=queries, cache_keys=cache_keys)
+        # yearly time grain
+        return row[column_index].strftime("%Y")

Review Comment:
   Hi @michael-s-molina, I'm great! These part codes are really important for the post processing calculation, so we should keep more eyes on the performance and maintainability! 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1213286077


##########
superset/common/query_context_processor.py:
##########
@@ -307,6 +324,20 @@ def _get_timestamp_format(
 
         return df
 
+    def get_time_grain(
+        self, query_context: QueryContext, query_object: QueryObject
+    ) -> Optional[Any]:
+        if query_context.form_data:
+            return query_context.form_data.get("time_grain_sqla")
+
+        if query_object.columns and len(query_object.columns) > 0:
+            # If the time grain is in the columns it will be the first one
+            # and it will be of AdhocColumn type
+            if isinstance(query_object.columns[0], dict):
+                return query_object.columns[0].get("timeGrain")
+
+        return query_object.extras.get("time_grain_sqla")

Review Comment:
   The joys of Superset and its N different ways to store/retrieve the same information 🤦



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] john-bodley commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "john-bodley (via GitHub)" <gi...@apache.org>.
john-bodley commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1212110157


##########
superset/common/query_context_processor.py:
##########
@@ -74,6 +74,19 @@
 stats_logger: BaseStatsLogger = config["STATS_LOGGER"]
 logger = logging.getLogger(__name__)
 
+AGGREGATED_JOIN_COLUMN = "__aggregated_join_column"
+
+AGGREGATED_JOIN_GRAINS = {

Review Comment:
   @michael-s-molina how are other time grains—day, hour, minute, etc.—handled?



##########
superset/db_engine_specs/base.py:
##########
@@ -63,6 +63,7 @@
 from typing_extensions import TypedDict
 
 from superset import security_manager, sql_parse
+from superset.constants import TimeGrain as TimeGrainConstants

Review Comment:
   Why do we need to alias `TimeGrain` here?



##########
superset/common/query_context_processor.py:
##########
@@ -444,10 +467,48 @@ def processing_time_offsets(  # pylint: disable=too-many-locals,too-many-stateme
                 datasource_uid=query_context.datasource.uid,
                 region=CacheRegion.DATA,
             )
-            rv_dfs.append(offset_slice)
+            offset_dfs.append(offset_metrics_df)
+
+        if offset_dfs:
+            # iterate on offset_dfs, left join each with df
+            for offset_df in offset_dfs:
+                df = dataframe_utils.left_join_df(
+                    left_df=df,
+                    right_df=offset_df,
+                    join_keys=join_keys,
+                    rsuffix="_right",
+                )
+
+        # remove AGGREGATED_JOIN_COLUMN from df
+        if use_aggregated_join_column:
+            df.drop(columns=[AGGREGATED_JOIN_COLUMN], inplace=True)
 
-        rv_df = pd.concat(rv_dfs, axis=1, copy=False) if time_offsets else df
-        return CachedTimeOffset(df=rv_df, queries=queries, cache_keys=cache_keys)
+        return CachedTimeOffset(df=df, queries=queries, cache_keys=cache_keys)
+
+    @staticmethod
+    def get_aggregated_join_column(
+        row: pd.Series, column_index: int, time_grain: str

Review Comment:
   Should `time_grain` be defined as `TimeGrain` rather than `str`?



##########
superset/db_engine_specs/ascend.py:
##########
@@ -16,6 +16,7 @@
 # under the License.
 from sqlalchemy.dialects import registry
 
+from superset.constants import TimeGrain

Review Comment:
   Nice!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on PR #24176:
URL: https://github.com/apache/superset/pull/24176#issuecomment-1572148485

   > 1. IMO, the renaming/refining of TimeGrain should be put in a separate chore pull request rather than this one.
   
   I could do that but I guess I was excited to fix the problem and ended up doing all at once. Sorry if this makes it more difficult to review but I think the important part is that I took the time to improve the code base.
   
   > 2. I can't get result of your screenshot. (on this PR branch)
   
   It was not working indeed with `GENERIC_CHART_AXES` enabled because the query object didn't contain a `time_grain_sqla` field. I submitted a fix to get this from the `form_data` and now it should be working.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1204710408


##########
superset/common/query_context_processor.py:
##########
@@ -444,10 +460,47 @@ def processing_time_offsets(  # pylint: disable=too-many-locals,too-many-stateme
                 datasource_uid=query_context.datasource.uid,
                 region=CacheRegion.DATA,
             )
-            rv_dfs.append(offset_slice)
+            offset_dfs.append(offset_metrics_df)
+
+        if offset_dfs:
+            # iterate on offset_dfs, left join each with df
+            for offset_df in offset_dfs:
+                df = dataframe_utils.left_join_df(
+                    left_df=df,
+                    right_df=offset_df,
+                    join_keys=join_keys,
+                    rsuffix="_right",
+                )
+
+        # remove AGGREGATED_JOIN_COLUMN from df
+        if use_aggregated_join_column:
+            df = df.drop(columns=[self.AGGREGATED_JOIN_COLUMN])
+
+        return CachedTimeOffset(df=df, queries=queries, cache_keys=cache_keys)
+
+    def get_aggregated_join_column(
+        self, row: pd.Series, column_index: int, time_grain: str
+    ) -> str:
+        # weekly time grain
+        if "P1W" in time_grain:
+            if time_grain in (
+                WeeklyTimeGrain.WEEK_STARTING_SUNDAY,
+                WeeklyTimeGrain.WEEK_ENDING_SATURDAY,
+            ):
+                return row[column_index].strftime("%Y-W%U")
+            else:
+                return row[column_index].strftime("%Y-W%W")
+
+        # monthly time grain
+        elif "P1M" in time_grain:
+            return row[column_index].strftime("%Y-%m")
+
+        # quarterly time grain
+        elif "P3M" in time_grain:
+            return row[column_index].strftime("%Y-Q") + str(row[column_index].quarter)
 
-        rv_df = pd.concat(rv_dfs, axis=1, copy=False) if time_offsets else df
-        return CachedTimeOffset(df=rv_df, queries=queries, cache_keys=cache_keys)
+        # yearly time grain
+        return row[column_index].strftime("%Y")

Review Comment:
   Hi @zhaoyongjie. Hope you're doing fine! This PR is still in draft mode, that's why there's no description yet 😉 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] villebro commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "villebro (via GitHub)" <gi...@apache.org>.
villebro commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1203575002


##########
superset/common/query_context_processor.py:
##########
@@ -328,7 +325,25 @@ def processing_time_offsets(  # pylint: disable=too-many-locals,too-many-stateme
                     "when using a Time Comparison."
                 )
             )
-        for offset in time_offsets:
+
+        columns = df.columns
+        time_grain = query_object.extras["time_grain_sqla"]
+        use_aggregated_join_column = any(
+            grain in time_grain for grain in ("P1W", "P1M", "P3M", "P1Y")
+        )

Review Comment:
   Could this be made more explicit and at the same time slightly easier to read? I think it might improve readability if we list all the time grains that are applicable, and then just check if `time_grain` is contained in that list. Something like
   ```python
   AGGREGATED_JOIN_GRAINS = {
       "1969-12-28T00:00:00Z/P1W",
       "1969-12-29T00:00:00Z/P1W",
       "P1W/1970-01-03T00:00:00Z",
       "P1W/1970-01-04T00:00:00Z",
       "P1W",
       "P1M",
       "P3M",
       "P1Y",
   }
   ...
   use_aggregated_join_column = time_grain in AGGREGATED_JOIN_GRAINS
   ```



##########
superset/common/query_context_processor.py:
##########
@@ -87,12 +87,10 @@ class QueryContextProcessor:
     to retrieve the data payload for a given viz.
     """
 
+    AGGREGATED_JOIN_COLUMN = "$aggregated_join_column"

Review Comment:
   In general we've assumed that double underscores mean Superset internal columns. For consistency, do you think it could be possible to call this "__aggregated_join_column"?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] zhaoyongjie commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "zhaoyongjie (via GitHub)" <gi...@apache.org>.
zhaoyongjie commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1214670640


##########
superset/common/query_context_processor.py:
##########
@@ -420,21 +487,19 @@ def processing_time_offsets(  # pylint: disable=too-many-locals,too-many-stateme
                         )
                     )
 
+                # modifies temporal column using offset
                 offset_metrics_df[index] = offset_metrics_df[index] - DateOffset(
                     **normalize_time_delta(offset)
                 )

Review Comment:
   the index of `offset_metrics_df` seems constructing an appropriate index for the result of dataframe, if the align of the results incorrect, I think we should find root cause from here.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1217966354


##########
superset/common/query_context_processor.py:
##########
@@ -307,6 +324,40 @@ def _get_timestamp_format(
 
         return df
 
+    @staticmethod
+    def get_time_grain(
+        query_context: QueryContext, query_object: QueryObject
+    ) -> Any | None:
+        if query_context.form_data:
+            return query_context.form_data.get("time_grain_sqla")

Review Comment:
   I can remove this line given that the created function deals with the different `query_object` variations that depend on `GENERIC_CHART_AXES`. I was using the `form_data` because it was the only structure that looks consistent independently of the feature flag.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] villebro commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "villebro (via GitHub)" <gi...@apache.org>.
villebro commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1223042935


##########
superset/common/query_context_processor.py:
##########
@@ -307,6 +324,40 @@ def _get_timestamp_format(
 
         return df
 
+    @staticmethod
+    def get_time_grain(
+        query_context: QueryContext, query_object: QueryObject
+    ) -> Any | None:
+        if query_context.form_data:
+            return query_context.form_data.get("time_grain_sqla")

Review Comment:
   I understand the confusion this causes. I'll try to prepare a follow-up that moves the relevant info from form data into query context/object and removes form data all together.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on PR #24176:
URL: https://github.com/apache/superset/pull/24176#issuecomment-1583216598

   > Draft a [PR](https://github.com/apache/superset/pull/24328/files) to refine the join key generator. please review. Thanks both!
   
   @zhaoyongjie That's not the best way to help reviewing a PR. I spent a lot of time debugging the issue, addressing comments and executing tests using Airbnb charts to get to a solution. If you think the solution can be improved, you can make suggestions, provide more context, contribute code to the PR, etc. 
   
   Completely ignoring the PR and opening your own is not cool 😕 
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] zhaoyongjie commented on pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "zhaoyongjie (via GitHub)" <gi...@apache.org>.
zhaoyongjie commented on PR #24176:
URL: https://github.com/apache/superset/pull/24176#issuecomment-1583244689

   @michael-s-molina 
   I've made the following suggestions during the code review:
   
   1. It would be better to keep this pull request focused on the necessary changes rather than including refactorings and unrelated fixes. Let's aim to minimize the scope of the PR.
   2. We should avoid hard coding values without considering the maintainability for other engineers. 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] villebro commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "villebro (via GitHub)" <gi...@apache.org>.
villebro commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1223047484


##########
superset/constants.py:
##########
@@ -186,6 +186,30 @@ class RouteMethod:  # pylint: disable=too-few-public-methods
 )
 
 
+class TimeGrain:  # pylint: disable=too-few-public-methods

Review Comment:
   I believe this should be
   ```suggestion
   class TimeGrain(str, Enum):
   ```
   



##########
superset/db_engine_specs/base.py:
##########
@@ -80,25 +81,25 @@ class TimeGrain(NamedTuple):
 
 
 builtin_time_grains: dict[str | None, str] = {
-    "PT1S": __("Second"),

Review Comment:
   If you make the `Enum` change above, you should be able to change the above to 
   ```
   builtin_time_grains: dict[Optional[TimeGrainConstants], str] = {
   ```



##########
tests/unit_tests/common/test_get_aggregated_join_column.py:
##########
@@ -0,0 +1,73 @@
+# 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
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from pandas import DataFrame, Series, Timestamp
+from pandas.testing import assert_frame_equal
+from pytest import mark
+
+from superset.common.chart_data import ChartDataResultFormat, ChartDataResultType
+from superset.common.query_context import QueryContext
+from superset.common.query_context_processor import (
+    AGGREGATED_JOIN_COLUMN,
+    QueryContextProcessor,
+)
+from superset.connectors.base.models import BaseDatasource
+from superset.constants import TimeGrain
+
+query_context_processor = QueryContextProcessor(
+    QueryContext(
+        datasource=BaseDatasource(),
+        queries=[],
+        result_type=ChartDataResultType.COLUMNS,
+        form_data={},
+        slice_=None,
+        result_format=ChartDataResultFormat.CSV,
+        cache_values={},
+    )
+)
+
+
+def join_column_producer(row: Series, column_index: int) -> str:
+    return "CUSTOM_FORMAT"

Review Comment:
   style nit: it would probably be best practice to define this as a `@pytest.fixture`



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1212132275


##########
superset/common/query_context_processor.py:
##########
@@ -74,6 +74,19 @@
 stats_logger: BaseStatsLogger = config["STATS_LOGGER"]
 logger = logging.getLogger(__name__)
 
+AGGREGATED_JOIN_COLUMN = "__aggregated_join_column"
+
+AGGREGATED_JOIN_GRAINS = {

Review Comment:
   These time grains don't require an aggregated join column because time shifts don't influence the join criteria.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1212124286


##########
superset/db_engine_specs/base.py:
##########
@@ -63,6 +63,7 @@
 from typing_extensions import TypedDict
 
 from superset import security_manager, sql_parse
+from superset.constants import TimeGrain as TimeGrainConstants

Review Comment:
   Because there's another class defined in this file with the same name.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] zhaoyongjie commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "zhaoyongjie (via GitHub)" <gi...@apache.org>.
zhaoyongjie commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1204706872


##########
superset/common/query_context_processor.py:
##########
@@ -444,10 +460,47 @@ def processing_time_offsets(  # pylint: disable=too-many-locals,too-many-stateme
                 datasource_uid=query_context.datasource.uid,
                 region=CacheRegion.DATA,
             )
-            rv_dfs.append(offset_slice)
+            offset_dfs.append(offset_metrics_df)
+
+        if offset_dfs:
+            # iterate on offset_dfs, left join each with df
+            for offset_df in offset_dfs:
+                df = dataframe_utils.left_join_df(
+                    left_df=df,
+                    right_df=offset_df,
+                    join_keys=join_keys,
+                    rsuffix="_right",
+                )
+
+        # remove AGGREGATED_JOIN_COLUMN from df
+        if use_aggregated_join_column:
+            df = df.drop(columns=[self.AGGREGATED_JOIN_COLUMN])
+
+        return CachedTimeOffset(df=df, queries=queries, cache_keys=cache_keys)
+
+    def get_aggregated_join_column(
+        self, row: pd.Series, column_index: int, time_grain: str
+    ) -> str:
+        # weekly time grain
+        if "P1W" in time_grain:
+            if time_grain in (
+                WeeklyTimeGrain.WEEK_STARTING_SUNDAY,
+                WeeklyTimeGrain.WEEK_ENDING_SATURDAY,
+            ):
+                return row[column_index].strftime("%Y-W%U")
+            else:
+                return row[column_index].strftime("%Y-W%W")
+
+        # monthly time grain
+        elif "P1M" in time_grain:
+            return row[column_index].strftime("%Y-%m")
+
+        # quarterly time grain
+        elif "P3M" in time_grain:
+            return row[column_index].strftime("%Y-Q") + str(row[column_index].quarter)
 
-        rv_df = pd.concat(rv_dfs, axis=1, copy=False) if time_offsets else df
-        return CachedTimeOffset(df=rv_df, queries=queries, cache_keys=cache_keys)
+        # yearly time grain
+        return row[column_index].strftime("%Y")

Review Comment:
   We must AVOID hard code in the core codebase. Please fill up the more description for this PR.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1221682792


##########
superset/db_engine_specs/base.py:
##########
@@ -80,25 +81,25 @@ class TimeGrain(NamedTuple):
 
 
 builtin_time_grains: dict[str | None, str] = {
-    "PT1S": __("Second"),

Review Comment:
   It's actually not the class but the string values defined in it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1217873928


##########
superset/common/query_context_processor.py:
##########
@@ -420,21 +487,19 @@ def processing_time_offsets(  # pylint: disable=too-many-locals,too-many-stateme
                         )
                     )
 
+                # modifies temporal column using offset
                 offset_metrics_df[index] = offset_metrics_df[index] - DateOffset(
                     **normalize_time_delta(offset)
                 )

Review Comment:
   I'm not sure if I understand what you're suggesting. Can you explain more?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on PR #24176:
URL: https://github.com/apache/superset/pull/24176#issuecomment-1580918236

   @villebro I addressed your comments.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] zhaoyongjie commented on pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "zhaoyongjie (via GitHub)" <gi...@apache.org>.
zhaoyongjie commented on PR #24176:
URL: https://github.com/apache/superset/pull/24176#issuecomment-1583014776

   @villebro @michael-s-molina I'll take another look this PR, give me some time. Thanks!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1213297299


##########
superset/common/query_context_processor.py:
##########
@@ -307,6 +324,24 @@ def _get_timestamp_format(
 
         return df
 
+    @staticmethod
+    def get_time_grain(
+        query_context: QueryContext, query_object: QueryObject
+    ) -> Optional[Any]:
+        if query_context.form_data:
+            return query_context.form_data.get("time_grain_sqla")
+
+        if (
+            query_object.columns
+            and len(query_object.columns) > 0
+            and isinstance(query_object.columns[0], dict)
+        ):
+            # If the time grain is in the columns it will be the first one
+            # and it will be of AdhocColumn type
+            return query_object.columns[0].get("timeGrain")
+
+        return query_object.extras.get("time_grain_sqla")

Review Comment:
   The joys of Superset and its N different ways to store/retrieve the same information 🤦



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1213286077


##########
superset/common/query_context_processor.py:
##########
@@ -307,6 +324,20 @@ def _get_timestamp_format(
 
         return df
 
+    def get_time_grain(
+        self, query_context: QueryContext, query_object: QueryObject
+    ) -> Optional[Any]:
+        if query_context.form_data:
+            return query_context.form_data.get("time_grain_sqla")
+
+        if query_object.columns and len(query_object.columns) > 0:
+            # If the time grain is in the columns it will be the first one
+            # and it will be of AdhocColumn type
+            if isinstance(query_object.columns[0], dict):
+                return query_object.columns[0].get("timeGrain")
+
+        return query_object.extras.get("time_grain_sqla")

Review Comment:
   The joys of Superset and its N different ways to store/retrieve the same information 🤦



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] villebro commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "villebro (via GitHub)" <gi...@apache.org>.
villebro commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1217949437


##########
superset/common/query_context_processor.py:
##########
@@ -328,7 +378,25 @@ def processing_time_offsets(  # pylint: disable=too-many-locals,too-many-stateme
                     "when using a Time Comparison."
                 )
             )
-        for offset in time_offsets:
+
+        columns = df.columns
+        time_grain = self.get_time_grain(query_context, query_object) or TimeGrain.DAY
+        join_column_producer = config["TIME_GRAIN_JOIN_COLUMN_PRODUCERS"].get(
+            time_grain
+        )
+        use_aggregated_join_column = (
+            time_grain in AGGREGATED_JOIN_GRAINS or join_column_producer
+        )

Review Comment:
   Ok, this is a total mininit and functionally they're equivalent, but for readability I'd place the check for `join_column_producer` first, as it takes precedent in downstream logic (this code is generally pretty heavy on the eyes, so any improved readability helps):
   ```suggestion
           use_aggregated_join_column = (
               join_column_producer  or time_grain in AGGREGATED_JOIN_GRAINS
           )
   ```



##########
tests/unit_tests/common/test_get_aggregated_join_column.py:
##########
@@ -0,0 +1,52 @@
+# 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
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from pandas import Timestamp
+
+from superset.common.query_context_processor import QueryContextProcessor
+from superset.constants import TimeGrain
+
+get_aggregated_join_column = QueryContextProcessor.get_aggregated_join_column
+
+row = [Timestamp("2020-01-07")]
+
+
+def test_week_join_column():

Review Comment:
   I notice we don't have any tests for `TIME_GRAIN_JOIN_COLUMN_PRODUCERS` - it'd be nice to add at least one test to guard against future regressions.



##########
superset/common/query_context_processor.py:
##########
@@ -74,6 +74,27 @@
 stats_logger: BaseStatsLogger = config["STATS_LOGGER"]
 logger = logging.getLogger(__name__)
 
+# Artificial column used for joining aggregated offset results
+AGGREGATED_JOIN_COLUMN = "__aggregated_join_column"

Review Comment:
   nit: temporary seems more appropriate here
   ```suggestion
   # Temporary column used for joining aggregated offset results
   AGGREGATED_JOIN_COLUMN = "__aggregated_join_column"
   ```



##########
superset/common/query_context_processor.py:
##########
@@ -328,7 +378,25 @@ def processing_time_offsets(  # pylint: disable=too-many-locals,too-many-stateme
                     "when using a Time Comparison."
                 )
             )
-        for offset in time_offsets:
+
+        columns = df.columns
+        time_grain = self.get_time_grain(query_context, query_object) or TimeGrain.DAY

Review Comment:
   Why are we defaulting to a daily time grain? If it's mandatory, I'd rather return a 400 if it's missing.



##########
superset/db_engine_specs/base.py:
##########
@@ -80,25 +81,25 @@ class TimeGrain(NamedTuple):
 
 
 builtin_time_grains: dict[str | None, str] = {
-    "PT1S": __("Second"),

Review Comment:
   The type declaration on line 82 should be updated; the key should be `TimeGrainConstants`, right?



##########
superset/common/query_context_processor.py:
##########
@@ -307,6 +324,40 @@ def _get_timestamp_format(
 
         return df
 
+    @staticmethod
+    def get_time_grain(
+        query_context: QueryContext, query_object: QueryObject
+    ) -> Any | None:
+        if query_context.form_data:
+            return query_context.form_data.get("time_grain_sqla")

Review Comment:
   I think this should be avoided. The form data has been introduced fairly recently in query_context, and isn't really meant to influence rendering of the query_object (IIRC, it was originally added to relay some context about query timeouts that are defined in the chart object). Is there some reason we are primarily looking at the form data here, and not the query object?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1213284543


##########
superset/common/query_context_processor.py:
##########
@@ -307,6 +324,20 @@ def _get_timestamp_format(
 
         return df
 
+    def get_time_grain(

Review Comment:
   The joys of Superset and its N different ways to store/retrieve the same information :facepalm:



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1221669225


##########
tests/unit_tests/common/test_get_aggregated_join_column.py:
##########
@@ -0,0 +1,52 @@
+# 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
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from pandas import Timestamp
+
+from superset.common.query_context_processor import QueryContextProcessor
+from superset.constants import TimeGrain
+
+get_aggregated_join_column = QueryContextProcessor.get_aggregated_join_column
+
+row = [Timestamp("2020-01-07")]
+
+
+def test_week_join_column():

Review Comment:
   I added a test 👍🏼 



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] zhaoyongjie commented on pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "zhaoyongjie (via GitHub)" <gi...@apache.org>.
zhaoyongjie commented on PR #24176:
URL: https://github.com/apache/superset/pull/24176#issuecomment-1583169481

   @michael-s-molina @villebro 
   
   Draft a PR to refine the join key generator. please review. Thanks both!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina merged pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina merged PR #24176:
URL: https://github.com/apache/superset/pull/24176


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] codecov[bot] commented on pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #24176:
URL: https://github.com/apache/superset/pull/24176#issuecomment-1570713618

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/24176?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#24176](https://app.codecov.io/gh/apache/superset/pull/24176?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (0231f50) into [master](https://app.codecov.io/gh/apache/superset/commit/d1c57e0ddbaece8e61d98e566372d22af6e66885?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (d1c57e0) will **decrease** coverage by `1.63%`.
   > The diff coverage is `95.78%`.
   
   > :exclamation: Current head 0231f50 differs from pull request most recent head b9ddfa4. Consider uploading reports for the commit b9ddfa4 to get more accurate results
   
   ```diff
   @@            Coverage Diff             @@
   ##           master   #24176      +/-   ##
   ==========================================
   - Coverage   68.31%   66.68%   -1.63%     
   ==========================================
     Files        1957     1957              
     Lines       75596    75670      +74     
     Branches     8222     8222              
   ==========================================
   - Hits        51640    50461    -1179     
   - Misses      21848    23101    +1253     
     Partials     2108     2108              
   ```
   
   | Flag | Coverage Δ | |
   |---|---|---|
   | hive | `53.41% <67.36%> (+0.04%)` | :arrow_up: |
   | mysql | `78.95% <95.78%> (+0.03%)` | :arrow_up: |
   | postgres | `79.02% <95.78%> (+0.03%)` | :arrow_up: |
   | presto | `53.34% <67.36%> (+0.04%)` | :arrow_up: |
   | python | `79.43% <95.78%> (-3.39%)` | :arrow_down: |
   | sqlite | `?` | |
   | unit | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   
   | [Impacted Files](https://app.codecov.io/gh/apache/superset/pull/24176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [superset-frontend/src/components/Table/index.tsx](https://app.codecov.io/gh/apache/superset/pull/24176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2NvbXBvbmVudHMvVGFibGUvaW5kZXgudHN4) | `75.29% <ø> (ø)` | |
   | [superset-frontend/src/dashboard/types.ts](https://app.codecov.io/gh/apache/superset/pull/24176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2Rhc2hib2FyZC90eXBlcy50cw==) | `100.00% <ø> (ø)` | |
   | [...set-frontend/src/dashboard/util/permissionUtils.ts](https://app.codecov.io/gh/apache/superset/pull/24176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2Rhc2hib2FyZC91dGlsL3Blcm1pc3Npb25VdGlscy50cw==) | `86.66% <ø> (ø)` | |
   | [...perset-frontend/src/hooks/apiResources/queryApi.ts](https://app.codecov.io/gh/apache/superset/pull/24176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQtZnJvbnRlbmQvc3JjL2hvb2tzL2FwaVJlc291cmNlcy9xdWVyeUFwaS50cw==) | `100.00% <ø> (ø)` | |
   | [superset/common/query\_context\_processor.py](https://app.codecov.io/gh/apache/superset/pull/24176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvY29tbW9uL3F1ZXJ5X2NvbnRleHRfcHJvY2Vzc29yLnB5) | `88.76% <88.57%> (-0.63%)` | :arrow_down: |
   | [superset/common/utils/dataframe\_utils.py](https://app.codecov.io/gh/apache/superset/pull/24176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvY29tbW9uL3V0aWxzL2RhdGFmcmFtZV91dGlscy5weQ==) | `85.71% <100.00%> (-9.53%)` | :arrow_down: |
   | [superset/constants.py](https://app.codecov.io/gh/apache/superset/pull/24176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvY29uc3RhbnRzLnB5) | `100.00% <100.00%> (ø)` | |
   | [superset/db\_engine\_specs/ascend.py](https://app.codecov.io/gh/apache/superset/pull/24176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL2FzY2VuZC5weQ==) | `100.00% <100.00%> (ø)` | |
   | [superset/db\_engine\_specs/athena.py](https://app.codecov.io/gh/apache/superset/pull/24176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL2F0aGVuYS5weQ==) | `70.96% <100.00%> (-22.37%)` | :arrow_down: |
   | [superset/db\_engine\_specs/base.py](https://app.codecov.io/gh/apache/superset/pull/24176?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvZGJfZW5naW5lX3NwZWNzL2Jhc2UucHk=) | `80.46% <100.00%> (-10.34%)` | :arrow_down: |
   | ... and [32 more](https://app.codecov.io/gh/apache/superset/pull/24176?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | |
   
   ... and [66 files with indirect coverage changes](https://app.codecov.io/gh/apache/superset/pull/24176/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] zhaoyongjie commented on pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "zhaoyongjie (via GitHub)" <gi...@apache.org>.
zhaoyongjie commented on PR #24176:
URL: https://github.com/apache/superset/pull/24176#issuecomment-1571040952

   Additionally, I believe that the time grain and time offset granularity should be consistent. We might use same dataset to discuss this topic.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] zhaoyongjie commented on pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "zhaoyongjie (via GitHub)" <gi...@apache.org>.
zhaoyongjie commented on PR #24176:
URL: https://github.com/apache/superset/pull/24176#issuecomment-1571033958

   @michael-s-molina 
   1) IMO, the renaming/refining of TimeGrain should be put in a separate chore pull request rather than this one.
   2) I can't get you result of the screen
   
   <img width="1545" alt="image" src="https://github.com/apache/superset/assets/2016594/33489949-dab1-4d33-9c4c-20bcd03033d5">
   
   
   BTW, If you could provide a dataset for testing, it would be helpful in testing this PR.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] michael-s-molina commented on pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "michael-s-molina (via GitHub)" <gi...@apache.org>.
michael-s-molina commented on PR #24176:
URL: https://github.com/apache/superset/pull/24176#issuecomment-1583254732

   @zhaoyongjie I thought I have addressed both your suggestions with my latest commits. You even removed the **Request Changes** status. Then you asked time to review the PR and suddenly opened your own which was really confusing for me.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


[GitHub] [superset] villebro commented on a diff in pull request #24176: fix: Time shifts with different granularity for ECharts

Posted by "villebro (via GitHub)" <gi...@apache.org>.
villebro commented on code in PR #24176:
URL: https://github.com/apache/superset/pull/24176#discussion_r1223046180


##########
superset/db_engine_specs/base.py:
##########
@@ -80,25 +81,25 @@ class TimeGrain(NamedTuple):
 
 
 builtin_time_grains: dict[str | None, str] = {
-    "PT1S": __("Second"),

Review Comment:
   Oh right - I believe it should in fact be an enum (I'll comment on the relevant line)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org