Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container 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
public
satella
Commits
6d515d7c
Commit
6d515d7c
authored
5 years ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
further improve parallel_for
parent
28b19fc6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
satella/__init__.py
+1
-1
1 addition, 1 deletion
satella/__init__.py
satella/cassandra/__init__.py
+12
-3
12 additions, 3 deletions
satella/cassandra/__init__.py
tests/test_cassandra.py
+11
-1
11 additions, 1 deletion
tests/test_cassandra.py
with
24 additions
and
5 deletions
satella/__init__.py
+
1
−
1
View file @
6d515d7c
__version__
=
'
2.8.15_a
5
'
__version__
=
'
2.8.15_a
6
'
This diff is collapsed.
Click to expand it.
satella/cassandra/__init__.py
+
12
−
3
View file @
6d515d7c
...
...
@@ -14,7 +14,7 @@ def parallel_for(cursor, query: tp.Union[tp.List[str], str, 'Statement', tp.List
>>>
for
future
in
futures
:
>>>
yield
future
.
result
()
If query is a string, or else
If query is a string
or a Cassandra Statement
, or else
>>>
futures
=
[]
>>>
for
query
,
args
in
zip
(
query
,
arguments
):
...
...
@@ -22,6 +22,9 @@ def parallel_for(cursor, query: tp.Union[tp.List[str], str, 'Statement', tp.List
>>>
for
future
in
futures
:
>>>
yield
future
.
result
()
Note that if None is encountered in the argument iterable, session.execute() will
be called with a single argument. You better have it as a BoundStatement then!
:param cursor: the Cassandra cursor to use (obtained using connection.session())
:param query: base query or a list of queries, if a different one is to be used
:param arguments: iterable yielding arguments to use in execute_async
...
...
@@ -30,8 +33,14 @@ def parallel_for(cursor, query: tp.Union[tp.List[str], str, 'Statement', tp.List
if
isinstance
(
query
,
(
str
,
Statement
)):
query
=
itertools
.
repeat
(
query
)
futures
=
[
cursor
.
execute_async
(
query
,
args
)
for
query
,
args
in
zip
(
query
,
arguments
)]
futures
=
[]
for
query
,
args
in
zip
(
query
,
arguments
):
if
args
is
None
:
future
=
cursor
.
execute_async
(
query
)
else
:
future
=
cursor
.
execute_async
(
query
,
args
)
futures
.
append
(
future
)
for
future
in
futures
:
yield
future
.
result
()
This diff is collapsed.
Click to expand it.
tests/test_cassandra.py
+
11
−
1
View file @
6d515d7c
...
...
@@ -8,12 +8,15 @@ class TestCassandra(unittest.TestCase):
def
__init__
(
self
):
self
.
execute_times_called
=
0
self
.
result_times_called
=
0
self
.
execute_without_args_called
=
0
def
result
(
self
):
self
.
result_times_called
+=
1
return
[]
def
execute_async
(
self
,
query
,
args
):
def
execute_async
(
self
,
query
,
args
=
None
):
if
args
is
None
:
self
.
execute_without_args_called
+=
1
self
.
execute_times_called
+=
1
return
self
...
...
@@ -29,3 +32,10 @@ class TestCassandra(unittest.TestCase):
self
.
assertEqual
(
cur
.
execute_times_called
,
6
)
self
.
assertEqual
(
cur
.
result_times_called
,
6
)
list
(
parallel_for
(
cur
,
[
'
SELECT * FROM table
'
,
'
SELECT * FROM table2
'
,
'
SELECT * FROM table3
'
],
[
None
,
None
,
None
]))
self
.
assertEqual
(
cur
.
execute_without_args_called
,
3
)
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