-
Notifications
You must be signed in to change notification settings - Fork 90
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
Include size in pkgselect responses #1744
Merged
Merged
Changes from 6 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
51f8d1f
Include size in pkgselect responses
be16f30
Add physical key
a745d06
Avoid double encoding strings and update tests
43c9f4e
Add package-level & directory-level meta
b4cea4f
Move meta inside contents
05a2fe1
Drop physical key for prefixes
85637c3
Fix tests
8d26196
disable `raise-missing-from` in pylint
04a14b6
disable `super-with-arguments` in pylint
aa32faf
pylint cleanup
ca1bbff
comments
6c7942f
Update lambdas/pkgselect/index.py
kevinemoore 7489fc7
linter
975066e
Merge branch 'pkgselect-size' of https://github.com/quiltdata/quilt i…
af31ec2
Merge branch 'master' into pkgselect-size
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,10 +56,17 @@ def file_list_to_folder(df: pd.DataFrame) -> dict: | |
lambda). | ||
""" | ||
try: | ||
folder = pd.Series(df.logical_key.dropna().str.extract('([^/]+/?).*')[0].unique()) | ||
prefixes = folder[folder.str.endswith('/')].sort_values().tolist() | ||
objects = folder[~folder.str.endswith('/')].sort_values().tolist() | ||
except AttributeError: | ||
groups = df.groupby(df.logical_key.str.extract('([^/]+/?).*')[0], dropna=True) | ||
folder = groups.agg( | ||
size=('size', 'sum'), | ||
physical_key=('physical_key', 'first') | ||
) | ||
folder.reset_index(inplace=True) | ||
kevinemoore marked this conversation as resolved.
Show resolved
Hide resolved
|
||
folder.rename(columns={0: 'logical_key'}, inplace=True) | ||
# Do not return physical_key for prefixes | ||
prefixes = folder[folder.logical_key.str.contains('/')].drop(['physical_key'], axis=1).to_dict(orient='records') | ||
objects = folder[~folder.logical_key.str.contains('/')].to_dict(orient='records') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens in keys with successive There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. // is illegal in logical keys isn't it? |
||
except AttributeError as err: | ||
# Pandas will raise an attribute error if the DataFrame has | ||
# no rows with a non-null logical_key. We expect that case if | ||
# either: (1) the package is empty (has zero package entries) | ||
|
@@ -172,7 +179,8 @@ def lambda_handler(request): | |
# Call s3 select to fetch only logical keys matching the | ||
# desired prefix (folder path) | ||
prefix_length = len(prefix) if prefix is not None else 0 | ||
sql_stmt = f"SELECT SUBSTRING(s.logical_key, {prefix_length + 1}) AS logical_key FROM s3object s" | ||
sql_stmt = f"SELECT SUBSTRING(s.logical_key, {prefix_length + 1}) AS logical_key" | ||
sql_stmt += ", s.\"size\", s.physical_keys[0] as physical_key FROM s3object s" | ||
kevinemoore marked this conversation as resolved.
Show resolved
Hide resolved
kevinemoore marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if prefix: | ||
sql_stmt += f" WHERE SUBSTRING(s.logical_key, 1, {prefix_length}) = '{sql_escape(prefix)}'" | ||
result = query_manifest_content( | ||
|
@@ -185,6 +193,20 @@ def lambda_handler(request): | |
df = pd.read_json(result, lines=True) | ||
response_data = file_list_to_folder(df) | ||
|
||
# Fetch package-level or directory-level metadata | ||
if prefix: | ||
sql_stmt = f"SELECT s.meta FROM s3object s WHERE s.logical_key = '{sql_escape(prefix)}'" | ||
else: | ||
sql_stmt = "SELECT s.* FROM s3object s WHERE s.logical_key is NULL" | ||
result = query_manifest_content( | ||
s3_client, | ||
bucket=bucket, | ||
key=key, | ||
sql_stmt=sql_stmt | ||
) | ||
meta = json.load(result) if result else {} | ||
response_data.update(dict(meta=meta)) | ||
|
||
ret_val = make_json_response( | ||
200, | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this automatically skip undefined values?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes.