MCPcopy Create free account
hub / github.com/apache/cassandra-python-driver / GraphOptions

Class GraphOptions

cassandra/datastax/graph/query.py:67–149  ·  view source on GitHub ↗

Options for DSE Graph Query handler.

Source from the content-addressed store, hash-verified

65
66
67class GraphOptions(object):
68 """
69 Options for DSE Graph Query handler.
70 """
71 # See _graph_options map above for notes on valid options
72
73 DEFAULT_GRAPH_PROTOCOL = GraphProtocol.GRAPHSON_1_0
74 DEFAULT_GRAPH_LANGUAGE = b'gremlin-groovy'
75
76 def __init__(self, **kwargs):
77 self._graph_options = {}
78 kwargs.setdefault('graph_source', 'g')
79 kwargs.setdefault('graph_language', GraphOptions.DEFAULT_GRAPH_LANGUAGE)
80 for attr, value in kwargs.items():
81 if attr not in _graph_option_names:
82 warn("Unknown keyword argument received for GraphOptions: {0}".format(attr))
83 setattr(self, attr, value)
84
85 def copy(self):
86 new_options = GraphOptions()
87 new_options._graph_options = self._graph_options.copy()
88 return new_options
89
90 def update(self, options):
91 self._graph_options.update(options._graph_options)
92
93 def get_options_map(self, other_options=None):
94 """
95 Returns a map for these options updated with other options,
96 and mapped to graph payload types.
97 """
98 options = self._graph_options.copy()
99 if other_options:
100 options.update(other_options._graph_options)
101
102 # cls are special-cased so they can be enums in the API, and names in the protocol
103 for cl in ('graph-write-consistency', 'graph-read-consistency'):
104 cl_enum = options.get(cl)
105 if cl_enum is not None:
106 options[cl] = ConsistencyLevel.value_to_name[cl_enum].encode()
107 return options
108
109 def set_source_default(self):
110 """
111 Sets ``graph_source`` to the server-defined default traversal source ('default')
112 """
113 self.graph_source = 'default'
114
115 def set_source_analytics(self):
116 """
117 Sets ``graph_source`` to the server-defined analytic traversal source ('a')
118 """
119 self.graph_source = 'a'
120
121 def set_source_graph(self):
122 """
123 Sets ``graph_source`` to the server-defined graph traversal source ('g')
124 """

Calls

no outgoing calls