Skip to content

Instantly share code, notes, and snippets.

@beltran
Last active July 31, 2017 19:37
Show Gist options
  • Save beltran/8295ec859a74f93322fb168c3e8a5d9c to your computer and use it in GitHub Desktop.
Save beltran/8295ec859a74f93322fb168c3e8a5d9c to your computer and use it in GitHub Desktop.
from dse_graph import DseGraph, graph_traversal_row_factory
from dse_graph.serializers import IntegerSerializer
from dse.cluster import EXEC_PROFILE_GRAPH_DEFAULT, EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT
from gremlin_python.structure.io.graphson import GraphSONUtil
from dse.cluster import Cluster
cluster = Cluster()
session = cluster.connect()
graph_name = "graph_name_poc_datetime"
session.execute_graph('system.graph(name).ifNotExists().create()', {'name': graph_name})
profiles = cluster.profile_manager.profiles
profiles[EXEC_PROFILE_GRAPH_DEFAULT].request_timeout = 10
profiles[EXEC_PROFILE_GRAPH_DEFAULT].graph_options.graph_name = graph_name
profiles[EXEC_PROFILE_GRAPH_ANALYTICS_DEFAULT].graph_options.graph_name = graph_name
session.execute_graph('schema.clear()')
ALLOW_SCANS = "schema.config().option('graph.allow_scan').set('true')"
MAKE_NON_STRICT = "schema.config().option('graph.schema_mode').set('development')"
session.execute_graph(MAKE_NON_STRICT)
session.execute_graph(ALLOW_SCANS)
g = DseGraph().traversal_source(session, graph_name)
property_name= "bigint1" + "value"
value = -2**32+1
def dictify(cls, n, _):
return GraphSONUtil.typedValue('Int32', n)
IntegerSerializer.dictify = classmethod(dictify)
traversal = g.addV("poc_int").property(property_name, value)
# This should race an InvalidRequest exception
#traversal.toList()
# This emulates what would happen with traversal.toList() commented above
# That might not always give the expected result since the order in the serialized JSON matters to
# trigger the bug
ep = session.execution_profile_clone_update(profiles[EXEC_PROFILE_GRAPH_DEFAULT], row_factory=graph_traversal_row_factory)
graph_options = ep.graph_options.copy()
graph_options.graph_language = DseGraph.DSE_GRAPH_QUERY_LANGUAGE
graph_options.graph_name = graph_name
ep.graph_options = graph_options
# If we use this it works as expected, Invalid request is arisen
query_graph = '{"@type":"g:Bytecode","@value":{"step":[["addV","poc_int"],["property","bigint1value",{"@type":"g:Int32","@value":-4294967295}]]}}'
# 1 is written to Graph
query_graph = '{"@value":{"step":[["addV","poc_int"],["property","bigint1value",{"@value":-4294967295,"@type":"g:Int32"}]]},"@type":"g:Bytecode"}'
session.execute_graph(query_graph, execution_profile=ep)
for i in g.V().valueMap():
# This will be one
print(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment