Skip to content

redis-py 4 #85

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

Merged
merged 1 commit into from
Mar 1, 2022
Merged
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
5 changes: 2 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "redisgraph-bulk-loader"
version = "0.9.15"
version = "0.10.0"
description = "RedisGraph Bulk Import Tool"
authors = ["Redis Inc <oss@redis.com>"]
license = "BSD-3-Clause"
Expand Down Expand Up @@ -30,7 +30,7 @@ repository = "https://github.com/RedisGraph/redisgraph-bulk-loader"
[tool.poetry.dependencies]
python = "^3.8.5"
click = "^8.0.1"
redis = "3.5.3"
redis = "^4.1.4"
pathos = "^0.2.8"

[tool.poetry.dev-dependencies]
Expand All @@ -42,7 +42,6 @@ bandit = "^1.7.0"
vulture = "^2.3"
pytest = "^6.2.4"
pytest-cov = "^2.12.1"
redisgraph = "^2.4.0"
pathos = "^0.2.8"

[build-system]
Expand Down
4 changes: 2 additions & 2 deletions redisgraph_bulk_loader/bulk_insert.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ def bulk_insert(graph, host, port, password, user, unix_socket_path, ssl_keyfile

# Attempt to verify that RedisGraph module is loaded
try:
module_list = client.execute_command("MODULE LIST")
if not any(b'graph' in module_description for module_description in module_list):
module_list = [m[b'name'] for m in client.module_list()]
if b'graph' not in module_list:
print("RedisGraph module not loaded on connected server.")
sys.exit(1)
except redis.exceptions.ResponseError:
Expand Down
7 changes: 3 additions & 4 deletions redisgraph_bulk_loader/bulk_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import csv
import redis
import click
from redisgraph import Graph
from timeit import default_timer as timer


Expand All @@ -28,7 +27,7 @@ def __init__(self, graph_name, max_token_size, separator, no_header, filename, q
self.max_token_size = max_token_size * 1024 * 1024 - utf8len(self.query)
self.filename = filename
self.graph_name = graph_name
self.graph = Graph(graph_name, client)
self.graph = client.graph(graph_name)
self.statistics = {}

def update_statistics(self, result):
Expand Down Expand Up @@ -136,8 +135,8 @@ def bulk_update(graph, host, port, password, user, unix_socket_path, query, vari

# Attempt to verify that RedisGraph module is loaded
try:
module_list = client.execute_command("MODULE LIST")
if not any('graph' in module_description for module_description in module_list):
module_list = [m['name'] for m in client.module_list()]
if 'graph' not in module_list:
print("RedisGraph module not loaded on connected server.")
sys.exit(1)
except redis.exceptions.ResponseError:
Expand Down
43 changes: 23 additions & 20 deletions test/test_bulk_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import csv
import redis
import unittest
from redisgraph import Graph
from redis import Redis
from click.testing import CliRunner
from redisgraph_bulk_loader.bulk_insert import bulk_insert

Expand Down Expand Up @@ -39,10 +39,13 @@ def setUpClass(cls):
@classmethod
def tearDownClass(cls):
"""Delete temporary files"""
os.remove('/tmp/nodes.tmp')
os.remove('/tmp/relations.tmp')
os.remove('/tmp/nodes_index.tmp')
os.remove('/tmp/nodes_full_text_index.tmp')
try:
os.remove('/tmp/nodes.tmp')
os.remove('/tmp/relations.tmp')
os.remove('/tmp/nodes_index.tmp')
os.remove('/tmp/nodes_full_text_index.tmp')
except OSError:
pass
cls.redis_con.flushall()

def validate_exception(self, res, expected_msg):
Expand Down Expand Up @@ -89,7 +92,7 @@ def test01_social_graph(self):
self.assertIn(visited_count + " relations created for type 'VISITED'", res.output)

# Open the constructed graph.
graph = Graph('social', self.redis_con)
graph = self.redis_con.graph('social')
query_result = graph.query("MATCH (p:Person) RETURN p.name, p.age, p.gender, p.status ORDER BY p.name")
# Verify that the Person label exists, has the correct attributes, and is properly populated.
expected_result = [['Ailon Velger', 32, 'male', 'married'],
Expand Down Expand Up @@ -207,7 +210,7 @@ def test02_private_identifiers(self):
self.assertIn('3 nodes created', res.output)
self.assertIn('2 relations created', res.output)

tmp_graph = Graph(graphname, self.redis_con)
tmp_graph = self.redis_con.graph(graphname)
# The field "_identifier" should not be a property in the graph
query_result = tmp_graph.query('MATCH (a) RETURN a')

Expand Down Expand Up @@ -280,8 +283,8 @@ def test04_batched_build(self):
self.assertIn(knows_count + " relations created for type 'KNOWS'", res.output)
self.assertIn(visited_count + " relations created for type 'VISITED'", res.output)

original_graph = Graph('social', self.redis_con)
new_graph = Graph(graphname, self.redis_con)
original_graph = self.redis_con.graph('social')
new_graph = self.redis_con.graph(graphname)

# Newly-created graph should be identical to graph created in single bulk command
original_result = original_graph.query('MATCH (p:Person) RETURN p, ID(p) ORDER BY p.name')
Expand Down Expand Up @@ -368,7 +371,7 @@ def test06_property_types(self):
self.assertIn('3 nodes created', res.output)
self.assertIn('3 relations created', res.output)

graph = Graph(graphname, self.redis_con)
graph = self.redis_con.graph(graphname)
query_result = graph.query('MATCH (a)-[e]->() RETURN a.numeric, a.mixed, a.bool, e.prop ORDER BY a.numeric, e.prop')
expected_result = [[0.2, 'string_prop_1', True, True],
[5, 'notnull', False, 3.5],
Expand Down Expand Up @@ -401,7 +404,7 @@ def test07_utf8(self):
assert res.exit_code == 0
assert '9 nodes created' in res.output

graph = Graph(graphname, self.redis_con)
graph = self.redis_con.graph(graphname)
# The non-ASCII property string must be escaped backticks to parse correctly
query_result = graph.query("""MATCH (a) RETURN a.`utf8_str_ß` ORDER BY a.id""")
expected_strs = [['Straße'],
Expand Down Expand Up @@ -439,7 +442,7 @@ def test08_nonstandard_separators(self):
self.assertEqual(res.exit_code, 0)
self.assertIn('2 nodes created', res.output)

graph = Graph(graphname, self.redis_con)
graph = self.redis_con.graph(graphname)
query_result = graph.query('MATCH (a) RETURN a.prop_a, a.prop_b, a.prop_c ORDER BY a.prop_a, a.prop_b, a.prop_c')
expected_result = [['val1', 5, True],
[10.5, 'a', False]]
Expand All @@ -465,7 +468,7 @@ def test09_schema(self):
self.assertEqual(res.exit_code, 0)
self.assertIn('2 nodes created', res.output)

graph = Graph(graphname, self.redis_con)
graph = self.redis_con.graph(graphname)
query_result = graph.query('MATCH (a) RETURN a.str_col, a.num_col, a.bool_col ORDER BY a.num_col')
expected_result = [['0', 0, True],
['1', 1, False]]
Expand Down Expand Up @@ -512,7 +515,7 @@ def test11_schema_ignore_columns(self):
self.assertEqual(res.exit_code, 0)
self.assertIn('2 nodes created', res.output)

graph = Graph(graphname, self.redis_con)
graph = self.redis_con.graph(graphname)
query_result = graph.query('MATCH (a) RETURN a ORDER BY a.str_col')

# The nodes should only have the 'str_col' property
Expand All @@ -538,7 +541,7 @@ def test12_no_null_values(self):
self.assertEqual(res.exit_code, 0)
self.assertIn('2 nodes created', res.output)

graph = Graph(graphname, self.redis_con)
graph = self.redis_con.graph(graphname)
query_result = graph.query('MATCH (a) RETURN a ORDER BY a.str_col')

# Only the first node should only have the 'mixed_col' property
Expand Down Expand Up @@ -580,7 +583,7 @@ def test13_id_namespaces(self):
self.assertIn('4 nodes created', res.output)
self.assertIn("2 relations created", res.output)

graph = Graph(graphname, self.redis_con)
graph = self.redis_con.graph(graphname)
query_result = graph.query('MATCH (src)-[]->(dest) RETURN src.id, src.name, LABELS(src), dest.id, dest.views, LABELS(dest) ORDER BY src.id')

expected_result = [['0', 'Jeffrey', ['User'], '0', 20, ['Post']],
Expand All @@ -605,7 +608,7 @@ def test14_array_properties_inferred(self):
self.assertEqual(res.exit_code, 0)
self.assertIn('2 nodes created', res.output)

graph = Graph(graphname, self.redis_con)
graph = self.redis_con.graph(graphname)
query_result = graph.query('MATCH (a) RETURN a ORDER BY a.str_col')

node_1 = {'str_col': 'str1', 'arr_col': [1, 0.2, 'nested_str', False]}
Expand All @@ -632,7 +635,7 @@ def test15_array_properties_schema_enforced(self):
self.assertEqual(res.exit_code, 0)
self.assertIn('2 nodes created', res.output)

graph = Graph(graphname, self.redis_con)
graph = self.redis_con.graph(graphname)
query_result = graph.query('MATCH (a) RETURN a ORDER BY a.str_col')

node_1 = {'str_col': 'str1', 'arr_col': [1, 0.2, 'nested_str', False]}
Expand Down Expand Up @@ -707,7 +710,7 @@ def test18_ensure_full_text_index_is_created(self):
self.assertIn('4 nodes created', res.output)
self.assertIn('Indices created: 1', res.output)

graph = Graph(graphname, self.redis_con)
graph = self.redis_con.graph(graphname)
query_result = graph.query("CALL db.idx.fulltext.queryNodes('Monkeys', 'tamarin') YIELD node RETURN node.name")
expected_result = [['Emperor Tamarin'], ['Golden Lion Tamarin'], ['Cotton-top Tamarin']]

Expand Down Expand Up @@ -748,7 +751,7 @@ def test19_integer_ids(self):
self.assertIn('4 nodes created', res.output)
self.assertIn("2 relations created", res.output)

graph = Graph(graphname, self.redis_con)
graph = self.redis_con.graph(graphname)
query_result = graph.query('MATCH (src)-[]->(dest) RETURN src.id, src.name, LABELS(src), dest.id, dest.views, LABELS(dest) ORDER BY src.id')

# The IDs of the results should be parsed as integers
Expand Down
16 changes: 8 additions & 8 deletions test/test_bulk_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import csv
import redis
import unittest
from redisgraph import Graph
from redis import Redis
from click.testing import CliRunner
from redisgraph_bulk_loader.bulk_update import bulk_update

Expand Down Expand Up @@ -45,7 +45,7 @@ def test01_simple_updates(self):
self.assertIn('Nodes created: 3', res.output)
self.assertIn('Properties set: 6', res.output)

tmp_graph = Graph(graphname, self.redis_con)
tmp_graph = self.redis_con.graph(graphname)
query_result = tmp_graph.query('MATCH (a) RETURN a.id, a.name ORDER BY a.id')

# Validate that the expected results are all present in the graph
Expand Down Expand Up @@ -88,7 +88,7 @@ def test02_traversal_updates(self):
self.assertIn('Relationships created: 3', res.output)
self.assertIn('Properties set: 6', res.output)

tmp_graph = Graph(graphname, self.redis_con)
tmp_graph = self.redis_con.graph(graphname)
query_result = tmp_graph.query('MATCH (a)-[:R]->(b) RETURN a.name, b.name ORDER BY a.name, b.name')

# Validate that the expected results are all present in the graph
Expand All @@ -115,7 +115,7 @@ def test03_datatypes(self):
self.assertIn('Nodes created: 1', res.output)
self.assertIn('Properties set: 5', res.output)

tmp_graph = Graph(graphname, self.redis_con)
tmp_graph = self.redis_con.graph(graphname)
query_result = tmp_graph.query('MATCH (a) RETURN a.intval, a.doubleval, a.boolval, a.stringval, a.arrayval')

# Validate that the expected results are all present in the graph
Expand Down Expand Up @@ -144,7 +144,7 @@ def test04_custom_delimiter(self):
self.assertIn('Nodes created: 3', res.output)
self.assertIn('Properties set: 6', res.output)

tmp_graph = Graph(graphname, self.redis_con)
tmp_graph = self.redis_con.graph(graphname)
query_result = tmp_graph.query('MATCH (a) RETURN a.id, a.name ORDER BY a.id')

# Validate that the expected results are all present in the graph
Expand Down Expand Up @@ -183,7 +183,7 @@ def test05_custom_variable_name(self):
self.assertIn('Nodes created: 14', res.output)
self.assertIn('Properties set: 56', res.output)

tmp_graph = Graph(graphname, self.redis_con)
tmp_graph = self.redis_con.graph(graphname)

# Validate that the expected results are all present in the graph
query_result = tmp_graph.query('MATCH (p:Person) RETURN p.name, p.age, p.gender, p.status ORDER BY p.name')
Expand Down Expand Up @@ -224,7 +224,7 @@ def test06_no_header(self):
self.assertIn('Nodes created: 3', res.output)
self.assertIn('Properties set: 6', res.output)

tmp_graph = Graph(graphname, self.redis_con)
tmp_graph = self.redis_con.graph(graphname)
query_result = tmp_graph.query('MATCH (a) RETURN a.id, a.name ORDER BY a.id')

# Validate that the expected results are all present in the graph
Expand Down Expand Up @@ -256,7 +256,7 @@ def test07_batched_update(self):
self.assertIn('Nodes created: 100000', res.output)
self.assertIn('Properties set: 100000', res.output)

tmp_graph = Graph(graphname, self.redis_con)
tmp_graph = self.redis_con.graph(graphname)
query_result = tmp_graph.query('MATCH (a) RETURN DISTINCT a.prop')

# Validate that the expected results are all present in the graph
Expand Down