Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
workspaces
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ssa
workspaces
Commits
726dc7a7
Commit
726dc7a7
authored
1 year ago
by
Brittany Faciane
Browse files
Options
Downloads
Patches
Plain Diff
Fix the core sampler access to project code linking table.
parent
de160c0a
Loading
Loading
3 merge requests
!1606
catch 2.8.3 up with main
,
!1605
Merge 2.8.2.3 work to main
,
!1589
Fix the core sampler access to project code linking table.
Pipeline
#14491
passed
1 year ago
Stage: pull-db
Stage: build-packages
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/cli/utilities/core_sampler/core_sampler/core_sampler.py
+36
-0
36 additions, 0 deletions
apps/cli/utilities/core_sampler/core_sampler/core_sampler.py
with
36 additions
and
0 deletions
apps/cli/utilities/core_sampler/core_sampler/core_sampler.py
+
36
−
0
View file @
726dc7a7
...
...
@@ -170,6 +170,15 @@ class CoreSampler:
self
.
visited
.
clear
()
self
.
save
(
ancillary_rows
)
# the science products table doesn't directly connect to the projects table via a key,
# so the sampler can't find them by default; grab the project code entries manually
products_projects
=
self
.
table
(
"
science_products_projects
"
)
finder
=
ProductsProjectsFinder
(
self
.
connection
)
project_codes
=
finder
.
find_project_codes_for_product
(
science_product_locators
)
products_projects_rows
=
products_projects
.
fetch_from_many
(
{
"
project_code
"
:
project_codes
,
"
science_product_locator
"
:
science_product_locators
})
self
.
save
(
products_projects_rows
)
# finally, grab the files associated with the entries
filegroup_ids
=
[
row
[
"
filegroup_id
"
]
for
row
in
science_product_rows
]
+
\
[
row
[
"
filegroup_id
"
]
for
row
in
ancillary_rows
]
...
...
@@ -207,10 +216,19 @@ class CoreSampler:
ancillary_product_locators
=
finder
.
find_ancillary_product_locators
(
product_group_id
,
science_product_locators
)
requested_ancillary_rows
=
ancillary_products
.
fetch_from_many
({
"
ancillary_product_locator
"
:
ancillary_product_locators
})
# the science products table doesn't directly connect to the projects table via a key,
# so the sampler can't find them by default; grab the project code entries manually
products_projects
=
self
.
table
(
"
science_products_projects
"
)
finder
=
ProductsProjectsFinder
(
self
.
connection
)
project_codes
=
finder
.
find_project_codes_for_product
(
science_product_locators
)
requested_project_product_rows
=
products_projects
.
fetch_from_many
(
{
"
project_code
"
:
project_codes
,
"
science_product_locator
"
:
science_product_locators
})
# Create one dictionary pairing table names to row sets
rows_dict
=
self
.
create_row_dict
(
requested_product_group_rows
,
{})
rows_dict
=
self
.
create_row_dict
(
requested_product_rows
,
rows_dict
)
rows_dict
=
self
.
create_row_dict
(
requested_ancillary_rows
,
rows_dict
)
rows_dict
=
self
.
create_row_dict
(
requested_project_product_rows
,
rows_dict
)
# the correct table deletion order is not the same as the reverse of the topographic map, set the order
deletion_order
=
[
"
ancillary_products
"
,
"
science_products_projects
"
,
"
science_products_product_groups
"
,
...
...
@@ -326,6 +344,24 @@ class CoreSampler:
rows
.
write_to
(
self
.
writer
)
class
ProductsProjectsFinder
:
"""
Looks up project codes for a list of spls
"""
def
__init__
(
self
,
connection
:
MDDBConnector
):
self
.
connection
=
connection
def
find_project_codes_for_product
(
self
,
spls
:
[
str
])
->
[
str
]:
cursor
=
self
.
connection
.
cursor
()
sql
=
"""
SELECT project_code FROM science_products_projects
WHERE science_product_locator IN %(spls)s
"""
cursor
.
execute
(
sql
,
{
"
spls
"
:
tuple
(
spls
)})
data
=
cursor
.
fetchall
()
# All spls will have the same project code, but return a list with a length matching the spls list
return
[
data
[
0
][
"
project_code
"
]]
*
len
(
spls
)
class
ProductFinder
:
"""
Looks up science product locators for a product group id
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment