Skip to content

Add handling for metadata footers #105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions redisgraph/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ def _refresh_attributes(self):
for i, p in enumerate(props):
self._properties[i] = p[0]

def refresh_metadata(self, version, labels, reltypes, properties):
self.version = version
self._labels = labels
self._relationshipTypes = reltypes
self._properties = properties

def get_label(self, idx):
try:
label = self._labels[idx]
Expand Down Expand Up @@ -161,8 +167,8 @@ def query(self, q, params=None, timeout=None, read_only=False):
# ask for compact result-set format
# specify known graph version
cmd = "GRAPH.RO_QUERY" if read_only else "GRAPH.QUERY"
# command = [cmd, self.name, query, "--compact", "version", self.version]
command = [cmd, self.name, query, "--compact"]
command = [cmd, self.name, query, "--compact", "version", self.version]
# command = [cmd, self.name, query, "--compact"]

# include timeout is specified
if timeout:
Expand Down
21 changes: 20 additions & 1 deletion redisgraph/query_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ def __init__(self, graph, response):
self.parse_statistics(response[0])
else:
# start by parsing statistics, matches the one we have
self.parse_statistics(response[-1]) # Last element.
self.parse_statistics(response[2]) # Third element, after header and records.
self.parse_results(response)
if len(response) == 4:
self.parse_metadata(response[3])

def _check_for_errors(self, response):
if isinstance(response[0], ResponseError):
Expand Down Expand Up @@ -95,6 +97,23 @@ def parse_statistics(self, raw_statistics):
if v is not None:
self.statistics[s] = v

def parse_metadata(self, raw_metadata):
# Decode metadata:
# {
# "version", VERSION,
# "labels", [[VALUE_STRING, "label_1"] ... ],
# "relationship types ", [[VALUE_STRING, "reltype_1"] ... ],
# "property keys", [[VALUE_STRING, "prop_1"] ... ]
# }
metadata = self.parse_map(raw_metadata)
version = metadata["version"]
labels = metadata["labels"]
reltypes = metadata["relationship types"]
properties = metadata["property keys"]

# Update the graph's internal metadata.
self.graph.refresh_metadata(version, labels, reltypes, properties)

def parse_header(self, raw_result_set):
# An array of column name/column type pairs.
header = raw_result_set[0]
Expand Down
12 changes: 12 additions & 0 deletions tests/functional/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,18 @@ def test_cache_sync(self):
assert(A._relationshipTypes[0] == 'S')
assert(A._relationshipTypes[1] == 'R')

def test_metadata(self):
A = Graph('metadata', self.r)
# Since this query modifies schemas and returns data, it should
# update all graph metadata in a single call.
A.query("CREATE (l:L {v: 1}) RETURN l")
assert(len(A._labels) == 1)
assert(len(A._properties) == 1)
assert(len(A._relationshipTypes) == 0)
assert(A._labels[0] == 'L')
assert(A._properties[0] == 'v')
assert(A.version != 0)


if __name__ == '__main__':
unittest.main()