Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing use of timestamp keyword in snowflake query #1014

Merged
merged 3 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions data-workflows/activity/github_activity_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from pynamodb.attributes import UnicodeAttribute, NumberAttribute

from utils.utils import get_current_timestamp, date_to_utc_timestamp_in_millis, datetime_to_utc_timestamp_in_millis
from plugin.helpers import _get_cache, _get_repo_to_plugin_dict
from plugin.helpers import _get_repo_to_plugin_dict


LOGGER = logging.getLogger()
Expand All @@ -27,11 +27,11 @@ def __new__(cls, timestamp_formatter, type_identifier_formatter, query_projectio
return github_activity_type

LATEST = (datetime_to_utc_timestamp_in_millis, 'LATEST:{0}',
'repo AS name, to_timestamp(max(commit_author_date)) as latest_commit', 'name')
'repo AS name, to_timestamp(max(commit_author_date)) AS latest_commit', 'name')
manasaV3 marked this conversation as resolved.
Show resolved Hide resolved
MONTH = (date_to_utc_timestamp_in_millis, 'MONTH:{1:%Y%m}:{0}',
'repo AS name, date_trunc("month", to_date(commit_author_date)) as month, count(*) as commit_count',
'repo AS name, date_trunc("month", to_date(commit_author_date)) AS month, count(*) AS commit_count',
manasaV3 marked this conversation as resolved.
Show resolved Hide resolved
'name, month')
TOTAL = (lambda timestamp: None, 'TOTAL:{0}', 'repo AS name, count(*) as commit_count', 'name')
TOTAL = (lambda timestamp: None, 'TOTAL:{0}', 'repo AS name, count(*) AS commit_count', 'name')
manasaV3 marked this conversation as resolved.
Show resolved Hide resolved

def format_to_timestamp(self, timestamp: datetime) -> Union[int, None]:
return self.timestamp_formatter(timestamp)
Expand Down
6 changes: 3 additions & 3 deletions data-workflows/activity/snowflake_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ def get_plugins_install_count_since_timestamp(plugins_by_earliest_ts: dict[str,
query = f"""
SELECT
LOWER(file_project) AS name,
{install_activity_type.get_query_timestamp_projection()} AS timestamp,
{install_activity_type.get_query_timestamp_projection()} AS ts,
COUNT(*) AS count
FROM
imaging.pypi.labeled_downloads
WHERE
download_type = 'pip'
AND project_type = 'plugin'
AND ({_generate_subquery_by_type(plugins_by_earliest_ts, install_activity_type)})
GROUP BY name, timestamp
ORDER BY name, timestamp
GROUP BY name, ts
ORDER BY name, ts
"""
LOGGER.info(f'Fetching data for granularity={install_activity_type.name}')
return _mapped_query_results(query, 'PYPI', {}, _cursor_to_plugin_activity_mapper)
Expand Down
6 changes: 3 additions & 3 deletions data-workflows/activity/tests/test_snowflake_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ def get_plugins_install_count_since_timestamp_query(projection, subquery):
return f"""
SELECT
LOWER(file_project) AS name,
{projection} AS timestamp,
{projection} AS ts,
COUNT(*) AS count
FROM
imaging.pypi.labeled_downloads
WHERE
download_type = 'pip'
AND project_type = 'plugin'
AND ({subquery})
GROUP BY name, timestamp
ORDER BY name, timestamp
GROUP BY name, ts
ORDER BY name, ts
"""


Expand Down
Loading