zhaoyongjie commented on a change in pull request #15279:
URL: https://github.com/apache/superset/pull/15279#discussion_r677950784
##########
File path: superset/common/query_context.py
##########
@@ -101,21 +111,143 @@ def __init__( # pylint: disable=too-many-arguments
"result_format": self.result_format,
}
- def get_query_result(self, query_object: QueryObject) -> Dict[str, Any]:
- """Returns a pandas dataframe based on the query object"""
+ @staticmethod
+ def left_join_on_dttm(
+ left_df: pd.DataFrame, right_df: pd.DataFrame
+ ) -> pd.DataFrame:
+ df = left_df.set_index(DTTM_ALIAS).join(right_df.set_index(DTTM_ALIAS))
+ df.reset_index(level=0, inplace=True)
+ return df
+
+ def processing_time_offsets(
+ self, df: pd.DataFrame, query_object: QueryObject,
+ ) -> CachedTimeOffset:
+ # ensure query_object is immutable
+ query_object_clone = copy.copy(query_object)
+ queries = []
+ cache_keys = []
+
+ time_offsets = query_object.time_offsets
+ outer_from_dttm = query_object.from_dttm
+ outer_to_dttm = query_object.to_dttm
+ for offset in time_offsets:
+ try:
+ query_object_clone.from_dttm = get_past_or_future(
+ offset, outer_from_dttm,
+ )
+ query_object_clone.to_dttm = get_past_or_future(offset,
outer_to_dttm)
+ except ValueError as ex:
+ raise QueryObjectValidationError(str(ex))
+ # make sure subquery use main query where clause
+ query_object_clone.inner_from_dttm = outer_from_dttm
+ query_object_clone.inner_to_dttm = outer_to_dttm
+ query_object_clone.time_offsets = []
+ query_object_clone.post_processing = []
+
+ if not query_object.from_dttm or not query_object.to_dttm:
+ raise QueryObjectValidationError(
+ _(
+ "An enclosed time range (both start and end) must be
specified "
+ "when using a Time Comparison."
+ )
+ )
+ # `offset` is added to the hash function
+ cache_key = self.query_cache_key(query_object_clone,
time_offset=offset)
+ _cache = QueryCacheManager.get(cache_key, CacheRegion.DATA,
self.force)
Review comment:
Just for private variables. I will rename `_cache` to `cache`
##########
File path: superset/common/query_context.py
##########
@@ -101,21 +111,143 @@ def __init__( # pylint: disable=too-many-arguments
"result_format": self.result_format,
}
- def get_query_result(self, query_object: QueryObject) -> Dict[str, Any]:
- """Returns a pandas dataframe based on the query object"""
+ @staticmethod
+ def left_join_on_dttm(
+ left_df: pd.DataFrame, right_df: pd.DataFrame
+ ) -> pd.DataFrame:
+ df = left_df.set_index(DTTM_ALIAS).join(right_df.set_index(DTTM_ALIAS))
+ df.reset_index(level=0, inplace=True)
+ return df
+
+ def processing_time_offsets(
+ self, df: pd.DataFrame, query_object: QueryObject,
+ ) -> CachedTimeOffset:
+ # ensure query_object is immutable
+ query_object_clone = copy.copy(query_object)
+ queries = []
+ cache_keys = []
+
+ time_offsets = query_object.time_offsets
+ outer_from_dttm = query_object.from_dttm
+ outer_to_dttm = query_object.to_dttm
+ for offset in time_offsets:
+ try:
+ query_object_clone.from_dttm = get_past_or_future(
+ offset, outer_from_dttm,
+ )
+ query_object_clone.to_dttm = get_past_or_future(offset,
outer_to_dttm)
+ except ValueError as ex:
+ raise QueryObjectValidationError(str(ex))
+ # make sure subquery use main query where clause
+ query_object_clone.inner_from_dttm = outer_from_dttm
+ query_object_clone.inner_to_dttm = outer_to_dttm
+ query_object_clone.time_offsets = []
+ query_object_clone.post_processing = []
+
+ if not query_object.from_dttm or not query_object.to_dttm:
+ raise QueryObjectValidationError(
+ _(
+ "An enclosed time range (both start and end) must be
specified "
+ "when using a Time Comparison."
+ )
+ )
+ # `offset` is added to the hash function
+ cache_key = self.query_cache_key(query_object_clone,
time_offset=offset)
+ _cache = QueryCacheManager.get(cache_key, CacheRegion.DATA,
self.force)
Review comment:
Just for private variables. I will rename `_cache` to `cache` for more
readable
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]