cassandra.graph
- Graph Statements, Options, and Row Factories
- Note:
-
This module is only for backward compatibility for dse-driver users. Consider using cassandra.datastax.graph.
Functions
single_object_row_factory
(column_names, rows)returns the JSON string value of graph results
graph_result_row_factory
(column_names, rows)Returns a Result
object that can load graph results and produce specific types.
The Result JSON is deserialized and unpacked from the top-level ‘result’ dict.
graph_object_row_factory
(column_names, rows)Like graph_result_row_factory()
, except known element types (Vertex
, Edge
) are
converted to their simplified objects. Some low-level metadata is shed in this conversion. Unknown result types are
still returned as Result
.
class GraphProtocol
Attributes
GRAPHSON_1_0
= ‘graphson-1.0’GraphSON1
GRAPHSON_2_0
= ‘graphson-2.0’GraphSON2
class GraphOptions
Options for DSE Graph Query handler.
Attributes
graph_name
name of the targeted graph.
graph_source
choose the graph traversal source, configured on the server side.
graph_language
the language used in the queries (default “gremlin-groovy”)
graph_read_consistency_level
read cassandra.ConsistencyLevel for graph queries (if distinct from session default). Setting this overrides the native Statement.consistency_level for read operations from Cassandra persistence
graph_write_consistency_level
write cassandra.ConsistencyLevel for graph queries (if distinct from session default). Setting this overrides the native Statement.consistency_level for write operations to Cassandra persistence.
is_default_source
is_analytics_source
True if graph_source
is set to the server-defined analytics traversal source (‘a’)
is_graph_source
True if graph_source
is set to the server-defined graph traversal source (‘g’)
Methods
set_source_default
()Sets graph_source
to the server-defined default traversal source (‘default’)
set_source_analytics
()Sets graph_source
to the server-defined analytic traversal source (‘a’)
set_source_graph
()Sets graph_source
to the server-defined graph traversal source (‘g’)
class SimpleGraphStatement
Simple graph statement for Session.execute_graph()
.
Takes the same parameters as SimpleStatement
.
query_string should be a literal CQL statement with the exception
of parameter placeholders that will be filled through the
parameters argument of Session.execute()
.
See Statement
attributes for a description of the other parameters.
class Result
Represents deserialized graph results. Property and item getters are provided for convenience.
Attributes
value
= NoneDeserialized value from the result
Methods
as_vertex
()Return a Vertex
parsed from this result
Raises TypeError if parsing fails (i.e. the result structure is not valid).
as_edge
()Return a Edge
parsed from this result
Raises TypeError if parsing fails (i.e. the result structure is not valid).
as_path
()Return a Path
parsed from this result
Raises TypeError if parsing fails (i.e. the result structure is not valid).
class Vertex
Represents a Vertex element from a graph query.
Vertex properties
are extracted into a dict
of property names to list of VertexProperty
(list
because they are always encoded that way, and sometimes have multiple cardinality; VertexProperty because sometimes
the properties themselves have property maps).
class VertexProperty
Vertex properties have a top-level value and an optional dict
of properties.
Attributes
label
= Nonelabel of the property
value
= NoneValue of the property
properties
= Nonedict of properties attached to the property
class Edge
Represents an Edge element from a graph query.
Attributes match initializer parameters.
class Path
Represents a graph path.
Labels list is taken verbatim from the results.
Objects are either Result
or Vertex
/Edge
for recognized types
Attributes
labels
= NoneList of labels in the path
objects
= NoneList of objects in the path
class GraphSON1Serializer
Serialize python objects to graphson types.
class GraphSON1Deserializer
Deserialize graphson1 types to python objects.
Class Methods
deserialize_date
(value)deserialize_timestamp
(value)deserialize_time
(value)deserialize_duration
(value)deserialize_int
(value)deserialize_bigint
(value)deserialize_double
(value)deserialize_float
(value)deserialize_uuid
(value)deserialize_blob
(value)deserialize_decimal
(value)deserialize_point
(value)deserialize_linestring
(value)deserialize_polygon
(value)class GraphSON2Reader
GraphSON2 Reader that parse json and deserialize to python objects.
- Parameters
-
extra_deserializer_map – map from GraphSON type tag to deserializer instance implementing deserialize
Methods
read
(json_data)Read and deserialize json_data
.
deserialize
(obj)Deserialize GraphSON type-tagged dict values into objects mapped in self.deserializers