Skip to content

Commit 2129057

Browse files
committed
Merge branch 'oss-next' of github.com:riptano/python-driver into oss-next
2 parents 65a4a78 + 4d9677e commit 2129057

File tree

11 files changed

+541
-107
lines changed

11 files changed

+541
-107
lines changed

README-dev.rst

Lines changed: 29 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Releasing
2626
# Download all wheels from the jfrog repository and copy them in
2727
# the dist/ directory
2828
cp /path/to/wheels/*.whl dist/
29-
29+
3030
# Upload all files
3131
twine upload dist/*
3232

@@ -128,67 +128,34 @@ web servers, use the SimpleHTTPServer module::
128128

129129
Then, browse to `localhost:8000 <http://localhost:8000>`_.
130130

131+
Tests
132+
=====
131133

132-
Running the Tests
133-
=================
134-
In order for the extensions to be built and used in the test, run::
135-
136-
nosetests
137-
138-
You can run a specific test module or package like so::
134+
Running Unit Tests
135+
------------------
136+
Unit tests can be run like so::
139137

140138
nosetests -w tests/unit/
141139

142140
You can run a specific test method like so::
143141

144142
nosetests -w tests/unit/test_connection.py:ConnectionTest.test_bad_protocol_version
145143

146-
Seeing Test Logs in Real Time
147-
-----------------------------
148-
Sometimes it's useful to output logs for the tests as they run::
149-
150-
nosetests -w tests/unit/ --nocapture --nologcapture
151-
152-
Use tee to capture logs and see them on your terminal::
153-
154-
nosetests -w tests/unit/ --nocapture --nologcapture 2>&1 | tee test.log
155-
156-
Specifying a Cassandra/DSE Version for Integration Tests
157-
----------------------------------------------------
158-
You can specify a cassandra version with the ``CASSANDRA_VERSION`` or ``DSE_VERSION` environment variable::
144+
Running Integration Tests
145+
-------------------------
146+
In order to run integration tests, you must specify a version to run using the ``CASSANDRA_VERSION`` or ``DSE_VERSION`` environment variable::
159147

160148
CASSANDRA_VERSION=2.0.9 nosetests -w tests/integration/standard
161-
DSE_VERSION=6.7.4 nosetests -w tests/integration/standard
162-
163-
You can also specify a cassandra directory (to test unreleased versions)::
164-
165-
CASSANDRA_DIR=/home/thobbs/cassandra nosetests -w tests/integration/standard
166-
167-
For this to work with DSE, you have to build it before. Once the appropriate commit is checked out, inside the ``bdp`` folder:
168149

169-
./gradlew clean dist
150+
Or you can specify a cassandra directory (to test unreleased versions)::
170151

171-
Running the advanced authentication tests for DSE
172-
-------------------------------------------------
173-
These tests are in the file ``tests/integration/advanced/test_auth.py``. These tests are run the same way
174-
as the rest but first the we have to set the variable ADS_HOME:
152+
CASSANDRA_DIR=/home/thobbs/cassandra nosetests -w tests/integration/standard/
175153

176-
git clone https://github.com/riptano/testeng-devtools.git
177-
cd testeng-devtools/EmbeddedAds
178-
mvn clean install
179-
cp target/embedded-ads-1.0.1-SNAPSHOT-*.jar embedded-ads.jar
180-
export ADS_HOME=`pwd`
154+
Specifying the usage of an already running Cassandra cluster
155+
------------------------------------------------------------
156+
The test will start the appropriate Cassandra clusters when necessary but if you don't want this to happen because a Cassandra cluster is already running the flag ``USE_CASS_EXTERNAL`` can be used, for example::
181157

182-
After this we can run the tests normally from the appropriate folder:
183-
184-
DSE_VERSION=6.7.4 nosetests -w tests/integration/advanced/test_auth.py
185-
186-
Specifying the usage of an already running cluster
187-
--------------------------------------------------
188-
The test will start the appropriate Cassandra clusters when necessary but if you don't want this to happen
189-
because a Cassandra cluster is already running the flag ``USE_CASS_EXTERNAL`` can be used, for example:
190-
191-
USE_CASS_EXTERNAL=1 python setup.py nosetests -w tests/integration/standard
158+
USE_CASS_EXTERNAL=1 CASSANDRA_VERSION=2.0.9 nosetests -w tests/integration/standard
192159

193160
Specify a Protocol Version for Tests
194161
------------------------------------
@@ -197,31 +164,31 @@ it with the ``PROTOCOL_VERSION`` environment variable::
197164

198165
PROTOCOL_VERSION=3 nosetests -w tests/integration/standard
199166

167+
Seeing Test Logs in Real Time
168+
-----------------------------
169+
Sometimes it's useful to output logs for the tests as they run::
170+
171+
nosetests -w tests/unit/ --nocapture --nologcapture
172+
173+
Use tee to capture logs and see them on your terminal::
174+
175+
nosetests -w tests/unit/ --nocapture --nologcapture 2>&1 | tee test.log
176+
200177
Testing Multiple Python Versions
201178
--------------------------------
202-
If you want to test all of python 2.7, 3.4, 3.5, 3.6 and pypy, use tox (this is what
179+
If you want to test all of python 2.7, 3.4, 3.5, 3.6, 3.7, and pypy, use tox (this is what
203180
TravisCI runs)::
204181

205182
tox
206183

207-
By default, tox only runs the unit tests because I haven't put in the effort
208-
to get the integration tests to run on TravicCI. However, the integration
209-
tests should work locally. To run them, edit the following line in tox.ini::
210-
211-
commands = {envpython} setup.py build_ext --inplace nosetests --verbosity=2 tests/unit/
212-
213-
and change ``tests/unit/`` to ``tests/``.
184+
By default, tox only runs the unit tests.
214185

215186
Running the Benchmarks
216187
======================
217188
There needs to be a version of cassandra running locally so before running the benchmarks, if ccm is installed:
218189

219190
ccm create benchmark_cluster -v 3.0.1 -n 1 -s
220191

221-
If testing against DSE:
222-
223-
ccm create 6.7.4 --dse [email protected] --dse-password=your_password -v 6.7.4 -n 1 -s
224-
225192
To run the benchmarks, pick one of the files under the ``benchmarks/`` dir and run it::
226193

227194
python benchmarks/future_batches.py
@@ -242,7 +209,7 @@ name to specify the built version::
242209

243210
python setup.py egg_info -b-`git rev-parse --short HEAD` sdist --formats=zip
244211

245-
The file (``dist/cassandra-driver-<version spec>.zip``) is packaged with Cassandra in ``cassandra/lib/cassandra-driver-internal-only.zip``.
212+
The file (``dist/cassandra-driver-<version spec>.zip``) is packaged with Cassandra in ``cassandra/lib/cassandra-driver-internal-only*zip``.
246213

247214
Releasing an EAP
248215
================
@@ -266,4 +233,4 @@ An EAP release is only uploaded on a private server and it is not published on p
266233

267234
python setup.py doc
268235

269-
* Upload the docs on the EAP download server.
236+
* Upload the docs on the EAP download server.

README.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@ DataStax Python Driver for Apache Cassandra
44
.. image:: https://travis-ci.org/datastax/python-driver.png?branch=master
55
:target: https://travis-ci.org/datastax/python-driver
66

7-
A modern, `feature-rich <https://github.com/datastax/python-driver#features>`_ and highly-tunable Python client library for Apache Cassandra (2.1+) using exclusively Cassandra's binary protocol and Cassandra Query Language v3.
7+
A modern, `feature-rich <https://github.com/datastax/python-driver#features>`_ and highly-tunable Python client library for Apache Cassandra (2.1+) and DataStax Enterprise (4.7+) using exclusively Cassandra's binary protocol and Cassandra Query Language v3.
88

99
The driver supports Python 2.7, 3.4, 3.5, 3.6 and 3.7.
1010

11-
If you require compatibility with DataStax Enterprise, use the `DataStax Enterprise Python Driver <http://docs.datastax.com/en/developer/python-dse-driver/>`_.
12-
1311
**Note:** DataStax products do not support big-endian systems.
1412

1513
Feedback Requested
@@ -27,6 +25,11 @@ Features
2725
* Configurable `load balancing <http://datastax.github.io/python-driver/api/cassandra/policies.html#load-balancing>`_ and `retry policies <http://datastax.github.io/python-driver/api/cassandra/policies.html#retrying-failed-operations>`_
2826
* `Concurrent execution utilities <http://datastax.github.io/python-driver/api/cassandra/concurrent.html>`_
2927
* `Object mapper <http://datastax.github.io/python-driver/object_mapper.html>`_
28+
* DSE Graph execution API
29+
* DSE Geometric type serialization
30+
* DSE PlainText and GSSAPI authentication
31+
32+
A fluent API extension for DSE Graph is available in the ``dse-graph`` package. For more information, see `the documentation here <http://docs.datastax.com/en/developer/python-dse-graph/>`_.
3033

3134
Installation
3235
------------

docs/CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*********
2+
CHANGELOG
3+
*********
4+
5+
.. include:: ../CHANGELOG.rst

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
#html_domain_indices = True
154154

155155
# If false, no index is generated.
156-
#html_use_index = True
156+
html_use_index = False
157157

158158
# If true, the index is split into individual pages for each letter.
159159
#html_split_index = False
@@ -223,5 +223,5 @@
223223
# (source start file, name, description, authors, manual section).
224224
man_pages = [
225225
('index', 'cassandra-driver', u'Cassandra Driver Documentation',
226-
[u'Tyler Hobbs'], 1)
226+
[u'DataStax'], 1)
227227
]

docs/execution_profiles.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ New profiles can be added constructing from scratch, or deriving from default:
121121
locked_execution = ExecutionProfile(load_balancing_policy=WhiteListRoundRobinPolicy(['127.0.0.1']))
122122
node1_profile = 'node1_whitelist'
123123
cluster.add_execution_profile(node1_profile, locked_execution)
124-
124+
125125
for _ in cluster.metadata.all_hosts():
126126
print session.execute(local_query, execution_profile=node1_profile)[0]
127127
@@ -141,7 +141,7 @@ We also have the ability to pass profile instances to be used for execution, but
141141
.. code:: python
142142
143143
from cassandra.query import tuple_factory
144-
144+
145145
tmp = session.execution_profile_clone_update('node1', request_timeout=100, row_factory=tuple_factory)
146146
147147
print session.execute(local_query, execution_profile=tmp)[0]

docs/geo_types.rst

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
DSE Geometry Types
2+
==================
3+
This section shows how to query and work with the geometric types provided by DSE.
4+
5+
These types are enabled implicitly by creating the Session from :class:`cassandra.cluster.Cluster`.
6+
This module implicitly registers these types for use in the driver. This extension provides
7+
some simple representative types in :mod:`cassandra.util` for inserting and retrieving data::
8+
9+
from cassandra.cluster import Cluster
10+
from cassandra.util import Point, LineString, Polygon
11+
session = Cluster().connect()
12+
13+
session.execute("INSERT INTO ks.geo (k, point, line, poly) VALUES (%s, %s, %s, %s)",
14+
0, Point(1, 2), LineString(((1, 2), (3, 4))), Polygon(((1, 2), (3, 4), (5, 6))))
15+
16+
Queries returning geometric types return the :mod:`dse.util` types. Note that these can easily be used to construct
17+
types from third-party libraries using the common attributes::
18+
19+
from shapely.geometry import LineString
20+
shapely_linestrings = [LineString(res.line.coords) for res in session.execute("SELECT line FROM ks.geo")]
21+
22+
For prepared statements, shapely geometry types can be used interchangeably with the built-in types because their
23+
defining attributes are the same::
24+
25+
from shapely.geometry import Point
26+
prepared = session.prepare("UPDATE ks.geo SET point = ? WHERE k = ?")
27+
session.execute(prepared, (0, Point(1.2, 3.4)))
28+
29+
In order to use shapely types in a CQL-interpolated (non-prepared) query, one must update the encoder with those types, specifying
30+
the same string encoder as set for the internal types::
31+
32+
from cassandra import util
33+
from shapely.geometry import Point, LineString, Polygon
34+
35+
encoder_func = session.encoder.mapping[util.Point]
36+
for t in (Point, LineString, Polygon):
37+
session.encoder.mapping[t] = encoder_func
38+
39+
session.execute("UPDATE ks.geo SET point = %s where k = %s", (0, Point(1.2, 3.4)))

docs/getting_started.rst

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ instance of :class:`~.Cluster` for each Cassandra cluster you want to interact
1111
with.
1212

1313
The simplest way to create a :class:`~.Cluster` is like this:
14+
First, make sure you have the Cassandra driver properly :doc:`installed <installation>`.
1415

1516
.. code-block:: python
1617
@@ -39,16 +40,48 @@ behavior in some other way, this is the place to do it:
3940

4041
.. code-block:: python
4142
42-
from cassandra.cluster import Cluster
43-
from cassandra.policies import DCAwareRoundRobinPolicy
43+
from cassandra.cluster import Cluster, ExecutionProfile, EXEC_PROFILE_DEFAULT
44+
from cassandra.query import tuple_factory
45+
46+
profile = ExecutionProfile(row_factory=tuple_factory)
47+
cluster = Cluster(execution_profiles={EXEC_PROFILE_DEFAULT: profile})
48+
session = cluster.connect()
49+
50+
print session.execute("SELECT release_version FROM system.local")[0]
4451
45-
cluster = Cluster(
46-
['10.1.1.3', '10.1.1.4', '10.1.1.5'],
47-
load_balancing_policy=DCAwareRoundRobinPolicy(local_dc='US_EAST'),
48-
port=9042)
52+
Profiles are passed in by ``execution_profiles`` dict.
4953

54+
In this case we can construct the base ``ExecutionProfile`` passing all attributes:
55+
56+
.. code-block:: python
57+
58+
from cassandra.cluster import Cluster, ExecutionProfile, EXEC_PROFILE_DEFAULT
59+
from cassandra.policies import WhiteListRoundRobinPolicy, DowngradingConsistencyRetryPolicy
60+
from cassandra.query import tuple_factory
61+
62+
profile = ExecutionProfile(
63+
load_balancing_policy=WhiteListRoundRobinPolicy(['127.0.0.1']),
64+
retry_policy=DowngradingConsistencyRetryPolicy(),
65+
consistency_level=ConsistencyLevel.LOCAL_QUORUM,
66+
serial_consistency_level=ConsistencyLevel.LOCAL_SERIAL,
67+
request_timeout=15,
68+
row_factory=tuple_factory
69+
)
70+
cluster = Cluster(execution_profiles={EXEC_PROFILE_DEFAULT: profile})
71+
session = cluster.connect()
72+
73+
print session.execute("SELECT release_version FROM system.local")[0]
74+
75+
Users are free to setup additional profiles to be used by name:
76+
77+
.. code-block:: python
78+
79+
profile_long = ExecutionProfile(request_timeout=30)
80+
cluster = Cluster(execution_profiles={'long': profile_long})
81+
session = cluster.connect()
82+
session.execute(statement, execution_profile='long')
5083
51-
You can find a more complete list of options in the :class:`~.Cluster` documentation.
84+
Also, parameters passed to ``Session.execute`` or attached to ``Statement``\s are still honored as before.
5285

5386
Instantiating a :class:`~.Cluster` does not actually connect us to any nodes.
5487
To establish connections and begin executing queries we need a
@@ -328,10 +361,8 @@ replicas of the data you are interacting with need to respond for
328361
the query to be considered a success.
329362
330363
By default, :attr:`.ConsistencyLevel.LOCAL_ONE` will be used for all queries.
331-
You can specify a different default for the session on :attr:`.Session.default_consistency_level`
332-
if the cluster is configured in legacy mode (not using execution profiles). Otherwise this can
333-
be done by setting the :attr:`.ExecutionProfile.consistency_level` for the execution profile with key
334-
:data:`~.cluster.EXEC_PROFILE_DEFAULT`.
364+
You can specify a different default by setting the :attr:`.ExecutionProfile.consistency_level`
365+
for the execution profile with key :data:`~.cluster.EXEC_PROFILE_DEFAULT`.
335366
To specify a different consistency level per request, wrap queries
336367
in a :class:`~.SimpleStatement`:
337368

0 commit comments

Comments
 (0)