Skip to content

Commit f284fb1

Browse files
committed
Merge pull request apache#513 from datastax/py323-docs
Py323 docs
2 parents 9362948 + eef8258 commit f284fb1

4 files changed

Lines changed: 44 additions & 4 deletions

File tree

CHANGELOG.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ Bug Fixes
4646
* cqlengine: class.MultipleObjectsReturned has DoesNotExist as base class (PYTHON-489)
4747
* cqlengine: Typo in cqlengine UserType __len__ breaks attribute assignment (PYTHON-502)
4848

49+
50+
Other
51+
-----
52+
53+
* cqlengine: a major improvement on queryset has been introduced. It
54+
is a lot more efficient to iterate large datasets: the rows are
55+
now fetched on demand using the driver pagination.
56+
57+
* cqlengine: the queryset len() and count() behaviors have changed. It
58+
now executes a "SELECT COUNT(*)" of the query rather than returning
59+
the size of the internal result_cache (loaded rows). On large
60+
queryset, you might want to avoid using them due to the performance
61+
cost. Note that trying to access objects using list index/slicing
62+
with negative indices also requires a count to be
63+
executed.
64+
65+
66+
4967
3.0.0
5068
=====
5169
November 24, 2015

cassandra/cqlengine/query.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,9 @@ class Comment(Model):
700700

701701
def count(self):
702702
"""
703-
Returns the number of rows matched by this query
703+
Returns the number of rows matched by this query.
704+
705+
*Note: This function executes a SELECT COUNT() and has a performance cost on large datasets*
704706
"""
705707
if self._batch:
706708
raise CQLEngineException("Only inserts, updates, and deletes are available in batch mode")
@@ -751,14 +753,19 @@ class Automobile(Model):
751753

752754
def limit(self, v):
753755
"""
754-
Limits the number of results returned by Cassandra.
756+
Limits the number of results returned by Cassandra. Use *0* or *None* to disable.
755757
756758
*Note that CQL's default limit is 10,000, so all queries without a limit set explicitly will have an implicit limit of 10,000*
757759
758760
.. code-block:: python
759761
762+
# Fetch 100 users
760763
for user in User.objects().limit(100):
761764
print(user)
765+
766+
# Fetch all users
767+
for user in User.objects().limit(None):
768+
print(user)
762769
"""
763770

764771
if v is None:
@@ -780,7 +787,7 @@ def fetch_size(self, v):
780787
"""
781788
Sets the number of rows that are fetched at a time.
782789
783-
*Note that driver's default fetch size is 5000.
790+
*Note that driver's default fetch size is 5000.*
784791
785792
.. code-block:: python
786793

docs/api/cassandra/cqlengine/query.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ The methods here are used to filter, order, and constrain results.
1818

1919
.. automethod:: count
2020

21+
.. method:: len(queryset)
22+
23+
Returns the number of rows matched by this query. This function uses :meth:`~.cassandra.cqlengine.query.ModelQuerySet.count` internally.
24+
25+
*Note: This function executes a SELECT COUNT() and has a performance cost on large datasets*
26+
2127
.. automethod:: distinct
2228

2329
.. automethod:: filter
@@ -26,6 +32,8 @@ The methods here are used to filter, order, and constrain results.
2632

2733
.. automethod:: limit
2834

35+
.. automethod:: fetch_size
36+
2937
.. automethod:: if_not_exists
3038

3139
.. automethod:: if_exists

docs/cqlengine/queryset.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ Accessing objects in a QuerySet
7979
q[0] #returns the first result
8080
q[1] #returns the second result
8181
82+
.. note::
83+
84+
* CQL does not support specifying a start position in it's queries. Therefore, accessing elements using array indexing will load every result up to the index value requested
85+
* Using negative indices requires a "SELECT COUNT()" to be executed. This has a performance cost on large datasets.
8286

8387
* list slicing
8488
.. code-block:: python
@@ -87,7 +91,10 @@ Accessing objects in a QuerySet
8791
q[1:] #returns all results except the first
8892
q[1:9] #returns a slice of the results
8993
90-
*Note: CQL does not support specifying a start position in it's queries. Therefore, accessing elements using array indexing / slicing will load every result up to the index value requested*
94+
.. note::
95+
96+
* CQL does not support specifying a start position in it's queries. Therefore, accessing elements using array slicing will load every result up to the index value requested
97+
* Using negative indices requires a "SELECT COUNT()" to be executed. This has a performance cost on large datasets.
9198

9299
* calling :attr:`get() <query.QuerySet.get>` on the queryset
93100
.. code-block:: python

0 commit comments

Comments
 (0)