|
| 1 | +from typing import Tuple |
| 2 | + |
| 3 | +from pandas import DataFrame |
| 4 | + |
| 5 | +from graphdatascience import ServerVersion |
| 6 | +from graphdatascience.call_parameters import CallParameters |
| 7 | +from graphdatascience.query_runner.aura_db_arrow_query_runner import ( |
| 8 | + AuraDbArrowQueryRunner, |
| 9 | +) |
| 10 | +from graphdatascience.tests.unit.conftest import CollectingQueryRunner |
| 11 | + |
| 12 | + |
| 13 | +class FakeArrowClient: |
| 14 | + |
| 15 | + def connection_info(self) -> Tuple[str, str]: |
| 16 | + return "myHost", "1234" |
| 17 | + |
| 18 | + def request_token(self) -> str: |
| 19 | + return "myToken" |
| 20 | + |
| 21 | + |
| 22 | +def test_extracts_parameters_projection() -> None: |
| 23 | + version = ServerVersion(2, 7, 0) |
| 24 | + db_query_runner = CollectingQueryRunner(version) |
| 25 | + gds_query_runner = CollectingQueryRunner(version) |
| 26 | + gds_query_runner.set__mock_result(DataFrame([{"databaseLocation": "remote"}])) |
| 27 | + qr = AuraDbArrowQueryRunner(gds_query_runner, db_query_runner, FakeArrowClient(), False) # type: ignore |
| 28 | + |
| 29 | + qr.call_procedure( |
| 30 | + endpoint="gds.arrow.project", |
| 31 | + params=CallParameters( |
| 32 | + graph_name="g", |
| 33 | + query="RETURN 1", |
| 34 | + concurrency=2, |
| 35 | + undirRels=[], |
| 36 | + inverseRels=[], |
| 37 | + arrow_configuration={"batchSize": 100}, |
| 38 | + ), |
| 39 | + ) |
| 40 | + |
| 41 | + # doesn't run anything on GDS |
| 42 | + assert gds_query_runner.last_query() == "" |
| 43 | + assert gds_query_runner.last_params() == {} |
| 44 | + assert ( |
| 45 | + db_query_runner.last_query() |
| 46 | + == "CALL gds.arrow.project($graph_name, $query, $concurrency, $undirRels, $inverseRels, $arrow_configuration)" |
| 47 | + ) |
| 48 | + assert db_query_runner.last_params() == { |
| 49 | + "graph_name": "g", |
| 50 | + "query": "RETURN 1", |
| 51 | + "concurrency": 2, |
| 52 | + "undirRels": [], |
| 53 | + "inverseRels": [], |
| 54 | + "arrow_configuration": { |
| 55 | + "encrypted": False, |
| 56 | + "host": "myHost", |
| 57 | + "port": "1234", |
| 58 | + "token": "myToken", |
| 59 | + "batchSize": 100, |
| 60 | + }, |
| 61 | + } |
| 62 | + |
| 63 | + |
| 64 | +def test_extracts_parameters_algo_write() -> None: |
| 65 | + version = ServerVersion(2, 7, 0) |
| 66 | + db_query_runner = CollectingQueryRunner(version) |
| 67 | + gds_query_runner = CollectingQueryRunner(version) |
| 68 | + gds_query_runner.set__mock_result(DataFrame([{"databaseLocation": "remote"}])) |
| 69 | + qr = AuraDbArrowQueryRunner(gds_query_runner, db_query_runner, FakeArrowClient(), False) # type: ignore |
| 70 | + |
| 71 | + qr.call_procedure(endpoint="gds.degree.write", params=CallParameters(graph_name="g", config={})) |
| 72 | + |
| 73 | + assert gds_query_runner.last_query() == "CALL gds.degree.write($graph_name, $config)" |
| 74 | + assert gds_query_runner.last_params() == { |
| 75 | + "graph_name": "g", |
| 76 | + "config": {"writeToResultStore": True}, |
| 77 | + } |
| 78 | + assert ( |
| 79 | + db_query_runner.last_query() |
| 80 | + == "CALL gds.arrow.write($graphName, $databaseName, $writeConfiguration, $arrowConfiguration)" |
| 81 | + ) |
| 82 | + assert db_query_runner.last_params() == { |
| 83 | + "graphName": "g", |
| 84 | + "databaseName": "dummy", |
| 85 | + "writeConfiguration": {"nodeLabels": ["*"]}, |
| 86 | + "arrowConfiguration": {"encrypted": False, "host": "myHost", "port": "1234", "token": "myToken"}, |
| 87 | + } |
| 88 | + |
| 89 | + |
| 90 | +def test_arrow_and_write_configuration() -> None: |
| 91 | + version = ServerVersion(2, 7, 0) |
| 92 | + db_query_runner = CollectingQueryRunner(version) |
| 93 | + gds_query_runner = CollectingQueryRunner(version) |
| 94 | + gds_query_runner.set__mock_result(DataFrame([{"databaseLocation": "remote"}])) |
| 95 | + qr = AuraDbArrowQueryRunner(gds_query_runner, db_query_runner, FakeArrowClient(), False) # type: ignore |
| 96 | + |
| 97 | + qr.call_procedure( |
| 98 | + endpoint="gds.degree.write", |
| 99 | + params=CallParameters( |
| 100 | + graph_name="g", |
| 101 | + config={"arrowConfiguration": {"batchSize": 1000}, "writeConfiguration": {"writeMode": "FOOBAR"}}, |
| 102 | + ), |
| 103 | + ) |
| 104 | + |
| 105 | + assert gds_query_runner.last_query() == "CALL gds.degree.write($graph_name, $config)" |
| 106 | + assert gds_query_runner.last_params() == { |
| 107 | + "graph_name": "g", |
| 108 | + "config": {"writeToResultStore": True}, |
| 109 | + } |
| 110 | + assert ( |
| 111 | + db_query_runner.last_query() |
| 112 | + == "CALL gds.arrow.write($graphName, $databaseName, $writeConfiguration, $arrowConfiguration)" |
| 113 | + ) |
| 114 | + assert db_query_runner.last_params() == { |
| 115 | + "graphName": "g", |
| 116 | + "databaseName": "dummy", |
| 117 | + "writeConfiguration": {"nodeLabels": ["*"], "writeMode": "FOOBAR"}, |
| 118 | + "arrowConfiguration": { |
| 119 | + "encrypted": False, |
| 120 | + "host": "myHost", |
| 121 | + "port": "1234", |
| 122 | + "token": "myToken", |
| 123 | + "batchSize": 1000, |
| 124 | + }, |
| 125 | + } |
| 126 | + |
| 127 | + |
| 128 | +def test_arrow_and_write_configuration_graph_write() -> None: |
| 129 | + version = ServerVersion(2, 7, 0) |
| 130 | + db_query_runner = CollectingQueryRunner(version) |
| 131 | + gds_query_runner = CollectingQueryRunner(version) |
| 132 | + gds_query_runner.set__mock_result(DataFrame([{"databaseLocation": "remote"}])) |
| 133 | + qr = AuraDbArrowQueryRunner(gds_query_runner, db_query_runner, FakeArrowClient(), False) # type: ignore |
| 134 | + |
| 135 | + qr.call_procedure( |
| 136 | + endpoint="gds.graph.nodeProperties.write", |
| 137 | + params=CallParameters( |
| 138 | + graph_name="g", |
| 139 | + properties=[], |
| 140 | + entities=[], |
| 141 | + config={"arrowConfiguration": {"batchSize": 42}, "writeConfiguration": {"writeMode": "FOOBAR"}}, |
| 142 | + ), |
| 143 | + ) |
| 144 | + |
| 145 | + assert ( |
| 146 | + gds_query_runner.last_query() |
| 147 | + == "CALL gds.graph.nodeProperties.write($graph_name, $properties, $entities, $config)" |
| 148 | + ) |
| 149 | + assert gds_query_runner.last_params() == { |
| 150 | + "graph_name": "g", |
| 151 | + "entities": [], |
| 152 | + "properties": [], |
| 153 | + "config": {"writeToResultStore": True}, |
| 154 | + } |
| 155 | + assert ( |
| 156 | + db_query_runner.last_query() |
| 157 | + == "CALL gds.arrow.write($graphName, $databaseName, $writeConfiguration, $arrowConfiguration)" |
| 158 | + ) |
| 159 | + assert db_query_runner.last_params() == { |
| 160 | + "graphName": "g", |
| 161 | + "databaseName": "dummy", |
| 162 | + "writeConfiguration": {"nodeLabels": [], "nodeProperties": [], "writeMode": "FOOBAR"}, |
| 163 | + "arrowConfiguration": { |
| 164 | + "encrypted": False, |
| 165 | + "host": "myHost", |
| 166 | + "port": "1234", |
| 167 | + "token": "myToken", |
| 168 | + "batchSize": 42, |
| 169 | + }, |
| 170 | + } |
0 commit comments