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
2e012f6b
Commit
2e012f6b
authored
3 years ago
by
Daniel Lyons
Committed by
Daniel Lyons
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Descending into filegroups and files successfully
parent
374edb24
No related branches found
No related tags found
1 merge request
!343
Core sampler
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
apps/cli/utilities/core_sampler/core_sampler/core_sampler.py
+22
-15
22 additions, 15 deletions
apps/cli/utilities/core_sampler/core_sampler/core_sampler.py
with
22 additions
and
15 deletions
apps/cli/utilities/core_sampler/core_sampler/core_sampler.py
+
22
−
15
View file @
2e012f6b
...
...
@@ -128,6 +128,19 @@ class Table:
:return: a RowSet with the row in it
"""
# 1. Determine the primary key columns
primary_key_columns
=
self
.
primary_key_columns
()
# 2. Generate the WHERE clause
pkey
=
{
column_name
:
primary_key
[
column_name
]
for
column_name
in
primary_key_columns
}
whereclause
=
"
AND
"
.
join
(
f
"
{
name
}
= %(
{
name
}
)s
"
for
name
in
pkey
.
keys
())
# 3. Run the query
self
.
cursor
.
execute
(
f
"
SELECT * FROM
{
self
.
name
}
WHERE
{
whereclause
}
"
,
pkey
)
# 4. Manufacture the result
return
RowSet
(
self
.
cursor
,
self
,
self
.
cursor
.
fetchall
())
def
primary_key_columns
(
self
):
self
.
cursor
.
execute
(
"""
SELECT c.column_name
FROM information_schema.table_constraints tc
...
...
@@ -139,18 +152,8 @@ class Table:
tc.table_name = %(tablename)s
"""
,
dict
(
tablename
=
self
.
name
),
)
primary_key_columns
=
[
r
[
"
column_name
"
]
for
r
in
self
.
cursor
.
fetchall
()]
# 2. Generate the WHERE clause
pkey
=
{
column_name
:
primary_key
[
column_name
]
for
column_name
in
primary_key_columns
}
whereclause
=
"
AND
"
.
join
(
f
"
{
name
}
= %(
{
name
}
)s
"
for
name
in
pkey
.
keys
())
# 3. Run the query
self
.
cursor
.
execute
(
f
"
SELECT * FROM
{
self
.
name
}
WHERE
{
whereclause
}
"
,
pkey
)
# 4. Manufacture the result
return
RowSet
(
self
.
cursor
,
self
,
self
.
cursor
.
fetchall
())
return
primary_key_columns
def
fetch_according_to
(
self
,
rows
:
"
RowSet
"
,
columns
:
list
[
str
]):
"""
...
...
@@ -160,17 +163,21 @@ class Table:
:param columns: columns to consider in the generated WHERE clause
:return: RowSet for the rows in this table
"""
print
(
f
"
fetching from
{
self
.
name
}
"
)
# 1. generate the where clause
escaped
=
[
self
.
escape
(
row
[
column
])
for
column
in
columns
for
row
in
rows
if
row
[
column
]
is
not
None
]
# 1. Escape the WHERE clause entries. it's important to use the primary keys
# to retrieve the values from the previous resultset; the new columns will
# appear in the query below.
key_columns
=
rows
.
table
.
primary_key_columns
()
escaped
=
[
self
.
escape
(
row
[
column
])
for
column
in
key_columns
for
row
in
rows
if
row
[
column
]
is
not
None
]
# If we have no escaped entries, then there won't be anything in the resultset and we can return now
if
len
(
escaped
)
==
0
:
return
RowSet
(
self
.
cursor
,
self
,
[])
# 2. Build the WHERE clause
whereclause
=
f
"
(
{
'
,
'
.
join
(
columns
)
}
) IN (
{
'
,
'
.
join
(
escaped
)
}
)
"
#
2
.
s
end the query off and make the result
#
3
.
S
end the query off and make the result
self
.
cursor
.
execute
(
f
"
SELECT * FROM
{
self
.
name
}
WHERE
{
whereclause
}
"
)
return
RowSet
(
self
.
cursor
,
self
,
self
.
cursor
.
fetchall
())
...
...
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