Was this page helpful?
ScyllaDB Python Driver is available under the Apache v2 License. ScyllaDB Python Driver is a fork of DataStax Python Driver. See Copyright here.
Caution
You're viewing documentation for a deprecated version of Scylla Python Driver. Switch to the latest stable version.
This section shows how to query and work with the geometric types provided by DSE.
These types are enabled implicitly by creating the Session from cassandra.cluster.Cluster
.
This module implicitly registers these types for use in the driver. This extension provides
some simple representative types in cassandra.util
for inserting and retrieving data:
from cassandra.cluster import Cluster
from cassandra.util import Point, LineString, Polygon
session = Cluster().connect()
session.execute("INSERT INTO ks.geo (k, point, line, poly) VALUES (%s, %s, %s, %s)",
0, Point(1, 2), LineString(((1, 2), (3, 4))), Polygon(((1, 2), (3, 4), (5, 6))))
Queries returning geometric types return the dse.util
types. Note that these can easily be used to construct
types from third-party libraries using the common attributes:
from shapely.geometry import LineString
shapely_linestrings = [LineString(res.line.coords) for res in session.execute("SELECT line FROM ks.geo")]
For prepared statements, shapely geometry types can be used interchangeably with the built-in types because their defining attributes are the same:
from shapely.geometry import Point
prepared = session.prepare("UPDATE ks.geo SET point = ? WHERE k = ?")
session.execute(prepared, (0, Point(1.2, 3.4)))
In order to use shapely types in a CQL-interpolated (non-prepared) query, one must update the encoder with those types, specifying the same string encoder as set for the internal types:
from cassandra import util
from shapely.geometry import Point, LineString, Polygon
encoder_func = session.encoder.mapping[util.Point]
for t in (Point, LineString, Polygon):
session.encoder.mapping[t] = encoder_func
session.execute("UPDATE ks.geo SET point = %s where k = %s", (0, Point(1.2, 3.4)))
Was this page helpful?
ScyllaDB Python Driver is available under the Apache v2 License. ScyllaDB Python Driver is a fork of DataStax Python Driver. See Copyright here.
cassandra
- Exceptions and Enumscassandra.cluster
- Clusters and Sessionscassandra.policies
- Load balancing and Failure Handling Policiescassandra.auth
- Authenticationcassandra.graph
- Graph Statements, Options, and Row Factoriescassandra.metadata
- Schema and Ring Topologycassandra.metrics
- Performance Metricscassandra.query
- Prepared Statements, Batch Statements, Tracing, and Row Factoriescassandra.pool
- Hosts and Connection Poolscassandra.protocol
- Protocol Featurescassandra.encoder
- Encoders for non-prepared Statementscassandra.decoder
- Data Return Formatscassandra.concurrent
- Utilities for Concurrent Statement Executioncassandra.connection
- Low Level Connection Infocassandra.util
- Utilitiescassandra.timestamps
- Timestamp Generationcassandra.io.asyncioreactor
- asyncio
Event Loopcassandra.io.asyncorereactor
- asyncore
Event Loopcassandra.io.eventletreactor
- eventlet
-compatible Connectioncassandra.io.libevreactor
- libev
Event Loopcassandra.io.geventreactor
- gevent
-compatible Event Loopcassandra.io.twistedreactor
- Twisted Event Loopcassandra.cqlengine.models
- Table models for object mappingcassandra.cqlengine.columns
- Column types for object mapping modelscassandra.cqlengine.query
- Query and filter model objectscassandra.cqlengine.connection
- Connection management for cqlenginecassandra.cqlengine.management
- Schema management for cqlenginecassandra.cqlengine.usertype
- Model classes for User Defined Typescassandra.datastax.graph
- Graph Statements, Options, and Row Factoriescassandra.datastax.graph.fluent
cassandra.datastax.graph.fluent.query
cassandra.datastax.graph.fluent.predicates